Skip to content

Commit ae48ee4

Browse files
authored
Merge pull request #8983 from philljj/linuxkm_make_rsa_again
Linuxkm make rsa again
2 parents 783ab14 + e73fa74 commit ae48ee4

File tree

4 files changed

+41
-20
lines changed

4 files changed

+41
-20
lines changed

linuxkm/lkcapi_dh_glue.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,10 @@ static int km_dh_reset_ctx(struct km_dh_ctx * ctx)
443443
}
444444
}
445445

446+
reset_ctx_end:
446447
/* clear old priv and public key arrays. */
447448
km_dh_clear_keys(ctx);
448449

449-
reset_ctx_end:
450-
if (err) {
451-
km_dh_clear_keys(ctx);
452-
}
453-
454450
return err;
455451
}
456452

@@ -885,7 +881,6 @@ static int km_dh_gen_pub(struct kpp_request *req)
885881
#ifdef WOLFKM_DEBUG_DH
886882
pr_info("info: exiting km_dh_gen_pub: %d", ctx->pub_len);
887883
#endif /* WOLFKM_DEBUG_DH */
888-
889884
return err;
890885
}
891886

linuxkm/lkcapi_ecdh_glue.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,6 @@ static int km_ecdh_gen_pub(struct kpp_request *req)
534534
#ifdef WOLFKM_DEBUG_ECDH
535535
pr_info("info: exiting km_ecdh_gen_pub: %d", err);
536536
#endif /* WOLFKM_DEBUG_ECDH */
537-
538537
return err;
539538
}
540539

@@ -717,7 +716,6 @@ static int linuxkm_test_ecdh_nist_p192(void)
717716
b_pub, expected_a_pub, sizeof(b_pub),
718717
secret, sizeof(secret),
719718
shared_secret, sizeof(shared_secret));
720-
721719
return rc;
722720
}
723721
#endif /* LINUXKM_ECC192 */
@@ -777,7 +775,6 @@ static int linuxkm_test_ecdh_nist_p256(void)
777775
b_pub, expected_a_pub, sizeof(b_pub),
778776
secret, sizeof(secret),
779777
shared_secret, sizeof(shared_secret));
780-
781778
return rc;
782779
}
783780

@@ -849,7 +846,6 @@ static int linuxkm_test_ecdh_nist_p384(void)
849846
b_pub, expected_a_pub, sizeof(b_pub),
850847
secret, sizeof(secret),
851848
shared_secret, sizeof(shared_secret));
852-
853849
return rc;
854850
}
855851

@@ -991,7 +987,6 @@ static int linuxkm_test_ecdh_nist_driver(const char * driver,
991987
#ifdef WOLFKM_DEBUG_ECDH
992988
pr_info("info: %s: self test returned: %d\n", driver, test_rc);
993989
#endif /* WOLFKM_DEBUG_ECDH */
994-
995990
return test_rc;
996991
}
997992

linuxkm/lkcapi_ecdsa_glue.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ static int linuxkm_test_ecdsa_nist_p192(void)
496496
p192_pub, pub_len,
497497
sig, sig_len,
498498
hash, hash_len);
499-
500499
return rc;
501500
}
502501
#endif /* LINUXKM_ECC192 */
@@ -840,7 +839,6 @@ static int linuxkm_test_ecdsa_nist_driver(const char * driver,
840839
#ifdef WOLFKM_DEBUG_ECDSA
841840
pr_info("info: %s: self test returned: %d\n", driver, test_rc);
842841
#endif /* WOLFKM_DEBUG_ECDSA */
843-
844842
return test_rc;
845843
}
846844

