mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 02:37:28 +02:00
Fixes for STM32 CubeMX AES GCM crypto hardware where less than a block size (16) is used.
This commit is contained in:
@ -5323,7 +5323,7 @@ static int wc_AesGcmEncrypt_STM32(Aes* aes, byte* out, const byte* in, word32 sz
|
||||
word32 keyCopy[AES_256_KEY_SIZE/sizeof(word32)];
|
||||
#endif
|
||||
word32 keySize;
|
||||
int status = 0;
|
||||
int status = HAL_OK;
|
||||
word32 blocks = sz / AES_BLOCK_SIZE;
|
||||
word32 partial = sz % AES_BLOCK_SIZE;
|
||||
byte tag[AES_BLOCK_SIZE];
|
||||
@ -5390,8 +5390,10 @@ static int wc_AesGcmEncrypt_STM32(Aes* aes, byte* out, const byte* in, word32 sz
|
||||
if (status == HAL_OK) {
|
||||
/* GCM payload phase - blocks */
|
||||
hcryp.Init.GCMCMACPhase = CRYP_PAYLOAD_PHASE;
|
||||
status = HAL_CRYPEx_AES_Auth(&hcryp, in, (blocks * AES_BLOCK_SIZE), out,
|
||||
STM32_HAL_TIMEOUT);
|
||||
if (blocks) {
|
||||
status = HAL_CRYPEx_AES_Auth(&hcryp, (byte*)in,
|
||||
(blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT);
|
||||
}
|
||||
}
|
||||
if (status == HAL_OK && partial != 0) {
|
||||
/* GCM payload phase - partial remainder */
|
||||
@ -5408,9 +5410,11 @@ static int wc_AesGcmEncrypt_STM32(Aes* aes, byte* out, const byte* in, word32 sz
|
||||
}
|
||||
#else
|
||||
HAL_CRYP_Init(&hcryp);
|
||||
/* GCM payload phase - blocks */
|
||||
status = HAL_CRYPEx_AESGCM_Encrypt(&hcryp, (byte*)in,
|
||||
(blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT);
|
||||
if (blocks) {
|
||||
/* GCM payload phase - blocks */
|
||||
status = HAL_CRYPEx_AESGCM_Encrypt(&hcryp, (byte*)in,
|
||||
(blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT);
|
||||
}
|
||||
if (status == HAL_OK && partial != 0) {
|
||||
/* GCM payload phase - partial remainder */
|
||||
XMEMSET(partialBlock, 0, sizeof(partialBlock));
|
||||
@ -5718,7 +5722,7 @@ static int wc_AesGcmDecrypt_STM32(Aes* aes, byte* out,
|
||||
word32 keyCopy[AES_256_KEY_SIZE/sizeof(word32)];
|
||||
#endif
|
||||
word32 keySize;
|
||||
int status;
|
||||
int status = HAL_OK;
|
||||
word32 blocks = sz / AES_BLOCK_SIZE;
|
||||
word32 partial = sz % AES_BLOCK_SIZE;
|
||||
byte tag[AES_BLOCK_SIZE];
|
||||
@ -5785,8 +5789,10 @@ static int wc_AesGcmDecrypt_STM32(Aes* aes, byte* out,
|
||||
if (status == HAL_OK) {
|
||||
/* GCM payload phase - blocks */
|
||||
hcryp.Init.GCMCMACPhase = CRYP_PAYLOAD_PHASE;
|
||||
status = HAL_CRYPEx_AES_Auth(&hcryp, in, (blocks * AES_BLOCK_SIZE), out,
|
||||
STM32_HAL_TIMEOUT);
|
||||
if (blocks) {
|
||||
status = HAL_CRYPEx_AES_Auth(&hcryp, (byte*)in,
|
||||
(blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT);
|
||||
}
|
||||
}
|
||||
if (status == HAL_OK && partial != 0) {
|
||||
/* GCM payload phase - partial remainder */
|
||||
@ -5803,9 +5809,11 @@ static int wc_AesGcmDecrypt_STM32(Aes* aes, byte* out,
|
||||
}
|
||||
#else
|
||||
HAL_CRYP_Init(&hcryp);
|
||||
/* GCM payload phase - blocks */
|
||||
status = HAL_CRYPEx_AESGCM_Decrypt(&hcryp, (byte*)in,
|
||||
(blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT);
|
||||
if (blocks) {
|
||||
/* GCM payload phase - blocks */
|
||||
status = HAL_CRYPEx_AESGCM_Decrypt(&hcryp, (byte*)in,
|
||||
(blocks * AES_BLOCK_SIZE), out, STM32_HAL_TIMEOUT);
|
||||
}
|
||||
if (status == HAL_OK && partial != 0) {
|
||||
/* GCM payload phase - partial remainder */
|
||||
XMEMSET(partialBlock, 0, sizeof(partialBlock));
|
||||
|
Reference in New Issue
Block a user