From 6015e1edc2e003d8108b1cab8d122222067a4ee9 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Fri, 26 Oct 2018 13:57:03 +0200 Subject: [PATCH] btstack_crypto: provide auth_len for ccm init --- src/btstack_crypto.c | 6 ++++-- src/btstack_crypto.h | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/btstack_crypto.c b/src/btstack_crypto.c index e261b6b56..f86100198 100644 --- a/src/btstack_crypto.c +++ b/src/btstack_crypto.c @@ -364,7 +364,8 @@ static void btstack_crypto_ccm_setup_a_i(btstack_crypto_ccm_t * btstack_crypto_c */ static void btstack_crypto_ccm_setup_b_0(btstack_crypto_ccm_t * btstack_crypto_ccm, uint8_t * b0){ - b0[0] = (3 << 3) | 1 ; // Adata = 0, M' = (M-2)/2, L' = L - 1 + uint8_t m_prime = (btstack_crypto_ccm->auth_len - 2) / 2; + b0[0] = (m_prime << 3) | 1 ; // Adata = 0, M', L' = L - 1 memcpy(&b0[1], btstack_crypto_ccm->nonce, 13); big_endian_store_16(b0, 14, btstack_crypto_ccm->message_len); } @@ -997,10 +998,11 @@ int btstack_crypto_ecc_p256_validate_public_key(const uint8_t * public_key){ } #endif -void btstack_crypo_ccm_init(btstack_crypto_ccm_t * request, const uint8_t * key, const uint8_t * nonce, uint16_t message_len){ +void btstack_crypo_ccm_init(btstack_crypto_ccm_t * request, const uint8_t * key, const uint8_t * nonce, uint16_t message_len, uint8_t auth_len){ request->key = key; request->nonce = nonce; request->message_len = message_len; + request->auth_len = auth_len; request->counter = 1; } diff --git a/src/btstack_crypto.h b/src/btstack_crypto.h index 618448aae..690b667b0 100644 --- a/src/btstack_crypto.h +++ b/src/btstack_crypto.h @@ -121,6 +121,7 @@ typedef struct { uint16_t message_len; uint16_t block_len; uint16_t counter; + uint8_t auth_len; } btstack_crypto_ccm_t; /** @@ -219,8 +220,9 @@ int btstack_crypto_ecc_p256_validate_public_key(const uint8_t * public_key); * @param nonce * @param key * @param message_len + * @param auth_len */ -void btstack_crypo_ccm_init(btstack_crypto_ccm_t * request, const uint8_t * key, const uint8_t * nonce, uint16_t message_len); +void btstack_crypo_ccm_init(btstack_crypto_ccm_t * request, const uint8_t * key, const uint8_t * nonce, uint16_t message_len, uint8_t auth_len); /** * Get authentication value (M=8) after encrypt or decrypt operation