Use the correct counter values with encryption/decryption
This commit is contained in:
parent
138cc5d2f5
commit
0cb02aaf14
12
puer.c
12
puer.c
|
@ -394,15 +394,15 @@ void ccm_encrypt(unsigned char key[16], uint32_t messageindex, unsigned char mes
|
||||||
|
|
||||||
// Xor full blocks
|
// Xor full blocks
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
uint32_t counter = 1;
|
||||||
for (; index + 16 <= length; index += 16) {
|
for (; index + 16 <= length; index += 16) {
|
||||||
// Message blocks are numbered from index 1 onwards
|
ccm_xor_block(&message[index], key_words, messageindex, counter++);
|
||||||
ccm_xor_block(&message[index], key_words, messageindex, index + 1);
|
|
||||||
}
|
}
|
||||||
// Xor partial block, if any
|
// Xor partial block, if any
|
||||||
if (index < length) {
|
if (index < length) {
|
||||||
unsigned char fullblock[16];
|
unsigned char fullblock[16];
|
||||||
memcpy(fullblock, &message[index], length - index);
|
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);
|
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
|
// Xor full blocks
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
|
uint32_t counter = 1;
|
||||||
for (; index + 16 <= length; index += 16) {
|
for (; index + 16 <= length; index += 16) {
|
||||||
// Message blocks are numbered from index 1 onwards
|
// 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
|
// Xor partial block, if any
|
||||||
if (index < length) {
|
if (index < length) {
|
||||||
unsigned char fullblock[16];
|
unsigned char fullblock[16];
|
||||||
|
memset(fullblock, 0, 16);
|
||||||
memcpy(fullblock, &message[index], length - index);
|
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);
|
memcpy(&message[index], fullblock, length - index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue