11
11
*/
12
12
#include "csip_crypto.h"
13
13
#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>
19
14
#include <zephyr/sys/byteorder.h>
20
15
#include <zephyr/sys/util.h>
21
16
17
+ #include "crypto/bt_crypto.h"
18
+
22
19
#include "common/bt_str.h"
23
20
24
21
#include <zephyr/logging/log.h>
@@ -29,29 +26,6 @@ LOG_MODULE_REGISTER(bt_csip_crypto, CONFIG_BT_CSIP_SET_MEMBER_CRYPTO_LOG_LEVEL);
29
26
#define BT_CSIP_PADDED_RAND_SIZE (BT_CSIP_CRYPTO_PADDING_SIZE + BT_CSIP_CRYPTO_PRAND_SIZE)
30
27
#define BT_CSIP_R_MASK BIT_MASK(24) /* r is 24 bit / 3 octet */
31
28
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
-
55
29
int bt_csip_sih (const uint8_t sirk [BT_CSIP_SET_SIRK_SIZE ], uint8_t r [BT_CSIP_CRYPTO_PRAND_SIZE ],
56
30
uint8_t out [BT_CSIP_CRYPTO_HASH_SIZE ])
57
31
{
@@ -130,15 +104,15 @@ static int k1(const uint8_t *n, size_t n_size,
130
104
LOG_DBG ("BE: salt %s" , bt_hex (salt , BT_CSIP_CRYPTO_SALT_SIZE ));
131
105
LOG_DBG ("BE: p %s" , bt_hex (p , p_size ));
132
106
133
- err = aes_cmac (salt , n , n_size , t );
107
+ err = bt_crypto_aes_cmac (salt , n , n_size , t );
134
108
135
109
LOG_DBG ("BE: t %s" , bt_hex (t , sizeof (t )));
136
110
137
111
if (err ) {
138
112
return err ;
139
113
}
140
114
141
- err = aes_cmac (t , p , p_size , out );
115
+ err = bt_crypto_aes_cmac (t , p , p_size , out );
142
116
143
117
LOG_DBG ("BE: out %s" , bt_hex (out , 16 ));
144
118
@@ -167,7 +141,7 @@ static int s1(const uint8_t *m, size_t m_size,
167
141
168
142
memset (zero , 0 , sizeof (zero ));
169
143
170
- err = aes_cmac (zero , m , m_size , out );
144
+ err = bt_crypto_aes_cmac (zero , m , m_size , out );
171
145
172
146
LOG_DBG ("BE: out %s" , bt_hex (out , 16 ));
173
147
0 commit comments