smp.c (3a37471551cd3b287ce7f02ed25bcf8ec37a191d) smp.c (58771c1cb0023fdd744e76d6cad7716dc4f579ee)
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation;
8

--- 17 unchanged lines hidden (view full) ---

26#include <crypto/b128ops.h>
27#include <crypto/hash.h>
28
29#include <net/bluetooth/bluetooth.h>
30#include <net/bluetooth/hci_core.h>
31#include <net/bluetooth/l2cap.h>
32#include <net/bluetooth/mgmt.h>
33
1/*
2 BlueZ - Bluetooth protocol stack for Linux
3 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation;
8

--- 17 unchanged lines hidden (view full) ---

26#include <crypto/b128ops.h>
27#include <crypto/hash.h>
28
29#include <net/bluetooth/bluetooth.h>
30#include <net/bluetooth/hci_core.h>
31#include <net/bluetooth/l2cap.h>
32#include <net/bluetooth/mgmt.h>
33
34#include "ecc.h"
34#include "ecdh_helper.h"
35#include "smp.h"
36
37#define SMP_DEV(hdev) \
38 ((struct smp_dev *)((struct l2cap_chan *)((hdev)->smp_data))->data)
39
40/* Low-level debug macros to be used for stuff that we don't want
41 * accidentially in dmesg, i.e. the values of the various crypto keys
42 * and the inputs & outputs of crypto functions.

--- 522 unchanged lines hidden (view full) ---

565 if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) {
566 BT_DBG("Using debug keys");
567 memcpy(smp->local_pk, debug_pk, 64);
568 memcpy(smp->local_sk, debug_sk, 32);
569 smp->debug_key = true;
570 } else {
571 while (true) {
572 /* Generate local key pair for Secure Connections */
35#include "smp.h"
36
37#define SMP_DEV(hdev) \
38 ((struct smp_dev *)((struct l2cap_chan *)((hdev)->smp_data))->data)
39
40/* Low-level debug macros to be used for stuff that we don't want
41 * accidentially in dmesg, i.e. the values of the various crypto keys
42 * and the inputs & outputs of crypto functions.

--- 522 unchanged lines hidden (view full) ---

565 if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) {
566 BT_DBG("Using debug keys");
567 memcpy(smp->local_pk, debug_pk, 64);
568 memcpy(smp->local_sk, debug_sk, 32);
569 smp->debug_key = true;
570 } else {
571 while (true) {
572 /* Generate local key pair for Secure Connections */
573 if (!ecc_make_key(smp->local_pk, smp->local_sk))
573 if (!generate_ecdh_keys(smp->local_pk, smp->local_sk))
574 return -EIO;
575
576 /* This is unlikely, but we need to check that
577 * we didn't accidentially generate a debug key.
578 */
579 if (memcmp(smp->local_sk, debug_sk, 32))
580 break;
581 }

--- 1309 unchanged lines hidden (view full) ---

1891 if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) {
1892 BT_DBG("Using debug keys");
1893 memcpy(smp->local_pk, debug_pk, 64);
1894 memcpy(smp->local_sk, debug_sk, 32);
1895 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags);
1896 } else {
1897 while (true) {
1898 /* Generate local key pair for Secure Connections */
574 return -EIO;
575
576 /* This is unlikely, but we need to check that
577 * we didn't accidentially generate a debug key.
578 */
579 if (memcmp(smp->local_sk, debug_sk, 32))
580 break;
581 }

--- 1309 unchanged lines hidden (view full) ---

1891 if (hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) {
1892 BT_DBG("Using debug keys");
1893 memcpy(smp->local_pk, debug_pk, 64);
1894 memcpy(smp->local_sk, debug_sk, 32);
1895 set_bit(SMP_FLAG_DEBUG_KEY, &smp->flags);
1896 } else {
1897 while (true) {
1898 /* Generate local key pair for Secure Connections */
1899 if (!ecc_make_key(smp->local_pk, smp->local_sk))
1899 if (!generate_ecdh_keys(smp->local_pk, smp->local_sk))
1900 return SMP_UNSPECIFIED;
1901
1902 /* This is unlikely, but we need to check that
1903 * we didn't accidentially generate a debug key.
1904 */
1905 if (memcmp(smp->local_sk, debug_sk, 32))
1906 break;
1907 }

--- 757 unchanged lines hidden (view full) ---

2665 err = sc_send_public_key(smp);
2666 if (err)
2667 return err;
2668 }
2669
2670 SMP_DBG("Remote Public Key X: %32phN", smp->remote_pk);
2671 SMP_DBG("Remote Public Key Y: %32phN", smp->remote_pk + 32);
2672
1900 return SMP_UNSPECIFIED;
1901
1902 /* This is unlikely, but we need to check that
1903 * we didn't accidentially generate a debug key.
1904 */
1905 if (memcmp(smp->local_sk, debug_sk, 32))
1906 break;
1907 }

--- 757 unchanged lines hidden (view full) ---

2665 err = sc_send_public_key(smp);
2666 if (err)
2667 return err;
2668 }
2669
2670 SMP_DBG("Remote Public Key X: %32phN", smp->remote_pk);
2671 SMP_DBG("Remote Public Key Y: %32phN", smp->remote_pk + 32);
2672
2673 if (!ecdh_shared_secret(smp->remote_pk, smp->local_sk, smp->dhkey))
2673 if (!compute_ecdh_secret(smp->remote_pk, smp->local_sk, smp->dhkey))
2674 return SMP_UNSPECIFIED;
2675
2676 SMP_DBG("DHKey %32phN", smp->dhkey);
2677
2678 set_bit(SMP_FLAG_REMOTE_PK, &smp->flags);
2679
2680 smp->method = sc_select_method(smp);
2681

--- 1154 unchanged lines hidden ---
2674 return SMP_UNSPECIFIED;
2675
2676 SMP_DBG("DHKey %32phN", smp->dhkey);
2677
2678 set_bit(SMP_FLAG_REMOTE_PK, &smp->flags);
2679
2680 smp->method = sc_select_method(smp);
2681

--- 1154 unchanged lines hidden ---