Skip to content

Commit 22f60a6

Browse files
committed
Merge pull request bitcoin#245
c146b4a Add bench_internal to gitignore. (Gregory Maxwell) 9c4fb23 Add a secp256k1_fe_cmov unit test. (Gregory Maxwell)
2 parents 61c1b1e + c146b4a commit 22f60a6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ bench_inv
22
bench_sign
33
bench_verify
44
bench_recover
5+
bench_internal
56
tests
67
*.exe
78
*.so

src/tests.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**********************************************************************
2-
* Copyright (c) 2013, 2014 Pieter Wuille *
2+
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell *
33
* Distributed under the MIT software license, see the accompanying *
44
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
55
**********************************************************************/
@@ -753,12 +753,22 @@ void run_field_misc(void) {
753753
CHECK(secp256k1_fe_equal_var(&x, &x));
754754
z = x;
755755
secp256k1_fe_add(&z,&y);
756-
secp256k1_fe_normalize(&z);
756+
/* Test fe conditional move; z is not normalized here. */
757+
q = x;
758+
secp256k1_fe_cmov(&x, &z, 0);
759+
secp256k1_fe_cmov(&x, &x, 1);
760+
CHECK(memcmp(&x, &z, sizeof(x)) != 0);
761+
CHECK(memcmp(&x, &q, sizeof(x)) == 0);
762+
secp256k1_fe_cmov(&q, &z, 1);
763+
CHECK(memcmp(&q, &z, sizeof(q)) == 0);
757764
/* Test storage conversion and conditional moves. */
765+
secp256k1_fe_normalize(&z);
766+
CHECK(!secp256k1_fe_equal_var(&x, &z));
758767
secp256k1_fe_to_storage(&xs, &x);
759768
secp256k1_fe_to_storage(&ys, &y);
760769
secp256k1_fe_to_storage(&zs, &z);
761770
secp256k1_fe_storage_cmov(&zs, &xs, 0);
771+
secp256k1_fe_storage_cmov(&zs, &zs, 1);
762772
CHECK(memcmp(&xs, &zs, sizeof(xs)) != 0);
763773
secp256k1_fe_storage_cmov(&ys, &xs, 1);
764774
CHECK(memcmp(&xs, &ys, sizeof(xs)) == 0);

0 commit comments

Comments
 (0)