linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/5] Bluetooth: Add SMP self-tests through debugfs
@ 2014-12-29 10:04 Johan Hedberg
  2014-12-29 10:04 ` [PATCH 1/5] Bluetooth: Fix const declarations for smp_f5 and smp_f6 Johan Hedberg
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Johan Hedberg @ 2014-12-29 10:04 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

Here's yet another attempt at introducing the SMP self-tests. The
objection to the separate module approach was the need to always export
the low-level SMP crypto functions. This set of patches takes a
different approach by triggering the tests through debugfs. This way
only two new bt_smp_init & bt_smp_exit function need to be exposed from
smp.c. And before anyone asks, the extra bt_ prefix is because there's
otherwise a conflict with another already existing "smp_init" function
in the kernel.

Once enabled the new tests can be run by issuing the following command:

	cat /sys/kernel/debug/bluetooth/smp_selftest

Johan

----------------------------------------------------------------
Johan Hedberg (5):
      Bluetooth: Fix const declarations for smp_f5 and smp_f6
      Bluetooth: Add skeleton for debugfs-based SMP self-tests
      Bluetooth: Add SMP self-tests for legacy crypto functions
      Bluetooth: Add SMP self-tests for SC crypto functions
      Bluetooth: Add SMP self-tests for ECDH functionality

 include/net/bluetooth/bluetooth.h |   3 +
 net/bluetooth/Kconfig             |   9 +
 net/bluetooth/af_bluetooth.c      |   4 +
 net/bluetooth/smp.c               | 520 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 533 insertions(+), 3 deletions(-)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] Bluetooth: Fix const declarations for smp_f5 and smp_f6
  2014-12-29 10:04 [PATCH 0/5] Bluetooth: Add SMP self-tests through debugfs Johan Hedberg
@ 2014-12-29 10:04 ` Johan Hedberg
  2014-12-30  6:30   ` Marcel Holtmann
  2014-12-29 10:04 ` [PATCH 2/5] Bluetooth: Add skeleton for debugfs-based SMP self-tests Johan Hedberg
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Johan Hedberg @ 2014-12-29 10:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

These SMP crypto functions should have all their input parameters
declared as const. This patch fixes the parameters that were missing the
const declaration.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index b67749bb55bf..9025e177d278 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -223,8 +223,9 @@ static int smp_f4(struct crypto_hash *tfm_cmac, const u8 u[32], const u8 v[32],
 	return err;
 }
 
