comparison libtomcrypt/testprof/pkcs_1_test.c @ 435:337c45621e81

merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee' and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
author Matt Johnston <matt@ucc.asn.au>
date Thu, 22 Feb 2007 14:53:49 +0000
parents 0cbe8f6dbf9e
children f849a5ca2efc
comparison
equal deleted inserted replaced
434:0aaaf68e97dc 435:337c45621e81
3 #ifdef PKCS_1 3 #ifdef PKCS_1
4 4
5 int pkcs_1_test(void) 5 int pkcs_1_test(void)
6 { 6 {
7 unsigned char buf[3][128]; 7 unsigned char buf[3][128];
8 int res1, res2, res3, prng_idx, hash_idx; 8 int res1, res2, res3, prng_idx, hash_idx, err;
9 unsigned long x, y, l1, l2, l3, i1, i2, lparamlen, saltlen, modlen; 9 unsigned long x, y, l1, l2, l3, i1, i2, lparamlen, saltlen, modlen;
10 static const unsigned char lparam[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 }; 10 static const unsigned char lparam[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 };
11 11
12 /* get hash/prng */ 12 /* get hash/prng */
13 hash_idx = find_hash("sha1"); 13 hash_idx = find_hash("sha1");
16 if (hash_idx == -1 || prng_idx == -1) { 16 if (hash_idx == -1 || prng_idx == -1) {
17 fprintf(stderr, "pkcs_1 tests require sha1/yarrow"); 17 fprintf(stderr, "pkcs_1 tests require sha1/yarrow");
18 return 1; 18 return 1;
19 } 19 }
20 20
21 srand(time(NULL));
21 /* do many tests */ 22 /* do many tests */
22 for (x = 0; x < 100; x++) { 23 for (x = 0; x < 100; x++) {
23 zeromem(buf, sizeof(buf)); 24 zeromem(buf, sizeof(buf));
24 25
25 /* make a dummy message (of random length) */ 26 /* make a dummy message (of random length) */
26 l3 = (rand() & 31) + 8; 27 l3 = (rand() & 31) + 8;
27 for (y = 0; y < l3; y++) buf[0][y] = rand() & 255; 28 for (y = 0; y < l3; y++) buf[0][y] = rand() & 255;
28
29 /* random modulus len (v1.5 must be multiple of 8 though arbitrary sizes seem to work) */
30 modlen = 800 + 8 * (abs(rand()) % 28);
31 29
32 /* pick a random lparam len [0..16] */ 30 /* pick a random lparam len [0..16] */
33 lparamlen = abs(rand()) % 17; 31 lparamlen = abs(rand()) % 17;
34 32
35 /* pick a random saltlen 0..16 */ 33 /* pick a random saltlen 0..16 */
67 65
68 buf[0][i1 = abs(rand()) % l3] ^= 1; 66 buf[0][i1 = abs(rand()) % l3] ^= 1;
69 DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res2)); 67 DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res2));
70 68
71 buf[0][i1] ^= 1; 69 buf[0][i1] ^= 1;
72 buf[1][i2 = abs(rand()) % l1] ^= 1; 70 buf[1][i2 = abs(rand()) % (l1 - 1)] ^= 1;
73 DO(pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3)); 71 pkcs_1_pss_decode(buf[0], l3, buf[1], l1, saltlen, hash_idx, modlen, &res3);
74
75 if (!(res1 == 1 && res2 == 0 && res3 == 0)) { 72 if (!(res1 == 1 && res2 == 0 && res3 == 0)) {
76 fprintf(stderr, "PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen); 73 fprintf(stderr, "PSS failed: %d, %d, %d, %lu, %lu\n", res1, res2, res3, l3, saltlen);
77 return 1; 74 return 1;
78 } 75 }
79 } 76 }
90 87
91 #endif 88 #endif
92 89
93 90
94 /* $Source: /cvs/libtom/libtomcrypt/testprof/pkcs_1_test.c,v $ */ 91 /* $Source: /cvs/libtom/libtomcrypt/testprof/pkcs_1_test.c,v $ */
95 /* $Revision: 1.6 $ */ 92 /* $Revision: 1.7 $ */
96 /* $Date: 2005/05/21 12:51:25 $ */ 93 /* $Date: 2006/11/30 03:30:45 $ */