Skip to content

Commit 97c57f4

Browse files
real-or-randomtheStack
authored andcommitted
Implement various _clear() functions with secp256k1_memclear()
1 parent 9bb368d commit 97c57f4

File tree

9 files changed

+10
-55
lines changed

9 files changed

+10
-55
lines changed

src/field.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ static const secp256k1_fe secp256k1_const_beta = SECP256K1_FE_CONST(
8181
# define secp256k1_fe_normalizes_to_zero secp256k1_fe_impl_normalizes_to_zero
8282
# define secp256k1_fe_normalizes_to_zero_var secp256k1_fe_impl_normalizes_to_zero_var
8383
# define secp256k1_fe_set_int secp256k1_fe_impl_set_int
84-
# define secp256k1_fe_clear secp256k1_fe_impl_clear
8584
# define secp256k1_fe_is_zero secp256k1_fe_impl_is_zero
8685
# define secp256k1_fe_is_odd secp256k1_fe_impl_is_odd
8786
# define secp256k1_fe_cmp_var secp256k1_fe_impl_cmp_var

src/field_10x26_impl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,6 @@ SECP256K1_INLINE static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a) {
270270
return a->n[0] & 1;
271271
}
272272

273-
SECP256K1_INLINE static void secp256k1_fe_impl_clear(secp256k1_fe *a) {
274-
int i;
275-
for (i=0; i<10; i++) {
276-
a->n[i] = 0;
277-
}
278-
}
279-
280273
static int secp256k1_fe_impl_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {
281274
int i;
282275
for (i = 9; i >= 0; i--) {

src/field_5x52_impl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,6 @@ SECP256K1_INLINE static int secp256k1_fe_impl_is_odd(const secp256k1_fe *a) {
212212
return a->n[0] & 1;
213213
}
214214

215-
SECP256K1_INLINE static void secp256k1_fe_impl_clear(secp256k1_fe *a) {
216-
int i;
217-
for (i=0; i<5; i++) {
218-
a->n[i] = 0;
219-
}
220-
}
221-
222215
static int secp256k1_fe_impl_cmp_var(const secp256k1_fe *a, const secp256k1_fe *b) {
223216
int i;
224217
for (i = 4; i >= 0; i--) {

src/field_impl.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
#error "Please select wide multiplication implementation"
1919
#endif
2020

21+
SECP256K1_INLINE static void secp256k1_fe_clear(secp256k1_fe *a) {
22+
secp256k1_memclear(a, sizeof(secp256k1_fe));
23+
}
24+
2125
SECP256K1_INLINE static int secp256k1_fe_equal(const secp256k1_fe *a, const secp256k1_fe *b) {
2226
secp256k1_fe na;
2327
SECP256K1_FE_VERIFY(a);
@@ -232,15 +236,6 @@ SECP256K1_INLINE static void secp256k1_fe_add_int(secp256k1_fe *r, int a) {
232236
SECP256K1_FE_VERIFY(r);
233237
}
234238

235-
static void secp256k1_fe_impl_clear(secp256k1_fe *a);
236-
SECP256K1_INLINE static void secp256k1_fe_clear(secp256k1_fe *a) {
237-
a->magnitude = 0;
238-
a->normalized = 0;
239-
secp256k1_fe_impl_clear(a);
240-
241-
SECP256K1_FE_VERIFY(a);
242-
}
243-
244239
static int secp256k1_fe_impl_is_zero(const secp256k1_fe *a);
245240
SECP256K1_INLINE static int secp256k1_fe_is_zero(const secp256k1_fe *a) {
246241
SECP256K1_FE_VERIFY(a);

src/group_impl.h

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,20 +299,11 @@ static void secp256k1_ge_set_infinity(secp256k1_ge *r) {
299299
}
300300

301301
static void secp256k1_gej_clear(secp256k1_gej *r) {
302-
r->infinity = 0;
303-
secp256k1_fe_clear(&r->x);
304-
secp256k1_fe_clear(&r->y);
305-
secp256k1_fe_clear(&r->z);
306-
307-
SECP256K1_GEJ_VERIFY(r);
302+
secp256k1_memclear(r, sizeof(secp256k1_gej));
308303
}
309304

310305
static void secp256k1_ge_clear(secp256k1_ge *r) {
311-
r->infinity = 0;
312-
secp256k1_fe_clear(&r->x);
313-
secp256k1_fe_clear(&r->y);
314-
315-
SECP256K1_GE_VERIFY(r);
306+
secp256k1_memclear(r, sizeof(secp256k1_ge));
316307
}
317308

318309
static int secp256k1_ge_set_xo_var(secp256k1_ge *r, const secp256k1_fe *x, int odd) {

src/scalar_4x64_impl.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,6 @@
2929
#define SECP256K1_N_H_2 ((uint64_t)0xFFFFFFFFFFFFFFFFULL)
3030
#define SECP256K1_N_H_3 ((uint64_t)0x7FFFFFFFFFFFFFFFULL)
3131

32-
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) {
33-
r->d[0] = 0;
34-
r->d[1] = 0;
35-
r->d[2] = 0;
36-
r->d[3] = 0;
37-
}
38-
3932
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {
4033
r->d[0] = v;
4134
r->d[1] = 0;

src/scalar_8x32_impl.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,6 @@
3838
#define SECP256K1_N_H_6 ((uint32_t)0xFFFFFFFFUL)
3939
#define SECP256K1_N_H_7 ((uint32_t)0x7FFFFFFFUL)
4040

41-
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) {
42-
r->d[0] = 0;
43-
r->d[1] = 0;
44-
r->d[2] = 0;
45-
r->d[3] = 0;
46-
r->d[4] = 0;
47-
r->d[5] = 0;
48-
r->d[6] = 0;
49-
r->d[7] = 0;
50-
}
51-
5241
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {
5342
r->d[0] = v;
5443
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
static int secp256k1_scalar_set_b32_seckey(secp256k1_scalar *r, const unsigned char *bin) {
3135
int overflow;
3236
secp256k1_scalar_set_b32(r, bin, &overflow);

src/scalar_low_impl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ SECP256K1_INLINE static int secp256k1_scalar_is_even(const secp256k1_scalar *a)
1919
return !(*a & 1);
2020
}
2121

22-
SECP256K1_INLINE static void secp256k1_scalar_clear(secp256k1_scalar *r) { *r = 0; }
23-
2422
SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsigned int v) {
2523
*r = v % EXHAUSTIVE_TEST_ORDER;
2624

0 commit comments

Comments
 (0)