Skip to content

Commit 0aa0913

Browse files
alxelaxcarlescufi
authored andcommitted
Bluetooth: Host: fix aes ccm authentication
Bluetooth Host calculated authentication value correctly only for data smaller than 255 bytes. If data is larger then authentication transformation used wrong flags. Since the issue was symmetric two Zephyr based devices were able to understand each other. Hence, other devices like Android or IOS smartphones weren't able to authenticate large frames and broke communication. Signed-off-by: Aleksandr Khromykh <[email protected]>
1 parent 17eb313 commit 0aa0913

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

subsys/bluetooth/host/aes_ccm.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ static inline void xor16(uint8_t *dst, const uint8_t *a, const uint8_t *b)
3535
dst[15] = a[15] ^ b[15];
3636
}
3737

38-
/* pmsg is assumed to have the nonce already present in bytes 1-13 */
38+
/* b field is assumed to have the nonce already present in bytes 1-13 */
3939
static int ccm_calculate_X0(const uint8_t key[16], const uint8_t *aad, uint8_t aad_len,
40-
size_t mic_size, uint8_t msg_len, uint8_t b[16],
40+
size_t mic_size, uint16_t msg_len, uint8_t b[16],
4141
uint8_t X0[16])
4242
{
4343
int i, j, err;
@@ -95,7 +95,7 @@ static int ccm_calculate_X0(const uint8_t key[16], const uint8_t *aad, uint8_t a
9595
}
9696

9797
static int ccm_auth(const uint8_t key[16], uint8_t nonce[13],
98-
const uint8_t *cleartext_msg, size_t msg_len, const uint8_t *aad,
98+
const uint8_t *cleartext_msg, uint16_t msg_len, const uint8_t *aad,
9999
size_t aad_len, uint8_t *mic, size_t mic_size)
100100
{
101101
uint8_t b[16], Xn[16], s0[16];
@@ -148,7 +148,7 @@ static int ccm_auth(const uint8_t key[16], uint8_t nonce[13],
148148
}
149149

150150
static int ccm_crypt(const uint8_t key[16], const uint8_t nonce[13],
151-
const uint8_t *in_msg, uint8_t *out_msg, size_t msg_len)
151+
const uint8_t *in_msg, uint8_t *out_msg, uint16_t msg_len)
152152
{
153153
uint8_t a_i[16], s_i[16];
154154
uint16_t last_blk, blk_cnt;
@@ -192,7 +192,7 @@ int bt_ccm_decrypt(const uint8_t key[16], uint8_t nonce[13],
192192
{
193193
uint8_t mic[16];
194194

195-
if (aad_len >= 0xff00 || mic_size > sizeof(mic)) {
195+
if (aad_len >= 0xff00 || mic_size > sizeof(mic) || len > UINT16_MAX) {
196196
return -EINVAL;
197197
}
198198

@@ -219,7 +219,7 @@ int bt_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13],
219219
BT_DBG("aad_len %zu mic_size %zu", aad_len, mic_size);
220220

221221
/* Unsupported AAD size */
222-
if (aad_len >= 0xff00 || mic_size > 16) {
222+
if (aad_len >= 0xff00 || mic_size > 16 || len > UINT16_MAX) {
223223
return -EINVAL;
224224
}
225225

0 commit comments

Comments
 (0)