From f75329aa2e086cc80ca28981c6677db3b687bb46 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Fri, 30 Jan 2015 09:03:44 -0800 Subject: [PATCH] 1. Changed a memset to 0 of some mp_ints with mp_inits() 2. For alt-ecc, implemented the function fp_init_copy() 3. Added an fp_init() for the temp fp_int in fp_sub_d() --- wolfcrypt/src/ecc.c | 4 ++-- wolfcrypt/src/tfm.c | 9 +++++++++ wolfssl/wolfcrypt/tfm.h | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index ed23adb63..185922854 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -2088,8 +2088,8 @@ int wc_ecc_verify_hash(const byte* sig, word32 siglen, const byte* hash, * If either of those don't allocate correctly, none of * the rest of this function will execute, and everything * gets cleaned up at the end. */ - XMEMSET(&r, 0, sizeof(r)); - XMEMSET(&s, 0, sizeof(s)); + mp_init(&r); + mp_init(&s); if (err == MP_OKAY) err = DecodeECC_DSA_Sig(sig, siglen, &r, &s); diff --git a/wolfcrypt/src/tfm.c b/wolfcrypt/src/tfm.c index 983ff98e7..8ac48323a 100644 --- a/wolfcrypt/src/tfm.c +++ b/wolfcrypt/src/tfm.c @@ -1829,6 +1829,7 @@ void fp_reverse (unsigned char *s, int len) void fp_sub_d(fp_int *a, fp_digit b, fp_int *c) { fp_int tmp; + fp_init(&tmp); fp_set(&tmp, b); fp_sub(a, &tmp, c); } @@ -1983,6 +1984,14 @@ void fp_copy(fp_int *a, fp_int* b) XMEMCPY(b->dp, a->dp, a->used * sizeof(fp_digit)); } } + +void fp_init_copy(fp_int *a, fp_int* b) +{ + if (a != b) { + fp_init(a); + fp_copy(b, a); + } +} #endif /* fast math conversion */ diff --git a/wolfssl/wolfcrypt/tfm.h b/wolfssl/wolfcrypt/tfm.h index ee59c8162..a928a2ac6 100644 --- a/wolfssl/wolfcrypt/tfm.h +++ b/wolfssl/wolfcrypt/tfm.h @@ -375,10 +375,11 @@ void fp_set(fp_int *a, fp_digit b); /* copy from a to b */ #ifndef ALT_ECC_SIZE #define fp_copy(a, b) (void)(((a) != (b)) ? ((void)XMEMCPY((b), (a), sizeof(fp_int))) : (void)0) + #define fp_init_copy(a, b) fp_copy(b, a) #else void fp_copy(fp_int *a, fp_int *b); + void fp_init_copy(fp_int *a, fp_int *b); #endif -#define fp_init_copy(a, b) fp_copy(b, a) /* clamp digits */ #define fp_clamp(a) { while ((a)->used && (a)->dp[(a)->used-1] == 0) --((a)->used); (a)->sign = (a)->used ? (a)->sign : FP_ZPOS; }