diff --git a/wolfcrypt/src/ecc.c b/wolfcrypt/src/ecc.c index 69bcb2d18..19a885907 100644 --- a/wolfcrypt/src/ecc.c +++ b/wolfcrypt/src/ecc.c @@ -3222,13 +3222,13 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a, if (err == MP_OKAY) { int kIsMinusOne = (mp_cmp((mp_int*)k, &t) == MP_EQ); err = mp_cond_copy(tG->x, kIsMinusOne, R->x); - if (err == 0) { + if (err == MP_OKAY) { err = mp_sub(modulus, tG->y, &t); } - if (err == 0) { + if (err == MP_OKAY) { err = mp_cond_copy(&t, kIsMinusOne, R->y); } - if (err == 0) { + if (err == MP_OKAY) { err = mp_cond_copy(tG->z, kIsMinusOne, R->z); } } @@ -4291,8 +4291,12 @@ int wc_ecc_gen_k(WC_RNG* rng, int size, mp_int* k, mp_int* order) int err; byte buf[ECC_MAXSIZE_GEN]; - /*generate 8 extra bytes to mitigate bias from the modulo operation below*/ - /*see section A.1.2 in 'Suite B Implementor's Guide to FIPS 186-3 (ECDSA)'*/ + if (rng == NULL || size > ECC_MAXSIZE_GEN || k == NULL || order == NULL) { + return BAD_FUNC_ARG; + } + + /* generate 8 extra bytes to mitigate bias from the modulo operation below */ + /* see section A.1.2 in 'Suite B Implementor's Guide to FIPS 186-3 (ECDSA)' */ size += 8; /* make up random string */ diff --git a/wolfssl/wolfcrypt/sp_int.h b/wolfssl/wolfcrypt/sp_int.h index 9f247daf0..a32810e49 100644 --- a/wolfssl/wolfcrypt/sp_int.h +++ b/wolfssl/wolfcrypt/sp_int.h @@ -156,7 +156,7 @@ extern "C" { #endif -/* Detemine the number of bits to use in each word. */ +/* Determine the number of bits to use in each word. */ #ifdef SP_WORD_SIZE #elif defined(WOLFSSL_DSP_BUILD) #define SP_WORD_SIZE 32 @@ -510,7 +510,7 @@ typedef struct sp_ecc_ctx { #define sp_print_digit(a, s) #define sp_print_int(a, s) -#endif +#endif /* !NO_FILESYSTEM */ /* Returns whether multi-precision number is odd * @@ -978,8 +978,12 @@ WOLFSSL_API word32 CheckRunTimeFastMath(void); #define mp_gcd sp_gcd #define mp_lcm sp_lcm +#ifdef WOLFSSL_DEBUG_MATH +#define mp_dump(d, a, v) sp_print(a, d) #endif +#endif /* WOLFSSL_SP_MATH || WOLFSSL_SP_MATH_ALL */ + #ifdef __cplusplus } /* extern "C" */ #endif