-static int smp_f5(struct crypto_hash *tfm_cmac, u8 w[32], u8 n1[16], u8 n2[16],
-		  u8 a1[7], u8 a2[7], u8 mackey[16], u8 ltk[16])
+static int smp_f5(struct crypto_hash *tfm_cmac, const u8 w[32],
+		  const u8 n1[16], const u8 n2[16], const u8 a1[7],
+		  const u8 a2[7], u8 mackey[16], u8 ltk[16])
 {
 	/* The btle, salt and length "magic" values are as defined in
 	 * the SMP section of the Bluetooth core specification. In ASCII
@@ -276,7 +277,7 @@ static int smp_f5(struct crypto_hash *tfm_cmac, u8 w[32], u8 n1[16], u8 n2[16],
 }
 
 static int smp_f6(struct crypto_hash *tfm_cmac, const u8 w[16],
-		  const u8 n1[16], u8 n2[16], const u8 r[16],
+		  const u8 n1[16], const u8 n2[16], const u8 r[16],
 		  const u8 io_cap[3], const u8 a1[7], const u8 a2[7],
 		  u8 res[16])
 {
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/5] Bluetooth: Add skeleton for debugfs-based SMP self-tests
  2014-12-29 10:04 [PATCH 0/5] Bluetooth: Add SMP self-tests through debugfs Johan Hedberg
  2014-12-29 10:04 ` [PATCH 1/5] Bluetooth: Fix const declarations for smp_f5 and smp_f6 Johan Hedberg
@ 2014-12-29 10:04 ` Johan Hedberg
  2014-12-29 10:04 ` [PATCH 3/5] Bluetooth: Add SMP self-tests for legacy crypto functions Johan Hedberg
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2014-12-29 10:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds the basic initialization and cleanup of a selftest file
in debugfs to be used for triggering SMP self-tests. This is an
alternative approach to the independent module one which doesn't require
exporting the SMP crypto functions anywhere.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 include/net/bluetooth/bluetooth.h |  3 ++
 net/bluetooth/Kconfig             |  9 +++++
 net/bluetooth/af_bluetooth.c      |  4 ++
 net/bluetooth/smp.c               | 77 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 93 insertions(+)

diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
index 58695ffeb138..35a08cfed113 100644
--- a/include/net/bluetooth/bluetooth.h
+++ b/include/net/bluetooth/bluetooth.h
@@ -358,6 +358,9 @@ void l2cap_exit(void);
 int sco_init(void);
 void sco_exit(void);
 
+void bt_smp_init(void);
+void bt_smp_exit(void);
+
 void bt_sock_reclassify_lock(struct sock *sk, int proto);
 
 #endif /* __BLUETOOTH_H */
diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig
index 29bcafc41adf..af6a827b2d96 100644
--- a/net/bluetooth/Kconfig
+++ b/net/bluetooth/Kconfig
@@ -64,4 +64,13 @@ config BT_6LOWPAN
 	help
 	  IPv6 compression over Bluetooth Low Energy.
 
+config BT_SELFTEST
+        bool "Include self-tests that can be triggered through debugfs"
+        depends on BT_LE && DEBUG_KERNEL
+        help
+          This option creates debugfs files that can be used to trigger
+	  various self-tests. For now this is limited to SMP which will
+	  expose a smp_selftest file. To run the tests simply do a
+	  'cat smp_selftest' which will then print the result.
+
 source "drivers/bluetooth/Kconfig"
diff --git a/net/bluetooth/af_bluetooth.c b/net/bluetooth/af_bluetooth.c
index 012e3b03589d..e735b838d2df 100644
--- a/net/bluetooth/af_bluetooth.c
+++ b/net/bluetooth/af_bluetooth.c
@@ -744,6 +744,8 @@ static int __init bt_init(void)
 		goto sock_err;
 	}
 
+	bt_smp_init();
+
 	return 0;
 
 sock_err:
@@ -758,6 +760,8 @@ error:
 
 static void __exit bt_exit(void)
 {
+	bt_smp_exit();
+
 	sco_exit();
 
 	l2cap_exit();
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 9025e177d278..79af975e83ab 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -23,6 +23,7 @@
 #include <linux/crypto.h>
 #include <linux/scatterlist.h>
 #include <crypto/b128ops.h>
+#include <linux/debugfs.h>
 
 #include <net/bluetooth/bluetooth.h>
 #include <net/bluetooth/hci_core.h>
@@ -3022,3 +3023,79 @@ void smp_unregister(struct hci_dev *hdev)
 		smp_del_chan(chan);
 	}
 }
