From 3d81b20b6c48d899282c616fcbac242efca0c1e5 Mon Sep 17 00:00:00 2001 From: Anthony Hu Date: Wed, 22 Jan 2025 14:50:51 -0500 Subject: [PATCH] Changes requested in review. --- wolfcrypt/src/port/maxim/maxq10xx.c | 47 ++++++----------- wolfssl/wolfcrypt/cryptocb.h | 80 ++++++++++++----------------- 2 files changed, 48 insertions(+), 79 deletions(-) diff --git a/wolfcrypt/src/port/maxim/maxq10xx.c b/wolfcrypt/src/port/maxim/maxq10xx.c index a7667ee526..0e43a76ba8 100644 --- a/wolfcrypt/src/port/maxim/maxq10xx.c +++ b/wolfcrypt/src/port/maxim/maxq10xx.c @@ -97,7 +97,9 @@ void dbg_dumphex(const char *identifier, const uint8_t* pdata, uint32_t plen); #define MAX_SIGNKEY_DATASIZE 96 #define MAX_SIG_DATASIZE 64 #define ECC_KEYCOMPLEN 32 - +#define ESTABLISH_OUT_MAX 128 +#define FIXED_INFO_LEN 32 +#define FIXED_INFO_VALUE 0xaa #ifdef WOLFSSL_MAXQ108X #define PSK_KID (0x1235) @@ -602,7 +604,7 @@ static int aes_set_key(Aes* aes, const byte* userKey, word32 keylen) /* Delete object if one already exists. Ignore error in case it doesn't * exist. */ - mxq_rc = MXQ_DeleteObject(obj_id); + (void)MXQ_DeleteObject(obj_id); mxq_rc = MXQ_CreateObject(obj_id, keylen, MXQ_OBJTYPE_SECRETKEY, OBJPROP_PERSISTENT, (char *)"ahs=rwdgx:ahs=rwdgx:ahs=rwdgx"); @@ -756,7 +758,7 @@ static int ecc_set_key(ecc_key* key, const byte* userKey, word32 keycomplen, /* Delete object if one already exists. Ignore error in case it doesn't * exist. */ - mxq_rc = MXQ_DeleteObject(obj_id); + (void)MXQ_DeleteObject(obj_id); mxq_rc = MXQ_CreateObject(obj_id, keylen, objtype, OBJPROP_PERSISTENT, (char *)"ahs=rwdgx:ahs=rwdgx:ahs=rwdgx"); if (mxq_rc) { @@ -867,7 +869,7 @@ static int ecc_gen_key(ecc_key* key, word32 keycomplen) /* Delete object if one already exists. Ignore error in case it doesn't * exist. */ - mxq_rc = MXQ_DeleteObject(obj_id); + (void)MXQ_DeleteObject(obj_id); mxq_rc = MXQ_CreateObject(obj_id, keylen, objtype, OBJPROP_PERSISTENT, (char *)"ahs=rwdgx:ahs=rwdgx:ahs=rwdgx"); if (mxq_rc) { @@ -938,10 +940,10 @@ static int ecc_establish(ecc_key* key, ecc_key* peer, byte *ss, word32 *ss_len) { mxq_err_t mxq_rc; int rc = 0; - byte fixed_info_len = 32; - byte fixed_info[32]; - mxq_length output_len = 128; - byte output[128]; + byte fixed_info_len = FIXED_INFO_LEN; + byte fixed_info[FIXED_INFO_LEN]; + mxq_length output_len = ESTABLISH_OUT_MAX; + byte output[ESTABLISH_OUT_MAX]; word32 peerKeySz = peer->dp->size; uint8_t peerKeyBuf[MAX_EC_KEY_SIZE]; @@ -993,7 +995,8 @@ static int ecc_establish(ecc_key* key, ecc_key* peer, byte *ss, word32 *ss_len) return rc; } - XMEMSET(fixed_info, 0xaa, fixed_info_len); + /* This follows what is done in other MAXQ10xx examples. */ + XMEMSET(fixed_info, FIXED_INFO_VALUE, fixed_info_len); /* 0xFFFF indicates that the peer's public key will be in the buffer; not * referenced via key ID. */ @@ -1574,31 +1577,13 @@ static int do_aesecb(wc_CryptoInfo* info) #endif /* HAVE_AES_ECB */ #ifdef HAVE_AESCCM -/* Both info->cipher.aesccm_enc and info->cipher.aesccm_dec are defined this - * way. */ -typedef struct aes_ccm { - Aes* aes; - byte* out; - const byte* in; - word32 sz; - const byte* nonce; - word32 nonceSz; - byte* authTag; - word32 authTagSz; - const byte* authIn; - word32 authInSz; -} aes_ccm; - static int do_aesccm(wc_CryptoInfo* info) { int rc; - aes_ccm *aesccm = NULL; - - if (info->cipher.enc) { - aesccm = (aes_ccm*) &info->cipher.aesccm_enc; - } else { - aesccm = (aes_ccm*) &info->cipher.aesccm_dec; - } + wc_CryptoCb_AesAuthEnc *aesccm = (info->cipher.enc) ? + (wc_CryptoCb_AesAuthEnc*)&info->cipher.aesccm_enc : + /* dec->enc cast is okay */ + (wc_CryptoCb_AesAuthEnc*)&info->cipher.aesccm_dec; if (aesccm->sz == 0) { return CRYPTOCB_UNAVAILABLE; diff --git a/wolfssl/wolfcrypt/cryptocb.h b/wolfssl/wolfcrypt/cryptocb.h index 976332f4eb..2e02e00182 100644 --- a/wolfssl/wolfcrypt/cryptocb.h +++ b/wolfssl/wolfcrypt/cryptocb.h @@ -101,6 +101,34 @@ enum wc_CryptoCbCmdType { }; #endif + +#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM) +typedef struct { + Aes* aes; + byte* out; + const byte* in; + word32 sz; + const byte* iv; + word32 ivSz; + byte* authTag; + word32 authTagSz; + const byte* authIn; + word32 authInSz; +} wc_CryptoCb_AesAuthEnc; +typedef struct { + Aes* aes; + byte* out; + const byte* in; + word32 sz; + const byte* iv; + word32 ivSz; + const byte* authTag; + word32 authTagSz; + const byte* authIn; + word32 authInSz; +} wc_CryptoCb_AesAuthDec; +#endif + /* Crypto Information Structure for callbacks */ typedef struct wc_CryptoInfo { int algo_type; /* enum wc_AlgoType */ @@ -291,56 +319,12 @@ typedef struct wc_CryptoInfo { union { #endif #ifdef HAVE_AESGCM - struct { - Aes* aes; - byte* out; - const byte* in; - word32 sz; - const byte* iv; - word32 ivSz; - byte* authTag; - word32 authTagSz; - const byte* authIn; - word32 authInSz; - } aesgcm_enc; - struct { - Aes* aes; - byte* out; - const byte* in; - word32 sz; - const byte* iv; - word32 ivSz; - const byte* authTag; - word32 authTagSz; - const byte* authIn; - word32 authInSz; - } aesgcm_dec; + wc_CryptoCb_AesAuthEnc aesgcm_enc; + wc_CryptoCb_AesAuthDec aesgcm_dec; #endif /* HAVE_AESGCM */ #ifdef HAVE_AESCCM - struct { - Aes* aes; - byte* out; - const byte* in; - word32 sz; - const byte* nonce; - word32 nonceSz; - byte* authTag; - word32 authTagSz; - const byte* authIn; - word32 authInSz; - } aesccm_enc; - struct { - Aes* aes; - byte* out; - const byte* in; - word32 sz; - const byte* nonce; - word32 nonceSz; - const byte* authTag; - word32 authTagSz; - const byte* authIn; - word32 authInSz; - } aesccm_dec; + wc_CryptoCb_AesAuthEnc aesccm_enc; + wc_CryptoCb_AesAuthDec aesccm_dec; #endif /* HAVE_AESCCM */ #if defined(HAVE_AES_CBC) struct {