7 #ifndef SECP256K1_MODULE_RECOVERY_TESTS_H
8 #define SECP256K1_MODULE_RECOVERY_TESTS_H
10 static int recovery_test_nonce_function(
unsigned char *nonce32,
const unsigned char *msg32,
const unsigned char *key32,
const unsigned char *algo16,
void *data,
unsigned int counter) {
18 memset(nonce32, 0, 32);
23 memset(nonce32, 0xff, 32);
27 memset(nonce32, 1, 32);
28 return secp256k1_rand_bits(1);
41 unsigned char privkey[32] = { 1 };
42 unsigned char message[32] = { 2 };
45 unsigned char sig[74];
46 unsigned char zero_privkey[32] = { 0 };
47 unsigned char over_privkey[32] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
48 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
49 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
50 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
139 memcpy(sig, over_privkey, 32);
151 unsigned char extra[32] = {0x00};
152 unsigned char privkey[32];
153 unsigned char message[32];
156 unsigned char sig[74];
166 secp256k1_scalar_get_b32(privkey, &
key);
167 secp256k1_scalar_get_b32(message, &msg);
187 CHECK(memcmp(&signature[4], &signature[0], 64) == 0);
189 memset(&rsignature[4], 0,
sizeof(rsignature[4]));
196 CHECK(memcmp(&pubkey, &recpubkey,
sizeof(pubkey)) == 0);
199 sig[secp256k1_rand_bits(6)] += 1 + secp256k1_rand_int(255);
205 memcmp(&pubkey, &recpubkey,
sizeof(pubkey)) != 0);
210 const unsigned char msg32[32] = {
211 'T',
'h',
'i',
's',
' ',
'i',
's',
' ',
212 'a',
' ',
'v',
'e',
'r',
'y',
' ',
's',
213 'e',
'c',
'r',
'e',
't',
' ',
'm',
'e',
214 's',
's',
'a',
'g',
'e',
'.',
'.',
'.'
216 const unsigned char sig64[64] = {
219 0x67, 0xCB, 0x28, 0x5F, 0x9C, 0xD1, 0x94, 0xE8,
220 0x40, 0xD6, 0x29, 0x39, 0x7A, 0xF5, 0x56, 0x96,
221 0x62, 0xFD, 0xE4, 0x46, 0x49, 0x99, 0x59, 0x63,
222 0x17, 0x9A, 0x7D, 0xD1, 0x7B, 0xD2, 0x35, 0x32,
223 0x4B, 0x1B, 0x7D, 0xF3, 0x4C, 0xE1, 0xF6, 0x8E,
224 0x69, 0x4F, 0xF6, 0xF1, 0x1A, 0xC7, 0x51, 0xDD,
225 0x7D, 0xD7, 0x3E, 0x38, 0x7E, 0xE4, 0xFC, 0x86,
226 0x6E, 0x1B, 0xE8, 0xEC, 0xC7, 0xDD, 0x95, 0x57
230 const unsigned char sigb64[64] = {
231 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
232 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
233 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
234 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
235 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
236 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
237 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
238 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
254 for (recid = 0; recid < 4; recid++) {
258 unsigned char sigbder[8] = {0x30, 0x06, 0x02, 0x01, 0x04, 0x02, 0x01, 0x04};
259 unsigned char sigcder_zr[7] = {0x30, 0x05, 0x02, 0x00, 0x02, 0x01, 0x01};
260 unsigned char sigcder_zs[7] = {0x30, 0x05, 0x02, 0x01, 0x01, 0x02, 0x00};
261 unsigned char sigbderalt1[39] = {
262 0x30, 0x25, 0x02, 0x20, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x04,
268 unsigned char sigbderalt2[39] = {
269 0x30, 0x25, 0x02, 0x01, 0x04, 0x02, 0x20, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
275 unsigned char sigbderalt3[40] = {
276 0x30, 0x26, 0x02, 0x21, 0x00, 0x00, 0x00, 0x00,
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00, 0x04, 0x02, 0x01, 0x04,
282 unsigned char sigbderalt4[40] = {
283 0x30, 0x26, 0x02, 0x01, 0x04, 0x02, 0x21, 0x00,
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
285 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
286 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
287 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04,
290 unsigned char sigbderlong[40] = {
291 0x30, 0x26, 0x02, 0x21, 0x00, 0xFF, 0xFF, 0xFF,
292 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
293 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xBA, 0xAE, 0xDC,
294 0xE6, 0xAF, 0x48, 0xA0, 0x3B, 0xBF, 0xD2, 0x5E,
295 0x8C, 0xD0, 0x36, 0x41, 0x45, 0x02, 0x01, 0x04
301 for (recid2 = 0; recid2 < 4; recid2++) {
331 for(i = 0; i < 8; i++) {
333 unsigned char orig = sigbder[i];
335 for (c = 0; c < 256; c++) {
349 unsigned char sigcder[8] = {0x30, 0x06, 0x02, 0x01, 0x01, 0x02, 0x01, 0x01};
350 unsigned char sigc64[64] = {
351 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
353 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
355 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
384 for (i = 0; i < count; i++) {
387 for (i = 0; i < 64*count; i++) {