Bluetooth: Add check for accidentally generating a debug key
authorJohan Hedberg <johan.hedberg@intel.com>
Fri, 6 Jun 2014 12:33:30 +0000 (15:33 +0300)
committerMarcel Holtmann <marcel@holtmann.org>
Wed, 3 Dec 2014 15:51:18 +0000 (16:51 +0100)
It is very unlikely, but to have a 100% guarantee of the generated key
type we need to reject any keys which happen to match the debug key.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
net/bluetooth/smp.c

index ddc76cf..63d5ba7 100644 (file)
@@ -1399,9 +1399,17 @@ static u8 sc_send_public_key(struct smp_chan *smp)
 {
        BT_DBG("");
 
-       /* Generate local key pair for Secure Connections */
-       if (!ecc_make_key(smp->local_pk, smp->local_sk))
-               return SMP_UNSPECIFIED;
+       while (true) {
+               /* Generate local key pair for Secure Connections */
+               if (!ecc_make_key(smp->local_pk, smp->local_sk))
+                       return SMP_UNSPECIFIED;
+
+               /* This is unlikely, but we need to check that we didn't
+                * accidentially generate a debug key.
+                */
+               if (memcmp(smp->local_sk, debug_sk, 32))
+                       break;
+       }
 
        BT_DBG("Local Public Key X: %32phN", smp->local_pk);
        BT_DBG("Local Public Key Y: %32phN", &smp->local_pk[32]);