From 9244bbbf837fa042b00f1115c5253073a9086292 Mon Sep 17 00:00:00 2001 From: Daniele Lacamera Date: Tue, 22 Sep 2020 13:29:27 +0200 Subject: [PATCH] NXP-DCP: Fixed AES-GCM setkey; added AES direct. --- wolfcrypt/src/aes.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wolfcrypt/src/aes.c b/wolfcrypt/src/aes.c index 8816a8b07..8d06a4cc3 100644 --- a/wolfcrypt/src/aes.c +++ b/wolfcrypt/src/aes.c @@ -1743,6 +1743,13 @@ static void wc_AesEncrypt(Aes* aes, const byte* inBlock, byte* outBlock) return; #endif +#if defined(WOLFSSL_IMXRT_DCP) + if (aes->keylen == 16) { + DCPAesEcbEncrypt(aes, outBlock, inBlock, AES_BLOCK_SIZE); + return; + } +#endif + /* * map byte array block to cipher state * and add initial round key: @@ -2027,6 +2034,12 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) #if defined(WOLFSSL_SCE) && !defined(WOLFSSL_SCE_NO_AES) return AES_ECB_decrypt(aes, inBlock, outBlock, AES_BLOCK_SIZE); #endif +#if defined(WOLFSSL_IMXRT_DCP) + if (aes->keylen == 16) { + DCPAesEcbDecrypt(aes, outBlock, inBlock, AES_BLOCK_SIZE); + return; + } +#endif /* * map byte array block to cipher state @@ -2585,7 +2598,6 @@ static void wc_AesDecrypt(Aes* aes, const byte* inBlock, byte* outBlock) #elif defined(WOLFSSL_DEVCRYPTO_AES) /* implemented in wolfcrypt/src/port/devcrypto/devcrypto_aes.c */ - #else /* Software AES - SetKey */ @@ -4184,6 +4196,14 @@ int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len) ForceZero(local, sizeof(local)); #endif +#ifdef WOLFSSL_IMXRT_DCP + ret = 0; + if (len == 16) + ret = DCPAesSetKey(aes, key, len, iv, AES_ENCRYPTION); + if (ret != 0) + return WC_HW_E; +#endif + return ret; }