Skip to content

Commit b8b9462

Browse files
Implement various _clear() functions with secp256k1_memclear()
1 parent b7bbb66 commit b8b9462

File tree

8 files changed

+10
-48
lines changed

8 files changed

+10
-48
lines changed

src/field_10x26_impl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,6 @@ SECP256K1_INLINE static int secp256k1_fe_is_odd(const secp256k1_fe *a) {
289289
return a->n[0] & 1;
290290
}
291291

292-
SECP256K1_INLINE static void secp256k1_fe_clear(secp256k1_fe *a) {
293-
int i;
294-
#ifdef VERIFY
295-
a->magnitude = 0;
296-
a->normalized = 0;
297-
#endif
298-
for (i=0; i<10; i++) {
299-
a->n[i] = 0;
300-
}
301-
}
302-
303292
static int secp256k1_fe_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {
304293
int i;
305294
#ifdef VERIFY

src/field_5x52_impl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -252,17 +252,6 @@ SECP256K1_INLINE static int secp256k1_fe_is_odd(const secp256k1_fe *a) {
252252
return a->n[0] & 1;
253253
}
254254

255-
SECP256K1_INLINE static void secp256k1_fe_clear(secp256k1_fe *a) {
256-
int i;
257-
#ifdef VERIFY
258-
a->magnitude = 0;
259-
a->normalized = 0;
260-
#endif
261-
for (i=0; i<5; i++) {
262-
a->n[i] = 0;
263-
}
264-
}
265-
266255
static int secp256k1_fe_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {
267256
int i;
268257
#ifdef VERIFY

src/field_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ SECP256K1_INLINE static int secp256k1_fe_equal_var(const secp256k1_fe *a, const
3636
return secp256k1_fe_normalizes_to_zero_var(&na);
3737
}
3838

39+
SECP256K1_INLINE static void secp256k1_fe_clear(secp256k1_fe *a) {
40+
secp256k1_memclear(a, sizeof(secp256k1_fe));
41+
}
42+
3943
static int secp256k1_fe_sqrt(secp256k1_fe *r, const secp256k1_fe *a) {
4044
/** Given that p is congruent to 3 mod 4, we can compute the square root of
4145
* a mod p as the (p+1)/4'th power of a.

src/group_impl.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,11 @@ static void secp256k1_ge_set_infinity(secp256k1_ge *r) {
206206
}
207207

208208
static void secp256k1_gej_clear(secp256k1_gej *r) {
209-
r->infinity = 0;
210-
secp256k1_fe_clear(&r->x);
211-
secp256k1_fe_clear(&r->y);
212-
secp256k1_fe_clear(&r->z);
209+
secp256k1_memclear(r, sizeof(secp256k1_gej));
213210
}
214211

215212
static void secp256k1_ge_clear(secp256k1_ge *r) {
216-
r->infinity = 0;
217-
secp256k1_fe_clear(&r->x);
218-
secp256k1_fe_clear(&r->y);
213+
secp256k1_memclear(r, sizeof(secp256k1_ge));
219214
}
220215

221216
static int secp256k1_ge_set_xquad(secp256k1_ge *r, const secp256k1_fe *x) {

src/scalar_4x64_impl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,6 @@
2424
#define SECP256K1_N_H_2 ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
2525
#define SECP256K1_N_H_3 ((uint64_t)0x7FFFFFFFFFFFFFFFULL)
2626

27-
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) {
28-
r->d[0] = 0;
29-
r->d[1] = 0;
30-
r->d[2] = 0;
31-
r->d[3] = 0;
32-
}
33-
3427
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {
3528
r->d[0] = v;
3629
r->d[1] = 0;

src/scalar_8x32_impl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,6 @@
3434
#define SECP256K1_N_H_6 ((uint32_t)0xFFFFFFFFUL)
3535
#define SECP256K1_N_H_7 ((uint32_t)0x7FFFFFFFUL)
3636

37-
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) {
38-
r->d[0] = 0;
39-
r->d[1] = 0;
40-
r->d[2] = 0;
41-
r->d[3] = 0;
42-
r->d[4] = 0;
43-
r->d[5] = 0;
44-
r->d[6] = 0;
45-
r->d[7] = 0;
46-
}
47-
4837
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {
4938
r->d[0] = v;
5039
r->d[1] = 0;

src/scalar_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
static const secp256k1_scalar secp256k1_scalar_one = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 1);
2828
static const secp256k1_scalar secp256k1_scalar_zero = SECP256K1_SCALAR_CONST(0, 0, 0, 0, 0, 0, 0, 0);
2929

30+
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) {
31+
secp256k1_memclear(r, sizeof(secp256k1_scalar));
32+
}
33+
3034
#ifndef USE_NUM_NONE
3135
static void secp256k1_scalar_get_num(secp256k1_num *r, const secp256k1_scalar *a) {
3236
unsigned char c[32];

src/scalar_low_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a)
1515
return !(*a & 1);
1616
}
1717

18-
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) { *r = 0; }
1918
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) { *r = v; }
2019

2120
SECP256K1_INLINE static unsigned int secp256k1_scalar_get_bits(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {

0 commit comments

Comments
 (0)