1 /*
2  * Copyright (c) 2016-2017 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "common/bt_str.h"
8 
9 #include "util/memq.h"
10 
11 #include "hal/ecb.h"
12 #include "ll_sw/lll.h"
13 
14 #define LOG_LEVEL CONFIG_BT_HCI_DRIVER_LOG_LEVEL
15 #include <zephyr/logging/log.h>
16 LOG_MODULE_REGISTER(bt_ctlr_crypto);
17 
bt_rand(void * buf,size_t len)18 int bt_rand(void *buf, size_t len)
19 {
20 	return lll_csrand_get(buf, len);
21 }
22 
bt_encrypt_le(const uint8_t key[16],const uint8_t plaintext[16],uint8_t enc_data[16])23 int bt_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
24 		  uint8_t enc_data[16])
25 {
26 	LOG_DBG("key %s", bt_hex(key, 16));
27 	LOG_DBG("plaintext %s", bt_hex(plaintext, 16));
28 
29 	ecb_encrypt(key, plaintext, enc_data, NULL);
30 
31 	LOG_DBG("enc_data %s", bt_hex(enc_data, 16));
32 
33 	return 0;
34 }
35 
bt_encrypt_be(const uint8_t key[16],const uint8_t plaintext[16],uint8_t enc_data[16])36 int bt_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
37 		  uint8_t enc_data[16])
38 {
39 	LOG_DBG("key %s", bt_hex(key, 16));
40 	LOG_DBG("plaintext %s", bt_hex(plaintext, 16));
41 
42 	ecb_encrypt_be(key, plaintext, enc_data);
43 
44 	LOG_DBG("enc_data %s", bt_hex(enc_data, 16));
45 
46 	return 0;
47 }
48