Correct PPTP server firewall rules chain.
[tomato/davidwu.git] / release / src / router / openssl / crypto / jpake / jpaketest.c
blobeaba75ed8abe1b8e51d6696a1f884a02576ffd30
1 #include <openssl/opensslconf.h>
3 #ifdef OPENSSL_NO_JPAKE
5 #include <stdio.h>
7 int main(int argc, char *argv[])
9 printf("No J-PAKE support\n");
10 return(0);
13 #else
15 #include <openssl/jpake.h>
16 #include <openssl/err.h>
18 static void showbn(const char *name, const BIGNUM *bn)
20 fputs(name, stdout);
21 fputs(" = ", stdout);
22 BN_print_fp(stdout, bn);
23 putc('\n', stdout);
26 static int run_jpake(JPAKE_CTX *alice, JPAKE_CTX *bob)
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;
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))
41 printf("Bob fails to process Alice's step 1\n");
42 ERR_print_errors_fp(stdout);
43 return 1;
45 JPAKE_STEP1_release(&alice_s1);
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))
53 printf("Alice fails to process Bob's step 1\n");
54 ERR_print_errors_fp(stdout);
55 return 2;
57 JPAKE_STEP1_release(&bob_s1);
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))
65 printf("Bob fails to process Alice's step 2\n");
66 ERR_print_errors_fp(stdout);
67 return 3;
69 JPAKE_STEP2_release(&alice_s2);
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))
77 printf("Alice fails to process Bob's step 2\n");
78 ERR_print_errors_fp(stdout);
79 return 4;
81 JPAKE_STEP2_release(&bob_s2);
83 showbn("Alice's key", JPAKE_get_shared_key(alice));
84 showbn("Bob's key ", JPAKE_get_shared_key(bob));
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))
92 printf("Bob fails to process Alice's step 3a\n");
93 ERR_print_errors_fp(stdout);
94 return 5;
96 JPAKE_STEP3A_release(&alice_s3a);
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))
104 printf("Alice fails to process Bob's step 3b\n");
105 ERR_print_errors_fp(stdout);
106 return 6;
108 JPAKE_STEP3B_release(&bob_s3b);
110 return 0;
113 int main(int argc, char **argv)
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;
123 bio_err = BIO_new_fp(stderr, BIO_NOCLOSE);
125 CRYPTO_malloc_debug_init();
126 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
127 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
129 ERR_load_crypto_strings();
132 BN_hex2bn(&p, "fd7f53811d75122952df4a9c2eece4e7f611b7523cef4400c31e3f80b6512669455d402251fb593d8d58fabfc5f5ba30f6cb9b556cd7813b801d346ff26660b76b9950a5a49f9fe8047b1022c24fbba9d7feb7c61bf83b57e7c6a8a6150f04fb83f6d3c51ec3023554135a169132f675f3ae2b61d72aeff22203199dd14801c7");
133 BN_hex2bn(&g, "f7e1a085d69b3ddecbbcab5c36b857b97994afbbfa3aea82f9574c0b3d0782675159578ebad4594fe67107108180b449167123e84c281613b7cf09328cc8a6e13c167a8b547c8d28e0a3ae1e2bb3a675916ea37f0bfa213562f1fb627a01243bcca4f1bea8519089a883dfe15ae59f06928b665e807b552564014c3bfecf492a");
134 BN_hex2bn(&q, "9760508f15230bccb292b982a2eb840bf0581cf5");
137 p = BN_new();
138 BN_generate_prime(p, 1024, 1, NULL, NULL, NULL, NULL);
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);
150 BN_rand(secret, 32, -1, 0);
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);
156 if(run_jpake(alice, bob) != 0)
158 fprintf(stderr, "Plain JPAKE run failed\n");
159 return 1;
162 JPAKE_CTX_free(bob);
163 JPAKE_CTX_free(alice);
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);
170 if(run_jpake(alice, bob) != 5)
172 fprintf(stderr, "Mismatched secret JPAKE run failed\n");
173 return 1;
176 JPAKE_CTX_free(bob);
177 JPAKE_CTX_free(alice);
179 BN_free(secret);
180 BN_free(q);
181 BN_free(g);
182 BN_free(p);
184 CRYPTO_cleanup_all_ex_data();
185 ERR_remove_thread_state(NULL);
186 ERR_free_strings();
187 CRYPTO_mem_leaks(bio_err);
189 return 0;
192 #endif