Skip to content

Commit

Permalink
Merge pull request bitcoin#245
Browse files Browse the repository at this point in the history
c146b4a Add bench_internal to gitignore. (Gregory Maxwell)
9c4fb23 Add a secp256k1_fe_cmov unit test. (Gregory Maxwell)
  • Loading branch information
sipa committed Apr 22, 2015
2 parents 61c1b1e + c146b4a commit 22f60a6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bench_inv
bench_sign
bench_verify
bench_recover
bench_internal
tests
*.exe
*.so
Expand Down
14 changes: 12 additions & 2 deletions src/tests.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**********************************************************************
* Copyright (c) 2013, 2014 Pieter Wuille *
* Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell *
* Distributed under the MIT software license, see the accompanying *
* file COPYING or http://www.opensource.org/licenses/mit-license.php.*
**********************************************************************/
Expand Down Expand Up @@ -753,12 +753,22 @@ void run_field_misc(void) {
CHECK(secp256k1_fe_equal_var(&x, &x));
z = x;
secp256k1_fe_add(&z,&y);
secp256k1_fe_normalize(&z);
/* Test fe conditional move; z is not normalized here. */
q = x;
secp256k1_fe_cmov(&x, &z, 0);
secp256k1_fe_cmov(&x, &x, 1);
CHECK(memcmp(&x, &z, sizeof(x)) != 0);
CHECK(memcmp(&x, &q, sizeof(x)) == 0);
secp256k1_fe_cmov(&q, &z, 1);
CHECK(memcmp(&q, &z, sizeof(q)) == 0);
/* Test storage conversion and conditional moves. */
secp256k1_fe_normalize(&z);
CHECK(!secp256k1_fe_equal_var(&x, &z));
secp256k1_fe_to_storage(&xs, &x);
secp256k1_fe_to_storage(&ys, &y);
secp256k1_fe_to_storage(&zs, &z);
secp256k1_fe_storage_cmov(&zs, &xs, 0);
secp256k1_fe_storage_cmov(&zs, &zs, 1);
CHECK(memcmp(&xs, &zs, sizeof(xs)) != 0);
secp256k1_fe_storage_cmov(&ys, &xs, 1);
CHECK(memcmp(&xs, &ys, sizeof(xs)) == 0);
Expand Down

0 comments on commit 22f60a6

Please sign in to comment.