@@ -20,58 +20,93 @@ namespace ack::tests {
20
20
using point_type = std::remove_cvref_t <decltype(curve)>::point_type;
21
21
using int_type = std::remove_cvref_t <decltype(curve)>::int_type;
22
22
23
- constexpr auto q = curve.make_point(
24
- " e424dc61d4bb3cb7ef4344a7f8957a0c5134e16f7a67c074f82e6e12f49abf3c" ,
25
- " 970eed7aa2bc48651545949de1dddaf0127e5965ac85d1243d6f60e7dfaee927"
26
- );
27
-
28
- constexpr auto h = from_hex( " d1b8ef21eb4182ee270638061063a3f3c16c114e33937f69fb232cc833965a94" );
29
- auto md = hash256( h );
30
- constexpr int_type r = " bf96b99aa49c705c910be33142017c642ff540c76349b9dab72f981fd9347f4f" ;
31
- constexpr int_type s = " 17c55095819089c2e03b9cd415abdf12444e323075d98f31920b9e0f57ec871c" ;
32
- constexpr size_t recid = 1 ;
33
-
34
23
// Misc ECDSA key recovery tests
35
24
{
36
- // Test recovery succeeds
37
- REQUIRE_EQUAL ( ecdsa_recover ( q.curve (), h, r, s, recid, /* verify=*/ true ), q )
25
+ auto q = curve.make_point (
26
+ " e424dc61d4bb3cb7ef4344a7f8957a0c5134e16f7a67c074f82e6e12f49abf3c" ,
27
+ " 970eed7aa2bc48651545949de1dddaf0127e5965ac85d1243d6f60e7dfaee927"
28
+ );
29
+
30
+ auto h = from_hex ( " d1b8ef21eb4182ee270638061063a3f3c16c114e33937f69fb232cc833965a94" );
31
+ auto md = hash256 ( h );
32
+ int_type r = " bf96b99aa49c705c910be33142017c642ff540c76349b9dab72f981fd9347f4f" ;
33
+ int_type s = " 17c55095819089c2e03b9cd415abdf12444e323075d98f31920b9e0f57ec871c" ;
34
+ size_t recid = 1 ;
38
35
39
- // Test passing too big recid results in point at infinity
40
- REQUIRE_EQUAL ( ecdsa_recover ( q.curve (), h, r, s, /* recid=*/ 4 , /* verify=*/ true ).is_identity (), true )
41
- REQUIRE_EQUAL ( ecdsa_recover ( q.curve (), md, r, s, /* recid=*/ 4 , /* verify=*/ true ).is_identity (), true )
42
- REQUIRE_EQUAL ( ecdsa_recover ( q.curve (), h, r, s, /* recid=*/ 0xff , /* verify=*/ true ).is_identity (), true )
43
- REQUIRE_EQUAL ( ecdsa_recover ( q.curve (), md, r, s, /* recid=*/ 0xff , /* verify=*/ true ).is_identity (), true )
36
+ // Test recovery succeeds
37
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, recid, /* verify=*/ true ), q )
38
+
39
+ // Test using invalid recid recovers different point than q
40
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, /* recid=*/ 0 , /* verify=*/ true ) != q, true )
41
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, s, /* recid=*/ 0 , /* verify=*/ true ) != q, true )
42
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, /* recid=*/ 2 , /* verify=*/ true ) != q, true )
43
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, s, /* recid=*/ 2 , /* verify=*/ true ) != q, true )
44
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, /* recid=*/ 3 , /* verify=*/ true ) != q, true )
45
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, s, /* recid=*/ 3 , /* verify=*/ true ) != q, true )
46
+
47
+ // Test passing too big recid results in point at infinity
48
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, /* recid=*/ 0x04 , /* verify=*/ true ).is_identity (), true )
49
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, s, /* recid=*/ 0x04 , /* verify=*/ true ).is_identity (), true )
50
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, /* recid=*/ 0xff , /* verify=*/ true ).is_identity (), true )
51
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, s, /* recid=*/ 0xff , /* verify=*/ true ).is_identity (), true )
44
52
45
53
// Test passing too small and too big r
46
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve (), h, int_type ( 0 ), s, recid, /* verify=*/ true ).is_identity (), true )
47
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve () , md, int_type ( 0 ), s, recid, /* verify=*/ true ).is_identity (), true )
54
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, int_type ( 0 ), s, recid, /* verify=*/ true ).is_identity (), true )
55
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, int_type ( 0 ), s, recid, /* verify=*/ true ).is_identity (), true )
48
56
49
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve (), h, curve.n , s, recid, /* verify=*/ true ).is_identity (), true )
50
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve () , md, curve.n , s, recid, /* verify=*/ true ).is_identity (), true )
57
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, curve.n , s, recid, /* verify=*/ true ).is_identity (), true )
58
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, curve.n , s, recid, /* verify=*/ true ).is_identity (), true )
51
59
52
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve (), h, curve.n + 1 , s, recid, /* verify=*/ true ).is_identity (), true )
53
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve () , md, curve.n + 1 , s, recid, /* verify=*/ true ).is_identity (), true )
60
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, curve.n + 1 , s, recid, /* verify=*/ true ).is_identity (), true )
61
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, curve.n + 1 , s, recid, /* verify=*/ true ).is_identity (), true )
54
62
55
63
// Test passing too small and too big s
56
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve (), h, r, int_type ( 0 ), recid, /* verify=*/ true ).is_identity (), true )
57
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve () , md, r, int_type ( 0 ), recid, /* verify=*/ true ).is_identity (), true )
64
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, int_type ( 0 ), recid, /* verify=*/ true ).is_identity (), true )
65
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, int_type ( 0 ), recid, /* verify=*/ true ).is_identity (), true )
58
66
59
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve (), h, r, curve.n , recid, /* verify=*/ true ).is_identity (), true )
60
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve () , md, r, curve.n , recid, /* verify=*/ true ).is_identity (), true )
67
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, curve.n , recid, /* verify=*/ true ).is_identity (), true )
68
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, curve.n , recid, /* verify=*/ true ).is_identity (), true )
61
69
62
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve (), h, r, curve.n + 1 , recid, /* verify=*/ true ).is_identity (), true )
63
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve () , md, r, curve.n + 1 , recid, /* verify=*/ true ).is_identity (), true )
70
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, curve.n + 1 , recid, /* verify=*/ true ).is_identity (), true )
71
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, curve.n + 1 , recid, /* verify=*/ true ).is_identity (), true )
64
72
65
73
// Test passing too big r when recovering second key
66
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve (), h, curve.p_minus_n , s, 2 , /* verify=*/ true ).is_identity (), true )
67
- REQUIRE_EQUAL ( ecdsa_recover ( q. curve () , md, curve.p_minus_n , s, 2 , /* verify=*/ true ).is_identity (), true )
74
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, curve.p_minus_n , s, 2 , /* verify=*/ true ).is_identity (), true )
75
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, curve.p_minus_n , s, 2 , /* verify=*/ true ).is_identity (), true )
68
76
69
- REQUIRE_EQUAL ( ecdsa_recover ( q.curve (), h, curve.p_minus_n + 1 , s, 2 , /* verify=*/ true ).is_identity (), true )
70
- REQUIRE_EQUAL ( ecdsa_recover ( q.curve (), md, curve.p_minus_n + 1 , s, 2 , /* verify=*/ true ).is_identity (), true )
77
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, curve.p_minus_n + 1 , s, 2 , /* verify=*/ true ).is_identity (), true )
78
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, curve.p_minus_n + 1 , s, 2 , /* verify=*/ true ).is_identity (), true )
79
+
80
+ // Test recovery fails when signed message changes
81
+ q = curve.make_point (
82
+ " 69b7667056e1e11d6caf6e45643f8b21e7a4bebda463c7fdbc13bc98efbd0214" ,
83
+ " d3f9b12eb46c7c6fda0da3fc85bc1fd831557f9abc902a3be3cb3e8be7d1aa2f"
84
+ );
85
+ h = from_hex ( " d80e9933e86769731ec16ff31e6821531bcf07fcbad9e2ac16ec9e6cb343a870" );
86
+ md = hash256 ( h );
87
+ r = " 288f7a1cd391842cce21f00e6f15471c04dc182fe4b14d92dc18910879799790" ;
88
+ s = " 247b3c4e89a3bcadfea73c7bfd361def43715fa382b8c3edf4ae15d6e55e9979" ;
89
+ for ( std::size_t i = 0 ; i < 4 ; i++ ) {
90
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, /* recid=*/ i, /* verify=*/ false ) != q, true )
91
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, s, /* recid=*/ i, /* verify=*/ false ) != q, true )
92
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, h, r, s, /* recid=*/ i, /* verify=*/ true ) != q, true )
93
+ REQUIRE_EQUAL ( ecdsa_recover ( curve, md, r, s, /* recid=*/ i, /* verify=*/ true ) != q, true )
94
+ }
71
95
}
72
96
73
97
// Misc ECDSA sigver tests
74
98
{
99
+ auto q = curve.make_point (
100
+ " e424dc61d4bb3cb7ef4344a7f8957a0c5134e16f7a67c074f82e6e12f49abf3c" ,
101
+ " 970eed7aa2bc48651545949de1dddaf0127e5965ac85d1243d6f60e7dfaee927"
102
+ );
103
+
104
+ auto h = from_hex ( " d1b8ef21eb4182ee270638061063a3f3c16c114e33937f69fb232cc833965a94" );
105
+ auto md = hash256 ( h );
106
+ int_type r = " bf96b99aa49c705c910be33142017c642ff540c76349b9dab72f981fd9347f4f" ;
107
+ int_type s = " 17c55095819089c2e03b9cd415abdf12444e323075d98f31920b9e0f57ec871c" ;
108
+ size_t recid = 1 ;
109
+
75
110
// Test verification ECDSA signature succeeds
76
111
REQUIRE_EQUAL ( ecdsa_verify ( q, h, r, s ), true )
77
112
REQUIRE_EQUAL ( ecdsa_verify ( q, md, r, s ), true )
0 commit comments