Skip to content

Commit 9c4fb23

Browse files
committed
Add a secp256k1_fe_cmov unit test.
(Also add my name to the top of tests.c: I wrote a bunch of that and update the copyright dates)
1 parent 426fa52 commit 9c4fb23

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

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)