Zephyr Project API 4.0.0
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
Encrypted Advertising Data (EAD)

Encrypted Advertising Data (EAD) More...

Macros

#define BT_EAD_RANDOMIZER_SIZE   5
 Randomizer size in bytes.
 
#define BT_EAD_KEY_SIZE   16
 Key size in bytes.
 
#define BT_EAD_IV_SIZE   8
 Initialisation Vector size in bytes.
 
#define BT_EAD_MIC_SIZE   4
 MIC size in bytes.
 
#define BT_EAD_ENCRYPTED_PAYLOAD_SIZE(payload_size)    ((payload_size) + BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE)
 Get the size (in bytes) of the encrypted advertising data for a given payload size in bytes.
 
#define BT_EAD_DECRYPTED_PAYLOAD_SIZE(encrypted_payload_size)    ((encrypted_payload_size) - (BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE))
 Get the size (in bytes) of the decrypted payload for a given payload size in bytes.
 

Functions

int bt_ead_encrypt (const uint8_t session_key[16], const uint8_t iv[8], const uint8_t *payload, size_t payload_size, uint8_t *encrypted_payload)
 Encrypt and authenticate the given advertising data.
 
int bt_ead_decrypt (const uint8_t session_key[16], const uint8_t iv[8], const uint8_t *encrypted_payload, size_t encrypted_payload_size, uint8_t *payload)
 Decrypt and authenticate the given encrypted advertising data.
 

Detailed Description

Encrypted Advertising Data (EAD)

Macro Definition Documentation

◆ BT_EAD_DECRYPTED_PAYLOAD_SIZE

#define BT_EAD_DECRYPTED_PAYLOAD_SIZE (   encrypted_payload_size)     ((encrypted_payload_size) - (BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE))

#include <include/zephyr/bluetooth/ead.h>

Get the size (in bytes) of the decrypted payload for a given payload size in bytes.

◆ BT_EAD_ENCRYPTED_PAYLOAD_SIZE

#define BT_EAD_ENCRYPTED_PAYLOAD_SIZE (   payload_size)     ((payload_size) + BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE)

#include <include/zephyr/bluetooth/ead.h>

Get the size (in bytes) of the encrypted advertising data for a given payload size in bytes.

◆ BT_EAD_IV_SIZE

#define BT_EAD_IV_SIZE   8

#include <include/zephyr/bluetooth/ead.h>

Initialisation Vector size in bytes.

◆ BT_EAD_KEY_SIZE

#define BT_EAD_KEY_SIZE   16

#include <include/zephyr/bluetooth/ead.h>

Key size in bytes.

◆ BT_EAD_MIC_SIZE

#define BT_EAD_MIC_SIZE   4

#include <include/zephyr/bluetooth/ead.h>

MIC size in bytes.

◆ BT_EAD_RANDOMIZER_SIZE

#define BT_EAD_RANDOMIZER_SIZE   5

#include <include/zephyr/bluetooth/ead.h>

Randomizer size in bytes.

Function Documentation

◆ bt_ead_decrypt()

int bt_ead_decrypt ( const uint8_t  session_key[16],
const uint8_t  iv[8],
const uint8_t encrypted_payload,
size_t  encrypted_payload_size,
uint8_t payload 
)

#include <include/zephyr/bluetooth/ead.h>

Decrypt and authenticate the given encrypted advertising data.

Note
The term advertising structure is used to describe the advertising data with the advertising type and the length of those two.
Parameters
[in]session_keyKey of 16 bytes used for the encryption.
[in]ivInitialisation Vector used to generate the nonce.
[in]encrypted_payloadEncrypted Advertising Data received. This should only contain the advertising data from the received advertising structure, not the length nor the type.
[in]encrypted_payload_sizeSize of the received advertising data in bytes. Should be equal to the length field of the received advertising structure, minus the size of the type (1 byte).
[out]payloadDecrypted advertising payload. Use BT_EAD_DECRYPTED_PAYLOAD_SIZE to get the right size.
Return values
0Data have been correctly decrypted and authenticated.
-EIOError occurred during the decryption or the authentication.
-EINVALOne of the argument is a NULL pointer or encrypted_payload_size is less than BT_EAD_RANDOMIZER_SIZE + BT_EAD_MIC_SIZE.

◆ bt_ead_encrypt()

int bt_ead_encrypt ( const uint8_t  session_key[16],
const uint8_t  iv[8],
const uint8_t payload,
size_t  payload_size,
uint8_t encrypted_payload 
)

#include <include/zephyr/bluetooth/ead.h>

Encrypt and authenticate the given advertising data.

The resulting data in encrypted_payload will look like that:

Attention
The function must be called each time the RPA is updated or the data are modified.
Note
The term advertising structure is used to describe the advertising data with the advertising type and the length of those two.
Parameters
[in]session_keyKey of BT_EAD_KEY_SIZE bytes used for the encryption.
[in]ivInitialisation Vector used to generate the nonce. It must be changed each time the Session Key changes.
[in]payloadAdvertising Data to encrypt. Can be multiple advertising structures that are concatenated.
[in]payload_sizeSize of the Advertising Data to encrypt.
[out]encrypted_payloadEncrypted Ad Data including the Randomizer and the MIC. Size must be at least BT_EAD_RANDOMIZER_SIZE + payload_size + BT_EAD_MIC_SIZE. Use BT_EAD_ENCRYPTED_PAYLOAD_SIZE to get the right size.
Return values
0Data have been correctly encrypted and authenticated.
-EIOError occurred during the encryption or the authentication.
-EINVALOne of the argument is a NULL pointer.
-ECANCELEDError occurred during the random number generation.