|
41 | 41 | #include <wolfssl/wolfcrypt/cryptocb.h> |
42 | 42 | #include <wolfssl/wolfcrypt/error-crypt.h> |
43 | 43 | #include <wolfssl/wolfcrypt/logging.h> |
| 44 | +#ifdef USS_API |
| 45 | +#include <MXQ_API.h> |
| 46 | +#else |
44 | 47 | #include <wolfssl/wolfcrypt/port/maxim/MXQ_API.h> |
| 48 | +#endif |
45 | 49 |
|
46 | 50 | #ifndef WOLFSSL_HAVE_ECC_KEY_GET_PRIV |
47 | 51 | /* FIPS build has replaced ecc.h. */ |
@@ -72,9 +76,17 @@ void dbg_dumphex(const char *identifier, const uint8_t* pdata, uint32_t plen); |
72 | 76 | #endif |
73 | 77 |
|
74 | 78 | #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 |
75 | 85 | #define ROOT_CA_CERT_OBJ_ID 0x1003 |
76 | 86 | #define DEVICE_CERT_OBJ_ID 0x1002 |
77 | 87 | #define DEVICE_KEY_PAIR_OBJ_ID 0x1004 |
| 88 | +#endif |
| 89 | + |
78 | 90 | #define PSK_OBJ_ID 0x1236 |
79 | 91 | #define K_CHUNKSIZE 2032 |
80 | 92 | #define K_CIPHER_BLOCKSIZE 16 |
@@ -120,7 +132,7 @@ static int tls13_server_key_len = -1; |
120 | 132 |
|
121 | 133 | /* Please define MAXQ10XX_PRODUCTION_KEY in your build scripts once you have a |
122 | 134 | * production key. */ |
123 | | -#if defined(MAXQ10XX_PRODUCTION_KEY) || !defined(DEBUG_WOLFSSL) |
| 135 | +#if defined(MAXQ10XX_PRODUCTION_KEY) |
124 | 136 | #include "maxq10xx_key.h" |
125 | 137 | #else |
126 | 138 | /* 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) |
568 | 580 | return BAD_FUNC_ARG; |
569 | 581 | } |
570 | 582 |
|
| 583 | + #if defined(MAXQ10XX_MUTEX) |
571 | 584 | rc = maxq_CryptHwMutexTryLock(); |
572 | 585 | if (rc != 0) { |
573 | 586 | WOLFSSL_ERROR_MSG("MAXQ: aes_set_key() lock could not be acquired"); |
574 | 587 | rc = NOT_COMPILED_IN; |
575 | 588 | return rc; |
576 | 589 | } |
| 590 | + #endif |
577 | 591 |
|
578 | 592 | if (aes->maxq_ctx.key_obj_id) { |
579 | 593 | wc_MAXQ10XX_AesFree(aes); |
@@ -694,12 +708,14 @@ static int ecc_set_key(ecc_key* key, const byte* userKey, word32 keycomplen) |
694 | 708 | objtype = MXQ_OBJTYPE_KEYPAIR; |
695 | 709 | } |
696 | 710 |
|
| 711 | + #if defined(MAXQ10XX_MUTEX) |
697 | 712 | rc = maxq_CryptHwMutexTryLock(); |
698 | 713 | if (rc != 0) { |
699 | 714 | WOLFSSL_ERROR_MSG("MAXQ: ecc_set_key() lock could not be acquired"); |
700 | 715 | rc = NOT_COMPILED_IN; |
701 | 716 | return rc; |
702 | 717 | } |
| 718 | + #endif |
703 | 719 |
|
704 | 720 | if (key->maxq_ctx.key_obj_id) { |
705 | 721 | wc_MAXQ10XX_EccFree(key); |
@@ -1074,24 +1090,20 @@ static int maxq10xx_ecc_verify_local( |
1074 | 1090 | #endif /* MAXQ_ECC */ |
1075 | 1091 |
|
1076 | 1092 | #ifdef MAXQ_RNG |
1077 | | -static int maxq10xx_random(byte* output, unsigned short sz) |
| 1093 | +int maxq10xx_random(byte* output, unsigned short sz) |
1078 | 1094 | { |
1079 | | -#if defined(WOLFSSL_MAXQ108X) |
1080 | | - if (!tls13active) { |
1081 | | - return NOT_COMPILED_IN; |
1082 | | - } |
1083 | | -#endif |
1084 | | - |
1085 | 1095 | if (output == NULL) { |
1086 | 1096 | return BUFFER_E; |
1087 | 1097 | } |
1088 | 1098 |
|
| 1099 | + #if defined(MAXQ10XX_MUTEX) |
1089 | 1100 | int ret = maxq_CryptHwMutexTryLock(); |
1090 | 1101 | if (ret != 0) { |
1091 | 1102 | WOLFSSL_ERROR_MSG("MAXQ: maxq10xx_random() lock could not be acquired"); |
1092 | 1103 | ret = NOT_COMPILED_IN; |
1093 | 1104 | return ret; |
1094 | 1105 | } |
| 1106 | + #endif |
1095 | 1107 |
|
1096 | 1108 | if (MXQ_Get_Random_Ext(output, sz, 0)) { |
1097 | 1109 | WOLFSSL_ERROR_MSG("MAXQ: MXQ_Get_Random_Ext() failed"); |
@@ -1222,13 +1234,15 @@ static int do_sha256(wc_CryptoInfo* info) |
1222 | 1234 | return WC_HW_E; |
1223 | 1235 | } |
1224 | 1236 |
|
| 1237 | + #if defined(MAXQ10XX_MUTEX) |
1225 | 1238 | if (info->hash.sha256->maxq_ctx.hash_running == 0) { |
1226 | 1239 | rc = maxq_CryptHwMutexTryLock(); |
1227 | 1240 | if (rc != 0) { |
1228 | 1241 | info->hash.sha256->maxq_ctx.soft_hash = 1; |
1229 | 1242 | return CRYPTOCB_UNAVAILABLE; |
1230 | 1243 | } |
1231 | 1244 | } |
| 1245 | + #endif |
1232 | 1246 |
|
1233 | 1247 | if (info->hash.in != NULL) { |
1234 | 1248 | /* wc_Sha256Update */ |
@@ -1981,12 +1995,14 @@ int maxq10xx_port_init(void) |
1981 | 1995 | } |
1982 | 1996 | #endif |
1983 | 1997 |
|
| 1998 | + #if defined(MAXQ10XX_MUTEX) |
1984 | 1999 | ret = maxq_CryptHwMutexTryLock(); |
1985 | 2000 | if (ret) { |
1986 | 2001 | WOLFSSL_ERROR_MSG("MAXQ: maxq10xx_port_init() -> device is busy " |
1987 | 2002 | "(switching to soft mode)"); |
1988 | 2003 | return 0; |
1989 | 2004 | } |
| 2005 | + #endif |
1990 | 2006 |
|
1991 | 2007 | mxq_rc = MXQ_Module_Init(); |
1992 | 2008 | if (mxq_rc) { |
@@ -3290,7 +3306,7 @@ static int maxq10xx_perform_tls13_record_processing(WOLFSSL* ssl, |
3290 | 3306 | { |
3291 | 3307 | int rc; |
3292 | 3308 | mxq_err_t mxq_rc; |
3293 | | - mxq_u2 key_id; |
| 3309 | + mxq_u2 key_id = 0xFFFF; |
3294 | 3310 |
|
3295 | 3311 | if (!tls13active) { |
3296 | 3312 | return NOT_COMPILED_IN; |
|
0 commit comments