allow different sized fast math for both RSA and ECC

add C_EXTRA_FLAGS "-DALT_ECC_SIZE" to enable, and set
size with "-DFP_MAX_BITS_ECC=512", default is 512
This commit is contained in:
John Safranek
2015-01-15 14:54:29 -08:00
parent 1bd80b20d6
commit 2e6d118a50
7 changed files with 410 additions and 255 deletions

View File

@@ -57,12 +57,37 @@ typedef struct {
} ecc_set_type;
#ifdef ALT_ECC_SIZE
#ifndef FP_MAX_BITS_ECC
#define FP_MAX_BITS_ECC 512
#endif
#define FP_MAX_SIZE_ECC (FP_MAX_BITS_ECC+(8*DIGIT_BIT))
#if FP_MAX_BITS_ECC % CHAR_BIT
#error FP_MAX_BITS_ECC must be a multiple of CHAR_BIT
#endif
#define FP_SIZE_ECC (FP_MAX_SIZE_ECC/DIGIT_BIT)
/* This needs to match the size of the fp_int struct, except the
* fp_digit array will be shorter. */
typedef struct alt_fp_int {
int used, sign, size;
fp_digit dp[FP_SIZE_ECC];
} alt_fp_int;
#endif
/* A point on an ECC curve, stored in Jacbobian format such that (x,y,z) =>
(x/z^2, y/z^3, 1) when interpreted as affine */
typedef struct {
mp_int x; /* The x coordinate */
mp_int y; /* The y coordinate */
mp_int z; /* The z coordinate */
#ifndef ALT_ECC_SIZE
mp_int x[1]; /* The x coordinate */
mp_int y[1]; /* The y coordinate */
mp_int z[1]; /* The z coordinate */
#else
mp_int* x; /* The x coordinate */
mp_int* y; /* The y coordinate */
mp_int* z; /* The z coordinate */
alt_fp_int xyz[3];
#endif
} ecc_point;
@@ -95,7 +120,7 @@ WOLFSSL_API
int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash,
word32 hashlen, int* stat, ecc_key* key);
WOLFSSL_API
void wc_ecc_init(ecc_key* key);
int wc_ecc_init(ecc_key* key);
WOLFSSL_API
void wc_ecc_free(ecc_key* key);
WOLFSSL_API

View File

@@ -270,9 +270,12 @@
/* a FP type */
typedef struct {
fp_digit dp[FP_SIZE];
int used,
int used,
sign;
#ifdef ALT_ECC_SIZE
int size;
#endif
fp_digit dp[FP_SIZE];
} fp_int;
/* externally define this symbol to ignore the default settings, useful for changing the build from the make process */
@@ -353,8 +356,13 @@ typedef struct {
/*const char *fp_ident(void);*/
/* initialize [or zero] an fp int */
#define fp_init(a) (void)XMEMSET((a), 0, sizeof(fp_int))
#define fp_zero(a) fp_init(a)
#ifdef ALT_ECC_SIZE
void fp_init(fp_int *a);
void fp_zero(fp_int *a);
#else
#define fp_init(a) (void)XMEMSET((a), 0, sizeof(fp_int))
#define fp_zero(a) fp_init(a)
#endif
/* zero/even/odd ? */
#define fp_iszero(a) (((a)->used == 0) ? FP_YES : FP_NO)
@@ -365,7 +373,11 @@ typedef struct {
void fp_set(fp_int *a, fp_digit b);
/* copy from a to b */
#define fp_copy(a, b) (void)(((a) != (b)) ? ((void)XMEMCPY((b), (a), sizeof(fp_int))) : (void)0)
#ifndef ALT_ECC_SIZE
#define fp_copy(a, b) (void)(((a) != (b)) ? ((void)XMEMCPY((b), (a), sizeof(fp_int))) : (void)0)
#else
void fp_copy(fp_int *a, fp_int *b);
#endif
#define fp_init_copy(a, b) fp_copy(b, a)
/* clamp digits */