diff options
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r-- | src/lib/libcrypto/camellia/Makefile | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/cms/Makefile | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/fips_err.h | 137 | ||||
-rw-r--r-- | src/lib/libcrypto/jpake/Makefile | 64 | ||||
-rw-r--r-- | src/lib/libcrypto/jpake/jpake.c | 483 | ||||
-rw-r--r-- | src/lib/libcrypto/jpake/jpake.h | 129 | ||||
-rw-r--r-- | src/lib/libcrypto/jpake/jpake_err.c | 105 | ||||
-rw-r--r-- | src/lib/libcrypto/jpake/jpaketest.c | 192 | ||||
-rw-r--r-- | src/lib/libcrypto/pqueue/Makefile | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/seed/Makefile | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/store/Makefile | 18 | ||||
-rw-r--r-- | src/lib/libcrypto/util/copy.pl | 11 |
12 files changed, 1134 insertions, 13 deletions
diff --git a/src/lib/libcrypto/camellia/Makefile b/src/lib/libcrypto/camellia/Makefile index 1579de5ce5..dfb12951fd 100644 --- a/src/lib/libcrypto/camellia/Makefile +++ b/src/lib/libcrypto/camellia/Makefile | |||
@@ -41,7 +41,7 @@ top: | |||
41 | all: lib | 41 | all: lib |
42 | 42 | ||
43 | lib: $(LIBOBJ) | 43 | lib: $(LIBOBJ) |
44 | $(AR) $(LIB) $(LIBOBJ) | 44 | $(ARX) $(LIB) $(LIBOBJ) |
45 | $(RANLIB) $(LIB) || echo Never mind. | 45 | $(RANLIB) $(LIB) || echo Never mind. |
46 | @touch lib | 46 | @touch lib |
47 | 47 | ||
diff --git a/src/lib/libcrypto/cms/Makefile b/src/lib/libcrypto/cms/Makefile index e39c310b6c..1c137e0cff 100644 --- a/src/lib/libcrypto/cms/Makefile +++ b/src/lib/libcrypto/cms/Makefile | |||
@@ -37,7 +37,7 @@ test: | |||
37 | all: lib | 37 | all: lib |
38 | 38 | ||
39 | lib: $(LIBOBJ) | 39 | lib: $(LIBOBJ) |
40 | $(AR) $(LIB) $(LIBOBJ) | 40 | $(ARX) $(LIB) $(LIBOBJ) |
41 | $(RANLIB) $(LIB) || echo Never mind. | 41 | $(RANLIB) $(LIB) || echo Never mind. |
42 | @touch lib | 42 | @touch lib |
43 | 43 | ||
diff --git a/src/lib/libcrypto/fips_err.h b/src/lib/libcrypto/fips_err.h new file mode 100644 index 0000000000..b328616858 --- /dev/null +++ b/src/lib/libcrypto/fips_err.h | |||
@@ -0,0 +1,137 @@ | |||
1 | /* crypto/fips_err.h */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/fips.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_FIPS,func,0) | ||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_FIPS,0,reason) | ||
70 | |||
71 | static ERR_STRING_DATA FIPS_str_functs[]= | ||
72 | { | ||
73 | {ERR_FUNC(FIPS_F_DH_BUILTIN_GENPARAMS), "DH_BUILTIN_GENPARAMS"}, | ||
74 | {ERR_FUNC(FIPS_F_DSA_BUILTIN_PARAMGEN), "DSA_BUILTIN_PARAMGEN"}, | ||
75 | {ERR_FUNC(FIPS_F_DSA_DO_SIGN), "DSA_do_sign"}, | ||
76 | {ERR_FUNC(FIPS_F_DSA_DO_VERIFY), "DSA_do_verify"}, | ||
77 | {ERR_FUNC(FIPS_F_EVP_CIPHERINIT_EX), "EVP_CipherInit_ex"}, | ||
78 | {ERR_FUNC(FIPS_F_EVP_DIGESTINIT_EX), "EVP_DigestInit_ex"}, | ||
79 | {ERR_FUNC(FIPS_F_FIPS_CHECK_DSA), "FIPS_CHECK_DSA"}, | ||
80 | {ERR_FUNC(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT), "FIPS_CHECK_INCORE_FINGERPRINT"}, | ||
81 | {ERR_FUNC(FIPS_F_FIPS_CHECK_RSA), "FIPS_CHECK_RSA"}, | ||
82 | {ERR_FUNC(FIPS_F_FIPS_DSA_CHECK), "FIPS_DSA_CHECK"}, | ||
83 | {ERR_FUNC(FIPS_F_FIPS_MODE_SET), "FIPS_mode_set"}, | ||
84 | {ERR_FUNC(FIPS_F_FIPS_PKEY_SIGNATURE_TEST), "fips_pkey_signature_test"}, | ||
85 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES), "FIPS_selftest_aes"}, | ||
86 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DES), "FIPS_selftest_des"}, | ||
87 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DSA), "FIPS_selftest_dsa"}, | ||
88 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_HMAC), "FIPS_selftest_hmac"}, | ||
89 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_RNG), "FIPS_selftest_rng"}, | ||
90 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_SHA1), "FIPS_selftest_sha1"}, | ||
91 | {ERR_FUNC(FIPS_F_HASH_FINAL), "HASH_FINAL"}, | ||
92 | {ERR_FUNC(FIPS_F_RSA_BUILTIN_KEYGEN), "RSA_BUILTIN_KEYGEN"}, | ||
93 | {ERR_FUNC(FIPS_F_RSA_EAY_PRIVATE_DECRYPT), "RSA_EAY_PRIVATE_DECRYPT"}, | ||
94 | {ERR_FUNC(FIPS_F_RSA_EAY_PRIVATE_ENCRYPT), "RSA_EAY_PRIVATE_ENCRYPT"}, | ||
95 | {ERR_FUNC(FIPS_F_RSA_EAY_PUBLIC_DECRYPT), "RSA_EAY_PUBLIC_DECRYPT"}, | ||
96 | {ERR_FUNC(FIPS_F_RSA_EAY_PUBLIC_ENCRYPT), "RSA_EAY_PUBLIC_ENCRYPT"}, | ||
97 | {ERR_FUNC(FIPS_F_RSA_X931_GENERATE_KEY_EX), "RSA_X931_generate_key_ex"}, | ||
98 | {ERR_FUNC(FIPS_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, | ||
99 | {0,NULL} | ||
100 | }; | ||
101 | |||
102 | static ERR_STRING_DATA FIPS_str_reasons[]= | ||
103 | { | ||
104 | {ERR_REASON(FIPS_R_CANNOT_READ_EXE) ,"cannot read exe"}, | ||
105 | {ERR_REASON(FIPS_R_CANNOT_READ_EXE_DIGEST),"cannot read exe digest"}, | ||
106 | {ERR_REASON(FIPS_R_CONTRADICTING_EVIDENCE),"contradicting evidence"}, | ||
107 | {ERR_REASON(FIPS_R_EXE_DIGEST_DOES_NOT_MATCH),"exe digest does not match"}, | ||
108 | {ERR_REASON(FIPS_R_FINGERPRINT_DOES_NOT_MATCH),"fingerprint does not match"}, | ||
109 | {ERR_REASON(FIPS_R_FINGERPRINT_DOES_NOT_MATCH_NONPIC_RELOCATED),"fingerprint does not match nonpic relocated"}, | ||
110 | {ERR_REASON(FIPS_R_FINGERPRINT_DOES_NOT_MATCH_SEGMENT_ALIASING),"fingerprint does not match segment aliasing"}, | ||
111 | {ERR_REASON(FIPS_R_FIPS_MODE_ALREADY_SET),"fips mode already set"}, | ||
112 | {ERR_REASON(FIPS_R_FIPS_SELFTEST_FAILED) ,"fips selftest failed"}, | ||
113 | {ERR_REASON(FIPS_R_INVALID_KEY_LENGTH) ,"invalid key length"}, | ||
114 | {ERR_REASON(FIPS_R_KEY_TOO_SHORT) ,"key too short"}, | ||
115 | {ERR_REASON(FIPS_R_NON_FIPS_METHOD) ,"non fips method"}, | ||
116 | {ERR_REASON(FIPS_R_PAIRWISE_TEST_FAILED) ,"pairwise test failed"}, | ||
117 | {ERR_REASON(FIPS_R_RSA_DECRYPT_ERROR) ,"rsa decrypt error"}, | ||
118 | {ERR_REASON(FIPS_R_RSA_ENCRYPT_ERROR) ,"rsa encrypt error"}, | ||
119 | {ERR_REASON(FIPS_R_SELFTEST_FAILED) ,"selftest failed"}, | ||
120 | {ERR_REASON(FIPS_R_TEST_FAILURE) ,"test failure"}, | ||
121 | {ERR_REASON(FIPS_R_UNSUPPORTED_PLATFORM) ,"unsupported platform"}, | ||
122 | {0,NULL} | ||
123 | }; | ||
124 | |||
125 | #endif | ||
126 | |||
127 | void ERR_load_FIPS_strings(void) | ||
128 | { | ||
129 | #ifndef OPENSSL_NO_ERR | ||
130 | |||
131 | if (ERR_func_error_string(FIPS_str_functs[0].error) == NULL) | ||
132 | { | ||
133 | ERR_load_strings(0,FIPS_str_functs); | ||
134 | ERR_load_strings(0,FIPS_str_reasons); | ||
135 | } | ||
136 | #endif | ||
137 | } | ||
diff --git a/src/lib/libcrypto/jpake/Makefile b/src/lib/libcrypto/jpake/Makefile new file mode 100644 index 0000000000..a4a1402f2e --- /dev/null +++ b/src/lib/libcrypto/jpake/Makefile | |||
@@ -0,0 +1,64 @@ | |||
1 | DIR=jpake | ||
2 | TOP=../.. | ||
3 | |||
4 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
5 | |||
6 | LIB=$(TOP)/libcrypto.a | ||
7 | LIBOBJ=jpake.o jpake_err.o | ||
8 | LIBSRC=jpake.c jpake_err.c | ||
9 | |||
10 | EXHEADER=jpake.h | ||
11 | TEST=jpaketest.c | ||
12 | |||
13 | top: | ||
14 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
15 | |||
16 | all: lib | ||
17 | |||
18 | lib: $(LIBOBJ) | ||
19 | $(ARX) $(LIB) $(LIBOBJ) | ||
20 | $(RANLIB) $(LIB) || echo Never mind. | ||
21 | @touch lib | ||
22 | |||
23 | links: | ||
24 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
25 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
26 | |||
27 | install: | ||
28 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
29 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
30 | do \ | ||
31 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
32 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
33 | done; | ||
34 | |||
35 | depend: | ||
36 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
37 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
38 | |||
39 | dclean: | ||
40 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
41 | mv -f Makefile.new $(MAKEFILE) | ||
42 | |||
43 | clean: | ||
44 | rm -f *.s *.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff | ||
45 | |||
46 | jpaketest: top jpaketest.c $(LIB) | ||
47 | $(CC) $(CFLAGS) -Wall -Werror -g -o jpaketest jpaketest.c $(LIB) | ||
48 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
49 | |||
50 | jpake.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
51 | jpake.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
52 | jpake.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
53 | jpake.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
54 | jpake.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
55 | jpake.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
56 | jpake.o: ../../include/openssl/symhacks.h jpake.c jpake.h | ||
57 | jpake_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
58 | jpake_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
59 | jpake_err.o: ../../include/openssl/err.h ../../include/openssl/jpake.h | ||
60 | jpake_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
61 | jpake_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
62 | jpake_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
63 | jpake_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
64 | jpake_err.o: jpake_err.c | ||
diff --git a/src/lib/libcrypto/jpake/jpake.c b/src/lib/libcrypto/jpake/jpake.c new file mode 100644 index 0000000000..577b7ef375 --- /dev/null +++ b/src/lib/libcrypto/jpake/jpake.c | |||
@@ -0,0 +1,483 @@ | |||
1 | #include "jpake.h" | ||
2 | |||
3 | #include <openssl/crypto.h> | ||
4 | #include <openssl/sha.h> | ||
5 | #include <openssl/err.h> | ||
6 | #include <memory.h> | ||
7 | #include <assert.h> | ||
8 | |||
9 | /* | ||
10 | * In the definition, (xa, xb, xc, xd) are Alice's (x1, x2, x3, x4) or | ||
11 | * Bob's (x3, x4, x1, x2). If you see what I mean. | ||
12 | */ | ||
13 | |||
14 | typedef struct | ||
15 | { | ||
16 | char *name; /* Must be unique */ | ||
17 | char *peer_name; | ||
18 | BIGNUM *p; | ||
19 | BIGNUM *g; | ||
20 | BIGNUM *q; | ||
21 | BIGNUM *gxc; /* Alice's g^{x3} or Bob's g^{x1} */ | ||
22 | BIGNUM *gxd; /* Alice's g^{x4} or Bob's g^{x2} */ | ||
23 | } JPAKE_CTX_PUBLIC; | ||
24 | |||
25 | struct JPAKE_CTX | ||
26 | { | ||
27 | JPAKE_CTX_PUBLIC p; | ||
28 | BIGNUM *secret; /* The shared secret */ | ||
29 | BN_CTX *ctx; | ||
30 | BIGNUM *xa; /* Alice's x1 or Bob's x3 */ | ||
31 | BIGNUM *xb; /* Alice's x2 or Bob's x4 */ | ||
32 | BIGNUM *key; /* The calculated (shared) key */ | ||
33 | }; | ||
34 | |||
35 | static void JPAKE_ZKP_init(JPAKE_ZKP *zkp) | ||
36 | { | ||
37 | zkp->gr = BN_new(); | ||
38 | zkp->b = BN_new(); | ||
39 | } | ||
40 | |||
41 | static void JPAKE_ZKP_release(JPAKE_ZKP *zkp) | ||
42 | { | ||
43 | BN_free(zkp->b); | ||
44 | BN_free(zkp->gr); | ||
45 | } | ||
46 | |||
47 | /* Two birds with one stone - make the global name as expected */ | ||
48 | #define JPAKE_STEP_PART_init JPAKE_STEP2_init | ||
49 | #define JPAKE_STEP_PART_release JPAKE_STEP2_release | ||
50 | |||
51 | void JPAKE_STEP_PART_init(JPAKE_STEP_PART *p) | ||
52 | { | ||
53 | p->gx = BN_new(); | ||
54 | JPAKE_ZKP_init(&p->zkpx); | ||
55 | } | ||
56 | |||
57 | void JPAKE_STEP_PART_release(JPAKE_STEP_PART *p) | ||
58 | { | ||
59 | JPAKE_ZKP_release(&p->zkpx); | ||
60 | BN_free(p->gx); | ||
61 | } | ||
62 | |||
63 | void JPAKE_STEP1_init(JPAKE_STEP1 *s1) | ||
64 | { | ||
65 | JPAKE_STEP_PART_init(&s1->p1); | ||
66 | JPAKE_STEP_PART_init(&s1->p2); | ||
67 | } | ||
68 | |||
69 | void JPAKE_STEP1_release(JPAKE_STEP1 *s1) | ||
70 | { | ||
71 | JPAKE_STEP_PART_release(&s1->p2); | ||
72 | JPAKE_STEP_PART_release(&s1->p1); | ||
73 | } | ||
74 | |||
75 | static void JPAKE_CTX_init(JPAKE_CTX *ctx, const char *name, | ||
76 | const char *peer_name, const BIGNUM *p, | ||
77 | const BIGNUM *g, const BIGNUM *q, | ||
78 | const BIGNUM *secret) | ||
79 | { | ||
80 | ctx->p.name = OPENSSL_strdup(name); | ||
81 | ctx->p.peer_name = OPENSSL_strdup(peer_name); | ||
82 | ctx->p.p = BN_dup(p); | ||
83 | ctx->p.g = BN_dup(g); | ||
84 | ctx->p.q = BN_dup(q); | ||
85 | ctx->secret = BN_dup(secret); | ||
86 | |||
87 | ctx->p.gxc = BN_new(); | ||
88 | ctx->p.gxd = BN_new(); | ||
89 | |||
90 | ctx->xa = BN_new(); | ||
91 | ctx->xb = BN_new(); | ||
92 | ctx->key = BN_new(); | ||
93 | ctx->ctx = BN_CTX_new(); | ||
94 | } | ||
95 | |||
96 | static void JPAKE_CTX_release(JPAKE_CTX *ctx) | ||
97 | { | ||
98 | BN_CTX_free(ctx->ctx); | ||
99 | BN_clear_free(ctx->key); | ||
100 | BN_clear_free(ctx->xb); | ||
101 | BN_clear_free(ctx->xa); | ||
102 | |||
103 | BN_free(ctx->p.gxd); | ||
104 | BN_free(ctx->p.gxc); | ||
105 | |||
106 | BN_clear_free(ctx->secret); | ||
107 | BN_free(ctx->p.q); | ||
108 | BN_free(ctx->p.g); | ||
109 | BN_free(ctx->p.p); | ||
110 | OPENSSL_free(ctx->p.peer_name); | ||
111 | OPENSSL_free(ctx->p.name); | ||
112 | |||
113 | memset(ctx, '\0', sizeof *ctx); | ||
114 | } | ||
115 | |||
116 | JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name, | ||
117 | const BIGNUM *p, const BIGNUM *g, const BIGNUM *q, | ||
118 | const BIGNUM *secret) | ||
119 | { | ||
120 | JPAKE_CTX *ctx = OPENSSL_malloc(sizeof *ctx); | ||
121 | |||
122 | JPAKE_CTX_init(ctx, name, peer_name, p, g, q, secret); | ||
123 | |||
124 | return ctx; | ||
125 | } | ||
126 | |||
127 | void JPAKE_CTX_free(JPAKE_CTX *ctx) | ||
128 | { | ||
129 | JPAKE_CTX_release(ctx); | ||
130 | OPENSSL_free(ctx); | ||
131 | } | ||
132 | |||
133 | static void hashlength(SHA_CTX *sha, size_t l) | ||
134 | { | ||
135 | unsigned char b[2]; | ||
136 | |||
137 | assert(l <= 0xffff); | ||
138 | b[0] = l >> 8; | ||
139 | b[1] = l&0xff; | ||
140 | SHA1_Update(sha, b, 2); | ||
141 | } | ||
142 | |||
143 | static void hashstring(SHA_CTX *sha, const char *string) | ||
144 | { | ||
145 | size_t l = strlen(string); | ||
146 | |||
147 | hashlength(sha, l); | ||
148 | SHA1_Update(sha, string, l); | ||
149 | } | ||
150 | |||
151 | static void hashbn(SHA_CTX *sha, const BIGNUM *bn) | ||
152 | { | ||
153 | size_t l = BN_num_bytes(bn); | ||
154 | unsigned char *bin = OPENSSL_malloc(l); | ||
155 | |||
156 | hashlength(sha, l); | ||
157 | BN_bn2bin(bn, bin); | ||
158 | SHA1_Update(sha, bin, l); | ||
159 | OPENSSL_free(bin); | ||
160 | } | ||
161 | |||
162 | /* h=hash(g, g^r, g^x, name) */ | ||
163 | static void zkp_hash(BIGNUM *h, const BIGNUM *zkpg, const JPAKE_STEP_PART *p, | ||
164 | const char *proof_name) | ||
165 | { | ||
166 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
167 | SHA_CTX sha; | ||
168 | |||
169 | /* | ||
170 | * XXX: hash should not allow moving of the boundaries - Java code | ||
171 | * is flawed in this respect. Length encoding seems simplest. | ||
172 | */ | ||
173 | SHA1_Init(&sha); | ||
174 | hashbn(&sha, zkpg); | ||
175 | assert(!BN_is_zero(p->zkpx.gr)); | ||
176 | hashbn(&sha, p->zkpx.gr); | ||
177 | hashbn(&sha, p->gx); | ||
178 | hashstring(&sha, proof_name); | ||
179 | SHA1_Final(md, &sha); | ||
180 | BN_bin2bn(md, SHA_DIGEST_LENGTH, h); | ||
181 | } | ||
182 | |||
183 | /* | ||
184 | * Prove knowledge of x | ||
185 | * Note that p->gx has already been calculated | ||
186 | */ | ||
187 | static void generate_zkp(JPAKE_STEP_PART *p, const BIGNUM *x, | ||
188 | const BIGNUM *zkpg, JPAKE_CTX *ctx) | ||
189 | { | ||
190 | BIGNUM *r = BN_new(); | ||
191 | BIGNUM *h = BN_new(); | ||
192 | BIGNUM *t = BN_new(); | ||
193 | |||
194 | /* | ||
195 | * r in [0,q) | ||
196 | * XXX: Java chooses r in [0, 2^160) - i.e. distribution not uniform | ||
197 | */ | ||
198 | BN_rand_range(r, ctx->p.q); | ||
199 | /* g^r */ | ||
200 | BN_mod_exp(p->zkpx.gr, zkpg, r, ctx->p.p, ctx->ctx); | ||
201 | |||
202 | /* h=hash... */ | ||
203 | zkp_hash(h, zkpg, p, ctx->p.name); | ||
204 | |||
205 | /* b = r - x*h */ | ||
206 | BN_mod_mul(t, x, h, ctx->p.q, ctx->ctx); | ||
207 | BN_mod_sub(p->zkpx.b, r, t, ctx->p.q, ctx->ctx); | ||
208 | |||
209 | /* cleanup */ | ||
210 | BN_free(t); | ||
211 | BN_free(h); | ||
212 | BN_free(r); | ||
213 | } | ||
214 | |||
215 | static int verify_zkp(const JPAKE_STEP_PART *p, const BIGNUM *zkpg, | ||
216 | JPAKE_CTX *ctx) | ||
217 | { | ||
218 | BIGNUM *h = BN_new(); | ||
219 | BIGNUM *t1 = BN_new(); | ||
220 | BIGNUM *t2 = BN_new(); | ||
221 | BIGNUM *t3 = BN_new(); | ||
222 | int ret = 0; | ||
223 | |||
224 | zkp_hash(h, zkpg, p, ctx->p.peer_name); | ||
225 | |||
226 | /* t1 = g^b */ | ||
227 | BN_mod_exp(t1, zkpg, p->zkpx.b, ctx->p.p, ctx->ctx); | ||
228 | /* t2 = (g^x)^h = g^{hx} */ | ||
229 | BN_mod_exp(t2, p->gx, h, ctx->p.p, ctx->ctx); | ||
230 | /* t3 = t1 * t2 = g^{hx} * g^b = g^{hx+b} = g^r (allegedly) */ | ||
231 | BN_mod_mul(t3, t1, t2, ctx->p.p, ctx->ctx); | ||
232 | |||
233 | /* verify t3 == g^r */ | ||
234 | if(BN_cmp(t3, p->zkpx.gr) == 0) | ||
235 | ret = 1; | ||
236 | else | ||
237 | JPAKEerr(JPAKE_F_VERIFY_ZKP, JPAKE_R_ZKP_VERIFY_FAILED); | ||
238 | |||
239 | /* cleanup */ | ||
240 | BN_free(t3); | ||
241 | BN_free(t2); | ||
242 | BN_free(t1); | ||
243 | BN_free(h); | ||
244 | |||
245 | return ret; | ||
246 | } | ||
247 | |||
248 | static void generate_step_part(JPAKE_STEP_PART *p, const BIGNUM *x, | ||
249 | const BIGNUM *g, JPAKE_CTX *ctx) | ||
250 | { | ||
251 | BN_mod_exp(p->gx, g, x, ctx->p.p, ctx->ctx); | ||
252 | generate_zkp(p, x, g, ctx); | ||
253 | } | ||
254 | |||
255 | /* Generate each party's random numbers. xa is in [0, q), xb is in [1, q). */ | ||
256 | static void genrand(JPAKE_CTX *ctx) | ||
257 | { | ||
258 | BIGNUM *qm1; | ||
259 | |||
260 | /* xa in [0, q) */ | ||
261 | BN_rand_range(ctx->xa, ctx->p.q); | ||
262 | |||
263 | /* q-1 */ | ||
264 | qm1 = BN_new(); | ||
265 | BN_copy(qm1, ctx->p.q); | ||
266 | BN_sub_word(qm1, 1); | ||
267 | |||
268 | /* ... and xb in [0, q-1) */ | ||
269 | BN_rand_range(ctx->xb, qm1); | ||
270 | /* [1, q) */ | ||
271 | BN_add_word(ctx->xb, 1); | ||
272 | |||
273 | /* cleanup */ | ||
274 | BN_free(qm1); | ||
275 | } | ||
276 | |||
277 | int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx) | ||
278 | { | ||
279 | genrand(ctx); | ||
280 | generate_step_part(&send->p1, ctx->xa, ctx->p.g, ctx); | ||
281 | generate_step_part(&send->p2, ctx->xb, ctx->p.g, ctx); | ||
282 | |||
283 | return 1; | ||
284 | } | ||
285 | |||
286 | int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received) | ||
287 | { | ||
288 | /* verify their ZKP(xc) */ | ||
289 | if(!verify_zkp(&received->p1, ctx->p.g, ctx)) | ||
290 | { | ||
291 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X3_FAILED); | ||
292 | return 0; | ||
293 | } | ||
294 | |||
295 | /* verify their ZKP(xd) */ | ||
296 | if(!verify_zkp(&received->p2, ctx->p.g, ctx)) | ||
297 | { | ||
298 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_VERIFY_X4_FAILED); | ||
299 | return 0; | ||
300 | } | ||
301 | |||
302 | /* g^xd != 1 */ | ||
303 | if(BN_is_one(received->p2.gx)) | ||
304 | { | ||
305 | JPAKEerr(JPAKE_F_JPAKE_STEP1_PROCESS, JPAKE_R_G_TO_THE_X4_IS_ONE); | ||
306 | return 0; | ||
307 | } | ||
308 | |||
309 | /* Save the bits we need for later */ | ||
310 | BN_copy(ctx->p.gxc, received->p1.gx); | ||
311 | BN_copy(ctx->p.gxd, received->p2.gx); | ||
312 | |||
313 | return 1; | ||
314 | } | ||
315 | |||
316 | |||
317 | int JPAKE_STEP2_generate(JPAKE_STEP2 *send, JPAKE_CTX *ctx) | ||
318 | { | ||
319 | BIGNUM *t1 = BN_new(); | ||
320 | BIGNUM *t2 = BN_new(); | ||
321 | |||
322 | /* | ||
323 | * X = g^{(xa + xc + xd) * xb * s} | ||
324 | * t1 = g^xa | ||
325 | */ | ||
326 | BN_mod_exp(t1, ctx->p.g, ctx->xa, ctx->p.p, ctx->ctx); | ||
327 | /* t2 = t1 * g^{xc} = g^{xa} * g^{xc} = g^{xa + xc} */ | ||
328 | BN_mod_mul(t2, t1, ctx->p.gxc, ctx->p.p, ctx->ctx); | ||
329 | /* t1 = t2 * g^{xd} = g^{xa + xc + xd} */ | ||
330 | BN_mod_mul(t1, t2, ctx->p.gxd, ctx->p.p, ctx->ctx); | ||
331 | /* t2 = xb * s */ | ||
332 | BN_mod_mul(t2, ctx->xb, ctx->secret, ctx->p.q, ctx->ctx); | ||
333 | |||
334 | /* | ||
335 | * ZKP(xb * s) | ||
336 | * XXX: this is kinda funky, because we're using | ||
337 | * | ||
338 | * g' = g^{xa + xc + xd} | ||
339 | * | ||
340 | * as the generator, which means X is g'^{xb * s} | ||
341 | * X = t1^{t2} = t1^{xb * s} = g^{(xa + xc + xd) * xb * s} | ||
342 | */ | ||
343 | generate_step_part(send, t2, t1, ctx); | ||
344 | |||
345 | /* cleanup */ | ||
346 | BN_free(t1); | ||
347 | BN_free(t2); | ||
348 | |||
349 | return 1; | ||
350 | } | ||
351 | |||
352 | /* gx = g^{xc + xa + xb} * xd * s */ | ||
353 | static int compute_key(JPAKE_CTX *ctx, const BIGNUM *gx) | ||
354 | { | ||
355 | BIGNUM *t1 = BN_new(); | ||
356 | BIGNUM *t2 = BN_new(); | ||
357 | BIGNUM *t3 = BN_new(); | ||
358 | |||
359 | /* | ||
360 | * K = (gx/g^{xb * xd * s})^{xb} | ||
361 | * = (g^{(xc + xa + xb) * xd * s - xb * xd *s})^{xb} | ||
362 | * = (g^{(xa + xc) * xd * s})^{xb} | ||
363 | * = g^{(xa + xc) * xb * xd * s} | ||
364 | * [which is the same regardless of who calculates it] | ||
365 | */ | ||
366 | |||
367 | /* t1 = (g^{xd})^{xb} = g^{xb * xd} */ | ||
368 | BN_mod_exp(t1, ctx->p.gxd, ctx->xb, ctx->p.p, ctx->ctx); | ||
369 | /* t2 = -s = q-s */ | ||
370 | BN_sub(t2, ctx->p.q, ctx->secret); | ||
371 | /* t3 = t1^t2 = g^{-xb * xd * s} */ | ||
372 | BN_mod_exp(t3, t1, t2, ctx->p.p, ctx->ctx); | ||
373 | /* t1 = gx * t3 = X/g^{xb * xd * s} */ | ||
374 | BN_mod_mul(t1, gx, t3, ctx->p.p, ctx->ctx); | ||
375 | /* K = t1^{xb} */ | ||
376 | BN_mod_exp(ctx->key, t1, ctx->xb, ctx->p.p, ctx->ctx); | ||
377 | |||
378 | /* cleanup */ | ||
379 | BN_free(t3); | ||
380 | BN_free(t2); | ||
381 | BN_free(t1); | ||
382 | |||
383 | return 1; | ||
384 | } | ||
385 | |||
386 | int JPAKE_STEP2_process(JPAKE_CTX *ctx, const JPAKE_STEP2 *received) | ||
387 | { | ||
388 | BIGNUM *t1 = BN_new(); | ||
389 | BIGNUM *t2 = BN_new(); | ||
390 | int ret = 0; | ||
391 | |||
392 | /* | ||
393 | * g' = g^{xc + xa + xb} [from our POV] | ||
394 | * t1 = xa + xb | ||
395 | */ | ||
396 | BN_mod_add(t1, ctx->xa, ctx->xb, ctx->p.q, ctx->ctx); | ||
397 | /* t2 = g^{t1} = g^{xa+xb} */ | ||
398 | BN_mod_exp(t2, ctx->p.g, t1, ctx->p.p, ctx->ctx); | ||
399 | /* t1 = g^{xc} * t2 = g^{xc + xa + xb} */ | ||
400 | BN_mod_mul(t1, ctx->p.gxc, t2, ctx->p.p, ctx->ctx); | ||
401 | |||
402 | if(verify_zkp(received, t1, ctx)) | ||
403 | ret = 1; | ||
404 | else | ||
405 | JPAKEerr(JPAKE_F_JPAKE_STEP2_PROCESS, JPAKE_R_VERIFY_B_FAILED); | ||
406 | |||
407 | compute_key(ctx, received->gx); | ||
408 | |||
409 | /* cleanup */ | ||
410 | BN_free(t2); | ||
411 | BN_free(t1); | ||
412 | |||
413 | return ret; | ||
414 | } | ||
415 | |||
416 | static void quickhashbn(unsigned char *md, const BIGNUM *bn) | ||
417 | { | ||
418 | SHA_CTX sha; | ||
419 | |||
420 | SHA1_Init(&sha); | ||
421 | hashbn(&sha, bn); | ||
422 | SHA1_Final(md, &sha); | ||
423 | } | ||
424 | |||
425 | void JPAKE_STEP3A_init(JPAKE_STEP3A *s3a) | ||
426 | {} | ||
427 | |||
428 | int JPAKE_STEP3A_generate(JPAKE_STEP3A *send, JPAKE_CTX *ctx) | ||
429 | { | ||
430 | quickhashbn(send->hhk, ctx->key); | ||
431 | SHA1(send->hhk, sizeof send->hhk, send->hhk); | ||
432 | |||
433 | return 1; | ||
434 | } | ||
435 | |||
436 | int JPAKE_STEP3A_process(JPAKE_CTX *ctx, const JPAKE_STEP3A *received) | ||
437 | { | ||
438 | unsigned char hhk[SHA_DIGEST_LENGTH]; | ||
439 | |||
440 | quickhashbn(hhk, ctx->key); | ||
441 | SHA1(hhk, sizeof hhk, hhk); | ||
442 | if(memcmp(hhk, received->hhk, sizeof hhk)) | ||
443 | { | ||
444 | JPAKEerr(JPAKE_F_JPAKE_STEP3A_PROCESS, JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH); | ||
445 | return 0; | ||
446 | } | ||
447 | return 1; | ||
448 | } | ||
449 | |||
450 | void JPAKE_STEP3A_release(JPAKE_STEP3A *s3a) | ||
451 | {} | ||
452 | |||
453 | void JPAKE_STEP3B_init(JPAKE_STEP3B *s3b) | ||
454 | {} | ||
455 | |||
456 | int JPAKE_STEP3B_generate(JPAKE_STEP3B *send, JPAKE_CTX *ctx) | ||
457 | { | ||
458 | quickhashbn(send->hk, ctx->key); | ||
459 | |||
460 | return 1; | ||
461 | } | ||
462 | |||
463 | int JPAKE_STEP3B_process(JPAKE_CTX *ctx, const JPAKE_STEP3B *received) | ||
464 | { | ||
465 | unsigned char hk[SHA_DIGEST_LENGTH]; | ||
466 | |||
467 | quickhashbn(hk, ctx->key); | ||
468 | if(memcmp(hk, received->hk, sizeof hk)) | ||
469 | { | ||
470 | JPAKEerr(JPAKE_F_JPAKE_STEP3B_PROCESS, JPAKE_R_HASH_OF_KEY_MISMATCH); | ||
471 | return 0; | ||
472 | } | ||
473 | return 1; | ||
474 | } | ||
475 | |||
476 | void JPAKE_STEP3B_release(JPAKE_STEP3B *s3b) | ||
477 | {} | ||
478 | |||
479 | const BIGNUM *JPAKE_get_shared_key(JPAKE_CTX *ctx) | ||
480 | { | ||
481 | return ctx->key; | ||
482 | } | ||
483 | |||
diff --git a/src/lib/libcrypto/jpake/jpake.h b/src/lib/libcrypto/jpake/jpake.h new file mode 100644 index 0000000000..693ea188cb --- /dev/null +++ b/src/lib/libcrypto/jpake/jpake.h | |||
@@ -0,0 +1,129 @@ | |||
1 | /* | ||
2 | * Implement J-PAKE, as described in | ||
3 | * http://grouper.ieee.org/groups/1363/Research/contributions/hao-ryan-2008.pdf | ||
4 | * | ||
5 | * With hints from http://www.cl.cam.ac.uk/~fh240/software/JPAKE2.java. | ||
6 | */ | ||
7 | |||
8 | #ifndef HEADER_JPAKE_H | ||
9 | #define HEADER_JPAKE_H | ||
10 | |||
11 | #include <openssl/opensslconf.h> | ||
12 | |||
13 | #ifdef OPENSSL_NO_JPAKE | ||
14 | #error JPAKE is disabled. | ||
15 | #endif | ||
16 | |||
17 | #ifdef __cplusplus | ||
18 | extern "C" { | ||
19 | #endif | ||
20 | |||
21 | #include <openssl/bn.h> | ||
22 | #include <openssl/sha.h> | ||
23 | |||
24 | typedef struct JPAKE_CTX JPAKE_CTX; | ||
25 | |||
26 | /* Note that "g" in the ZKPs is not necessarily the J-PAKE g. */ | ||
27 | typedef struct | ||
28 | { | ||
29 | BIGNUM *gr; /* g^r (r random) */ | ||
30 | BIGNUM *b; /* b = r - x*h, h=hash(g, g^r, g^x, name) */ | ||
31 | } JPAKE_ZKP; | ||
32 | |||
33 | typedef struct | ||
34 | { | ||
35 | BIGNUM *gx; /* g^x in step 1, g^(xa + xc + xd) * xb * s in step 2 */ | ||
36 | JPAKE_ZKP zkpx; /* ZKP(x) or ZKP(xb * s) */ | ||
37 | } JPAKE_STEP_PART; | ||
38 | |||
39 | typedef struct | ||
40 | { | ||
41 | JPAKE_STEP_PART p1; /* g^x3, ZKP(x3) or g^x1, ZKP(x1) */ | ||
42 | JPAKE_STEP_PART p2; /* g^x4, ZKP(x4) or g^x2, ZKP(x2) */ | ||
43 | } JPAKE_STEP1; | ||
44 | |||
45 | typedef JPAKE_STEP_PART JPAKE_STEP2; | ||
46 | |||
47 | typedef struct | ||
48 | { | ||
49 | unsigned char hhk[SHA_DIGEST_LENGTH]; | ||
50 | } JPAKE_STEP3A; | ||
51 | |||
52 | typedef struct | ||
53 | { | ||
54 | unsigned char hk[SHA_DIGEST_LENGTH]; | ||
55 | } JPAKE_STEP3B; | ||
56 | |||
57 | /* Parameters are copied */ | ||
58 | JPAKE_CTX *JPAKE_CTX_new(const char *name, const char *peer_name, | ||
59 | const BIGNUM *p, const BIGNUM *g, const BIGNUM *q, | ||
60 | const BIGNUM *secret); | ||
61 | void JPAKE_CTX_free(JPAKE_CTX *ctx); | ||
62 | |||
63 | /* | ||
64 | * Note that JPAKE_STEP1 can be used multiple times before release | ||
65 | * without another init. | ||
66 | */ | ||
67 | void JPAKE_STEP1_init(JPAKE_STEP1 *s1); | ||
68 | int JPAKE_STEP1_generate(JPAKE_STEP1 *send, JPAKE_CTX *ctx); | ||
69 | int JPAKE_STEP1_process(JPAKE_CTX *ctx, const JPAKE_STEP1 *received); | ||
70 | void JPAKE_STEP1_release(JPAKE_STEP1 *s1); | ||
71 | |||
72 | /* | ||
73 | * Note that JPAKE_STEP2 can be used multiple times before release | ||
74 | * without another init. | ||
75 | */ | ||
76 | void JPAKE_STEP2_init(JPAKE_STEP2 *s2); | ||
77 | int JPAKE_STEP2_generate(JPAKE_STEP2 *send, JPAKE_CTX *ctx); | ||
78 | int JPAKE_STEP2_process(JPAKE_CTX *ctx, const JPAKE_STEP2 *received); | ||
79 | void JPAKE_STEP2_release(JPAKE_STEP2 *s2); | ||
80 | |||
81 | /* | ||
82 | * Optionally verify the shared key. If the shared secrets do not | ||
83 | * match, the two ends will disagree about the shared key, but | ||
84 | * otherwise the protocol will succeed. | ||
85 | */ | ||
86 | void JPAKE_STEP3A_init(JPAKE_STEP3A *s3a); | ||
87 | int JPAKE_STEP3A_generate(JPAKE_STEP3A *send, JPAKE_CTX *ctx); | ||
88 | int JPAKE_STEP3A_process(JPAKE_CTX *ctx, const JPAKE_STEP3A *received); | ||
89 | void JPAKE_STEP3A_release(JPAKE_STEP3A *s3a); | ||
90 | |||
91 | void JPAKE_STEP3B_init(JPAKE_STEP3B *s3b); | ||
92 | int JPAKE_STEP3B_generate(JPAKE_STEP3B *send, JPAKE_CTX *ctx); | ||
93 | int JPAKE_STEP3B_process(JPAKE_CTX *ctx, const JPAKE_STEP3B *received); | ||
94 | void JPAKE_STEP3B_release(JPAKE_STEP3B *s3b); | ||
95 | |||
96 | /* | ||
97 | * the return value belongs to the library and will be released when | ||
98 | * ctx is released, and will change when a new handshake is performed. | ||
99 | */ | ||
100 | const BIGNUM *JPAKE_get_shared_key(JPAKE_CTX *ctx); | ||
101 | |||
102 | /* BEGIN ERROR CODES */ | ||
103 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
104 | * made after this point may be overwritten when the script is next run. | ||
105 | */ | ||
106 | void ERR_load_JPAKE_strings(void); | ||
107 | |||
108 | /* Error codes for the JPAKE functions. */ | ||
109 | |||
110 | /* Function codes. */ | ||
111 | #define JPAKE_F_JPAKE_STEP1_PROCESS 101 | ||
112 | #define JPAKE_F_JPAKE_STEP2_PROCESS 102 | ||
113 | #define JPAKE_F_JPAKE_STEP3A_PROCESS 103 | ||
114 | #define JPAKE_F_JPAKE_STEP3B_PROCESS 104 | ||
115 | #define JPAKE_F_VERIFY_ZKP 100 | ||
116 | |||
117 | /* Reason codes. */ | ||
118 | #define JPAKE_R_G_TO_THE_X4_IS_ONE 105 | ||
119 | #define JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH 106 | ||
120 | #define JPAKE_R_HASH_OF_KEY_MISMATCH 107 | ||
121 | #define JPAKE_R_VERIFY_B_FAILED 102 | ||
122 | #define JPAKE_R_VERIFY_X3_FAILED 103 | ||
123 | #define JPAKE_R_VERIFY_X4_FAILED 104 | ||
124 | #define JPAKE_R_ZKP_VERIFY_FAILED 100 | ||
125 | |||
126 | #ifdef __cplusplus | ||
127 | } | ||
128 | #endif | ||
129 | #endif | ||
diff --git a/src/lib/libcrypto/jpake/jpake_err.c b/src/lib/libcrypto/jpake/jpake_err.c new file mode 100644 index 0000000000..1b95067967 --- /dev/null +++ b/src/lib/libcrypto/jpake/jpake_err.c | |||
@@ -0,0 +1,105 @@ | |||
1 | /* crypto/jpake/jpake_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/jpake.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef OPENSSL_NO_ERR | ||
67 | |||
68 | #define ERR_FUNC(func) ERR_PACK(ERR_LIB_JPAKE,func,0) | ||
69 | #define ERR_REASON(reason) ERR_PACK(ERR_LIB_JPAKE,0,reason) | ||
70 | |||
71 | static ERR_STRING_DATA JPAKE_str_functs[]= | ||
72 | { | ||
73 | {ERR_FUNC(JPAKE_F_JPAKE_STEP1_PROCESS), "JPAKE_STEP1_process"}, | ||
74 | {ERR_FUNC(JPAKE_F_JPAKE_STEP2_PROCESS), "JPAKE_STEP2_process"}, | ||
75 | {ERR_FUNC(JPAKE_F_JPAKE_STEP3A_PROCESS), "JPAKE_STEP3A_process"}, | ||
76 | {ERR_FUNC(JPAKE_F_JPAKE_STEP3B_PROCESS), "JPAKE_STEP3B_process"}, | ||
77 | {ERR_FUNC(JPAKE_F_VERIFY_ZKP), "VERIFY_ZKP"}, | ||
78 | {0,NULL} | ||
79 | }; | ||
80 | |||
81 | static ERR_STRING_DATA JPAKE_str_reasons[]= | ||
82 | { | ||
83 | {ERR_REASON(JPAKE_R_G_TO_THE_X4_IS_ONE) ,"g to the x4 is one"}, | ||
84 | {ERR_REASON(JPAKE_R_HASH_OF_HASH_OF_KEY_MISMATCH),"hash of hash of key mismatch"}, | ||
85 | {ERR_REASON(JPAKE_R_HASH_OF_KEY_MISMATCH),"hash of key mismatch"}, | ||
86 | {ERR_REASON(JPAKE_R_VERIFY_B_FAILED) ,"verify b failed"}, | ||
87 | {ERR_REASON(JPAKE_R_VERIFY_X3_FAILED) ,"verify x3 failed"}, | ||
88 | {ERR_REASON(JPAKE_R_VERIFY_X4_FAILED) ,"verify x4 failed"}, | ||
89 | {ERR_REASON(JPAKE_R_ZKP_VERIFY_FAILED) ,"zkp verify failed"}, | ||
90 | {0,NULL} | ||
91 | }; | ||
92 | |||
93 | #endif | ||
94 | |||
95 | void ERR_load_JPAKE_strings(void) | ||
96 | { | ||
97 | #ifndef OPENSSL_NO_ERR | ||
98 | |||
99 | if (ERR_func_error_string(JPAKE_str_functs[0].error) == NULL) | ||
100 | { | ||
101 | ERR_load_strings(0,JPAKE_str_functs); | ||
102 | ERR_load_strings(0,JPAKE_str_reasons); | ||
103 | } | ||
104 | #endif | ||
105 | } | ||
diff --git a/src/lib/libcrypto/jpake/jpaketest.c b/src/lib/libcrypto/jpake/jpaketest.c new file mode 100644 index 0000000000..792fc49eb4 --- /dev/null +++ b/src/lib/libcrypto/jpake/jpaketest.c | |||
@@ -0,0 +1,192 @@ | |||
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_state(0); | ||
186 | ERR_free_strings(); | ||
187 | CRYPTO_mem_leaks(bio_err); | ||
188 | |||
189 | return 0; | ||
190 | } | ||
191 | |||
192 | #endif | ||
diff --git a/src/lib/libcrypto/pqueue/Makefile b/src/lib/libcrypto/pqueue/Makefile index d0c39d25ce..36bfc349aa 100644 --- a/src/lib/libcrypto/pqueue/Makefile +++ b/src/lib/libcrypto/pqueue/Makefile | |||
@@ -33,7 +33,7 @@ top: | |||
33 | all: lib | 33 | all: lib |
34 | 34 | ||
35 | lib: $(LIBOBJ) | 35 | lib: $(LIBOBJ) |
36 | $(AR) $(LIB) $(LIBOBJ) | 36 | $(ARX) $(LIB) $(LIBOBJ) |
37 | $(RANLIB) $(LIB) || echo Never mind. | 37 | $(RANLIB) $(LIB) || echo Never mind. |
38 | @touch lib | 38 | @touch lib |
39 | 39 | ||
diff --git a/src/lib/libcrypto/seed/Makefile b/src/lib/libcrypto/seed/Makefile index f9de27b288..ffaeb84218 100644 --- a/src/lib/libcrypto/seed/Makefile +++ b/src/lib/libcrypto/seed/Makefile | |||
@@ -34,7 +34,7 @@ top: | |||
34 | all: lib | 34 | all: lib |
35 | 35 | ||
36 | lib: $(LIBOBJ) | 36 | lib: $(LIBOBJ) |
37 | $(AR) $(LIB) $(LIBOBJ) | 37 | $(ARX) $(LIB) $(LIBOBJ) |
38 | $(RANLIB) $(LIB) || echo Never mind. | 38 | $(RANLIB) $(LIB) || echo Never mind. |
39 | @touch lib | 39 | @touch lib |
40 | 40 | ||
diff --git a/src/lib/libcrypto/store/Makefile b/src/lib/libcrypto/store/Makefile index 0dcfd7857a..c9f5d001a3 100644 --- a/src/lib/libcrypto/store/Makefile +++ b/src/lib/libcrypto/store/Makefile | |||
@@ -35,7 +35,7 @@ top: | |||
35 | all: lib | 35 | all: lib |
36 | 36 | ||
37 | lib: $(LIBOBJ) | 37 | lib: $(LIBOBJ) |
38 | $(AR) $(LIB) $(LIBOBJ) | 38 | $(ARX) $(LIB) $(LIBOBJ) |
39 | $(RANLIB) $(LIB) || echo Never mind. | 39 | $(RANLIB) $(LIB) || echo Never mind. |
40 | @touch lib | 40 | @touch lib |
41 | 41 | ||
@@ -89,14 +89,14 @@ str_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | |||
89 | str_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | 89 | str_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h |
90 | str_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h | 90 | str_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h |
91 | str_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h | 91 | str_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h |
92 | str_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | 92 | str_lib.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h |
93 | str_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | 93 | str_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h |
94 | str_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | 94 | str_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h |
95 | str_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | 95 | str_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h |
96 | str_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | 96 | str_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h |
97 | str_lib.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h | 97 | str_lib.o: ../../include/openssl/stack.h ../../include/openssl/store.h |
98 | str_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | 98 | str_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h |
99 | str_lib.o: str_lib.c str_locl.h | 99 | str_lib.o: ../../include/openssl/x509_vfy.h str_lib.c str_locl.h |
100 | str_mem.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | 100 | str_mem.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h |
101 | str_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | 101 | str_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h |
102 | str_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | 102 | str_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h |
diff --git a/src/lib/libcrypto/util/copy.pl b/src/lib/libcrypto/util/copy.pl index e20b45530a..eba6d5815e 100644 --- a/src/lib/libcrypto/util/copy.pl +++ b/src/lib/libcrypto/util/copy.pl | |||
@@ -8,9 +8,16 @@ use Fcntl; | |||
8 | # Perl script 'copy' comment. On Windows the built in "copy" command also | 8 | # Perl script 'copy' comment. On Windows the built in "copy" command also |
9 | # copies timestamps: this messes up Makefile dependencies. | 9 | # copies timestamps: this messes up Makefile dependencies. |
10 | 10 | ||
11 | my $stripcr = 0; | ||
12 | |||
11 | my $arg; | 13 | my $arg; |
12 | 14 | ||
13 | foreach $arg (@ARGV) { | 15 | foreach $arg (@ARGV) { |
16 | if ($arg eq "-stripcr") | ||
17 | { | ||
18 | $stripcr = 1; | ||
19 | next; | ||
20 | } | ||
14 | $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob... | 21 | $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob... |
15 | foreach (glob $arg) | 22 | foreach (glob $arg) |
16 | { | 23 | { |
@@ -49,6 +56,10 @@ foreach (@filelist) | |||
49 | || die "Can't Open $dfile"; | 56 | || die "Can't Open $dfile"; |
50 | while (sysread IN, $buf, 10240) | 57 | while (sysread IN, $buf, 10240) |
51 | { | 58 | { |
59 | if ($stripcr) | ||
60 | { | ||
61 | $buf =~ tr/\015//d; | ||
62 | } | ||
52 | syswrite(OUT, $buf, length($buf)); | 63 | syswrite(OUT, $buf, length($buf)); |
53 | } | 64 | } |
54 | close(IN); | 65 | close(IN); |