Skip to content

Commit 8b048bc

Browse files
committed
Disable the old TI workarounds. Enable support for CCM.
1 parent 0bc2449 commit 8b048bc

2 files changed

Lines changed: 92 additions & 21 deletions

File tree

wolfcrypt/src/port/ti/ti-aes.c

Lines changed: 82 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,17 @@ int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len, const byte* iv,
298298

299299
#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
300300

301+
#ifndef NO_RNG
302+
static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
303+
{
304+
int i;
305+
for (i = (int)ctrSz - 1; i >= 0; i--) {
306+
if (++ctr[i])
307+
break;
308+
}
309+
}
310+
#endif
311+
301312
static int AesAuthSetKey(Aes* aes, const byte* key, word32 keySz)
302313
{
303314
byte nonce[AES_BLOCK_SIZE];
@@ -517,9 +528,9 @@ static int AesAuthEncrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
517528
ROM_AESKey1Set(AES_BASE, aes->key, aes->keylen-8);
518529

519530
ret = ROM_AESDataProcessAuth(AES_BASE,
520-
(unsigned int*)in_a, (unsigned int *)out_a, inSz,
531+
(unsigned int*)in_a, (unsigned int*)out_a, inSz,
521532
(unsigned int*)authIn_a, authInSz,
522-
(unsigned int *)tmpTag);
533+
(unsigned int*)tmpTag);
523534
wolfSSL_TI_unlockCCM();
524535

525536
if (ret == false) {
@@ -619,9 +630,9 @@ static int AesAuthDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
619630
ROM_AESIVSet(AES_BASE, aes->reg);
620631
ROM_AESKey1Set(AES_BASE, aes->key, aes->keylen-8);
621632
ret = ROM_AESDataProcessAuth(AES_BASE,
622-
(unsigned int*)in_a, (unsigned int *)out_a, inSz,
633+
(unsigned int*)in_a, (unsigned int*)out_a, inSz,
623634
(unsigned int*)authIn_a, authInSz,
624-
(unsigned int *)tmpTag);
635+
(unsigned int*)tmpTag);
625636
wolfSSL_TI_unlockCCM();
626637

627638
if ((ret == false) || (XMEMCMP(authTag, tmpTag, authTagSz) != 0)) {
@@ -685,14 +696,6 @@ int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
685696
}
686697

687698
#ifndef NO_RNG
688-
static WC_INLINE void IncCtr(byte* ctr, word32 ctrSz)
689-
{
690-
int i;
691-
for (i = (int)ctrSz - 1; i >= 0; i--) {
692-
if (++ctr[i])
693-
break;
694-
}
695-
}
696699
static WARN_UNUSED_RESULT WC_INLINE int CheckAesGcmIvSize(int ivSz) {
697700
return (ivSz == GCM_NONCE_MIN_SZ ||
698701
ivSz == GCM_NONCE_MID_SZ ||
@@ -890,6 +893,73 @@ int wc_AesCcmDecrypt(Aes* aes, byte* out, const byte* in, word32 inSz,
890893
return AesAuthDecrypt(aes, out, in, inSz, nonce, nonceSz, authTag, authTagSz,
891894
authIn, authInSz, AES_CFG_MODE_CCM);
892895
}
896+
897+
/* abstract functions that call lower level AESCCM functions */
898+
#ifndef WC_NO_RNG
899+
900+
int wc_AesCcmSetNonce(Aes* aes, const byte* nonce, word32 nonceSz)
901+
{
902+
int ret = 0;
903+
904+
if (aes == NULL || nonce == NULL ||
905+
nonceSz < CCM_NONCE_MIN_SZ || nonceSz > CCM_NONCE_MAX_SZ) {
906+
907+
ret = BAD_FUNC_ARG;
908+
}
909+
910+
if (ret == 0) {
911+
XMEMCPY(aes->reg, nonce, nonceSz);
912+
aes->nonceSz = nonceSz;
913+
914+
/* Invocation counter should be 2^61 */
915+
aes->invokeCtr[0] = 0;
916+
aes->invokeCtr[1] = 0xE0000000;
917+
}
918+
919+
return ret;
920+
}
921+
922+
923+
int wc_AesCcmEncrypt_ex(Aes* aes, byte* out, const byte* in, word32 sz,
924+
byte* ivOut, word32 ivOutSz,
925+
byte* authTag, word32 authTagSz,
926+
const byte* authIn, word32 authInSz)
927+
{
928+
int ret = 0;
929+
930+
if (aes == NULL || out == NULL ||
931+
(in == NULL && sz != 0) ||
932+
ivOut == NULL ||
933+
(authIn == NULL && authInSz != 0) ||
934+
(ivOutSz != aes->nonceSz)) {
935+
936+
ret = BAD_FUNC_ARG;
937+
}
938+
939+
if (ret == 0) {
940+
aes->invokeCtr[0]++;
941+
if (aes->invokeCtr[0] == 0) {
942+
aes->invokeCtr[1]++;
943+
if (aes->invokeCtr[1] == 0)
944+
ret = AES_CCM_OVERFLOW_E;
945+
}
946+
}
947+
948+
if (ret == 0) {
949+
ret = wc_AesCcmEncrypt(aes, out, in, sz,
950+
(byte*)aes->reg, aes->nonceSz,
951+
authTag, authTagSz,
952+
authIn, authInSz);
953+
if (ret == 0) {
954+
XMEMCPY(ivOut, aes->reg, aes->nonceSz);
955+
IncCtr((byte*)aes->reg, aes->nonceSz);
956+
}
957+
}
958+
959+
return ret;
960+
}
961+
#endif /* !WC_NO_RNG */
962+
893963
#endif /* HAVE_AESCCM */
894964

895965
int wc_AesInit(Aes* aes, void* heap, int devId)

wolfssl/wolfcrypt/settings.h

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -968,12 +968,6 @@ extern void uITRON4_free(void *p) ;
968968
#define NO_MAIN_DRIVER
969969
#endif
970970

971-
#ifdef WOLFSSL_TI_CRYPT
972-
#define NO_GCM_ENCRYPT_EXTRA
973-
#define NO_PUBLIC_GCM_SET_IV
974-
#define NO_PUBLIC_CCM_SET_NONCE
975-
#endif
976-
977971
#ifdef WOLFSSL_TIRTOS
978972
#define SIZEOF_LONG_LONG 8
979973
#define NO_WRITEV
@@ -983,13 +977,20 @@ extern void uITRON4_free(void *p) ;
983977
* specified in user_settings.
984978
*/
985979
#ifndef USE_FAST_MATH
986-
#define WOLFSSL_HAVE_SP_ECC
987980
#define SP_WORD_SIZE 32
988-
#define WOLFSSL_HAVE_SP_RSA
981+
#define WOLFSSL_HAVE_SP_ECC
982+
#ifndef NO_RSA
983+
#define WOLFSSL_HAVE_SP_RSA
984+
#endif
989985
#ifndef NO_DH
990986
#define WOLFSSL_HAVE_SP_DH
991987
#endif
992-
#define WOLFSSL_SP_4096
988+
#if !defined(NO_RSA) || !defined(NO_DH)
989+
/* DH/RSA 2048, 3072 and 4096 */
990+
#if defined(SP_INT_MAX_BITS) && SP_INT_MAX_BITS >= 4096
991+
#define WOLFSSL_SP_4096
992+
#endif
993+
#endif
993994
#endif
994995
#define TFM_TIMING_RESISTANT
995996
#define ECC_TIMING_RESISTANT

0 commit comments

Comments
 (0)