+
+#ifdef CONFIG_BT_SELFTEST
+
+static int run_selftests(struct seq_file *f, struct crypto_blkcipher *tfm_aes,
+			 struct crypto_hash *tfm_cmac)
+{
+	return 0;
+}
+
+static int smp_selftest_show(struct seq_file *f, void *p)
+{
+	struct crypto_blkcipher *tfm_aes;
+	struct crypto_hash *tfm_cmac;
+	int err;
+
+	tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC);
+	if (IS_ERR(tfm_aes)) {
+		seq_printf(f, "Unable to create ECB crypto context\n");
+		return 0;
+	}
+
+	tfm_cmac = crypto_alloc_hash("cmac(aes)", 0, CRYPTO_ALG_ASYNC);
+	if (IS_ERR(tfm_cmac)) {
+		seq_printf(f, "Unable to create CMAC crypto context\n");
+		crypto_free_blkcipher(tfm_aes);
+		return 0;
+	}
+
+	err = run_selftests(f, tfm_aes, tfm_cmac);
+	if (err < 0)
+		seq_printf(f, "Self tests failed\n");
+	else
+		seq_printf(f, "Self-tests passed\n");
+
+	crypto_free_hash(tfm_cmac);
+	crypto_free_blkcipher(tfm_aes);
+
+	return 0;
+}
+
+static int smp_selftest_open(struct inode *inode, struct file *file)
+{
+	return single_open(file, smp_selftest_show, inode->i_private);
+}
+
+static const struct file_operations smp_selftest_fops = {
+	.open		= smp_selftest_open,
+	.read		= seq_read,
+	.llseek		= seq_lseek,
+	.release	= single_release,
+};
+
+static struct dentry *smp_debugfs;
+
+void __init bt_smp_init(void)
+{
+	smp_debugfs = debugfs_create_file("smp_selftest", 0444, bt_debugfs,
+					    NULL, &smp_selftest_fops);
+}
+
+void bt_smp_exit(void)
+{
+	debugfs_remove(smp_debugfs);
+}
+
+#else
+
+void __init bt_smp_init(void)
+{
+}
+
+void bt_smp_exit(void)
+{
+}
+
+#endif /* CONFIG_BT_SELFTEST */
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/5] Bluetooth: Add SMP self-tests for legacy crypto functions
  2014-12-29 10:04 [PATCH 0/5] Bluetooth: Add SMP self-tests through debugfs Johan Hedberg
  2014-12-29 10:04 ` [PATCH 1/5] Bluetooth: Fix const declarations for smp_f5 and smp_f6 Johan Hedberg
  2014-12-29 10:04 ` [PATCH 2/5] Bluetooth: Add skeleton for debugfs-based SMP self-tests Johan Hedberg
