mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-09-14 21:20:06 +00:00
Revert "nimble/host: Fix build with new TinyCrypt"
This reverts commit d5d0082168a02401c63b83eed65dac3a5e5348c0. X-Original-Commit: c173f788344f150e155750e98c67005099f08479
This commit is contained in:
@@ -413,36 +413,31 @@ ble_sm_alg_g2(uint8_t *u, uint8_t *v, uint8_t *x, uint8_t *y,
|
||||
|
||||
int
|
||||
ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
|
||||
uint8_t *our_priv_key, uint8_t *out_dhkey)
|
||||
uint32_t *our_priv_key, void *out_dhkey)
|
||||
{
|
||||
uint8_t dh[32];
|
||||
uint8_t pk[64];
|
||||
uint8_t priv[32];
|
||||
int rc;
|
||||
uint32_t dh[8];
|
||||
EccPoint pk;
|
||||
|
||||
swap_buf(pk, peer_pub_key_x, 32);
|
||||
swap_buf(&pk[32], peer_pub_key_y, 32);
|
||||
swap_buf(priv, our_priv_key, 32);
|
||||
memcpy(pk.x, peer_pub_key_x, 32);
|
||||
memcpy(pk.y, peer_pub_key_y, 32);
|
||||
|
||||
if (uECC_valid_public_key(pk, &curve_secp256r1) < 0) {
|
||||
if (ecc_valid_public_key(&pk) < 0) {
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
rc = uECC_shared_secret(pk, priv, dh, &curve_secp256r1);
|
||||
if (rc == TC_CRYPTO_FAIL) {
|
||||
if (ecdh_shared_secret(dh, &pk, our_priv_key) == TC_CRYPTO_FAIL) {
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
swap_buf(out_dhkey, dh, 32);
|
||||
memcpy(out_dhkey, dh, 32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* based on Core Specification 4.2 Vol 3. Part H 2.3.5.6.1 */
|
||||
static const uint8_t ble_sm_alg_dbg_priv_key[32] = {
|
||||
0x3f, 0x49, 0xf6, 0xd4, 0xa3, 0xc5, 0x5f, 0x38, 0x74, 0xc9, 0xb3, 0xe3,
|
||||
0xd2, 0x10, 0x3f, 0x50, 0x4a, 0xff, 0x60, 0x7b, 0xeb, 0x40, 0xb7, 0x99,
|
||||
0x58, 0x99, 0xb8, 0xa6, 0xcd, 0x3c, 0x1a, 0xbd
|
||||
static const uint32_t ble_sm_alg_dbg_priv_key[8] = {
|
||||
0xcd3c1abd, 0x5899b8a6, 0xeb40b799, 0x4aff607b, 0xd2103f50, 0x74c9b3e3,
|
||||
0xa3c55f38, 0x3f49f6d4
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -450,35 +445,31 @@ static const uint8_t ble_sm_alg_dbg_priv_key[32] = {
|
||||
* priv: 32 bytes
|
||||
*/
|
||||
int
|
||||
ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv)
|
||||
ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv)
|
||||
{
|
||||
uint8_t pk[64];
|
||||
uint32_t random[16];
|
||||
EccPoint pkey;
|
||||
int rc;
|
||||
|
||||
do {
|
||||
if (uECC_make_key(pk, priv, &curve_secp256r1) != TC_CRYPTO_SUCCESS) {
|
||||
rc = ble_hs_hci_util_rand(random, sizeof random);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = ecc_make_key(&pkey, priv, random);
|
||||
if (rc != TC_CRYPTO_SUCCESS) {
|
||||
return BLE_HS_EUNKNOWN;
|
||||
}
|
||||
|
||||
/* Make sure generated key isn't debug key. */
|
||||
} while (memcmp(priv, ble_sm_alg_dbg_priv_key, 32) == 0);
|
||||
|
||||
swap_buf(pub, pk, 32);
|
||||
swap_buf(&pub[32], &pk[32], 32);
|
||||
swap_in_place(priv, 32);
|
||||
memcpy(pub + 0, pkey.x, 32);
|
||||
memcpy(pub + 32, pkey.y, 32);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* used by uECC to get random data */
|
||||
int
|
||||
default_CSPRNG(uint8_t *dst, unsigned int size)
|
||||
{
|
||||
if (ble_hs_hci_util_rand(dst, size)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -325,8 +325,8 @@ int ble_sm_alg_f6(const uint8_t *w, const uint8_t *n1, const uint8_t *n2,
|
||||
const uint8_t *a1, uint8_t a2t, const uint8_t *a2,
|
||||
uint8_t *check);
|
||||
int ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
|
||||
uint8_t *our_priv_key, uint8_t *out_dhkey);
|
||||
int ble_sm_alg_gen_key_pair(uint8_t *pub, uint8_t *priv);
|
||||
uint32_t *our_priv_key, void *out_dhkey);
|
||||
int ble_sm_alg_gen_key_pair(void *pub, uint32_t *priv);
|
||||
|
||||
void ble_sm_enc_change_rx(struct hci_encrypt_change *evt);
|
||||
void ble_sm_enc_key_refresh_rx(struct hci_encrypt_key_refresh *evt);
|
||||
|
||||
+23
-11
@@ -29,8 +29,19 @@
|
||||
#define BLE_SM_SC_PASSKEY_BYTES 4
|
||||
#define BLE_SM_SC_PASSKEY_BITS 20
|
||||
|
||||
static uint8_t ble_sm_sc_pub_key[64];
|
||||
static uint8_t ble_sm_sc_priv_key[32];
|
||||
/**
|
||||
* The public and private keys are stored in unions. Some crypto functions
|
||||
* accept pointers to uint32_t; others accept pointers to uint8_t. The use of
|
||||
* unions ensures the keys are properly aligned for pointers to uint32_t.
|
||||
*/
|
||||
static union {
|
||||
uint32_t u32[16];
|
||||
uint8_t u8[64];
|
||||
} ble_sm_sc_pub_key;
|
||||
static union {
|
||||
uint32_t u32[8];
|
||||
uint8_t u8[32];
|
||||
} ble_sm_sc_priv_key;
|
||||
|
||||
/**
|
||||
* Whether our public-private key pair has been generated. We generate it on
|
||||
@@ -150,7 +161,7 @@ ble_sm_sc_io_action(struct ble_sm_proc *proc, uint8_t *action)
|
||||
}
|
||||
|
||||
static int
|
||||
ble_sm_gen_pub_priv(uint8_t *pub, uint8_t *priv)
|
||||
ble_sm_gen_pub_priv(void *pub, uint32_t *priv)
|
||||
{
|
||||
int rc;
|
||||
|
||||
@@ -177,7 +188,8 @@ ble_sm_sc_ensure_keys_generated(void)
|
||||
int rc;
|
||||
|
||||
if (!ble_sm_sc_keys_generated) {
|
||||
rc = ble_sm_gen_pub_priv(ble_sm_sc_pub_key, ble_sm_sc_priv_key);
|
||||
rc = ble_sm_gen_pub_priv(ble_sm_sc_pub_key.u32,
|
||||
ble_sm_sc_priv_key.u32);
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
@@ -287,7 +299,7 @@ ble_sm_sc_confirm_exec(struct ble_sm_proc *proc, struct ble_sm_result *res)
|
||||
return;
|
||||
}
|
||||
|
||||
rc = ble_sm_alg_f4(ble_sm_sc_pub_key, proc->pub_key_peer.x,
|
||||
rc = ble_sm_alg_f4(ble_sm_sc_pub_key.u8, proc->pub_key_peer.x,
|
||||
ble_sm_our_pair_rand(proc), proc->ri, cmd->value);
|
||||
if (rc != 0) {
|
||||
os_mbuf_free_chain(txom);
|
||||
@@ -317,11 +329,11 @@ ble_sm_sc_gen_numcmp(struct ble_sm_proc *proc, struct ble_sm_result *res)
|
||||
uint8_t *pkb;
|
||||
|
||||
if (proc->flags & BLE_SM_PROC_F_INITIATOR) {
|
||||
pka = ble_sm_sc_pub_key;
|
||||
pka = ble_sm_sc_pub_key.u8;
|
||||
pkb = proc->pub_key_peer.x;
|
||||
} else {
|
||||
pka = proc->pub_key_peer.x;
|
||||
pkb = ble_sm_sc_pub_key;
|
||||
pkb = ble_sm_sc_pub_key.u8;
|
||||
}
|
||||
res->app_status = ble_sm_alg_g2(pka, pkb, proc->randm, proc->rands,
|
||||
&res->passkey_params.numcmp);
|
||||
@@ -421,7 +433,7 @@ ble_sm_sc_random_rx(struct ble_sm_proc *proc, struct ble_sm_result *res)
|
||||
ble_hs_log_flat_buf(proc->tk, 16);
|
||||
BLE_HS_LOG(DEBUG, "\n");
|
||||
|
||||
rc = ble_sm_alg_f4(proc->pub_key_peer.x, ble_sm_sc_pub_key,
|
||||
rc = ble_sm_alg_f4(proc->pub_key_peer.x, ble_sm_sc_pub_key.u8,
|
||||
ble_sm_peer_pair_rand(proc), proc->ri,
|
||||
confirm_val);
|
||||
if (rc != 0) {
|
||||
@@ -513,8 +525,8 @@ ble_sm_sc_public_key_exec(struct ble_sm_proc *proc, struct ble_sm_result *res,
|
||||
return;
|
||||
}
|
||||
|
||||
memcpy(cmd->x, ble_sm_sc_pub_key + 0, 32);
|
||||
memcpy(cmd->y, ble_sm_sc_pub_key + 32, 32);
|
||||
memcpy(cmd->x, ble_sm_sc_pub_key.u8 + 0, 32);
|
||||
memcpy(cmd->y, ble_sm_sc_pub_key.u8 + 32, 32);
|
||||
|
||||
res->app_status = ble_sm_tx(proc->conn_handle, txom);
|
||||
if (res->app_status != 0) {
|
||||
@@ -579,7 +591,7 @@ ble_sm_sc_public_key_rx(uint16_t conn_handle, struct os_mbuf **om,
|
||||
memcpy(&proc->pub_key_peer, cmd, sizeof(*cmd));
|
||||
rc = ble_sm_alg_gen_dhkey(proc->pub_key_peer.x,
|
||||
proc->pub_key_peer.y,
|
||||
ble_sm_sc_priv_key,
|
||||
ble_sm_sc_priv_key.u32,
|
||||
proc->dhkey);
|
||||
if (rc != 0) {
|
||||
res->app_status = BLE_HS_SM_US_ERR(BLE_SM_ERR_DHKEY);
|
||||
|
||||
Reference in New Issue
Block a user