summaryrefslogtreecommitdiff
path: root/mesh
diff options
context:
space:
mode:
authorBrian Gix <brian.gix@intel.com>2021-05-18 16:23:39 -0700
committerBrian Gix <brian.gix@intel.com>2021-05-19 12:54:40 -0700
commit9fd05a6eaea872d210cff214f36ce18f470bcf47 (patch)
treef1eef9d6464e8b607d9d2dd9e2332e4a30450324 /mesh
parent01404f570c67281b49cc6da6e3f9331309c3c9a2 (diff)
downloadbluez-9fd05a6eaea872d210cff214f36ce18f470bcf47.tar.gz
mesh: Normalize endian of public/private ECC keys
The Mesh profile specification defines a Mesh byte order of Big Endian for Public keys used to calculate shared secrets. Further the specification sample data also show this same byte order for Private keys. However, our internal ECDH shared secret calculation requires Little Endian byte ordering. This fixes our DBus interface, and debugging output to use Mesh Byte Ordering (Big Endian) for all human readable input/output.
Diffstat (limited to 'mesh')
-rw-r--r--mesh/prov-acceptor.c8
-rw-r--r--mesh/prov-initiator.c3
2 files changed, 10 insertions, 1 deletions
diff --git a/mesh/prov-acceptor.c b/mesh/prov-acceptor.c
index e806b12ef..0dbb84f50 100644
--- a/mesh/prov-acceptor.c
+++ b/mesh/prov-acceptor.c
@@ -223,7 +223,11 @@ static bool acp_credentials(struct mesh_prov_acceptor *prov)
print_packet("PublicKeyProv", prov->conf_inputs.prv_pub_key, 64);
print_packet("PublicKeyDev", prov->conf_inputs.dev_pub_key, 64);
+
+ /* Normalize for debug out -- No longer needed for calculations */
+ swap_u256_bytes(prov->private_key);
print_packet("PrivateKeyLocal", prov->private_key, 32);
+
print_packet("ConfirmationInputs", &prov->conf_inputs,
sizeof(prov->conf_inputs));
print_packet("ECDHSecret", prov->secret, 32);
@@ -307,11 +311,13 @@ static void priv_key_cb(void *user_data, int err, uint8_t *key, uint32_t len)
return;
}
+ /* API delivers Mesh byte order, switch to little endian */
+ swap_u256_bytes(key);
memcpy(prov->private_key, key, 32);
ecc_make_public_key(prov->private_key,
prov->conf_inputs.dev_pub_key);
- /* Convert to Mesh byte order */
+ /* Convert Public key to Mesh byte order */
swap_u256_bytes(prov->conf_inputs.dev_pub_key);
swap_u256_bytes(prov->conf_inputs.dev_pub_key + 32);
diff --git a/mesh/prov-initiator.c b/mesh/prov-initiator.c
index ae9c646de..c62577523 100644
--- a/mesh/prov-initiator.c
+++ b/mesh/prov-initiator.c
@@ -222,6 +222,9 @@ static bool int_credentials(struct mesh_prov_initiator *prov)
print_packet("PublicKeyProv", prov->conf_inputs.prv_pub_key, 64);
print_packet("PublicKeyDev", prov->conf_inputs.dev_pub_key, 64);
+
+ /* Print DBG out in Mesh order */
+ swap_u256_bytes(prov->private_key);
print_packet("PrivateKeyLocal", prov->private_key, 32);
print_packet("ConfirmationInputs", &prov->conf_inputs,
sizeof(prov->conf_inputs));