Get code compiling with SP math and RSA key gen again.

This commit is contained in:
Sean Parkinson
2020-01-08 09:48:56 +10:00
parent d257003341
commit 89d8a90781
3 changed files with 32 additions and 8 deletions

View File

@@ -987,14 +987,19 @@ int sp_tohex(sp_int* a, char* str)
* i Index of bit to set. * i Index of bit to set.
* returns MP_OKAY always. * returns MP_OKAY always.
*/ */
static int sp_set_bit(sp_int* a, int i) int sp_set_bit(sp_int* a, int i)
{ {
if (i / SP_WORD_SIZE < SP_INT_DIGITS) { int ret = MP_OKAY;
if ((a == NULL) || (i / SP_WORD_SIZE >= SP_INT_DIGITS)) {
ret = BAD_FUNC_ARG;
}
else {
a->dp[i/SP_WORD_SIZE] |= (sp_int_digit)1 << (i % SP_WORD_SIZE); a->dp[i/SP_WORD_SIZE] |= (sp_int_digit)1 << (i % SP_WORD_SIZE);
if (a->used <= i / SP_WORD_SIZE) if (a->used <= i / SP_WORD_SIZE)
a->used = (i / SP_WORD_SIZE) + 1; a->used = (i / SP_WORD_SIZE) + 1;
} }
return MP_OKAY; return ret;
} }
/* Exponentiate 2 to the power of e: a = 2^e /* Exponentiate 2 to the power of e: a = 2^e
@@ -2097,6 +2102,21 @@ int sp_exch(sp_int* a, sp_int* b)
#endif #endif
#endif #endif
#if defined(WOLFSSL_KEY_GEN) && !defined(NO_RSA)
/* Multiply a by digit n and put result into r. r = a * n
*
* a SP integer to be multiplied.
* n Number to multiply by.
* r SP integer result.
* returns MP_OKAY always.
*/
int sp_mul_d(sp_int* a, sp_int_digit n, sp_int* r)
{
_sp_mul_d(a, n, r, 0);
return MP_OKAY;
}
#endif
/* Returns the run time settings. /* Returns the run time settings.
* *
* returns the settings value. * returns the settings value.

View File

@@ -117,10 +117,10 @@ int mp_rand(mp_int* a, int digits, WC_RNG* rng)
ret = mp_set_bit(a, digits * DIGIT_BIT - 1); ret = mp_set_bit(a, digits * DIGIT_BIT - 1);
} }
#else #else
#if defined(USE_FAST_MATH) #if defined(WOLFSSL_SP_MATH)
if ((ret == MP_OKAY) && (digits > FP_SIZE))
#else
if ((ret == MP_OKAY) && (digits > SP_INT_DIGITS)) if ((ret == MP_OKAY) && (digits > SP_INT_DIGITS))
#else
if ((ret == MP_OKAY) && (digits > FP_SIZE))
#endif #endif
{ {
ret = BAD_FUNC_ARG; ret = BAD_FUNC_ARG;

View File

@@ -159,7 +159,7 @@ typedef struct sp_int {
} sp_int; } sp_int;
typedef sp_int mp_int; typedef sp_int mp_int;
typedef sp_digit mp_digit; typedef sp_int_digit mp_digit;
#include <wolfssl/wolfcrypt/wolfmath.h> #include <wolfssl/wolfcrypt/wolfmath.h>
@@ -191,6 +191,7 @@ MP_API int sp_lshd(sp_int* a, int s);
MP_API int sp_add(sp_int* a, sp_int* b, sp_int* r); MP_API int sp_add(sp_int* a, sp_int* b, sp_int* r);
MP_API int sp_set_int(sp_int* a, unsigned long b); MP_API int sp_set_int(sp_int* a, unsigned long b);
MP_API int sp_tohex(sp_int* a, char* str); MP_API int sp_tohex(sp_int* a, char* str);
MP_API int sp_set_bit(sp_int* a, int i);
MP_API int sp_2expt(sp_int* a, int e); 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_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_mul(sp_int* a, sp_int* b, sp_int* r);
@@ -205,6 +206,7 @@ MP_API int sp_exch(sp_int* a, sp_int* b);
MP_API int sp_get_digit_count(sp_int *a); MP_API int sp_get_digit_count(sp_int *a);
MP_API int sp_init_copy (sp_int * a, sp_int * b); MP_API int sp_init_copy (sp_int * a, sp_int * b);
MP_API void sp_rshb(sp_int* a, int n, sp_int* r); MP_API void sp_rshb(sp_int* a, int n, sp_int* r);
MP_API int sp_mul_d(sp_int* a, sp_int_digit n, sp_int* r);
#define MP_OKAY 0 #define MP_OKAY 0
@@ -259,6 +261,7 @@ MP_API void sp_rshb(sp_int* a, int n, sp_int* r);
#define mp_add sp_add #define mp_add sp_add
#define mp_set_int sp_set_int #define mp_set_int sp_set_int
#define mp_tohex sp_tohex #define mp_tohex sp_tohex
#define mp_set_bit sp_set_bit
#define mp_2expt sp_2expt #define mp_2expt sp_2expt
#define mp_rand_prime sp_rand_prime #define mp_rand_prime sp_rand_prime
#define mp_mul sp_mul #define mp_mul sp_mul
@@ -273,6 +276,7 @@ MP_API void sp_rshb(sp_int* a, int n, sp_int* r);
#define get_digit_count sp_get_digit_count #define get_digit_count sp_get_digit_count
#define mp_init_copy sp_init_copy #define mp_init_copy sp_init_copy
#define mp_rshb(A,x) sp_rshb(A,x,A) #define mp_rshb(A,x) sp_rshb(A,x,A)
#define mp_mul_d sp_mul_d
#endif #endif