fix on AES CCM nonce size

This commit is contained in:
Jacob Barthelmeh
2015-10-01 17:42:03 -06:00
parent 8f32604542
commit dd262fe939

View File

@@ -3565,9 +3565,20 @@ void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
byte B[AES_BLOCK_SIZE]; byte B[AES_BLOCK_SIZE];
byte lenSz; byte lenSz;
word32 i; word32 i;
byte mask = 0xFF;
word32 wordSz = (word32)sizeof(word32);
#ifdef FREESCALE_MMCAU #ifdef FREESCALE_MMCAU
byte* key = (byte*)aes->key; byte* key;
#endif
/* sanity check on arugments */
if (aes == NULL || out == NULL || in == NULL || nonce == NULL
|| authTag == NULL || nonceSz < 7 || nonceSz > 13)
return;
#ifdef FREESCALE_MMCAU
key = (byte*)aes->key;
#endif #endif
XMEMCPY(B+1, nonce, nonceSz); XMEMCPY(B+1, nonce, nonceSz);
@@ -3575,8 +3586,11 @@ void wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
B[0] = (authInSz > 0 ? 64 : 0) B[0] = (authInSz > 0 ? 64 : 0)
+ (8 * (((byte)authTagSz - 2) / 2)) + (8 * (((byte)authTagSz - 2) / 2))
+ (lenSz - 1); + (lenSz - 1);
for (i = 0; i < lenSz; i++) for (i = 0; i < lenSz; i++) {
B[AES_BLOCK_SIZE - 1 - i] = (inSz >> (8 * i)) & 0xFF; if (mask && i >= wordSz)
mask = 0x00;
B[AES_BLOCK_SIZE - 1 - i] = (inSz >> ((8 * i) & mask)) & mask;
}
#ifdef FREESCALE_MMCAU #ifdef FREESCALE_MMCAU
cau_aes_encrypt(B, key, aes->rounds, A); cau_aes_encrypt(B, key, aes->rounds, A);
@@ -3640,9 +3654,20 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
byte lenSz; byte lenSz;
word32 i, oSz; word32 i, oSz;
int result = 0; int result = 0;
byte mask = 0xFF;
word32 wordSz = (word32)sizeof(word32);
#ifdef FREESCALE_MMCAU #ifdef FREESCALE_MMCAU
byte* key = (byte*)aes->key; byte* key;
#endif
/* sanity check on arugments */
if (aes == NULL || out == NULL || in == NULL || nonce == NULL
|| authTag == NULL || nonceSz < 7 || nonceSz > 13)
return BAD_FUNC_ARG;
#ifdef FREESCALE_MMCAU
key = (byte*)aes->key;
#endif #endif
o = out; o = out;
@@ -3693,8 +3718,11 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
B[0] = (authInSz > 0 ? 64 : 0) B[0] = (authInSz > 0 ? 64 : 0)
+ (8 * (((byte)authTagSz - 2) / 2)) + (8 * (((byte)authTagSz - 2) / 2))
+ (lenSz - 1); + (lenSz - 1);
for (i = 0; i < lenSz; i++) for (i = 0; i < lenSz; i++) {
B[AES_BLOCK_SIZE - 1 - i] = (inSz >> (8 * i)) & 0xFF; if (mask && i >= wordSz)
mask = 0x00;
B[AES_BLOCK_SIZE - 1 - i] = (inSz >> ((8 * i) & mask)) & mask;
}
#ifdef FREESCALE_MMCAU #ifdef FREESCALE_MMCAU
cau_aes_encrypt(B, key, aes->rounds, A); cau_aes_encrypt(B, key, aes->rounds, A);