aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Hedberg <johan.hedberg@intel.com>2014-12-30 02:50:39 -0500
committerMarcel Holtmann <marcel@holtmann.org>2014-12-30 02:54:33 -0500
commit0a2b0f0452e2499a1037305fcfc314d0cdeb5260 (patch)
tree40be3edc04c30fe22299dd40bc95dad9036756fb
parent0b6415b65234ff723d32fd7dcdd917ba7ad5fe86 (diff)
Bluetooth: Add skeleton for SMP self-tests
This patch adds the initial skeleton and kernel config option for SMP self-tests. Signed-off-by: Johan Hedberg <johan.hedberg@intel.com> Signed-off-by: Marcel Holtmann <marcel@holtmann.org>
-rw-r--r--net/bluetooth/Kconfig7
-rw-r--r--net/bluetooth/selftest.c7
-rw-r--r--net/bluetooth/smp.c39
-rw-r--r--net/bluetooth/smp.h13
4 files changed, 66 insertions, 0 deletions
diff --git a/net/bluetooth/Kconfig b/net/bluetooth/Kconfig
index 8d3b607a72be..7de74635a110 100644
--- a/net/bluetooth/Kconfig
+++ b/net/bluetooth/Kconfig
@@ -84,4 +84,11 @@ config BT_SELFTEST_ECDH
84 Run test cases for ECDH cryptographic functionality used by the 84 Run test cases for ECDH cryptographic functionality used by the
85 Bluetooth Low Energy Secure Connections feature. 85 Bluetooth Low Energy Secure Connections feature.
86 86
87config BT_SELFTEST_SMP
88 bool "SMP test cases"
89 depends on BT_LE && BT_SELFTEST
90 help
91 Run test cases for SMP cryptographic functionality, including both
92 legacy SMP as well as the Secure Connections features.
93
87source "drivers/bluetooth/Kconfig" 94source "drivers/bluetooth/Kconfig"
diff --git a/net/bluetooth/selftest.c b/net/bluetooth/selftest.c
index b9cb33cd45d7..a7602b3d0b0d 100644
--- a/net/bluetooth/selftest.c
+++ b/net/bluetooth/selftest.c
@@ -22,8 +22,10 @@
22*/ 22*/
23 23
24#include <net/bluetooth/bluetooth.h> 24#include <net/bluetooth/bluetooth.h>
25#include <net/bluetooth/hci_core.h>
25 26
26#include "ecc.h" 27#include "ecc.h"
28#include "smp.h"
27#include "selftest.h" 29#include "selftest.h"
28 30
29#if IS_ENABLED(CONFIG_BT_SELFTEST_ECDH) 31#if IS_ENABLED(CONFIG_BT_SELFTEST_ECDH)
@@ -195,7 +197,12 @@ static int __init run_selftest(void)
195 BT_INFO("Starting self testing"); 197 BT_INFO("Starting self testing");
196 198
197 err = test_ecdh(); 199 err = test_ecdh();
200 if (err)
201 goto done;
198 202
203 err = bt_selftest_smp();
204
205done:
199 BT_INFO("Finished self testing"); 206 BT_INFO("Finished self testing");
200 207
201 return err; 208 return err;
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 9025e177d278..b47528d66a5f 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -3022,3 +3022,42 @@ void smp_unregister(struct hci_dev *hdev)
3022 smp_del_chan(chan); 3022 smp_del_chan(chan);
3023 } 3023 }
3024} 3024}
3025
3026#if IS_ENABLED(CONFIG_BT_SELFTEST_SMP)
3027
3028static int __init run_selftests(struct crypto_blkcipher *tfm_aes,
3029 struct crypto_hash *tfm_cmac)
3030{
3031 BT_INFO("SMP test passed");
3032
3033 return 0;
3034}
3035
3036int __init bt_selftest_smp(void)
3037{
3038 struct crypto_blkcipher *tfm_aes;
3039 struct crypto_hash *tfm_cmac;
3040 int err;
3041
3042 tfm_aes = crypto_alloc_blkcipher("ecb(aes)", 0, CRYPTO_ALG_ASYNC);
3043 if (IS_ERR(tfm_aes)) {
3044 BT_ERR("Unable to create ECB crypto context");
3045 return PTR_ERR(tfm_aes);
3046 }
3047
3048 tfm_cmac = crypto_alloc_hash("cmac(aes)", 0, CRYPTO_ALG_ASYNC);
3049 if (IS_ERR(tfm_cmac)) {
3050 BT_ERR("Unable to create CMAC crypto context");
3051 crypto_free_blkcipher(tfm_aes);
3052 return PTR_ERR(tfm_cmac);
3053 }
3054
3055 err = run_selftests(tfm_aes, tfm_cmac);
3056
3057 crypto_free_hash(tfm_cmac);
3058 crypto_free_blkcipher(tfm_aes);
3059
3060 return err;
3061}
3062
3063#endif
diff --git a/net/bluetooth/smp.h b/net/bluetooth/smp.h
index 3296bf42ae80..60c5b73fcb4b 100644
--- a/net/bluetooth/smp.h
+++ b/net/bluetooth/smp.h
@@ -192,4 +192,17 @@ int smp_generate_rpa(struct hci_dev *hdev, const u8 irk[16], bdaddr_t *rpa);
192int smp_register(struct hci_dev *hdev); 192int smp_register(struct hci_dev *hdev);
193void smp_unregister(struct hci_dev *hdev); 193void smp_unregister(struct hci_dev *hdev);
194 194
195#if IS_ENABLED(CONFIG_BT_SELFTEST_SMP)
196
197int bt_selftest_smp(void);
198
199#else
200
201static inline int bt_selftest_smp(void)
202{
203 return 0;
204}
205
206#endif
207
195#endif /* __SMP_H */ 208#endif /* __SMP_H */