comparison libtomcrypt/tests/pkcs_1_pss_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/pss-vect.c"
14
15
16
17 int pkcs_1_pss_test(void)
18 {
19 struct ltc_prng_descriptor* no_prng_desc = no_prng_desc_get();
20 int prng_idx = register_prng(no_prng_desc);
21 int hash_idx = find_hash("sha1");
22 unsigned int i;
23 unsigned int j;
24
25 DO(prng_is_valid(prng_idx));
26 DO(hash_is_valid(hash_idx));
27
28 for (i = 0; i < sizeof(testcases_pss)/sizeof(testcases_pss[0]); ++i) {
29 testcase_t* t = &testcases_pss[i];
30 rsa_key k, *key = &k;
31 DOX(mp_init_multi(&key->e, &key->d, &key->N, &key->dQ,
32 &key->dP, &key->qP, &key->p, &key->q, NULL), t->name);
33
34 DOX(mp_read_unsigned_bin(key->e, t->rsa.e, t->rsa.e_l), t->name);
35 DOX(mp_read_unsigned_bin(key->d, t->rsa.d, t->rsa.d_l), t->name);
36 DOX(mp_read_unsigned_bin(key->N, t->rsa.n, t->rsa.n_l), t->name);
37 DOX(mp_read_unsigned_bin(key->dQ, t->rsa.dQ, t->rsa.dQ_l), t->name);
38 DOX(mp_read_unsigned_bin(key->dP, t->rsa.dP, t->rsa.dP_l), t->name);
39 DOX(mp_read_unsigned_bin(key->qP, t->rsa.qInv, t->rsa.qInv_l), t->name);
40 DOX(mp_read_unsigned_bin(key->q, t->rsa.q, t->rsa.q_l), t->name);
41 DOX(mp_read_unsigned_bin(key->p, t->rsa.p, t->rsa.p_l), t->name);
42 key->type = PK_PRIVATE;
43
44 for (j = 0; j < sizeof(t->data)/sizeof(t->data[0]); ++j) {
45 rsaData_t* s = &t->data[j];
46 unsigned char buf[20], obuf[256];
47 unsigned long buflen = sizeof(buf), obuflen = sizeof(obuf);
48 int stat;
49 prng_descriptor[prng_idx].add_entropy(s->o2, s->o2_l, (prng_state*)no_prng_desc);
50 DOX(hash_memory(hash_idx, s->o1, s->o1_l, buf, &buflen), s->name);
51 DOX(rsa_sign_hash(buf, buflen, obuf, &obuflen, (prng_state*)no_prng_desc, prng_idx, hash_idx, s->o2_l, key), s->name);
52 DOX(obuflen == (unsigned long)s->o3_l?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
53 DOX(memcmp(s->o3, obuf, s->o3_l)==0?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
54 DOX(rsa_verify_hash(obuf, obuflen, buf, buflen, hash_idx, s->o2_l, &stat, key), s->name);
55 DOX(stat == 1?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name);
56 } /* for */
57
58 mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL);
59 } /* for */
60
61 unregister_prng(no_prng_desc);
62 no_prng_desc_free(no_prng_desc);
63
64 return 0;
65 }
66
67 #else
68
69 int pkcs_1_pss_test(void)
70 {
71 return CRYPT_NOP;
72 }
73
74 #endif
75
76
77 /* ref: $Format:%D$ */
78 /* git commit: $Format:%H$ */
79 /* commit time: $Format:%ai$ */