comparison testprof/rsa_test.c @ 209:39d5d58461d6 libtomcrypt-orig LTC_1.05

Import of libtomcrypt 1.05
author Matt Johnston <matt@ucc.asn.au>
date Wed, 06 Jul 2005 03:53:40 +0000
parents 1c15b283127b
children
comparison
equal deleted inserted replaced
191:1c15b283127b 209:39d5d58461d6
1 #include <tomcrypt_test.h> 1 #include <tomcrypt_test.h>
2 2
3 #ifdef MRSA 3 #ifdef MRSA
4 4
5 #define RSA_MSGSIZE 78 5 #define RSA_MSGSIZE 78
6
7 /* These are test keys [see file test.key] that I use to test my import/export against */
8 static const unsigned char openssl_private_rsa[] = {
9 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, 0x00, 0x02, 0x81, 0x81, 0x00, 0xcf, 0x9a, 0xde, 0x64, 0x8a,
10 0xda, 0xc8, 0x33, 0x20, 0xa9, 0xd7, 0x83, 0x31, 0x19, 0x54, 0xb2, 0x9a, 0x85, 0xa7, 0xa1, 0xb7,
11 0x75, 0x33, 0xb6, 0xa9, 0xac, 0x84, 0x24, 0xb3, 0xde, 0xdb, 0x7d, 0x85, 0x2d, 0x96, 0x65, 0xe5,
12 0x3f, 0x72, 0x95, 0x24, 0x9f, 0x28, 0x68, 0xca, 0x4f, 0xdb, 0x44, 0x1c, 0x3e, 0x60, 0x12, 0x8a,
13 0xdd, 0x26, 0xa5, 0xeb, 0xff, 0x0b, 0x5e, 0xd4, 0x88, 0x38, 0x49, 0x2a, 0x6e, 0x5b, 0xbf, 0x12,
14 0x37, 0x47, 0xbd, 0x05, 0x6b, 0xbc, 0xdb, 0xf3, 0xee, 0xe4, 0x11, 0x8e, 0x41, 0x68, 0x7c, 0x61,
15 0x13, 0xd7, 0x42, 0xc8, 0x80, 0xbe, 0x36, 0x8f, 0xdc, 0x08, 0x8b, 0x4f, 0xac, 0xa4, 0xe2, 0x76,
16 0x0c, 0xc9, 0x63, 0x6c, 0x49, 0x58, 0x93, 0xed, 0xcc, 0xaa, 0xdc, 0x25, 0x3b, 0x0a, 0x60, 0x3f,
17 0x8b, 0x54, 0x3a, 0xc3, 0x4d, 0x31, 0xe7, 0x94, 0xa4, 0x44, 0xfd, 0x02, 0x03, 0x01, 0x00, 0x01,
18 0x02, 0x81, 0x81, 0x00, 0xc8, 0x62, 0xb9, 0xea, 0xde, 0x44, 0x53, 0x1d, 0x56, 0x97, 0xd9, 0x97,
19 0x9e, 0x1a, 0xcf, 0x30, 0x1e, 0x0a, 0x88, 0x45, 0x86, 0x29, 0x30, 0xa3, 0x4d, 0x9f, 0x61, 0x65,
20 0x73, 0xe0, 0xd6, 0x87, 0x8f, 0xb6, 0xf3, 0x06, 0xa3, 0x82, 0xdc, 0x7c, 0xac, 0xfe, 0x9b, 0x28,
21 0x9a, 0xae, 0xfd, 0xfb, 0xfe, 0x2f, 0x0e, 0xd8, 0x97, 0x04, 0xe3, 0xbb, 0x1f, 0xd1, 0xec, 0x0d,
22 0xba, 0xa3, 0x49, 0x7f, 0x47, 0xac, 0x8a, 0x44, 0x04, 0x7e, 0x86, 0xb7, 0x39, 0x42, 0x3f, 0xad,
23 0x1e, 0xb7, 0x0e, 0xa5, 0x51, 0xf4, 0x40, 0x63, 0x1e, 0xfd, 0xbd, 0xea, 0x9f, 0x41, 0x9f, 0xa8,
24 0x90, 0x1d, 0x6f, 0x0a, 0x5a, 0x95, 0x13, 0x11, 0x0d, 0x80, 0xaf, 0x5f, 0x64, 0x98, 0x8a, 0x2c,
25 0x78, 0x68, 0x65, 0xb0, 0x2b, 0x8b, 0xa2, 0x53, 0x87, 0xca, 0xf1, 0x64, 0x04, 0xab, 0xf2, 0x7b,
26 0xdb, 0x83, 0xc8, 0x81, 0x02, 0x41, 0x00, 0xf7, 0xbe, 0x5e, 0x23, 0xc3, 0x32, 0x3f, 0xbf, 0x8b,
27 0x8e, 0x3a, 0xee, 0xfc, 0xfc, 0xcb, 0xe5, 0xf7, 0xf1, 0x0b, 0xbc, 0x42, 0x82, 0xae, 0xd5, 0x7a,
28 0x3e, 0xca, 0xf7, 0xd5, 0x69, 0x3f, 0x64, 0x25, 0xa2, 0x1f, 0xb7, 0x75, 0x75, 0x05, 0x92, 0x42,
29 0xeb, 0xb8, 0xf1, 0xf3, 0x0a, 0x05, 0xe3, 0x94, 0xd1, 0x55, 0x78, 0x35, 0xa0, 0x36, 0xa0, 0x9b,
30 0x7c, 0x92, 0x84, 0x6c, 0xdd, 0xdc, 0x4d, 0x02, 0x41, 0x00, 0xd6, 0x86, 0x0e, 0x85, 0x42, 0x0b,
31 0x04, 0x08, 0x84, 0x21, 0x60, 0xf0, 0x0e, 0x0d, 0x88, 0xfd, 0x1e, 0x36, 0x10, 0x65, 0x4f, 0x1e,
32 0x53, 0xb4, 0x08, 0x72, 0x80, 0x5c, 0x3f, 0x59, 0x66, 0x17, 0xe6, 0x98, 0xf2, 0xe9, 0x6c, 0x7a,
33 0x06, 0x4c, 0xac, 0x76, 0x3d, 0xed, 0x8c, 0xa1, 0xce, 0xad, 0x1b, 0xbd, 0xb4, 0x7d, 0x28, 0xbc,
34 0xe3, 0x0e, 0x38, 0x8d, 0x99, 0xd8, 0x05, 0xb5, 0xa3, 0x71, 0x02, 0x40, 0x6d, 0xeb, 0xc3, 0x2d,
35 0x2e, 0xf0, 0x5e, 0xa4, 0x88, 0x31, 0x05, 0x29, 0x00, 0x8a, 0xd1, 0x95, 0x29, 0x9b, 0x83, 0xcf,
36 0x75, 0xdb, 0x31, 0xe3, 0x7a, 0x27, 0xde, 0x3a, 0x74, 0x30, 0x0c, 0x76, 0x4c, 0xd4, 0x50, 0x2a,
37 0x40, 0x2d, 0x39, 0xd9, 0x99, 0x63, 0xa9, 0x5d, 0x80, 0xae, 0x53, 0xca, 0x94, 0x3f, 0x05, 0x23,
38 0x1e, 0xf8, 0x05, 0x04, 0xe1, 0xb8, 0x35, 0xf2, 0x17, 0xb3, 0xa0, 0x89, 0x02, 0x41, 0x00, 0xab,
39 0x90, 0x88, 0xfa, 0x60, 0x08, 0x29, 0x50, 0x9a, 0x43, 0x8b, 0xa0, 0x50, 0xcc, 0xd8, 0x5a, 0xfe,
40 0x97, 0x64, 0x63, 0x71, 0x74, 0x22, 0xa3, 0x20, 0x02, 0x5a, 0xcf, 0xeb, 0xc6, 0x16, 0x95, 0x54,
41 0xd1, 0xcb, 0xab, 0x8d, 0x1a, 0xc6, 0x00, 0xfa, 0x08, 0x92, 0x9c, 0x71, 0xd5, 0x52, 0x52, 0x35,
42 0x96, 0x71, 0x4b, 0x8b, 0x92, 0x0c, 0xd0, 0xe9, 0xbf, 0xad, 0x63, 0x0b, 0xa5, 0xe9, 0xb1, 0x02,
43 0x41, 0x00, 0xdc, 0xcc, 0x27, 0xc8, 0xe4, 0xdc, 0x62, 0x48, 0xd5, 0x9b, 0xaf, 0xf5, 0xab, 0x60,
44 0xf6, 0x21, 0xfd, 0x53, 0xe2, 0xb7, 0x5d, 0x09, 0xc9, 0x1a, 0xa1, 0x04, 0xa9, 0xfc, 0x61, 0x2c,
45 0x5d, 0x04, 0x58, 0x3a, 0x5a, 0x39, 0xf1, 0x4a, 0x21, 0x56, 0x67, 0xfd, 0xcc, 0x20, 0xa3, 0x8f,
46 0x78, 0x18, 0x5a, 0x79, 0x3d, 0x2e, 0x8e, 0x7e, 0x86, 0x0a, 0xe6, 0xa8, 0x33, 0xc1, 0x04, 0x17,
47 0x4a, 0x9f, };
48
49
50 /*** NOTE: OpenSSL seems to have more to their public key format. I've stripped the extra headers... */
51 static const unsigned char openssl_public_rsa[] = {
52 0x30, 0x81, 0x89, 0x02, 0x81, 0x81, 0x00, 0xcf, 0x9a, 0xde,
53 0x64, 0x8a, 0xda, 0xc8, 0x33, 0x20, 0xa9, 0xd7, 0x83, 0x31, 0x19, 0x54, 0xb2, 0x9a, 0x85, 0xa7,
54 0xa1, 0xb7, 0x75, 0x33, 0xb6, 0xa9, 0xac, 0x84, 0x24, 0xb3, 0xde, 0xdb, 0x7d, 0x85, 0x2d, 0x96,
55 0x65, 0xe5, 0x3f, 0x72, 0x95, 0x24, 0x9f, 0x28, 0x68, 0xca, 0x4f, 0xdb, 0x44, 0x1c, 0x3e, 0x60,
56 0x12, 0x8a, 0xdd, 0x26, 0xa5, 0xeb, 0xff, 0x0b, 0x5e, 0xd4, 0x88, 0x38, 0x49, 0x2a, 0x6e, 0x5b,
57 0xbf, 0x12, 0x37, 0x47, 0xbd, 0x05, 0x6b, 0xbc, 0xdb, 0xf3, 0xee, 0xe4, 0x11, 0x8e, 0x41, 0x68,
58 0x7c, 0x61, 0x13, 0xd7, 0x42, 0xc8, 0x80, 0xbe, 0x36, 0x8f, 0xdc, 0x08, 0x8b, 0x4f, 0xac, 0xa4,
59 0xe2, 0x76, 0x0c, 0xc9, 0x63, 0x6c, 0x49, 0x58, 0x93, 0xed, 0xcc, 0xaa, 0xdc, 0x25, 0x3b, 0x0a,
60 0x60, 0x3f, 0x8b, 0x54, 0x3a, 0xc3, 0x4d, 0x31, 0xe7, 0x94, 0xa4, 0x44, 0xfd, 0x02, 0x03, 0x01,
61 0x00, 0x01, };
62
63 static int rsa_compat_test(void)
64 {
65 rsa_key key;
66 unsigned char buf[1024];
67 unsigned long len;
68
69 /* try reading the key */
70 DO(rsa_import(openssl_private_rsa, sizeof(openssl_private_rsa), &key));
71
72 /* now try to export private/public and compare */
73 len = sizeof(buf);
74 DO(rsa_export(buf, &len, PK_PRIVATE, &key));
75 if (len != sizeof(openssl_private_rsa) || memcmp(buf, openssl_private_rsa, len)) {
76 fprintf(stderr, "RSA private export failed to match OpenSSL output, %lu, %lu\n", len, sizeof(openssl_private_rsa));
77
78
79 {
80 int x;
81 printf("\n\n");
82 for (x = 0; x < len; ) { if (buf[x] == openssl_private_rsa[x]) printf("-- "); else printf("%02x ", buf[x]^openssl_private_rsa[x]); if (!(++x & 15)) printf("\n"); }
83 }
84 printf("\n\n");
85
86 return 1;
87 }
88
89 len = sizeof(buf);
90 DO(rsa_export(buf, &len, PK_PUBLIC, &key));
91 if (len != sizeof(openssl_public_rsa) || memcmp(buf, openssl_public_rsa, len)) {
92 fprintf(stderr, "RSA(private) public export failed to match OpenSSL output\n");
93 return 1;
94 }
95 rsa_free(&key);
96
97 /* try reading the public key */
98 DO(rsa_import(openssl_public_rsa, sizeof(openssl_public_rsa), &key));
99 len = sizeof(buf);
100 DO(rsa_export(buf, &len, PK_PUBLIC, &key));
101 if (len != sizeof(openssl_public_rsa) || memcmp(buf, openssl_public_rsa, len)) {
102 fprintf(stderr, "RSA(public) public export failed to match OpenSSL output\n");
103 return 1;
104 }
105 rsa_free(&key);
106
107 return 0;
108 }
6 109
7 int rsa_test(void) 110 int rsa_test(void)
8 { 111 {
9 unsigned char in[1024], out[1024], tmp[1024]; 112 unsigned char in[1024], out[1024], tmp[1024];
10 rsa_key key, privKey, pubKey; 113 rsa_key key, privKey, pubKey;
11 int hash_idx, prng_idx, stat, stat2, cnt; 114 int hash_idx, prng_idx, stat, stat2;
12 unsigned long rsa_msgsize, len, len2; 115 unsigned long rsa_msgsize, len, len2, cnt;
13 static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 }; 116 static unsigned char lparam[] = { 0x01, 0x02, 0x03, 0x04 };
117
118 if (rsa_compat_test() != 0) {
119 return 1;
120 }
14 121
15 hash_idx = find_hash("sha1"); 122 hash_idx = find_hash("sha1");
16 prng_idx = find_prng("yarrow"); 123 prng_idx = find_prng("yarrow");
17 if (hash_idx == -1 || prng_idx == -1) { 124 if (hash_idx == -1 || prng_idx == -1) {
18 printf("rsa_test requires SHA1 and yarrow"); 125 fprintf(stderr, "rsa_test requires SHA1 and yarrow");
19 return 1; 126 return 1;
20 } 127 }
21 128
22 /* make 10 random key */ 129 /* make 10 random key */
23 for (cnt = 0; cnt < 10; cnt++) { 130 for (cnt = 0; cnt < 10; cnt++) {
24 DO(rsa_make_key(&yarrow_prng, prng_idx, 1024/8, 65537, &key)); 131 DO(rsa_make_key(&yarrow_prng, prng_idx, 1024/8, 65537, &key));
25 if (mp_count_bits(&key.N) != 1024) { 132 if (mp_count_bits(&key.N) != 1024) {
26 printf("rsa_1024 key modulus has %d bits\n", mp_count_bits(&key.N)); 133 fprintf(stderr, "rsa_1024 key modulus has %d bits\n", mp_count_bits(&key.N));
27 134
28 len = mp_unsigned_bin_size(&key.N); 135 len = mp_unsigned_bin_size(&key.N);
29 mp_to_unsigned_bin(&key.N, tmp); 136 mp_to_unsigned_bin(&key.N, tmp);
30 printf("N == \n"); 137 fprintf(stderr, "N == \n");
31 for (cnt = 0; cnt < len; ) { 138 for (cnt = 0; cnt < len; ) {
32 printf("%02x ", tmp[cnt]); 139 fprintf(stderr, "%02x ", tmp[cnt]);
33 if (!(++cnt & 15)) printf("\n"); 140 if (!(++cnt & 15)) fprintf(stderr, "\n");
34 } 141 }
35 142
36 len = mp_unsigned_bin_size(&key.p); 143 len = mp_unsigned_bin_size(&key.p);
37 mp_to_unsigned_bin(&key.p, tmp); 144 mp_to_unsigned_bin(&key.p, tmp);
38 printf("p == \n"); 145 fprintf(stderr, "p == \n");
39 for (cnt = 0; cnt < len; ) { 146 for (cnt = 0; cnt < len; ) {
40 printf("%02x ", tmp[cnt]); 147 fprintf(stderr, "%02x ", tmp[cnt]);
41 if (!(++cnt & 15)) printf("\n"); 148 if (!(++cnt & 15)) fprintf(stderr, "\n");
42 } 149 }
43 150
44 len = mp_unsigned_bin_size(&key.q); 151 len = mp_unsigned_bin_size(&key.q);
45 mp_to_unsigned_bin(&key.q, tmp); 152 mp_to_unsigned_bin(&key.q, tmp);
46 printf("\nq == \n"); 153 fprintf(stderr, "\nq == \n");
47 for (cnt = 0; cnt < len; ) { 154 for (cnt = 0; cnt < len; ) {
48 printf("%02x ", tmp[cnt]); 155 fprintf(stderr, "%02x ", tmp[cnt]);
49 if (!(++cnt & 15)) printf("\n"); 156 if (!(++cnt & 15)) fprintf(stderr, "\n");
50 } 157 }
51 printf("\n"); 158 fprintf(stderr, "\n");
52 159
53 160
54 return 1; 161 return 1;
55 } 162 }
56 if (cnt != 9) { 163 if (cnt != 9) {
57 rsa_free(&key); 164 rsa_free(&key);
58 } 165 }
59 } 166 }
60 167
61 /* test PKCS #1 v1.5 */
62 for (cnt = 0; cnt < 4; cnt++) {
63 for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) {
64 /* make a random key/msg */
65 yarrow_read(in, rsa_msgsize, &yarrow_prng);
66
67 len = sizeof(out);
68 len2 = rsa_msgsize;
69
70 /* encrypt */
71 DO(rsa_v15_encrypt_key(in, rsa_msgsize, out, &len, &yarrow_prng, prng_idx, &key));
72 DO(rsa_v15_decrypt_key(out, len, tmp, rsa_msgsize, &stat, &key));
73 if (stat != 1 || memcmp(tmp, in, rsa_msgsize)) {
74 printf("PKCS #1 v1.5 encrypt/decrypt failure (rsa_msgsize: %lu, stat: %d)\n", rsa_msgsize, stat);
75 return 1;
76 }
77 }
78 }
79
80 /* signature */
81 len = sizeof(out);
82 DO(rsa_v15_sign_hash(in, 20, out, &len, hash_idx, &key));
83 in[1] ^= 1;
84 DO(rsa_v15_verify_hash(out, len, in, 20, hash_idx, &stat, &key));
85 in[1] ^= 1;
86 DO(rsa_v15_verify_hash(out, len, in, 20, hash_idx, &stat2, &key));
87 if (!(stat == 0 && stat2 == 1)) {
88 printf("PKCS #1 v1.5 sign/verify failure (stat %d, stat2 %d)\n", stat, stat2);
89 return 1;
90 }
91
92 /* encrypt the key (without lparam) */ 168 /* encrypt the key (without lparam) */
93 for (cnt = 0; cnt < 4; cnt++) { 169 for (cnt = 0; cnt < 4; cnt++) {
94 for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) { 170 for (rsa_msgsize = 1; rsa_msgsize <= 86; rsa_msgsize++) {
95 /* make a random key/msg */ 171 /* make a random key/msg */
96 yarrow_read(in, rsa_msgsize, &yarrow_prng); 172 yarrow_read(in, rsa_msgsize, &yarrow_prng);
103 out[8] ^= 1; 179 out[8] ^= 1;
104 DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat2, &key)); 180 DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat2, &key));
105 /* change a byte back */ 181 /* change a byte back */
106 out[8] ^= 1; 182 out[8] ^= 1;
107 if (len2 != rsa_msgsize) { 183 if (len2 != rsa_msgsize) {
108 printf("\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2); 184 fprintf(stderr, "\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
109 return 1; 185 return 1;
110 } 186 }
111 187
112 len2 = rsa_msgsize; 188 len2 = rsa_msgsize;
113 DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat, &key)); 189 DO(rsa_decrypt_key(out, len, tmp, &len2, NULL, 0, hash_idx, &stat, &key));
114 if (!(stat == 1 && stat2 == 0)) { 190 if (!(stat == 1 && stat2 == 0)) {
115 printf("rsa_decrypt_key failed"); 191 fprintf(stderr, "rsa_decrypt_key failed");
116 return 1; 192 return 1;
117 } 193 }
118 if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) { 194 if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
119 unsigned long x; 195 unsigned long x;
120 printf("\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2); 196 fprintf(stderr, "\nrsa_decrypt_key mismatch, len %lu (second decrypt)\n", len2);
121 printf("Original contents: \n"); 197 fprintf(stderr, "Original contents: \n");
122 for (x = 0; x < rsa_msgsize; ) { 198 for (x = 0; x < rsa_msgsize; ) {
123 printf("%02x ", in[x]); 199 fprintf(stderr, "%02x ", in[x]);
124 if (!(++x % 16)) { 200 if (!(++x % 16)) {
125 printf("\n"); 201 fprintf(stderr, "\n");
126 } 202 }
127 } 203 }
128 printf("\n"); 204 fprintf(stderr, "\n");
129 printf("Output contents: \n"); 205 fprintf(stderr, "Output contents: \n");
130 for (x = 0; x < rsa_msgsize; ) { 206 for (x = 0; x < rsa_msgsize; ) {
131 printf("%02x ", out[x]); 207 fprintf(stderr, "%02x ", out[x]);
132 if (!(++x % 16)) { 208 if (!(++x % 16)) {
133 printf("\n"); 209 fprintf(stderr, "\n");
134 } 210 }
135 } 211 }
136 printf("\n"); 212 fprintf(stderr, "\n");
137 return 1; 213 return 1;
138 } 214 }
139 } 215 }
140 } 216 }
141 217
146 DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, lparam, sizeof(lparam), &yarrow_prng, prng_idx, hash_idx, &key)); 222 DO(rsa_encrypt_key(in, rsa_msgsize, out, &len, lparam, sizeof(lparam), &yarrow_prng, prng_idx, hash_idx, &key));
147 /* change a byte */ 223 /* change a byte */
148 out[8] ^= 1; 224 out[8] ^= 1;
149 DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat2, &key)); 225 DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat2, &key));
150 if (len2 != rsa_msgsize) { 226 if (len2 != rsa_msgsize) {
151 printf("\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2); 227 fprintf(stderr, "\nrsa_decrypt_key mismatch len %lu (first decrypt)", len2);
152 return 1; 228 return 1;
153 } 229 }
154 /* change a byte back */ 230 /* change a byte back */
155 out[8] ^= 1; 231 out[8] ^= 1;
156 232
157 len2 = rsa_msgsize; 233 len2 = rsa_msgsize;
158 DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat, &key)); 234 DO(rsa_decrypt_key(out, len, tmp, &len2, lparam, sizeof(lparam), hash_idx, &stat, &key));
159 if (!(stat == 1 && stat2 == 0)) { 235 if (!(stat == 1 && stat2 == 0)) {
160 printf("rsa_decrypt_key failed"); 236 fprintf(stderr, "rsa_decrypt_key failed");
161 return 1; 237 return 1;
162 } 238 }
163 if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) { 239 if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) {
164 printf("rsa_decrypt_key mismatch len %lu", len2); 240 fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2);
165 return 1; 241 return 1;
166 } 242 }
167 } 243 }
168 244
169 /* sign a message (unsalted, lower cholestorol and Atkins approved) now */ 245 /* sign a message (unsalted, lower cholestorol and Atkins approved) now */
183 /* change a byte */ 259 /* change a byte */
184 in[0] ^= 1; 260 in[0] ^= 1;
185 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &key)); 261 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &key));
186 262
187 if (!(stat == 1 && stat2 == 0)) { 263 if (!(stat == 1 && stat2 == 0)) {
188 printf("rsa_verify_hash (unsalted, origKey) failed, %d, %d", stat, stat2); 264 fprintf(stderr, "rsa_verify_hash (unsalted, origKey) failed, %d, %d", stat, stat2);
189 rsa_free(&key); 265 rsa_free(&key);
190 rsa_free(&pubKey); 266 rsa_free(&pubKey);
191 rsa_free(&privKey); 267 rsa_free(&privKey);
192 return 1; 268 return 1;
193 } 269 }
199 /* change a byte */ 275 /* change a byte */
200 in[0] ^= 1; 276 in[0] ^= 1;
201 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &privKey)); 277 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &privKey));
202 278
203 if (!(stat == 1 && stat2 == 0)) { 279 if (!(stat == 1 && stat2 == 0)) {
204 printf("rsa_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2); 280 fprintf(stderr, "rsa_verify_hash (unsalted, privKey) failed, %d, %d", stat, stat2);
205 rsa_free(&key); 281 rsa_free(&key);
206 rsa_free(&pubKey); 282 rsa_free(&pubKey);
207 rsa_free(&privKey); 283 rsa_free(&privKey);
208 return 1; 284 return 1;
209 } 285 }
215 /* change a byte */ 291 /* change a byte */
216 in[0] ^= 1; 292 in[0] ^= 1;
217 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &pubKey)); 293 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 0, &stat2, &pubKey));
218 294
219 if (!(stat == 1 && stat2 == 0)) { 295 if (!(stat == 1 && stat2 == 0)) {
220 printf("rsa_verify_hash (unsalted, pubkey) failed, %d, %d", stat, stat2); 296 fprintf(stderr, "rsa_verify_hash (unsalted, pubkey) failed, %d, %d", stat, stat2);
221 rsa_free(&key); 297 rsa_free(&key);
222 rsa_free(&pubKey); 298 rsa_free(&pubKey);
223 rsa_free(&privKey); 299 rsa_free(&privKey);
224 return 1; 300 return 1;
225 } 301 }
231 /* change a byte */ 307 /* change a byte */
232 in[0] ^= 1; 308 in[0] ^= 1;
233 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 8, &stat2, &pubKey)); 309 DO(rsa_verify_hash(out, len, in, 20, hash_idx, 8, &stat2, &pubKey));
234 310
235 if (!(stat == 1 && stat2 == 0)) { 311 if (!(stat == 1 && stat2 == 0)) {
236 printf("rsa_verify_hash (salted) failed, %d, %d", stat, stat2); 312 fprintf(stderr, "rsa_verify_hash (salted) failed, %d, %d", stat, stat2);
237 rsa_free(&key); 313 rsa_free(&key);
238 rsa_free(&pubKey); 314 rsa_free(&pubKey);
239 rsa_free(&privKey); 315 rsa_free(&privKey);
240 return 1; 316 return 1;
241 } 317 }
249 325
250 #else 326 #else
251 327
252 int rsa_test(void) 328 int rsa_test(void)
253 { 329 {
254 printf("NOP"); 330 fprintf(stderr, "NOP");
255 return 0; 331 return 0;
256 } 332 }
257 333
258 #endif 334 #endif
335
336 /* $Source: /cvs/libtom/libtomcrypt/testprof/rsa_test.c,v $ */
337 /* $Revision: 1.10 $ */
338 /* $Date: 2005/06/03 19:18:33 $ */