forked from wolfSSL/wolfssl
Minor improvements to the STM32 CubeMX AES-GCM logic.
This commit is contained in:
@ -8224,7 +8224,7 @@ static WC_INLINE int wc_AesGcmEncrypt_STM32(Aes* aes, byte* out, const byte* in,
|
|||||||
}
|
}
|
||||||
XMEMCPY(outPadded, in, sz);
|
XMEMCPY(outPadded, in, sz);
|
||||||
|
|
||||||
if ((authInSz % AES_BLOCK_SIZE) != 0) {
|
if (authInSz == 0 || (authInSz % AES_BLOCK_SIZE) != 0) {
|
||||||
/* Need to pad the AAD to a full block with zeros. */
|
/* Need to pad the AAD to a full block with zeros. */
|
||||||
authPadSz = ((authInSz / AES_BLOCK_SIZE) + 1) * AES_BLOCK_SIZE;
|
authPadSz = ((authInSz / AES_BLOCK_SIZE) + 1) * AES_BLOCK_SIZE;
|
||||||
authInPadded = (byte*)XMALLOC(authPadSz, aes->heap,
|
authInPadded = (byte*)XMALLOC(authPadSz, aes->heap,
|
||||||
@ -8446,8 +8446,8 @@ int wc_AesGcmEncrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
defined(WOLFSSL_STM32F7) || \
|
defined(WOLFSSL_STM32F7) || \
|
||||||
defined(WOLFSSL_STM32L4))
|
defined(WOLFSSL_STM32L4))
|
||||||
|
|
||||||
/* additional argument checks - STM32 HW only supports 12 byte IV */
|
/* STM32 HW only supports 12 byte IV and 16 byte auth */
|
||||||
if (ivSz == GCM_NONCE_MID_SZ) {
|
if (ivSz == GCM_NONCE_MID_SZ && authInSz == AES_BLOCK_SIZE) {
|
||||||
return wc_AesGcmEncrypt_STM32(aes, out, in, sz, iv, ivSz,
|
return wc_AesGcmEncrypt_STM32(aes, out, in, sz, iv, ivSz,
|
||||||
authTag, authTagSz, authIn, authInSz);
|
authTag, authTagSz, authIn, authInSz);
|
||||||
}
|
}
|
||||||
@ -8611,7 +8611,7 @@ static WC_INLINE int wc_AesGcmDecrypt_STM32(Aes* aes, byte* out,
|
|||||||
}
|
}
|
||||||
XMEMCPY(outPadded, in, sz);
|
XMEMCPY(outPadded, in, sz);
|
||||||
|
|
||||||
if ((authInSz % AES_BLOCK_SIZE) != 0) {
|
if (authInSz == 0 || (authInSz % AES_BLOCK_SIZE) != 0) {
|
||||||
/* Need to pad the AAD to a full block with zeros. */
|
/* Need to pad the AAD to a full block with zeros. */
|
||||||
authPadSz = ((authInSz / AES_BLOCK_SIZE) + 1) * AES_BLOCK_SIZE;
|
authPadSz = ((authInSz / AES_BLOCK_SIZE) + 1) * AES_BLOCK_SIZE;
|
||||||
authInPadded = (byte*)XMALLOC(authPadSz, aes->heap,
|
authInPadded = (byte*)XMALLOC(authPadSz, aes->heap,
|
||||||
@ -8848,8 +8848,8 @@ int wc_AesGcmDecrypt(Aes* aes, byte* out, const byte* in, word32 sz,
|
|||||||
defined(WOLFSSL_STM32F7) || \
|
defined(WOLFSSL_STM32F7) || \
|
||||||
defined(WOLFSSL_STM32L4))
|
defined(WOLFSSL_STM32L4))
|
||||||
|
|
||||||
/* additional argument checks - STM32 HW only supports 12 byte IV */
|
/* STM32 HW only supports 12 byte IV and 16 byte auth */
|
||||||
if (ivSz == GCM_NONCE_MID_SZ) {
|
if (ivSz == GCM_NONCE_MID_SZ && authInSz == AES_BLOCK_SIZE) {
|
||||||
return wc_AesGcmDecrypt_STM32(aes, out, in, sz, iv, ivSz,
|
return wc_AesGcmDecrypt_STM32(aes, out, in, sz, iv, ivSz,
|
||||||
authTag, authTagSz, authIn, authInSz);
|
authTag, authTagSz, authIn, authInSz);
|
||||||
}
|
}
|
||||||
|
@ -769,7 +769,8 @@ initDefaultName();
|
|||||||
printf( "AES256 test passed!\n");
|
printf( "AES256 test passed!\n");
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_AESGCM
|
#ifdef HAVE_AESGCM
|
||||||
#if !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO) && !defined(STM32_CRYPTO)
|
#if !defined(WOLFSSL_AFALG) && !defined(WOLFSSL_DEVCRYPTO) && \
|
||||||
|
!defined(STM32_CRYPTO)
|
||||||
if ( (ret = aesgcm_test()) != 0)
|
if ( (ret = aesgcm_test()) != 0)
|
||||||
return err_sys("AES-GCM test failed!\n", ret);
|
return err_sys("AES-GCM test failed!\n", ret);
|
||||||
else
|
else
|
||||||
@ -6630,8 +6631,8 @@ static int aesgcm_default_test_helper(byte* key, int keySz, byte* iv, int ivSz,
|
|||||||
byte* plain, int plainSz, byte* cipher, int cipherSz,
|
byte* plain, int plainSz, byte* cipher, int cipherSz,
|
||||||
byte* aad, int aadSz, byte* tag, int tagSz)
|
byte* aad, int aadSz, byte* tag, int tagSz)
|
||||||
{
|
{
|
||||||
Aes enc;
|
Aes enc;
|
||||||
Aes dec;
|
Aes dec;
|
||||||
|
|
||||||
byte resultT[AES_BLOCK_SIZE];
|
byte resultT[AES_BLOCK_SIZE];
|
||||||
byte resultP[AES_BLOCK_SIZE * 3];
|
byte resultP[AES_BLOCK_SIZE * 3];
|
||||||
|
Reference in New Issue
Block a user