diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/bn/divtest.c | 41 | ||||
| -rw-r--r-- | src/lib/libcrypto/jpake/jpaketest.c | 192 | ||||
| -rw-r--r-- | src/lib/libcrypto/rsa/rsa_test.c | 340 | ||||
| -rw-r--r-- | src/lib/libcrypto/srp/srptest.c | 162 | ||||
| -rw-r--r-- | src/lib/libcrypto/whrlpool/wp_test.c | 228 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/bn/divtest.c | 41 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/jpake/jpaketest.c | 192 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/rsa/rsa_test.c | 340 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/srp/srptest.c | 162 | ||||
| -rw-r--r-- | src/lib/libssl/src/crypto/whrlpool/wp_test.c | 228 |
10 files changed, 0 insertions, 1926 deletions
diff --git a/src/lib/libcrypto/bn/divtest.c b/src/lib/libcrypto/bn/divtest.c deleted file mode 100644 index d3fc688f33..0000000000 --- a/src/lib/libcrypto/bn/divtest.c +++ /dev/null | |||
| @@ -1,41 +0,0 @@ | |||
| 1 | #include <openssl/bn.h> | ||
| 2 | #include <openssl/rand.h> | ||
| 3 | |||
| 4 | static int Rand(n) | ||
| 5 | { | ||
| 6 | unsigned char x[2]; | ||
| 7 | RAND_pseudo_bytes(x,2); | ||
| 8 | return (x[0] + 2*x[1]); | ||
| 9 | } | ||
| 10 | |||
| 11 | static void bug(char *m, BIGNUM *a, BIGNUM *b) | ||
| 12 | { | ||
| 13 | printf("%s!\na=",m); | ||
| 14 | BN_print_fp(stdout, a); | ||
| 15 | printf("\nb="); | ||
| 16 | BN_print_fp(stdout, b); | ||
| 17 | printf("\n"); | ||
| 18 | fflush(stdout); | ||
| 19 | } | ||
| 20 | |||
| 21 | main() | ||
| 22 | { | ||
| 23 | BIGNUM *a=BN_new(), *b=BN_new(), *c=BN_new(), *d=BN_new(), | ||
| 24 | *C=BN_new(), *D=BN_new(); | ||
| 25 | BN_RECP_CTX *recp=BN_RECP_CTX_new(); | ||
| 26 | BN_CTX *ctx=BN_CTX_new(); | ||
| 27 | |||
| 28 | for(;;) { | ||
| 29 | BN_pseudo_rand(a,Rand(),0,0); | ||
| 30 | BN_pseudo_rand(b,Rand(),0,0); | ||
| 31 | if (BN_is_zero(b)) continue; | ||
| 32 | |||
| 33 | BN_RECP_CTX_set(recp,b,ctx); | ||
| 34 | if (BN_div(C,D,a,b,ctx) != 1) | ||
| 35 | bug("BN_div failed",a,b); | ||
| 36 | if (BN_div_recp(c,d,a,recp,ctx) != 1) | ||
| 37 | bug("BN_div_recp failed",a,b); | ||
| 38 | else if (BN_cmp(c,C) != 0 || BN_cmp(c,C) != 0) | ||
| 39 | bug("mismatch",a,b); | ||
| 40 | } | ||
| 41 | } | ||
diff --git a/src/lib/libcrypto/jpake/jpaketest.c b/src/lib/libcrypto/jpake/jpaketest.c deleted file mode 100644 index eaba75ed8a..0000000000 --- a/src/lib/libcrypto/jpake/jpaketest.c +++ /dev/null | |||
| @@ -1,192 +0,0 @@ | |||
| 1 | #include <openssl/opensslconf.h> | ||
| 2 | |||
| 3 | #ifdef OPENSSL_NO_JPAKE | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | |||
| 7 | int main(int argc, char *argv[]) | ||
| 8 | { | ||
| 9 | printf("No J-PAKE support\n"); | ||
| 10 | return(0); | ||
| 11 | } | ||
| 12 | |||
| 13 | #else | ||
| 14 | |||
| 15 | #include <openssl/jpake.h> | ||
| 16 | #include <openssl/err.h> | ||
| 17 | |||
| 18 | static void showbn(const char *name, const BIGNUM *bn) | ||
| 19 | { | ||
| 20 | fputs(name, stdout); | ||
| 21 | fputs(" = ", stdout); | ||
| 22 | BN_print_fp(stdout, bn); | ||
| 23 | putc('\n', stdout); | ||
| 24 | } | ||
| 25 | |||
| 26 | static int run_jpake(JPAKE_CTX *alice, JPAKE_CTX *bob) | ||
| 27 | { | ||
| 28 | JPAKE_STEP1 alice_s1; | ||
| 29 | JPAKE_STEP1 bob_s1; | ||
| 30 | JPAKE_STEP2 alice_s2; | ||
| 31 | JPAKE_STEP2 bob_s2; | ||
| 32 | JPAKE_STEP3A alice_s3a; | ||
| 33 | JPAKE_STEP3B bob_s3b; | ||
| 34 | |||
| 35 | /* Alice -> Bob: step 1 */ | ||
| 36 | puts("A->B s1"); | ||
| 37 | JPAKE_STEP1_init(&alice_s1); | ||
| 38 | JPAKE_STEP1_generate(&alice_s1, alice); | ||
| 39 | if(!JPAKE_STEP1_process(bob, &alice_s1)) | ||
| 40 | { | ||
| 41 | printf("Bob fails to process Alice's step 1\n"); | ||
| 42 | ERR_print_errors_fp(stdout); | ||
| 43 | return 1; | ||
| 44 | } | ||
| 45 | JPAKE_STEP1_release(&alice_s1); | ||
| 46 | |||
| 47 | /* Bob -> Alice: step 1 */ | ||
| 48 | puts("B->A s1"); | ||
| 49 | JPAKE_STEP1_init(&bob_s1); | ||
| 50 | JPAKE_STEP1_generate(&bob_s1, bob); | ||
| 51 | if(!JPAKE_STEP1_process(alice, &bob_s1)) | ||
| 52 | { | ||
| 53 | printf("Alice fails to process Bob's step 1\n"); | ||
| 54 | ERR_print_errors_fp(stdout); | ||
| 55 | return 2; | ||
| 56 | } | ||
| 57 | JPAKE_STEP1_release(&bob_s1); | ||
| 58 | |||
| 59 | /* Alice -> Bob: step 2 */ | ||
| 60 | puts("A->B s2"); | ||
| 61 | JPAKE_STEP2_init(&alice_s2); | ||
| 62 | JPAKE_STEP2_generate(&alice_s2, alice); | ||
| 63 | if(!JPAKE_STEP2_process(bob, &alice_s2)) | ||
| 64 | { | ||
| 65 | printf("Bob fails to process Alice's step 2\n"); | ||
| 66 | ERR_print_errors_fp(stdout); | ||
| 67 | return 3; | ||
| 68 | } | ||
| 69 | JPAKE_STEP2_release(&alice_s2); | ||
| 70 | |||
| 71 | /* Bob -> Alice: step 2 */ | ||
| 72 | puts("B->A s2"); | ||
| 73 | JPAKE_STEP2_init(&bob_s2); | ||
| 74 | JPAKE_STEP2_generate(&bob_s2, bob); | ||
| 75 | if(!JPAKE_STEP2_process(alice, &bob_s2)) | ||
| 76 | { | ||
| 77 | printf("Alice fails to process Bob's step 2\n"); | ||
| 78 | ERR_print_errors_fp(stdout); | ||
| 79 | return 4; | ||
| 80 | } | ||
| 81 | JPAKE_STEP2_release(&bob_s2); | ||
| 82 | |||
| 83 | showbn("Alice's key", JPAKE_get_shared_key(alice)); | ||
| 84 | showbn("Bob's key ", JPAKE_get_shared_key(bob)); | ||
| 85 | |||
| 86 | /* Alice -> Bob: step 3a */ | ||
| 87 | puts("A->B s3a"); | ||
| 88 | JPAKE_STEP3A_init(&alice_s3a); | ||
| 89 | JPAKE_STEP3A_generate(&alice_s3a, alice); | ||
| 90 | if(!JPAKE_STEP3A_process(bob, &alice_s3a)) | ||
| 91 | { | ||
| 92 | printf("Bob fails to process Alice's step 3a\n"); | ||
| 93 | ERR_print_errors_fp(stdout); | ||
| 94 | return 5; | ||
| 95 | } | ||
| 96 | JPAKE_STEP3A_release(&alice_s3a); | ||
| 97 | |||
| 98 | /* Bob -> Alice: step 3b */ | ||
| 99 | puts("B->A s3b"); | ||
| 100 | JPAKE_STEP3B_init(&bob_s3b); | ||
| 101 | JPAKE_STEP3B_generate(&bob_s3b, bob); | ||
| 102 | if(!JPAKE_STEP3B_process(alice, &bob_s3b)) | ||
| 103 | { | ||
| 104 | printf("Alice fails to process Bob's step 3b\n"); | ||
| 105 | ERR_print_errors_fp(stdout); | ||
| 106 | return 6; | ||
| 107 | } | ||
| 108 | JPAKE_STEP3B_release(&bob_s3b); | ||
| 109 | |||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | int main(int argc, char **argv) | ||
| 114 | { | ||
| 115 | JPAKE_CTX *alice; | ||
| 116 | JPAKE_CTX *bob; | ||
| 117 | BIGNUM *p = NULL; | ||
| 118 | BIGNUM *g = NULL; | ||
| 119 | BIGNUM *q = NULL; | ||
| 120 | BIGNUM *secret = BN_new(); | ||
| 121 | BIO *bio_err; | ||
| 122 | |||
| 123 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); | ||
| 124 | |||
| 125 | CRYPTO_malloc_debug_init(); | ||
| 126 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 127 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 128 | |||
| 129 | ERR_load_crypto_strings(); | ||
| 130 | |||
| 131 | /* | ||
| 132 | BN_hex2bn(&p, "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7"); | ||
| 133 | BN_hex2bn(&g, "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a"); | ||
| 134 | BN_hex2bn(&q, "9760508f15230bccb292b982a2eb840bf0581cf5"); | ||
| 135 | */ | ||
| 136 | /* | ||
| 137 | p = BN_new(); | ||
| 138 | BN_generate_prime(p, 1024, 1, NULL, NULL, NULL, NULL); | ||
| 139 | */ | ||
| 140 | /* Use a safe prime for p (that we found earlier) */ | ||
| 141 | BN_hex2bn(&p, "F9E5B365665EA7A05A9C534502780FEE6F1AB5BD4F49947FD036DBD7E905269AF46EF28B0FC07487EE4F5D20FB3C0AF8E700F3A2FA3414970CBED44FEDFF80CE78D800F184BB82435D137AADA2C6C16523247930A63B85661D1FC817A51ACD96168E95898A1F83A79FFB529368AA7833ABD1B0C3AEDDB14D2E1A2F71D99F763F"); | ||
| 142 | showbn("p", p); | ||
| 143 | g = BN_new(); | ||
| 144 | BN_set_word(g, 2); | ||
| 145 | showbn("g", g); | ||
| 146 | q = BN_new(); | ||
| 147 | BN_rshift1(q, p); | ||
| 148 | showbn("q", q); | ||
| 149 | |||
| 150 | BN_rand(secret, 32, -1, 0); | ||
| 151 | |||
| 152 | /* A normal run, expect this to work... */ | ||
| 153 | alice = JPAKE_CTX_new("Alice", "Bob", p, g, q, secret); | ||
| 154 | bob = JPAKE_CTX_new("Bob", "Alice", p, g, q, secret); | ||
| 155 | |||
| 156 | if(run_jpake(alice, bob) != 0) | ||
| 157 | { | ||
| 158 | fprintf(stderr, "Plain JPAKE run failed\n"); | ||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | |||
| 162 | JPAKE_CTX_free(bob); | ||
| 163 | JPAKE_CTX_free(alice); | ||
| 164 | |||
| 165 | /* Now give Alice and Bob different secrets */ | ||
| 166 | alice = JPAKE_CTX_new("Alice", "Bob", p, g, q, secret); | ||
| 167 | BN_add_word(secret, 1); | ||
| 168 | bob = JPAKE_CTX_new("Bob", "Alice", p, g, q, secret); | ||
| 169 | |||
| 170 | if(run_jpake(alice, bob) != 5) | ||
| 171 | { | ||
| 172 | fprintf(stderr, "Mismatched secret JPAKE run failed\n"); | ||
| 173 | return 1; | ||
| 174 | } | ||
| 175 | |||
| 176 | JPAKE_CTX_free(bob); | ||
| 177 | JPAKE_CTX_free(alice); | ||
| 178 | |||
| 179 | BN_free(secret); | ||
| 180 | BN_free(q); | ||
| 181 | BN_free(g); | ||
| 182 | BN_free(p); | ||
| 183 | |||
| 184 | CRYPTO_cleanup_all_ex_data(); | ||
| 185 | ERR_remove_thread_state(NULL); | ||
| 186 | ERR_free_strings(); | ||
| 187 | CRYPTO_mem_leaks(bio_err); | ||
| 188 | |||
| 189 | return 0; | ||
| 190 | } | ||
| 191 | |||
| 192 | #endif | ||
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c deleted file mode 100644 index c8705a0f6e..0000000000 --- a/src/lib/libcrypto/rsa/rsa_test.c +++ /dev/null | |||
| @@ -1,340 +0,0 @@ | |||
| 1 | /* test vectors from p1ovect1.txt */ | ||
| 2 | |||
| 3 | #include <stdio.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | #include "e_os.h" | ||
| 7 | |||
| 8 | #include <openssl/crypto.h> | ||
| 9 | #include <openssl/err.h> | ||
| 10 | #include <openssl/rand.h> | ||
| 11 | #include <openssl/bn.h> | ||
| 12 | #ifdef OPENSSL_NO_RSA | ||
| 13 | int main(int argc, char *argv[]) | ||
| 14 | { | ||
| 15 | printf("No RSA support\n"); | ||
| 16 | return(0); | ||
| 17 | } | ||
| 18 | #else | ||
| 19 | #include <openssl/rsa.h> | ||
| 20 | |||
| 21 | #define SetKey \ | ||
| 22 | key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \ | ||
| 23 | key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \ | ||
| 24 | key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \ | ||
| 25 | key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \ | ||
| 26 | key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \ | ||
| 27 | key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \ | ||
| 28 | key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \ | ||
| 29 | key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \ | ||
| 30 | memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \ | ||
| 31 | return (sizeof(ctext_ex) - 1); | ||
| 32 | |||
| 33 | static int key1(RSA *key, unsigned char *c) | ||
| 34 | { | ||
| 35 | static unsigned char n[] = | ||
| 36 | "\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F" | ||
| 37 | "\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5" | ||
| 38 | "\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93" | ||
| 39 | "\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1" | ||
| 40 | "\xF5"; | ||
| 41 | |||
| 42 | static unsigned char e[] = "\x11"; | ||
| 43 | |||
| 44 | static unsigned char d[] = | ||
| 45 | "\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44" | ||
| 46 | "\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64" | ||
| 47 | "\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9" | ||
| 48 | "\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51"; | ||
| 49 | |||
| 50 | static unsigned char p[] = | ||
| 51 | "\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
| 52 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12" | ||
| 53 | "\x0D"; | ||
| 54 | |||
| 55 | static unsigned char q[] = | ||
| 56 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 57 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
| 58 | "\x89"; | ||
| 59 | |||
| 60 | static unsigned char dmp1[] = | ||
| 61 | "\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF" | ||
| 62 | "\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05"; | ||
| 63 | |||
| 64 | static unsigned char dmq1[] = | ||
| 65 | "\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99" | ||
| 66 | "\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D" | ||
| 67 | "\x51"; | ||
| 68 | |||
| 69 | static unsigned char iqmp[] = | ||
| 70 | "\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8" | ||
| 71 | "\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26"; | ||
| 72 | |||
| 73 | static unsigned char ctext_ex[] = | ||
| 74 | "\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89" | ||
| 75 | "\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52" | ||
| 76 | "\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44" | ||
| 77 | "\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2"; | ||
| 78 | |||
| 79 | SetKey; | ||
| 80 | } | ||
| 81 | |||
| 82 | static int key2(RSA *key, unsigned char *c) | ||
| 83 | { | ||
| 84 | static unsigned char n[] = | ||
| 85 | "\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8" | ||
| 86 | "\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26" | ||
| 87 | "\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8" | ||
| 88 | "\x34\x77\xCF"; | ||
| 89 | |||
| 90 | static unsigned char e[] = "\x3"; | ||
| 91 | |||
| 92 | static unsigned char d[] = | ||
| 93 | "\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2" | ||
| 94 | "\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41" | ||
| 95 | "\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21" | ||
| 96 | "\xE5\xEB"; | ||
| 97 | |||
| 98 | static unsigned char p[] = | ||
| 99 | "\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92" | ||
| 100 | "\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91"; | ||
| 101 | |||
| 102 | static unsigned char q[] = | ||
| 103 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 104 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F"; | ||
| 105 | |||
| 106 | static unsigned char dmp1[] = | ||
| 107 | "\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61" | ||
| 108 | "\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B"; | ||
| 109 | |||
| 110 | static unsigned char dmq1[] = | ||
| 111 | "\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90" | ||
| 112 | "\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F"; | ||
| 113 | |||
| 114 | static unsigned char iqmp[] = | ||
| 115 | "\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13" | ||
| 116 | "\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D"; | ||
| 117 | |||
| 118 | static unsigned char ctext_ex[] = | ||
| 119 | "\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a" | ||
| 120 | "\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4" | ||
| 121 | "\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52" | ||
| 122 | "\x62\x51"; | ||
| 123 | |||
| 124 | SetKey; | ||
| 125 | } | ||
| 126 | |||
| 127 | static int key3(RSA *key, unsigned char *c) | ||
| 128 | { | ||
| 129 | static unsigned char n[] = | ||
| 130 | "\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71" | ||
| 131 | "\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5" | ||
| 132 | "\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD" | ||
| 133 | "\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80" | ||
| 134 | "\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25" | ||
| 135 | "\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39" | ||
| 136 | "\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68" | ||
| 137 | "\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD" | ||
| 138 | "\xCB"; | ||
| 139 | |||
| 140 | static unsigned char e[] = "\x11"; | ||
| 141 | |||
| 142 | static unsigned char d[] = | ||
| 143 | "\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD" | ||
| 144 | "\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41" | ||
| 145 | "\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69" | ||
| 146 | "\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA" | ||
| 147 | "\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94" | ||
| 148 | "\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A" | ||
| 149 | "\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94" | ||
| 150 | "\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3" | ||
| 151 | "\xC1"; | ||
| 152 | |||
| 153 | static unsigned char p[] = | ||
| 154 | "\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60" | ||
| 155 | "\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6" | ||
| 156 | "\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A" | ||
| 157 | "\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65" | ||
| 158 | "\x99"; | ||
| 159 | |||
| 160 | static unsigned char q[] = | ||
| 161 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 162 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
| 163 | "\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
| 164 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15" | ||
| 165 | "\x03"; | ||
| 166 | |||
| 167 | static unsigned char dmp1[] = | ||
| 168 | "\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A" | ||
| 169 | "\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E" | ||
| 170 | "\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E" | ||
| 171 | "\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81"; | ||
| 172 | |||
| 173 | static unsigned char dmq1[] = | ||
| 174 | "\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9" | ||
| 175 | "\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7" | ||
| 176 | "\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D" | ||
| 177 | "\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D"; | ||
| 178 | |||
| 179 | static unsigned char iqmp[] = | ||
| 180 | "\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23" | ||
| 181 | "\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11" | ||
| 182 | "\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E" | ||
| 183 | "\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39" | ||
| 184 | "\xF7"; | ||
| 185 | |||
| 186 | static unsigned char ctext_ex[] = | ||
| 187 | "\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7" | ||
| 188 | "\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce" | ||
| 189 | "\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3" | ||
| 190 | "\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06" | ||
| 191 | "\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86" | ||
| 192 | "\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4" | ||
| 193 | "\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a" | ||
| 194 | "\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1"; | ||
| 195 | |||
| 196 | SetKey; | ||
| 197 | } | ||
| 198 | |||
| 199 | static int pad_unknown(void) | ||
| 200 | { | ||
| 201 | unsigned long l; | ||
| 202 | while ((l = ERR_get_error()) != 0) | ||
| 203 | if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE) | ||
| 204 | return(1); | ||
| 205 | return(0); | ||
| 206 | } | ||
| 207 | |||
| 208 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; | ||
| 209 | |||
| 210 | int main(int argc, char *argv[]) | ||
| 211 | { | ||
| 212 | int err=0; | ||
| 213 | int v; | ||
| 214 | RSA *key; | ||
| 215 | unsigned char ptext[256]; | ||
| 216 | unsigned char ctext[256]; | ||
| 217 | static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a"; | ||
| 218 | unsigned char ctext_ex[256]; | ||
| 219 | int plen; | ||
| 220 | int clen = 0; | ||
| 221 | int num; | ||
| 222 | int n; | ||
| 223 | |||
| 224 | CRYPTO_malloc_debug_init(); | ||
| 225 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 226 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 227 | |||
| 228 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */ | ||
| 229 | |||
| 230 | plen = sizeof(ptext_ex) - 1; | ||
| 231 | |||
| 232 | for (v = 0; v < 6; v++) | ||
| 233 | { | ||
| 234 | key = RSA_new(); | ||
| 235 | switch (v%3) { | ||
| 236 | case 0: | ||
| 237 | clen = key1(key, ctext_ex); | ||
| 238 | break; | ||
| 239 | case 1: | ||
| 240 | clen = key2(key, ctext_ex); | ||
| 241 | break; | ||
| 242 | case 2: | ||
| 243 | clen = key3(key, ctext_ex); | ||
| 244 | break; | ||
| 245 | } | ||
| 246 | if (v/3 >= 1) key->flags |= RSA_FLAG_NO_CONSTTIME; | ||
| 247 | |||
| 248 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
| 249 | RSA_PKCS1_PADDING); | ||
| 250 | if (num != clen) | ||
| 251 | { | ||
| 252 | printf("PKCS#1 v1.5 encryption failed!\n"); | ||
| 253 | err=1; | ||
| 254 | goto oaep; | ||
| 255 | } | ||
| 256 | |||
| 257 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
| 258 | RSA_PKCS1_PADDING); | ||
| 259 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
| 260 | { | ||
| 261 | printf("PKCS#1 v1.5 decryption failed!\n"); | ||
| 262 | err=1; | ||
| 263 | } | ||
| 264 | else | ||
| 265 | printf("PKCS #1 v1.5 encryption/decryption ok\n"); | ||
| 266 | |||
| 267 | oaep: | ||
| 268 | ERR_clear_error(); | ||
| 269 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
| 270 | RSA_PKCS1_OAEP_PADDING); | ||
| 271 | if (num == -1 && pad_unknown()) | ||
| 272 | { | ||
| 273 | printf("No OAEP support\n"); | ||
| 274 | goto next; | ||
| 275 | } | ||
| 276 | if (num != clen) | ||
| 277 | { | ||
| 278 | printf("OAEP encryption failed!\n"); | ||
| 279 | err=1; | ||
| 280 | goto next; | ||
| 281 | } | ||
| 282 | |||
| 283 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
| 284 | RSA_PKCS1_OAEP_PADDING); | ||
| 285 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
| 286 | { | ||
| 287 | printf("OAEP decryption (encrypted data) failed!\n"); | ||
| 288 | err=1; | ||
| 289 | } | ||
| 290 | else if (memcmp(ctext, ctext_ex, num) == 0) | ||
| 291 | printf("OAEP test vector %d passed!\n", v); | ||
| 292 | |||
| 293 | /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). | ||
| 294 | Try decrypting ctext_ex */ | ||
| 295 | |||
| 296 | num = RSA_private_decrypt(clen, ctext_ex, ptext, key, | ||
| 297 | RSA_PKCS1_OAEP_PADDING); | ||
| 298 | |||
| 299 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
| 300 | { | ||
| 301 | printf("OAEP decryption (test vector data) failed!\n"); | ||
| 302 | err=1; | ||
| 303 | } | ||
| 304 | else | ||
| 305 | printf("OAEP encryption/decryption ok\n"); | ||
| 306 | |||
| 307 | /* Try decrypting corrupted ciphertexts */ | ||
| 308 | for(n = 0 ; n < clen ; ++n) | ||
| 309 | { | ||
| 310 | int b; | ||
| 311 | unsigned char saved = ctext[n]; | ||
| 312 | for(b = 0 ; b < 256 ; ++b) | ||
| 313 | { | ||
| 314 | if(b == saved) | ||
| 315 | continue; | ||
| 316 | ctext[n] = b; | ||
| 317 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
| 318 | RSA_PKCS1_OAEP_PADDING); | ||
| 319 | if(num > 0) | ||
| 320 | { | ||
| 321 | printf("Corrupt data decrypted!\n"); | ||
| 322 | err = 1; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | } | ||
| 326 | next: | ||
| 327 | RSA_free(key); | ||
| 328 | } | ||
| 329 | |||
| 330 | CRYPTO_cleanup_all_ex_data(); | ||
| 331 | ERR_remove_thread_state(NULL); | ||
| 332 | |||
| 333 | CRYPTO_mem_leaks_fp(stderr); | ||
| 334 | |||
| 335 | #ifdef OPENSSL_SYS_NETWARE | ||
| 336 | if (err) printf("ERROR: %d\n", err); | ||
| 337 | #endif | ||
| 338 | return err; | ||
| 339 | } | ||
| 340 | #endif | ||
diff --git a/src/lib/libcrypto/srp/srptest.c b/src/lib/libcrypto/srp/srptest.c deleted file mode 100644 index 04b66b4544..0000000000 --- a/src/lib/libcrypto/srp/srptest.c +++ /dev/null | |||
| @@ -1,162 +0,0 @@ | |||
| 1 | #include <openssl/opensslconf.h> | ||
| 2 | #ifdef OPENSSL_NO_SRP | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | int main(int argc, char *argv[]) | ||
| 7 | { | ||
| 8 | printf("No SRP support\n"); | ||
| 9 | return(0); | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include <openssl/srp.h> | ||
| 15 | #include <openssl/rand.h> | ||
| 16 | #include <openssl/err.h> | ||
| 17 | |||
| 18 | static void showbn(const char *name, const BIGNUM *bn) | ||
| 19 | { | ||
| 20 | fputs(name, stdout); | ||
| 21 | fputs(" = ", stdout); | ||
| 22 | BN_print_fp(stdout, bn); | ||
| 23 | putc('\n', stdout); | ||
| 24 | } | ||
| 25 | |||
| 26 | #define RANDOM_SIZE 32 /* use 256 bits on each side */ | ||
| 27 | |||
| 28 | static int run_srp(const char *username, const char *client_pass, const char *server_pass) | ||
| 29 | { | ||
| 30 | int ret=-1; | ||
| 31 | BIGNUM *s = NULL; | ||
| 32 | BIGNUM *v = NULL; | ||
| 33 | BIGNUM *a = NULL; | ||
| 34 | BIGNUM *b = NULL; | ||
| 35 | BIGNUM *u = NULL; | ||
| 36 | BIGNUM *x = NULL; | ||
| 37 | BIGNUM *Apub = NULL; | ||
| 38 | BIGNUM *Bpub = NULL; | ||
| 39 | BIGNUM *Kclient = NULL; | ||
| 40 | BIGNUM *Kserver = NULL; | ||
| 41 | unsigned char rand_tmp[RANDOM_SIZE]; | ||
| 42 | /* use builtin 1024-bit params */ | ||
| 43 | SRP_gN *GN = SRP_get_default_gN("1024"); | ||
| 44 | |||
| 45 | if(GN == NULL) | ||
| 46 | { | ||
| 47 | fprintf(stderr, "Failed to get SRP parameters\n"); | ||
| 48 | return -1; | ||
| 49 | } | ||
| 50 | /* Set up server's password entry */ | ||
| 51 | if(!SRP_create_verifier_BN(username, server_pass, &s, &v, GN->N, GN->g)) | ||
| 52 | { | ||
| 53 | fprintf(stderr, "Failed to create SRP verifier\n"); | ||
| 54 | return -1; | ||
| 55 | } | ||
| 56 | |||
| 57 | showbn("N", GN->N); | ||
| 58 | showbn("g", GN->g); | ||
| 59 | showbn("Salt", s); | ||
| 60 | showbn("Verifier", v); | ||
| 61 | |||
| 62 | /* Server random */ | ||
| 63 | RAND_pseudo_bytes(rand_tmp, sizeof(rand_tmp)); | ||
| 64 | b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL); | ||
| 65 | /* TODO - check b != 0 */ | ||
| 66 | showbn("b", b); | ||
| 67 | |||
| 68 | /* Server's first message */ | ||
| 69 | Bpub = SRP_Calc_B(b, GN->N, GN->g, v); | ||
| 70 | showbn("B", Bpub); | ||
| 71 | |||
| 72 | if(!SRP_Verify_B_mod_N(Bpub, GN->N)) | ||
| 73 | { | ||
| 74 | fprintf(stderr, "Invalid B\n"); | ||
| 75 | return -1; | ||
| 76 | } | ||
| 77 | |||
| 78 | /* Client random */ | ||
| 79 | RAND_pseudo_bytes(rand_tmp, sizeof(rand_tmp)); | ||
| 80 | a = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL); | ||
| 81 | /* TODO - check a != 0 */ | ||
| 82 | showbn("a", a); | ||
| 83 | |||
| 84 | /* Client's response */ | ||
| 85 | Apub = SRP_Calc_A(a, GN->N, GN->g); | ||
| 86 | showbn("A", Apub); | ||
| 87 | |||
| 88 | if(!SRP_Verify_A_mod_N(Apub, GN->N)) | ||
| 89 | { | ||
| 90 | fprintf(stderr, "Invalid A\n"); | ||
| 91 | return -1; | ||
| 92 | } | ||
| 93 | |||
| 94 | /* Both sides calculate u */ | ||
| 95 | u = SRP_Calc_u(Apub, Bpub, GN->N); | ||
| 96 | |||
| 97 | /* Client's key */ | ||
| 98 | x = SRP_Calc_x(s, username, client_pass); | ||
| 99 | Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u); | ||
| 100 | showbn("Client's key", Kclient); | ||
| 101 | |||
| 102 | /* Server's key */ | ||
| 103 | Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N); | ||
| 104 | showbn("Server's key", Kserver); | ||
| 105 | |||
| 106 | if(BN_cmp(Kclient, Kserver) == 0) | ||
| 107 | { | ||
| 108 | ret = 0; | ||
| 109 | } | ||
| 110 | else | ||
| 111 | { | ||
| 112 | fprintf(stderr, "Keys mismatch\n"); | ||
| 113 | ret = 1; | ||
| 114 | } | ||
| 115 | |||
| 116 | BN_clear_free(Kclient); | ||
| 117 | BN_clear_free(Kserver); | ||
| 118 | BN_clear_free(x); | ||
| 119 | BN_free(u); | ||
| 120 | BN_free(Apub); | ||
| 121 | BN_clear_free(a); | ||
| 122 | BN_free(Bpub); | ||
| 123 | BN_clear_free(b); | ||
| 124 | BN_free(s); | ||
| 125 | BN_clear_free(v); | ||
| 126 | |||
| 127 | return ret; | ||
| 128 | } | ||
| 129 | |||
| 130 | int main(int argc, char **argv) | ||
| 131 | { | ||
| 132 | BIO *bio_err; | ||
| 133 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); | ||
| 134 | |||
| 135 | CRYPTO_malloc_debug_init(); | ||
| 136 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 137 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 138 | |||
| 139 | ERR_load_crypto_strings(); | ||
| 140 | |||
| 141 | /* "Negative" test, expect a mismatch */ | ||
| 142 | if(run_srp("alice", "password1", "password2") == 0) | ||
| 143 | { | ||
| 144 | fprintf(stderr, "Mismatched SRP run failed\n"); | ||
| 145 | return 1; | ||
| 146 | } | ||
| 147 | |||
| 148 | /* "Positive" test, should pass */ | ||
| 149 | if(run_srp("alice", "password", "password") != 0) | ||
| 150 | { | ||
| 151 | fprintf(stderr, "Plain SRP run failed\n"); | ||
| 152 | return 1; | ||
| 153 | } | ||
| 154 | |||
| 155 | CRYPTO_cleanup_all_ex_data(); | ||
| 156 | ERR_remove_thread_state(NULL); | ||
| 157 | ERR_free_strings(); | ||
| 158 | CRYPTO_mem_leaks(bio_err); | ||
| 159 | |||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | #endif | ||
diff --git a/src/lib/libcrypto/whrlpool/wp_test.c b/src/lib/libcrypto/whrlpool/wp_test.c deleted file mode 100644 index c68c2c62ca..0000000000 --- a/src/lib/libcrypto/whrlpool/wp_test.c +++ /dev/null | |||
| @@ -1,228 +0,0 @@ | |||
| 1 | /* ==================================================================== | ||
| 2 | * Copyright (c) 2005 The OpenSSL Project. All rights reserved. | ||
| 3 | * ==================================================================== | ||
| 4 | */ | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | |||
| 9 | #include <openssl/whrlpool.h> | ||
| 10 | #include <openssl/crypto.h> | ||
| 11 | |||
| 12 | #if defined(OPENSSL_NO_WHIRLPOOL) | ||
| 13 | int main(int argc, char *argv[]) | ||
| 14 | { | ||
| 15 | printf("No Whirlpool support\n"); | ||
| 16 | return(0); | ||
| 17 | } | ||
| 18 | #else | ||
| 19 | |||
| 20 | /* ISO/IEC 10118-3 test vector set */ | ||
| 21 | unsigned char iso_test_1[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 22 | 0x19,0xFA,0x61,0xD7,0x55,0x22,0xA4,0x66, | ||
| 23 | 0x9B,0x44,0xE3,0x9C,0x1D,0x2E,0x17,0x26, | ||
| 24 | 0xC5,0x30,0x23,0x21,0x30,0xD4,0x07,0xF8, | ||
| 25 | 0x9A,0xFE,0xE0,0x96,0x49,0x97,0xF7,0xA7, | ||
| 26 | 0x3E,0x83,0xBE,0x69,0x8B,0x28,0x8F,0xEB, | ||
| 27 | 0xCF,0x88,0xE3,0xE0,0x3C,0x4F,0x07,0x57, | ||
| 28 | 0xEA,0x89,0x64,0xE5,0x9B,0x63,0xD9,0x37, | ||
| 29 | 0x08,0xB1,0x38,0xCC,0x42,0xA6,0x6E,0xB3 }; | ||
| 30 | |||
| 31 | unsigned char iso_test_2[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 32 | 0x8A,0xCA,0x26,0x02,0x79,0x2A,0xEC,0x6F, | ||
| 33 | 0x11,0xA6,0x72,0x06,0x53,0x1F,0xB7,0xD7, | ||
| 34 | 0xF0,0xDF,0xF5,0x94,0x13,0x14,0x5E,0x69, | ||
| 35 | 0x73,0xC4,0x50,0x01,0xD0,0x08,0x7B,0x42, | ||
| 36 | 0xD1,0x1B,0xC6,0x45,0x41,0x3A,0xEF,0xF6, | ||
| 37 | 0x3A,0x42,0x39,0x1A,0x39,0x14,0x5A,0x59, | ||
| 38 | 0x1A,0x92,0x20,0x0D,0x56,0x01,0x95,0xE5, | ||
| 39 | 0x3B,0x47,0x85,0x84,0xFD,0xAE,0x23,0x1A }; | ||
| 40 | |||
| 41 | unsigned char iso_test_3[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 42 | 0x4E,0x24,0x48,0xA4,0xC6,0xF4,0x86,0xBB, | ||
| 43 | 0x16,0xB6,0x56,0x2C,0x73,0xB4,0x02,0x0B, | ||
| 44 | 0xF3,0x04,0x3E,0x3A,0x73,0x1B,0xCE,0x72, | ||
| 45 | 0x1A,0xE1,0xB3,0x03,0xD9,0x7E,0x6D,0x4C, | ||
| 46 | 0x71,0x81,0xEE,0xBD,0xB6,0xC5,0x7E,0x27, | ||
| 47 | 0x7D,0x0E,0x34,0x95,0x71,0x14,0xCB,0xD6, | ||
| 48 | 0xC7,0x97,0xFC,0x9D,0x95,0xD8,0xB5,0x82, | ||
| 49 | 0xD2,0x25,0x29,0x20,0x76,0xD4,0xEE,0xF5 }; | ||
| 50 | |||
| 51 | unsigned char iso_test_4[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 52 | 0x37,0x8C,0x84,0xA4,0x12,0x6E,0x2D,0xC6, | ||
| 53 | 0xE5,0x6D,0xCC,0x74,0x58,0x37,0x7A,0xAC, | ||
| 54 | 0x83,0x8D,0x00,0x03,0x22,0x30,0xF5,0x3C, | ||
| 55 | 0xE1,0xF5,0x70,0x0C,0x0F,0xFB,0x4D,0x3B, | ||
| 56 | 0x84,0x21,0x55,0x76,0x59,0xEF,0x55,0xC1, | ||
| 57 | 0x06,0xB4,0xB5,0x2A,0xC5,0xA4,0xAA,0xA6, | ||
| 58 | 0x92,0xED,0x92,0x00,0x52,0x83,0x8F,0x33, | ||
| 59 | 0x62,0xE8,0x6D,0xBD,0x37,0xA8,0x90,0x3E }; | ||
| 60 | |||
| 61 | unsigned char iso_test_5[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 62 | 0xF1,0xD7,0x54,0x66,0x26,0x36,0xFF,0xE9, | ||
| 63 | 0x2C,0x82,0xEB,0xB9,0x21,0x2A,0x48,0x4A, | ||
| 64 | 0x8D,0x38,0x63,0x1E,0xAD,0x42,0x38,0xF5, | ||
| 65 | 0x44,0x2E,0xE1,0x3B,0x80,0x54,0xE4,0x1B, | ||
| 66 | 0x08,0xBF,0x2A,0x92,0x51,0xC3,0x0B,0x6A, | ||
| 67 | 0x0B,0x8A,0xAE,0x86,0x17,0x7A,0xB4,0xA6, | ||
| 68 | 0xF6,0x8F,0x67,0x3E,0x72,0x07,0x86,0x5D, | ||
| 69 | 0x5D,0x98,0x19,0xA3,0xDB,0xA4,0xEB,0x3B }; | ||
| 70 | |||
| 71 | unsigned char iso_test_6[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 72 | 0xDC,0x37,0xE0,0x08,0xCF,0x9E,0xE6,0x9B, | ||
| 73 | 0xF1,0x1F,0x00,0xED,0x9A,0xBA,0x26,0x90, | ||
| 74 | 0x1D,0xD7,0xC2,0x8C,0xDE,0xC0,0x66,0xCC, | ||
| 75 | 0x6A,0xF4,0x2E,0x40,0xF8,0x2F,0x3A,0x1E, | ||
| 76 | 0x08,0xEB,0xA2,0x66,0x29,0x12,0x9D,0x8F, | ||
| 77 | 0xB7,0xCB,0x57,0x21,0x1B,0x92,0x81,0xA6, | ||
| 78 | 0x55,0x17,0xCC,0x87,0x9D,0x7B,0x96,0x21, | ||
| 79 | 0x42,0xC6,0x5F,0x5A,0x7A,0xF0,0x14,0x67 }; | ||
| 80 | |||
| 81 | unsigned char iso_test_7[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 82 | 0x46,0x6E,0xF1,0x8B,0xAB,0xB0,0x15,0x4D, | ||
| 83 | 0x25,0xB9,0xD3,0x8A,0x64,0x14,0xF5,0xC0, | ||
| 84 | 0x87,0x84,0x37,0x2B,0xCC,0xB2,0x04,0xD6, | ||
| 85 | 0x54,0x9C,0x4A,0xFA,0xDB,0x60,0x14,0x29, | ||
| 86 | 0x4D,0x5B,0xD8,0xDF,0x2A,0x6C,0x44,0xE5, | ||
| 87 | 0x38,0xCD,0x04,0x7B,0x26,0x81,0xA5,0x1A, | ||
| 88 | 0x2C,0x60,0x48,0x1E,0x88,0xC5,0xA2,0x0B, | ||
| 89 | 0x2C,0x2A,0x80,0xCF,0x3A,0x9A,0x08,0x3B }; | ||
| 90 | |||
| 91 | unsigned char iso_test_8[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 92 | 0x2A,0x98,0x7E,0xA4,0x0F,0x91,0x70,0x61, | ||
| 93 | 0xF5,0xD6,0xF0,0xA0,0xE4,0x64,0x4F,0x48, | ||
| 94 | 0x8A,0x7A,0x5A,0x52,0xDE,0xEE,0x65,0x62, | ||
| 95 | 0x07,0xC5,0x62,0xF9,0x88,0xE9,0x5C,0x69, | ||
| 96 | 0x16,0xBD,0xC8,0x03,0x1B,0xC5,0xBE,0x1B, | ||
| 97 | 0x7B,0x94,0x76,0x39,0xFE,0x05,0x0B,0x56, | ||
| 98 | 0x93,0x9B,0xAA,0xA0,0xAD,0xFF,0x9A,0xE6, | ||
| 99 | 0x74,0x5B,0x7B,0x18,0x1C,0x3B,0xE3,0xFD }; | ||
| 100 | |||
| 101 | unsigned char iso_test_9[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 102 | 0x0C,0x99,0x00,0x5B,0xEB,0x57,0xEF,0xF5, | ||
| 103 | 0x0A,0x7C,0xF0,0x05,0x56,0x0D,0xDF,0x5D, | ||
| 104 | 0x29,0x05,0x7F,0xD8,0x6B,0x20,0xBF,0xD6, | ||
| 105 | 0x2D,0xEC,0xA0,0xF1,0xCC,0xEA,0x4A,0xF5, | ||
| 106 | 0x1F,0xC1,0x54,0x90,0xED,0xDC,0x47,0xAF, | ||
| 107 | 0x32,0xBB,0x2B,0x66,0xC3,0x4F,0xF9,0xAD, | ||
| 108 | 0x8C,0x60,0x08,0xAD,0x67,0x7F,0x77,0x12, | ||
| 109 | 0x69,0x53,0xB2,0x26,0xE4,0xED,0x8B,0x01 }; | ||
| 110 | |||
| 111 | int main (int argc,char *argv[]) | ||
| 112 | { unsigned char md[WHIRLPOOL_DIGEST_LENGTH]; | ||
| 113 | int i; | ||
| 114 | WHIRLPOOL_CTX ctx; | ||
| 115 | |||
| 116 | #ifdef OPENSSL_IA32_SSE2 | ||
| 117 | /* Alternative to this is to call OpenSSL_add_all_algorithms... | ||
| 118 | * The below code is retained exclusively for debugging purposes. */ | ||
| 119 | { char *env; | ||
| 120 | |||
| 121 | if ((env=getenv("OPENSSL_ia32cap"))) | ||
| 122 | OPENSSL_ia32cap = strtoul (env,NULL,0); | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | fprintf(stdout,"Testing Whirlpool "); | ||
| 127 | |||
| 128 | WHIRLPOOL("",0,md); | ||
| 129 | if (memcmp(md,iso_test_1,sizeof(iso_test_1))) | ||
| 130 | { fflush(stdout); | ||
| 131 | fprintf(stderr,"\nTEST 1 of 9 failed.\n"); | ||
| 132 | return 1; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | fprintf(stdout,"."); fflush(stdout); | ||
| 136 | |||
| 137 | WHIRLPOOL("a",1,md); | ||
| 138 | if (memcmp(md,iso_test_2,sizeof(iso_test_2))) | ||
| 139 | { fflush(stdout); | ||
| 140 | fprintf(stderr,"\nTEST 2 of 9 failed.\n"); | ||
| 141 | return 1; | ||
| 142 | } | ||
| 143 | else | ||
| 144 | fprintf(stdout,"."); fflush(stdout); | ||
| 145 | |||
| 146 | WHIRLPOOL("abc",3,md); | ||
| 147 | if (memcmp(md,iso_test_3,sizeof(iso_test_3))) | ||
| 148 | { fflush(stdout); | ||
| 149 | fprintf(stderr,"\nTEST 3 of 9 failed.\n"); | ||
| 150 | return 1; | ||
| 151 | } | ||
| 152 | else | ||
| 153 | fprintf(stdout,"."); fflush(stdout); | ||
| 154 | |||
| 155 | WHIRLPOOL("message digest",14,md); | ||
| 156 | if (memcmp(md,iso_test_4,sizeof(iso_test_4))) | ||
| 157 | { fflush(stdout); | ||
| 158 | fprintf(stderr,"\nTEST 4 of 9 failed.\n"); | ||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | fprintf(stdout,"."); fflush(stdout); | ||
| 163 | |||
| 164 | WHIRLPOOL("abcdefghijklmnopqrstuvwxyz",26,md); | ||
| 165 | if (memcmp(md,iso_test_5,sizeof(iso_test_5))) | ||
| 166 | { fflush(stdout); | ||
| 167 | fprintf(stderr,"\nTEST 5 of 9 failed.\n"); | ||
| 168 | return 1; | ||
| 169 | } | ||
| 170 | else | ||
| 171 | fprintf(stdout,"."); fflush(stdout); | ||
| 172 | |||
| 173 | WHIRLPOOL( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
| 174 | "abcdefghijklmnopqrstuvwxyz" | ||
| 175 | "0123456789",62,md); | ||
| 176 | if (memcmp(md,iso_test_6,sizeof(iso_test_6))) | ||
| 177 | { fflush(stdout); | ||
| 178 | fprintf(stderr,"\nTEST 6 of 9 failed.\n"); | ||
| 179 | return 1; | ||
| 180 | } | ||
| 181 | else | ||
| 182 | fprintf(stdout,"."); fflush(stdout); | ||
| 183 | |||
| 184 | WHIRLPOOL( "1234567890""1234567890""1234567890""1234567890" | ||
| 185 | "1234567890""1234567890""1234567890""1234567890",80,md); | ||
| 186 | if (memcmp(md,iso_test_7,sizeof(iso_test_7))) | ||
| 187 | { fflush(stdout); | ||
| 188 | fprintf(stderr,"\nTEST 7 of 9 failed.\n"); | ||
| 189 | return 1; | ||
| 190 | } | ||
| 191 | else | ||
| 192 | fprintf(stdout,"."); fflush(stdout); | ||
| 193 | |||
| 194 | WHIRLPOOL("abcdbcdecdefdefgefghfghighijhijk",32,md); | ||
| 195 | if (memcmp(md,iso_test_8,sizeof(iso_test_8))) | ||
| 196 | { fflush(stdout); | ||
| 197 | fprintf(stderr,"\nTEST 8 of 9 failed.\n"); | ||
| 198 | return 1; | ||
| 199 | } | ||
| 200 | else | ||
| 201 | fprintf(stdout,"."); fflush(stdout); | ||
| 202 | |||
| 203 | WHIRLPOOL_Init (&ctx); | ||
| 204 | for (i=0;i<1000000;i+=288) | ||
| 205 | WHIRLPOOL_Update (&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 206 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 207 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 208 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 209 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 210 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 211 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 212 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 213 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 214 | (1000000-i)<288?1000000-i:288); | ||
| 215 | WHIRLPOOL_Final (md,&ctx); | ||
| 216 | if (memcmp(md,iso_test_9,sizeof(iso_test_9))) | ||
| 217 | { fflush(stdout); | ||
| 218 | fprintf(stderr,"\nTEST 9 of 9 failed.\n"); | ||
| 219 | return 1; | ||
| 220 | } | ||
| 221 | else | ||
| 222 | fprintf(stdout,"."); fflush(stdout); | ||
| 223 | |||
| 224 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 225 | |||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/bn/divtest.c b/src/lib/libssl/src/crypto/bn/divtest.c deleted file mode 100644 index d3fc688f33..0000000000 --- a/src/lib/libssl/src/crypto/bn/divtest.c +++ /dev/null | |||
| @@ -1,41 +0,0 @@ | |||
| 1 | #include <openssl/bn.h> | ||
| 2 | #include <openssl/rand.h> | ||
| 3 | |||
| 4 | static int Rand(n) | ||
| 5 | { | ||
| 6 | unsigned char x[2]; | ||
| 7 | RAND_pseudo_bytes(x,2); | ||
| 8 | return (x[0] + 2*x[1]); | ||
| 9 | } | ||
| 10 | |||
| 11 | static void bug(char *m, BIGNUM *a, BIGNUM *b) | ||
| 12 | { | ||
| 13 | printf("%s!\na=",m); | ||
| 14 | BN_print_fp(stdout, a); | ||
| 15 | printf("\nb="); | ||
| 16 | BN_print_fp(stdout, b); | ||
| 17 | printf("\n"); | ||
| 18 | fflush(stdout); | ||
| 19 | } | ||
| 20 | |||
| 21 | main() | ||
| 22 | { | ||
| 23 | BIGNUM *a=BN_new(), *b=BN_new(), *c=BN_new(), *d=BN_new(), | ||
| 24 | *C=BN_new(), *D=BN_new(); | ||
| 25 | BN_RECP_CTX *recp=BN_RECP_CTX_new(); | ||
| 26 | BN_CTX *ctx=BN_CTX_new(); | ||
| 27 | |||
| 28 | for(;;) { | ||
| 29 | BN_pseudo_rand(a,Rand(),0,0); | ||
| 30 | BN_pseudo_rand(b,Rand(),0,0); | ||
| 31 | if (BN_is_zero(b)) continue; | ||
| 32 | |||
| 33 | BN_RECP_CTX_set(recp,b,ctx); | ||
| 34 | if (BN_div(C,D,a,b,ctx) != 1) | ||
| 35 | bug("BN_div failed",a,b); | ||
| 36 | if (BN_div_recp(c,d,a,recp,ctx) != 1) | ||
| 37 | bug("BN_div_recp failed",a,b); | ||
| 38 | else if (BN_cmp(c,C) != 0 || BN_cmp(c,C) != 0) | ||
| 39 | bug("mismatch",a,b); | ||
| 40 | } | ||
| 41 | } | ||
diff --git a/src/lib/libssl/src/crypto/jpake/jpaketest.c b/src/lib/libssl/src/crypto/jpake/jpaketest.c deleted file mode 100644 index eaba75ed8a..0000000000 --- a/src/lib/libssl/src/crypto/jpake/jpaketest.c +++ /dev/null | |||
| @@ -1,192 +0,0 @@ | |||
| 1 | #include <openssl/opensslconf.h> | ||
| 2 | |||
| 3 | #ifdef OPENSSL_NO_JPAKE | ||
| 4 | |||
| 5 | #include <stdio.h> | ||
| 6 | |||
| 7 | int main(int argc, char *argv[]) | ||
| 8 | { | ||
| 9 | printf("No J-PAKE support\n"); | ||
| 10 | return(0); | ||
| 11 | } | ||
| 12 | |||
| 13 | #else | ||
| 14 | |||
| 15 | #include <openssl/jpake.h> | ||
| 16 | #include <openssl/err.h> | ||
| 17 | |||
| 18 | static void showbn(const char *name, const BIGNUM *bn) | ||
| 19 | { | ||
| 20 | fputs(name, stdout); | ||
| 21 | fputs(" = ", stdout); | ||
| 22 | BN_print_fp(stdout, bn); | ||
| 23 | putc('\n', stdout); | ||
| 24 | } | ||
| 25 | |||
| 26 | static int run_jpake(JPAKE_CTX *alice, JPAKE_CTX *bob) | ||
| 27 | { | ||
| 28 | JPAKE_STEP1 alice_s1; | ||
| 29 | JPAKE_STEP1 bob_s1; | ||
| 30 | JPAKE_STEP2 alice_s2; | ||
| 31 | JPAKE_STEP2 bob_s2; | ||
| 32 | JPAKE_STEP3A alice_s3a; | ||
| 33 | JPAKE_STEP3B bob_s3b; | ||
| 34 | |||
| 35 | /* Alice -> Bob: step 1 */ | ||
| 36 | puts("A->B s1"); | ||
| 37 | JPAKE_STEP1_init(&alice_s1); | ||
| 38 | JPAKE_STEP1_generate(&alice_s1, alice); | ||
| 39 | if(!JPAKE_STEP1_process(bob, &alice_s1)) | ||
| 40 | { | ||
| 41 | printf("Bob fails to process Alice's step 1\n"); | ||
| 42 | ERR_print_errors_fp(stdout); | ||
| 43 | return 1; | ||
| 44 | } | ||
| 45 | JPAKE_STEP1_release(&alice_s1); | ||
| 46 | |||
| 47 | /* Bob -> Alice: step 1 */ | ||
| 48 | puts("B->A s1"); | ||
| 49 | JPAKE_STEP1_init(&bob_s1); | ||
| 50 | JPAKE_STEP1_generate(&bob_s1, bob); | ||
| 51 | if(!JPAKE_STEP1_process(alice, &bob_s1)) | ||
| 52 | { | ||
| 53 | printf("Alice fails to process Bob's step 1\n"); | ||
| 54 | ERR_print_errors_fp(stdout); | ||
| 55 | return 2; | ||
| 56 | } | ||
| 57 | JPAKE_STEP1_release(&bob_s1); | ||
| 58 | |||
| 59 | /* Alice -> Bob: step 2 */ | ||
| 60 | puts("A->B s2"); | ||
| 61 | JPAKE_STEP2_init(&alice_s2); | ||
| 62 | JPAKE_STEP2_generate(&alice_s2, alice); | ||
| 63 | if(!JPAKE_STEP2_process(bob, &alice_s2)) | ||
| 64 | { | ||
| 65 | printf("Bob fails to process Alice's step 2\n"); | ||
| 66 | ERR_print_errors_fp(stdout); | ||
| 67 | return 3; | ||
| 68 | } | ||
| 69 | JPAKE_STEP2_release(&alice_s2); | ||
| 70 | |||
| 71 | /* Bob -> Alice: step 2 */ | ||
| 72 | puts("B->A s2"); | ||
| 73 | JPAKE_STEP2_init(&bob_s2); | ||
| 74 | JPAKE_STEP2_generate(&bob_s2, bob); | ||
| 75 | if(!JPAKE_STEP2_process(alice, &bob_s2)) | ||
| 76 | { | ||
| 77 | printf("Alice fails to process Bob's step 2\n"); | ||
| 78 | ERR_print_errors_fp(stdout); | ||
| 79 | return 4; | ||
| 80 | } | ||
| 81 | JPAKE_STEP2_release(&bob_s2); | ||
| 82 | |||
| 83 | showbn("Alice's key", JPAKE_get_shared_key(alice)); | ||
| 84 | showbn("Bob's key ", JPAKE_get_shared_key(bob)); | ||
| 85 | |||
| 86 | /* Alice -> Bob: step 3a */ | ||
| 87 | puts("A->B s3a"); | ||
| 88 | JPAKE_STEP3A_init(&alice_s3a); | ||
| 89 | JPAKE_STEP3A_generate(&alice_s3a, alice); | ||
| 90 | if(!JPAKE_STEP3A_process(bob, &alice_s3a)) | ||
| 91 | { | ||
| 92 | printf("Bob fails to process Alice's step 3a\n"); | ||
| 93 | ERR_print_errors_fp(stdout); | ||
| 94 | return 5; | ||
| 95 | } | ||
| 96 | JPAKE_STEP3A_release(&alice_s3a); | ||
| 97 | |||
| 98 | /* Bob -> Alice: step 3b */ | ||
| 99 | puts("B->A s3b"); | ||
| 100 | JPAKE_STEP3B_init(&bob_s3b); | ||
| 101 | JPAKE_STEP3B_generate(&bob_s3b, bob); | ||
| 102 | if(!JPAKE_STEP3B_process(alice, &bob_s3b)) | ||
| 103 | { | ||
| 104 | printf("Alice fails to process Bob's step 3b\n"); | ||
| 105 | ERR_print_errors_fp(stdout); | ||
| 106 | return 6; | ||
| 107 | } | ||
| 108 | JPAKE_STEP3B_release(&bob_s3b); | ||
| 109 | |||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | |||
| 113 | int main(int argc, char **argv) | ||
| 114 | { | ||
| 115 | JPAKE_CTX *alice; | ||
| 116 | JPAKE_CTX *bob; | ||
| 117 | BIGNUM *p = NULL; | ||
| 118 | BIGNUM *g = NULL; | ||
| 119 | BIGNUM *q = NULL; | ||
| 120 | BIGNUM *secret = BN_new(); | ||
| 121 | BIO *bio_err; | ||
| 122 | |||
| 123 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); | ||
| 124 | |||
| 125 | CRYPTO_malloc_debug_init(); | ||
| 126 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 127 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 128 | |||
| 129 | ERR_load_crypto_strings(); | ||
| 130 | |||
| 131 | /* | ||
| 132 | BN_hex2bn(&p, "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7"); | ||
| 133 | BN_hex2bn(&g, "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a"); | ||
| 134 | BN_hex2bn(&q, "9760508f15230bccb292b982a2eb840bf0581cf5"); | ||
| 135 | */ | ||
| 136 | /* | ||
| 137 | p = BN_new(); | ||
| 138 | BN_generate_prime(p, 1024, 1, NULL, NULL, NULL, NULL); | ||
| 139 | */ | ||
| 140 | /* Use a safe prime for p (that we found earlier) */ | ||
| 141 | BN_hex2bn(&p, "F9E5B365665EA7A05A9C534502780FEE6F1AB5BD4F49947FD036DBD7E905269AF46EF28B0FC07487EE4F5D20FB3C0AF8E700F3A2FA3414970CBED44FEDFF80CE78D800F184BB82435D137AADA2C6C16523247930A63B85661D1FC817A51ACD96168E95898A1F83A79FFB529368AA7833ABD1B0C3AEDDB14D2E1A2F71D99F763F"); | ||
| 142 | showbn("p", p); | ||
| 143 | g = BN_new(); | ||
| 144 | BN_set_word(g, 2); | ||
| 145 | showbn("g", g); | ||
| 146 | q = BN_new(); | ||
| 147 | BN_rshift1(q, p); | ||
| 148 | showbn("q", q); | ||
| 149 | |||
| 150 | BN_rand(secret, 32, -1, 0); | ||
| 151 | |||
| 152 | /* A normal run, expect this to work... */ | ||
| 153 | alice = JPAKE_CTX_new("Alice", "Bob", p, g, q, secret); | ||
| 154 | bob = JPAKE_CTX_new("Bob", "Alice", p, g, q, secret); | ||
| 155 | |||
| 156 | if(run_jpake(alice, bob) != 0) | ||
| 157 | { | ||
| 158 | fprintf(stderr, "Plain JPAKE run failed\n"); | ||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | |||
| 162 | JPAKE_CTX_free(bob); | ||
| 163 | JPAKE_CTX_free(alice); | ||
| 164 | |||
| 165 | /* Now give Alice and Bob different secrets */ | ||
| 166 | alice = JPAKE_CTX_new("Alice", "Bob", p, g, q, secret); | ||
| 167 | BN_add_word(secret, 1); | ||
| 168 | bob = JPAKE_CTX_new("Bob", "Alice", p, g, q, secret); | ||
| 169 | |||
| 170 | if(run_jpake(alice, bob) != 5) | ||
| 171 | { | ||
| 172 | fprintf(stderr, "Mismatched secret JPAKE run failed\n"); | ||
| 173 | return 1; | ||
| 174 | } | ||
| 175 | |||
| 176 | JPAKE_CTX_free(bob); | ||
| 177 | JPAKE_CTX_free(alice); | ||
| 178 | |||
| 179 | BN_free(secret); | ||
| 180 | BN_free(q); | ||
| 181 | BN_free(g); | ||
| 182 | BN_free(p); | ||
| 183 | |||
| 184 | CRYPTO_cleanup_all_ex_data(); | ||
| 185 | ERR_remove_thread_state(NULL); | ||
| 186 | ERR_free_strings(); | ||
| 187 | CRYPTO_mem_leaks(bio_err); | ||
| 188 | |||
| 189 | return 0; | ||
| 190 | } | ||
| 191 | |||
| 192 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/rsa/rsa_test.c b/src/lib/libssl/src/crypto/rsa/rsa_test.c deleted file mode 100644 index c8705a0f6e..0000000000 --- a/src/lib/libssl/src/crypto/rsa/rsa_test.c +++ /dev/null | |||
| @@ -1,340 +0,0 @@ | |||
| 1 | /* test vectors from p1ovect1.txt */ | ||
| 2 | |||
| 3 | #include <stdio.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | #include "e_os.h" | ||
| 7 | |||
| 8 | #include <openssl/crypto.h> | ||
| 9 | #include <openssl/err.h> | ||
| 10 | #include <openssl/rand.h> | ||
| 11 | #include <openssl/bn.h> | ||
| 12 | #ifdef OPENSSL_NO_RSA | ||
| 13 | int main(int argc, char *argv[]) | ||
| 14 | { | ||
| 15 | printf("No RSA support\n"); | ||
| 16 | return(0); | ||
| 17 | } | ||
| 18 | #else | ||
| 19 | #include <openssl/rsa.h> | ||
| 20 | |||
| 21 | #define SetKey \ | ||
| 22 | key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \ | ||
| 23 | key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \ | ||
| 24 | key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \ | ||
| 25 | key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \ | ||
| 26 | key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \ | ||
| 27 | key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \ | ||
| 28 | key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \ | ||
| 29 | key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \ | ||
| 30 | memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \ | ||
| 31 | return (sizeof(ctext_ex) - 1); | ||
| 32 | |||
| 33 | static int key1(RSA *key, unsigned char *c) | ||
| 34 | { | ||
| 35 | static unsigned char n[] = | ||
| 36 | "\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F" | ||
| 37 | "\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5" | ||
| 38 | "\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93" | ||
| 39 | "\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1" | ||
| 40 | "\xF5"; | ||
| 41 | |||
| 42 | static unsigned char e[] = "\x11"; | ||
| 43 | |||
| 44 | static unsigned char d[] = | ||
| 45 | "\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44" | ||
| 46 | "\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64" | ||
| 47 | "\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9" | ||
| 48 | "\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51"; | ||
| 49 | |||
| 50 | static unsigned char p[] = | ||
| 51 | "\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
| 52 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12" | ||
| 53 | "\x0D"; | ||
| 54 | |||
| 55 | static unsigned char q[] = | ||
| 56 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 57 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
| 58 | "\x89"; | ||
| 59 | |||
| 60 | static unsigned char dmp1[] = | ||
| 61 | "\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF" | ||
| 62 | "\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05"; | ||
| 63 | |||
| 64 | static unsigned char dmq1[] = | ||
| 65 | "\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99" | ||
| 66 | "\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D" | ||
| 67 | "\x51"; | ||
| 68 | |||
| 69 | static unsigned char iqmp[] = | ||
| 70 | "\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8" | ||
| 71 | "\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26"; | ||
| 72 | |||
| 73 | static unsigned char ctext_ex[] = | ||
| 74 | "\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89" | ||
| 75 | "\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52" | ||
| 76 | "\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44" | ||
| 77 | "\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2"; | ||
| 78 | |||
| 79 | SetKey; | ||
| 80 | } | ||
| 81 | |||
| 82 | static int key2(RSA *key, unsigned char *c) | ||
| 83 | { | ||
| 84 | static unsigned char n[] = | ||
| 85 | "\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8" | ||
| 86 | "\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26" | ||
| 87 | "\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8" | ||
| 88 | "\x34\x77\xCF"; | ||
| 89 | |||
| 90 | static unsigned char e[] = "\x3"; | ||
| 91 | |||
| 92 | static unsigned char d[] = | ||
| 93 | "\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2" | ||
| 94 | "\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41" | ||
| 95 | "\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21" | ||
| 96 | "\xE5\xEB"; | ||
| 97 | |||
| 98 | static unsigned char p[] = | ||
| 99 | "\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92" | ||
| 100 | "\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91"; | ||
| 101 | |||
| 102 | static unsigned char q[] = | ||
| 103 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 104 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F"; | ||
| 105 | |||
| 106 | static unsigned char dmp1[] = | ||
| 107 | "\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61" | ||
| 108 | "\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B"; | ||
| 109 | |||
| 110 | static unsigned char dmq1[] = | ||
| 111 | "\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90" | ||
| 112 | "\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F"; | ||
| 113 | |||
| 114 | static unsigned char iqmp[] = | ||
| 115 | "\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13" | ||
| 116 | "\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D"; | ||
| 117 | |||
| 118 | static unsigned char ctext_ex[] = | ||
| 119 | "\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a" | ||
| 120 | "\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4" | ||
| 121 | "\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52" | ||
| 122 | "\x62\x51"; | ||
| 123 | |||
| 124 | SetKey; | ||
| 125 | } | ||
| 126 | |||
| 127 | static int key3(RSA *key, unsigned char *c) | ||
| 128 | { | ||
| 129 | static unsigned char n[] = | ||
| 130 | "\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71" | ||
| 131 | "\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5" | ||
| 132 | "\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD" | ||
| 133 | "\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80" | ||
| 134 | "\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25" | ||
| 135 | "\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39" | ||
| 136 | "\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68" | ||
| 137 | "\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD" | ||
| 138 | "\xCB"; | ||
| 139 | |||
| 140 | static unsigned char e[] = "\x11"; | ||
| 141 | |||
| 142 | static unsigned char d[] = | ||
| 143 | "\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD" | ||
| 144 | "\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41" | ||
| 145 | "\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69" | ||
| 146 | "\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA" | ||
| 147 | "\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94" | ||
| 148 | "\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A" | ||
| 149 | "\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94" | ||
| 150 | "\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3" | ||
| 151 | "\xC1"; | ||
| 152 | |||
| 153 | static unsigned char p[] = | ||
| 154 | "\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60" | ||
| 155 | "\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6" | ||
| 156 | "\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A" | ||
| 157 | "\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65" | ||
| 158 | "\x99"; | ||
| 159 | |||
| 160 | static unsigned char q[] = | ||
| 161 | "\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9" | ||
| 162 | "\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D" | ||
| 163 | "\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5" | ||
| 164 | "\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15" | ||
| 165 | "\x03"; | ||
| 166 | |||
| 167 | static unsigned char dmp1[] = | ||
| 168 | "\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A" | ||
| 169 | "\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E" | ||
| 170 | "\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E" | ||
| 171 | "\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81"; | ||
| 172 | |||
| 173 | static unsigned char dmq1[] = | ||
| 174 | "\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9" | ||
| 175 | "\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7" | ||
| 176 | "\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D" | ||
| 177 | "\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D"; | ||
| 178 | |||
| 179 | static unsigned char iqmp[] = | ||
| 180 | "\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23" | ||
| 181 | "\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11" | ||
| 182 | "\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E" | ||
| 183 | "\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39" | ||
| 184 | "\xF7"; | ||
| 185 | |||
| 186 | static unsigned char ctext_ex[] = | ||
| 187 | "\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7" | ||
| 188 | "\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce" | ||
| 189 | "\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3" | ||
| 190 | "\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06" | ||
| 191 | "\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86" | ||
| 192 | "\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4" | ||
| 193 | "\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a" | ||
| 194 | "\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1"; | ||
| 195 | |||
| 196 | SetKey; | ||
| 197 | } | ||
| 198 | |||
| 199 | static int pad_unknown(void) | ||
| 200 | { | ||
| 201 | unsigned long l; | ||
| 202 | while ((l = ERR_get_error()) != 0) | ||
| 203 | if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE) | ||
| 204 | return(1); | ||
| 205 | return(0); | ||
| 206 | } | ||
| 207 | |||
| 208 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; | ||
| 209 | |||
| 210 | int main(int argc, char *argv[]) | ||
| 211 | { | ||
| 212 | int err=0; | ||
| 213 | int v; | ||
| 214 | RSA *key; | ||
| 215 | unsigned char ptext[256]; | ||
| 216 | unsigned char ctext[256]; | ||
| 217 | static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a"; | ||
| 218 | unsigned char ctext_ex[256]; | ||
| 219 | int plen; | ||
| 220 | int clen = 0; | ||
| 221 | int num; | ||
| 222 | int n; | ||
| 223 | |||
| 224 | CRYPTO_malloc_debug_init(); | ||
| 225 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 226 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 227 | |||
| 228 | RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */ | ||
| 229 | |||
| 230 | plen = sizeof(ptext_ex) - 1; | ||
| 231 | |||
| 232 | for (v = 0; v < 6; v++) | ||
| 233 | { | ||
| 234 | key = RSA_new(); | ||
| 235 | switch (v%3) { | ||
| 236 | case 0: | ||
| 237 | clen = key1(key, ctext_ex); | ||
| 238 | break; | ||
| 239 | case 1: | ||
| 240 | clen = key2(key, ctext_ex); | ||
| 241 | break; | ||
| 242 | case 2: | ||
| 243 | clen = key3(key, ctext_ex); | ||
| 244 | break; | ||
| 245 | } | ||
| 246 | if (v/3 >= 1) key->flags |= RSA_FLAG_NO_CONSTTIME; | ||
| 247 | |||
| 248 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
| 249 | RSA_PKCS1_PADDING); | ||
| 250 | if (num != clen) | ||
| 251 | { | ||
| 252 | printf("PKCS#1 v1.5 encryption failed!\n"); | ||
| 253 | err=1; | ||
| 254 | goto oaep; | ||
| 255 | } | ||
| 256 | |||
| 257 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
| 258 | RSA_PKCS1_PADDING); | ||
| 259 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
| 260 | { | ||
| 261 | printf("PKCS#1 v1.5 decryption failed!\n"); | ||
| 262 | err=1; | ||
| 263 | } | ||
| 264 | else | ||
| 265 | printf("PKCS #1 v1.5 encryption/decryption ok\n"); | ||
| 266 | |||
| 267 | oaep: | ||
| 268 | ERR_clear_error(); | ||
| 269 | num = RSA_public_encrypt(plen, ptext_ex, ctext, key, | ||
| 270 | RSA_PKCS1_OAEP_PADDING); | ||
| 271 | if (num == -1 && pad_unknown()) | ||
| 272 | { | ||
| 273 | printf("No OAEP support\n"); | ||
| 274 | goto next; | ||
| 275 | } | ||
| 276 | if (num != clen) | ||
| 277 | { | ||
| 278 | printf("OAEP encryption failed!\n"); | ||
| 279 | err=1; | ||
| 280 | goto next; | ||
| 281 | } | ||
| 282 | |||
| 283 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
| 284 | RSA_PKCS1_OAEP_PADDING); | ||
| 285 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
| 286 | { | ||
| 287 | printf("OAEP decryption (encrypted data) failed!\n"); | ||
| 288 | err=1; | ||
| 289 | } | ||
| 290 | else if (memcmp(ctext, ctext_ex, num) == 0) | ||
| 291 | printf("OAEP test vector %d passed!\n", v); | ||
| 292 | |||
| 293 | /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT). | ||
| 294 | Try decrypting ctext_ex */ | ||
| 295 | |||
| 296 | num = RSA_private_decrypt(clen, ctext_ex, ptext, key, | ||
| 297 | RSA_PKCS1_OAEP_PADDING); | ||
| 298 | |||
| 299 | if (num != plen || memcmp(ptext, ptext_ex, num) != 0) | ||
| 300 | { | ||
| 301 | printf("OAEP decryption (test vector data) failed!\n"); | ||
| 302 | err=1; | ||
| 303 | } | ||
| 304 | else | ||
| 305 | printf("OAEP encryption/decryption ok\n"); | ||
| 306 | |||
| 307 | /* Try decrypting corrupted ciphertexts */ | ||
| 308 | for(n = 0 ; n < clen ; ++n) | ||
| 309 | { | ||
| 310 | int b; | ||
| 311 | unsigned char saved = ctext[n]; | ||
| 312 | for(b = 0 ; b < 256 ; ++b) | ||
| 313 | { | ||
| 314 | if(b == saved) | ||
| 315 | continue; | ||
| 316 | ctext[n] = b; | ||
| 317 | num = RSA_private_decrypt(num, ctext, ptext, key, | ||
| 318 | RSA_PKCS1_OAEP_PADDING); | ||
| 319 | if(num > 0) | ||
| 320 | { | ||
| 321 | printf("Corrupt data decrypted!\n"); | ||
| 322 | err = 1; | ||
| 323 | } | ||
| 324 | } | ||
| 325 | } | ||
| 326 | next: | ||
| 327 | RSA_free(key); | ||
| 328 | } | ||
| 329 | |||
| 330 | CRYPTO_cleanup_all_ex_data(); | ||
| 331 | ERR_remove_thread_state(NULL); | ||
| 332 | |||
| 333 | CRYPTO_mem_leaks_fp(stderr); | ||
| 334 | |||
| 335 | #ifdef OPENSSL_SYS_NETWARE | ||
| 336 | if (err) printf("ERROR: %d\n", err); | ||
| 337 | #endif | ||
| 338 | return err; | ||
| 339 | } | ||
| 340 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/srp/srptest.c b/src/lib/libssl/src/crypto/srp/srptest.c deleted file mode 100644 index 04b66b4544..0000000000 --- a/src/lib/libssl/src/crypto/srp/srptest.c +++ /dev/null | |||
| @@ -1,162 +0,0 @@ | |||
| 1 | #include <openssl/opensslconf.h> | ||
| 2 | #ifdef OPENSSL_NO_SRP | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | int main(int argc, char *argv[]) | ||
| 7 | { | ||
| 8 | printf("No SRP support\n"); | ||
| 9 | return(0); | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include <openssl/srp.h> | ||
| 15 | #include <openssl/rand.h> | ||
| 16 | #include <openssl/err.h> | ||
| 17 | |||
| 18 | static void showbn(const char *name, const BIGNUM *bn) | ||
| 19 | { | ||
| 20 | fputs(name, stdout); | ||
| 21 | fputs(" = ", stdout); | ||
| 22 | BN_print_fp(stdout, bn); | ||
| 23 | putc('\n', stdout); | ||
| 24 | } | ||
| 25 | |||
| 26 | #define RANDOM_SIZE 32 /* use 256 bits on each side */ | ||
| 27 | |||
| 28 | static int run_srp(const char *username, const char *client_pass, const char *server_pass) | ||
| 29 | { | ||
| 30 | int ret=-1; | ||
| 31 | BIGNUM *s = NULL; | ||
| 32 | BIGNUM *v = NULL; | ||
| 33 | BIGNUM *a = NULL; | ||
| 34 | BIGNUM *b = NULL; | ||
| 35 | BIGNUM *u = NULL; | ||
| 36 | BIGNUM *x = NULL; | ||
| 37 | BIGNUM *Apub = NULL; | ||
| 38 | BIGNUM *Bpub = NULL; | ||
| 39 | BIGNUM *Kclient = NULL; | ||
| 40 | BIGNUM *Kserver = NULL; | ||
| 41 | unsigned char rand_tmp[RANDOM_SIZE]; | ||
| 42 | /* use builtin 1024-bit params */ | ||
| 43 | SRP_gN *GN = SRP_get_default_gN("1024"); | ||
| 44 | |||
| 45 | if(GN == NULL) | ||
| 46 | { | ||
| 47 | fprintf(stderr, "Failed to get SRP parameters\n"); | ||
| 48 | return -1; | ||
| 49 | } | ||
| 50 | /* Set up server's password entry */ | ||
| 51 | if(!SRP_create_verifier_BN(username, server_pass, &s, &v, GN->N, GN->g)) | ||
| 52 | { | ||
| 53 | fprintf(stderr, "Failed to create SRP verifier\n"); | ||
| 54 | return -1; | ||
| 55 | } | ||
| 56 | |||
| 57 | showbn("N", GN->N); | ||
| 58 | showbn("g", GN->g); | ||
| 59 | showbn("Salt", s); | ||
| 60 | showbn("Verifier", v); | ||
| 61 | |||
| 62 | /* Server random */ | ||
| 63 | RAND_pseudo_bytes(rand_tmp, sizeof(rand_tmp)); | ||
| 64 | b = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL); | ||
| 65 | /* TODO - check b != 0 */ | ||
| 66 | showbn("b", b); | ||
| 67 | |||
| 68 | /* Server's first message */ | ||
| 69 | Bpub = SRP_Calc_B(b, GN->N, GN->g, v); | ||
| 70 | showbn("B", Bpub); | ||
| 71 | |||
| 72 | if(!SRP_Verify_B_mod_N(Bpub, GN->N)) | ||
| 73 | { | ||
| 74 | fprintf(stderr, "Invalid B\n"); | ||
| 75 | return -1; | ||
| 76 | } | ||
| 77 | |||
| 78 | /* Client random */ | ||
| 79 | RAND_pseudo_bytes(rand_tmp, sizeof(rand_tmp)); | ||
| 80 | a = BN_bin2bn(rand_tmp, sizeof(rand_tmp), NULL); | ||
| 81 | /* TODO - check a != 0 */ | ||
| 82 | showbn("a", a); | ||
| 83 | |||
| 84 | /* Client's response */ | ||
| 85 | Apub = SRP_Calc_A(a, GN->N, GN->g); | ||
| 86 | showbn("A", Apub); | ||
| 87 | |||
| 88 | if(!SRP_Verify_A_mod_N(Apub, GN->N)) | ||
| 89 | { | ||
| 90 | fprintf(stderr, "Invalid A\n"); | ||
| 91 | return -1; | ||
| 92 | } | ||
| 93 | |||
| 94 | /* Both sides calculate u */ | ||
| 95 | u = SRP_Calc_u(Apub, Bpub, GN->N); | ||
| 96 | |||
| 97 | /* Client's key */ | ||
| 98 | x = SRP_Calc_x(s, username, client_pass); | ||
| 99 | Kclient = SRP_Calc_client_key(GN->N, Bpub, GN->g, x, a, u); | ||
| 100 | showbn("Client's key", Kclient); | ||
| 101 | |||
| 102 | /* Server's key */ | ||
| 103 | Kserver = SRP_Calc_server_key(Apub, v, u, b, GN->N); | ||
| 104 | showbn("Server's key", Kserver); | ||
| 105 | |||
| 106 | if(BN_cmp(Kclient, Kserver) == 0) | ||
| 107 | { | ||
| 108 | ret = 0; | ||
| 109 | } | ||
| 110 | else | ||
| 111 | { | ||
| 112 | fprintf(stderr, "Keys mismatch\n"); | ||
| 113 | ret = 1; | ||
| 114 | } | ||
| 115 | |||
| 116 | BN_clear_free(Kclient); | ||
| 117 | BN_clear_free(Kserver); | ||
| 118 | BN_clear_free(x); | ||
| 119 | BN_free(u); | ||
| 120 | BN_free(Apub); | ||
| 121 | BN_clear_free(a); | ||
| 122 | BN_free(Bpub); | ||
| 123 | BN_clear_free(b); | ||
| 124 | BN_free(s); | ||
| 125 | BN_clear_free(v); | ||
| 126 | |||
| 127 | return ret; | ||
| 128 | } | ||
| 129 | |||
| 130 | int main(int argc, char **argv) | ||
| 131 | { | ||
| 132 | BIO *bio_err; | ||
| 133 | bio_err = BIO_new_fp(stderr, BIO_NOCLOSE); | ||
| 134 | |||
| 135 | CRYPTO_malloc_debug_init(); | ||
| 136 | CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); | ||
| 137 | CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); | ||
| 138 | |||
| 139 | ERR_load_crypto_strings(); | ||
| 140 | |||
| 141 | /* "Negative" test, expect a mismatch */ | ||
| 142 | if(run_srp("alice", "password1", "password2") == 0) | ||
| 143 | { | ||
| 144 | fprintf(stderr, "Mismatched SRP run failed\n"); | ||
| 145 | return 1; | ||
| 146 | } | ||
| 147 | |||
| 148 | /* "Positive" test, should pass */ | ||
| 149 | if(run_srp("alice", "password", "password") != 0) | ||
| 150 | { | ||
| 151 | fprintf(stderr, "Plain SRP run failed\n"); | ||
| 152 | return 1; | ||
| 153 | } | ||
| 154 | |||
| 155 | CRYPTO_cleanup_all_ex_data(); | ||
| 156 | ERR_remove_thread_state(NULL); | ||
| 157 | ERR_free_strings(); | ||
| 158 | CRYPTO_mem_leaks(bio_err); | ||
| 159 | |||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | #endif | ||
diff --git a/src/lib/libssl/src/crypto/whrlpool/wp_test.c b/src/lib/libssl/src/crypto/whrlpool/wp_test.c deleted file mode 100644 index c68c2c62ca..0000000000 --- a/src/lib/libssl/src/crypto/whrlpool/wp_test.c +++ /dev/null | |||
| @@ -1,228 +0,0 @@ | |||
| 1 | /* ==================================================================== | ||
| 2 | * Copyright (c) 2005 The OpenSSL Project. All rights reserved. | ||
| 3 | * ==================================================================== | ||
| 4 | */ | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | |||
| 9 | #include <openssl/whrlpool.h> | ||
| 10 | #include <openssl/crypto.h> | ||
| 11 | |||
| 12 | #if defined(OPENSSL_NO_WHIRLPOOL) | ||
| 13 | int main(int argc, char *argv[]) | ||
| 14 | { | ||
| 15 | printf("No Whirlpool support\n"); | ||
| 16 | return(0); | ||
| 17 | } | ||
| 18 | #else | ||
| 19 | |||
| 20 | /* ISO/IEC 10118-3 test vector set */ | ||
| 21 | unsigned char iso_test_1[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 22 | 0x19,0xFA,0x61,0xD7,0x55,0x22,0xA4,0x66, | ||
| 23 | 0x9B,0x44,0xE3,0x9C,0x1D,0x2E,0x17,0x26, | ||
| 24 | 0xC5,0x30,0x23,0x21,0x30,0xD4,0x07,0xF8, | ||
| 25 | 0x9A,0xFE,0xE0,0x96,0x49,0x97,0xF7,0xA7, | ||
| 26 | 0x3E,0x83,0xBE,0x69,0x8B,0x28,0x8F,0xEB, | ||
| 27 | 0xCF,0x88,0xE3,0xE0,0x3C,0x4F,0x07,0x57, | ||
| 28 | 0xEA,0x89,0x64,0xE5,0x9B,0x63,0xD9,0x37, | ||
| 29 | 0x08,0xB1,0x38,0xCC,0x42,0xA6,0x6E,0xB3 }; | ||
| 30 | |||
| 31 | unsigned char iso_test_2[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 32 | 0x8A,0xCA,0x26,0x02,0x79,0x2A,0xEC,0x6F, | ||
| 33 | 0x11,0xA6,0x72,0x06,0x53,0x1F,0xB7,0xD7, | ||
| 34 | 0xF0,0xDF,0xF5,0x94,0x13,0x14,0x5E,0x69, | ||
| 35 | 0x73,0xC4,0x50,0x01,0xD0,0x08,0x7B,0x42, | ||
| 36 | 0xD1,0x1B,0xC6,0x45,0x41,0x3A,0xEF,0xF6, | ||
| 37 | 0x3A,0x42,0x39,0x1A,0x39,0x14,0x5A,0x59, | ||
| 38 | 0x1A,0x92,0x20,0x0D,0x56,0x01,0x95,0xE5, | ||
| 39 | 0x3B,0x47,0x85,0x84,0xFD,0xAE,0x23,0x1A }; | ||
| 40 | |||
| 41 | unsigned char iso_test_3[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 42 | 0x4E,0x24,0x48,0xA4,0xC6,0xF4,0x86,0xBB, | ||
| 43 | 0x16,0xB6,0x56,0x2C,0x73,0xB4,0x02,0x0B, | ||
| 44 | 0xF3,0x04,0x3E,0x3A,0x73,0x1B,0xCE,0x72, | ||
| 45 | 0x1A,0xE1,0xB3,0x03,0xD9,0x7E,0x6D,0x4C, | ||
| 46 | 0x71,0x81,0xEE,0xBD,0xB6,0xC5,0x7E,0x27, | ||
| 47 | 0x7D,0x0E,0x34,0x95,0x71,0x14,0xCB,0xD6, | ||
| 48 | 0xC7,0x97,0xFC,0x9D,0x95,0xD8,0xB5,0x82, | ||
| 49 | 0xD2,0x25,0x29,0x20,0x76,0xD4,0xEE,0xF5 }; | ||
| 50 | |||
| 51 | unsigned char iso_test_4[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 52 | 0x37,0x8C,0x84,0xA4,0x12,0x6E,0x2D,0xC6, | ||
| 53 | 0xE5,0x6D,0xCC,0x74,0x58,0x37,0x7A,0xAC, | ||
| 54 | 0x83,0x8D,0x00,0x03,0x22,0x30,0xF5,0x3C, | ||
| 55 | 0xE1,0xF5,0x70,0x0C,0x0F,0xFB,0x4D,0x3B, | ||
| 56 | 0x84,0x21,0x55,0x76,0x59,0xEF,0x55,0xC1, | ||
| 57 | 0x06,0xB4,0xB5,0x2A,0xC5,0xA4,0xAA,0xA6, | ||
| 58 | 0x92,0xED,0x92,0x00,0x52,0x83,0x8F,0x33, | ||
| 59 | 0x62,0xE8,0x6D,0xBD,0x37,0xA8,0x90,0x3E }; | ||
| 60 | |||
| 61 | unsigned char iso_test_5[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 62 | 0xF1,0xD7,0x54,0x66,0x26,0x36,0xFF,0xE9, | ||
| 63 | 0x2C,0x82,0xEB,0xB9,0x21,0x2A,0x48,0x4A, | ||
| 64 | 0x8D,0x38,0x63,0x1E,0xAD,0x42,0x38,0xF5, | ||
| 65 | 0x44,0x2E,0xE1,0x3B,0x80,0x54,0xE4,0x1B, | ||
| 66 | 0x08,0xBF,0x2A,0x92,0x51,0xC3,0x0B,0x6A, | ||
| 67 | 0x0B,0x8A,0xAE,0x86,0x17,0x7A,0xB4,0xA6, | ||
| 68 | 0xF6,0x8F,0x67,0x3E,0x72,0x07,0x86,0x5D, | ||
| 69 | 0x5D,0x98,0x19,0xA3,0xDB,0xA4,0xEB,0x3B }; | ||
| 70 | |||
| 71 | unsigned char iso_test_6[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 72 | 0xDC,0x37,0xE0,0x08,0xCF,0x9E,0xE6,0x9B, | ||
| 73 | 0xF1,0x1F,0x00,0xED,0x9A,0xBA,0x26,0x90, | ||
| 74 | 0x1D,0xD7,0xC2,0x8C,0xDE,0xC0,0x66,0xCC, | ||
| 75 | 0x6A,0xF4,0x2E,0x40,0xF8,0x2F,0x3A,0x1E, | ||
| 76 | 0x08,0xEB,0xA2,0x66,0x29,0x12,0x9D,0x8F, | ||
| 77 | 0xB7,0xCB,0x57,0x21,0x1B,0x92,0x81,0xA6, | ||
| 78 | 0x55,0x17,0xCC,0x87,0x9D,0x7B,0x96,0x21, | ||
| 79 | 0x42,0xC6,0x5F,0x5A,0x7A,0xF0,0x14,0x67 }; | ||
| 80 | |||
| 81 | unsigned char iso_test_7[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 82 | 0x46,0x6E,0xF1,0x8B,0xAB,0xB0,0x15,0x4D, | ||
| 83 | 0x25,0xB9,0xD3,0x8A,0x64,0x14,0xF5,0xC0, | ||
| 84 | 0x87,0x84,0x37,0x2B,0xCC,0xB2,0x04,0xD6, | ||
| 85 | 0x54,0x9C,0x4A,0xFA,0xDB,0x60,0x14,0x29, | ||
| 86 | 0x4D,0x5B,0xD8,0xDF,0x2A,0x6C,0x44,0xE5, | ||
| 87 | 0x38,0xCD,0x04,0x7B,0x26,0x81,0xA5,0x1A, | ||
| 88 | 0x2C,0x60,0x48,0x1E,0x88,0xC5,0xA2,0x0B, | ||
| 89 | 0x2C,0x2A,0x80,0xCF,0x3A,0x9A,0x08,0x3B }; | ||
| 90 | |||
| 91 | unsigned char iso_test_8[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 92 | 0x2A,0x98,0x7E,0xA4,0x0F,0x91,0x70,0x61, | ||
| 93 | 0xF5,0xD6,0xF0,0xA0,0xE4,0x64,0x4F,0x48, | ||
| 94 | 0x8A,0x7A,0x5A,0x52,0xDE,0xEE,0x65,0x62, | ||
| 95 | 0x07,0xC5,0x62,0xF9,0x88,0xE9,0x5C,0x69, | ||
| 96 | 0x16,0xBD,0xC8,0x03,0x1B,0xC5,0xBE,0x1B, | ||
| 97 | 0x7B,0x94,0x76,0x39,0xFE,0x05,0x0B,0x56, | ||
| 98 | 0x93,0x9B,0xAA,0xA0,0xAD,0xFF,0x9A,0xE6, | ||
| 99 | 0x74,0x5B,0x7B,0x18,0x1C,0x3B,0xE3,0xFD }; | ||
| 100 | |||
| 101 | unsigned char iso_test_9[WHIRLPOOL_DIGEST_LENGTH] = { | ||
| 102 | 0x0C,0x99,0x00,0x5B,0xEB,0x57,0xEF,0xF5, | ||
| 103 | 0x0A,0x7C,0xF0,0x05,0x56,0x0D,0xDF,0x5D, | ||
| 104 | 0x29,0x05,0x7F,0xD8,0x6B,0x20,0xBF,0xD6, | ||
| 105 | 0x2D,0xEC,0xA0,0xF1,0xCC,0xEA,0x4A,0xF5, | ||
| 106 | 0x1F,0xC1,0x54,0x90,0xED,0xDC,0x47,0xAF, | ||
| 107 | 0x32,0xBB,0x2B,0x66,0xC3,0x4F,0xF9,0xAD, | ||
| 108 | 0x8C,0x60,0x08,0xAD,0x67,0x7F,0x77,0x12, | ||
| 109 | 0x69,0x53,0xB2,0x26,0xE4,0xED,0x8B,0x01 }; | ||
| 110 | |||
| 111 | int main (int argc,char *argv[]) | ||
| 112 | { unsigned char md[WHIRLPOOL_DIGEST_LENGTH]; | ||
| 113 | int i; | ||
| 114 | WHIRLPOOL_CTX ctx; | ||
| 115 | |||
| 116 | #ifdef OPENSSL_IA32_SSE2 | ||
| 117 | /* Alternative to this is to call OpenSSL_add_all_algorithms... | ||
| 118 | * The below code is retained exclusively for debugging purposes. */ | ||
| 119 | { char *env; | ||
| 120 | |||
| 121 | if ((env=getenv("OPENSSL_ia32cap"))) | ||
| 122 | OPENSSL_ia32cap = strtoul (env,NULL,0); | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | fprintf(stdout,"Testing Whirlpool "); | ||
| 127 | |||
| 128 | WHIRLPOOL("",0,md); | ||
| 129 | if (memcmp(md,iso_test_1,sizeof(iso_test_1))) | ||
| 130 | { fflush(stdout); | ||
| 131 | fprintf(stderr,"\nTEST 1 of 9 failed.\n"); | ||
| 132 | return 1; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | fprintf(stdout,"."); fflush(stdout); | ||
| 136 | |||
| 137 | WHIRLPOOL("a",1,md); | ||
| 138 | if (memcmp(md,iso_test_2,sizeof(iso_test_2))) | ||
| 139 | { fflush(stdout); | ||
| 140 | fprintf(stderr,"\nTEST 2 of 9 failed.\n"); | ||
| 141 | return 1; | ||
| 142 | } | ||
| 143 | else | ||
| 144 | fprintf(stdout,"."); fflush(stdout); | ||
| 145 | |||
| 146 | WHIRLPOOL("abc",3,md); | ||
| 147 | if (memcmp(md,iso_test_3,sizeof(iso_test_3))) | ||
| 148 | { fflush(stdout); | ||
| 149 | fprintf(stderr,"\nTEST 3 of 9 failed.\n"); | ||
| 150 | return 1; | ||
| 151 | } | ||
| 152 | else | ||
| 153 | fprintf(stdout,"."); fflush(stdout); | ||
| 154 | |||
| 155 | WHIRLPOOL("message digest",14,md); | ||
| 156 | if (memcmp(md,iso_test_4,sizeof(iso_test_4))) | ||
| 157 | { fflush(stdout); | ||
| 158 | fprintf(stderr,"\nTEST 4 of 9 failed.\n"); | ||
| 159 | return 1; | ||
| 160 | } | ||
| 161 | else | ||
| 162 | fprintf(stdout,"."); fflush(stdout); | ||
| 163 | |||
| 164 | WHIRLPOOL("abcdefghijklmnopqrstuvwxyz",26,md); | ||
| 165 | if (memcmp(md,iso_test_5,sizeof(iso_test_5))) | ||
| 166 | { fflush(stdout); | ||
| 167 | fprintf(stderr,"\nTEST 5 of 9 failed.\n"); | ||
| 168 | return 1; | ||
| 169 | } | ||
| 170 | else | ||
| 171 | fprintf(stdout,"."); fflush(stdout); | ||
| 172 | |||
| 173 | WHIRLPOOL( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
| 174 | "abcdefghijklmnopqrstuvwxyz" | ||
| 175 | "0123456789",62,md); | ||
| 176 | if (memcmp(md,iso_test_6,sizeof(iso_test_6))) | ||
| 177 | { fflush(stdout); | ||
| 178 | fprintf(stderr,"\nTEST 6 of 9 failed.\n"); | ||
| 179 | return 1; | ||
| 180 | } | ||
| 181 | else | ||
| 182 | fprintf(stdout,"."); fflush(stdout); | ||
| 183 | |||
| 184 | WHIRLPOOL( "1234567890""1234567890""1234567890""1234567890" | ||
| 185 | "1234567890""1234567890""1234567890""1234567890",80,md); | ||
| 186 | if (memcmp(md,iso_test_7,sizeof(iso_test_7))) | ||
| 187 | { fflush(stdout); | ||
| 188 | fprintf(stderr,"\nTEST 7 of 9 failed.\n"); | ||
| 189 | return 1; | ||
| 190 | } | ||
| 191 | else | ||
| 192 | fprintf(stdout,"."); fflush(stdout); | ||
| 193 | |||
| 194 | WHIRLPOOL("abcdbcdecdefdefgefghfghighijhijk",32,md); | ||
| 195 | if (memcmp(md,iso_test_8,sizeof(iso_test_8))) | ||
| 196 | { fflush(stdout); | ||
| 197 | fprintf(stderr,"\nTEST 8 of 9 failed.\n"); | ||
| 198 | return 1; | ||
| 199 | } | ||
| 200 | else | ||
| 201 | fprintf(stdout,"."); fflush(stdout); | ||
| 202 | |||
| 203 | WHIRLPOOL_Init (&ctx); | ||
| 204 | for (i=0;i<1000000;i+=288) | ||
| 205 | WHIRLPOOL_Update (&ctx, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 206 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 207 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 208 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 209 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 210 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 211 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 212 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 213 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 214 | (1000000-i)<288?1000000-i:288); | ||
| 215 | WHIRLPOOL_Final (md,&ctx); | ||
| 216 | if (memcmp(md,iso_test_9,sizeof(iso_test_9))) | ||
| 217 | { fflush(stdout); | ||
| 218 | fprintf(stderr,"\nTEST 9 of 9 failed.\n"); | ||
| 219 | return 1; | ||
| 220 | } | ||
| 221 | else | ||
| 222 | fprintf(stdout,"."); fflush(stdout); | ||
| 223 | |||
| 224 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 225 | |||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | #endif | ||
