Stair56E UART project

This commit is contained in:
2026-08-05 19:07:52 +08:00
parent 7ca1af130d
commit f5654b70cc
2500 changed files with 619007 additions and 282610 deletions
+402 -402
View File
@@ -1,402 +1,402 @@
/**
****************************************************************************************
*
* @file aes.h
*
* @brief Header file for AES crypto module
*
* Copyright (C) RivieraWaves 2017-2018
*
****************************************************************************************
*/
#ifndef AES_H_
#define AES_H_
/**
****************************************************************************************
* @defgroup AES Crypto module
* @ingroup ROOT
* @brief AES Crypto module
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h"
#include "co_bt.h" // Common defines
/*
* Defines
****************************************************************************************
*/
/// Size of an a AES Message block in bytes
#define AES_BLOCK_SIZE 16
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Call back definition of the function that can handle result of an AES based algorithm
*
* @param[in] status Execution status
* @param[in] aes_res 16 bytes block result
* @param[in] src_info Information provided by requester
****************************************************************************************
*/
typedef void (*aes_func_result_cb) (uint8_t status, const uint8_t* aes_res, uint32_t src_info);
/**
****************************************************************************************
* @brief Call back definition of the function that can handle result of AES-CCM Cipher/Decipher
*
* @param[in] mic_error True if a MIC error detected when Decipher, False else
* In case of MIC error output message is considered invalid
* @param[in] src_info Information provided by requester
****************************************************************************************
*/
typedef void (*aes_ccm_func_result_cb) (bool mic_error, uint32_t src_info);
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Call back definition of the Resolvable Private Address resolution function
*
* @param[in] index Index of the IRK used to resolve the provided RPA (number of IRK if not resolved)
* @param[in] src_info Information provided by requester
****************************************************************************************
*/
typedef void (*aes_rpa_func_result_cb) (uint8_t index, uint32_t src_info);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize AES function management
*
* @param[in] init_type Type of initialization (@see enum rwip_init_type)
****************************************************************************************
*/
void aes_init(uint8_t init_type);
/**
****************************************************************************************
* @brief Handler of AES execution (HW accelerator if BLE controller present, HCI Encrypt for BLE Host Stack)
*
* @param[in] status Status of AES execution
* @param[in] result 16 bytes result of AES execution
****************************************************************************************
*/
void aes_result_handler(uint8_t status, uint8_t* result);
/**
****************************************************************************************
* @brief Perform an AES encryption - result within callback
* @param[in] key Key used for the encryption
* @param[in] val Value to encrypt using AES
* @param[in] copy Copy parameters because source is destroyed
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_encrypt(const uint8_t* key, const uint8_t *val, bool copy, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Generate a random number using AES encryption - result within callback
*
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_rand(aes_func_result_cb res_cb, uint32_t src_info);
#if (BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Compute Confirm value
*
* @param[in] k Key used for aes functions
* @param[in] r Random number
* @param[in] p1 p1 = pres || preq || rat || iat
* @param[in] p2 p2 = padding || ia || ra
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_c1(const uint8_t* k, const uint8_t* r, const uint8_t* p1, const uint8_t* p2,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Confirm Value Generation Function f4
*
* @param[in] u U is 256 bits
* @param[in] v V is 256 bits
* @param[in] x X is 128 bits
* @param[in] z Z is 8 bits
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_f4(const uint8_t* u, const uint8_t* v, const uint8_t* x, uint8_t z,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Key Generation Function f5
*
* @param[in] w W is 256 bits
* @param[in] n1 N1 is 128 bits
* @param[in] n2 N2 is 128 bits
* @param[in] a1 A1 is 56 bits
* @param[in] a2 A2 is 56 bits
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_f5(const uint8_t* w, const uint8_t* n1, const uint8_t* n2, const uint8_t* a1, const uint8_t* a2,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Check Value Generation Function f6
*
* @param[in] w W is 128 bits
* @param[in] n1 N1 is 128 bits
* @param[in] n2 N2 is 128 bits
* @param[in] r R is 128 bits
* @param[in] iocap IOcap is 24 bits
* @param[in] a1 A1 is 56 bits
* @param[in] a2 A2 is 56 bits
*
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_f6(const uint8_t* w, const uint8_t* n1, const uint8_t* n2, const uint8_t* r, const uint8_t* iocap,
const uint8_t* a1, const uint8_t* a2, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Numeric Comparison Value Generation Function g2
*
* @param[in] u U is 256 bits
* @param[in] v V is 256 bits
* @param[in] x X is 128 bits
* @param[in] y Y is 128 bits
*
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_g2(const uint8_t* u, const uint8_t* v, const uint8_t* x, const uint8_t* y,
aes_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_HOST_PRESENT)
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Start the AES CMAC crypto function. Allocate memory for the CMAC and
* begins the subkey generation
*
* @param[in] key Pointer to the Key to be used
* @param[in] message Pointer to the block of data the data on which the CMAC is performed
* @param[in] message_len Length (in bytes) of the block of data M
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_cmac(const uint8_t* key, const uint8_t* message, uint16_t message_len,
aes_func_result_cb res_cb, uint32_t src_info);
#if (BLE_MESH)
/**
****************************************************************************************
* @brief Start the AES S1 crypto function.
*
* @param[in] message Message used to generate Salted key
* @param[in] message_len Length (in bytes) of the block of data M
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_s1(const uint8_t* message, uint8_t message_len, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K1 crypto function.
*
* @param[in] salt Salted Key to use
* @param[in] n Value of N
* @param[in] n_len Length of N
* @param[in] p Value of P
* @param[in] p_len Length of P
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k1(const uint8_t* salt, const uint8_t* n, uint8_t n_len, const uint8_t* p, uint8_t p_len,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K2 crypto function.
*
* @param[in] n Value of N - 128 bits
* @param[in] p Value of P
* @param[in] p_len Length of P
* @param[in] res_cb Function that will handle the AES based result (33 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k2(const uint8_t* n, const uint8_t* p, uint8_t p_len, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K3 crypto function.
*
* @param[in] n Value of N - 128 bits
* @param[in] res_cb Function that will handle the AES based result (8 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k3(const uint8_t* n, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K4 crypto function.
*
* @param[in] n Value of N - 128 bits
* @param[in] res_cb Function that will handle the AES based result (1 byte)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k4(const uint8_t* n, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES CCM crypto function. Allocate memory for the CCM and start processing it
* Execute result callback at end of function execution
*
* @param[in] key Pointer to the Key to be used
* @param[in] nonce 13 Bytes Nonce to use for cipher/decipher
* @param[in] in_message Input message for AES-CCM exectuion
* @param[out] out_message Output message that will contain cipher+mic or decipher data
* @param[in] message_len Length of Input/Output message without mic
* @param[in] mic_len Length of the mic to use (2, 4, 6, 8, 10, 12, 14, 16 valid)
* @param[in] cipher True to encrypt message, False to decrypt it.
* @param[in] add_auth_data Additional Authentication data used for computation of MIC
* @param[in] add_auth_data_len Length of Additional Authentication data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_ccm(const uint8_t* key, const uint8_t* nonce, const uint8_t* in_message,
uint8_t* out_message, uint16_t message_len, uint8_t mic_len, bool cipher,
const uint8_t* add_auth_data, uint8_t add_auth_data_len, aes_ccm_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_MESH)
/**
****************************************************************************************
* @brief Key Conversion Function h6
*
* @param[in] w W is a 128bits data
* @param[in] keyId KeyID is a 32 bits data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h6(const uint8_t* w, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Key Conversion Function h7
*
* @param[in] salt SALT is a 128bits data
* @param[in] w W is a 128bits key
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h7(const uint8_t* salt, const uint8_t* w, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Group Session Key Derivation Function h8
*
* @param[in] k K is a 128bits data
* @param[in] s S is a 128bits key
* @param[in] keyId KeyID is a 32 bits data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h8(const uint8_t* k, const uint8_t* s, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Group Long Term Key Generation Function h9
*
* @param[in] w W is a 128bits data
* @param[in] keyId KeyID is a 32 bits data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h9(const uint8_t* w, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Resolvable Private Address generation Function
*
* @param[in] irk Pointer to IRK (local IRK to generate a local RPA)
* @param[in] res_cb Function that will handle the AES RPA generation result (address generated in the 6 LSBs of the returned buffer)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_rpa_gen(struct irk* irk, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Resolvable Private Address resolution Function
*
* @param[in] nb_irk Number of IRKs provided
* @param[in] irk Table of IRKs (stored internally to AES RPA, caller can destroy the table)
* @param[in] addr BD address to resolve
* @param[in] res_cb Function that will handle the AES RPA resolution result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_rpa_resolve(uint8_t nb_irk, struct irk* irk, struct bd_addr* addr, aes_rpa_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/// @} AES
///
#endif /* AES_H_ */
/**
****************************************************************************************
*
* @file aes.h
*
* @brief Header file for AES crypto module
*
* Copyright (C) RivieraWaves 2017-2018
*
****************************************************************************************
*/
#ifndef AES_H_
#define AES_H_
/**
****************************************************************************************
* @defgroup AES Crypto module
* @ingroup ROOT
* @brief AES Crypto module
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h"
#include "co_bt.h" // Common defines
/*
* Defines
****************************************************************************************
*/
/// Size of an a AES Message block in bytes
#define AES_BLOCK_SIZE 16
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Call back definition of the function that can handle result of an AES based algorithm
*
* @param[in] status Execution status
* @param[in] aes_res 16 bytes block result
* @param[in] src_info Information provided by requester
****************************************************************************************
*/
typedef void (*aes_func_result_cb) (uint8_t status, const uint8_t* aes_res, uint32_t src_info);
/**
****************************************************************************************
* @brief Call back definition of the function that can handle result of AES-CCM Cipher/Decipher
*
* @param[in] mic_error True if a MIC error detected when Decipher, False else
* In case of MIC error output message is considered invalid
* @param[in] src_info Information provided by requester
****************************************************************************************
*/
typedef void (*aes_ccm_func_result_cb) (bool mic_error, uint32_t src_info);
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Call back definition of the Resolvable Private Address resolution function
*
* @param[in] index Index of the IRK used to resolve the provided RPA (number of IRK if not resolved)
* @param[in] src_info Information provided by requester
****************************************************************************************
*/
typedef void (*aes_rpa_func_result_cb) (uint8_t index, uint32_t src_info);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize AES function management
*
* @param[in] init_type Type of initialization (@see enum rwip_init_type)
****************************************************************************************
*/
void aes_init(uint8_t init_type);
/**
****************************************************************************************
* @brief Handler of AES execution (HW accelerator if BLE controller present, HCI Encrypt for BLE Host Stack)
*
* @param[in] status Status of AES execution
* @param[in] result 16 bytes result of AES execution
****************************************************************************************
*/
void aes_result_handler(uint8_t status, uint8_t* result);
/**
****************************************************************************************
* @brief Perform an AES encryption - result within callback
* @param[in] key Key used for the encryption
* @param[in] val Value to encrypt using AES
* @param[in] copy Copy parameters because source is destroyed
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_encrypt(const uint8_t* key, const uint8_t *val, bool copy, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Generate a random number using AES encryption - result within callback
*
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_rand(aes_func_result_cb res_cb, uint32_t src_info);
#if (BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Compute Confirm value
*
* @param[in] k Key used for aes functions
* @param[in] r Random number
* @param[in] p1 p1 = pres || preq || rat || iat
* @param[in] p2 p2 = padding || ia || ra
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_c1(const uint8_t* k, const uint8_t* r, const uint8_t* p1, const uint8_t* p2,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Confirm Value Generation Function f4
*
* @param[in] u U is 256 bits
* @param[in] v V is 256 bits
* @param[in] x X is 128 bits
* @param[in] z Z is 8 bits
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_f4(const uint8_t* u, const uint8_t* v, const uint8_t* x, uint8_t z,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Key Generation Function f5
*
* @param[in] w W is 256 bits
* @param[in] n1 N1 is 128 bits
* @param[in] n2 N2 is 128 bits
* @param[in] a1 A1 is 56 bits
* @param[in] a2 A2 is 56 bits
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_f5(const uint8_t* w, const uint8_t* n1, const uint8_t* n2, const uint8_t* a1, const uint8_t* a2,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Check Value Generation Function f6
*
* @param[in] w W is 128 bits
* @param[in] n1 N1 is 128 bits
* @param[in] n2 N2 is 128 bits
* @param[in] r R is 128 bits
* @param[in] iocap IOcap is 24 bits
* @param[in] a1 A1 is 56 bits
* @param[in] a2 A2 is 56 bits
*
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_f6(const uint8_t* w, const uint8_t* n1, const uint8_t* n2, const uint8_t* r, const uint8_t* iocap,
const uint8_t* a1, const uint8_t* a2, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Compute LE Secure Connections Numeric Comparison Value Generation Function g2
*
* @param[in] u U is 256 bits
* @param[in] v V is 256 bits
* @param[in] x X is 128 bits
* @param[in] y Y is 128 bits
*
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_g2(const uint8_t* u, const uint8_t* v, const uint8_t* x, const uint8_t* y,
aes_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_HOST_PRESENT)
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Start the AES CMAC crypto function. Allocate memory for the CMAC and
* begins the subkey generation
*
* @param[in] key Pointer to the Key to be used
* @param[in] message Pointer to the block of data the data on which the CMAC is performed
* @param[in] message_len Length (in bytes) of the block of data M
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_cmac(const uint8_t* key, const uint8_t* message, uint16_t message_len,
aes_func_result_cb res_cb, uint32_t src_info);
#if (BLE_MESH)
/**
****************************************************************************************
* @brief Start the AES S1 crypto function.
*
* @param[in] message Message used to generate Salted key
* @param[in] message_len Length (in bytes) of the block of data M
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_s1(const uint8_t* message, uint8_t message_len, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K1 crypto function.
*
* @param[in] salt Salted Key to use
* @param[in] n Value of N
* @param[in] n_len Length of N
* @param[in] p Value of P
* @param[in] p_len Length of P
* @param[in] res_cb Function that will handle the AES based result (16 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k1(const uint8_t* salt, const uint8_t* n, uint8_t n_len, const uint8_t* p, uint8_t p_len,
aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K2 crypto function.
*
* @param[in] n Value of N - 128 bits
* @param[in] p Value of P
* @param[in] p_len Length of P
* @param[in] res_cb Function that will handle the AES based result (33 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k2(const uint8_t* n, const uint8_t* p, uint8_t p_len, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K3 crypto function.
*
* @param[in] n Value of N - 128 bits
* @param[in] res_cb Function that will handle the AES based result (8 bytes)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k3(const uint8_t* n, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES K4 crypto function.
*
* @param[in] n Value of N - 128 bits
* @param[in] res_cb Function that will handle the AES based result (1 byte)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_k4(const uint8_t* n, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Start the AES CCM crypto function. Allocate memory for the CCM and start processing it
* Execute result callback at end of function execution
*
* @param[in] key Pointer to the Key to be used
* @param[in] nonce 13 Bytes Nonce to use for cipher/decipher
* @param[in] in_message Input message for AES-CCM exectuion
* @param[out] out_message Output message that will contain cipher+mic or decipher data
* @param[in] message_len Length of Input/Output message without mic
* @param[in] mic_len Length of the mic to use (2, 4, 6, 8, 10, 12, 14, 16 valid)
* @param[in] cipher True to encrypt message, False to decrypt it.
* @param[in] add_auth_data Additional Authentication data used for computation of MIC
* @param[in] add_auth_data_len Length of Additional Authentication data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_ccm(const uint8_t* key, const uint8_t* nonce, const uint8_t* in_message,
uint8_t* out_message, uint16_t message_len, uint8_t mic_len, bool cipher,
const uint8_t* add_auth_data, uint8_t add_auth_data_len, aes_ccm_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_MESH)
/**
****************************************************************************************
* @brief Key Conversion Function h6
*
* @param[in] w W is a 128bits data
* @param[in] keyId KeyID is a 32 bits data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h6(const uint8_t* w, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Key Conversion Function h7
*
* @param[in] salt SALT is a 128bits data
* @param[in] w W is a 128bits key
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h7(const uint8_t* salt, const uint8_t* w, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Group Session Key Derivation Function h8
*
* @param[in] k K is a 128bits data
* @param[in] s S is a 128bits key
* @param[in] keyId KeyID is a 32 bits data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h8(const uint8_t* k, const uint8_t* s, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Group Long Term Key Generation Function h9
*
* @param[in] w W is a 128bits data
* @param[in] keyId KeyID is a 32 bits data
* @param[in] res_cb Function that will handle the AES CCM result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_h9(const uint8_t* w, const uint8_t* key_id, aes_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Resolvable Private Address generation Function
*
* @param[in] irk Pointer to IRK (local IRK to generate a local RPA)
* @param[in] res_cb Function that will handle the AES RPA generation result (address generated in the 6 LSBs of the returned buffer)
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_rpa_gen(struct irk* irk, aes_func_result_cb res_cb, uint32_t src_info);
/**
****************************************************************************************
* @brief Resolvable Private Address resolution Function
*
* @param[in] nb_irk Number of IRKs provided
* @param[in] irk Table of IRKs (stored internally to AES RPA, caller can destroy the table)
* @param[in] addr BD address to resolve
* @param[in] res_cb Function that will handle the AES RPA resolution result
* @param[in] src_info Information used retrieve requester
****************************************************************************************
*/
void aes_rpa_resolve(uint8_t nb_irk, struct irk* irk, struct bd_addr* addr, aes_rpa_func_result_cb res_cb, uint32_t src_info);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/// @} AES
///
#endif /* AES_H_ */
+197 -197
View File
@@ -1,197 +1,197 @@
/**
****************************************************************************************
*
* @file aes_int.h
*
* @brief Header file for AES Internal crypto module
*
* Copyright (C) RivieraWaves 2017-2018
*
****************************************************************************************
*/
#ifndef AES_INT_H_
#define AES_INT_H_
/**
****************************************************************************************
* @defgroup AES_INT
* @ingroup AES
* @brief AES_INT Crypto internal definitions
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h"
#include "aes.h"
#include "co_bt.h" // Common defines
#include "co_list.h" // List usage
/*
* Defines
****************************************************************************************
*/
// Size of an a AES Message block in bytes
#define AES_BLOCK_SIZE 16
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
struct aes_func_env;
/**
****************************************************************************************
* Callback used to continue execution of the AES based function.
*
* @param[in] aes_result Result of the AES (aes(key , val))
*
* @return True if function execution is over
****************************************************************************************
*/
typedef bool (*aes_func_continue_cb) (struct aes_func_env* aes_env, uint8_t* aes_result);
/// Environment variable required for an AES based function
/// This structure must be Header of all function environment variables
struct aes_func_env
{
/// used to put AES function in the AES execution queue
struct co_list_hdr hdr;
/// AES continue callback
aes_func_continue_cb aes_continue_cb;
/// AES End callback
aes_func_result_cb aes_res_cb;
/// Key to use for the AES execution
const uint8_t* key;
/// Value to use for AES Cypher/Decypher
const uint8_t* val;
/// Information put in source id message to retrieve requester
uint32_t src_info;
};
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
// Structure definition of the AES CMAC algorithm
struct aes_cmac_env
{
/// AES Environment structure
struct aes_func_env aes_env;
/// M: Pointer to the message to be authenticated
const uint8_t* message; // pointer to memory allocated by calling function
/// K: authentication key
const uint8_t* auth_key;
/// T: message authentication code
uint8_t auth_code[AES_BLOCK_SIZE];
/// Length of the message
uint16_t message_len;
/// Number of blocks (1 block = 16 bytes)
uint8_t num_blocks;
/// Current block to process
uint8_t cur_block;
};
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/*
* GLOBAL VARIABLE DECLARATIONS
****************************************************************************************
*/
/// zero block
extern const uint8_t aes_cmac_zero[AES_BLOCK_SIZE];
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Allocate environment for the AES based function execution
*
* @param[in] size Size of the environment to allocate (must be >= sizeof(struct aes_func_env))
* @param[in] aes_continue_cb Callback used to send the AES result
* @param[in] res_cb Function that will handle end of AES Based algorithm
* @param[in] src_info Information used to retrieve requester
*
* @return Allocated environment variable
****************************************************************************************
*/
struct aes_func_env* aes_alloc(uint16_t size, aes_func_continue_cb aes_continue_cb, aes_func_result_cb res_cb,
uint32_t src_info);
/**
****************************************************************************************
* @brief AES Cypher request function.
*
* This will queue AES request in the AES execution queue
* When the AES result is received, the AES continue callback is executed.
*
* If AES continue function returns that AES execution is over, a message will be send to destination task
* with latest AES result.
*
* @param[in] env AES environment
* @param[in] key Key used for cyphering
* @param[in] val Value to cypher
****************************************************************************************
*/
void aes_start(struct aes_func_env* env, const uint8_t* key, const uint8_t *val);
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Start the AES CMAC crypto function. Allocate memory for the CMAC and
* begins the subkey generation
*
* @param[in] enc AES CMAC Environment
* @param[in] key Pointer to the Key to be used
* @param[in] message Pointer to the block of data the data on which the CMAC is performed
* @param[in] message_len Length (in bytes) of the block of data M
****************************************************************************************
*/
void aes_cmac_start(struct aes_cmac_env* env, const uint8_t* key, const uint8_t* message, uint16_t message_len);
/**
****************************************************************************************
* @brief Continue AES CMAC algorithm
*
* @param[in] env AES CMAC Environment
* @param[in] aes_res AES Result
*
* @return True if algorithm is over, False else
****************************************************************************************
*/
bool aes_cmac_continue(struct aes_cmac_env* env, uint8_t* aes_res);
/**
* @brief Perform a XOR of two numbers.
*
* @param[out] result Output 128 bits number: result = a ^ b
* @param[in] a first 128 bits operand
* @param[in] b second 128 bits operand
* @param[in] size number of bytes to XOR
*/
void aes_xor_128(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size);
/**
* @brief Perform shift left of a 128 bits numvber
*
* @param[in] input Input 128 bits number
* @param[out] output Output 128 bits number: output = input << 1
*/
void aes_shift_left_128(const uint8_t* input,uint8_t* output);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/// @} AES_INT
///
#endif /* AES_INT_H_ */
/**
****************************************************************************************
*
* @file aes_int.h
*
* @brief Header file for AES Internal crypto module
*
* Copyright (C) RivieraWaves 2017-2018
*
****************************************************************************************
*/
#ifndef AES_INT_H_
#define AES_INT_H_
/**
****************************************************************************************
* @defgroup AES_INT
* @ingroup AES
* @brief AES_INT Crypto internal definitions
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h"
#include "aes.h"
#include "co_bt.h" // Common defines
#include "co_list.h" // List usage
/*
* Defines
****************************************************************************************
*/
// Size of an a AES Message block in bytes
#define AES_BLOCK_SIZE 16
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
struct aes_func_env;
/**
****************************************************************************************
* Callback used to continue execution of the AES based function.
*
* @param[in] aes_result Result of the AES (aes(key , val))
*
* @return True if function execution is over
****************************************************************************************
*/
typedef bool (*aes_func_continue_cb) (struct aes_func_env* aes_env, uint8_t* aes_result);
/// Environment variable required for an AES based function
/// This structure must be Header of all function environment variables
struct aes_func_env
{
/// used to put AES function in the AES execution queue
struct co_list_hdr hdr;
/// AES continue callback
aes_func_continue_cb aes_continue_cb;
/// AES End callback
aes_func_result_cb aes_res_cb;
/// Key to use for the AES execution
const uint8_t* key;
/// Value to use for AES Cypher/Decypher
const uint8_t* val;
/// Information put in source id message to retrieve requester
uint32_t src_info;
};
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
// Structure definition of the AES CMAC algorithm
struct aes_cmac_env
{
/// AES Environment structure
struct aes_func_env aes_env;
/// M: Pointer to the message to be authenticated
const uint8_t* message; // pointer to memory allocated by calling function
/// K: authentication key
const uint8_t* auth_key;
/// T: message authentication code
uint8_t auth_code[AES_BLOCK_SIZE];
/// Length of the message
uint16_t message_len;
/// Number of blocks (1 block = 16 bytes)
uint8_t num_blocks;
/// Current block to process
uint8_t cur_block;
};
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/*
* GLOBAL VARIABLE DECLARATIONS
****************************************************************************************
*/
/// zero block
extern const uint8_t aes_cmac_zero[AES_BLOCK_SIZE];
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Allocate environment for the AES based function execution
*
* @param[in] size Size of the environment to allocate (must be >= sizeof(struct aes_func_env))
* @param[in] aes_continue_cb Callback used to send the AES result
* @param[in] res_cb Function that will handle end of AES Based algorithm
* @param[in] src_info Information used to retrieve requester
*
* @return Allocated environment variable
****************************************************************************************
*/
struct aes_func_env* aes_alloc(uint16_t size, aes_func_continue_cb aes_continue_cb, aes_func_result_cb res_cb,
uint32_t src_info);
/**
****************************************************************************************
* @brief AES Cypher request function.
*
* This will queue AES request in the AES execution queue
* When the AES result is received, the AES continue callback is executed.
*
* If AES continue function returns that AES execution is over, a message will be send to destination task
* with latest AES result.
*
* @param[in] env AES environment
* @param[in] key Key used for cyphering
* @param[in] val Value to cypher
****************************************************************************************
*/
void aes_start(struct aes_func_env* env, const uint8_t* key, const uint8_t *val);
#if (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/**
****************************************************************************************
* @brief Start the AES CMAC crypto function. Allocate memory for the CMAC and
* begins the subkey generation
*
* @param[in] enc AES CMAC Environment
* @param[in] key Pointer to the Key to be used
* @param[in] message Pointer to the block of data the data on which the CMAC is performed
* @param[in] message_len Length (in bytes) of the block of data M
****************************************************************************************
*/
void aes_cmac_start(struct aes_cmac_env* env, const uint8_t* key, const uint8_t* message, uint16_t message_len);
/**
****************************************************************************************
* @brief Continue AES CMAC algorithm
*
* @param[in] env AES CMAC Environment
* @param[in] aes_res AES Result
*
* @return True if algorithm is over, False else
****************************************************************************************
*/
bool aes_cmac_continue(struct aes_cmac_env* env, uint8_t* aes_res);
/**
* @brief Perform a XOR of two numbers.
*
* @param[out] result Output 128 bits number: result = a ^ b
* @param[in] a first 128 bits operand
* @param[in] b second 128 bits operand
* @param[in] size number of bytes to XOR
*/
void aes_xor_128(uint8_t* result, const uint8_t* a, const uint8_t* b, uint8_t size);
/**
* @brief Perform shift left of a 128 bits numvber
*
* @param[in] input Input 128 bits number
* @param[out] output Output 128 bits number: output = input << 1
*/
void aes_shift_left_128(const uint8_t* input,uint8_t* output);
#endif // (BLE_EMB_PRESENT || BLE_HOST_PRESENT)
/// @} AES_INT
///
#endif /* AES_INT_H_ */