diff --git a/src/lmic_config.h b/src/lmic_config.h index 5197f046..33e336aa 100644 --- a/src/lmic_config.h +++ b/src/lmic_config.h @@ -89,10 +89,12 @@ // implementation is optimized for speed on 32-bit processors using // fairly big lookup tables, but it takes up big amounts of flash on the // AVR architecture. -#define USE_ORIGINAL_AES +//#define USE_ORIGINAL_AES // // This selects the AES implementation written by Ideetroon for their // own LoRaWAN library. It also uses lookup tables, but smaller // byte-oriented ones, making it use a lot less flash space (but it is // also about twice as slow as the original). // #define USE_IDEETRON_AES +// +#define USE_MBEDTLS_AES diff --git a/src/mbedtls_aes.c b/src/mbedtls_aes.c new file mode 100644 index 00000000..0a40ed3c --- /dev/null +++ b/src/mbedtls_aes.c @@ -0,0 +1,28 @@ +/******************************************************************************* + * + * ttn-esp32 - The Things Network device library for ESP-IDF / SX127x + * + * Copyright (c) 2018 Manuel Bleichenbacher + * + * Licensed under MIT License + * https://opensource.org/licenses/MIT + * + * AES encryption using ESP32's hardware AES unit. + *******************************************************************************/ + +#include "mbedtls/aes.h" +#include "lmic/oslmic.h" + +#if defined(USE_MBEDTLS_AES) + +void lmic_aes_encrypt(u1_t *data, u1_t *key) +{ + mbedtls_aes_context ctx; + mbedtls_aes_init(&ctx); + mbedtls_aes_setkey_enc(&ctx, key, 128); + mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, data, data); + mbedtls_aes_free(&ctx); +} + + +#endif \ No newline at end of file