forked from wolfSSL/wolfssl
ECC: ecc point multiply doesn't handle large multipliers
Detect large multiplier and return error.
This commit is contained in:
@@ -3036,6 +3036,12 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* k can't have more bits than modulus count plus 1 */
|
||||||
|
if (mp_count_bits(k) > mp_count_bits(modulus) + 1) {
|
||||||
|
err = ECC_OUT_OF_RANGE_E;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
#ifdef WOLFSSL_SMALL_STACK_CACHE
|
||||||
if (key == NULL) {
|
if (key == NULL) {
|
||||||
err = MP_MEM;
|
err = MP_MEM;
|
||||||
@@ -3170,6 +3176,11 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
|||||||
return ECC_BAD_ARG_E;
|
return ECC_BAD_ARG_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* k can't have more bits than order */
|
||||||
|
if (mp_count_bits(k) > mp_count_bits(order)) {
|
||||||
|
return ECC_OUT_OF_RANGE_E;
|
||||||
|
}
|
||||||
|
|
||||||
/* init variables */
|
/* init variables */
|
||||||
tG = NULL;
|
tG = NULL;
|
||||||
XMEMSET(M, 0, sizeof(M));
|
XMEMSET(M, 0, sizeof(M));
|
||||||
@@ -10675,6 +10686,11 @@ int wc_ecc_mulmod_ex(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
|||||||
return ECC_BAD_ARG_E;
|
return ECC_BAD_ARG_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* k can't have more bits than modulus count plus 1 */
|
||||||
|
if (mp_count_bits(k) > mp_count_bits(modulus) + 1) {
|
||||||
|
return ECC_OUT_OF_RANGE_E;
|
||||||
|
}
|
||||||
|
|
||||||
if (mp_init(&mu) != MP_OKAY)
|
if (mp_init(&mu) != MP_OKAY)
|
||||||
return MP_INIT_E;
|
return MP_INIT_E;
|
||||||
|
|
||||||
@@ -10785,14 +10801,14 @@ int wc_ecc_mulmod_ex2(const mp_int* k, ecc_point *G, ecc_point *R, mp_int* a,
|
|||||||
return ECC_BAD_ARG_E;
|
return ECC_BAD_ARG_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mp_init(&mu) != MP_OKAY)
|
|
||||||
return MP_INIT_E;
|
|
||||||
|
|
||||||
/* k can't have more bits than order */
|
/* k can't have more bits than order */
|
||||||
if (mp_count_bits(k) > mp_count_bits(order)) {
|
if (mp_count_bits(k) > mp_count_bits(order)) {
|
||||||
return ECC_OUT_OF_RANGE_E;
|
return ECC_OUT_OF_RANGE_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mp_init(&mu) != MP_OKAY)
|
||||||
|
return MP_INIT_E;
|
||||||
|
|
||||||
#ifndef HAVE_THREAD_LS
|
#ifndef HAVE_THREAD_LS
|
||||||
if (initMutex == 0) { /* extra sanity check if wolfCrypt_Init not called */
|
if (initMutex == 0) { /* extra sanity check if wolfCrypt_Init not called */
|
||||||
wc_InitMutex(&ecc_fp_lock);
|
wc_InitMutex(&ecc_fp_lock);
|
||||||
|
Reference in New Issue
Block a user