From 6a4460383e98fbdbdf568c0cb154dafec833ed44 Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Tue, 27 Jul 2021 21:34:14 +0100 Subject: Update to mybed 3.0.0 (#5275) --- src/mbedTLS++/RsaPrivateKey.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/mbedTLS++/RsaPrivateKey.cpp') diff --git a/src/mbedTLS++/RsaPrivateKey.cpp b/src/mbedTLS++/RsaPrivateKey.cpp index 3fd429dc0..d0c5b7c8b 100644 --- a/src/mbedTLS++/RsaPrivateKey.cpp +++ b/src/mbedTLS++/RsaPrivateKey.cpp @@ -11,7 +11,7 @@ cRsaPrivateKey::cRsaPrivateKey(void) { - mbedtls_rsa_init(&m_Rsa, MBEDTLS_RSA_PKCS_V15, 0); + mbedtls_rsa_init(&m_Rsa); m_CtrDrbg.Initialize("RSA", 3); } @@ -21,7 +21,7 @@ cRsaPrivateKey::cRsaPrivateKey(void) cRsaPrivateKey::cRsaPrivateKey(const cRsaPrivateKey & a_Other) { - mbedtls_rsa_init(&m_Rsa, MBEDTLS_RSA_PKCS_V15, 0); + mbedtls_rsa_init(&m_Rsa); mbedtls_rsa_copy(&m_Rsa, &a_Other.m_Rsa); m_CtrDrbg.Initialize("RSA", 3); } @@ -107,25 +107,22 @@ ContiguousByteBuffer cRsaPrivateKey::GetPubKeyDER(void) int cRsaPrivateKey::Decrypt(const ContiguousByteBufferView a_EncryptedData, Byte * a_DecryptedData, size_t a_DecryptedMaxLength) { - if (a_EncryptedData.size() < m_Rsa.len) + const auto KeyLength = mbedtls_rsa_get_len(&m_Rsa); + if (a_EncryptedData.size() < KeyLength) { - LOGD("%s: Invalid a_EncryptedLength: got %u, exp at least %u", - __FUNCTION__, static_cast(a_EncryptedData.size()), static_cast(m_Rsa.len) - ); + 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 < m_Rsa.len) + if (a_DecryptedMaxLength < KeyLength) { - LOGD("%s: Invalid a_DecryptedMaxLength: got %u, exp at least %u", - __FUNCTION__, static_cast(a_DecryptedMaxLength), static_cast(m_Rsa.len) - ); + 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(), MBEDTLS_RSA_PRIVATE, &DecryptedLength, + &m_Rsa, mbedtls_ctr_drbg_random, m_CtrDrbg.GetInternal(), &DecryptedLength, reinterpret_cast(a_EncryptedData.data()), a_DecryptedData, a_DecryptedMaxLength ); if (res != 0) -- cgit v1.2.3