Skip to content

Commit

Permalink
Changes requested in review.
Browse files Browse the repository at this point in the history
  • Loading branch information
anhu committed Jan 22, 2025
1 parent accce53 commit 0a75a75
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 79 deletions.
47 changes: 16 additions & 31 deletions wolfcrypt/src/port/maxim/maxq10xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down
84 changes: 36 additions & 48 deletions wolfssl/wolfcrypt/cryptocb.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,38 @@ enum wc_CryptoCbCmdType {
};
#endif


#if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
typedef struct {
Aes* aes;
byte* out;
const byte* in;
word32 sz;
const byte* nonce;
word32 nonceSz;
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* nonce;
word32 nonceSz;
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 */
Expand Down Expand Up @@ -291,56 +323,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 {
Expand Down

0 comments on commit 0a75a75

Please sign in to comment.