Skip to content

Commit 25da3bf

Browse files
authored
Merge pull request #8070 from JacobBarthelmeh/testing_static_memory
use heap hint with wolfSSL_CTX_check_private_key
2 parents 8a71c3b + bc0a2c4 commit 25da3bf

5 files changed

Lines changed: 24 additions & 19 deletions

File tree

src/ssl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6347,7 +6347,7 @@ static int check_cert_key(DerBuffer* cert, DerBuffer* key, DerBuffer* altKey,
63476347
if (ret == WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
63486348
#endif /* WOLF_PRIVATE_KEY_ID */
63496349
{
6350-
ret = wc_CheckPrivateKeyCert(buff, size, der, 0);
6350+
ret = wc_CheckPrivateKeyCert(buff, size, der, 0, heap);
63516351
ret = (ret == 1) ? WOLFSSL_SUCCESS: WOLFSSL_FAILURE;
63526352
}
63536353

@@ -6407,7 +6407,7 @@ static int check_cert_key(DerBuffer* cert, DerBuffer* key, DerBuffer* altKey,
64076407
if (ret == WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE))
64086408
#endif /* WOLF_PRIVATE_KEY_ID */
64096409
{
6410-
ret = wc_CheckPrivateKeyCert(buff, size, der, 1);
6410+
ret = wc_CheckPrivateKeyCert(buff, size, der, 1, heap);
64116411
ret = (ret == 1) ? WOLFSSL_SUCCESS: WOLFSSL_FAILURE;
64126412
}
64136413
}

src/x509.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12984,7 +12984,7 @@ WOLFSSL_ASN1_OBJECT* wolfSSL_X509_NAME_ENTRY_get_object(
1298412984
#ifndef NO_CHECK_PRIVATE_KEY
1298512985
return wc_CheckPrivateKey((byte*)key->pkey.ptr, key->pkey_sz,
1298612986
x509->pubKey.buffer, x509->pubKey.length,
12987-
(enum Key_Sum)x509->pubKeyOID) == 1 ?
12987+
(enum Key_Sum)x509->pubKeyOID, key->heap) == 1 ?
1298812988
WOLFSSL_SUCCESS : WOLFSSL_FAILURE;
1298912989
#else
1299012990
/* not compiled in */

wolfcrypt/src/asn.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7446,9 +7446,11 @@ int wc_CreatePKCS8Key(byte* out, word32* outSz, byte* key, word32 keySz,
74467446
* privKeySz : size of private key buffer
74477447
* pubKey : buffer holding DER format public key
74487448
* pubKeySz : size of public key buffer
7449-
* ks : type of key */
7449+
* ks : type of key
7450+
* heap : heap hint to use */
74507451
int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
7451-
const byte* pubKey, word32 pubKeySz, enum Key_Sum ks)
7452+
const byte* pubKey, word32 pubKeySz, enum Key_Sum ks,
7453+
void* heap)
74527454
{
74537455
int ret;
74547456
(void)privKeySz;
@@ -7485,14 +7487,14 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
74857487
}
74867488
#endif
74877489

