Skip to content

Commit 9fc630d

Browse files
ThalleyMaureenHelm
authored andcommitted
Bluetooth: CSIP: Use bt_crypto_aes_cmac instead of own
Instead of reimplementing the aes_cmac function, CSIP will now use the bt_crypto_aes_cmac function. Signed-off-by: Emil Gydesen <[email protected]>
1 parent 64adf0b commit 9fc630d

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

subsys/bluetooth/audio/csip_crypto.c

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,11 @@
1111
*/
1212
#include "csip_crypto.h"
1313
#include <zephyr/bluetooth/crypto.h>
14-
#include <tinycrypt/constants.h>
15-
#include <tinycrypt/utils.h>
16-
#include <tinycrypt/aes.h>
17-
#include <tinycrypt/cmac_mode.h>
18-
#include <tinycrypt/ccm_mode.h>
1914
#include <zephyr/sys/byteorder.h>
2015
#include <zephyr/sys/util.h>
2116

17+
#include "crypto/bt_crypto.h"
18+
2219
#include "common/bt_str.h"
2320

2421
#include <zephyr/logging/log.h>
@@ -29,29 +26,6 @@ LOG_MODULE_REGISTER(bt_csip_crypto, CONFIG_BT_CSIP_SET_MEMBER_CRYPTO_LOG_LEVEL);
2926
#define BT_CSIP_PADDED_RAND_SIZE (BT_CSIP_CRYPTO_PADDING_SIZE + BT_CSIP_CRYPTO_PRAND_SIZE)
3027
#define BT_CSIP_R_MASK BIT_MASK(24) /* r is 24 bit / 3 octet */
3128

32-
static int aes_cmac(const uint8_t key[BT_CSIP_CRYPTO_KEY_SIZE],
33-
const uint8_t *in, size_t in_len, uint8_t *out)
34-
{
35-
struct tc_aes_key_sched_struct sched;
36-
struct tc_cmac_struct state;
37-
38-
/* TODO: Copy of the aes_cmac from smp.c: Can we merge them? */
39-
40-
if (tc_cmac_setup(&state, key, &sched) == TC_CRYPTO_FAIL) {
41-
return -EIO;
42-
}
43-
44-
if (tc_cmac_update(&state, in, in_len) == TC_CRYPTO_FAIL) {
45-
return -EIO;
46-
}
47-
48-
if (tc_cmac_final(out, &state) == TC_CRYPTO_FAIL) {
49-
return -EIO;
50-
}
51-
52-
return 0;
53-
}
54-
5529
int bt_csip_sih(const uint8_t sirk[BT_CSIP_SET_SIRK_SIZE], uint8_t r[BT_CSIP_CRYPTO_PRAND_SIZE],
5630
uint8_t out[BT_CSIP_CRYPTO_HASH_SIZE])
5731
{
@@ -130,15 +104,15 @@ static int k1(const uint8_t *n, size_t n_size,
130104
LOG_DBG("BE: salt %s", bt_hex(salt, BT_CSIP_CRYPTO_SALT_SIZE));
131105
LOG_DBG("BE: p %s", bt_hex(p, p_size));
132106

133-
err = aes_cmac(salt, n, n_size, t);
107+
err = bt_crypto_aes_cmac(salt, n, n_size, t);
134108

135109
LOG_DBG("BE: t %s", bt_hex(t, sizeof(t)));
136110

137111
if (err) {
138112
return err;
139113
}
140114

141-
err = aes_cmac(t, p, p_size, out);
115+
err = bt_crypto_aes_cmac(t, p, p_size, out);
142116

143117
LOG_DBG("BE: out %s", bt_hex(out, 16));
144118

@@ -167,7 +141,7 @@ static int s1(const uint8_t *m, size_t m_size,
167141

168142
memset(zero, 0, sizeof(zero));
169143

170-
err = aes_cmac(zero, m, m_size, out);
144+
err = bt_crypto_aes_cmac(zero, m, m_size, out);
171145

172146
LOG_DBG("BE: out %s", bt_hex(out, 16));
173147

0 commit comments

Comments
 (0)