@ 2014-12-29 10:04 ` Johan Hedberg
  2014-12-29 10:04 ` [PATCH 4/5] Bluetooth: Add SMP self-tests for SC " Johan Hedberg
  2014-12-29 10:04 ` [PATCH 5/5] Bluetooth: Add SMP self-tests for ECDH functionality Johan Hedberg
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2014-12-29 10:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds self-tests for the legacy (non-Secure Connections) SMP
crypto functions. The sample data has been taken from the core
specification.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 79af975e83ab..e4d6ae5028f5 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -3026,9 +3026,104 @@ void smp_unregister(struct hci_dev *hdev)
 
 #ifdef CONFIG_BT_SELFTEST
 
+static int test_ah(struct crypto_blkcipher *tfm_aes)
+{
+	const u8 const irk[16] = {
+			0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
+			0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec };
+	const u8 const r[3] = { 0x94, 0x81, 0x70 };
+	const u8 const exp[3] = { 0xaa, 0xfb, 0x0d };
+	u8 res[3];
+	int err;
+
+	err = smp_ah(tfm_aes, irk, r, res);
+	if (err)
+		return err;
+
+	if (memcmp(res, exp, 3) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int test_c1(struct crypto_blkcipher *tfm_aes)
+{
+	const u8 const k[16] = {
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+	const u8 const r[16] = {
+			0xe0, 0x2e, 0x70, 0xc6, 0x4e, 0x27, 0x88, 0x63,
+			0x0e, 0x6f, 0xad, 0x56, 0x21, 0xd5, 0x83, 0x57 };
+	const u8 const preq[7] = { 0x01, 0x01, 0x00, 0x00, 0x10, 0x07, 0x07 };
+	const u8 const pres[7] = { 0x02, 0x03, 0x00, 0x00, 0x08, 0x00, 0x05 };
+	const u8 _iat = 0x01;
+	const u8 _rat = 0x00;
+	const bdaddr_t ra = { { 0xb6, 0xb5, 0xb4, 0xb3, 0xb2, 0xb1 } };
+	const bdaddr_t ia = { { 0xa6, 0xa5, 0xa4, 0xa3, 0xa2, 0xa1 } };
+	const u8 const exp[16] = {
+			0x86, 0x3b, 0xf1, 0xbe, 0xc5, 0x4d, 0xa7, 0xd2,
+			0xea, 0x88, 0x89, 0x87, 0xef, 0x3f, 0x1e, 0x1e };
+	u8 res[16];
+	int err;
+
+	err = smp_c1(tfm_aes, k, r, preq, pres, _iat, &ia, _rat, &ra, res);
+	if (err)
+		return err;
+
+	if (memcmp(res, exp, 16) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int test_s1(struct crypto_blkcipher *tfm_aes)
+{
+	const u8 const k[16] = {
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
+	const u8 const r1[16] = {
+			0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 };
+	const u8 const r2[16] = {
+			0x00, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99 };
+	const u8 const exp[16] = {
+			0x62, 0xa0, 0x6d, 0x79, 0xae, 0x16, 0x42, 0x5b,
+			0x9b, 0xf4, 0xb0, 0xe8, 0xf0, 0xe1, 0x1f, 0x9a };
+	u8 res[16];
+	int err;
+
+	err = smp_s1(tfm_aes, k, r1, r2, res);
+	if (err)
+		return err;
+
+	if (memcmp(res, exp, 16) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int run_selftests(struct seq_file *f, struct crypto_blkcipher *tfm_aes,
 			 struct crypto_hash *tfm_cmac)
 {
+	int err;
+
+	err = test_ah(tfm_aes);
+	if (err) {
+		seq_printf(f, "smp_ah test failed\n");
+		return err;
+	}
+
+	err = test_c1(tfm_aes);
+	if (err) {
+		seq_printf(f, "smp_c1 test failed\n");
+		return err;
+	}
+
+	err = test_s1(tfm_aes);
+	if (err) {
+		seq_printf(f, "smp_s1 test failed\n");
+		return err;
+	}
+
 	return 0;
 }
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/5] Bluetooth: Add SMP self-tests for SC crypto functions
  2014-12-29 10:04 [PATCH 0/5] Bluetooth: Add SMP self-tests through debugfs Johan Hedberg
                   ` (2 preceding siblings ...)
  2014-12-29 10:04 ` [PATCH 3/5] Bluetooth: Add SMP self-tests for legacy crypto functions Johan Hedberg
@ 2014-12-29 10:04 ` Johan Hedberg
  2014-12-29 10:04 ` [PATCH 5/5] Bluetooth: Add SMP self-tests for ECDH functionality Johan Hedberg
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2014-12-29 10:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds self-tests for the Secure Connections SMP crypto
functions. The sample data has been taken from the core specification.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 186 insertions(+)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index e4d6ae5028f5..768f4f0e0d44 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -3101,6 +3101,162 @@ static int test_s1(struct crypto_blkcipher *tfm_aes)
 	return 0;
 }
 
+static int test_f4(struct crypto_hash *tfm_cmac)
+{
+	const u8 const u[32] = {
+			0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
+			0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
+			0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
+			0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20 };
+	const u8 const v[32] = {
+			0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b,
+			0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59,
+			0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90,
+			0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55 };
+	const u8 const x[16] = {
+			0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
+			0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
+	const u8 z = 0x00;
+	const u8 const exp[16] = {
+			0x2d, 0x87, 0x74, 0xa9, 0xbe, 0xa1, 0xed, 0xf1,
+			0x1c, 0xbd, 0xa9, 0x07, 0xf1, 0x16, 0xc9, 0xf2 };
+	u8 res[16];
+	int err;
+
+	err = smp_f4(tfm_cmac, u, v, x, z, res);
+	if (err)
+		return err;
+
+	if (memcmp(res, exp, 16) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int test_f5(struct crypto_hash *tfm_cmac)
+{
+	const u8 const w[32] = {
+			0x98, 0xa6, 0xbf, 0x73, 0xf3, 0x34, 0x8d, 0x86,
+			0xf1, 0x66, 0xf8, 0xb4, 0x13, 0x6b, 0x79, 0x99,
+			0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
+			0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec };
+	const u8 const n1[16] = {
+			0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
+			0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
+	const u8 const n2[16] = {
+			0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21,
+			0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 };
+	const u8 const a1[7] = { 0xce, 0xbf, 0x37, 0x37, 0x12, 0x56, 0x00 };
+	const u8 const a2[7] = { 0xc1, 0xcf, 0x2d, 0x70, 0x13, 0xa7, 0x00 };
+	const u8 const exp_ltk[16] = {
+			0x38, 0x0a, 0x75, 0x94, 0xb5, 0x22, 0x05, 0x98,
+			0x23, 0xcd, 0xd7, 0x69, 0x11, 0x79, 0x86, 0x69 };
+	const u8 const exp_mackey[16] = {
+			0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd,
+			0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29 };
+	u8 mackey[16], ltk[16];
+	int err;
+
+	err = smp_f5(tfm_cmac, w, n1, n2, a1, a2, mackey, ltk);
+	if (err)
+		return err;
+
+	if (memcmp(mackey, exp_mackey, 16) != 0)
+		return -EINVAL;
+
+	if (memcmp(ltk, exp_ltk, 16) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int test_f6(struct crypto_hash *tfm_cmac)
+{
+	const u8 const w[16] = {
+			0x20, 0x6e, 0x63, 0xce, 0x20, 0x6a, 0x3f, 0xfd,
+			0x02, 0x4a, 0x08, 0xa1, 0x76, 0xf1, 0x65, 0x29 };
+	const u8 const n1[16] = {
+			0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
+			0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
+	const u8 const n2[16] = {
+			0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21,
+			0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 };
+	const u8 const r[16] = {
+			0xc8, 0x0f, 0x2d, 0x0c, 0xd2, 0x42, 0xda, 0x08,
+			0x54, 0xbb, 0x53, 0xb4, 0x3b, 0x34, 0xa3, 0x12 };
+	const u8 const io_cap[3] = { 0x02, 0x01, 0x01 };
+	const u8 const a1[7] = { 0xce, 0xbf, 0x37, 0x37, 0x12, 0x56, 0x00 };
+	const u8 const a2[7] = { 0xc1, 0xcf, 0x2d, 0x70, 0x13, 0xa7, 0x00 };
+	const u8 const exp[16] = {
+			0x61, 0x8f, 0x95, 0xda, 0x09, 0x0b, 0x6c, 0xd2,
+			0xc5, 0xe8, 0xd0, 0x9c, 0x98, 0x73, 0xc4, 0xe3 };
+	u8 res[16];
+	int err;
+
+	err = smp_f6(tfm_cmac, w, n1, n2, r, io_cap, a1, a2, res);
+	if (err)
+		return err;
+
+	if (memcmp(res, exp, 16) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int test_g2(struct crypto_hash *tfm_cmac)
+{
+	const u8 const u[32] = {
+			0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
+			0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
+			0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
+			0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20 };
+	const u8 const v[32] = {
+			0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b,
+			0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59,
+			0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90,
+			0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55 };
+	const u8 const x[16] = {
+			0xab, 0xae, 0x2b, 0x71, 0xec, 0xb2, 0xff, 0xff,
+			0x3e, 0x73, 0x77, 0xd1, 0x54, 0x84, 0xcb, 0xd5 };
+	const u8 const y[16] = {
+			0xcf, 0xc4, 0x3d, 0xff, 0xf7, 0x83, 0x65, 0x21,
+			0x6e, 0x5f, 0xa7, 0x25, 0xcc, 0xe7, 0xe8, 0xa6 };
+	const u32 exp_val = 0x2f9ed5ba % 1000000;
+	u32 val;
+	int err;
+
+	err = smp_g2(tfm_cmac, u, v, x, y, &val);
+	if (err)
+		return err;
+
+	if (val != exp_val)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int test_h6(struct crypto_hash *tfm_cmac)
+{
+	const u8 const w[16] = {
+			0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
+			0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec };
+	const u8 const key_id[4] = { 0x72, 0x62, 0x65, 0x6c };
+	const u8 exp[16] = {
+			0x99, 0x63, 0xb1, 0x80, 0xe2, 0xa9, 0xd3, 0xe8,
+			0x1c, 0xc9, 0x6d, 0xe7, 0x02, 0xe1, 0x9a, 0x2d };
+	u8 res[16];
+	int err;
+
+	err = smp_h6(tfm_cmac, w, key_id, res);
+	if (err)
+		return err;
+
+	if (memcmp(res, exp, 16) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
 static int run_selftests(struct seq_file *f, struct crypto_blkcipher *tfm_aes,
 			 struct crypto_hash *tfm_cmac)
 {
@@ -3124,6 +3280,36 @@ static int run_selftests(struct seq_file *f, struct crypto_blkcipher *tfm_aes,
 		return err;
 	}
 
+	err = test_f4(tfm_cmac);
+	if (err) {
+		seq_printf(f, "smp_f4 test failed\n");
+		return err;
+	}
+
+	err = test_f5(tfm_cmac);
+	if (err) {
+		seq_printf(f, "smp_f5 test failed\n");
+		return err;
+	}
+
+	err = test_f6(tfm_cmac);
+	if (err) {
+		seq_printf(f, "smp_f6 test failed\n");
+		return err;
+	}
+
+	err = test_g2(tfm_cmac);
+	if (err) {
+		seq_printf(f, "smp_g2 test failed\n");
+		return err;
+	}
+
+	err = test_h6(tfm_cmac);
+	if (err) {
+		seq_printf(f, "smp_h6 test failed\n");
+		return err;
+	}
+
 	return 0;
 }
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 5/5] Bluetooth: Add SMP self-tests for ECDH functionality
  2014-12-29 10:04 [PATCH 0/5] Bluetooth: Add SMP self-tests through debugfs Johan Hedberg
                   ` (3 preceding siblings ...)
  2014-12-29 10:04 ` [PATCH 4/5] Bluetooth: Add SMP self-tests for SC " Johan Hedberg
@ 2014-12-29 10:04 ` Johan Hedberg
  4 siblings, 0 replies; 7+ messages in thread
