Skip to content

Commit c4f2002

Browse files
committed
narrow ecc_size/sig_size guards to SETKEY||EXPORT_KEY, update _WC_PK_TYPE_MAX, const-qualify export_key.obj, call _ecc_import_x963_ex2 directly, fix GetSetKeyTypeStr, fix NULL deref in wc_RsaPrivateKeyDecode with WOLF_CRYPTO_CB_FIND, add FIND CI config.
1 parent 9ee7c18 commit c4f2002

7 files changed

Lines changed: 19 additions & 12 deletions

File tree

.github/workflows/os-check.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ jobs:
9090
'--enable-cryptocb --enable-keygen --enable-cryptocbutils=export',
9191
'--enable-cryptocb --enable-keygen CPPFLAGS="-DWOLF_CRYPTO_CB_EXPORT_KEY"',
9292
'--enable-cryptocb --enable-keygen --enable-aesgcm --enable-cryptocbutils=setkey,free,export CPPFLAGS="-DWOLF_CRYPTO_CB_AES_SETKEY"',
93+
'--enable-cryptocb --enable-keygen --enable-cryptocbutils=setkey,export CPPFLAGS="-DWOLF_CRYPTO_CB_FIND"',
9394
'--disable-examples CPPFLAGS=-DWOLFSSL_NO_MALLOC',
9495
'CPPFLAGS=-DNO_WOLFSSL_CLIENT',
9596
'CPPFLAGS=-DNO_WOLFSSL_SERVER',

wolfcrypt/src/asn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8304,7 +8304,7 @@ int wc_RsaPrivateKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
83048304
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
83058305
#endif
83068306

