Skip to content

Commit a99a720

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 d58eea5 commit a99a720

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

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

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

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

12323-
#ifdef WOLF_CRYPTO_CB
12324+
#if defined(WOLF_CRYPTO_CB) && \
12325+
(defined(WOLF_CRYPTO_CB_SETKEY) || defined(WOLF_CRYPTO_CB_EXPORT_KEY))
1232412326
if (key->devId != INVALID_DEVID) {
1232512327
int ret;
1232612328
int cbKeySz = 0;

wolfcrypt/src/rsa.c

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

45984598
ret = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_RSA,
4599-
(void*)key, tmpKey);
4599+
key, tmpKey);
46004600
if (ret == 0) {
46014601
/* Call software helper (no callback recursion) */
46024602
ret = _RsaFlattenPublicKey(tmpKey, e, eSz, n, nSz);
@@ -4719,7 +4719,7 @@ int wc_RsaExportKey(const RsaKey* key,
47194719
}
47204720

47214721
ret = wc_CryptoCb_ExportKey(key->devId, WC_PK_TYPE_RSA,
4722-
(void*)key, tmpKey);
4722+
key, tmpKey);
47234723
if (ret == 0) {
47244724
/* Call software helper (no callback recursion) */
47254725
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)