Skip to content

Commit fcc48c4

Browse files
committed
Remove the non-storage cmov
1 parent 55422b6 commit fcc48c4

File tree

4 files changed

+12
-42
lines changed

4 files changed

+12
-42
lines changed

src/field.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ static void secp256k1_fe_to_storage(secp256k1_fe_storage_t *r, const secp256k1_f
117117
static void secp256k1_fe_from_storage(secp256k1_fe_t *r, const secp256k1_fe_storage_t*);
118118

119119
/** If flag is true, set *r equal to *a; otherwise leave it. Constant-time. */
120-
static void secp256k1_fe_cmov(secp256k1_fe_t *r, const secp256k1_fe_t *a, int flag);
121120
static void secp256k1_fe_storage_cmov(secp256k1_fe_storage_t *r, const secp256k1_fe_storage_t *a, int flag);
122121

123122
#endif

src/field_10x26_impl.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,26 +1063,6 @@ static void secp256k1_fe_sqr(secp256k1_fe_t *r, const secp256k1_fe_t *a) {
10631063
#endif
10641064
}
10651065

1066-
static void secp256k1_fe_cmov(secp256k1_fe_t *r, const secp256k1_fe_t *a, int flag) {
1067-
uint32_t mask0 = flag + ~((uint32_t)0), mask1 = ~mask0;
1068-
r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);
1069-
r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);
1070-
r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);
1071-
r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);
1072-
r->n[4] = (r->n[4] & mask0) | (a->n[4] & mask1);
1073-
r->n[5] = (r->n[5] & mask0) | (a->n[5] & mask1);
1074-
r->n[6] = (r->n[6] & mask0) | (a->n[6] & mask1);
1075-
r->n[7] = (r->n[7] & mask0) | (a->n[7] & mask1);
1076-
r->n[8] = (r->n[8] & mask0) | (a->n[8] & mask1);
1077-
r->n[9] = (r->n[9] & mask0) | (a->n[9] & mask1);
1078-
#ifdef VERIFY
1079-
if (flag) {
1080-
r->magnitude = a->magnitude;
1081-
r->normalized = a->normalized;
1082-
}
1083-
#endif
1084-
}
1085-
10861066
static inline void secp256k1_fe_storage_cmov(secp256k1_fe_storage_t *r, const secp256k1_fe_storage_t *a, int flag) {
10871067
uint32_t mask0 = flag + ~((uint32_t)0), mask1 = ~mask0;
10881068
r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);

src/field_5x52_impl.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -398,21 +398,6 @@ static void secp256k1_fe_sqr(secp256k1_fe_t *r, const secp256k1_fe_t *a) {
398398
#endif
399399
}
400400

401-
static void secp256k1_fe_cmov(secp256k1_fe_t *r, const secp256k1_fe_t *a, int flag) {
402-
uint64_t mask0 = flag + ~((uint64_t)0), mask1 = ~mask0;
403-
r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);
404-
r->n[1] = (r->n[1] & mask0) | (a->n[1] & mask1);
405-
r->n[2] = (r->n[2] & mask0) | (a->n[2] & mask1);
406-
r->n[3] = (r->n[3] & mask0) | (a->n[3] & mask1);
407-
r->n[4] = (r->n[4] & mask0) | (a->n[4] & mask1);
408-
#ifdef VERIFY
409-
if (flag) {
410-
r->magnitude = a->magnitude;
411-
r->normalized = a->normalized;
412-
}
413-
#endif
414-
}
415-
416401
static inline void secp256k1_fe_storage_cmov(secp256k1_fe_storage_t *r, const secp256k1_fe_storage_t *a, int flag) {
417402
uint64_t mask0 = flag + ~((uint64_t)0), mask1 = ~mask0;
418403
r->n[0] = (r->n[0] & mask0) | (a->n[0] & mask1);

src/tests.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -685,12 +685,18 @@ void run_field_misc(void) {
685685
z = x;
686686
secp256k1_fe_add(&z,&y);
687687
secp256k1_fe_normalize(&z);
688-
/* Test the conditional move. */
689-
secp256k1_fe_cmov(&z, &x, 0);
690-
CHECK(secp256k1_fe_equal_var(&x, &z) == 0);
691-
CHECK(secp256k1_fe_cmp_var(&x, &z) != 0);
692-
secp256k1_fe_cmov(&y, &x, 1);
693-
CHECK(secp256k1_fe_equal_var(&x, &y));
688+
/* Test storage conversion and conditional moves. */
689+
secp256k1_fe_storage_t xs, ys, zs;
690+
secp256k1_fe_to_storage(&xs, &x);
691+
secp256k1_fe_to_storage(&ys, &y);
692+
secp256k1_fe_to_storage(&zs, &z);
693+
secp256k1_fe_storage_cmov(&zs, &xs, 0);
694+
CHECK(memcmp(&xs, &zs, sizeof(xs)) != 0);
695+
secp256k1_fe_storage_cmov(&ys, &xs, 1);
696+
CHECK(memcmp(&xs, &ys, sizeof(xs)) == 0);
697+
secp256k1_fe_from_storage(&x, &xs);
698+
secp256k1_fe_from_storage(&y, &ys);
699+
secp256k1_fe_from_storage(&z, &zs);
694700
/* Test that mul_int, mul, and add agree. */
695701
secp256k1_fe_add(&y, &x);
696702
secp256k1_fe_add(&y, &x);

0 commit comments

Comments
 (0)