From: Johan Hedberg @ 2014-12-29 10:04 UTC (permalink / raw)
  To: linux-bluetooth

From: Johan Hedberg <johan.hedberg@intel.com>

This patch adds self-tests for the ECDH functionality that's used by the
SMP Secure Connections feature.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
---
 net/bluetooth/smp.c | 155 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 155 insertions(+)

diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 768f4f0e0d44..6da31c3bcafb 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -3257,6 +3257,155 @@ static int test_h6(struct crypto_hash *tfm_cmac)
 	return 0;
 }
 
+static const u8 const priv_a_1[32] = {
+	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
+	0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
+	0x50, 0x3f, 0x10, 0xd2, 0xe3, 0xb3, 0xc9, 0x74,
+	0x38, 0x5f, 0xc5, 0xa3, 0xd4, 0xf6, 0x49, 0x3f,
+};
+static const u8 const priv_b_1[32] = {
+	0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b,
+	0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59,
+	0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90,
+	0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55,
+};
+static const u8 const pub_a_1[64] = {
+	0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
+	0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
+	0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
+	0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
+
+	0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
+	0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
+	0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
+	0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc,
+};
+static const u8 const pub_b_1[64] = {
+	0x90, 0xa1, 0xaa, 0x2f, 0xb2, 0x77, 0x90, 0x55,
+	0x9f, 0xa6, 0x15, 0x86, 0xfd, 0x8a, 0xb5, 0x47,
+	0x00, 0x4c, 0x9e, 0xf1, 0x84, 0x22, 0x59, 0x09,
+	0x96, 0x1d, 0xaf, 0x1f, 0xf0, 0xf0, 0xa1, 0x1e,
+
+	0x4a, 0x21, 0xb1, 0x15, 0xf9, 0xaf, 0x89, 0x5f,
+	0x76, 0x36, 0x8e, 0xe2, 0x30, 0x11, 0x2d, 0x47,
+	0x60, 0x51, 0xb8, 0x9a, 0x3a, 0x70, 0x56, 0x73,
+	0x37, 0xad, 0x9d, 0x42, 0x3e, 0xf3, 0x55, 0x4c,
+};
+static const u8 const dhkey_1[32] = {
+	0x98, 0xa6, 0xbf, 0x73, 0xf3, 0x34, 0x8d, 0x86,
+	0xf1, 0x66, 0xf8, 0xb4, 0x13, 0x6b, 0x79, 0x99,
+	0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
+	0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec,
+};
+
+static const u8 const priv_a_2[32] = {
+	0x63, 0x76, 0x45, 0xd0, 0xf7, 0x73, 0xac, 0xb7,
+	0xff, 0xdd, 0x03, 0x72, 0xb9, 0x72, 0x85, 0xb4,
+	0x41, 0xb6, 0x5d, 0x0c, 0x5d, 0x54, 0x84, 0x60,
+	0x1a, 0xa3, 0x9a, 0x3c, 0x69, 0x16, 0xa5, 0x06,
+};
+static const u8 const priv_b_2[32] = {
+	0xba, 0x30, 0x55, 0x50, 0x19, 0xa2, 0xca, 0xa3,
+	0xa5, 0x29, 0x08, 0xc6, 0xb5, 0x03, 0x88, 0x7e,
+	0x03, 0x2b, 0x50, 0x73, 0xd4, 0x2e, 0x50, 0x97,
+	0x64, 0xcd, 0x72, 0x0d, 0x67, 0xa0, 0x9a, 0x52,
+};
+static const u8 const pub_a_2[64] = {
+	0xdd, 0x78, 0x5c, 0x74, 0x03, 0x9b, 0x7e, 0x98,
+	0xcb, 0x94, 0x87, 0x4a, 0xad, 0xfa, 0xf8, 0xd5,
+	0x43, 0x3e, 0x5c, 0xaf, 0xea, 0xb5, 0x4c, 0xf4,
+	0x9e, 0x80, 0x79, 0x57, 0x7b, 0xa4, 0x31, 0x2c,
+
+	0x4f, 0x5d, 0x71, 0x43, 0x77, 0x43, 0xf8, 0xea,
+	0xd4, 0x3e, 0xbd, 0x17, 0x91, 0x10, 0x21, 0xd0,
+	0x1f, 0x87, 0x43, 0x8e, 0x40, 0xe2, 0x52, 0xcd,
+	0xbe, 0xdf, 0x98, 0x38, 0x18, 0x12, 0x95, 0x91,
+};
+static const u8 const pub_b_2[64] = {
+	0xcc, 0x00, 0x65, 0xe1, 0xf5, 0x6c, 0x0d, 0xcf,
+	0xec, 0x96, 0x47, 0x20, 0x66, 0xc9, 0xdb, 0x84,
+	0x81, 0x75, 0xa8, 0x4d, 0xc0, 0xdf, 0xc7, 0x9d,
+	0x1b, 0x3f, 0x3d, 0xf2, 0x3f, 0xe4, 0x65, 0xf4,
+
+	0x79, 0xb2, 0xec, 0xd8, 0xca, 0x55, 0xa1, 0xa8,
+	0x43, 0x4d, 0x6b, 0xca, 0x10, 0xb0, 0xc2, 0x01,
+	0xc2, 0x33, 0x4e, 0x16, 0x24, 0xc4, 0xef, 0xee,
+	0x99, 0xd8, 0xbb, 0xbc, 0x48, 0xd0, 0x01, 0x02,
+};
+static const u8 const dhkey_2[32] = {
+	0x69, 0xeb, 0x21, 0x32, 0xf2, 0xc6, 0x05, 0x41,
+	0x60, 0x19, 0xcd, 0x5e, 0x94, 0xe1, 0xe6, 0x5f,
+	0x33, 0x07, 0xe3, 0x38, 0x4b, 0x68, 0xe5, 0x62,
+	0x3f, 0x88, 0x6d, 0x2f, 0x3a, 0x84, 0x85, 0xab,
+};
+
+static const u8 const priv_a_3[32] = {
+	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
+	0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
+	0x50, 0x3f, 0x10, 0xd2, 0xe3, 0xb3, 0xc9, 0x74,
+	0x38, 0x5f, 0xc5, 0xa3, 0xd4, 0xf6, 0x49, 0x3f,
+};
+static const u8 const pub_a_3[64] = {
+	0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
+	0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
+	0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
+	0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
+
+	0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
+	0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
+	0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
+	0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc,
+};
+static const u8 const dhkey_3[32] = {
+	0x2d, 0xab, 0x00, 0x48, 0xcb, 0xb3, 0x7b, 0xda,
+	0x55, 0x7b, 0x8b, 0x72, 0xa8, 0x57, 0x87, 0xc3,
+	0x87, 0x27, 0x99, 0x32, 0xfc, 0x79, 0x5f, 0xae,
+	0x7c, 0x1c, 0xf9, 0x49, 0xe6, 0xd7, 0xaa, 0x70,
+};
+
+static int test_ecdh_sample(const u8 priv_a[32], const u8 priv_b[32],
+			    const u8 pub_a[64], const u8 pub_b[64],
+			    const u8 dhkey[32])
+{
+	u8 dhkey_a[32], dhkey_b[32];
+
+	ecdh_shared_secret(pub_b, priv_a, dhkey_a);
+	ecdh_shared_secret(pub_a, priv_b, dhkey_b);
+
+	if (memcmp(dhkey_a, dhkey, 32) != 0)
+		return -EINVAL;
+
+	if (memcmp(dhkey_b, dhkey, 32) != 0)
+		return -EINVAL;
+
+	return 0;
+}
+
+static int test_ecdh(struct seq_file *f)
+{
+	int err;
+
+	err = test_ecdh_sample(priv_a_1, priv_b_1, pub_a_1, pub_b_1, dhkey_1);
+	if (err) {
+		seq_printf(f, "ECDH sample 1 failed\n");
+		return err;
+	}
+
+	err = test_ecdh_sample(priv_a_2, priv_b_2, pub_a_2, pub_b_2, dhkey_2);
+	if (err) {
+		seq_printf(f, "ECDH sample 2 failed\n");
+		return err;
+	}
+
+	err = test_ecdh_sample(priv_a_3, priv_a_3, pub_a_3, pub_a_3, dhkey_3);
+	if (err) {
+		seq_printf(f, "ECDH sample 3 failed\n");
+		return err;
+	}
+
+	return 0;
+}
+
 static int run_selftests(struct seq_file *f, struct crypto_blkcipher *tfm_aes,
 			 struct crypto_hash *tfm_cmac)
 {
@@ -3310,6 +3459,12 @@ static int run_selftests(struct seq_file *f, struct crypto_blkcipher *tfm_aes,
 		return err;
 	}
 
+	err = test_ecdh(f);
+	if (err) {
+		seq_printf(f, "ECDH test failed\n");
+		return err;
+	}
+
 	return 0;
 }
 
