Mercurial > dropbear
comparison libtomcrypt/tests/pkcs_1_eme_test.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
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/pkcs1v15crypt-vectors.c" | |
14 | |
15 | |
16 | |
17 int pkcs_1_eme_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_eme)/sizeof(testcases_eme[0]); ++i) { | |
29 testcase_t* t = &testcases_eme[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[256], 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(rsa_encrypt_key_ex(s->o1, s->o1_l, obuf, &obuflen, NULL, 0, (prng_state*)no_prng_desc, prng_idx, -1, LTC_PKCS_1_V1_5, key), s->name); | |
51 DOX(obuflen == (unsigned long)s->o3_l?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name); | |
52 DOX(memcmp(s->o3, obuf, s->o3_l)==0?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name); | |
53 DOX(rsa_decrypt_key_ex(obuf, obuflen, buf, &buflen, NULL, 0, -1, LTC_PKCS_1_V1_5, &stat, key), s->name); | |
54 DOX(stat == 1?CRYPT_OK:CRYPT_FAIL_TESTVECTOR, s->name); | |
55 } /* for */ | |
56 | |
57 mp_clear_multi(key->d, key->e, key->N, key->dQ, key->dP, key->qP, key->p, key->q, NULL); | |
58 } /* for */ | |
59 | |
60 unregister_prng(no_prng_desc); | |
61 no_prng_desc_free(no_prng_desc); | |
62 | |
63 return 0; | |
64 } | |
65 | |
66 #else | |
67 | |
68 int pkcs_1_eme_test(void) | |
69 { | |
70 return CRYPT_NOP; | |
71 } | |
72 | |
73 #endif | |
74 | |
75 | |
76 /* ref: $Format:%D$ */ | |
77 /* git commit: $Format:%H$ */ | |
78 /* commit time: $Format:%ai$ */ |