Fixes from code review

This commit is contained in:
Sean Parkinson
2017-02-17 11:05:29 -08:00
parent d625645338
commit 24cd46f1f1
6 changed files with 20 additions and 13 deletions

View File

@@ -347,7 +347,8 @@ int Base64_Encode_NoNl(const byte* in, word32 inLen, byte* out, word32* outLen)
#endif /* defined(WOLFSSL_BASE64_ENCODE) */ #endif /* defined(WOLFSSL_BASE64_ENCODE) */
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS) #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS) \
|| defined(HAVE_ECC_CDH)
static static
const byte hexDecode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, const byte hexDecode[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,

View File

@@ -2591,10 +2591,8 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
k = &k_lcl; k = &k_lcl;
if (mp_init(k) != MP_OKAY) if (mp_init(k) != MP_OKAY)
return MEMORY_E; return MEMORY_E;
/* multiple cofactor times private key "k" */ /* multiply cofactor times private key "k" */
err = mp_set_int(k, cofactor); err = mp_mul_d(&private_key->k, cofactor, k);
if (err == MP_OKAY)
err = mp_mul(k, &private_key->k, k);
if (err != MP_OKAY) { if (err != MP_OKAY) {
mp_clear(k); mp_clear(k);
return err; return err;
@@ -2606,6 +2604,7 @@ static int wc_ecc_shared_secret_gen_sync(ecc_key* private_key, ecc_point* point,
/* make new point */ /* make new point */
result = wc_ecc_new_point_h(private_key->heap); result = wc_ecc_new_point_h(private_key->heap);
if (result == NULL) { if (result == NULL) {
mp_clear(k);
return MEMORY_E; return MEMORY_E;
} }

View File

@@ -2254,6 +2254,12 @@ int mp_mul (mp_int * a, mp_int * b, mp_int * c)
return MP_OKAY; return MP_OKAY;
} }
int mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
{
fp_mul_d(a, b, c);
return MP_OKAY;
}
/* d = a * b (mod c) */ /* d = a * b (mod c) */
int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d) int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
{ {

View File

@@ -8204,8 +8204,7 @@ static int ecc_test_cdh_vectors(void)
int ret; int ret;
ecc_key pub_key, priv_key; ecc_key pub_key, priv_key;
byte sharedA[32] = {0}, sharedB[32] = {0}; byte sharedA[32] = {0}, sharedB[32] = {0};
word32 x; word32 x, z;
mp_int z;
const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287"; const char* QCAVSx = "700c48f77f56584c5cc632ca65640db91b6bacce3a4df6b42ce7cc838833d287";
const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac"; const char* QCAVSy = "db71e509e3fd9b060ddb20ba5c51dcc5948d46fbf640dfe0441782cab85fa4ac";
@@ -8234,13 +8233,13 @@ static int ecc_test_cdh_vectors(void)
} }
/* read in expected Z */ /* read in expected Z */
mp_init(&z); z = sizeof(sharedB);
mp_read_radix(&z, ZIUT, 16); ret = Base16_Decode((const byte*)ZIUT, (word32)XSTRLEN(ZIUT), sharedB, &z);
mp_to_unsigned_bin(&z, sharedB); if (ret != 0)
mp_clear(&z); goto done;
/* compare results */ /* compare results */
if (XMEMCMP(sharedA, sharedB, x)) { if (x != z || XMEMCMP(sharedA, sharedB, x)) {
ERROR_OUT(-1007, done); ERROR_OUT(-1007, done);
} }

View File

@@ -61,7 +61,8 @@ WOLFSSL_API int Base64_Decode(const byte* in, word32 inLen, byte* out,
word32* outLen); word32* outLen);
#endif #endif
#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS) #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) || defined(HAVE_FIPS) \
|| defined(HAVE_ECC_CDH)
WOLFSSL_API WOLFSSL_API
int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen); int Base16_Decode(const byte* in, word32 inLen, byte* out, word32* outLen);
WOLFSSL_API WOLFSSL_API

View File

@@ -622,6 +622,7 @@ int mp_sub (mp_int * a, mp_int * b, mp_int * c);
int mp_add_d (mp_int * a, mp_digit b, mp_int * c); int mp_add_d (mp_int * a, mp_digit b, mp_int * c);
int mp_mul (mp_int * a, mp_int * b, mp_int * c); int mp_mul (mp_int * a, mp_int * b, mp_int * c);
int mp_mul_d (mp_int * a, mp_digit b, mp_int * c);
int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d); int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d);
int mp_submod (mp_int* a, mp_int* b, mp_int* c, mp_int* d); int mp_submod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);
int mp_addmod (mp_int* a, mp_int* b, mp_int* c, mp_int* d); int mp_addmod (mp_int* a, mp_int* b, mp_int* c, mp_int* d);