Skip to content

Commit f8a60b6

Browse files
committed
provider: rsa: Check RSA keys with p < q at key generation and import
Since OpenSSL 3.0 the OpenSSL RSA key generation taking place within libica may generate RSA keys where p < q (privileged form). While such a key is automatically corrected with the first call to libica's ica_rsa_crt(), such correction modifies the libica RSA key object and may cause concurrency problems when the same key object is used by multiple threads. Check and correct such keys right after key generation or during import, so that it is ensured that p > q whenever the key is used afterwards, and thus no correction is applied by ica_rsa_crt() later on. Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
1 parent 3ea8f4e commit f8a60b6

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/provider/rsa_keymgmt.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,15 @@ static void *ibmca_keymgmt_rsa_gen(void *vgenctx, OSSL_CALLBACK *osslcb,
12031203
}
12041204
}
12051205

1206+
/* If p < q, swap and recalculate now */
1207+
rc = ica_rsa_crt_key_check(&key->rsa.private);
1208+
if (rc > 1) {
1209+
put_error_op_ctx(genctx, IBMCA_ERR_INTERNAL_ERROR,
1210+
"ica_rsa_crt_key_check failed");
1211+
ibmca_keymgmt_free(key);
1212+
return NULL;
1213+
}
1214+
12061215
p = 3;
12071216
n = 0;
12081217
if (osslcb != NULL && osslcb(cb_params, cbarg) == 0) {
@@ -1823,6 +1832,15 @@ int ibmca_keymgmt_rsa_import(void *vkey, int selection,
18231832
"BN_bn2binpad failed for private qinv");
18241833
goto out;
18251834
}
1835+
1836+
/* If p < q, swap and recalculate now */
1837+
rc = ica_rsa_crt_key_check(&key->rsa.private);
1838+
if (rc > 1) {
1839+
rc = 0;
1840+
put_error_key(key, IBMCA_ERR_INTERNAL_ERROR,
1841+
"ica_rsa_crt_key_check failed");
1842+
goto out;
1843+
}
18261844
}
18271845

18281846
if ((selection & OSSL_KEYMGMT_SELECT_OTHER_PARAMETERS) != 0 &&

0 commit comments

Comments
 (0)