Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/nimble/nimble/host/mesh/src/mesh.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ int bt_mesh_init(uint8_t own_addr_type, const struct bt_mesh_prov *prov,
g_mesh_addr_type = own_addr_type;

/* initialize SM alg ECC subsystem (it is used directly from mesh code) */
ble_sm_alg_ecc_init();
na_ble_sm_alg_ecc_init();

err = bt_mesh_comp_register(comp);
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions src/nimble/nimble/host/src/ble_att_clt.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ ble_att_clt_tx_signed_write_cmd(uint16_t conn_handle, uint16_t cid, uint16_t han
/** Copying sign counter */
memcpy(&message[BLE_ATT_SIGNED_WRITE_DATA_OFFSET + OS_MBUF_PKTLEN(txom)], &counter, sizeof(counter));

/* ble_sm_alg_aes_cmac takes data in little-endian format,
/* na_ble_sm_alg_aes_cmac takes data in little-endian format,
* so converting it to LE.
*/
swap_in_place(message, len);
Expand All @@ -838,7 +838,7 @@ ble_att_clt_tx_signed_write_cmd(uint16_t conn_handle, uint16_t cid, uint16_t han
* for the message using our CSRK for this connection.
*/
memset(cmac, 0, sizeof cmac);
rc = ble_sm_alg_aes_cmac(csrk, message, len, cmac);
rc = na_ble_sm_alg_aes_cmac(csrk, message, len, cmac);
if (rc != 0) {
goto err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/nimble/nimble/host/src/ble_att_svr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2467,7 +2467,7 @@ ble_att_svr_rx_signed_write(uint16_t conn_handle, uint16_t cid, struct os_mbuf *

/* Using AES-CMAC to get the CMAC from the message and CSRK of this device */
memset(cmac, 0, sizeof cmac);
rc = ble_sm_alg_aes_cmac(csrk, message, len, cmac);
rc = na_ble_sm_alg_aes_cmac(csrk, message, len, cmac);
if (rc != 0) {
goto err;
}
Expand Down
2 changes: 1 addition & 1 deletion src/nimble/nimble/host/src/ble_gatts.c
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ ble_gatts_calculate_hash(uint8_t *out_hash_key)
goto done;
}

rc = ble_sm_alg_aes_cmac(key, buf, size, out_hash_key);
rc = na_ble_sm_alg_aes_cmac(key, buf, size, out_hash_key);
if(rc != 0) {
goto done;
}
Expand Down
6 changes: 3 additions & 3 deletions src/nimble/nimble/host/src/ble_hs_resolv.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ ble_hs_resolv_gen_priv_addr(struct ble_hs_resolv_entry *rl, int local)
swap_in_place(ecb.plain_text, 16);

/* Calculate hash */
if (ble_sm_alg_encrypt(ecb.key, ecb.plain_text, ecb.cipher_text) != 0) {
if (na_ble_sm_alg_encrypt(ecb.key, ecb.plain_text, ecb.cipher_text) != 0) {
/* We can't do much here if the encryption fails */
return;
}
Expand Down Expand Up @@ -768,8 +768,8 @@ ble_hs_resolv_rpa(uint8_t *rpa, uint8_t *irk)

swap_in_place(ecb.plain_text, 16);

/* Send the data to ble_sm_alg_encrypt in little-endian style */
rc = ble_sm_alg_encrypt(ecb.key, ecb.plain_text, ecb.cipher_text);
/* Send the data to na_ble_sm_alg_encrypt in little-endian style */
rc = na_ble_sm_alg_encrypt(ecb.key, ecb.plain_text, ecb.cipher_text);
if (rc != 0) {
return rc;
}
Expand Down
54 changes: 27 additions & 27 deletions src/nimble/nimble/host/src/ble_sm_alg.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ ble_sm_alg_xor_128(const uint8_t *p, const uint8_t *q, uint8_t *r)
}

int
ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
na_ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
uint8_t *enc_data)
{
uint8_t tmp[16];
Expand Down Expand Up @@ -135,7 +135,7 @@ ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
}

int
ble_sm_alg_s1(const uint8_t *k, const uint8_t *r1, const uint8_t *r2,
na_ble_sm_alg_s1(const uint8_t *k, const uint8_t *r1, const uint8_t *r2,
uint8_t *out)
{
int rc;
Expand All @@ -152,12 +152,12 @@ ble_sm_alg_s1(const uint8_t *k, const uint8_t *r1, const uint8_t *r2,
memcpy(out + 8, r1, 8);

/* s1(k, r1 , r2) = e(k, r') */
rc = ble_sm_alg_encrypt(k, out, out);
rc = na_ble_sm_alg_encrypt(k, out, out);
if (rc != 0) {
return rc;
}

BLE_HS_LOG(DEBUG, "ble_sm_alg_s1()\n k=");
BLE_HS_LOG(DEBUG, "na_ble_sm_alg_s1()\n k=");
ble_hs_log_flat_buf(k, 16);
BLE_HS_LOG(DEBUG, "\n r1=");
ble_hs_log_flat_buf(r1, 16);
Expand All @@ -171,7 +171,7 @@ ble_sm_alg_s1(const uint8_t *k, const uint8_t *r1, const uint8_t *r2,
}

int
ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,
na_ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,
const uint8_t *preq, const uint8_t *pres,
uint8_t iat, uint8_t rat,
const uint8_t *ia, const uint8_t *ra,
Expand All @@ -180,7 +180,7 @@ ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,
uint8_t p1[16], p2[16];
int rc;

BLE_HS_LOG(DEBUG, "ble_sm_alg_c1()\n k=");
BLE_HS_LOG(DEBUG, "na_ble_sm_alg_c1()\n k=");
ble_hs_log_flat_buf(k, 16);
BLE_HS_LOG(DEBUG, "\n r=");
ble_hs_log_flat_buf(r, 16);
Expand Down Expand Up @@ -208,7 +208,7 @@ ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,
/* Using out_enc_data as temporary output buffer */
ble_sm_alg_xor_128(r, p1, out_enc_data);

rc = ble_sm_alg_encrypt(k, out_enc_data, out_enc_data);
rc = na_ble_sm_alg_encrypt(k, out_enc_data, out_enc_data);
if (rc != 0) {
rc = BLE_HS_EUNKNOWN;
goto done;
Expand All @@ -224,7 +224,7 @@ ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,

ble_sm_alg_xor_128(out_enc_data, p2, out_enc_data);

rc = ble_sm_alg_encrypt(k, out_enc_data, out_enc_data);
rc = na_ble_sm_alg_encrypt(k, out_enc_data, out_enc_data);
if (rc != 0) {
rc = BLE_HS_EUNKNOWN;
goto done;
Expand All @@ -251,7 +251,7 @@ ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,

#if MYNEWT_VAL(BLE_CRYPTO_STACK_MBEDTLS)
int
ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
na_ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
uint8_t *out)
{
int rc = BLE_HS_EUNKNOWN;
Expand Down Expand Up @@ -289,7 +289,7 @@ ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,

#else
int
ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
na_ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
uint8_t *out)
{
struct tc_aes_key_sched_struct sched;
Expand Down Expand Up @@ -322,14 +322,14 @@ ble_sm_alg_log_buf(const char *name, const uint8_t *buf, int len)
}

int
ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
na_ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
uint8_t z, uint8_t *out_enc_data)
{
uint8_t xs[16];
uint8_t m[65];
int rc;

BLE_HS_LOG(DEBUG, "ble_sm_alg_f4()\n u=");
BLE_HS_LOG(DEBUG, "na_ble_sm_alg_f4()\n u=");
ble_hs_log_flat_buf(u, 32);
BLE_HS_LOG(DEBUG, "\n v=");
ble_hs_log_flat_buf(v, 32);
Expand All @@ -344,15 +344,15 @@ ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
* Core Spec 4.2 Vol 3 Part H 2.2.5
*
* note:
* ble_sm_alg_aes_cmac uses BE data; ble_sm_alg_f4 accepts LE so we swap.
* na_ble_sm_alg_aes_cmac uses BE data; na_ble_sm_alg_f4 accepts LE so we swap.
*/
swap_buf(m, u, 32);
swap_buf(m + 32, v, 32);
m[64] = z;

swap_buf(xs, x, 16);

rc = ble_sm_alg_aes_cmac(xs, m, sizeof(m), out_enc_data);
rc = na_ble_sm_alg_aes_cmac(xs, m, sizeof(m), out_enc_data);
if (rc != 0) {
return BLE_HS_EUNKNOWN;
}
Expand All @@ -367,7 +367,7 @@ ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
}

int
ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
na_ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
uint8_t a1t, const uint8_t *a1, uint8_t a2t, const uint8_t *a2,
uint8_t *mackey, uint8_t *ltk)
{
Expand All @@ -389,14 +389,14 @@ ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
uint8_t t[16];
int rc;

BLE_HS_LOG(DEBUG, "ble_sm_alg_f5()\n");
BLE_HS_LOG(DEBUG, "na_ble_sm_alg_f5()\n");
ble_sm_alg_log_buf("w", w, 32);
ble_sm_alg_log_buf("n1", n1, 16);
ble_sm_alg_log_buf("n2", n2, 16);

swap_buf(ws, w, 32);

rc = ble_sm_alg_aes_cmac(salt, ws, 32, t);
rc = na_ble_sm_alg_aes_cmac(salt, ws, 32, t);
if (rc != 0) {
return BLE_HS_EUNKNOWN;
}
Expand All @@ -410,7 +410,7 @@ ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
m[44] = a2t;
swap_buf(m + 45, a2, 6);

rc = ble_sm_alg_aes_cmac(t, m, sizeof(m), mackey);
rc = na_ble_sm_alg_aes_cmac(t, m, sizeof(m), mackey);
if (rc != 0) {
return BLE_HS_EUNKNOWN;
}
Expand All @@ -422,7 +422,7 @@ ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
/* Counter for ltk is 1. */
m[0] = 0x01;

rc = ble_sm_alg_aes_cmac(t, m, sizeof(m), ltk);
rc = na_ble_sm_alg_aes_cmac(t, m, sizeof(m), ltk);
if (rc != 0) {
return BLE_HS_EUNKNOWN;
}
Expand All @@ -435,7 +435,7 @@ ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
}

int
ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
na_ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
const uint8_t *r, const uint8_t *iocap, uint8_t a1t,
const uint8_t *a1, uint8_t a2t, const uint8_t *a2,
uint8_t *check)
Expand All @@ -444,7 +444,7 @@ ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
uint8_t m[65];
int rc;

BLE_HS_LOG(DEBUG, "ble_sm_alg_f6()\n");
BLE_HS_LOG(DEBUG, "na_ble_sm_alg_f6()\n");
ble_sm_alg_log_buf("w", w, 16);
ble_sm_alg_log_buf("n1", n1, 16);
ble_sm_alg_log_buf("n2", n2, 16);
Expand All @@ -470,7 +470,7 @@ ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,

swap_buf(ws, w, 16);

rc = ble_sm_alg_aes_cmac(ws, m, sizeof(m), check);
rc = na_ble_sm_alg_aes_cmac(ws, m, sizeof(m), check);
if (rc != 0) {
return BLE_HS_EUNKNOWN;
}
Expand All @@ -483,13 +483,13 @@ ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
}

int
ble_sm_alg_g2(const uint8_t *u, const uint8_t *v, const uint8_t *x,
na_ble_sm_alg_g2(const uint8_t *u, const uint8_t *v, const uint8_t *x,
const uint8_t *y, uint32_t *passkey)
{
uint8_t m[80], xs[16];
int rc;

BLE_HS_LOG(DEBUG, "ble_sm_alg_g2()\n");
BLE_HS_LOG(DEBUG, "na_ble_sm_alg_g2()\n");
ble_sm_alg_log_buf("u", u, 32);
ble_sm_alg_log_buf("v", v, 32);
ble_sm_alg_log_buf("x", x, 16);
Expand All @@ -502,7 +502,7 @@ ble_sm_alg_g2(const uint8_t *u, const uint8_t *v, const uint8_t *x,
swap_buf(xs, x, 16);

/* reuse xs (key) as buffer for result */
rc = ble_sm_alg_aes_cmac(xs, m, sizeof(m), xs);
rc = na_ble_sm_alg_aes_cmac(xs, m, sizeof(m), xs);
if (rc != 0) {
return BLE_HS_EUNKNOWN;
}
Expand Down Expand Up @@ -688,7 +688,7 @@ mbedtls_gen_keypair(uint8_t *public_key, uint8_t *private_key)
return 0;
}

void mbedtls_free_keypair(void)
void na_mbedtls_free_keypair(void)
{
mbedtls_ecp_keypair_free(&keypair);
}
Expand Down Expand Up @@ -765,7 +765,7 @@ ble_sm_alg_rand(uint8_t *dst, unsigned int size)
#endif

void
ble_sm_alg_ecc_init(void)
na_ble_sm_alg_ecc_init(void)
{
#if (!MYNEWT_VAL(BLE_CRYPTO_STACK_MBEDTLS))
uECC_set_rng(ble_sm_alg_rand);
Expand Down
6 changes: 3 additions & 3 deletions src/nimble/nimble/host/src/ble_sm_lgcy.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ ble_sm_lgcy_confirm_exec(struct ble_sm_proc *proc, struct ble_sm_result *res)

ble_sm_ia_ra(proc, &iat, ia, &rat, ra);

rc = ble_sm_alg_c1(proc->tk, ble_sm_our_pair_rand(proc), proc->pair_req,
rc = na_ble_sm_alg_c1(proc->tk, ble_sm_our_pair_rand(proc), proc->pair_req,
proc->pair_rsp, iat, rat, ia, ra, cmd->value);
if (rc != 0) {
goto err;
Expand Down Expand Up @@ -160,7 +160,7 @@ ble_sm_gen_stk(struct ble_sm_proc *proc)
uint8_t key[16];
int rc;

rc = ble_sm_alg_s1(proc->tk, proc->rands, proc->randm, key);
rc = na_ble_sm_alg_s1(proc->tk, proc->rands, proc->randm, key);
if (rc != 0) {
return rc;
}
Expand Down Expand Up @@ -215,7 +215,7 @@ ble_sm_lgcy_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)

ble_sm_ia_ra(proc, &iat, ia, &rat, ra);

rc = ble_sm_alg_c1(proc->tk, ble_sm_peer_pair_rand(proc), proc->pair_req,
rc = na_ble_sm_alg_c1(proc->tk, ble_sm_peer_pair_rand(proc), proc->pair_req,
proc->pair_rsp, iat, rat, ia, ra, confirm_val);
if (rc != 0) {
res->app_status = rc;
Expand Down
22 changes: 11 additions & 11 deletions src/nimble/nimble/host/src/ble_sm_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,29 +301,29 @@ void ble_sm_dbg_set_sc_keys(uint8_t *pubkey, uint8_t *privkey);

int ble_sm_num_procs(void);

int ble_sm_alg_s1(const uint8_t *k, const uint8_t *r1, const uint8_t *r2,
int na_ble_sm_alg_s1(const uint8_t *k, const uint8_t *r1, const uint8_t *r2,
uint8_t *out);
int ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,
int na_ble_sm_alg_c1(const uint8_t *k, const uint8_t *r,
const uint8_t *preq, const uint8_t *pres,
uint8_t iat, uint8_t rat,
const uint8_t *ia, const uint8_t *ra,
uint8_t *out_enc_data);
int ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
int na_ble_sm_alg_f4(const uint8_t *u, const uint8_t *v, const uint8_t *x,
uint8_t z, uint8_t *out_enc_data);
int ble_sm_alg_g2(const uint8_t *u, const uint8_t *v, const uint8_t *x,
int na_ble_sm_alg_g2(const uint8_t *u, const uint8_t *v, const uint8_t *x,
const uint8_t *y, uint32_t *passkey);
int ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
int na_ble_sm_alg_f5(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
uint8_t a1t, const uint8_t *a1, uint8_t a2t,
const uint8_t *a2, uint8_t *mackey, uint8_t *ltk);
int ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
int na_ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
const uint8_t *r, const uint8_t *iocap, uint8_t a1t,
const uint8_t *a1, uint8_t a2t, const uint8_t *a2,
uint8_t *check);
int ble_sm_alg_gen_dhkey(const uint8_t *peer_pub_key_x,
const uint8_t *peer_pub_key_y,
const uint8_t *our_priv_key, uint8_t *out_dhkey);
int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv);
void ble_sm_alg_ecc_init(void);
void na_ble_sm_alg_ecc_init(void);

void ble_sm_enc_change_rx(const struct ble_hci_ev_enrypt_chg *ev);
void ble_sm_enc_key_refresh_rx(const struct ble_hci_ev_enc_key_refresh *ev);
Expand Down Expand Up @@ -395,7 +395,7 @@ void ble_sm_ia_ra(struct ble_sm_proc *proc,

int ble_sm_incr_our_sign_counter(uint16_t conn_handle);
int ble_sm_incr_peer_sign_counter(uint16_t conn_handle);
int ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
int na_ble_sm_alg_aes_cmac(const uint8_t *key, const uint8_t *in, size_t len,
uint8_t *out);
int32_t ble_sm_timer(void);
void ble_sm_connection_broken(uint16_t conn_handle);
Expand All @@ -404,14 +404,14 @@ int ble_sm_slave_initiate(uint16_t conn_handle);
int ble_sm_enc_initiate(uint16_t conn_handle, uint8_t key_size,
const uint8_t *ltk, uint16_t ediv,
uint64_t rand_val, int auth);
int ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
int na_ble_sm_alg_encrypt(const uint8_t *key, const uint8_t *plaintext,
uint8_t *enc_data);
int ble_sm_init(void);
#else

#define ble_sm_incr_our_sign_counter(conn_handle) BLE_HS_ENOTSUP
#define ble_sm_incr_peer_sign_counter(conn_handle) BLE_HS_ENOTSUP
#define ble_sm_alg_aes_cmac(key, in, len, out) BLE_HS_ENOTSUP
#define na_ble_sm_alg_aes_cmac(key, in, len, out) BLE_HS_ENOTSUP
#define ble_sm_enc_change_rx(evt) ((void)(evt))
#define ble_sm_ltk_req_rx(evt) ((void)(evt))
#define ble_sm_enc_key_refresh_rx(evt) ((void)(evt))
Expand All @@ -425,7 +425,7 @@ int ble_sm_init(void);

#define ble_sm_init() 0

#define ble_sm_alg_encrypt(key, plaintext, enc_data) \
#define na_ble_sm_alg_encrypt(key, plaintext, enc_data) \
BLE_HS_ENOTSUP

#endif
Expand Down
Loading