summaryrefslogtreecommitdiffstats
path: root/src/mbedTLS++/RsaPrivateKey.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/mbedTLS++/RsaPrivateKey.cpp')
-rw-r--r--src/mbedTLS++/RsaPrivateKey.cpp37
1 files changed, 28 insertions, 9 deletions
diff --git a/src/mbedTLS++/RsaPrivateKey.cpp b/src/mbedTLS++/RsaPrivateKey.cpp
index d0c5b7c8b..2cc65a0ac 100644
--- a/src/mbedTLS++/RsaPrivateKey.cpp
+++ b/src/mbedTLS++/RsaPrivateKey.cpp
@@ -59,7 +59,7 @@ ContiguousByteBuffer cRsaPrivateKey::GetPubKeyDER(void)
{
class cPubKey
{
- public:
+ public:
cPubKey(mbedtls_rsa_context * a_Rsa) :
m_IsValid(false)
{
@@ -85,9 +85,9 @@ ContiguousByteBuffer cRsaPrivateKey::GetPubKeyDER(void)
}
}
- operator mbedtls_pk_context * (void) { return &m_Key; }
+ operator mbedtls_pk_context *(void) { return &m_Key; }
- protected:
+ protected:
bool m_IsValid;
mbedtls_pk_context m_Key;
} PkCtx(&m_Rsa);
@@ -98,32 +98,51 @@ ContiguousByteBuffer cRsaPrivateKey::GetPubKeyDER(void)
{
return {};
}
- return { reinterpret_cast<const std::byte *>(buf + sizeof(buf) - res), static_cast<size_t>(res) };
+ return {reinterpret_cast<const std::byte *>(buf + sizeof(buf) - res), static_cast<size_t>(res)};
}
-int cRsaPrivateKey::Decrypt(const ContiguousByteBufferView a_EncryptedData, Byte * a_DecryptedData, size_t a_DecryptedMaxLength)
+int cRsaPrivateKey::Decrypt(
+ const ContiguousByteBufferView a_EncryptedData,
+ Byte * a_DecryptedData,
+ size_t a_DecryptedMaxLength
+)
{
const auto KeyLength = mbedtls_rsa_get_len(&m_Rsa);
if (a_EncryptedData.size() < KeyLength)
{
- LOGD("%s: Invalid a_EncryptedLength: got %zu, exp at least %zu", __FUNCTION__, a_EncryptedData.size(), KeyLength);
+ LOGD(
+ "%s: Invalid a_EncryptedLength: got %zu, exp at least %zu",
+ __FUNCTION__,
+ a_EncryptedData.size(),
+ KeyLength
+ );
ASSERT(!"Invalid a_DecryptedMaxLength!");
return -1;
}
if (a_DecryptedMaxLength < KeyLength)
{
- LOGD("%s: Invalid a_DecryptedMaxLength: got %zu, exp at least %zu", __FUNCTION__, a_DecryptedMaxLength, KeyLength);
+ LOGD(
+ "%s: Invalid a_DecryptedMaxLength: got %zu, exp at least %zu",
+ __FUNCTION__,
+ a_DecryptedMaxLength,
+ KeyLength
+ );
ASSERT(!"Invalid a_DecryptedMaxLength!");
return -1;
}
size_t DecryptedLength;
int res = mbedtls_rsa_pkcs1_decrypt(
- &m_Rsa, mbedtls_ctr_drbg_random, m_CtrDrbg.GetInternal(), &DecryptedLength,
- reinterpret_cast<const unsigned char *>(a_EncryptedData.data()), a_DecryptedData, a_DecryptedMaxLength
+ &m_Rsa,
+ mbedtls_ctr_drbg_random,
+ m_CtrDrbg.GetInternal(),
+ &DecryptedLength,
+ reinterpret_cast<const unsigned char *>(a_EncryptedData.data()),
+ a_DecryptedData,
+ a_DecryptedMaxLength
);
if (res != 0)
{