Skip to content

Commit 5005abe

Browse files
committed
Rename scalar_get_bits -> scalar_get_bits_limb32; return uint32_t
1 parent 6247f48 commit 5005abe

9 files changed

+19
-19
lines changed

src/ecmult_const_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,8 @@ static void secp256k1_ecmult_const(secp256k1_gej *r, const secp256k1_ge *a, cons
214214
#ifdef VERIFY
215215
/* Verify that v1 and v2 are in range [0, 2^129-1]. */
216216
for (i = 129; i < 256; ++i) {
217-
VERIFY_CHECK(secp256k1_scalar_get_bits(&v1, i, 1) == 0);
218-
VERIFY_CHECK(secp256k1_scalar_get_bits(&v2, i, 1) == 0);
217+
VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&v1, i, 1) == 0);
218+
VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&v2, i, 1) == 0);
219219
}
220220
#endif
221221

src/ecmult_gen_compute_table_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ static void secp256k1_ecmult_gen_compute_table(secp256k1_ge_storage* table, cons
3434
for (i = 255; i >= 0; --i) {
3535
/* Use a very simple multiplication ladder to avoid dependency on ecmult. */
3636
secp256k1_gej_double_var(&u, &u, NULL);
37-
if (secp256k1_scalar_get_bits(&half, i, 1)) {
37+
if (secp256k1_scalar_get_bits_limb32(&half, i, 1)) {
3838
secp256k1_gej_add_ge_var(&u, &u, gen, NULL);
3939
}
4040
}

src/ecmult_gen_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context *ctx, secp25
189189
* bits[tooth] = d[(block*COMB_TEETH + tooth)*COMB_SPACING + comb_off]. */
190190
uint32_t bits = 0, sign, abs, index, tooth;
191191
for (tooth = 0; tooth < COMB_TEETH && bit_pos < 256; ++tooth) {
192-
uint32_t bit = secp256k1_scalar_get_bits(&d, bit_pos, 1);
192+
uint32_t bit = secp256k1_scalar_get_bits_limb32(&d, bit_pos, 1);
193193
bits |= bit << tooth;
194194
bit_pos += COMB_SPACING;
195195
}

src/ecmult_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
174174
memset(wnaf, 0, len * sizeof(wnaf[0]));
175175

176176
s = *a;
177-
if (secp256k1_scalar_get_bits(&s, 255, 1)) {
177+
if (secp256k1_scalar_get_bits_limb32(&s, 255, 1)) {
178178
secp256k1_scalar_negate(&s, &s);
179179
sign = -1;
180180
}
181181

182182
while (bit < len) {
183183
int now;
184184
int word;
185-
if (secp256k1_scalar_get_bits(&s, bit, 1) == (unsigned int)carry) {
185+
if (secp256k1_scalar_get_bits_limb32(&s, bit, 1) == (unsigned int)carry) {
186186
bit++;
187187
continue;
188188
}
@@ -209,7 +209,7 @@ static int secp256k1_ecmult_wnaf(int *wnaf, int len, const secp256k1_scalar *a,
209209
VERIFY_CHECK(carry == 0);
210210

211211
while (verify_bit < 256) {
212-
VERIFY_CHECK(secp256k1_scalar_get_bits(&s, verify_bit, 1) == 0);
212+
VERIFY_CHECK(secp256k1_scalar_get_bits_limb32(&s, verify_bit, 1) == 0);
213213
verify_bit++;
214214
}
215215
}

src/scalar.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
static void secp256k1_scalar_clear(secp256k1_scalar *r);
2424

2525
/** Access bits from a scalar. All requested bits must belong to the same 32-bit limb. */
26-
static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count);
26+
static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count);
2727

2828
/** Access bits from a scalar. Not constant time in offset and count. */
29-
static unsigned int secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count);
29+
static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count);
3030

3131
/** Set a scalar from a big endian byte array. The scalar will be reduced modulo group order `n`.
3232
* In: bin: pointer to a 32-byte array.

src/scalar_4x64_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,20 @@ SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsig
4545
SECP256K1_SCALAR_VERIFY(r);
4646
}
4747

48-
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
48+
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
4949
SECP256K1_SCALAR_VERIFY(a);
5050
VERIFY_CHECK((offset + count - 1) >> 6 == offset >> 6);
5151

5252
return (a->d[offset >> 6] >> (offset & 0x3F)) & ((((uint64_t)1) << count) - 1);
5353
}
5454

55-
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
55+
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
5656
SECP256K1_SCALAR_VERIFY(a);
5757
VERIFY_CHECK(count < 32);
5858
VERIFY_CHECK(offset + count <= 256);
5959

6060
if ((offset + count - 1) >> 6 == offset >> 6) {
61-
return secp256k1_scalar_get_bits(a, offset, count);
61+
return secp256k1_scalar_get_bits_limb32(a, offset, count);
6262
} else {
6363
VERIFY_CHECK((offset >> 6) + 1 < 4);
6464
return ((a->d[offset >> 6] >> (offset & 0x3F)) | (a->d[(offset >> 6) + 1] << (64 - (offset & 0x3F)))) & ((((uint64_t)1) << count) - 1);

src/scalar_8x32_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsig
6262
SECP256K1_SCALAR_VERIFY(r);
6363
}
6464

65-
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
65+
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
6666
SECP256K1_SCALAR_VERIFY(a);
6767
VERIFY_CHECK((offset + count - 1) >> 5 == offset >> 5);
6868

6969
return (a->d[offset >> 5] >> (offset & 0x1F)) & ((1 << count) - 1);
7070
}
7171

72-
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
72+
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
7373
SECP256K1_SCALAR_VERIFY(a);
7474
VERIFY_CHECK(count < 32);
7575
VERIFY_CHECK(offset + count <= 256);
7676

7777
if ((offset + count - 1) >> 5 == offset >> 5) {
78-
return secp256k1_scalar_get_bits(a, offset, count);
78+
return secp256k1_scalar_get_bits_limb32(a, offset, count);
7979
} else {
8080
VERIFY_CHECK((offset >> 5) + 1 < 8);
8181
return ((a->d[offset >> 5] >> (offset & 0x1F)) | (a->d[(offset >> 5) + 1] << (32 - (offset & 0x1F)))) & ((((uint32_t)1) << count) - 1);

src/scalar_low_impl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsig
2727
SECP256K1_SCALAR_VERIFY(r);
2828
}
2929

30-
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
30+
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
3131
SECP256K1_SCALAR_VERIFY(a);
3232

3333
if (offset < 32)
@@ -36,10 +36,10 @@ SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits(const secp256k1_s
3636
return 0;
3737
}
3838

39-
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
39+
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
4040
SECP256K1_SCALAR_VERIFY(a);
4141

42-
return secp256k1_scalar_get_bits(a, offset, count);
42+
return secp256k1_scalar_get_bits_limb32(a, offset, count);
4343
}
4444

4545
SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) { return *a >= EXHAUSTIVE_TEST_ORDER; }

src/tests.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2149,7 +2149,7 @@ static void scalar_test(void) {
21492149
for (i = 0; i < 256; i += 4) {
21502150
secp256k1_scalar t;
21512151
int j;
2152-
secp256k1_scalar_set_int(&t, secp256k1_scalar_get_bits(&s, 256 - 4 - i, 4));
2152+
secp256k1_scalar_set_int(&t, secp256k1_scalar_get_bits_limb32(&s, 256 - 4 - i, 4));
21532153
for (j = 0; j < 4; j++) {
21542154
secp256k1_scalar_add(&n, &n, &n);
21552155
}

0 commit comments

Comments
 (0)