summaryrefslogtreecommitdiffstats
path: root/src/mbedTLS++/CryptoKey.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbedTLS++/CryptoKey.cpp')
-rw-r--r--src/mbedTLS++/CryptoKey.cpp61
1 files changed, 47 insertions, 14 deletions
diff --git a/src/mbedTLS++/CryptoKey.cpp b/src/mbedTLS++/CryptoKey.cpp
index 742d9c73c..2c253c500 100644
--- a/src/mbedTLS++/CryptoKey.cpp
+++ b/src/mbedTLS++/CryptoKey.cpp
@@ -63,15 +63,25 @@ cCryptoKey::~cCryptoKey()
-int cCryptoKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength, Byte * a_DecryptedData, size_t a_DecryptedMaxLength)
+int cCryptoKey::Decrypt(
+ const Byte * a_EncryptedData,
+ size_t a_EncryptedLength,
+ Byte * a_DecryptedData,
+ size_t a_DecryptedMaxLength
+)
{
ASSERT(IsValid());
size_t DecryptedLen = a_DecryptedMaxLength;
- int res = mbedtls_pk_decrypt(&m_Pk,
- a_EncryptedData, a_EncryptedLength,
- a_DecryptedData, &DecryptedLen, a_DecryptedMaxLength,
- mbedtls_ctr_drbg_random, m_CtrDrbg.GetInternal()
+ int res = mbedtls_pk_decrypt(
+ &m_Pk,
+ a_EncryptedData,
+ a_EncryptedLength,
+ a_DecryptedData,
+ &DecryptedLen,
+ a_DecryptedMaxLength,
+ mbedtls_ctr_drbg_random,
+ m_CtrDrbg.GetInternal()
);
if (res != 0)
{
@@ -84,14 +94,25 @@ int cCryptoKey::Decrypt(const Byte * a_EncryptedData, size_t a_EncryptedLength,
-int cCryptoKey::Encrypt(const Byte * a_PlainData, size_t a_PlainLength, Byte * a_EncryptedData, size_t a_EncryptedMaxLength)
+int cCryptoKey::Encrypt(
+ const Byte * a_PlainData,
+ size_t a_PlainLength,
+ Byte * a_EncryptedData,
+ size_t a_EncryptedMaxLength
+)
{
ASSERT(IsValid());
size_t EncryptedLength = a_EncryptedMaxLength;
- int res = mbedtls_pk_encrypt(&m_Pk,
- a_PlainData, a_PlainLength, a_EncryptedData, &EncryptedLength, a_EncryptedMaxLength,
- mbedtls_ctr_drbg_random, m_CtrDrbg.GetInternal()
+ int res = mbedtls_pk_encrypt(
+ &m_Pk,
+ a_PlainData,
+ a_PlainLength,
+ a_EncryptedData,
+ &EncryptedLength,
+ a_EncryptedMaxLength,
+ mbedtls_ctr_drbg_random,
+ m_CtrDrbg.GetInternal()
);
if (res != 0)
{
@@ -119,20 +140,32 @@ int cCryptoKey::ParsePrivate(const void * a_Data, size_t a_NumBytes, const AStri
{
ASSERT(!IsValid()); // Cannot parse a second key
// mbedTLS requires that PEM-encoded data is passed including the terminating NUL byte,
- // and DER-encoded data is decoded properly even with an extra trailing NUL byte, so we simply add one to everything:
+ // and DER-encoded data is decoded properly even with an extra trailing NUL byte, so we simply add one to
+ // everything:
AString keyData(static_cast<const char *>(a_Data), a_NumBytes);
if (a_Password.empty())
{
- return mbedtls_pk_parse_key(&m_Pk, reinterpret_cast<const unsigned char *>(keyData.data()), a_NumBytes + 1, nullptr, 0, mbedtls_ctr_drbg_random, m_CtrDrbg.GetInternal());
+ return mbedtls_pk_parse_key(
+ &m_Pk,
+ reinterpret_cast<const unsigned char *>(keyData.data()),
+ a_NumBytes + 1,
+ nullptr,
+ 0,
+ mbedtls_ctr_drbg_random,
+ m_CtrDrbg.GetInternal()
+ );
}
else
{
return mbedtls_pk_parse_key(
&m_Pk,
- reinterpret_cast<const unsigned char *>(keyData.data()), a_NumBytes + 1,
- reinterpret_cast<const unsigned char *>(a_Password.c_str()), a_Password.size(),
- mbedtls_ctr_drbg_random, m_CtrDrbg.GetInternal()
+ reinterpret_cast<const unsigned char *>(keyData.data()),
+ a_NumBytes + 1,
+ reinterpret_cast<const unsigned char *>(a_Password.c_str()),
+ a_Password.size(),
+ mbedtls_ctr_drbg_random,
+ m_CtrDrbg.GetInternal()
);
}
}