-- 
2.1.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/5] Bluetooth: Fix const declarations for smp_f5 and smp_f6
  2014-12-29 10:04 ` [PATCH 1/5] Bluetooth: Fix const declarations for smp_f5 and smp_f6 Johan Hedberg
@ 2014-12-30  6:30   ` Marcel Holtmann
  0 siblings, 0 replies; 7+ messages in thread
From: Marcel Holtmann @ 2014-12-30  6:30 UTC (permalink / raw)
  To: Johan Hedberg; +Cc: linux-bluetooth

Hi Johan,

> These SMP crypto functions should have all their input parameters
> declared as const. This patch fixes the parameters that were missing the
> const declaration.
> 
> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
> ---
> net/bluetooth/smp.c | 7 ++++---
> 1 file changed, 4 insertions(+), 3 deletions(-)

this patch out of this series has been applied to bluetooth-next tree.

Regards

Marcel


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-12-30  6:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-29 10:04 [PATCH 0/5] Bluetooth: Add SMP self-tests through debugfs Johan Hedberg
2014-12-29 10:04 ` [PATCH 1/5] Bluetooth: Fix const declarations for smp_f5 and smp_f6 Johan Hedberg
2014-12-30  6:30   ` Marcel Holtmann
2014-12-29 10:04 ` [PATCH 2/5] Bluetooth: Add skeleton for debugfs-based SMP self-tests Johan Hedberg
2014-12-29 10:04 ` [PATCH 3/5] Bluetooth: Add SMP self-tests for legacy crypto functions Johan Hedberg
2014-12-29 10:04 ` [PATCH 4/5] Bluetooth: Add SMP self-tests for SC " Johan Hedberg
2014-12-29 10:04 ` [PATCH 5/5] Bluetooth: Add SMP self-tests for ECDH functionality Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).