Skip to content

Commit 6f8b55c

Browse files
committed
Add regression test for Issue #603
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent e6be20b commit 6f8b55c

File tree

1 file changed

+161
-0
lines changed

1 file changed

+161
-0
lines changed

tests/dsa_test.c

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,166 @@ static int s_dsa_wycheproof_test(void)
298298
return CRYPT_OK;
299299
}
300300

301+
static int s_dsa_603_regression(void)
302+
{
303+
/* Test case reported to fail in OP-TEE
304+
* https://github.com/libtom/libtomcrypt/issues/603
305+
*/
306+
static const unsigned char ac_dsa_vect106_prime[] = {
307+
/* P */
308+
0xa4, 0xc7, 0xea, 0xab, 0x42, 0xc4, 0xc7, 0x3b, 0x75, 0x77, 0x70, 0x91,
309+
0x64, 0x89, 0xf1, 0x7c, 0xd5, 0x07, 0x25, 0xcd, 0x0a, 0x4b, 0xc4, 0xe1,
310+
0xcf, 0x67, 0xf7, 0x63, 0xb8, 0xc1, 0xde, 0x2d, 0x6d, 0xab, 0x98, 0x56,
311+
0xba, 0xaf, 0xb0, 0x08, 0xf3, 0x65, 0xb1, 0x8a, 0x42, 0xe1, 0x4d, 0xc5,
312+
0x1f, 0x35, 0x0b, 0x88, 0xec, 0xa0, 0x20, 0x9c, 0x5a, 0xa4, 0xfd, 0x71,
313+
0xa7, 0xa9, 0x6c, 0x76, 0x5f, 0x59, 0x01, 0xc2, 0x1e, 0x72, 0x05, 0x70,
314+
0xd7, 0x83, 0x7b, 0xec, 0x7c, 0x76, 0xd2, 0xe4, 0x93, 0x44, 0x73, 0x1c,
315+
0xa3, 0x94, 0x05, 0xd0, 0xa8, 0x79, 0xb9, 0xe0, 0xdc, 0xd1, 0xa8, 0x12,
316+
0x5f, 0xd1, 0x30, 0xec, 0x1e, 0x78, 0x3e, 0x65, 0x4b, 0x94, 0xe3, 0x00,
317+
0x2e, 0x6b, 0x62, 0x9e, 0x90, 0x4a, 0xb3, 0x87, 0x78, 0x67, 0x72, 0x0c,
318+
0xbd, 0x54, 0xb4, 0x27, 0x0a, 0x9e, 0x15, 0xcd, 0x02, 0x8c, 0x7c, 0xc7,
319+
0x96, 0xf0, 0x6c, 0x27, 0x2a, 0x66, 0x09, 0x51, 0x92, 0x8f, 0xdb, 0xeb,
320+
0x2d, 0xca, 0x06, 0x1b, 0x41, 0xe9, 0x32, 0x25, 0x73, 0x05, 0x74, 0x2f,
321+
0xf1, 0x6e, 0x2f, 0x42, 0x91, 0x91, 0xd5, 0xe5, 0xf1, 0xa6, 0xdd, 0xf6,
322+
0xe7, 0x8c, 0x5d, 0x77, 0x22, 0xcf, 0xf8, 0x0a, 0x9c, 0x0b, 0xd5, 0xc8,
323+
0xd7, 0xae, 0xba, 0x8c, 0x04, 0x43, 0x89, 0x92, 0xb0, 0x75, 0xe3, 0x07,
324+
0xc1, 0x53, 0x4c, 0x49, 0xad, 0x38, 0x0f, 0x47, 0x7f, 0x5f, 0x79, 0x87,
325+
0xdc, 0x17, 0x2c, 0x16, 0x1d, 0xca, 0x38, 0xdc, 0xaf, 0x3f, 0xb3, 0x84,
326+
0x6c, 0x72, 0xc9, 0x11, 0x9a, 0x52, 0x99, 0xad, 0xc7, 0x48, 0x95, 0x1b,
327+
0x3d, 0xce, 0x0d, 0x00, 0xd4, 0xa9, 0x01, 0x38, 0x00, 0xb2, 0x00, 0x82,
328+
0x03, 0xb7, 0x24, 0x65, 0xbc, 0x6a, 0x84, 0xae, 0x05, 0x9a, 0x30, 0xc4,
329+
0x52, 0x2d, 0xea, 0x57
330+
};
331+
static const unsigned char ac_dsa_vect106_sub_prime[] = {
332+
/* Q */
333+
0xce, 0x89, 0xfe, 0x33, 0x2b, 0x8e, 0x4e, 0xb3, 0xd1, 0xe8, 0xdd, 0xce,
334+
0xa5, 0xd1, 0x63, 0xa5, 0xbc, 0x13, 0xb6, 0x3f, 0x16, 0x99, 0x37, 0x55,
335+
0x42, 0x7a, 0xef, 0x43
336+
};
337+
static const unsigned char ac_dsa_vect106_base[] = {
338+
/* G */
339+
0x8c, 0x46, 0x5e, 0xdf, 0x5a, 0x18, 0x07, 0x30, 0x29, 0x1e, 0x08, 0x0d,
340+
0xfc, 0x53, 0x85, 0x39, 0x7a, 0x50, 0x06, 0x45, 0x0d, 0xba, 0x2e, 0xfe,
341+
0x01, 0x29, 0x26, 0x4f, 0xbd, 0x89, 0x7b, 0xb5, 0x57, 0x9c, 0xa0, 0xea,
342+
0xb1, 0x9a, 0xa2, 0x78, 0x22, 0x04, 0x24, 0x72, 0x4b, 0x4f, 0x2a, 0x6f,
343+
0x6e, 0xe6, 0x32, 0x84, 0x32, 0xab, 0xf6, 0x61, 0x38, 0x06, 0x46, 0x09,
344+
0x72, 0x33, 0x50, 0x53, 0x39, 0xc5, 0x51, 0x9d, 0x35, 0x7d, 0x71, 0x12,
345+
0xb6, 0xee, 0xc9, 0x38, 0xb8, 0x5d, 0x5a, 0xa7, 0x5c, 0xc2, 0xe3, 0x80,
346+
0x92, 0xf0, 0xa5, 0x30, 0xac, 0xb5, 0x4e, 0x50, 0xfe, 0x82, 0xc4, 0xd5,
347+
0x62, 0xfb, 0x0f, 0x30, 0x36, 0xb8, 0x0b, 0x30, 0x33, 0x40, 0x23, 0xeb,
348+
0xbe, 0x66, 0x37, 0xa0, 0x01, 0x0b, 0x00, 0xc7, 0xdb, 0x86, 0x37, 0x11,
349+
0x68, 0x56, 0x36, 0x71, 0xe1, 0xe0, 0xf0, 0x28, 0xae, 0xdb, 0xd4, 0x5d,
350+
0x2d, 0x57, 0x26, 0x21, 0xa6, 0x09, 0x98, 0x2a, 0x07, 0x3e, 0x51, 0xaa,
351+
0xe2, 0x77, 0x07, 0xaf, 0xbe, 0xef, 0x29, 0xe2, 0xec, 0xee, 0x84, 0xd7,
352+
0xa6, 0xd5, 0xda, 0x38, 0x2b, 0xe3, 0xa3, 0x5f, 0x42, 0xb6, 0xc6, 0x68,
353+
0x49, 0x20, 0x2a, 0xb1, 0x9d, 0x02, 0x5b, 0x86, 0x9d, 0x08, 0x77, 0x64,
354+
0x76, 0xd1, 0xab, 0x98, 0x14, 0x75, 0xad, 0x2a, 0xd2, 0xf3, 0xe6, 0xfd,
355+
0x07, 0xe3, 0x06, 0x96, 0xd9, 0x0a, 0x62, 0x68, 0x16, 0xdf, 0x60, 0xd6,
356+
0xca, 0x7a, 0xfd, 0x7b, 0x48, 0x2f, 0x94, 0x2f, 0x83, 0xb4, 0x5c, 0xc8,
357+
0x29, 0x33, 0x73, 0x1f, 0x87, 0xfa, 0xee, 0x32, 0x09, 0x00, 0xf2, 0xaa,
358+
0x3e, 0x70, 0xb1, 0x86, 0x7e, 0x14, 0x30, 0xe4, 0x0b, 0xe6, 0x7c, 0x07,
359+
0xf9, 0x29, 0x02, 0x99, 0xef, 0x06, 0x7b, 0x8b, 0x24, 0xa7, 0x51, 0x5b,
360+
0x3f, 0x99, 0x2c, 0x07
361+
};
362+
static const unsigned char ac_dsa_vect106_ptx[] = {
363+
/* Msg */
364+
0xce, 0xc8, 0xd2, 0x84, 0x3d, 0xee, 0x7c, 0xb5, 0xf9, 0x11, 0x9b, 0x75,
365+
0x56, 0x25, 0x85, 0xe0, 0x5c, 0x5c, 0xe2, 0xf4, 0xe6, 0x45, 0x7e, 0x9b,
366+
0xcc, 0x3c, 0x1c, 0x78, 0x1c, 0xcd, 0x2c, 0x04, 0x42, 0xb6, 0x28, 0x2a,
367+
0xea, 0x61, 0x0f, 0x71, 0x61, 0xdc, 0xed, 0xe1, 0x76, 0xe7, 0x74, 0x86,
368+
0x1f, 0x7d, 0x26, 0x91, 0xbe, 0x6c, 0x89, 0x4a, 0xc3, 0xeb, 0xf8, 0x0c,
369+
0x0f, 0xab, 0x21, 0xe5, 0x2a, 0x3e, 0x63, 0xae, 0x0b, 0x35, 0x02, 0x57,
370+
0x62, 0xcc, 0xd6, 0xc9, 0xe1, 0xfe, 0xcc, 0x7f, 0x9f, 0xe0, 0x0a, 0xa5,
371+
0x5c, 0x0c, 0x3a, 0xe3, 0x3a, 0xe8, 0x8f, 0x66, 0x18, 0x7f, 0x95, 0x98,
372+
0xeb, 0xa9, 0xf8, 0x63, 0x17, 0x1f, 0x3f, 0x56, 0x48, 0x46, 0x25, 0xbf,
373+
0x39, 0xd8, 0x83, 0x42, 0x73, 0x49, 0xb8, 0x67, 0x1d, 0x9b, 0xb7, 0xd3,
374+
0x96, 0x18, 0x06, 0x94, 0xe5, 0xb5, 0x46, 0xae
375+
};
376+
static const unsigned char ac_dsa_vect106_priv_val[] = {
377+
/* X */
378+
0x55, 0x15, 0x95, 0xec, 0xcb, 0xb0, 0x03, 0xb0, 0xbf, 0x8d, 0xdd, 0xa1,
379+
0x84, 0xa5, 0x9d, 0xa5, 0x1e, 0x45, 0x9a, 0x0d, 0x28, 0x20, 0x5e, 0x55,
380+
0x92, 0xca, 0x4c, 0xb1
381+
};
382+
static const unsigned char ac_dsa_vect106_pub_val[] = {
383+
/* Y */
384+
0x74, 0x8a, 0x40, 0x23, 0x72, 0x11, 0xa2, 0xd9, 0x85, 0x25, 0x96, 0xe7,
385+
0xa8, 0x91, 0xf4, 0x3d, 0x4e, 0xb0, 0xee, 0x48, 0x82, 0x6c, 0x9c, 0xfb,
386+
0x33, 0x6b, 0xbb, 0x68, 0xdb, 0xe5, 0xa5, 0xe1, 0x6b, 0x2e, 0x12, 0x71,
387+
0xd4, 0xd1, 0x3d, 0xe0, 0x36, 0x44, 0xbb, 0x85, 0xef, 0x6b, 0xe5, 0x23,
388+
0xa4, 0xd4, 0xd8, 0x84, 0x15, 0xbc, 0xd5, 0x96, 0xba, 0x8e, 0x0a, 0x3c,
389+
0x4f, 0x64, 0x39, 0xe9, 0x81, 0xed, 0x01, 0x3d, 0x7d, 0x9c, 0x70, 0x33,
390+
0x6f, 0xeb, 0xf7, 0xd4, 0x20, 0xcf, 0xed, 0x02, 0xc2, 0x67, 0x45, 0x7b,
391+
0xb3, 0xf3, 0xe7, 0xc8, 0x21, 0x45, 0xd2, 0xaf, 0x54, 0x83, 0x0b, 0x94,
392+
0x2e, 0xc7, 0x4a, 0x5d, 0x50, 0x3e, 0x42, 0x26, 0xcd, 0x25, 0xdd, 0x75,
393+
0xde, 0xcd, 0x3f, 0x50, 0xf0, 0xa8, 0x58, 0x15, 0x5d, 0x7b, 0xe7, 0x99,
394+
0x41, 0x08, 0x36, 0xdd, 0xc5, 0x59, 0xce, 0x99, 0xe1, 0xae, 0x51, 0x38,
395+
0x08, 0xfd, 0xae, 0xac, 0x34, 0x84, 0x3d, 0xd7, 0x25, 0x8f, 0x16, 0xf6,
396+
0x7f, 0x19, 0x20, 0x5f, 0x6f, 0x13, 0x92, 0x51, 0xa4, 0x18, 0x6d, 0xa8,
397+
0x49, 0x6d, 0x5e, 0x90, 0xd3, 0xfe, 0xcf, 0x8e, 0xd1, 0x0b, 0xe6, 0xc2,
398+
0x5f, 0xf5, 0xeb, 0x33, 0xd9, 0x60, 0xc9, 0xa8, 0xf4, 0xc5, 0x81, 0xc8,
399+
0xc7, 0x24, 0xca, 0x43, 0xb7, 0x61, 0xe9, 0xfd, 0xb5, 0xaf, 0x66, 0xbf,
400+
0xfb, 0x9d, 0x2e, 0xbb, 0x11, 0xa6, 0xb5, 0x04, 0xa1, 0xfb, 0xe4, 0xf8,
401+
0x34, 0xec, 0xb6, 0xac, 0x25, 0x4c, 0xab, 0x51, 0x3e, 0x94, 0x3b, 0x9a,
402+
0x95, 0x3a, 0x70, 0x84, 0xb3, 0x30, 0x5c, 0x66, 0x1b, 0xfa, 0xd4, 0x34,
403+
0xf6, 0xa8, 0x35, 0x50, 0x3c, 0x9a, 0xde, 0x7f, 0x4a, 0x57, 0xf5, 0xc9,
404+
0x65, 0xec, 0x30, 0x1e, 0xcd, 0xe9, 0x38, 0xee, 0x31, 0xb4, 0xde, 0xb0,
405+
0x38, 0xaf, 0x97, 0xb3
406+
};
407+
/* K = 6f326546aa174b3d319ef7331ec8dfd363dd78ae583a920165ff7e54 */
408+
static const unsigned char ac_dsa_vect106_out[] = {
409+
/* R */
410+
0x9c, 0x5f, 0xa4, 0x68, 0x79, 0xdd, 0xaf, 0x5c, 0x14, 0xf0, 0x7d, 0xfb,
411+
0x53, 0x20, 0x71, 0x5f, 0x67, 0xa6, 0xfe, 0xc1, 0x79, 0xe3, 0xad, 0x53,
412+
0x34, 0x2f, 0xb6, 0xd1,
413+
/* S */
414+
0xc3, 0xe1, 0x7e, 0x7b, 0x3c, 0x4d, 0x0a, 0xc8, 0xd4, 0x9f, 0x4d, 0xd0,
415+
0xf0, 0x4c, 0x16, 0xa0, 0x94, 0xf4, 0x2d, 0xa0, 0xaf, 0xcc, 0x6c, 0x90,
416+
0xf5, 0xf1, 0xbb, 0xc8
417+
};
418+
419+
dsa_key key[1];
420+
const char K[] = "6f326546aa174b3d319ef7331ec8dfd363dd78ae583a920165ff7e54";
421+
unsigned char Kbin[sizeof(K)];
422+
unsigned char hash[MAXBLOCKSIZE];
423+
unsigned char sig[MAXBLOCKSIZE];
424+
unsigned char pub[sizeof(ac_dsa_vect106_pub_val)];
425+
unsigned long outlen[1];
426+
unsigned long siglen[1];
427+
int stat[1];
428+
struct ltc_prng_descriptor* no_prng_desc = no_prng_desc_get();
429+
int prng_idx = register_prng(no_prng_desc);
430+
431+
*outlen = sizeof(Kbin);
432+
DO(base16_decode(K, sizeof(K) - 1, Kbin, outlen));
433+
prng_descriptor[prng_idx].add_entropy(Kbin, *outlen, (void*)no_prng_desc);
434+
435+
DO(dsa_set_pqg(ac_dsa_vect106_prime, sizeof(ac_dsa_vect106_prime), ac_dsa_vect106_sub_prime,
436+
sizeof(ac_dsa_vect106_sub_prime), ac_dsa_vect106_base, sizeof(ac_dsa_vect106_base), key));
437+
DO(dsa_set_key(ac_dsa_vect106_priv_val, sizeof(ac_dsa_vect106_priv_val), PK_PRIVATE, key));
438+
*outlen = sizeof(hash);
439+
DO(hash_memory(find_hash("sha256"), ac_dsa_vect106_ptx, sizeof(ac_dsa_vect106_ptx), hash, outlen));
440+
*siglen = sizeof(sig);
441+
DO(dsa_sign_hash(hash, *outlen, sig, siglen, (void*)no_prng_desc, prng_idx, key));
442+
DO(dsa_verify_hash(sig, *siglen, hash, *outlen, stat, key));
443+
ENSURE(*stat == 1);
444+
445+
mp_to_unsigned_bin(key->y, pub);
446+
447+
COMPARE_TESTVECTOR(pub, sizeof(pub),
448+
ac_dsa_vect106_pub_val, sizeof(ac_dsa_vect106_pub_val), "Y", 0);
449+
COMPARE_TESTVECTOR(&sig[5], sizeof(ac_dsa_vect106_out)/2,
450+
ac_dsa_vect106_out, sizeof(ac_dsa_vect106_out)/2, "R", 0);
451+
COMPARE_TESTVECTOR(&sig[36], sizeof(ac_dsa_vect106_out)/2,
452+
&ac_dsa_vect106_out[sizeof(ac_dsa_vect106_out)/2], sizeof(ac_dsa_vect106_out)/2, "S", 0);
453+
454+
dsa_free(key);
455+
unregister_prng(no_prng_desc);
456+
no_prng_desc_free(no_prng_desc);
457+
458+
return 0;
459+
}
460+
301461
int dsa_test(void)
302462
{
303463
unsigned char msg[16], out[1024], out2[1024], ch;
@@ -307,6 +467,7 @@ int dsa_test(void)
307467

308468
if (ltc_mp.name == NULL) return CRYPT_NOP;
309469

470+
DO(s_dsa_603_regression());
310471
DO(s_dsa_compat_test());
311472
DO(s_dsa_wycheproof_test());
312473

0 commit comments

Comments
 (0)