mesh: Normalize endian of public/private ECC keys
authorBrian Gix <brian.gix@intel.com>
Tue, 18 May 2021 23:23:39 +0000 (16:23 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 11 Mar 2022 13:38:35 +0000 (19:08 +0530)
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.

Signed-off-by: Anuj Jain <anuj01.jain@samsung.com>
Signed-off-by: Ayush Garg <ayush.garg@samsung.com>
mesh/prov-acceptor.c
mesh/prov-initiator.c

index e806b12..0dbb84f 100644 (file)
@@ -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);
 
index ae9c646..c625775 100644 (file)
@@ -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));