Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to the maxq10xx support #7824

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion wolfcrypt/src/dh.c
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ static int _ffc_pairwise_consistency_test(DhKey* key,
if (n < 5)
return 0;
else
return (word32)(2.4 * XPOW((double)n, 1.0/3.0) *
return (word32)((double)2.4 * XPOW((double)n, 1.0/3.0) *
XPOW(XLOG((double)n), 2.0/3.0) - 5);
}
#endif /* WOLFSSL_DH_CONST*/
Expand Down
34 changes: 25 additions & 9 deletions wolfcrypt/src/port/maxim/maxq10xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
#include <wolfssl/wolfcrypt/cryptocb.h>
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/wolfcrypt/logging.h>
#ifdef USS_API
#include <MXQ_API.h>
#else
#include <wolfssl/wolfcrypt/port/maxim/MXQ_API.h>
#endif

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

#define PUBKEY_IMPORT_OBJID 0x1000

#if defined (TEST_SETUP)
#define ROOT_CA_CERT_OBJ_ID 0x1006
#define DEVICE_CERT_OBJ_ID 0x1005
#define DEVICE_KEY_PAIR_OBJ_ID 0x1007
#else
#define ROOT_CA_CERT_OBJ_ID 0x1003
#define DEVICE_CERT_OBJ_ID 0x1002
#define DEVICE_KEY_PAIR_OBJ_ID 0x1004
#endif

#define PSK_OBJ_ID 0x1236
#define K_CHUNKSIZE 2032
#define K_CIPHER_BLOCKSIZE 16
Expand Down Expand Up @@ -120,7 +132,7 @@ static int tls13_server_key_len = -1;

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

#if defined(MAXQ10XX_MUTEX)
rc = maxq_CryptHwMutexTryLock();
if (rc != 0) {
WOLFSSL_ERROR_MSG("MAXQ: aes_set_key() lock could not be acquired");
rc = NOT_COMPILED_IN;
return rc;
}
#endif

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

#if defined(MAXQ10XX_MUTEX)
rc = maxq_CryptHwMutexTryLock();
if (rc != 0) {
WOLFSSL_ERROR_MSG("MAXQ: ecc_set_key() lock could not be acquired");
rc = NOT_COMPILED_IN;
return rc;
}
#endif

if (key->maxq_ctx.key_obj_id) {
wc_MAXQ10XX_EccFree(key);
Expand Down Expand Up @@ -1074,24 +1090,20 @@ static int maxq10xx_ecc_verify_local(
#endif /* MAXQ_ECC */

#ifdef MAXQ_RNG
static int maxq10xx_random(byte* output, unsigned short sz)
int maxq10xx_random(byte* output, unsigned short sz)
{
#if defined(WOLFSSL_MAXQ108X)
if (!tls13active) {
return NOT_COMPILED_IN;
}
#endif

if (output == NULL) {
return BUFFER_E;
}

#if defined(MAXQ10XX_MUTEX)
int ret = maxq_CryptHwMutexTryLock();
if (ret != 0) {
WOLFSSL_ERROR_MSG("MAXQ: maxq10xx_random() lock could not be acquired");
ret = NOT_COMPILED_IN;
return ret;
}
#endif

if (MXQ_Get_Random_Ext(output, sz, 0)) {
WOLFSSL_ERROR_MSG("MAXQ: MXQ_Get_Random_Ext() failed");
Expand Down Expand Up @@ -1222,13 +1234,15 @@ static int do_sha256(wc_CryptoInfo* info)
return WC_HW_E;
}

#if defined(MAXQ10XX_MUTEX)
if (info->hash.sha256->maxq_ctx.hash_running == 0) {
rc = maxq_CryptHwMutexTryLock();
if (rc != 0) {
info->hash.sha256->maxq_ctx.soft_hash = 1;
return CRYPTOCB_UNAVAILABLE;
}
}
#endif

if (info->hash.in != NULL) {
/* wc_Sha256Update */
Expand Down Expand Up @@ -1981,12 +1995,14 @@ int maxq10xx_port_init(void)
}
#endif

#if defined(MAXQ10XX_MUTEX)
ret = maxq_CryptHwMutexTryLock();
if (ret) {
WOLFSSL_ERROR_MSG("MAXQ: maxq10xx_port_init() -> device is busy "
"(switching to soft mode)");
return 0;
}
#endif

mxq_rc = MXQ_Module_Init();
if (mxq_rc) {
Expand Down Expand Up @@ -3290,7 +3306,7 @@ static int maxq10xx_perform_tls13_record_processing(WOLFSSL* ssl,
{
int rc;
mxq_err_t mxq_rc;
mxq_u2 key_id;
mxq_u2 key_id = 0xFFFF;

if (!tls13active) {
return NOT_COMPILED_IN;
Expand Down
1 change: 1 addition & 0 deletions wolfssl/wolfcrypt/port/maxim/maxq10xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ WOLFSSL_LOCAL void wc_MAXQ10XX_Sha256Copy(wc_Sha256* sha256);
WOLFSSL_LOCAL void wc_MAXQ10XX_Sha256Free(wc_Sha256* sha256);
WOLFSSL_LOCAL int wc_MAXQ10XX_EccSetKey(ecc_key* key, word32 keysize);
WOLFSSL_LOCAL void wc_MAXQ10XX_EccFree(ecc_key* key);
WOLFSSL_LOCAL int maxq10xx_random(byte* output, unsigned short sz);
#endif /* WOLFSSL_MAXQ10XX_CRYPTO */

#ifdef HAVE_PK_CALLBACKS
Expand Down