@@ -123,10 +123,40 @@ void test_bad_scalar(void) {
123
123
CHECK (secp256k1_ecdh (ctx , output , & point , s_overflow , ecdh_hash_function_test_fail , NULL ) == 0 );
124
124
}
125
125
126
+ void test_result_basepoint (void ) {
127
+ secp256k1_pubkey point ;
128
+ secp256k1_scalar rand ;
129
+ unsigned char s [32 ];
130
+ unsigned char s_inv [32 ];
131
+ unsigned char out [32 ];
132
+ unsigned char out_eq [32 ];
133
+ int i ;
134
+
135
+ for (i = 0 ; i < 64 ; i ++ ) {
136
+ random_scalar_order (& rand );
137
+ secp256k1_scalar_get_b32 (s , & rand );
138
+ secp256k1_scalar_inverse (& rand , & rand );
139
+ secp256k1_scalar_get_b32 (s_inv , & rand );
140
+
141
+ CHECK (secp256k1_ec_pubkey_create (ctx , & point , s ) == 1 );
142
+ CHECK (secp256k1_ecdh (ctx , out , & point , s_inv , NULL , NULL ) == 1 );
143
+
144
+ if (i > 0 ) {
145
+ CHECK (secp256k1_memcmp_var (out , out_eq , 32 ) == 0 );
146
+ }
147
+
148
+ CHECK (secp256k1_ec_pubkey_create (ctx , & point , s_inv ) == 1 );
149
+ CHECK (secp256k1_ecdh (ctx , out_eq , & point , s , NULL , NULL ) == 1 );
150
+
151
+ CHECK (secp256k1_memcmp_var (out , out_eq , 32 ) == 0 );
152
+ }
153
+ }
154
+
126
155
void run_ecdh_tests (void ) {
127
156
test_ecdh_api ();
128
157
test_ecdh_generator_basepoint ();
129
158
test_bad_scalar ();
159
+ test_result_basepoint ();
130
160
}
131
161
132
162
#endif /* SECP256K1_MODULE_ECDH_TESTS_H */
0 commit comments