Skip to content

Commit 6116d5e

Browse files
authored
Merge pull request #7824 from anhu/maxq10xx_update
Update to the maxq10xx support
2 parents 2cc5ecf + 29a5cc3 commit 6116d5e

3 files changed

Lines changed: 27 additions & 10 deletions

File tree

wolfcrypt/src/dh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static int _ffc_pairwise_consistency_test(DhKey* key,
10281028
if (n < 5)
10291029
return 0;
10301030
else
1031-
return (word32)(2.4 * XPOW((double)n, 1.0/3.0) *
1031+
return (word32)((double)2.4 * XPOW((double)n, 1.0/3.0) *
10321032
XPOW(XLOG((double)n), 2.0/3.0) - 5);
10331033
}
10341034
#endif /* WOLFSSL_DH_CONST*/

wolfcrypt/src/port/maxim/maxq10xx.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,11 @@
4141
#include <wolfssl/wolfcrypt/cryptocb.h>
4242
#include <wolfssl/wolfcrypt/error-crypt.h>
4343
#include <wolfssl/wolfcrypt/logging.h>
44+
#ifdef USS_API
45+
#include <MXQ_API.h>
46+
#else
4447
#include <wolfssl/wolfcrypt/port/maxim/MXQ_API.h>
48+
#endif
4549

4650
#ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV
4751
/* FIPS build has replaced ecc.h. */
@@ -72,9 +76,17 @@ void dbg_dumphex(const char *identifier, const uint8_t* pdata, uint32_t plen);
7276
#endif
7377

7478
#define PUBKEY_IMPORT_OBJID 0x1000
79+
80+
#if defined (TEST_SETUP)
81+
#define ROOT_CA_CERT_OBJ_ID 0x1006
82+
#define DEVICE_CERT_OBJ_ID 0x1005
83+
#define DEVICE_KEY_PAIR_OBJ_ID 0x1007
84+
#else
7585
#define ROOT_CA_CERT_OBJ_ID 0x1003
7686
#define DEVICE_CERT_OBJ_ID 0x1002
7787
#define DEVICE_KEY_PAIR_OBJ_ID 0x1004
88+
#endif
89+
7890
#define PSK_OBJ_ID 0x1236
7991
#define K_CHUNKSIZE 2032
8092
#define K_CIPHER_BLOCKSIZE 16
@@ -120,7 +132,7 @@ static int tls13_server_key_len = -1;
120132

121133
/* Please define MAXQ10XX_PRODUCTION_KEY in your build scripts once you have a
122134
* production key. */
123-
#if defined(MAXQ10XX_PRODUCTION_KEY) || !defined(DEBUG_WOLFSSL)
135+
#if defined(MAXQ10XX_PRODUCTION_KEY)
124136
#include "maxq10xx_key.h"
125137
#else
126138
/* TEST KEY. This must be changed for production environments!! */
@@ -568,12 +580,14 @@ static int aes_set_key(Aes* aes, const byte* userKey, word32 keylen)
568580
return BAD_FUNC_ARG;
569581
}
570582

583+
#if defined(MAXQ10XX_MUTEX)
571584
rc = maxq_CryptHwMutexTryLock();
572585
if (rc != 0) {
573586
WOLFSSL_ERROR_MSG("MAXQ: aes_set_key() lock could not be acquired");
574587
rc = NOT_COMPILED_IN;
575588
return rc;
576589
}
590+
#endif
577591

578592
if (aes->maxq_ctx.key_obj_id) {
579593
wc_MAXQ10XX_AesFree(aes);
@@ -694,12 +708,14 @@ static int ecc_set_key(ecc_key* key, const byte* userKey, word32 keycomplen)
694708
objtype = MXQ_OBJTYPE_KEYPAIR;
695709
}
696710

711+
#if defined(MAXQ10XX_MUTEX)
697712
rc = maxq_CryptHwMutexTryLock();
698713
if (rc != 0) {
699714
WOLFSSL_ERROR_MSG("MAXQ: ecc_set_key() lock could not be acquired");
700715
rc = NOT_COMPILED_IN;
701716
return rc;
702717
}
718+
#endif
703719