7488-
if ((ret = wc_InitRsaKey(a, NULL)) < 0) {
7490+
if ((ret = wc_InitRsaKey(a, heap)) < 0) {
74897491
#ifdef WOLFSSL_SMALL_STACK
74907492
XFREE(b, NULL, DYNAMIC_TYPE_RSA);
74917493
XFREE(a, NULL, DYNAMIC_TYPE_RSA);
74927494
#endif
74937495
return ret;
74947496
}
7495-
if ((ret = wc_InitRsaKey(b, NULL)) < 0) {
7497+
if ((ret = wc_InitRsaKey(b, heap)) < 0) {
74967498
wc_FreeRsaKey(a);
74977499
#ifdef WOLFSSL_SMALL_STACK
74987500
XFREE(b, NULL, DYNAMIC_TYPE_RSA);
@@ -7553,7 +7555,7 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
75537555
}
75547556
#endif
75557557

7556-
if ((ret = wc_ecc_init(key_pair)) < 0) {
7558+
if ((ret = wc_ecc_init_ex(key_pair, heap, INVALID_DEVID)) < 0) {
75577559
#ifdef WOLFSSL_SMALL_STACK
75587560
XFREE(privDer, NULL, DYNAMIC_TYPE_TMP_BUFFER);
75597561
XFREE(key_pair, NULL, DYNAMIC_TYPE_ECC);
@@ -7571,7 +7573,7 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
75717573
wc_MemZero_Add("wc_CheckPrivateKey privDer", privDer, privSz);
75727574
#endif
75737575
wc_ecc_free(key_pair);
7574-
ret = wc_ecc_init(key_pair);
7576+
ret = wc_ecc_init_ex(key_pair, heap, INVALID_DEVID);
75757577
if (ret == 0) {
75767578
ret = wc_ecc_import_private_key(privDer,
75777579
privSz, pubKey,
@@ -7622,7 +7624,7 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
76227624
return MEMORY_E;
76237625
#endif
76247626

7625-
if ((ret = wc_ed25519_init(key_pair)) < 0) {
7627+
if ((ret = wc_ed25519_init_ex(key_pair, heap, INVALID_DEVID)) < 0) {
76267628
#ifdef WOLFSSL_SMALL_STACK
76277629
XFREE(key_pair, NULL, DYNAMIC_TYPE_ED25519);
76287630
#endif
@@ -7672,7 +7674,7 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
76727674
return MEMORY_E;
76737675
#endif
76747676

7675-
if ((ret = wc_ed448_init(key_pair)) < 0) {
7677+
if ((ret = wc_ed448_init_ex(key_pair, heap, INVALID_DEVID)) < 0) {
76767678
#ifdef WOLFSSL_SMALL_STACK
76777679
XFREE(key_pair, NULL, DYNAMIC_TYPE_ED448);
76787680
#endif
@@ -7919,6 +7921,7 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
79197921
ret = 0;
79207922
}
79217923
(void)ks;
7924+
(void)heap;
79227925

79237926
return ret;
79247927
}
@@ -7933,7 +7936,7 @@ int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
79337936
* checkAlt : indicate if we check primary or alternative key
79347937
*/
79357938
int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der,
7936-
int checkAlt)
7939+
int checkAlt, void* heap)
79377940
{
79387941
int ret = 0;
79397942

@@ -7947,7 +7950,7 @@ int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der,
79477950
word32 idx = 0;
79487951
/* Dilithium has the largest public key at the moment */
79497952
word32 pubKeyLen = DILITHIUM_MAX_PUB_KEY_SIZE;
7950-
byte* decodedPubKey = (byte*)XMALLOC(pubKeyLen, NULL,
7953+
byte* decodedPubKey = (byte*)XMALLOC(pubKeyLen, heap,
79517954
DYNAMIC_TYPE_PUBLIC_KEY);
79527955
if (decodedPubKey == NULL) {
79537956
ret = MEMORY_E;
@@ -7966,15 +7969,15 @@ int wc_CheckPrivateKeyCert(const byte* key, word32 keySz, DecodedCert* der,
79667969
}
79677970
if (ret == 0) {
79687971
ret = wc_CheckPrivateKey(key, keySz, decodedPubKey, pubKeyLen,
7969-
(enum Key_Sum) der->sapkiOID);
7972+
(enum Key_Sum) der->sapkiOID, heap);
79707973
}
7971-
XFREE(decodedPubKey, NULL, DYNAMIC_TYPE_PUBLIC_KEY);
7974+
XFREE(decodedPubKey, heap, DYNAMIC_TYPE_PUBLIC_KEY);
79727975
}
79737976
else
79747977
#endif
79757978
{
79767979
ret = wc_CheckPrivateKey(key, keySz, der->publicKey,
7977-
der->pubKeySize, (enum Key_Sum) der->keyOID);
7980+
der->pubKeySize, (enum Key_Sum) der->keyOID, heap);
79787981
}
79797982

79807983
(void)checkAlt;

wolfcrypt/src/pkcs12.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ static WARN_UNUSED_RESULT int freeDecCertList(WC_DerCertList** list,
11121112

11131113
InitDecodedCert(DeCert, current->buffer, current->bufferSz, heap);
11141114
if (ParseCertRelative(DeCert, CERT_TYPE, NO_VERIFY, NULL, NULL) == 0) {
1115-
if (wc_CheckPrivateKeyCert(*pkey, *pkeySz, DeCert, 0) == 1) {
1115+
if (wc_CheckPrivateKeyCert(*pkey, *pkeySz, DeCert, 0, heap) == 1) {
11161116
WOLFSSL_MSG("Key Pair found");
11171117
*cert = current->buffer;
11181118
*certSz = current->bufferSz;

wolfssl/wolfcrypt/asn.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,9 +2382,11 @@ WOLFSSL_LOCAL int GetNameHash(const byte* source, word32* idx, byte* hash,
23822382
WOLFSSL_LOCAL int GetNameHash_ex(const byte* source, word32* idx, byte* hash,
23832383
int maxIdx, word32 sigOID);
23842384
WOLFSSL_LOCAL int wc_CheckPrivateKeyCert(const byte* key, word32 keySz,
2385-
DecodedCert* der, int checkAlt);
2385+
DecodedCert* der, int checkAlt,
2386+
void* heap);
23862387
WOLFSSL_LOCAL int wc_CheckPrivateKey(const byte* privKey, word32 privKeySz,
2387-
const byte* pubKey, word32 pubKeySz, enum Key_Sum ks);
2388+
const byte* pubKey, word32 pubKeySz,
2389+
enum Key_Sum ks, void* heap);
23882390
WOLFSSL_LOCAL int StoreDHparams(byte* out, word32* outLen, mp_int* p, mp_int* g);
23892391
#ifdef WOLFSSL_DH_EXTRA
23902392
WOLFSSL_API int wc_DhPublicKeyDecode(const byte* input, word32* inOutIdx,

0 commit comments

Comments
 (0)