Skip to content

Commit b242b44

Browse files
committed
ARMv8 AES-GCM streaming: check size of IV before storing
Only store IV in Init function if it will fit in reg field of Aes object.
1 parent 0306d07 commit b242b44

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

wolfcrypt/src/port/arm/armv8-aes.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14512,8 +14512,7 @@ int wc_AesGcmInit(Aes* aes, const byte* key, word32 len, const byte* iv,
1451214512

1451314513
/* Check validity of parameters. */
1451414514
if ((aes == NULL) || ((len > 0) && (key == NULL)) ||
14515-
((ivSz == 0) && (iv != NULL)) ||
14516-
((ivSz > 0) && (iv == NULL))) {
14515+
((ivSz == 0) && (iv != NULL)) || ((ivSz > 0) && (iv == NULL))) {
1451714516
ret = BAD_FUNC_ARG;
1451814517
}
1451914518

@@ -14534,14 +14533,14 @@ int wc_AesGcmInit(Aes* aes, const byte* key, word32 len, const byte* iv,
1453414533
}
1453514534

1453614535
if (ret == 0) {
14537-
/* Setup with IV if needed. */
14538-
if (iv != NULL) {
14539-
/* Cache the IV in AES GCM object. */
14540-
XMEMCPY((byte*)aes->reg, iv, ivSz);
14536+
/* Set the IV passed in if it is smaller than a block. */
14537+
if ((iv != NULL) && (ivSz <= AES_BLOCK_SIZE)) {
14538+
XMEMMOVE((byte*)aes->reg, iv, ivSz);
1454114539
aes->nonceSz = ivSz;
1454214540
}
14543-
else if (aes->nonceSz != 0) {
14544-
/* Copy out the cached copy. */
14541+
/* No IV passed in, check for cached IV. */
14542+
if ((iv == NULL) && (aes->nonceSz != 0)) {
14543+
/* Use the cached copy. */
1454514544
iv = (byte*)aes->reg;
1454614545
ivSz = aes->nonceSz;
1454714546
}

0 commit comments

Comments
 (0)