1 #include <openssl/opensslconf.h>
3 #ifdef OPENSSL_NO_JPAKE
7 int main(int argc
, char *argv
[])
9 printf("No J-PAKE support\n");
15 #include <openssl/jpake.h>
16 #include <openssl/err.h>
18 static void showbn(const char *name
, const BIGNUM
*bn
)
22 BN_print_fp(stdout
, bn
);
26 static int run_jpake(JPAKE_CTX
*alice
, JPAKE_CTX
*bob
)
32 JPAKE_STEP3A alice_s3a
;
35 /* Alice -> Bob: step 1 */
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
);
45 JPAKE_STEP1_release(&alice_s1
);
47 /* Bob -> Alice: step 1 */
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
);
57 JPAKE_STEP1_release(&bob_s1
);
59 /* Alice -> Bob: step 2 */
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
);
69 JPAKE_STEP2_release(&alice_s2
);
71 /* Bob -> Alice: step 2 */
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
);
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 */
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
);
96 JPAKE_STEP3A_release(&alice_s3a
);
98 /* Bob -> Alice: step 3b */
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
);
108 JPAKE_STEP3B_release(&bob_s3b
);
113 int main(int argc
, char **argv
)
120 BIGNUM
*secret
= BN_new();
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");
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");
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");
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");
177 JPAKE_CTX_free(alice
);
184 CRYPTO_cleanup_all_ex_data();
185 ERR_remove_thread_state(NULL
);
187 CRYPTO_mem_leaks(bio_err
);