NimBLE-Arduino 2.1.2
Loading...
Searching...
No Matches
ble_ead.h
1/*
2 * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
3 *
4 * SPDX-License-Identifier: Unlicense OR CC0-1.0
5 */
6
7#ifndef H_BLE_EAD_
8#define H_BLE_EAD_
9
10#include "nimble/porting/nimble/include/os/queue.h"
11#include <inttypes.h>
12#include "nimble/porting/nimble/include/syscfg/syscfg.h"
13#include "nimble/nimble/host/include/host/ble_gap.h"
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18#if MYNEWT_VAL(ENC_ADV_DATA)
19
21#define BLE_EAD_RANDOMIZER_SIZE 5
22
24#define BLE_EAD_KEY_SIZE 16
25
27#define BLE_EAD_IV_SIZE 8
28
30#define BLE_EAD_MIC_SIZE 4
31
33#define BLE_EAD_NONCE_SIZE 13
34
35/* This value is used to set the directionBit of the CCM nonce to the MSB of the Randomizer field
36 * (see Supplement to the Bluetooth Core Specification v11, Part A 1.23.3)
37 */
38#define BLE_EAD_RANDOMIZER_DIRECTION_BIT 7
39
41#define BLE_EAD_AAD_SIZE 1
42
43
47#define BLE_EAD_ENCRYPTED_PAYLOAD_SIZE(payload_size) \
48 ((payload_size) + BLE_EAD_RANDOMIZER_SIZE + BLE_EAD_MIC_SIZE)
49
53#define BLE_EAD_DECRYPTED_PAYLOAD_SIZE(encrypted_payload_size) \
54 ((encrypted_payload_size) - (BLE_EAD_RANDOMIZER_SIZE + BLE_EAD_MIC_SIZE))
55
56struct key_material {
57 uint8_t session_key[BLE_EAD_KEY_SIZE];
58 uint8_t iv[BLE_EAD_IV_SIZE];
59};
60
94int ble_ead_encrypt(const uint8_t session_key[BLE_EAD_KEY_SIZE],
95 const uint8_t iv[BLE_EAD_IV_SIZE], const uint8_t *payload,
96 size_t payload_size, uint8_t *encrypted_payload);
97
119int ble_ead_decrypt(const uint8_t session_key[BLE_EAD_KEY_SIZE],
120 const uint8_t iv[BLE_EAD_IV_SIZE], const uint8_t *encrypted_payload,
121 size_t encrypted_payload_size, uint8_t *payload);
122
123int ble_ead_serialize_data(const struct enc_adv_data *input, uint8_t *output);
124
125#endif /* ENC_ADV_DATA */
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif