Merge pull request #3012 from SparkiDev/ecc_mulmod_fix

Fix ecc mulmod to only do one more bit than modulus len
This commit is contained in:
toddouska 2020-05-29 13:07:18 -07:00 committed by GitHub
commit 63a1ccda9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2836,11 +2836,13 @@ int wc_ecc_mulmod_ex(mp_int* k, ecc_point *G, ecc_point *R,
/* setup sliding window */
mode = 0;
bitcnt = 1;
buf = 0;
digidx = get_digit_count(modulus) - 1;
/* The order MAY be 1 bit longer than the modulus. */
digidx += (modulus->dp[digidx] >> (DIGIT_BIT-1));
digidx += modulus->dp[digidx] >> (DIGIT_BIT-1);
bitcnt = (mp_count_bits(modulus) + 1) % DIGIT_BIT;
buf = get_digit(k, digidx) << (DIGIT_BIT - bitcnt);
bitcnt = (bitcnt + 1) % DIGIT_BIT;
digidx -= bitcnt != 1;
/* perform ops */
if (err == MP_OKAY) {