wiced-h5: use mbedtls for aes128 on SDK 5.2+

This commit is contained in:
Matthias Ringwald 2017-11-06 15:26:38 +01:00
parent d4def6f450
commit ab379a4a0a
5 changed files with 42 additions and 2 deletions

View File

@ -20,8 +20,11 @@ GLOBAL_INCLUDES += .
$(NAME)_SOURCES := ../../../libraries/btstack/example/EXAMPLE.c
$(NAME)_COMPONENTS += btstack/port/wiced-h4
$(NAME)_CFLAGS += ADDITIONAL_CFLAGS
# Additional CFLAGS for BTstack Component compilation
BTSTACK_CFLAGS += ADDITIONAL_CFLAGS
# Name of Firmware file
BT_FIRMWARE_FILE := BLUETOOTH_FIRMWARE_FILE
'''

View File

@ -19,6 +19,9 @@ GLOBAL_INCLUDES += \
# micro-ecc of WICED tree used for SECP256R1 in LE Secure Connections
$(NAME)_COMPONENTS += crypto/micro-ecc
# additional CFLAGS
$(NAME)_CFLAGS += $(BTSTACK_CFLAGS)
# core BTstack sources
$(NAME)_SOURCES += \
../../src/ad_parser.c \

View File

@ -37,6 +37,9 @@
#define __BTSTACK_FILE__ "main.c"
#ifndef WICED_HAVE_MBEDTLS
// pre 5.2
#include "wiced_security.h"
static aes_context_t wiced_aes128_context;
@ -46,3 +49,22 @@ void btstack_aes128_calc(uint8_t * key, uint8_t * plaintext, uint8_t * result){
aes_setkey_enc(&wiced_aes128_context, key, 128);
aes_crypt_ecb(&wiced_aes128_context, AES_ENCRYPT , plaintext, result);
}
#else
// 5.2+
#include <string.h>
#include "mbedtls/aes.h"
static aes_context_t wiced_aes128_context;
void btstack_aes128_calc(uint8_t * key, uint8_t * plaintext, uint8_t * result);
void btstack_aes128_calc(uint8_t * key, uint8_t * plaintext, uint8_t * result){
memset(&wiced_aes128_context, 0, sizeof(aes_context_t));
mbedtls_aes_setkey_enc(&wiced_aes128_context, key, 128);
mbedtls_aes_crypt_ecb(&wiced_aes128_context, AES_ENCRYPT, plaintext, result);
}
#endif

View File

@ -20,8 +20,11 @@ GLOBAL_INCLUDES += .
$(NAME)_SOURCES := ../../../libraries/btstack/example/EXAMPLE.c
$(NAME)_COMPONENTS += btstack/port/wiced-h5
$(NAME)_CFLAGS += ADDITIONAL_CFLAGS
# Additional CFLAGS for BTstack Component compilation
BTSTACK_CFLAGS += ADDITIONAL_CFLAGS
# Name of Firmware file
BT_FIRMWARE_FILE := BLUETOOTH_FIRMWARE_FILE
'''
@ -62,11 +65,17 @@ wiced_version = "%u.%u" % (wiced_version_major, wiced_version_minor)
# show WICED version
print("Found WICED SDK version: %s" % wiced_version)
# UART API changes in 3.4
additional_cflags = ""
if wiced_version < "3.4.0":
print("Adding WICED_UART_READ_DOES_NOT_RETURN_BYTES_READ for SDK < 3.4.0")
additional_cflags = "-DWICED_UART_READ_DOES_NOT_RETURN_BYTES_READ"
# aes in wiced_security was replaced by mbedTLS in 5.2
if wiced_version >= "5.2":
print("Add WICED_HAVE_MBEDTLS for SDK >= 5.2")
additional_cflags += " -DWICED_HAVE_MBEDTLS"
# NOTE: it would be more robust to check for files on disk
# bluetooth firmware image name changed in 5.2

View File

@ -19,6 +19,9 @@ GLOBAL_INCLUDES += \
# micro-ecc of WICED tree used for SECP256R1 in LE Secure Connections
$(NAME)_COMPONENTS += crypto/micro-ecc
# additional CFLAGS
$(NAME)_CFLAGS += $(BTSTACK_CFLAGS)
# core BTstack sources
$(NAME)_SOURCES += \
../../src/ad_parser.c \