@@ -188,4 +188,36 @@ BOOST_AUTO_TEST_CASE(key_signature_tests)
188
188
BOOST_CHECK (found_small);
189
189
}
190
190
191
+ BOOST_AUTO_TEST_CASE (key_key_negation)
192
+ {
193
+ // create a dummy hash for signature comparison
194
+ unsigned char rnd[8 ];
195
+ std::string str = " Bitcoin key verification\n " ;
196
+ GetRandBytes (rnd, sizeof (rnd));
197
+ uint256 hash;
198
+ CHash256 ().Write ((unsigned char *)str.data (), str.size ()).Write (rnd, sizeof (rnd)).Finalize (hash.begin ());
199
+
200
+ // import the static test key
201
+ CKey key = DecodeSecret (strSecret1C);
202
+
203
+ // create a signature
204
+ std::vector<unsigned char > vch_sig;
205
+ std::vector<unsigned char > vch_sig_cmp;
206
+ key.Sign (hash, vch_sig);
207
+
208
+ // negate the key twice
209
+ BOOST_CHECK (key.GetPubKey ().data ()[0 ] == 0x03 );
210
+ key.Negate ();
211
+ // after the first negation, the signature must be different
212
+ key.Sign (hash, vch_sig_cmp);
213
+ BOOST_CHECK (vch_sig_cmp != vch_sig);
214
+ BOOST_CHECK (key.GetPubKey ().data ()[0 ] == 0x02 );
215
+ key.Negate ();
216
+ // after the second negation, we should have the original key and thus the
217
+ // same signature
218
+ key.Sign (hash, vch_sig_cmp);
219
+ BOOST_CHECK (vch_sig_cmp == vch_sig);
220
+ BOOST_CHECK (key.GetPubKey ().data ()[0 ] == 0x03 );
221
+ }
222
+
191
223
BOOST_AUTO_TEST_SUITE_END ()
0 commit comments