Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/ecmult_impl.h
Show First 20 Lines • Show All 389 Lines • ▼ Show 20 Lines | |||||
/** Convert a number to WNAF notation. The number becomes represented by sum(2^i * wnaf[i], i=0..bits), | /** Convert a number to WNAF notation. The number becomes represented by sum(2^i * wnaf[i], i=0..bits), | ||||
* with the following guarantees: | * with the following guarantees: | ||||
* - each wnaf[i] is either 0, or an odd integer between -(1<<(w-1) - 1) and (1<<(w-1) - 1) | * - each wnaf[i] is either 0, or an odd integer between -(1<<(w-1) - 1) and (1<<(w-1) - 1) | ||||
* - two non-zero entries in wnaf are separated by at least w-1 zeroes. | * - two non-zero entries in wnaf are separated by at least w-1 zeroes. | ||||
* - the number of set values in wnaf is returned. This number is at most 256, and at most one more | * - the number of set values in wnaf is returned. This number is at most 256, and at most one more | ||||
* than the number of bits in the (absolute value) of the input. | * than the number of bits in the (absolute value) of the input. | ||||
*/ | */ | ||||
static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a, int w) { | static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a, int w) { | ||||
secp256k1_scalar s = *a; | secp256k1_scalar s; | ||||
int last_set_bit = -1; | int last_set_bit = -1; | ||||
int bit = 0; | int bit = 0; | ||||
int sign = 1; | int sign = 1; | ||||
int carry = 0; | int carry = 0; | ||||
VERIFY_CHECK(wnaf != NULL); | VERIFY_CHECK(wnaf != NULL); | ||||
VERIFY_CHECK(0 <= len && len <= 256); | VERIFY_CHECK(0 <= len && len <= 256); | ||||
VERIFY_CHECK(a != NULL); | VERIFY_CHECK(a != NULL); | ||||
VERIFY_CHECK(2 <= w && w <= 31); | VERIFY_CHECK(2 <= w && w <= 31); | ||||
memset(wnaf, 0, len * sizeof(wnaf[0])); | memset(wnaf, 0, len * sizeof(wnaf[0])); | ||||
s = *a; | |||||
if (secp256k1_scalar_get_bits(&s, 255, 1)) { | if (secp256k1_scalar_get_bits(&s, 255, 1)) { | ||||
secp256k1_scalar_negate(&s, &s); | secp256k1_scalar_negate(&s, &s); | ||||
sign = -1; | sign = -1; | ||||
} | } | ||||
while (bit < len) { | while (bit < len) { | ||||
int now; | int now; | ||||
int word; | int word; | ||||
▲ Show 20 Lines • Show All 797 Lines • Show Last 20 Lines |