mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Fixes for building against latest nRF52 SDK. Allow nRF5x AES GCM to be enabled (uses software, but ECB is accelerated). Fix in wolfCrypt test for building AES GSM only with NO_AES_DECRYPT
.
This commit is contained in:
@@ -3999,9 +3999,6 @@ static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
|
||||
#if defined(HAVE_COLDFIRE_SEC)
|
||||
#error "Coldfire SEC doesn't currently support AES-GCM mode"
|
||||
|
||||
#elif defined(WOLFSSL_NRF51_AES)
|
||||
#error "nRF51 doesn't currently support AES-GCM mode"
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_ARMASM
|
||||
|
@@ -25,8 +25,9 @@
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
|
||||
#ifdef WOLFSSL_NRF51
|
||||
#if defined(WOLFSSL_NRF51) || defined(WOLFSSL_NRF5x)
|
||||
|
||||
#include "bsp.h"
|
||||
#include "nrf_delay.h"
|
||||
@@ -50,7 +51,7 @@ const nrf_drv_rtc_t rtc = NRF_DRV_RTC_INSTANCE(0); /**< Declaring an instance of
|
||||
#endif /* !NO_CRYPT_BENCHMARK */
|
||||
|
||||
/* AES */
|
||||
#if !defined(NO_AES) && !defined(SOFTDEVICE_PRESENT)
|
||||
#if !defined(NO_AES) && defined(WOLFSSL_NRF51_AES) && !defined(SOFTDEVICE_PRESENT)
|
||||
static byte mAesInitDone = 0;
|
||||
#endif
|
||||
|
||||
@@ -74,16 +75,14 @@ int nrf51_random_generate(byte* output, word32 size)
|
||||
}
|
||||
|
||||
while (remaining > 0) {
|
||||
err_code = nrf_drv_rng_bytes_available(&available);
|
||||
if (err_code == NRF_SUCCESS) {
|
||||
length = (remaining < available) ? remaining : available;
|
||||
if (length > 0) {
|
||||
err_code = nrf_drv_rng_rand(&output[pos], length);
|
||||
remaining -= length;
|
||||
pos += length;
|
||||
}
|
||||
available = 0;
|
||||
nrf_drv_rng_bytes_available(&available); /* is void */
|
||||
length = (remaining < available) ? remaining : available;
|
||||
if (length > 0) {
|
||||
err_code = nrf_drv_rng_rand(&output[pos], length);
|
||||
remaining -= length;
|
||||
pos += length;
|
||||
}
|
||||
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
@@ -166,28 +165,37 @@ static void rtc_handler(nrf_drv_rtc_int_type_t int_type)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef RTC0_CONFIG_FREQUENCY
|
||||
#define RTC0_CONFIG_FREQUENCY 32768
|
||||
#endif
|
||||
|
||||
static void rtc_config(void)
|
||||
{
|
||||
uint32_t err_code;
|
||||
|
||||
// Start the internal LFCLK XTAL oscillator
|
||||
/* Start the internal LFCLK XTAL oscillator */
|
||||
#ifdef NRF52
|
||||
err_code = nrf_drv_clock_init();
|
||||
APP_ERROR_CHECK(err_code);
|
||||
nrf_drv_clock_lfclk_request(NULL);
|
||||
#else
|
||||
err_code = nrf_drv_clock_init(NULL);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
nrf_drv_clock_lfclk_request();
|
||||
#endif
|
||||
|
||||
// Initialize RTC instance
|
||||
/* Initialize RTC instance */
|
||||
err_code = nrf_drv_rtc_init(&rtc, NULL, rtc_handler);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
// Enable tick event
|
||||
/* Enable tick event */
|
||||
nrf_drv_rtc_tick_enable(&rtc, false);
|
||||
|
||||
// Set compare channel to trigger interrupt after 1 seconds
|
||||
/* Set compare channel to trigger interrupt after 1 seconds */
|
||||
err_code = nrf_drv_rtc_cc_set(&rtc, 0, RTC0_CONFIG_FREQUENCY, true);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
|
||||
// Power on RTC instance
|
||||
/* Power on RTC instance */
|
||||
nrf_drv_rtc_enable(&rtc);
|
||||
}
|
||||
|
||||
@@ -217,4 +225,4 @@ double current_time(int reset)
|
||||
}
|
||||
#endif /* !NO_CRYPT_BENCHMARK */
|
||||
|
||||
#endif /* WOLFSSL_NRF51 */
|
||||
#endif /* WOLFSSL_NRF51 || WOLFSSL_NRF5x */
|
||||
|
@@ -2070,36 +2070,41 @@ int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#elif defined(WOLFSSL_NRF51)
|
||||
#elif defined(WOLFSSL_NRF51) || defined(WOLFSSL_NRF5x)
|
||||
#include "app_error.h"
|
||||
#include "nrf_drv_rng.h"
|
||||
int wc_GenerateSeed(OS_Seed* os, byte* output, word32 sz)
|
||||
{
|
||||
int remaining = sz, length, pos = 0;
|
||||
uint8_t available;
|
||||
uint32_t err_code;
|
||||
uint8_t available;
|
||||
static uint8_t initialized = 0;
|
||||
|
||||
(void)os;
|
||||
|
||||
/* Make sure RNG is running */
|
||||
err_code = nrf_drv_rng_init(NULL);
|
||||
if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE) {
|
||||
return -1;
|
||||
if (!initialized) {
|
||||
err_code = nrf_drv_rng_init(NULL);
|
||||
if (err_code != NRF_SUCCESS && err_code != NRF_ERROR_INVALID_STATE
|
||||
#ifdef NRF_ERROR_MODULE_ALREADY_INITIALIZED
|
||||
&& err_code != NRF_ERROR_MODULE_ALREADY_INITIALIZED
|
||||
#endif
|
||||
) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
while (remaining > 0) {
|
||||
err_code = nrf_drv_rng_bytes_available(&available);
|
||||
if (err_code == NRF_SUCCESS) {
|
||||
length = (remaining < available) ? remaining : available;
|
||||
if (length > 0) {
|
||||
err_code = nrf_drv_rng_rand(&output[pos], length);
|
||||
remaining -= length;
|
||||
pos += length;
|
||||
available = 0;
|
||||
nrf_drv_rng_bytes_available(&available); /* void func */
|
||||
length = (remaining < available) ? remaining : available;
|
||||
if (length > 0) {
|
||||
err_code = nrf_drv_rng_rand(&output[pos], length);
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (err_code != NRF_SUCCESS) {
|
||||
break;
|
||||
remaining -= length;
|
||||
pos += length;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -8438,7 +8438,7 @@ int aesgcm_test(void)
|
||||
0xba, 0x63, 0x7b, 0x39
|
||||
};
|
||||
|
||||
#if defined(HAVE_AES_DECRYPT) || defined(WOLFSSL_AES_256)
|
||||
#if defined(WOLFSSL_AES_256)
|
||||
const byte a[] =
|
||||
{
|
||||
0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
|
||||
@@ -9014,7 +9014,7 @@ int gmac_test(void)
|
||||
if (XMEMCMP(t2, tag, sizeof(t2)) != 0)
|
||||
return -6201;
|
||||
|
||||
#if !(defined(WC_NO_RNG) || defined(HAVE_SELFTEST))
|
||||
#if !defined(WC_NO_RNG) && !defined(HAVE_SELFTEST) && !defined(NO_AES_DECRYPT)
|
||||
{
|
||||
const byte badT[] =
|
||||
{
|
||||
@@ -9053,7 +9053,7 @@ int gmac_test(void)
|
||||
return -6208;
|
||||
wc_FreeRng(&rng);
|
||||
}
|
||||
#endif /* WC_NO_RNG HAVE_SELFTEST */
|
||||
#endif /* !WC_NO_RNG && !HAVE_SELFTEST && !NO_AES_DECRYPT */
|
||||
#endif /* HAVE_FIPS */
|
||||
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user