From fefe5d75e3eb9c736837a158d158820b00cd9ce8 Mon Sep 17 00:00:00 2001 From: Baojun Wang Date: Thu, 18 Jan 2018 11:40:38 -0800 Subject: [PATCH] flavor condition checks instead of asserts --- cbits/cryptonite_aes.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cbits/cryptonite_aes.c b/cbits/cryptonite_aes.c index 1888566..3af46d6 100644 --- a/cbits/cryptonite_aes.c +++ b/cbits/cryptonite_aes.c @@ -30,7 +30,6 @@ #include #include -#include #include #include @@ -530,7 +529,8 @@ void cryptonite_aes_ccm_aad(aes_ccm *ccm, aes_key *key, uint8_t *input, uint32_t { block128 tmp; - assert (ccm->length_aad == 0); + if (ccm->length_aad == 0) return; + ccm->length_aad = length; int len_len; @@ -915,7 +915,6 @@ void cryptonite_aes_generic_ccm_encrypt(uint8_t *output, aes_ccm *ccm, aes_key * block128_copy(&ccm->header_cbcmac, &ccm->xi); } - assert (length == ccm->length_input); if (length != ccm->length_input) { return; } @@ -938,6 +937,10 @@ void cryptonite_aes_generic_ccm_decrypt(uint8_t *output, aes_ccm *ccm, aes_key * { block128 tmp, ctr; + if (length != ccm->length_input) { + return; + } + /* when aad is absent, reset b0 block */ if (ccm->length_aad == 0) { ccm_encode_b0(&ccm->b0, ccm, 0); /* assume aad is present */ @@ -945,11 +948,6 @@ void cryptonite_aes_generic_ccm_decrypt(uint8_t *output, aes_ccm *ccm, aes_key * block128_copy(&ccm->header_cbcmac, &ccm->xi); } - assert (length == ccm->length_input); - if (length != ccm->length_input) { - return; - } - ccm_encode_ctr(&ctr, ccm, 1); cryptonite_aes_encrypt_ctr(output, key, &ctr, input, length); block128_copy(&ccm->xi, &ccm->header_cbcmac);