Skip to content

Commit 049d702

Browse files
authored
Fixes for 5.8.2 FIPS ready, including updated private key lock/unlock handling and updates for RSA min keysize change. (#266)
1 parent c5e7219 commit 049d702

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

src/wp_ecc_kmgmt.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,9 @@ static int wp_ecc_get_params_enc_pub_key(wp_Ecc* ecc, OSSL_PARAM params[],
733733
outLen = 1 + 2 * ((ecc->bits + 7) / 8);
734734
}
735735
else {
736+
PRIVATE_KEY_UNLOCK();
736737
rc = wc_ecc_export_x963_ex(&ecc->key, p->data, &outLen, 0);
738+
PRIVATE_KEY_LOCK();
737739
if (rc != 0) {
738740
ok = 0;
739741
}
@@ -1433,7 +1435,9 @@ static int wp_ecc_export_keypair(wp_Ecc* ecc, OSSL_PARAM* params, int* pIdx,
14331435
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_export_keypair");
14341436

14351437
outLen = WP_ECC_PUBLIC_KEY_SIZE(ecc);
1438+
PRIVATE_KEY_UNLOCK();
14361439
rc = wc_ecc_export_x963_ex(&ecc->key, data + *idx, &outLen, 0);
1440+
PRIVATE_KEY_LOCK();
14371441
if (rc != 0) {
14381442
ok = 0;
14391443
}
@@ -2389,8 +2393,9 @@ static int wp_ecc_encode_pub_size(const wp_Ecc *ecc, size_t* keyLen)
23892393
word32 len;
23902394

23912395
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_encode_pub_size");
2392-
2396+
PRIVATE_KEY_UNLOCK();
23932397
rc = wc_ecc_export_x963_ex((ecc_key*)&ecc->key, NULL, &len, 0);
2398+
PRIVATE_KEY_LOCK();
23942399
if (rc != LENGTH_ONLY_E) {
23952400
ok = 0;
23962401
}
@@ -2421,7 +2426,9 @@ static int wp_ecc_encode_pub(const wp_Ecc *ecc, unsigned char* keyData,
24212426

24222427
WOLFPROV_ENTER(WP_LOG_ECC, "wp_ecc_encode_pub");
24232428

2429+
PRIVATE_KEY_UNLOCK();
24242430
rc = wc_ecc_export_x963_ex((ecc_key*)&ecc->key, keyData, &len, 0);
2431+
PRIVATE_KEY_LOCK();
24252432
if (rc != 0) {
24262433
ok = 0;
24272434
}

src/wp_ecx_kmgmt.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,10 @@ static int wp_ecx_get_params_priv_key(wp_Ecx* ecx, OSSL_PARAM params[])
544544
outLen = ecx->data->len;
545545
}
546546
else {
547+
PRIVATE_KEY_UNLOCK();
547548
int rc = (*ecx->data->exportPriv)((void*)&ecx->key, p->data,
548549
&outLen);
550+
PRIVATE_KEY_LOCK();
549551
if (rc != 0) {
550552
ok = 0;
551553
}
@@ -662,14 +664,18 @@ static int wp_ecx_match_priv_key(const wp_Ecx* ecx1, const wp_Ecx* ecx2)
662664
ok &= ecx1->hasPriv && ecx2->hasPriv;
663665
if (ok) {
664666
len1 = ecx1->data->len;
667+
PRIVATE_KEY_UNLOCK();
665668
rc = (*ecx1->data->exportPriv)((void*)&ecx1->key, key1, &len1);
669+
PRIVATE_KEY_LOCK();
666670
if (rc != 0) {
667671
ok = 0;
668672
}
669673
}
670674
if (ok) {
671675
len2 = ecx2->data->len;
676+
PRIVATE_KEY_UNLOCK();
672677
rc = (*ecx2->data->exportPriv)((void*)&ecx2->key, key2, &len2);
678+
PRIVATE_KEY_LOCK();
673679
if (rc != 0) {
674680
ok = 0;
675681
}
@@ -1066,7 +1072,12 @@ static int wp_ecx_export_keypair(wp_Ecx* ecx, OSSL_PARAM* params, int* pIdx,
10661072
}
10671073
if (ok && priv) {
10681074
outLen = ecx->data->len;
1075+
PRIVATE_KEY_UNLOCK();
10691076
rc = (*ecx->data->exportPriv)((void*)&ecx->key, data + *idx, &outLen);
1077+
PRIVATE_KEY_LOCK();
1078+
if (rc != 0) {
1079+
ok = 0;
1080+
}
10701081
if (ok) {
10711082
if (ecx->clamped) {
10721083
data[*idx + 0 ] = ecx->unclamped[0];

src/wp_rsa_kmgmt.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@
3636

3737
#ifdef WP_HAVE_RSA
3838

39+
/* In 5.8.2 RSA_MIN_SIZE was changed from 1024 to 2048. We still need to
40+
* allow 1024 in some cases, and have extended logic in place for it already.
41+
* For FIPS 1024 bit keys, use existing checks and let wolfssl throw us back */
42+
#define WP_RSA_MIN_SIZE 1024
43+
#define WP_RSA_MAX_SIZE RSA_MAX_SIZE
44+
3945
/** Supported selections (key parts) in this key manager for RSA. */
4046
#define WP_RSA_POSSIBLE_SELECTIONS \
4147
(OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS)
@@ -357,7 +363,7 @@ static int wp_rsa_check_key_size_int(int keySize, int allow1024)
357363

358364
WOLFPROV_ENTER(WP_LOG_RSA, "wp_rsa_check_key_size_int");
359365

360-
if ((keySize < RSA_MIN_SIZE) || (keySize > RSA_MAX_SIZE)) {
366+
if ((keySize < WP_RSA_MIN_SIZE) || (keySize > WP_RSA_MAX_SIZE)) {
361367
WOLFPROV_MSG(WP_LOG_RSA, "RSA key size invalid: %d\n", keySize);
362368
ok = 0;
363369
}

0 commit comments

Comments
 (0)