40#define USE_SMP_CRYPTO_AES128_ 1
42#define USE_SMP_CRYPTO_F5_ 0
47#include <tinycrypt/constants.h>
49#if USE_SMP_CRYPTO_AES128_
50 #include <tinycrypt/aes.h>
52#if USE_SMP_CRYPTO_CMAC_
54 #include <tinycrypt/cmac_mode.h>
74 uint8_t *pdst = (uint8_t *)dst;
75 const uint8_t *psrc = (
const uint8_t *)src;
84 for (; length > 0; length--) {
103 for (i = 0; i < (length/2); i++) {
104 uint8_t tmp = ((uint8_t *)buf)[i];
106 ((uint8_t *)buf)[i] = ((uint8_t *)buf)[length - 1 - i];
107 ((uint8_t *)buf)[length - 1 - i] = tmp;
112 uint8_t enc_data[16])
114 struct tc_aes_key_sched_struct s;
122 if (tc_aes128_set_encrypt_key(&s, tmp) == TC_CRYPTO_FAIL) {
128 if (tc_aes_encrypt(enc_data, tmp, &s) == TC_CRYPTO_FAIL) {
139static int smp_crypto_ah(
const uint8_t irk[16],
const uint8_t r[3], uint8_t out[3])
148 std::memcpy(res, r, 3);
149 (void)std::memset(res + 3, 0, 13);
162 std::memcpy(out, res, 3);
177 return !memcmp(rpa.b, hash, 3);
180#if USE_SMP_CRYPTO_F5_
192#if defined(USE_SMP_CRYPTO_CMAC_) && defined(USE_SMP_CRYPTO_AES128_)
193 struct tc_aes_key_sched_struct sched;
194 struct tc_cmac_struct state;
196 if (tc_cmac_setup(&state, key.
data, &sched) == TC_CRYPTO_FAIL) {
199 if (tc_cmac_update(&state, in, len) == TC_CRYPTO_FAIL) {
202 if (tc_cmac_final(out.
data, &state) == TC_CRYPTO_FAIL) {
227 const BDAddressAndType& a1,
const BDAddressAndType& a2,
236 0xa5, 0x38, 0x60, 0x37, 0x0b, 0xdb,
237 0x5a, 0x60, 0x83, 0xbe } );
240 uint8_t m[53] = { 0x00,
241 0x62, 0x74, 0x6c, 0x65,
242 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
243 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
244 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 if( bt_smp_aes_cmac(salt, ws, 32, t) ) {
266 if constexpr ( jau::isLittleEndian() ) {
270 if constexpr ( jau::isLittleEndian() ) {
274 if( !bt_smp_aes_cmac(t, m,
sizeof(m), temp_) ) {
283 if( !bt_smp_aes_cmac(t, m,
sizeof(m), temp_) ) {
constexpr const bool USE_SMP_CRYPTO_IRK
constexpr const bool USE_SMP_CRYPTO_F5
#define DBG_PRINT(...)
Use for environment-variable environment::DEBUG conditional debug messages, prefix '[elapsed_time] De...
constexpr uint16_t bswap(uint16_t const source) noexcept
std::string bytesHexString(const void *data, const nsize_t offset, const nsize_t length, const bool lsbFirst, const bool lowerCase=true) noexcept
Produce a hexadecimal string representation of the given byte values.
static void sys_memcpy_swap(void *dst, const void *src, size_t length)
Swap one buffer content into another.
static int bt_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16], uint8_t enc_data[16])
bool smp_crypto_rpa_irk_matches(const jau::uint128dp_t irk, const EUI48 &rpa) noexcept
Returns true if the given IRK matches the given random private address (RPA).
static int smp_crypto_ah(const uint8_t irk[16], const uint8_t r[3], uint8_t out[3])
static void sys_mem_swap(void *buf, size_t length)
Swap buffer content.
bool smp_crypto_f5(const jau::uint256dp_t w, const jau::uint128dp_t n1, const jau::uint128dp_t n2, const BDAddressAndType &a1, const BDAddressAndType &a2, jau::uint128dp_t &mackey, jau::uint128dp_t <k) noexcept
A packed 48 bit EUI-48 identifier, formerly known as MAC-48 or simply network device MAC address (Med...
A 128-bit packed uint8_t data array.