8307-
if (key == NULL) {
8307+
if (key == NULL || input == NULL || inOutIdx == NULL) {
83088308
return BAD_FUNC_ARG;
83098309
}
83108310

wolfcrypt/src/cryptocb.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,16 @@ static const char* GetAlgoTypeStr(int algo)
118118
static const char* GetSetKeyTypeStr(int type)
119119
{
120120
switch (type) {
121+
case WC_SETKEY_NONE: return "None";
121122
case WC_SETKEY_HMAC: return "HMAC";
122123
case WC_SETKEY_RSA_PUB: return "RSA-Pub";
123124
case WC_SETKEY_RSA_PRIV: return "RSA-Priv";
124125
case WC_SETKEY_ECC_PUB: return "ECC-Pub";
125126
case WC_SETKEY_ECC_PRIV: return "ECC-Priv";
126127
case WC_SETKEY_AES: return "AES";
128+
default: break;
127129
}
128-
return "Unknown";
130+
return NULL;
129131
}
130132
#endif /* WOLF_CRYPTO_CB_SETKEY */
131133
static const char* GetPkTypeStr(int pk)
@@ -2301,7 +2303,7 @@ int wc_CryptoCb_SetKey(int devId, int type, void* obj,
23012303
* uses normal software export functions on 'out' and frees it.
23022304
* Returns: 0 on success, CRYPTOCB_UNAVAILABLE if not handled, negative on error
23032305
*/
2304-
int wc_CryptoCb_ExportKey(int devId, int type, void* obj, void* out)
2306+
int wc_CryptoCb_ExportKey(int devId, int type, const void* obj, void* out)
23052307
{
23062308
int ret = WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE);
23072309
CryptoCb* dev;

wolfcrypt/src/ecc.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9997,7 +9997,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
99979997
}
99989998

99999999
ret = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_ECDSA_SIGN,
10000-
(void*)key, tmpKey);
10000+
key, tmpKey);
1000110001
if (ret == 0) {
1000210002
/* Call software helper (no callback recursion) */
1000310003
ret = _ecc_export_x963(tmpKey, out, outLen);
@@ -11326,7 +11326,7 @@ int wc_ecc_export_ex(ecc_key* key, byte* qx, word32* qxLen,
1132611326
}
1132711327

1132811328
err = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_ECDSA_SIGN,
11329-
(void*)key, tmpKey);
11329+
key, tmpKey);
1133011330
if (err == 0) {
1133111331
/* Call software helper (no callback recursion) */
1133211332
err = _ecc_export_ex(tmpKey, qx, qxLen, qy, qyLen, d, dLen,
@@ -11412,7 +11412,7 @@ static int _ecc_import_private_key_ex(const byte* priv, word32 privSz,
1141211412
if (pub != NULL) {
1141311413
#ifndef NO_ASN
1141411414
word32 idx = 0;
11415-
ret = wc_ecc_import_x963_ex(pub, pubSz, key, curve_id);
11415+
ret = _ecc_import_x963_ex2(pub, pubSz, key, curve_id, 0);
1141611416
if (ret < 0)
1141711417
ret = wc_EccPublicKeyDecode(pub, &idx, key, pubSz);
1141811418
key->type = ECC_PRIVATEKEY;
@@ -12250,7 +12250,8 @@ int wc_ecc_size(ecc_key* key)
1225012250
return 0;
1225112251
}
1225212252

12253-
#ifdef WOLF_CRYPTO_CB
12253+
#if defined(WOLF_CRYPTO_CB) && \
12254+
(defined(WOLF_CRYPTO_CB_SETKEY) || defined(WOLF_CRYPTO_CB_EXPORT_KEY))
1225412255
if (key->devId != INVALID_DEVID) {
1225512256
int ret;
1225612257
int keySz = 0;
@@ -12301,7 +12302,8 @@ int wc_ecc_sig_size(const ecc_key* key)
1230112302
return 0;
1230212303
}
1230312304

12304-
#ifdef WOLF_CRYPTO_CB
12305+
#if defined(WOLF_CRYPTO_CB) && \
12306+
(defined(WOLF_CRYPTO_CB_SETKEY) || defined(WOLF_CRYPTO_CB_EXPORT_KEY))
1230512307
if (key->devId != INVALID_DEVID) {
1230612308
int ret;
1230712309
int cbKeySz = 0;

wolfcrypt/src/rsa.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4531,7 +4531,7 @@ int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
45314531
}
45324532

45334533
ret = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_RSA,
4534-
(void*)key, tmpKey);
4534+
key, tmpKey);
45354535
if (ret == 0) {
45364536
/* Call software helper (no callback recursion) */
45374537
ret = _RsaFlattenPublicKey(tmpKey, e, eSz, n, nSz);
@@ -4654,7 +4654,7 @@ int wc_RsaExportKey(const RsaKey* key,
46544654
}
46554655

46564656
ret = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_RSA,
4657-
(void*)key, tmpKey);
4657+
key, tmpKey);
46584658
if (ret == 0) {
46594659
/* Call software helper (no callback recursion) */
46604660
ret = _RsaExportKey(tmpKey, e, eSz, n, nSz,

wolfssl/wolfcrypt/cryptocb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ typedef struct wc_CryptoInfo {
526526
#ifdef WOLF_CRYPTO_CB_EXPORT_KEY
527527
struct { /* uses wc_AlgoType=WC_ALGO_TYPE_EXPORT_KEY */
528528
int type; /* enum wc_PkType (WC_PK_TYPE_RSA, etc.) */
529-
void* obj; /* Hardware key (has devCtx/id[]) */
529+
const void* obj; /* Hardware key (has devCtx/id[]) */
530530
void* out; /* Software key to fill (same type as obj) */
531531
} export_key;
532532
#endif /* WOLF_CRYPTO_CB_EXPORT_KEY */
@@ -821,7 +821,7 @@ WOLFSSL_LOCAL int wc_CryptoCb_SetKey(int devId, int type, void* obj,
821821
#endif /* WOLF_CRYPTO_CB_SETKEY */
822822
#ifdef WOLF_CRYPTO_CB_EXPORT_KEY
823823
WOLFSSL_LOCAL int wc_CryptoCb_ExportKey(int devId, int type,
824-
void* obj, void* out);
824+
const void* obj, void* out);
825825
#endif /* WOLF_CRYPTO_CB_EXPORT_KEY */
826826

827827
#endif /* WOLF_CRYPTO_CB */

wolfssl/wolfcrypt/types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,6 +1570,8 @@ enum wc_PkType {
15701570
WC_PK_TYPE_RSA_OAEP = 27,
15711571
WC_PK_TYPE_EC_GET_SIZE = 28,
15721572
WC_PK_TYPE_EC_GET_SIG_SIZE = 29,
1573+
#undef _WC_PK_TYPE_MAX
1574+
#define _WC_PK_TYPE_MAX WC_PK_TYPE_EC_GET_SIG_SIZE
15731575
WC_PK_TYPE_MAX = _WC_PK_TYPE_MAX
15741576
};
15751577

0 commit comments

Comments
 (0)