18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci   BlueZ - Bluetooth protocol stack for Linux
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci   Copyright (C) 2014 Intel Corporation
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci   This program is free software; you can redistribute it and/or modify
78c2ecf20Sopenharmony_ci   it under the terms of the GNU General Public License version 2 as
88c2ecf20Sopenharmony_ci   published by the Free Software Foundation;
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
118c2ecf20Sopenharmony_ci   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
128c2ecf20Sopenharmony_ci   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
138c2ecf20Sopenharmony_ci   IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
148c2ecf20Sopenharmony_ci   CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
158c2ecf20Sopenharmony_ci   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
168c2ecf20Sopenharmony_ci   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
178c2ecf20Sopenharmony_ci   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci   ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
208c2ecf20Sopenharmony_ci   COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
218c2ecf20Sopenharmony_ci   SOFTWARE IS DISCLAIMED.
228c2ecf20Sopenharmony_ci*/
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include <linux/debugfs.h>
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#include <net/bluetooth/bluetooth.h>
278c2ecf20Sopenharmony_ci#include <net/bluetooth/hci_core.h>
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci#include "ecdh_helper.h"
308c2ecf20Sopenharmony_ci#include "smp.h"
318c2ecf20Sopenharmony_ci#include "selftest.h"
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_BT_SELFTEST_ECDH)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic const u8 priv_a_1[32] __initconst = {
368c2ecf20Sopenharmony_ci	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
378c2ecf20Sopenharmony_ci	0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
388c2ecf20Sopenharmony_ci	0x50, 0x3f, 0x10, 0xd2, 0xe3, 0xb3, 0xc9, 0x74,
398c2ecf20Sopenharmony_ci	0x38, 0x5f, 0xc5, 0xa3, 0xd4, 0xf6, 0x49, 0x3f,
408c2ecf20Sopenharmony_ci};
418c2ecf20Sopenharmony_cistatic const u8 priv_b_1[32] __initconst = {
428c2ecf20Sopenharmony_ci	0xfd, 0xc5, 0x7f, 0xf4, 0x49, 0xdd, 0x4f, 0x6b,
438c2ecf20Sopenharmony_ci	0xfb, 0x7c, 0x9d, 0xf1, 0xc2, 0x9a, 0xcb, 0x59,
448c2ecf20Sopenharmony_ci	0x2a, 0xe7, 0xd4, 0xee, 0xfb, 0xfc, 0x0a, 0x90,
458c2ecf20Sopenharmony_ci	0x9a, 0xbb, 0xf6, 0x32, 0x3d, 0x8b, 0x18, 0x55,
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_cistatic const u8 pub_a_1[64] __initconst = {
488c2ecf20Sopenharmony_ci	0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
498c2ecf20Sopenharmony_ci	0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
508c2ecf20Sopenharmony_ci	0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
518c2ecf20Sopenharmony_ci	0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci	0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
548c2ecf20Sopenharmony_ci	0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
558c2ecf20Sopenharmony_ci	0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
568c2ecf20Sopenharmony_ci	0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc,
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_cistatic const u8 pub_b_1[64] __initconst = {
598c2ecf20Sopenharmony_ci	0x90, 0xa1, 0xaa, 0x2f, 0xb2, 0x77, 0x90, 0x55,
608c2ecf20Sopenharmony_ci	0x9f, 0xa6, 0x15, 0x86, 0xfd, 0x8a, 0xb5, 0x47,
618c2ecf20Sopenharmony_ci	0x00, 0x4c, 0x9e, 0xf1, 0x84, 0x22, 0x59, 0x09,
628c2ecf20Sopenharmony_ci	0x96, 0x1d, 0xaf, 0x1f, 0xf0, 0xf0, 0xa1, 0x1e,
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	0x4a, 0x21, 0xb1, 0x15, 0xf9, 0xaf, 0x89, 0x5f,
658c2ecf20Sopenharmony_ci	0x76, 0x36, 0x8e, 0xe2, 0x30, 0x11, 0x2d, 0x47,
668c2ecf20Sopenharmony_ci	0x60, 0x51, 0xb8, 0x9a, 0x3a, 0x70, 0x56, 0x73,
678c2ecf20Sopenharmony_ci	0x37, 0xad, 0x9d, 0x42, 0x3e, 0xf3, 0x55, 0x4c,
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_cistatic const u8 dhkey_1[32] __initconst = {
708c2ecf20Sopenharmony_ci	0x98, 0xa6, 0xbf, 0x73, 0xf3, 0x34, 0x8d, 0x86,
718c2ecf20Sopenharmony_ci	0xf1, 0x66, 0xf8, 0xb4, 0x13, 0x6b, 0x79, 0x99,
728c2ecf20Sopenharmony_ci	0x9b, 0x7d, 0x39, 0x0a, 0xa6, 0x10, 0x10, 0x34,
738c2ecf20Sopenharmony_ci	0x05, 0xad, 0xc8, 0x57, 0xa3, 0x34, 0x02, 0xec,
748c2ecf20Sopenharmony_ci};
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_cistatic const u8 priv_a_2[32] __initconst = {
778c2ecf20Sopenharmony_ci	0x63, 0x76, 0x45, 0xd0, 0xf7, 0x73, 0xac, 0xb7,
788c2ecf20Sopenharmony_ci	0xff, 0xdd, 0x03, 0x72, 0xb9, 0x72, 0x85, 0xb4,
798c2ecf20Sopenharmony_ci	0x41, 0xb6, 0x5d, 0x0c, 0x5d, 0x54, 0x84, 0x60,
808c2ecf20Sopenharmony_ci	0x1a, 0xa3, 0x9a, 0x3c, 0x69, 0x16, 0xa5, 0x06,
818c2ecf20Sopenharmony_ci};
828c2ecf20Sopenharmony_cistatic const u8 priv_b_2[32] __initconst = {
838c2ecf20Sopenharmony_ci	0xba, 0x30, 0x55, 0x50, 0x19, 0xa2, 0xca, 0xa3,
848c2ecf20Sopenharmony_ci	0xa5, 0x29, 0x08, 0xc6, 0xb5, 0x03, 0x88, 0x7e,
858c2ecf20Sopenharmony_ci	0x03, 0x2b, 0x50, 0x73, 0xd4, 0x2e, 0x50, 0x97,
868c2ecf20Sopenharmony_ci	0x64, 0xcd, 0x72, 0x0d, 0x67, 0xa0, 0x9a, 0x52,
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_cistatic const u8 pub_a_2[64] __initconst = {
898c2ecf20Sopenharmony_ci	0xdd, 0x78, 0x5c, 0x74, 0x03, 0x9b, 0x7e, 0x98,
908c2ecf20Sopenharmony_ci	0xcb, 0x94, 0x87, 0x4a, 0xad, 0xfa, 0xf8, 0xd5,
918c2ecf20Sopenharmony_ci	0x43, 0x3e, 0x5c, 0xaf, 0xea, 0xb5, 0x4c, 0xf4,
928c2ecf20Sopenharmony_ci	0x9e, 0x80, 0x79, 0x57, 0x7b, 0xa4, 0x31, 0x2c,
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci	0x4f, 0x5d, 0x71, 0x43, 0x77, 0x43, 0xf8, 0xea,
958c2ecf20Sopenharmony_ci	0xd4, 0x3e, 0xbd, 0x17, 0x91, 0x10, 0x21, 0xd0,
968c2ecf20Sopenharmony_ci	0x1f, 0x87, 0x43, 0x8e, 0x40, 0xe2, 0x52, 0xcd,
978c2ecf20Sopenharmony_ci	0xbe, 0xdf, 0x98, 0x38, 0x18, 0x12, 0x95, 0x91,
988c2ecf20Sopenharmony_ci};
998c2ecf20Sopenharmony_cistatic const u8 pub_b_2[64] __initconst = {
1008c2ecf20Sopenharmony_ci	0xcc, 0x00, 0x65, 0xe1, 0xf5, 0x6c, 0x0d, 0xcf,
1018c2ecf20Sopenharmony_ci	0xec, 0x96, 0x47, 0x20, 0x66, 0xc9, 0xdb, 0x84,
1028c2ecf20Sopenharmony_ci	0x81, 0x75, 0xa8, 0x4d, 0xc0, 0xdf, 0xc7, 0x9d,
1038c2ecf20Sopenharmony_ci	0x1b, 0x3f, 0x3d, 0xf2, 0x3f, 0xe4, 0x65, 0xf4,
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_ci	0x79, 0xb2, 0xec, 0xd8, 0xca, 0x55, 0xa1, 0xa8,
1068c2ecf20Sopenharmony_ci	0x43, 0x4d, 0x6b, 0xca, 0x10, 0xb0, 0xc2, 0x01,
1078c2ecf20Sopenharmony_ci	0xc2, 0x33, 0x4e, 0x16, 0x24, 0xc4, 0xef, 0xee,
1088c2ecf20Sopenharmony_ci	0x99, 0xd8, 0xbb, 0xbc, 0x48, 0xd0, 0x01, 0x02,
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_cistatic const u8 dhkey_2[32] __initconst = {
1118c2ecf20Sopenharmony_ci	0x69, 0xeb, 0x21, 0x32, 0xf2, 0xc6, 0x05, 0x41,
1128c2ecf20Sopenharmony_ci	0x60, 0x19, 0xcd, 0x5e, 0x94, 0xe1, 0xe6, 0x5f,
1138c2ecf20Sopenharmony_ci	0x33, 0x07, 0xe3, 0x38, 0x4b, 0x68, 0xe5, 0x62,
1148c2ecf20Sopenharmony_ci	0x3f, 0x88, 0x6d, 0x2f, 0x3a, 0x84, 0x85, 0xab,
1158c2ecf20Sopenharmony_ci};
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic const u8 priv_a_3[32] __initconst = {
1188c2ecf20Sopenharmony_ci	0xbd, 0x1a, 0x3c, 0xcd, 0xa6, 0xb8, 0x99, 0x58,
1198c2ecf20Sopenharmony_ci	0x99, 0xb7, 0x40, 0xeb, 0x7b, 0x60, 0xff, 0x4a,
1208c2ecf20Sopenharmony_ci	0x50, 0x3f, 0x10, 0xd2, 0xe3, 0xb3, 0xc9, 0x74,
1218c2ecf20Sopenharmony_ci	0x38, 0x5f, 0xc5, 0xa3, 0xd4, 0xf6, 0x49, 0x3f,
1228c2ecf20Sopenharmony_ci};
1238c2ecf20Sopenharmony_cistatic const u8 pub_a_3[64] __initconst = {
1248c2ecf20Sopenharmony_ci	0xe6, 0x9d, 0x35, 0x0e, 0x48, 0x01, 0x03, 0xcc,
1258c2ecf20Sopenharmony_ci	0xdb, 0xfd, 0xf4, 0xac, 0x11, 0x91, 0xf4, 0xef,
1268c2ecf20Sopenharmony_ci	0xb9, 0xa5, 0xf9, 0xe9, 0xa7, 0x83, 0x2c, 0x5e,
1278c2ecf20Sopenharmony_ci	0x2c, 0xbe, 0x97, 0xf2, 0xd2, 0x03, 0xb0, 0x20,
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	0x8b, 0xd2, 0x89, 0x15, 0xd0, 0x8e, 0x1c, 0x74,
1308c2ecf20Sopenharmony_ci	0x24, 0x30, 0xed, 0x8f, 0xc2, 0x45, 0x63, 0x76,
1318c2ecf20Sopenharmony_ci	0x5c, 0x15, 0x52, 0x5a, 0xbf, 0x9a, 0x32, 0x63,
1328c2ecf20Sopenharmony_ci	0x6d, 0xeb, 0x2a, 0x65, 0x49, 0x9c, 0x80, 0xdc,
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_cistatic const u8 dhkey_3[32] __initconst = {
1358c2ecf20Sopenharmony_ci	0x2d, 0xab, 0x00, 0x48, 0xcb, 0xb3, 0x7b, 0xda,
1368c2ecf20Sopenharmony_ci	0x55, 0x7b, 0x8b, 0x72, 0xa8, 0x57, 0x87, 0xc3,
1378c2ecf20Sopenharmony_ci	0x87, 0x27, 0x99, 0x32, 0xfc, 0x79, 0x5f, 0xae,
1388c2ecf20Sopenharmony_ci	0x7c, 0x1c, 0xf9, 0x49, 0xe6, 0xd7, 0xaa, 0x70,
1398c2ecf20Sopenharmony_ci};
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_cistatic int __init test_ecdh_sample(struct crypto_kpp *tfm, const u8 priv_a[32],
1428c2ecf20Sopenharmony_ci				   const u8 priv_b[32], const u8 pub_a[64],
1438c2ecf20Sopenharmony_ci				   const u8 pub_b[64], const u8 dhkey[32])
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	u8 *tmp, *dhkey_a, *dhkey_b;
1468c2ecf20Sopenharmony_ci	int ret;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	tmp = kmalloc(64, GFP_KERNEL);
1498c2ecf20Sopenharmony_ci	if (!tmp)
1508c2ecf20Sopenharmony_ci		return -EINVAL;
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci	dhkey_a = &tmp[0];
1538c2ecf20Sopenharmony_ci	dhkey_b = &tmp[32];
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci	ret = set_ecdh_privkey(tfm, priv_a);
1568c2ecf20Sopenharmony_ci	if (ret)
1578c2ecf20Sopenharmony_ci		goto out;
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_ci	ret = compute_ecdh_secret(tfm, pub_b, dhkey_a);
1608c2ecf20Sopenharmony_ci	if (ret)
1618c2ecf20Sopenharmony_ci		goto out;
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci	if (memcmp(dhkey_a, dhkey, 32)) {
1648c2ecf20Sopenharmony_ci		ret = -EINVAL;
1658c2ecf20Sopenharmony_ci		goto out;
1668c2ecf20Sopenharmony_ci	}
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci	ret = set_ecdh_privkey(tfm, priv_b);
1698c2ecf20Sopenharmony_ci	if (ret)
1708c2ecf20Sopenharmony_ci		goto out;
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci	ret = compute_ecdh_secret(tfm, pub_a, dhkey_b);
1738c2ecf20Sopenharmony_ci	if (ret)
1748c2ecf20Sopenharmony_ci		goto out;
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci	if (memcmp(dhkey_b, dhkey, 32))
1778c2ecf20Sopenharmony_ci		ret = -EINVAL;
1788c2ecf20Sopenharmony_ci	/* fall through*/
1798c2ecf20Sopenharmony_ciout:
1808c2ecf20Sopenharmony_ci	kfree(tmp);
1818c2ecf20Sopenharmony_ci	return ret;
1828c2ecf20Sopenharmony_ci}
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_cistatic char test_ecdh_buffer[32];
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistatic ssize_t test_ecdh_read(struct file *file, char __user *user_buf,
1878c2ecf20Sopenharmony_ci			      size_t count, loff_t *ppos)
1888c2ecf20Sopenharmony_ci{
1898c2ecf20Sopenharmony_ci	return simple_read_from_buffer(user_buf, count, ppos, test_ecdh_buffer,
1908c2ecf20Sopenharmony_ci				       strlen(test_ecdh_buffer));
1918c2ecf20Sopenharmony_ci}
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_cistatic const struct file_operations test_ecdh_fops = {
1948c2ecf20Sopenharmony_ci	.open		= simple_open,
1958c2ecf20Sopenharmony_ci	.read		= test_ecdh_read,
1968c2ecf20Sopenharmony_ci	.llseek		= default_llseek,
1978c2ecf20Sopenharmony_ci};
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistatic int __init test_ecdh(void)
2008c2ecf20Sopenharmony_ci{
2018c2ecf20Sopenharmony_ci	struct crypto_kpp *tfm;
2028c2ecf20Sopenharmony_ci	ktime_t calltime, delta, rettime;
2038c2ecf20Sopenharmony_ci	unsigned long long duration = 0;
2048c2ecf20Sopenharmony_ci	int err;
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci	calltime = ktime_get();
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci	tfm = crypto_alloc_kpp("ecdh", 0, 0);
2098c2ecf20Sopenharmony_ci	if (IS_ERR(tfm)) {
2108c2ecf20Sopenharmony_ci		BT_ERR("Unable to create ECDH crypto context");
2118c2ecf20Sopenharmony_ci		err = PTR_ERR(tfm);
2128c2ecf20Sopenharmony_ci		goto done;
2138c2ecf20Sopenharmony_ci	}
2148c2ecf20Sopenharmony_ci
2158c2ecf20Sopenharmony_ci	err = test_ecdh_sample(tfm, priv_a_1, priv_b_1, pub_a_1, pub_b_1,
2168c2ecf20Sopenharmony_ci			       dhkey_1);
2178c2ecf20Sopenharmony_ci	if (err) {
2188c2ecf20Sopenharmony_ci		BT_ERR("ECDH sample 1 failed");
2198c2ecf20Sopenharmony_ci		goto done;
2208c2ecf20Sopenharmony_ci	}
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_ci	err = test_ecdh_sample(tfm, priv_a_2, priv_b_2, pub_a_2, pub_b_2,
2238c2ecf20Sopenharmony_ci			       dhkey_2);
2248c2ecf20Sopenharmony_ci	if (err) {
2258c2ecf20Sopenharmony_ci		BT_ERR("ECDH sample 2 failed");
2268c2ecf20Sopenharmony_ci		goto done;
2278c2ecf20Sopenharmony_ci	}
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci	err = test_ecdh_sample(tfm, priv_a_3, priv_a_3, pub_a_3, pub_a_3,
2308c2ecf20Sopenharmony_ci			       dhkey_3);
2318c2ecf20Sopenharmony_ci	if (err) {
2328c2ecf20Sopenharmony_ci		BT_ERR("ECDH sample 3 failed");
2338c2ecf20Sopenharmony_ci		goto done;
2348c2ecf20Sopenharmony_ci	}
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci	crypto_free_kpp(tfm);
2378c2ecf20Sopenharmony_ci
2388c2ecf20Sopenharmony_ci	rettime = ktime_get();
2398c2ecf20Sopenharmony_ci	delta = ktime_sub(rettime, calltime);
2408c2ecf20Sopenharmony_ci	duration = (unsigned long long) ktime_to_ns(delta) >> 10;
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci	BT_INFO("ECDH test passed in %llu usecs", duration);
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_cidone:
2458c2ecf20Sopenharmony_ci	if (!err)
2468c2ecf20Sopenharmony_ci		snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer),
2478c2ecf20Sopenharmony_ci			 "PASS (%llu usecs)\n", duration);
2488c2ecf20Sopenharmony_ci	else
2498c2ecf20Sopenharmony_ci		snprintf(test_ecdh_buffer, sizeof(test_ecdh_buffer), "FAIL\n");
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	debugfs_create_file("selftest_ecdh", 0444, bt_debugfs, NULL,
2528c2ecf20Sopenharmony_ci			    &test_ecdh_fops);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci	return err;
2558c2ecf20Sopenharmony_ci}
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci#else
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistatic inline int test_ecdh(void)
2608c2ecf20Sopenharmony_ci{
2618c2ecf20Sopenharmony_ci	return 0;
2628c2ecf20Sopenharmony_ci}
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_ci#endif
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistatic int __init run_selftest(void)
2678c2ecf20Sopenharmony_ci{
2688c2ecf20Sopenharmony_ci	int err;
2698c2ecf20Sopenharmony_ci
2708c2ecf20Sopenharmony_ci	BT_INFO("Starting self testing");
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	err = test_ecdh();
2738c2ecf20Sopenharmony_ci	if (err)
2748c2ecf20Sopenharmony_ci		goto done;
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_ci	err = bt_selftest_smp();
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_cidone:
2798c2ecf20Sopenharmony_ci	BT_INFO("Finished self testing");
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci	return err;
2828c2ecf20Sopenharmony_ci}
2838c2ecf20Sopenharmony_ci
2848c2ecf20Sopenharmony_ci#if IS_MODULE(CONFIG_BT)
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_ci/* This is run when CONFIG_BT_SELFTEST=y and CONFIG_BT=m and is just a
2878c2ecf20Sopenharmony_ci * wrapper to allow running this at module init.
2888c2ecf20Sopenharmony_ci *
2898c2ecf20Sopenharmony_ci * If CONFIG_BT_SELFTEST=n, then this code is not compiled at all.
2908c2ecf20Sopenharmony_ci */
2918c2ecf20Sopenharmony_ciint __init bt_selftest(void)
2928c2ecf20Sopenharmony_ci{
2938c2ecf20Sopenharmony_ci	return run_selftest();
2948c2ecf20Sopenharmony_ci}
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci#else
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci/* This is run when CONFIG_BT_SELFTEST=y and CONFIG_BT=y and is run
2998c2ecf20Sopenharmony_ci * via late_initcall() as last item in the initialization sequence.
3008c2ecf20Sopenharmony_ci *
3018c2ecf20Sopenharmony_ci * If CONFIG_BT_SELFTEST=n, then this code is not compiled at all.
3028c2ecf20Sopenharmony_ci */
3038c2ecf20Sopenharmony_cistatic int __init bt_selftest_init(void)
3048c2ecf20Sopenharmony_ci{
3058c2ecf20Sopenharmony_ci	return run_selftest();
3068c2ecf20Sopenharmony_ci}
3078c2ecf20Sopenharmony_cilate_initcall(bt_selftest_init);
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci#endif
310