diff --git a/puer.c b/puer.c index 15b576c..4bb4f97 100644 --- a/puer.c +++ b/puer.c @@ -394,15 +394,15 @@ void ccm_encrypt(unsigned char key[16], uint32_t messageindex, unsigned char mes // Xor full blocks size_t index = 0; + uint32_t counter = 1; for (; index + 16 <= length; index += 16) { - // Message blocks are numbered from index 1 onwards - ccm_xor_block(&message[index], key_words, messageindex, index + 1); + ccm_xor_block(&message[index], key_words, messageindex, counter++); } // Xor partial block, if any if (index < length) { unsigned char fullblock[16]; memcpy(fullblock, &message[index], length - index); - ccm_xor_block(fullblock, key_words, messageindex, index + 1); + ccm_xor_block(fullblock, key_words, messageindex, counter++); memcpy(&message[index], fullblock, length - index); } } @@ -417,15 +417,17 @@ bool ccm_decrypt(unsigned char key[16], uint32_t messageindex, unsigned char mes // Xor full blocks size_t index = 0; + uint32_t counter = 1; for (; index + 16 <= length; index += 16) { // Message blocks are numbered from index 1 onwards - ccm_xor_block(&message[index], key_words, messageindex, index + 1); + ccm_xor_block(&message[index], key_words, messageindex, counter++); } // Xor partial block, if any if (index < length) { unsigned char fullblock[16]; + memset(fullblock, 0, 16); memcpy(fullblock, &message[index], length - index); - ccm_xor_block(fullblock, key_words, messageindex, index + 1); + ccm_xor_block(fullblock, key_words, messageindex, counter++); memcpy(&message[index], fullblock, length - index); }