704720
if (key->maxq_ctx.key_obj_id) {
705721
wc_MAXQ10XX_EccFree(key);
@@ -1074,24 +1090,20 @@ static int maxq10xx_ecc_verify_local(
10741090
#endif /* MAXQ_ECC */
10751091

10761092
#ifdef MAXQ_RNG
1077-
static int maxq10xx_random(byte* output, unsigned short sz)
1093+
int maxq10xx_random(byte* output, unsigned short sz)
10781094
{
1079-
#if defined(WOLFSSL_MAXQ108X)
1080-
if (!tls13active) {
1081-
return NOT_COMPILED_IN;
1082-
}
1083-
#endif
1084-
10851095
if (output == NULL) {
10861096
return BUFFER_E;
10871097
}
10881098

1099+
#if defined(MAXQ10XX_MUTEX)
10891100
int ret = maxq_CryptHwMutexTryLock();
10901101
if (ret != 0) {
10911102
WOLFSSL_ERROR_MSG("MAXQ: maxq10xx_random() lock could not be acquired");
10921103
ret = NOT_COMPILED_IN;
10931104
return ret;
10941105
}
1106+
#endif
10951107

10961108
if (MXQ_Get_Random_Ext(output, sz, 0)) {
10971109
WOLFSSL_ERROR_MSG("MAXQ: MXQ_Get_Random_Ext() failed");
@@ -1222,13 +1234,15 @@ static int do_sha256(wc_CryptoInfo* info)
12221234
return WC_HW_E;
12231235
}
12241236

1237+
#if defined(MAXQ10XX_MUTEX)
12251238
if (info->hash.sha256->maxq_ctx.hash_running == 0) {
12261239
rc = maxq_CryptHwMutexTryLock();
12271240
if (rc != 0) {
12281241
info->hash.sha256->maxq_ctx.soft_hash = 1;
12291242
return CRYPTOCB_UNAVAILABLE;
12301243
}
12311244
}
1245+
#endif
12321246

12331247
if (info->hash.in != NULL) {
12341248
/* wc_Sha256Update */
@@ -1981,12 +1995,14 @@ int maxq10xx_port_init(void)
19811995
}
19821996
#endif
19831997

1998+
#if defined(MAXQ10XX_MUTEX)
19841999
ret = maxq_CryptHwMutexTryLock();
19852000
if (ret) {
19862001
WOLFSSL_ERROR_MSG("MAXQ: maxq10xx_port_init() -> device is busy "
19872002
"(switching to soft mode)");
19882003
return 0;
19892004
}
2005+
#endif
19902006

19912007
mxq_rc = MXQ_Module_Init();
19922008
if (mxq_rc) {
@@ -3290,7 +3306,7 @@ static int maxq10xx_perform_tls13_record_processing(WOLFSSL* ssl,
32903306
{
32913307
int rc;
32923308
mxq_err_t mxq_rc;
3293-
mxq_u2 key_id;
3309+
mxq_u2 key_id = 0xFFFF;
32943310

32953311
if (!tls13active) {
32963312
return NOT_COMPILED_IN;

wolfssl/wolfcrypt/port/maxim/maxq10xx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ WOLFSSL_LOCAL void wc_MAXQ10XX_Sha256Copy(wc_Sha256* sha256);
9696
WOLFSSL_LOCAL void wc_MAXQ10XX_Sha256Free(wc_Sha256* sha256);
9797
WOLFSSL_LOCAL int wc_MAXQ10XX_EccSetKey(ecc_key* key, word32 keysize);
9898
WOLFSSL_LOCAL void wc_MAXQ10XX_EccFree(ecc_key* key);
99+
WOLFSSL_LOCAL int maxq10xx_random(byte* output, unsigned short sz);
99100
#endif /* WOLFSSL_MAXQ10XX_CRYPTO */
100101

101102
#ifdef HAVE_PK_CALLBACKS

0 commit comments

Comments
 (0)