linuxkm/lkcapi_rsa_glue.c

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ static int km_direct_rsa_enc(struct akcipher_request *req)
719719
rsa_enc_out:
720720
if (enc != NULL) { free(enc); enc = NULL; }
721721
if (dec != NULL) { free(dec); dec = NULL; }
722+
722723
#ifdef WOLFKM_DEBUG_RSA
723724
pr_info("info: exiting km_direct_rsa_enc\n");
724725
#endif /* WOLFKM_DEBUG_RSA */
@@ -937,9 +938,7 @@ static int km_rsa_set_pub(struct crypto_akcipher *tfm, const void *key,
937938
static unsigned int km_rsa_max_size(struct crypto_akcipher *tfm)
938939
{
939940
struct km_rsa_ctx * ctx = NULL;
940-
941941
ctx = akcipher_tfm_ctx(tfm);
942-
943942
return (unsigned int) ctx->key_len;
944943
}
945944

@@ -1134,7 +1133,6 @@ static int km_pkcs1pad_sign(struct akcipher_request *req)
11341133
pr_info("info: exiting km_pkcs1pad_sign msg_len %d, enc_msg_len %d,"
11351134
" sig_len %d, err %d", req->src_len, enc_len, sig_len, err);
11361135
#endif /* WOLFKM_DEBUG_RSA */
1137-
11381136
return err;
11391137
}
11401138

@@ -1379,7 +1377,6 @@ static int km_pkcs1_sign(struct crypto_sig *tfm,
13791377
pr_info("info: exiting km_pkcs1_sign msg_len %d, enc_msg_len %d,"
13801378
" sig_len %d, err %d", slen, enc_msg_len, sig_len, err);
13811379
#endif /* WOLFKM_DEBUG_RSA */
1382-
13831380
return err;
13841381
}
13851382

@@ -2075,7 +2072,19 @@ static int linuxkm_test_rsa_driver(const char * driver, int nbits)
20752072
}
20762073
#endif /* WC_RSA_BLINDING */
20772074

2078-
ret = wc_MakeRsaKey(key, nbits, WC_RSA_EXPONENT, &rng);
2075+
#ifdef HAVE_FIPS
2076+
for (;;) {
2077+
#endif
2078+
ret = wc_MakeRsaKey(key, nbits, WC_RSA_EXPONENT, &rng);
2079+
#ifdef HAVE_FIPS
2080+
/* Retry if not prime. */
2081+
if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E)) {
2082+
continue;
2083+
}
2084+
break;
2085+
}
2086+
#endif
2087+
20792088
if (ret) {
20802089
pr_err("error: make rsa key returned: %d\n", ret);
20812090
goto test_rsa_end;
@@ -2431,7 +2440,19 @@ static int linuxkm_test_pkcs1pad_driver(const char * driver, int nbits,
24312440
}
24322441
#endif /* WC_RSA_BLINDING */
24332442

2434-
ret = wc_MakeRsaKey(key, nbits, WC_RSA_EXPONENT, &rng);
2443+
#ifdef HAVE_FIPS
2444+
for (;;) {
2445+
#endif
2446+
ret = wc_MakeRsaKey(key, nbits, WC_RSA_EXPONENT, &rng);
2447+
#ifdef HAVE_FIPS
2448+
/* Retry if not prime. */
2449+
if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E)) {
2450+
continue;
2451+
}
2452+
break;
2453+
}
2454+
#endif
2455+
24352456
if (ret) {
24362457
pr_err("error: make rsa key returned: %d\n", ret);
24372458
test_rc = ret;
@@ -2929,7 +2950,19 @@ static int linuxkm_test_pkcs1_driver(const char * driver, int nbits,
29292950
}
29302951
#endif /* WC_RSA_BLINDING */
29312952

2932-
ret = wc_MakeRsaKey(key, nbits, WC_RSA_EXPONENT, &rng);
2953+
#ifdef HAVE_FIPS
2954+
for (;;) {
2955+
#endif
2956+
ret = wc_MakeRsaKey(key, nbits, WC_RSA_EXPONENT, &rng);
2957+
#ifdef HAVE_FIPS
2958+
/* Retry if not prime. */
2959+
if (ret == WC_NO_ERR_TRACE(PRIME_GEN_E)) {
2960+
continue;
2961+
}
2962+
break;
2963+
}
2964+
#endif
2965+
29332966
if (ret) {
29342967
pr_err("error: make rsa key returned: %d\n", ret);
29352968
test_rc = ret;

0 commit comments

Comments
 (0)