@@ -123,10 +123,42 @@ 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_inv [32 ];
133
+ unsigned char out_base [32 ];
134
+ int i ;
135
+
136
+ unsigned char s_one [32 ] = { 0 };
137
+ s_one [31 ] = 1 ;
138
+ CHECK (secp256k1_ec_pubkey_create (ctx , & point , s_one ) == 1 );
139
+ CHECK (secp256k1_ecdh (ctx , out_base , & point , s_one , NULL , NULL ) == 1 );
140
+
141
+ for (i = 0 ; i < 2 * count ; i ++ ) {
142
+ random_scalar_order (& rand );
143
+ secp256k1_scalar_get_b32 (s , & rand );
144
+ secp256k1_scalar_inverse (& rand , & rand );
145
+ secp256k1_scalar_get_b32 (s_inv , & rand );
146
+
147
+ CHECK (secp256k1_ec_pubkey_create (ctx , & point , s ) == 1 );
148
+ CHECK (secp256k1_ecdh (ctx , out , & point , s_inv , NULL , NULL ) == 1 );
149
+ CHECK (secp256k1_memcmp_var (out , out_base , 32 ) == 0 );
150
+
151
+ CHECK (secp256k1_ec_pubkey_create (ctx , & point , s_inv ) == 1 );
152
+ CHECK (secp256k1_ecdh (ctx , out_inv , & point , s , NULL , NULL ) == 1 );
153
+ CHECK (secp256k1_memcmp_var (out_inv , out_base , 32 ) == 0 );
154
+ }
155
+ }
156
+
126
157
void run_ecdh_tests (void ) {
127
158
test_ecdh_api ();
128
159
test_ecdh_generator_basepoint ();
129
160
test_bad_scalar ();
161
+ test_result_basepoint ();
130
162
}
131
163
132
164
#endif /* SECP256K1_MODULE_ECDH_TESTS_H */
0 commit comments