|
1 | 1 | /********************************************************************** |
2 | | - * Copyright (c) 2013, 2014 Pieter Wuille * |
| 2 | + * Copyright (c) 2013, 2014, 2015 Pieter Wuille, Gregory Maxwell * |
3 | 3 | * Distributed under the MIT software license, see the accompanying * |
4 | 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* |
5 | 5 | **********************************************************************/ |
@@ -753,12 +753,22 @@ void run_field_misc(void) { |
753 | 753 | CHECK(secp256k1_fe_equal_var(&x, &x)); |
754 | 754 | z = x; |
755 | 755 | 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); |
757 | 764 | /* Test storage conversion and conditional moves. */ |
| 765 | + secp256k1_fe_normalize(&z); |
| 766 | + CHECK(!secp256k1_fe_equal_var(&x, &z)); |
758 | 767 | secp256k1_fe_to_storage(&xs, &x); |
759 | 768 | secp256k1_fe_to_storage(&ys, &y); |
760 | 769 | secp256k1_fe_to_storage(&zs, &z); |
761 | 770 | secp256k1_fe_storage_cmov(&zs, &xs, 0); |
| 771 | + secp256k1_fe_storage_cmov(&zs, &zs, 1); |
762 | 772 | CHECK(memcmp(&xs, &zs, sizeof(xs)) != 0); |
763 | 773 | secp256k1_fe_storage_cmov(&ys, &xs, 1); |
764 | 774 | CHECK(memcmp(&xs, &ys, sizeof(xs)) == 0); |
|
0 commit comments