Skip to content

Commit 0a2b0f0

Browse files
jhedbergholtmann
authored andcommitted
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>
1 parent 0b6415b commit 0a2b0f0

4 files changed

Lines changed: 66 additions & 0 deletions

File tree

‎net/bluetooth/Kconfig‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,11 @@ config BT_SELFTEST_ECDH
8484
Run test cases for ECDH cryptographic functionality used by the
8585
Bluetooth Low Energy Secure Connections feature.
8686

87+
config 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+
8794
source "drivers/bluetooth/Kconfig"

‎net/bluetooth/selftest.c‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
*/
2323

2424
#include <net/bluetooth/bluetooth.h>
25+
#include <net/bluetooth/hci_core.h>
2526

2627
#include "ecc.h"
28+
#include "smp.h"
2729
#include "selftest.h"
2830

2931
#if IS_ENABLED(CONFIG_BT_SELFTEST_ECDH)
@@ -195,7 +197,12 @@ static int __init run_selftest(void)
195197
BT_INFO("Starting self testing");
196198

197199
err = test_ecdh();
200+
if (err)
201+
goto done;
198202

203+
err = bt_selftest_smp();
204+
205+
done:
199206
BT_INFO("Finished self testing");
200207

201208
return err;

‎net/bluetooth/smp.c‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,3 +3022,42 @@ void smp_unregister(struct hci_dev *hdev)
30223022
smp_del_chan(chan);
30233023
}
30243024
}
3025+
3026+
#if IS_ENABLED(CONFIG_BT_SELFTEST_SMP)
3027+
3028+
static 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+
3036+
int __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

‎net/bluetooth/smp.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,17 @@ int smp_generate_rpa(struct hci_dev *hdev, const u8 irk[16], bdaddr_t *rpa);
192192
int smp_register(struct hci_dev *hdev);
193193
void smp_unregister(struct hci_dev *hdev);
194194

195+
#if IS_ENABLED(CONFIG_BT_SELFTEST_SMP)
196+
197+
int bt_selftest_smp(void);
198+
199+
#else
200+
201+
static inline int bt_selftest_smp(void)
202+
{
203+
return 0;
204+
}
205+
206+
#endif
207+
195208
#endif /* __SMP_H */

0 commit comments

Comments
 (0)