btstack_crypto: use rijndael aes128 if ENABLE_SOFTWARE_AES128 [a2472]

This commit is contained in:
Matthias Ringwald 2019-12-07 22:34:33 +01:00
parent f13fc29007
commit cfbd0db491
2 changed files with 44 additions and 6 deletions

View File

@ -46,6 +46,30 @@
#include "btstack_util.h"
#include "hci.h"
//
// AES128 Configuration
//
// By default, AES128 is computed by Bluetooth Controller using HCI Command/Event asynchronously
// as fallback/alternative, a software implementation can be used
// configure ECC implementations
#if defined(HAVE_AES128) && defined(ENABLE_SOFTWARE_AES128)
#error "If you have custom AES128 implementation (HAVE_AES128), please disable software AES128 (ENABLE_SOFTWARE_AES128) in bstack_config.h"
#endif
#ifdef ENABLE_SOFTWARE_AES128
#define HAVE_AES128
#include "rijndael.h"
#endif
#ifdef HAVE_AES128
#define USE_BTSTACK_AES128
#endif
//
// ECC Configuration
//
// backwards-compatitility ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS -> ENABLE_MICRO_ECC_P256
#if defined(ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS) && !defined(ENABLE_MICRO_ECC_P256)
#define ENABLE_MICRO_ECC_P256
@ -78,12 +102,6 @@
#define ENABLE_ECC_P256
#endif
// Software AES128
#ifdef HAVE_AES128
#define USE_BTSTACK_AES128
void btstack_aes128_calc(const uint8_t * key, const uint8_t * plaintext, uint8_t * result);
#endif
// degbugging
// #define DEBUG_CCM
@ -146,6 +164,15 @@ static mbedtls_ecp_group mbedtls_ec_group;
#endif /* ENABLE_ECC_P256 */
#ifdef ENABLE_SOFTWARE_AES128
// AES128 using public domain rijndael implementation
void btstack_aes128_calc(const uint8_t * key, const uint8_t * plaintext, uint8_t * ciphertext){
uint32_t rk[RKLENGTH(KEYBITS)];
int nrounds = rijndaelSetupEncrypt(rk, &key[0], KEYBITS);
rijndaelEncrypt(rk, nrounds, plaintext, ciphertext);
}
#endif
static void btstack_crypto_done(btstack_crypto_t * btstack_crypto){
btstack_linked_list_pop(&btstack_crypto_operations);
(*btstack_crypto->context_callback.callback)(btstack_crypto->context_callback.context);

View File

@ -270,6 +270,17 @@ void btstack_crypto_ccm_encrypt_block(btstack_crypto_ccm_t * request, uint16_t l
*/
void btstack_crypto_ccm_decrypt_block(btstack_crypto_ccm_t * request, uint16_t len, const uint8_t * ciphertext, uint8_t * plaintext, void (* callback)(void * arg), void * callback_arg);
#ifdef HAVE_AES128
/**
* Encrypt plaintext using AES128
* @note Prototype for custom AES128 implementation
* @param key (16 bytes)
* @param plaintext (16 bytes)
* @param ciphertext (16 bytes)
*/
void btstack_aes128_calc(const uint8_t * key, const uint8_t * plaintext, uint8_t * ciphertext);
#endif
// PTS testing only - not possible when using Buetooth Controller for ECC operations
void btstack_crypto_ecc_p256_set_key(const uint8_t * public_key, const uint8_t * private_key);