mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 18:57:27 +02:00
Merge pull request #2565 from SparkiDev/rsa_kg_sp_math
SP Math and RSA Key Gen working again
This commit is contained in:
@ -1067,7 +1067,7 @@ static int sp_sqrmod(sp_int* a, sp_int* m, sp_int* r)
|
||||
return err;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_HAVE_SP_DH) && defined(WOLFSSL_KEY_GEN)
|
||||
#if defined(WOLFSSL_HAVE_SP_DH) || defined(WOLFSSL_KEY_GEN)
|
||||
/* Multiply a by b mod m and store in r: r = (a * b) mod m
|
||||
*
|
||||
* a SP integer to multiply.
|
||||
@ -1077,14 +1077,32 @@ static int sp_sqrmod(sp_int* a, sp_int* m, sp_int* r)
|
||||
* returns MP_VAL when m is 0, MP_MEM when dynamic memory allocation fails and
|
||||
* MP_OKAY otherwise.
|
||||
*/
|
||||
static int sp_mulmod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
|
||||
int sp_mulmod(sp_int* a, sp_int* b, sp_int* m, sp_int* r)
|
||||
{
|
||||
int err;
|
||||
int err = MP_OKAY;
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
sp_int* t;
|
||||
#else
|
||||
sp_int t[1];
|
||||
#endif
|
||||
|
||||
err = sp_mul(a, b, r);
|
||||
if (err == MP_OKAY)
|
||||
err = sp_mod(r, m, r);
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
t = (sp_int*)XMALLOC(sizeof(sp_int), NULL, DYNAMIC_TYPE_BIGINT);
|
||||
if (t == NULL) {
|
||||
err = MP_MEM;
|
||||
}
|
||||
#endif
|
||||
if (err == MP_OKAY) {
|
||||
err = sp_mul(a, b, t);
|
||||
}
|
||||
if (err == MP_OKAY) {
|
||||
err = sp_mod(t, m, r);
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_SMALL_STACK
|
||||
if (t != NULL)
|
||||
XFREE(t, NULL, DYNAMIC_TYPE_BIGINT);
|
||||
#endif
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
@ -180,6 +180,7 @@ MP_API int sp_tohex(sp_int* a, char* str);
|
||||
MP_API int sp_2expt(sp_int* a, int e);
|
||||
MP_API int sp_rand_prime(sp_int* r, int len, WC_RNG* rng, void* heap);
|
||||
MP_API int sp_mul(sp_int* a, sp_int* b, sp_int* r);
|
||||
MP_API int sp_mulmod(sp_int* a, sp_int* b, sp_int* m, sp_int* r);
|
||||
MP_API int sp_gcd(sp_int* a, sp_int* b, sp_int* r);
|
||||
MP_API int sp_invmod(sp_int* a, sp_int* m, sp_int* r);
|
||||
MP_API int sp_lcm(sp_int* a, sp_int* b, sp_int* r);
|
||||
@ -246,6 +247,7 @@ MP_API void sp_rshb(sp_int* a, int n, sp_int* r);
|
||||
#define mp_2expt sp_2expt
|
||||
#define mp_rand_prime sp_rand_prime
|
||||
#define mp_mul sp_mul
|
||||
#define mp_mulmod sp_mulmod
|
||||
#define mp_gcd sp_gcd
|
||||
#define mp_invmod sp_invmod
|
||||
#define mp_lcm sp_lcm
|
||||
|
Reference in New Issue
Block a user