Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check on tag length for AES-CCM #2930

Merged
merged 4 commits into from
Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions wolfcrypt/src/aes.c
Original file line number Diff line number Diff line change
Expand Up @@ -6996,6 +6996,14 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
|| authTag == NULL || nonceSz < 7 || nonceSz > 13)
return BAD_FUNC_ARG;

/* sanity check on tag size */
JacobBarthelmeh marked this conversation as resolved.
Show resolved Hide resolved
if (authTagSz != 4 && authTagSz != 6 && authTagSz != 8 &&
authTagSz != 10 && authTagSz != 12 && authTagSz != 14 &&
authTagSz != 16) {
WOLFSSL_MSG("Bad auth tag size AES-CCM");
return BAD_FUNC_ARG;
}

key = (byte*)aes->key;

status = wc_AesGetKeySize(aes, &keySize);
Expand Down Expand Up @@ -7184,6 +7192,14 @@ int wc_AesCcmEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
authTagSz > AES_BLOCK_SIZE)
return BAD_FUNC_ARG;

/* sanity check on tag size */
if (authTagSz != 4 && authTagSz != 6 && authTagSz != 8 &&
authTagSz != 10 && authTagSz != 12 && authTagSz != 14 &&
authTagSz != 16) {
WOLFSSL_MSG("Bad auth tag size AES-CCM");
return BAD_FUNC_ARG;
}

XMEMSET(A, 0, sizeof(A));
XMEMCPY(B+1, nonce, nonceSz);
lenSz = AES_BLOCK_SIZE - 1 - (byte)nonceSz;
Expand Down Expand Up @@ -7280,6 +7296,14 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
authTagSz > AES_BLOCK_SIZE)
return BAD_FUNC_ARG;

/* sanity check on tag size */
if (authTagSz != 4 && authTagSz != 6 && authTagSz != 8 &&
JacobBarthelmeh marked this conversation as resolved.
Show resolved Hide resolved
authTagSz != 10 && authTagSz != 12 && authTagSz != 14 &&
authTagSz != 16) {
WOLFSSL_MSG("Bad auth tag size AES-CCM");
return BAD_FUNC_ARG;
}

o = out;
oSz = inSz;
XMEMCPY(B+1, nonce, nonceSz);
Expand Down
14 changes: 14 additions & 0 deletions wolfcrypt/test/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -9157,6 +9157,20 @@ int aesccm_test(void)
return -6313;
#endif

#if !defined(HAVE_FIPS) && !defined(HAVE_SELFTEST)
/* test fail on invalid IV sizes */
result = wc_AesCcmSetKey(&enc, k, sizeof(k));
if (result != 0)
return -6314;

/* AES-CCM encrypt and decrypt both use AES encrypt internally */
result = wc_AesCcmEncrypt(&enc, c2, p, sizeof(c2), iv, sizeof(iv),
t2, 1, a, sizeof(a));
if (result == 0) {
return -6315;
}
#endif

return 0;
}
#endif /* HAVE_AESCCM WOLFSSL_AES_128 */
Expand Down