1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:52:44 +01:00

crypto/ccm: fix plaintext_len write

plaintext_len should be written in MSB first order into bytes
[16-L..15] both included and not ]16-L..15].

[RFC3610: 2.2 Authentication]
This commit is contained in:
Gaëtan Harter 2017-11-20 12:57:40 +01:00 committed by Francisco Molina
parent 4eb0538e74
commit 480a8bf076

View File

@ -83,8 +83,8 @@ static int ccm_create_mac_iv(cipher_t *cipher, uint8_t auth_data_len, uint8_t M,
/* copy nonce to B[1..15-L] */
memcpy(&X1[1], nonce, min(nonce_len, 15 - L));
/* write plaintext_len to B[15..16-L] */
for (uint8_t i = 15; i > 16 - L; --i) {
/* write plaintext_len to B[15..16-L] (reverse) */
for (uint8_t i = 15; i > 16 - L - 1; --i) {
X1[i] = plaintext_len & 0xff;
plaintext_len >>= 8;
}