diff --git a/wolfcrypt/src/port/ti/ti-aes.c b/wolfcrypt/src/port/ti/ti-aes.c index 83bcd3be4..18feb969e 100644 --- a/wolfcrypt/src/port/ti/ti-aes.c +++ b/wolfcrypt/src/port/ti/ti-aes.c @@ -298,6 +298,17 @@ int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len, const byte* iv, #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) +#ifndef NO_RNG +static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz) +{ + int i; + for (i = (int)ctrSz - 1; i >= 0; i--) { + if (++ctr[i]) + break; + } +} +#endif + static int AesAuthSetKey(Aes* aes, const byte* key, word32 keySz) { byte nonce[AES_BLOCK_SIZE]; @@ -517,9 +528,9 @@ static int AesAuthEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz, ROM_AESKey1Set(AES_BASE, aes->key, aes->keylen-8); ret = ROM_AESDataProcessAuth(AES_BASE, - (unsigned int*)in_a, (unsigned int *)out_a, inSz, + (unsigned int*)in_a, (unsigned int*)out_a, inSz, (unsigned int*)authIn_a, authInSz, - (unsigned int *)tmpTag); + (unsigned int*)tmpTag); wolfSSL_TI_unlockCCM(); if (ret == false) { @@ -619,9 +630,9 @@ static int AesAuthDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, ROM_AESIVSet(AES_BASE, aes->reg); ROM_AESKey1Set(AES_BASE, aes->key, aes->keylen-8); ret = ROM_AESDataProcessAuth(AES_BASE, - (unsigned int*)in_a, (unsigned int *)out_a, inSz, + (unsigned int*)in_a, (unsigned int*)out_a, inSz, (unsigned int*)authIn_a, authInSz, - (unsigned int *)tmpTag); + (unsigned int*)tmpTag); wolfSSL_TI_unlockCCM(); if ((ret == false) || (XMEMCMP(authTag, tmpTag, authTagSz) != 0)) { @@ -685,14 +696,6 @@ int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz, } #ifndef NO_RNG -static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz) -{ - int i; - for (i = (int)ctrSz - 1; i >= 0; i--) { - if (++ctr[i]) - break; - } -} static WARN_UNUSED_RESULT WC_INLINE int CheckAesGcmIvSize(int ivSz) { return (ivSz == GCM_NONCE_MIN_SZ || ivSz == GCM_NONCE_MID_SZ || @@ -890,6 +893,73 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz, return AesAuthDecrypt(aes, out, in, inSz, nonce, nonceSz, authTag, authTagSz, authIn, authInSz, AES_CFG_MODE_CCM); } + +/* abstract functions that call lower level AESCCM functions */ +#ifndef WC_NO_RNG + +int wc_AesCcmSetNonce(Aes* aes, const byte* nonce, word32 nonceSz) +{ + int ret = 0; + + if (aes == NULL || nonce == NULL || + nonceSz < CCM_NONCE_MIN_SZ || nonceSz > CCM_NONCE_MAX_SZ) { + + ret = BAD_FUNC_ARG; + } + + if (ret == 0) { + XMEMCPY(aes->reg, nonce, nonceSz); + aes->nonceSz = nonceSz; + + /* Invocation counter should be 2^61 */ + aes->invokeCtr[0] = 0; + aes->invokeCtr[1] = 0xE0000000; + } + + return ret; +} + + +int wc_AesCcmEncrypt_ex(Aes* aes, byte* out, const byte* in, word32 sz, + byte* ivOut, word32 ivOutSz, + byte* authTag, word32 authTagSz, + const byte* authIn, word32 authInSz) +{ + int ret = 0; + + if (aes == NULL || out == NULL || + (in == NULL && sz != 0) || + ivOut == NULL || + (authIn == NULL && authInSz != 0) || + (ivOutSz != aes->nonceSz)) { + + ret = BAD_FUNC_ARG; + } + + if (ret == 0) { + aes->invokeCtr[0]++; + if (aes->invokeCtr[0] == 0) { + aes->invokeCtr[1]++; + if (aes->invokeCtr[1] == 0) + ret = AES_CCM_OVERFLOW_E; + } + } + + if (ret == 0) { + ret = wc_AesCcmEncrypt(aes, out, in, sz, + (byte*)aes->reg, aes->nonceSz, + authTag, authTagSz, + authIn, authInSz); + if (ret == 0) { + XMEMCPY(ivOut, aes->reg, aes->nonceSz); + IncCtr((byte*)aes->reg, aes->nonceSz); + } + } + + return ret; +} +#endif /* !WC_NO_RNG */ + #endif /* HAVE_AESCCM */ int wc_AesInit(Aes* aes, void* heap, int devId) diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 8203f7cef..1f9c355cd 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -968,12 +968,6 @@ extern void uITRON4_free(void *p) ; #define NO_MAIN_DRIVER #endif -#ifdef WOLFSSL_TI_CRYPT - #define NO_GCM_ENCRYPT_EXTRA - #define NO_PUBLIC_GCM_SET_IV - #define NO_PUBLIC_CCM_SET_NONCE -#endif - #ifdef WOLFSSL_TIRTOS #define SIZEOF_LONG_LONG 8 #define NO_WRITEV @@ -983,13 +977,20 @@ extern void uITRON4_free(void *p) ; * specified in user_settings. */ #ifndef USE_FAST_MATH - #define WOLFSSL_HAVE_SP_ECC #define SP_WORD_SIZE 32 - #define WOLFSSL_HAVE_SP_RSA + #define WOLFSSL_HAVE_SP_ECC + #ifndef NO_RSA + #define WOLFSSL_HAVE_SP_RSA + #endif #ifndef NO_DH #define WOLFSSL_HAVE_SP_DH #endif - #define WOLFSSL_SP_4096 + #if !defined(NO_RSA) || !defined(NO_DH) + /* DH/RSA 2048, 3072 and 4096 */ + #if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS >= 4096 + #define WOLFSSL_SP_4096 + #endif + #endif #endif #define TFM_TIMING_RESISTANT #define ECC_TIMING_RESISTANT