From dc71f957f3353a32723229c2f2b7547031eefec9 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 17 Jul 2019 13:43:15 -0700 Subject: [PATCH] RSA-Key Gen Speedup 1. When doing the test divides on the first few primes, short circuit out of the loop if the prospective possible prime divides evenly. --- wolfcrypt/src/tfm.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index b7cb3d69a..99a428128 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -3749,8 +3749,10 @@ int mp_prime_is_prime_ex(mp_int* a, int t, int* result, WC_RNG* rng) /* do trial division */ for (r = 0; r < FP_PRIME_SIZE; r++) { if (fp_mod_d(a, primes[r], &d) == MP_OKAY) { - if (d == 0) - ret = FP_NO; + if (d == 0) { + *result = FP_NO; + return FP_OKAY; + } } else return FP_VAL;