Skip to content

Commit 8b6972e

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 d2ce541 commit 8b6972e

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
@@ -68,6 +68,7 @@ jobs:
6868
'--enable-cryptocb --enable-keygen --enable-cryptocbutils=export',
6969
'--enable-cryptocb --enable-keygen CPPFLAGS="-DWOLF_CRYPTO_CB_EXPORT_KEY"',
7070
'--enable-cryptocb --enable-keygen --enable-aesgcm --enable-cryptocbutils=setkey,free,export CPPFLAGS="-DWOLF_CRYPTO_CB_AES_SETKEY"',
71+
'--enable-cryptocb --enable-keygen --enable-cryptocbutils=setkey,export CPPFLAGS="-DWOLF_CRYPTO_CB_FIND"',
7172
'CPPFLAGS=-DWOLFSSL_NO_CLIENT_AUTH',
7273
'CPPFLAGS=''-DNO_WOLFSSL_CLIENT -DWOLFSSL_NO_CLIENT_AUTH''',
7374
'CPPFLAGS=''-DNO_WOLFSSL_SERVER -DWOLFSSL_NO_CLIENT_AUTH''',

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
@@ -9990,7 +9990,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
99909990
}
99919991

99929992
ret = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_ECDSA_SIGN,
9993-
(void*)key, tmpKey);
9993+
key, tmpKey);
99949994
if (ret == 0) {
99959995
/* Call software helper (no callback recursion) */
99969996
ret = _ecc_export_x963(tmpKey, out, outLen);
@@ -11346,7 +11346,7 @@ int wc_ecc_export_ex(ecc_key* key, byte* qx, word32* qxLen,
1134611346
}
1134711347

1134811348
err = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_ECDSA_SIGN,
11349-
(void*)key, tmpKey);
11349+
key, tmpKey);
1135011350
if (err == 0) {
1135111351
/* Call software helper (no callback recursion) */
1135211352
err = _ecc_export_ex(tmpKey, qx, qxLen, qy, qyLen, d, dLen,
@@ -11432,7 +11432,7 @@ static int _ecc_import_private_key_ex(const byte* priv, word32 privSz,
1143211432
if (pub != NULL) {
1143311433
#ifndef NO_ASN
1143411434
word32 idx = 0;
11435-
ret = wc_ecc_import_x963_ex(pub, pubSz, key, curve_id);
11435+
ret = _ecc_import_x963_ex2(pub, pubSz, key, curve_id, 0);
1143611436
if (ret < 0)
1143711437
ret = wc_EccPublicKeyDecode(pub, &idx, key, pubSz);
1143811438
key->type = ECC_PRIVATEKEY;
@@ -12270,7 +12270,8 @@ int wc_ecc_size(ecc_key* key)
1227012270
return 0;
1227112271
}
1227212272

12273-
#ifdef WOLF_CRYPTO_CB
12273+
#if defined(WOLF_CRYPTO_CB) && \
12274+
(defined(WOLF_CRYPTO_CB_SETKEY) || defined(WOLF_CRYPTO_CB_EXPORT_KEY))
1227412275
if (key->devId != INVALID_DEVID) {
1227512276
int ret;
1227612277
int keySz = 0;
@@ -12321,7 +12322,8 @@ int wc_ecc_sig_size(const ecc_key* key)
1232112322
return 0;
1232212323
}
1232312324

12324-
#ifdef WOLF_CRYPTO_CB
12325+
#if defined(WOLF_CRYPTO_CB) && \
12326+
(defined(WOLF_CRYPTO_CB_SETKEY) || defined(WOLF_CRYPTO_CB_EXPORT_KEY))
1232512327
if (key->devId != INVALID_DEVID) {
1232612328
int ret;
1232712329
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)