diff --git a/arch/arm/src/common/up_initialize.c b/arch/arm/src/common/up_initialize.c index ed4291a93b..19b948e5c0 100644 --- a/arch/arm/src/common/up_initialize.c +++ b/arch/arm/src/common/up_initialize.c @@ -46,6 +46,7 @@ #include #include #include +#include #include @@ -196,14 +197,6 @@ void up_initialize(void) devnull_register(); /* Standard /dev/null */ #endif -#if defined(CONFIG_CRYPTO) - up_cryptoinitialize(); -#endif - -#if defined(CONFIG_CRYPTO_CRYPTODEV) - devcrypto_register(); /* /dev/crypto */ -#endif - #if defined(CONFIG_DEV_ZERO) devzero_register(); /* Standard /dev/zero */ #endif @@ -228,6 +221,18 @@ void up_initialize(void) ramlog_consoleinit(); #endif + /* Initialize the HW crypto and /dev/crypto */ + +#if defined(CONFIG_CRYPTO) + up_cryptoinitialize(); +#endif + +#if CONFIG_NFILE_DESCRIPTORS > 0 +#if defined(CONFIG_CRYPTO_CRYPTODEV) + devcrypto_register(); +#endif +#endif + /* Initialize the Random Number Generator (RNG) */ #ifdef CONFIG_DEV_RANDOM diff --git a/crypto/testmngr.c b/crypto/testmngr.c index 28f4b0c306..4002a2d980 100644 --- a/crypto/testmngr.c +++ b/crypto/testmngr.c @@ -54,6 +54,14 @@ #include "testmngr.h" +/***************************************************************************** + * Pre-processor Definitions + *****************************************************************************/ + +#ifndef ARRAY_SIZE +# define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#endif + #if defined(CONFIG_CRYPTO_AES) /**************************************************************************** @@ -99,9 +107,15 @@ static int test_aes(void) { int i; - AES_CYPHER_TEST(AES_MODE_ECB, "ECB", AES_ENC_TEST_VECTORS, AES_DEC_TEST_VECTORS, aes_enc_tv_template, aes_dec_tv_template) - AES_CYPHER_TEST(AES_MODE_CBC, "CBC", AES_CBC_ENC_TEST_VECTORS, AES_CBC_DEC_TEST_VECTORS, aes_cbc_enc_tv_template, aes_cbc_dec_tv_template) - AES_CYPHER_TEST(AES_MODE_CTR, "CTR", AES_CTR_ENC_TEST_VECTORS, AES_CTR_DEC_TEST_VECTORS, aes_ctr_enc_tv_template, aes_ctr_dec_tv_template) + AES_CYPHER_TEST(AES_MODE_ECB, "ECB", ARRAY_SIZE(aes_enc_tv_template), + ARRAY_SIZE(aes_dec_tv_template), aes_enc_tv_template, + aes_dec_tv_template) + AES_CYPHER_TEST(AES_MODE_CBC, "CBC", ARRAY_SIZE(aes_cbc_enc_tv_template), + ARRAY_SIZE(aes_cbc_dec_tv_template), + aes_cbc_enc_tv_template, aes_cbc_dec_tv_template) + AES_CYPHER_TEST(AES_MODE_CTR, "CTR", ARRAY_SIZE(aes_ctr_enc_tv_template), + ARRAY_SIZE(aes_ctr_dec_tv_template), + aes_ctr_enc_tv_template, aes_ctr_dec_tv_template) return OK; } diff --git a/crypto/testmngr.h b/crypto/testmngr.h index 63004c7701..3405eed41e 100644 --- a/crypto/testmngr.h +++ b/crypto/testmngr.h @@ -64,13 +64,6 @@ struct cipher_testvec /* AES test vectors */ -#define AES_ENC_TEST_VECTORS 3 -#define AES_DEC_TEST_VECTORS 3 -#define AES_CBC_ENC_TEST_VECTORS 4 -#define AES_CBC_DEC_TEST_VECTORS 4 -#define AES_CTR_ENC_TEST_VECTORS 3 -#define AES_CTR_DEC_TEST_VECTORS 3 - static struct cipher_testvec aes_enc_tv_template[] = { #ifndef CONFIG_CRYPTO_AES128_DISABLE diff --git a/include/nuttx/crypto/crypto.h b/include/nuttx/crypto/crypto.h index 9cca6cdc83..84f903eb29 100644 --- a/include/nuttx/crypto/crypto.h +++ b/include/nuttx/crypto/crypto.h @@ -79,6 +79,8 @@ extern "C" * Public Function Prototypes ************************************************************************************/ +int up_cryptoinitialize(void); + #if defined(CONFIG_CRYPTO_AES) int up_aesinitialize(void); int aes_cypher(FAR void *out, FAR const void *in, uint32_t size, FAR const void *iv,