Mercurial > dropbear
comparison libtomcrypt/tests/pkcs_1_emsa_test.c @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 */ | |
9 #include <tomcrypt_test.h> | |
10 | |
11 #if defined(LTC_PKCS_1) && defined(LTC_TEST_MPI) | |
12 | |
13 #include "../notes/rsa-testvectors/pkcs1v15sign-vectors.c" | |
14 | |
15 | |
16 | |
17 int pkcs_1_emsa_test(void) | |
18 { | |
19 int hash_idx = find_hash("sha1"); | |
20 unsigned int i; | |
21 unsigned int j; | |
22 | |
23 DO(hash_is_valid(hash_idx)); | |
24 | |
25 for (i = 0; i < sizeof(testcases_emsa)/sizeof(testcases_emsa[0]); ++i) { | |
26 testcase_t* t = &testcases_emsa[i]; | |
27 rsa_key k, *key = &k; | |
28 DOX(mp_init_multi(&key->e, &key->d, &key->N, &key->dQ, | |
29 &key->dP, &key->qP, &key->p, &key->q, NULL), t->name); | |
30 | |
31 DOX(mp_read_unsigned_bin(key->e, t->rsa.e, t->rsa.e_l), t->name); | |
32 DOX(mp_read_unsigned_bin(key->d, t->rsa.d, t->rsa.d_l), t->name); | |
33 DOX(mp_read_unsigned_bin(key->N, t->rsa.n, t->rsa.n_l), t->name); | |
34 DOX(mp_read_unsigned_bin(key->dQ, t->rsa.dQ, t->rsa.dQ_l), t->name); | |
35 DOX(mp_read_unsigned_bin(key->dP, t->rsa.dP, t->rsa.dP_l), t->name); | |
36 DOX(mp_read_unsigned_bin(key->qP, t->rsa.qInv, t->rsa.qInv_l), t->name); | |
37 DOX(mp_read_unsigned_bin(key->q, t->rsa.q, t->rsa.q_l), t->name); | |
38 DOX(mp_read_unsigned_bin(key->p, t->rsa.p, t->rsa.p_l), t->name); | |
39 key->type = PK_PRIVATE; | |
40 | |
41 for (j = 0; j < sizeof(t->data)/sizeof(t->data[0]); ++j) { | |
42 rsaData_t* s = &t->data[j]; | |
43 unsigned char buf[20], obuf[256]; | |
44 unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf); | |
45 int stat; | |
46 DOX(hash_memory(hash_idx, s->o1, s->o1_l, buf, &buflen), s->name); | |
47 DOX(rsa_sign_hash_ex(buf, buflen, obuf, &obuflen, LTC_PKCS_1_V1_5, NULL, -1, hash_idx, 0, key), s->name); | |
48 DOX(obuflen == (unsigned long)s->o2_l?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name); | |
49 DOX(memcmp(s->o2, obuf, s->o2_l)==0?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name); | |
50 DOX(rsa_verify_hash_ex(obuf, obuflen, buf, buflen, LTC_PKCS_1_V1_5, hash_idx, 0, &stat, key), s->name); | |
51 DOX(stat == 1?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name); | |
52 } /* for */ | |
53 | |
54 mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL); | |
55 } /* for */ | |
56 | |
57 return 0; | |
58 } | |
59 | |
60 #else | |
61 | |
62 int pkcs_1_emsa_test(void) | |
63 { | |
64 return CRYPT_NOP; | |
65 } | |
66 | |
67 #endif | |
68 | |
69 | |
70 /* ref: $Format:%D$ */ | |
71 /* git commit: $Format:%H$ */ | |
72 /* commit time: $Format:%ai$ */ |