2017-03-15 16:06:07 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016-2017 Nordic Semiconductor ASA
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2017-08-09 14:21:11 +08:00
|
|
|
#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER)
|
2018-07-17 15:35:52 +08:00
|
|
|
#define LOG_MODULE_NAME bt_ctlr_crypto
|
2017-05-10 22:27:16 +08:00
|
|
|
#include "common/log.h"
|
2020-01-30 01:44:25 +08:00
|
|
|
#include "../util/util.h"
|
2017-03-15 18:19:27 +08:00
|
|
|
|
|
|
|
#include "hal/ecb.h"
|
2017-03-15 16:06:07 +08:00
|
|
|
|
|
|
|
int bt_rand(void *buf, size_t len)
|
|
|
|
{
|
2020-01-30 01:44:25 +08:00
|
|
|
return util_rand(buf, len);
|
2017-03-15 16:06:07 +08:00
|
|
|
}
|
2017-03-15 18:19:27 +08:00
|
|
|
|
2017-04-21 01:00:29 +08:00
|
|
|
int bt_encrypt_le(const u8_t key[16], const u8_t plaintext[16],
|
|
|
|
u8_t enc_data[16])
|
2017-03-15 18:19:27 +08:00
|
|
|
{
|
2019-09-30 19:21:11 +08:00
|
|
|
BT_DBG("key %s", bt_hex(key, 16));
|
|
|
|
BT_DBG("plaintext %s", bt_hex(plaintext, 16));
|
2017-03-15 18:19:27 +08:00
|
|
|
|
|
|
|
ecb_encrypt(key, plaintext, enc_data, NULL);
|
|
|
|
|
|
|
|
BT_DBG("enc_data %s", bt_hex(enc_data, 16));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-03-16 16:56:35 +08:00
|
|
|
|
2017-04-21 01:00:29 +08:00
|
|
|
int bt_encrypt_be(const u8_t key[16], const u8_t plaintext[16],
|
|
|
|
u8_t enc_data[16])
|
2017-03-16 16:56:35 +08:00
|
|
|
{
|
2019-09-30 19:21:11 +08:00
|
|
|
BT_DBG("key %s", bt_hex(key, 16));
|
|
|
|
BT_DBG("plaintext %s", bt_hex(plaintext, 16));
|
2017-03-16 16:56:35 +08:00
|
|
|
|
|
|
|
ecb_encrypt_be(key, plaintext, enc_data);
|
|
|
|
|
|
|
|
BT_DBG("enc_data %s", bt_hex(enc_data, 16));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|