Mercurial > dropbear
comparison libtomcrypt/testprof/rsa_test.c @ 1435:f849a5ca2efc
update to libtomcrypt 1.17 (with Dropbear changes)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 24 Jun 2017 17:50:50 +0800 |
parents | 0cbe8f6dbf9e |
children |
comparison
equal
deleted
inserted
replaced
1434:27b9ddb06b09 | 1435:f849a5ca2efc |
---|---|
1 #include <tomcrypt_test.h> | 1 #include <tomcrypt_test.h> |
2 | 2 |
3 #ifdef MRSA | 3 #ifdef LTC_MRSA |
4 | 4 |
5 #define RSA_MSGSIZE 78 | 5 #define RSA_MSGSIZE 78 |
6 | 6 |
7 /* These are test keys [see file test.key] that I use to test my import/export against */ | 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[] = { | 8 static const unsigned char openssl_private_rsa[] = { |
135 } | 135 } |
136 | 136 |
137 hash_idx = find_hash("sha1"); | 137 hash_idx = find_hash("sha1"); |
138 prng_idx = find_prng("yarrow"); | 138 prng_idx = find_prng("yarrow"); |
139 if (hash_idx == -1 || prng_idx == -1) { | 139 if (hash_idx == -1 || prng_idx == -1) { |
140 fprintf(stderr, "rsa_test requires SHA1 and yarrow"); | 140 fprintf(stderr, "rsa_test requires LTC_SHA1 and yarrow"); |
141 return 1; | 141 return 1; |
142 } | 142 } |
143 | 143 |
144 /* make 10 random key */ | 144 /* make 10 random key */ |
145 for (cnt = 0; cnt < 10; cnt++) { | 145 for (cnt = 0; cnt < 10; cnt++) { |
255 fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2); | 255 fprintf(stderr, "rsa_decrypt_key mismatch len %lu", len2); |
256 return 1; | 256 return 1; |
257 } | 257 } |
258 } | 258 } |
259 | 259 |
260 /* encrypt the key PKCS #1 v1.5 (payload from 1 to 117 bytes) */ | 260 /* encrypt the key LTC_PKCS #1 v1.5 (payload from 1 to 117 bytes) */ |
261 for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) { | 261 for (rsa_msgsize = 1; rsa_msgsize <= 117; rsa_msgsize++) { |
262 len = sizeof(out); | 262 len = sizeof(out); |
263 len2 = rsa_msgsize; | 263 len2 = rsa_msgsize; |
264 DO(rsa_encrypt_key_ex(in, rsa_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, 0, LTC_PKCS_1_V1_5, &key)); | 264 DO(rsa_encrypt_key_ex(in, rsa_msgsize, out, &len, NULL, 0, &yarrow_prng, prng_idx, 0, LTC_LTC_PKCS_1_V1_5, &key)); |
265 | 265 |
266 len2 = rsa_msgsize; | 266 len2 = rsa_msgsize; |
267 DO(rsa_decrypt_key_ex(out, len, tmp, &len2, NULL, 0, 0, LTC_PKCS_1_V1_5, &stat, &key)); | 267 DO(rsa_decrypt_key_ex(out, len, tmp, &len2, NULL, 0, 0, LTC_LTC_PKCS_1_V1_5, &stat, &key)); |
268 if (!(stat == 1 && stat2 == 0)) { | 268 if (!(stat == 1 && stat2 == 0)) { |
269 fprintf(stderr, "rsa_decrypt_key_ex failed, %d, %d", stat, stat2); | 269 fprintf(stderr, "rsa_decrypt_key_ex failed, %d, %d", stat, stat2); |
270 return 1; | 270 return 1; |
271 } | 271 } |
272 if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) { | 272 if (len2 != rsa_msgsize || memcmp(tmp, in, rsa_msgsize)) { |
347 rsa_free(&pubKey); | 347 rsa_free(&pubKey); |
348 rsa_free(&privKey); | 348 rsa_free(&privKey); |
349 return 1; | 349 return 1; |
350 } | 350 } |
351 | 351 |
352 /* sign a message with PKCS #1 v1.5 */ | 352 /* sign a message with LTC_PKCS #1 v1.5 */ |
353 len = sizeof(out); | 353 len = sizeof(out); |
354 DO(rsa_sign_hash_ex(in, 20, out, &len, LTC_PKCS_1_V1_5, &yarrow_prng, prng_idx, hash_idx, 8, &privKey)); | 354 DO(rsa_sign_hash_ex(in, 20, out, &len, LTC_LTC_PKCS_1_V1_5, &yarrow_prng, prng_idx, hash_idx, 8, &privKey)); |
355 DO(rsa_verify_hash_ex(out, len, in, 20, LTC_PKCS_1_V1_5, hash_idx, 8, &stat, &pubKey)); | 355 DO(rsa_verify_hash_ex(out, len, in, 20, LTC_LTC_PKCS_1_V1_5, hash_idx, 8, &stat, &pubKey)); |
356 /* change a byte */ | 356 /* change a byte */ |
357 in[0] ^= 1; | 357 in[0] ^= 1; |
358 DO(rsa_verify_hash_ex(out, len, in, 20, LTC_PKCS_1_V1_5, hash_idx, 8, &stat2, &pubKey)); | 358 DO(rsa_verify_hash_ex(out, len, in, 20, LTC_LTC_PKCS_1_V1_5, hash_idx, 8, &stat2, &pubKey)); |
359 | 359 |
360 if (!(stat == 1 && stat2 == 0)) { | 360 if (!(stat == 1 && stat2 == 0)) { |
361 fprintf(stderr, "rsa_verify_hash_ex failed, %d, %d", stat, stat2); | 361 fprintf(stderr, "rsa_verify_hash_ex failed, %d, %d", stat, stat2); |
362 rsa_free(&key); | 362 rsa_free(&key); |
363 rsa_free(&pubKey); | 363 rsa_free(&pubKey); |
380 return 0; | 380 return 0; |
381 } | 381 } |
382 | 382 |
383 #endif | 383 #endif |
384 | 384 |
385 /* $Source: /cvs/libtom/libtomcrypt/testprof/rsa_test.c,v $ */ | 385 /* $Source$ */ |
386 /* $Revision: 1.18 $ */ | 386 /* $Revision$ */ |
387 /* $Date: 2006/11/21 00:10:18 $ */ | 387 /* $Date$ */ |