diff options
Diffstat (limited to 'src/lib/libcrypto')
30 files changed, 3915 insertions, 51 deletions
diff --git a/src/lib/libcrypto/camellia/Makefile b/src/lib/libcrypto/camellia/Makefile index ff5fe4a01d..6ce6fc99cd 100644 --- a/src/lib/libcrypto/camellia/Makefile +++ b/src/lib/libcrypto/camellia/Makefile | |||
@@ -23,9 +23,9 @@ APPS= | |||
23 | 23 | ||
24 | LIB=$(TOP)/libcrypto.a | 24 | LIB=$(TOP)/libcrypto.a |
25 | LIBSRC=camellia.c cmll_misc.c cmll_ecb.c cmll_cbc.c cmll_ofb.c \ | 25 | LIBSRC=camellia.c cmll_misc.c cmll_ecb.c cmll_cbc.c cmll_ofb.c \ |
26 | cmll_cfb.c cmll_ctr.c | 26 | cmll_cfb.c cmll_ctr.c cmll_utl.c |
27 | 27 | ||
28 | LIBOBJ= cmll_ecb.o cmll_ofb.o cmll_cfb.o cmll_ctr.o $(CMLL_ENC) | 28 | LIBOBJ= cmll_ecb.o cmll_ofb.o cmll_cfb.o cmll_ctr.o cmll_utl.o $(CMLL_ENC) |
29 | 29 | ||
30 | SRC= $(LIBSRC) | 30 | SRC= $(LIBSRC) |
31 | 31 | ||
@@ -96,8 +96,15 @@ cmll_ctr.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h | |||
96 | cmll_ctr.o: ../../include/openssl/opensslconf.h cmll_ctr.c | 96 | cmll_ctr.o: ../../include/openssl/opensslconf.h cmll_ctr.c |
97 | cmll_ecb.o: ../../include/openssl/camellia.h | 97 | cmll_ecb.o: ../../include/openssl/camellia.h |
98 | cmll_ecb.o: ../../include/openssl/opensslconf.h cmll_ecb.c cmll_locl.h | 98 | cmll_ecb.o: ../../include/openssl/opensslconf.h cmll_ecb.c cmll_locl.h |
99 | cmll_misc.o: ../../include/openssl/camellia.h | 99 | cmll_misc.o: ../../include/openssl/camellia.h ../../include/openssl/crypto.h |
100 | cmll_misc.o: ../../include/openssl/opensslconf.h | 100 | cmll_misc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h |
101 | cmll_misc.o: ../../include/openssl/opensslv.h cmll_locl.h cmll_misc.c | 101 | cmll_misc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
102 | cmll_misc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
103 | cmll_misc.o: ../../include/openssl/symhacks.h cmll_locl.h cmll_misc.c | ||
102 | cmll_ofb.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h | 104 | cmll_ofb.o: ../../include/openssl/camellia.h ../../include/openssl/modes.h |
103 | cmll_ofb.o: ../../include/openssl/opensslconf.h cmll_ofb.c | 105 | cmll_ofb.o: ../../include/openssl/opensslconf.h cmll_ofb.c |
106 | cmll_utl.o: ../../include/openssl/camellia.h ../../include/openssl/crypto.h | ||
107 | cmll_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
108 | cmll_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
109 | cmll_utl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
110 | cmll_utl.o: ../../include/openssl/symhacks.h cmll_locl.h cmll_utl.c | ||
diff --git a/src/lib/libcrypto/camellia/cmll_utl.c b/src/lib/libcrypto/camellia/cmll_utl.c new file mode 100644 index 0000000000..7a35711ec1 --- /dev/null +++ b/src/lib/libcrypto/camellia/cmll_utl.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* crypto/camellia/cmll_utl.c -*- mode:C; c-file-style: "eay" -*- */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2011 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 | */ | ||
51 | |||
52 | #include <openssl/opensslv.h> | ||
53 | #include <openssl/crypto.h> | ||
54 | #include <openssl/camellia.h> | ||
55 | #include "cmll_locl.h" | ||
56 | |||
57 | int Camellia_set_key(const unsigned char *userKey, const int bits, | ||
58 | CAMELLIA_KEY *key) | ||
59 | { | ||
60 | #ifdef OPENSSL_FIPS | ||
61 | fips_cipher_abort(Camellia); | ||
62 | #endif | ||
63 | return private_Camellia_set_key(userKey, bits, key); | ||
64 | } | ||
diff --git a/src/lib/libcrypto/cmac/Makefile b/src/lib/libcrypto/cmac/Makefile new file mode 100644 index 0000000000..54e7cc39d5 --- /dev/null +++ b/src/lib/libcrypto/cmac/Makefile | |||
@@ -0,0 +1,111 @@ | |||
1 | # | ||
2 | # OpenSSL/crypto/cmac/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= cmac | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= | ||
9 | CFLAG=-g | ||
10 | MAKEFILE= Makefile | ||
11 | AR= ar r | ||
12 | |||
13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
14 | |||
15 | GENERAL=Makefile | ||
16 | TEST= | ||
17 | APPS= | ||
18 | |||
19 | LIB=$(TOP)/libcrypto.a | ||
20 | LIBSRC=cmac.c cm_ameth.c cm_pmeth.c | ||
21 | LIBOBJ=cmac.o cm_ameth.o cm_pmeth.o | ||
22 | |||
23 | SRC= $(LIBSRC) | ||
24 | |||
25 | EXHEADER= cmac.h | ||
26 | HEADER= $(EXHEADER) | ||
27 | |||
28 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
29 | |||
30 | top: | ||
31 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
32 | |||
33 | all: lib | ||
34 | |||
35 | lib: $(LIBOBJ) | ||
36 | $(AR) $(LIB) $(LIBOBJ) | ||
37 | $(RANLIB) $(LIB) || echo Never mind. | ||
38 | @touch lib | ||
39 | |||
40 | files: | ||
41 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
42 | |||
43 | links: | ||
44 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
45 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
46 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
47 | |||
48 | install: | ||
49 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
50 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
51 | do \ | ||
52 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
53 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
54 | done; | ||
55 | |||
56 | tags: | ||
57 | ctags $(SRC) | ||
58 | |||
59 | tests: | ||
60 | |||
61 | lint: | ||
62 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
63 | |||
64 | depend: | ||
65 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
66 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
67 | |||
68 | dclean: | ||
69 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
70 | mv -f Makefile.new $(MAKEFILE) | ||
71 | |||
72 | clean: | ||
73 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
74 | |||
75 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
76 | |||
77 | cm_ameth.o: ../../e_os.h ../../include/openssl/asn1.h | ||
78 | cm_ameth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
79 | cm_ameth.o: ../../include/openssl/cmac.h ../../include/openssl/crypto.h | ||
80 | cm_ameth.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
81 | cm_ameth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
82 | cm_ameth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
83 | cm_ameth.o: ../../include/openssl/opensslconf.h | ||
84 | cm_ameth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
85 | cm_ameth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
86 | cm_ameth.o: ../../include/openssl/symhacks.h ../asn1/asn1_locl.h ../cryptlib.h | ||
87 | cm_ameth.o: cm_ameth.c | ||
88 | cm_pmeth.o: ../../e_os.h ../../include/openssl/asn1.h | ||
89 | cm_pmeth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
90 | cm_pmeth.o: ../../include/openssl/cmac.h ../../include/openssl/conf.h | ||
91 | cm_pmeth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
92 | cm_pmeth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
93 | cm_pmeth.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
94 | cm_pmeth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
95 | cm_pmeth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
96 | cm_pmeth.o: ../../include/openssl/opensslconf.h | ||
97 | cm_pmeth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
98 | cm_pmeth.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h | ||
99 | cm_pmeth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
100 | cm_pmeth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h | ||
101 | cm_pmeth.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h | ||
102 | cm_pmeth.o: ../cryptlib.h ../evp/evp_locl.h cm_pmeth.c | ||
103 | cmac.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h | ||
104 | cmac.o: ../../include/openssl/buffer.h ../../include/openssl/cmac.h | ||
105 | cmac.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
106 | cmac.o: ../../include/openssl/err.h ../../include/openssl/evp.h | ||
107 | cmac.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h | ||
108 | cmac.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h | ||
109 | cmac.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
110 | cmac.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
111 | cmac.o: ../../include/openssl/symhacks.h ../cryptlib.h cmac.c | ||
diff --git a/src/lib/libcrypto/cms/Makefile b/src/lib/libcrypto/cms/Makefile index 5837049725..9820adb212 100644 --- a/src/lib/libcrypto/cms/Makefile +++ b/src/lib/libcrypto/cms/Makefile | |||
@@ -18,9 +18,11 @@ APPS= | |||
18 | 18 | ||
19 | LIB=$(TOP)/libcrypto.a | 19 | LIB=$(TOP)/libcrypto.a |
20 | LIBSRC= cms_lib.c cms_asn1.c cms_att.c cms_io.c cms_smime.c cms_err.c \ | 20 | LIBSRC= cms_lib.c cms_asn1.c cms_att.c cms_io.c cms_smime.c cms_err.c \ |
21 | cms_sd.c cms_dd.c cms_cd.c cms_env.c cms_enc.c cms_ess.c | 21 | cms_sd.c cms_dd.c cms_cd.c cms_env.c cms_enc.c cms_ess.c \ |
22 | cms_pwri.c | ||
22 | LIBOBJ= cms_lib.o cms_asn1.o cms_att.o cms_io.o cms_smime.o cms_err.o \ | 23 | LIBOBJ= cms_lib.o cms_asn1.o cms_att.o cms_io.o cms_smime.o cms_err.o \ |
23 | cms_sd.o cms_dd.o cms_cd.o cms_env.o cms_enc.o cms_ess.o | 24 | cms_sd.o cms_dd.o cms_cd.o cms_env.o cms_enc.o cms_ess.o \ |
25 | cms_pwri.o | ||
24 | 26 | ||
25 | SRC= $(LIBSRC) | 27 | SRC= $(LIBSRC) |
26 | 28 | ||
@@ -230,6 +232,24 @@ cms_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | |||
230 | cms_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | 232 | cms_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h |
231 | cms_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h | 233 | cms_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h |
232 | cms_lib.o: cms_lcl.h cms_lib.c | 234 | cms_lib.o: cms_lcl.h cms_lib.c |
235 | cms_pwri.o: ../../e_os.h ../../include/openssl/aes.h | ||
236 | cms_pwri.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h | ||
237 | cms_pwri.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h | ||
238 | cms_pwri.o: ../../include/openssl/cms.h ../../include/openssl/conf.h | ||
239 | cms_pwri.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
240 | cms_pwri.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h | ||
241 | cms_pwri.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h | ||
242 | cms_pwri.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
243 | cms_pwri.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
244 | cms_pwri.o: ../../include/openssl/opensslconf.h | ||
245 | cms_pwri.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
246 | cms_pwri.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h | ||
247 | cms_pwri.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h | ||
248 | cms_pwri.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
249 | cms_pwri.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
250 | cms_pwri.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h | ||
251 | cms_pwri.o: ../../include/openssl/x509v3.h ../asn1/asn1_locl.h ../cryptlib.h | ||
252 | cms_pwri.o: cms_lcl.h cms_pwri.c | ||
233 | cms_sd.o: ../../e_os.h ../../include/openssl/asn1.h | 253 | cms_sd.o: ../../e_os.h ../../include/openssl/asn1.h |
234 | cms_sd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h | 254 | cms_sd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h |
235 | cms_sd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h | 255 | cms_sd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h |
diff --git a/src/lib/libcrypto/ecdh/ecdhtest.c b/src/lib/libcrypto/ecdh/ecdhtest.c index 212a87efa4..823d7baa65 100644 --- a/src/lib/libcrypto/ecdh/ecdhtest.c +++ b/src/lib/libcrypto/ecdh/ecdhtest.c | |||
@@ -158,11 +158,13 @@ static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) | |||
158 | if (!EC_POINT_get_affine_coordinates_GFp(group, | 158 | if (!EC_POINT_get_affine_coordinates_GFp(group, |
159 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; | 159 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; |
160 | } | 160 | } |
161 | #ifndef OPENSSL_NO_EC2M | ||
161 | else | 162 | else |
162 | { | 163 | { |
163 | if (!EC_POINT_get_affine_coordinates_GF2m(group, | 164 | if (!EC_POINT_get_affine_coordinates_GF2m(group, |
164 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; | 165 | EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err; |
165 | } | 166 | } |
167 | #endif | ||
166 | #ifdef NOISY | 168 | #ifdef NOISY |
167 | BIO_puts(out," pri 1="); | 169 | BIO_puts(out," pri 1="); |
168 | BN_print(out,a->priv_key); | 170 | BN_print(out,a->priv_key); |
@@ -183,11 +185,13 @@ static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out) | |||
183 | if (!EC_POINT_get_affine_coordinates_GFp(group, | 185 | if (!EC_POINT_get_affine_coordinates_GFp(group, |
184 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; | 186 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; |
185 | } | 187 | } |
188 | #ifndef OPENSSL_NO_EC2M | ||
186 | else | 189 | else |
187 | { | 190 | { |
188 | if (!EC_POINT_get_affine_coordinates_GF2m(group, | 191 | if (!EC_POINT_get_affine_coordinates_GF2m(group, |
189 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; | 192 | EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err; |
190 | } | 193 | } |
194 | #endif | ||
191 | 195 | ||
192 | #ifdef NOISY | 196 | #ifdef NOISY |
193 | BIO_puts(out," pri 2="); | 197 | BIO_puts(out," pri 2="); |
@@ -324,6 +328,7 @@ int main(int argc, char *argv[]) | |||
324 | if (!test_ecdh_curve(NID_X9_62_prime256v1, "NIST Prime-Curve P-256", ctx, out)) goto err; | 328 | if (!test_ecdh_curve(NID_X9_62_prime256v1, "NIST Prime-Curve P-256", ctx, out)) goto err; |
325 | if (!test_ecdh_curve(NID_secp384r1, "NIST Prime-Curve P-384", ctx, out)) goto err; | 329 | if (!test_ecdh_curve(NID_secp384r1, "NIST Prime-Curve P-384", ctx, out)) goto err; |
326 | if (!test_ecdh_curve(NID_secp521r1, "NIST Prime-Curve P-521", ctx, out)) goto err; | 330 | if (!test_ecdh_curve(NID_secp521r1, "NIST Prime-Curve P-521", ctx, out)) goto err; |
331 | #ifndef OPENSSL_NO_EC2M | ||
327 | /* NIST BINARY CURVES TESTS */ | 332 | /* NIST BINARY CURVES TESTS */ |
328 | if (!test_ecdh_curve(NID_sect163k1, "NIST Binary-Curve K-163", ctx, out)) goto err; | 333 | if (!test_ecdh_curve(NID_sect163k1, "NIST Binary-Curve K-163", ctx, out)) goto err; |
329 | if (!test_ecdh_curve(NID_sect163r2, "NIST Binary-Curve B-163", ctx, out)) goto err; | 334 | if (!test_ecdh_curve(NID_sect163r2, "NIST Binary-Curve B-163", ctx, out)) goto err; |
@@ -335,6 +340,7 @@ int main(int argc, char *argv[]) | |||
335 | if (!test_ecdh_curve(NID_sect409r1, "NIST Binary-Curve B-409", ctx, out)) goto err; | 340 | if (!test_ecdh_curve(NID_sect409r1, "NIST Binary-Curve B-409", ctx, out)) goto err; |
336 | if (!test_ecdh_curve(NID_sect571k1, "NIST Binary-Curve K-571", ctx, out)) goto err; | 341 | if (!test_ecdh_curve(NID_sect571k1, "NIST Binary-Curve K-571", ctx, out)) goto err; |
337 | if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", ctx, out)) goto err; | 342 | if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", ctx, out)) goto err; |
343 | #endif | ||
338 | 344 | ||
339 | ret = 0; | 345 | ret = 0; |
340 | 346 | ||
diff --git a/src/lib/libcrypto/ecdh/ech_ossl.c b/src/lib/libcrypto/ecdh/ech_ossl.c index 2a40ff12df..4a30628fbc 100644 --- a/src/lib/libcrypto/ecdh/ech_ossl.c +++ b/src/lib/libcrypto/ecdh/ech_ossl.c | |||
@@ -157,6 +157,7 @@ static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | |||
157 | goto err; | 157 | goto err; |
158 | } | 158 | } |
159 | } | 159 | } |
160 | #ifndef OPENSSL_NO_EC2M | ||
160 | else | 161 | else |
161 | { | 162 | { |
162 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, ctx)) | 163 | if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, ctx)) |
@@ -165,6 +166,7 @@ static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, | |||
165 | goto err; | 166 | goto err; |
166 | } | 167 | } |
167 | } | 168 | } |
169 | #endif | ||
168 | 170 | ||
169 | buflen = (EC_GROUP_get_degree(group) + 7)/8; | 171 | buflen = (EC_GROUP_get_degree(group) + 7)/8; |
170 | len = BN_num_bytes(x); | 172 | len = BN_num_bytes(x); |
diff --git a/src/lib/libcrypto/ecdsa/ecdsatest.c b/src/lib/libcrypto/ecdsa/ecdsatest.c index 54cfb8c753..537bb30362 100644 --- a/src/lib/libcrypto/ecdsa/ecdsatest.c +++ b/src/lib/libcrypto/ecdsa/ecdsatest.c | |||
@@ -262,6 +262,7 @@ int x9_62_tests(BIO *out) | |||
262 | "3238135532097973577080787768312505059318910517550078427819" | 262 | "3238135532097973577080787768312505059318910517550078427819" |
263 | "78505179448783")) | 263 | "78505179448783")) |
264 | goto x962_err; | 264 | goto x962_err; |
265 | #ifndef OPENSSL_NO_EC2M | ||
265 | if (!x9_62_test_internal(out, NID_X9_62_c2tnb191v1, | 266 | if (!x9_62_test_internal(out, NID_X9_62_c2tnb191v1, |
266 | "87194383164871543355722284926904419997237591535066528048", | 267 | "87194383164871543355722284926904419997237591535066528048", |
267 | "308992691965804947361541664549085895292153777025772063598")) | 268 | "308992691965804947361541664549085895292153777025772063598")) |
@@ -272,7 +273,7 @@ int x9_62_tests(BIO *out) | |||
272 | "1970303740007316867383349976549972270528498040721988191026" | 273 | "1970303740007316867383349976549972270528498040721988191026" |
273 | "49413465737174")) | 274 | "49413465737174")) |
274 | goto x962_err; | 275 | goto x962_err; |
275 | 276 | #endif | |
276 | ret = 1; | 277 | ret = 1; |
277 | x962_err: | 278 | x962_err: |
278 | if (!restore_rand()) | 279 | if (!restore_rand()) |
@@ -289,7 +290,8 @@ int test_builtin(BIO *out) | |||
289 | ECDSA_SIG *ecdsa_sig = NULL; | 290 | ECDSA_SIG *ecdsa_sig = NULL; |
290 | unsigned char digest[20], wrong_digest[20]; | 291 | unsigned char digest[20], wrong_digest[20]; |
291 | unsigned char *signature = NULL; | 292 | unsigned char *signature = NULL; |
292 | unsigned char *sig_ptr; | 293 | const unsigned char *sig_ptr; |
294 | unsigned char *sig_ptr2; | ||
293 | unsigned char *raw_buf = NULL; | 295 | unsigned char *raw_buf = NULL; |
294 | unsigned int sig_len, degree, r_len, s_len, bn_len, buf_len; | 296 | unsigned int sig_len, degree, r_len, s_len, bn_len, buf_len; |
295 | int nid, ret = 0; | 297 | int nid, ret = 0; |
@@ -464,8 +466,8 @@ int test_builtin(BIO *out) | |||
464 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) | 466 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) |
465 | goto builtin_err; | 467 | goto builtin_err; |
466 | 468 | ||
467 | sig_ptr = signature; | 469 | sig_ptr2 = signature; |
468 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr); | 470 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); |
469 | if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) | 471 | if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1) |
470 | { | 472 | { |
471 | BIO_printf(out, " failed\n"); | 473 | BIO_printf(out, " failed\n"); |
@@ -477,8 +479,8 @@ int test_builtin(BIO *out) | |||
477 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) | 479 | (BN_bin2bn(raw_buf + bn_len, bn_len, ecdsa_sig->s) == NULL)) |
478 | goto builtin_err; | 480 | goto builtin_err; |
479 | 481 | ||
480 | sig_ptr = signature; | 482 | sig_ptr2 = signature; |
481 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr); | 483 | sig_len = i2d_ECDSA_SIG(ecdsa_sig, &sig_ptr2); |
482 | if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) | 484 | if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1) |
483 | { | 485 | { |
484 | BIO_printf(out, " failed\n"); | 486 | BIO_printf(out, " failed\n"); |
diff --git a/src/lib/libcrypto/engine/eng_rdrand.c b/src/lib/libcrypto/engine/eng_rdrand.c new file mode 100644 index 0000000000..a9ba5ae6f9 --- /dev/null +++ b/src/lib/libcrypto/engine/eng_rdrand.c | |||
@@ -0,0 +1,142 @@ | |||
1 | /* ==================================================================== | ||
2 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. | ||
3 | * | ||
4 | * Redistribution and use in source and binary forms, with or without | ||
5 | * modification, are permitted provided that the following conditions | ||
6 | * are met: | ||
7 | * | ||
8 | * 1. Redistributions of source code must retain the above copyright | ||
9 | * notice, this list of conditions and the following disclaimer. | ||
10 | * | ||
11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer in | ||
13 | * the documentation and/or other materials provided with the | ||
14 | * distribution. | ||
15 | * | ||
16 | * 3. All advertising materials mentioning features or use of this | ||
17 | * software must display the following acknowledgment: | ||
18 | * "This product includes software developed by the OpenSSL Project | ||
19 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
20 | * | ||
21 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
22 | * endorse or promote products derived from this software without | ||
23 | * prior written permission. For written permission, please contact | ||
24 | * licensing@OpenSSL.org. | ||
25 | * | ||
26 | * 5. Products derived from this software may not be called "OpenSSL" | ||
27 | * nor may "OpenSSL" appear in their names without prior written | ||
28 | * permission of the OpenSSL Project. | ||
29 | * | ||
30 | * 6. Redistributions of any form whatsoever must retain the following | ||
31 | * acknowledgment: | ||
32 | * "This product includes software developed by the OpenSSL Project | ||
33 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
34 | * | ||
35 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
36 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
37 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
38 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
39 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
40 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
41 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
42 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
44 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
45 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
46 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
47 | * ==================================================================== | ||
48 | */ | ||
49 | |||
50 | #include <openssl/opensslconf.h> | ||
51 | |||
52 | #include <stdio.h> | ||
53 | #include <string.h> | ||
54 | #include <openssl/engine.h> | ||
55 | #include <openssl/rand.h> | ||
56 | #include <openssl/err.h> | ||
57 | |||
58 | #if (defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ | ||
59 | defined(__x86_64) || defined(__x86_64__) || \ | ||
60 | defined(_M_AMD64) || defined (_M_X64)) && defined(OPENSSL_CPUID_OBJ) | ||
61 | |||
62 | size_t OPENSSL_ia32_rdrand(void); | ||
63 | |||
64 | static int get_random_bytes (unsigned char *buf, int num) | ||
65 | { | ||
66 | size_t rnd; | ||
67 | |||
68 | while (num>=(int)sizeof(size_t)) { | ||
69 | if ((rnd = OPENSSL_ia32_rdrand()) == 0) return 0; | ||
70 | |||
71 | *((size_t *)buf) = rnd; | ||
72 | buf += sizeof(size_t); | ||
73 | num -= sizeof(size_t); | ||
74 | } | ||
75 | if (num) { | ||
76 | if ((rnd = OPENSSL_ia32_rdrand()) == 0) return 0; | ||
77 | |||
78 | memcpy (buf,&rnd,num); | ||
79 | } | ||
80 | |||
81 | return 1; | ||
82 | } | ||
83 | |||
84 | static int random_status (void) | ||
85 | { return 1; } | ||
86 | |||
87 | static RAND_METHOD rdrand_meth = | ||
88 | { | ||
89 | NULL, /* seed */ | ||
90 | get_random_bytes, | ||
91 | NULL, /* cleanup */ | ||
92 | NULL, /* add */ | ||
93 | get_random_bytes, | ||
94 | random_status, | ||
95 | }; | ||
96 | |||
97 | static int rdrand_init(ENGINE *e) | ||
98 | { return 1; } | ||
99 | |||
100 | static const char *engine_e_rdrand_id = "rdrand"; | ||
101 | static const char *engine_e_rdrand_name = "Intel RDRAND engine"; | ||
102 | |||
103 | static int bind_helper(ENGINE *e) | ||
104 | { | ||
105 | if (!ENGINE_set_id(e, engine_e_rdrand_id) || | ||
106 | !ENGINE_set_name(e, engine_e_rdrand_name) || | ||
107 | !ENGINE_set_init_function(e, rdrand_init) || | ||
108 | !ENGINE_set_RAND(e, &rdrand_meth) ) | ||
109 | return 0; | ||
110 | |||
111 | return 1; | ||
112 | } | ||
113 | |||
114 | static ENGINE *ENGINE_rdrand(void) | ||
115 | { | ||
116 | ENGINE *ret = ENGINE_new(); | ||
117 | if(!ret) | ||
118 | return NULL; | ||
119 | if(!bind_helper(ret)) | ||
120 | { | ||
121 | ENGINE_free(ret); | ||
122 | return NULL; | ||
123 | } | ||
124 | return ret; | ||
125 | } | ||
126 | |||
127 | void ENGINE_load_rdrand (void) | ||
128 | { | ||
129 | extern unsigned int OPENSSL_ia32cap_P[]; | ||
130 | |||
131 | if (OPENSSL_ia32cap_P[1] & (1<<(62-32))) | ||
132 | { | ||
133 | ENGINE *toadd = ENGINE_rdrand(); | ||
134 | if(!toadd) return; | ||
135 | ENGINE_add(toadd); | ||
136 | ENGINE_free(toadd); | ||
137 | ERR_clear_error(); | ||
138 | } | ||
139 | } | ||
140 | #else | ||
141 | void ENGINE_load_rdrand (void) {} | ||
142 | #endif | ||
diff --git a/src/lib/libcrypto/engine/eng_rsax.c b/src/lib/libcrypto/engine/eng_rsax.c new file mode 100644 index 0000000000..96e63477ee --- /dev/null +++ b/src/lib/libcrypto/engine/eng_rsax.c | |||
@@ -0,0 +1,668 @@ | |||
1 | /* crypto/engine/eng_rsax.c */ | ||
2 | /* Copyright (c) 2010-2010 Intel Corp. | ||
3 | * Author: Vinodh.Gopal@intel.com | ||
4 | * Jim Guilford | ||
5 | * Erdinc.Ozturk@intel.com | ||
6 | * Maxim.Perminov@intel.com | ||
7 | * Ying.Huang@intel.com | ||
8 | * | ||
9 | * More information about algorithm used can be found at: | ||
10 | * http://www.cse.buffalo.edu/srds2009/escs2009_submission_Gopal.pdf | ||
11 | */ | ||
12 | /* ==================================================================== | ||
13 | * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved. | ||
14 | * | ||
15 | * Redistribution and use in source and binary forms, with or without | ||
16 | * modification, are permitted provided that the following conditions | ||
17 | * are met: | ||
18 | * | ||
19 | * 1. Redistributions of source code must retain the above copyright | ||
20 | * notice, this list of conditions and the following disclaimer. | ||
21 | * | ||
22 | * 2. Redistributions in binary form must reproduce the above copyright | ||
23 | * notice, this list of conditions and the following disclaimer in | ||
24 | * the documentation and/or other materials provided with the | ||
25 | * distribution. | ||
26 | * | ||
27 | * 3. All advertising materials mentioning features or use of this | ||
28 | * software must display the following acknowledgment: | ||
29 | * "This product includes software developed by the OpenSSL Project | ||
30 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
31 | * | ||
32 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
33 | * endorse or promote products derived from this software without | ||
34 | * prior written permission. For written permission, please contact | ||
35 | * licensing@OpenSSL.org. | ||
36 | * | ||
37 | * 5. Products derived from this software may not be called "OpenSSL" | ||
38 | * nor may "OpenSSL" appear in their names without prior written | ||
39 | * permission of the OpenSSL Project. | ||
40 | * | ||
41 | * 6. Redistributions of any form whatsoever must retain the following | ||
42 | * acknowledgment: | ||
43 | * "This product includes software developed by the OpenSSL Project | ||
44 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
45 | * | ||
46 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
47 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
49 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
50 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
51 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
52 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
53 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
54 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
55 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
56 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
57 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
58 | * ==================================================================== | ||
59 | * | ||
60 | * This product includes cryptographic software written by Eric Young | ||
61 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
62 | * Hudson (tjh@cryptsoft.com). | ||
63 | */ | ||
64 | |||
65 | #include <openssl/opensslconf.h> | ||
66 | |||
67 | #include <stdio.h> | ||
68 | #include <string.h> | ||
69 | #include <openssl/crypto.h> | ||
70 | #include <openssl/buffer.h> | ||
71 | #include <openssl/engine.h> | ||
72 | #ifndef OPENSSL_NO_RSA | ||
73 | #include <openssl/rsa.h> | ||
74 | #endif | ||
75 | #include <openssl/bn.h> | ||
76 | #include <openssl/err.h> | ||
77 | |||
78 | /* RSAX is available **ONLY* on x86_64 CPUs */ | ||
79 | #undef COMPILE_RSAX | ||
80 | |||
81 | #if (defined(__x86_64) || defined(__x86_64__) || \ | ||
82 | defined(_M_AMD64) || defined (_M_X64)) && !defined(OPENSSL_NO_ASM) | ||
83 | #define COMPILE_RSAX | ||
84 | static ENGINE *ENGINE_rsax (void); | ||
85 | #endif | ||
86 | |||
87 | void ENGINE_load_rsax (void) | ||
88 | { | ||
89 | /* On non-x86 CPUs it just returns. */ | ||
90 | #ifdef COMPILE_RSAX | ||
91 | ENGINE *toadd = ENGINE_rsax(); | ||
92 | if(!toadd) return; | ||
93 | ENGINE_add(toadd); | ||
94 | ENGINE_free(toadd); | ||
95 | ERR_clear_error(); | ||
96 | #endif | ||
97 | } | ||
98 | |||
99 | #ifdef COMPILE_RSAX | ||
100 | #define E_RSAX_LIB_NAME "rsax engine" | ||
101 | |||
102 | static int e_rsax_destroy(ENGINE *e); | ||
103 | static int e_rsax_init(ENGINE *e); | ||
104 | static int e_rsax_finish(ENGINE *e); | ||
105 | static int e_rsax_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); | ||
106 | |||
107 | #ifndef OPENSSL_NO_RSA | ||
108 | /* RSA stuff */ | ||
109 | static int e_rsax_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa, BN_CTX *ctx); | ||
110 | static int e_rsax_rsa_finish(RSA *r); | ||
111 | #endif | ||
112 | |||
113 | static const ENGINE_CMD_DEFN e_rsax_cmd_defns[] = { | ||
114 | {0, NULL, NULL, 0} | ||
115 | }; | ||
116 | |||
117 | #ifndef OPENSSL_NO_RSA | ||
118 | /* Our internal RSA_METHOD that we provide pointers to */ | ||
119 | static RSA_METHOD e_rsax_rsa = | ||
120 | { | ||
121 | "Intel RSA-X method", | ||
122 | NULL, | ||
123 | NULL, | ||
124 | NULL, | ||
125 | NULL, | ||
126 | e_rsax_rsa_mod_exp, | ||
127 | NULL, | ||
128 | NULL, | ||
129 | e_rsax_rsa_finish, | ||
130 | RSA_FLAG_CACHE_PUBLIC|RSA_FLAG_CACHE_PRIVATE, | ||
131 | NULL, | ||
132 | NULL, | ||
133 | NULL | ||
134 | }; | ||
135 | #endif | ||
136 | |||
137 | /* Constants used when creating the ENGINE */ | ||
138 | static const char *engine_e_rsax_id = "rsax"; | ||
139 | static const char *engine_e_rsax_name = "RSAX engine support"; | ||
140 | |||
141 | /* This internal function is used by ENGINE_rsax() */ | ||
142 | static int bind_helper(ENGINE *e) | ||
143 | { | ||
144 | #ifndef OPENSSL_NO_RSA | ||
145 | const RSA_METHOD *meth1; | ||
146 | #endif | ||
147 | if(!ENGINE_set_id(e, engine_e_rsax_id) || | ||
148 | !ENGINE_set_name(e, engine_e_rsax_name) || | ||
149 | #ifndef OPENSSL_NO_RSA | ||
150 | !ENGINE_set_RSA(e, &e_rsax_rsa) || | ||
151 | #endif | ||
152 | !ENGINE_set_destroy_function(e, e_rsax_destroy) || | ||
153 | !ENGINE_set_init_function(e, e_rsax_init) || | ||
154 | !ENGINE_set_finish_function(e, e_rsax_finish) || | ||
155 | !ENGINE_set_ctrl_function(e, e_rsax_ctrl) || | ||
156 | !ENGINE_set_cmd_defns(e, e_rsax_cmd_defns)) | ||
157 | return 0; | ||
158 | |||
159 | #ifndef OPENSSL_NO_RSA | ||
160 | meth1 = RSA_PKCS1_SSLeay(); | ||
161 | e_rsax_rsa.rsa_pub_enc = meth1->rsa_pub_enc; | ||
162 | e_rsax_rsa.rsa_pub_dec = meth1->rsa_pub_dec; | ||
163 | e_rsax_rsa.rsa_priv_enc = meth1->rsa_priv_enc; | ||
164 | e_rsax_rsa.rsa_priv_dec = meth1->rsa_priv_dec; | ||
165 | e_rsax_rsa.bn_mod_exp = meth1->bn_mod_exp; | ||
166 | #endif | ||
167 | return 1; | ||
168 | } | ||
169 | |||
170 | static ENGINE *ENGINE_rsax(void) | ||
171 | { | ||
172 | ENGINE *ret = ENGINE_new(); | ||
173 | if(!ret) | ||
174 | return NULL; | ||
175 | if(!bind_helper(ret)) | ||
176 | { | ||
177 | ENGINE_free(ret); | ||
178 | return NULL; | ||
179 | } | ||
180 | return ret; | ||
181 | } | ||
182 | |||
183 | #ifndef OPENSSL_NO_RSA | ||
184 | /* Used to attach our own key-data to an RSA structure */ | ||
185 | static int rsax_ex_data_idx = -1; | ||
186 | #endif | ||
187 | |||
188 | static int e_rsax_destroy(ENGINE *e) | ||
189 | { | ||
190 | return 1; | ||
191 | } | ||
192 | |||
193 | /* (de)initialisation functions. */ | ||
194 | static int e_rsax_init(ENGINE *e) | ||
195 | { | ||
196 | #ifndef OPENSSL_NO_RSA | ||
197 | if (rsax_ex_data_idx == -1) | ||
198 | rsax_ex_data_idx = RSA_get_ex_new_index(0, | ||
199 | NULL, | ||
200 | NULL, NULL, NULL); | ||
201 | #endif | ||
202 | if (rsax_ex_data_idx == -1) | ||
203 | return 0; | ||
204 | return 1; | ||
205 | } | ||
206 | |||
207 | static int e_rsax_finish(ENGINE *e) | ||
208 | { | ||
209 | return 1; | ||
210 | } | ||
211 | |||
212 | static int e_rsax_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) | ||
213 | { | ||
214 | int to_return = 1; | ||
215 | |||
216 | switch(cmd) | ||
217 | { | ||
218 | /* The command isn't understood by this engine */ | ||
219 | default: | ||
220 | to_return = 0; | ||
221 | break; | ||
222 | } | ||
223 | |||
224 | return to_return; | ||
225 | } | ||
226 | |||
227 | |||
228 | #ifndef OPENSSL_NO_RSA | ||
229 | |||
230 | #ifdef _WIN32 | ||
231 | typedef unsigned __int64 UINT64; | ||
232 | #else | ||
233 | typedef unsigned long long UINT64; | ||
234 | #endif | ||
235 | typedef unsigned short UINT16; | ||
236 | |||
237 | /* Table t is interleaved in the following manner: | ||
238 | * The order in memory is t[0][0], t[0][1], ..., t[0][7], t[1][0], ... | ||
239 | * A particular 512-bit value is stored in t[][index] rather than the more | ||
240 | * normal t[index][]; i.e. the qwords of a particular entry in t are not | ||
241 | * adjacent in memory | ||
242 | */ | ||
243 | |||
244 | /* Init BIGNUM b from the interleaved UINT64 array */ | ||
245 | static int interleaved_array_to_bn_512(BIGNUM* b, UINT64 *array); | ||
246 | |||
247 | /* Extract array elements from BIGNUM b | ||
248 | * To set the whole array from b, call with n=8 | ||
249 | */ | ||
250 | static int bn_extract_to_array_512(const BIGNUM* b, unsigned int n, UINT64 *array); | ||
251 | |||
252 | struct mod_ctx_512 { | ||
253 | UINT64 t[8][8]; | ||
254 | UINT64 m[8]; | ||
255 | UINT64 m1[8]; /* 2^278 % m */ | ||
256 | UINT64 m2[8]; /* 2^640 % m */ | ||
257 | UINT64 k1[2]; /* (- 1/m) % 2^128 */ | ||
258 | }; | ||
259 | |||
260 | static int mod_exp_pre_compute_data_512(UINT64 *m, struct mod_ctx_512 *data); | ||
261 | |||
262 | void mod_exp_512(UINT64 *result, /* 512 bits, 8 qwords */ | ||
263 | UINT64 *g, /* 512 bits, 8 qwords */ | ||
264 | UINT64 *exp, /* 512 bits, 8 qwords */ | ||
265 | struct mod_ctx_512 *data); | ||
266 | |||
267 | typedef struct st_e_rsax_mod_ctx | ||
268 | { | ||
269 | UINT64 type; | ||
270 | union { | ||
271 | struct mod_ctx_512 b512; | ||
272 | } ctx; | ||
273 | |||
274 | } E_RSAX_MOD_CTX; | ||
275 | |||
276 | static E_RSAX_MOD_CTX *e_rsax_get_ctx(RSA *rsa, int idx, BIGNUM* m) | ||
277 | { | ||
278 | E_RSAX_MOD_CTX *hptr; | ||
279 | |||
280 | if (idx < 0 || idx > 2) | ||
281 | return NULL; | ||
282 | |||
283 | hptr = RSA_get_ex_data(rsa, rsax_ex_data_idx); | ||
284 | if (!hptr) { | ||
285 | hptr = OPENSSL_malloc(3*sizeof(E_RSAX_MOD_CTX)); | ||
286 | if (!hptr) return NULL; | ||
287 | hptr[2].type = hptr[1].type= hptr[0].type = 0; | ||
288 | RSA_set_ex_data(rsa, rsax_ex_data_idx, hptr); | ||
289 | } | ||
290 | |||
291 | if (hptr[idx].type == (UINT64)BN_num_bits(m)) | ||
292 | return hptr+idx; | ||
293 | |||
294 | if (BN_num_bits(m) == 512) { | ||
295 | UINT64 _m[8]; | ||
296 | bn_extract_to_array_512(m, 8, _m); | ||
297 | memset( &hptr[idx].ctx.b512, 0, sizeof(struct mod_ctx_512)); | ||
298 | mod_exp_pre_compute_data_512(_m, &hptr[idx].ctx.b512); | ||
299 | } | ||
300 | |||
301 | hptr[idx].type = BN_num_bits(m); | ||
302 | return hptr+idx; | ||
303 | } | ||
304 | |||
305 | static int e_rsax_rsa_finish(RSA *rsa) | ||
306 | { | ||
307 | E_RSAX_MOD_CTX *hptr = RSA_get_ex_data(rsa, rsax_ex_data_idx); | ||
308 | if(hptr) | ||
309 | { | ||
310 | OPENSSL_free(hptr); | ||
311 | RSA_set_ex_data(rsa, rsax_ex_data_idx, NULL); | ||
312 | } | ||
313 | if (rsa->_method_mod_n) | ||
314 | BN_MONT_CTX_free(rsa->_method_mod_n); | ||
315 | if (rsa->_method_mod_p) | ||
316 | BN_MONT_CTX_free(rsa->_method_mod_p); | ||
317 | if (rsa->_method_mod_q) | ||
318 | BN_MONT_CTX_free(rsa->_method_mod_q); | ||
319 | return 1; | ||
320 | } | ||
321 | |||
322 | |||
323 | static int e_rsax_bn_mod_exp(BIGNUM *r, const BIGNUM *g, const BIGNUM *e, | ||
324 | const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont, E_RSAX_MOD_CTX* rsax_mod_ctx ) | ||
325 | { | ||
326 | if (rsax_mod_ctx && BN_get_flags(e, BN_FLG_CONSTTIME) != 0) { | ||
327 | if (BN_num_bits(m) == 512) { | ||
328 | UINT64 _r[8]; | ||
329 | UINT64 _g[8]; | ||
330 | UINT64 _e[8]; | ||
331 | |||
332 | /* Init the arrays from the BIGNUMs */ | ||
333 | bn_extract_to_array_512(g, 8, _g); | ||
334 | bn_extract_to_array_512(e, 8, _e); | ||
335 | |||
336 | mod_exp_512(_r, _g, _e, &rsax_mod_ctx->ctx.b512); | ||
337 | /* Return the result in the BIGNUM */ | ||
338 | interleaved_array_to_bn_512(r, _r); | ||
339 | return 1; | ||
340 | } | ||
341 | } | ||
342 | |||
343 | return BN_mod_exp_mont(r, g, e, m, ctx, in_mont); | ||
344 | } | ||
345 | |||
346 | /* Declares for the Intel CIAP 512-bit / CRT / 1024 bit RSA modular | ||
347 | * exponentiation routine precalculations and a structure to hold the | ||
348 | * necessary values. These files are meant to live in crypto/rsa/ in | ||
349 | * the target openssl. | ||
350 | */ | ||
351 | |||
352 | /* | ||
353 | * Local method: extracts a piece from a BIGNUM, to fit it into | ||
354 | * an array. Call with n=8 to extract an entire 512-bit BIGNUM | ||
355 | */ | ||
356 | static int bn_extract_to_array_512(const BIGNUM* b, unsigned int n, UINT64 *array) | ||
357 | { | ||
358 | int i; | ||
359 | UINT64 tmp; | ||
360 | unsigned char bn_buff[64]; | ||
361 | memset(bn_buff, 0, 64); | ||
362 | if (BN_num_bytes(b) > 64) { | ||
363 | printf ("Can't support this byte size\n"); | ||
364 | return 0; } | ||
365 | if (BN_num_bytes(b)!=0) { | ||
366 | if (!BN_bn2bin(b, bn_buff+(64-BN_num_bytes(b)))) { | ||
367 | printf ("Error's in bn2bin\n"); | ||
368 | /* We have to error, here */ | ||
369 | return 0; } } | ||
370 | while (n-- > 0) { | ||
371 | array[n] = 0; | ||
372 | for (i=7; i>=0; i--) { | ||
373 | tmp = bn_buff[63-(n*8+i)]; | ||
374 | array[n] |= tmp << (8*i); } } | ||
375 | return 1; | ||
376 | } | ||
377 | |||
378 | /* Init a 512-bit BIGNUM from the UINT64*_ (8 * 64) interleaved array */ | ||
379 | static int interleaved_array_to_bn_512(BIGNUM* b, UINT64 *array) | ||
380 | { | ||
381 | unsigned char tmp[64]; | ||
382 | int n=8; | ||
383 | int i; | ||
384 | while (n-- > 0) { | ||
385 | for (i = 7; i>=0; i--) { | ||
386 | tmp[63-(n*8+i)] = (unsigned char)(array[n]>>(8*i)); } } | ||
387 | BN_bin2bn(tmp, 64, b); | ||
388 | return 0; | ||
389 | } | ||
390 | |||
391 | |||
392 | /* The main 512bit precompute call */ | ||
393 | static int mod_exp_pre_compute_data_512(UINT64 *m, struct mod_ctx_512 *data) | ||
394 | { | ||
395 | BIGNUM two_768, two_640, two_128, two_512, tmp, _m, tmp2; | ||
396 | |||
397 | /* We need a BN_CTX for the modulo functions */ | ||
398 | BN_CTX* ctx; | ||
399 | /* Some tmps */ | ||
400 | UINT64 _t[8]; | ||
401 | int i, j, ret = 0; | ||
402 | |||
403 | /* Init _m with m */ | ||
404 | BN_init(&_m); | ||
405 | interleaved_array_to_bn_512(&_m, m); | ||
406 | memset(_t, 0, 64); | ||
407 | |||
408 | /* Inits */ | ||
409 | BN_init(&two_768); | ||
410 | BN_init(&two_640); | ||
411 | BN_init(&two_128); | ||
412 | BN_init(&two_512); | ||
413 | BN_init(&tmp); | ||
414 | BN_init(&tmp2); | ||
415 | |||
416 | /* Create our context */ | ||
417 | if ((ctx=BN_CTX_new()) == NULL) { goto err; } | ||
418 | BN_CTX_start(ctx); | ||
419 | |||
420 | /* | ||
421 | * For production, if you care, these only need to be set once, | ||
422 | * and may be made constants. | ||
423 | */ | ||
424 | BN_lshift(&two_768, BN_value_one(), 768); | ||
425 | BN_lshift(&two_640, BN_value_one(), 640); | ||
426 | BN_lshift(&two_128, BN_value_one(), 128); | ||
427 | BN_lshift(&two_512, BN_value_one(), 512); | ||
428 | |||
429 | if (0 == (m[7] & 0x8000000000000000)) { | ||
430 | exit(1); | ||
431 | } | ||
432 | if (0 == (m[0] & 0x1)) { /* Odd modulus required for Mont */ | ||
433 | exit(1); | ||
434 | } | ||
435 | |||
436 | /* Precompute m1 */ | ||
437 | BN_mod(&tmp, &two_768, &_m, ctx); | ||
438 | if (!bn_extract_to_array_512(&tmp, 8, &data->m1[0])) { | ||
439 | goto err; } | ||
440 | |||
441 | /* Precompute m2 */ | ||
442 | BN_mod(&tmp, &two_640, &_m, ctx); | ||
443 | if (!bn_extract_to_array_512(&tmp, 8, &data->m2[0])) { | ||
444 | goto err; | ||
445 | } | ||
446 | |||
447 | /* | ||
448 | * Precompute k1, a 128b number = ((-1)* m-1 ) mod 2128; k1 should | ||
449 | * be non-negative. | ||
450 | */ | ||
451 | BN_mod_inverse(&tmp, &_m, &two_128, ctx); | ||
452 | if (!BN_is_zero(&tmp)) { BN_sub(&tmp, &two_128, &tmp); } | ||
453 | if (!bn_extract_to_array_512(&tmp, 2, &data->k1[0])) { | ||
454 | goto err; } | ||
455 | |||
456 | /* Precompute t */ | ||
457 | for (i=0; i<8; i++) { | ||
458 | BN_zero(&tmp); | ||
459 | if (i & 1) { BN_add(&tmp, &two_512, &tmp); } | ||
460 | if (i & 2) { BN_add(&tmp, &two_512, &tmp); } | ||
461 | if (i & 4) { BN_add(&tmp, &two_640, &tmp); } | ||
462 | |||
463 | BN_nnmod(&tmp2, &tmp, &_m, ctx); | ||
464 | if (!bn_extract_to_array_512(&tmp2, 8, _t)) { | ||
465 | goto err; } | ||
466 | for (j=0; j<8; j++) data->t[j][i] = _t[j]; } | ||
467 | |||
468 | /* Precompute m */ | ||
469 | for (i=0; i<8; i++) { | ||
470 | data->m[i] = m[i]; } | ||
471 | |||
472 | ret = 1; | ||
473 | |||
474 | err: | ||
475 | /* Cleanup */ | ||
476 | if (ctx != NULL) { | ||
477 | BN_CTX_end(ctx); BN_CTX_free(ctx); } | ||
478 | BN_free(&two_768); | ||
479 | BN_free(&two_640); | ||
480 | BN_free(&two_128); | ||
481 | BN_free(&two_512); | ||
482 | BN_free(&tmp); | ||
483 | BN_free(&tmp2); | ||
484 | BN_free(&_m); | ||
485 | |||
486 | return ret; | ||
487 | } | ||
488 | |||
489 | |||
490 | static int e_rsax_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) | ||
491 | { | ||
492 | BIGNUM *r1,*m1,*vrfy; | ||
493 | BIGNUM local_dmp1,local_dmq1,local_c,local_r1; | ||
494 | BIGNUM *dmp1,*dmq1,*c,*pr1; | ||
495 | int ret=0; | ||
496 | |||
497 | BN_CTX_start(ctx); | ||
498 | r1 = BN_CTX_get(ctx); | ||
499 | m1 = BN_CTX_get(ctx); | ||
500 | vrfy = BN_CTX_get(ctx); | ||
501 | |||
502 | { | ||
503 | BIGNUM local_p, local_q; | ||
504 | BIGNUM *p = NULL, *q = NULL; | ||
505 | int error = 0; | ||
506 | |||
507 | /* Make sure BN_mod_inverse in Montgomery | ||
508 | * intialization uses the BN_FLG_CONSTTIME flag | ||
509 | * (unless RSA_FLAG_NO_CONSTTIME is set) | ||
510 | */ | ||
511 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
512 | { | ||
513 | BN_init(&local_p); | ||
514 | p = &local_p; | ||
515 | BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME); | ||
516 | |||
517 | BN_init(&local_q); | ||
518 | q = &local_q; | ||
519 | BN_with_flags(q, rsa->q, BN_FLG_CONSTTIME); | ||
520 | } | ||
521 | else | ||
522 | { | ||
523 | p = rsa->p; | ||
524 | q = rsa->q; | ||
525 | } | ||
526 | |||
527 | if (rsa->flags & RSA_FLAG_CACHE_PRIVATE) | ||
528 | { | ||
529 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_p, CRYPTO_LOCK_RSA, p, ctx)) | ||
530 | error = 1; | ||
531 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_q, CRYPTO_LOCK_RSA, q, ctx)) | ||
532 | error = 1; | ||
533 | } | ||
534 | |||
535 | /* clean up */ | ||
536 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
537 | { | ||
538 | BN_free(&local_p); | ||
539 | BN_free(&local_q); | ||
540 | } | ||
541 | if ( error ) | ||
542 | goto err; | ||
543 | } | ||
544 | |||
545 | if (rsa->flags & RSA_FLAG_CACHE_PUBLIC) | ||
546 | if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n, CRYPTO_LOCK_RSA, rsa->n, ctx)) | ||
547 | goto err; | ||
548 | |||
549 | /* compute I mod q */ | ||
550 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
551 | { | ||
552 | c = &local_c; | ||
553 | BN_with_flags(c, I, BN_FLG_CONSTTIME); | ||
554 | if (!BN_mod(r1,c,rsa->q,ctx)) goto err; | ||
555 | } | ||
556 | else | ||
557 | { | ||
558 | if (!BN_mod(r1,I,rsa->q,ctx)) goto err; | ||
559 | } | ||
560 | |||
561 | /* compute r1^dmq1 mod q */ | ||
562 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
563 | { | ||
564 | dmq1 = &local_dmq1; | ||
565 | BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME); | ||
566 | } | ||
567 | else | ||
568 | dmq1 = rsa->dmq1; | ||
569 | |||
570 | if (!e_rsax_bn_mod_exp(m1,r1,dmq1,rsa->q,ctx, | ||
571 | rsa->_method_mod_q, e_rsax_get_ctx(rsa, 0, rsa->q) )) goto err; | ||
572 | |||
573 | /* compute I mod p */ | ||
574 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
575 | { | ||
576 | c = &local_c; | ||
577 | BN_with_flags(c, I, BN_FLG_CONSTTIME); | ||
578 | if (!BN_mod(r1,c,rsa->p,ctx)) goto err; | ||
579 | } | ||
580 | else | ||
581 | { | ||
582 | if (!BN_mod(r1,I,rsa->p,ctx)) goto err; | ||
583 | } | ||
584 | |||
585 | /* compute r1^dmp1 mod p */ | ||
586 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
587 | { | ||
588 | dmp1 = &local_dmp1; | ||
589 | BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME); | ||
590 | } | ||
591 | else | ||
592 | dmp1 = rsa->dmp1; | ||
593 | |||
594 | if (!e_rsax_bn_mod_exp(r0,r1,dmp1,rsa->p,ctx, | ||
595 | rsa->_method_mod_p, e_rsax_get_ctx(rsa, 1, rsa->p) )) goto err; | ||
596 | |||
597 | if (!BN_sub(r0,r0,m1)) goto err; | ||
598 | /* This will help stop the size of r0 increasing, which does | ||
599 | * affect the multiply if it optimised for a power of 2 size */ | ||
600 | if (BN_is_negative(r0)) | ||
601 | if (!BN_add(r0,r0,rsa->p)) goto err; | ||
602 | |||
603 | if (!BN_mul(r1,r0,rsa->iqmp,ctx)) goto err; | ||
604 | |||
605 | /* Turn BN_FLG_CONSTTIME flag on before division operation */ | ||
606 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
607 | { | ||
608 | pr1 = &local_r1; | ||
609 | BN_with_flags(pr1, r1, BN_FLG_CONSTTIME); | ||
610 | } | ||
611 | else | ||
612 | pr1 = r1; | ||
613 | if (!BN_mod(r0,pr1,rsa->p,ctx)) goto err; | ||
614 | |||
615 | /* If p < q it is occasionally possible for the correction of | ||
616 | * adding 'p' if r0 is negative above to leave the result still | ||
617 | * negative. This can break the private key operations: the following | ||
618 | * second correction should *always* correct this rare occurrence. | ||
619 | * This will *never* happen with OpenSSL generated keys because | ||
620 | * they ensure p > q [steve] | ||
621 | */ | ||
622 | if (BN_is_negative(r0)) | ||
623 | if (!BN_add(r0,r0,rsa->p)) goto err; | ||
624 | if (!BN_mul(r1,r0,rsa->q,ctx)) goto err; | ||
625 | if (!BN_add(r0,r1,m1)) goto err; | ||
626 | |||
627 | if (rsa->e && rsa->n) | ||
628 | { | ||
629 | if (!e_rsax_bn_mod_exp(vrfy,r0,rsa->e,rsa->n,ctx,rsa->_method_mod_n, e_rsax_get_ctx(rsa, 2, rsa->n) )) | ||
630 | goto err; | ||
631 | |||
632 | /* If 'I' was greater than (or equal to) rsa->n, the operation | ||
633 | * will be equivalent to using 'I mod n'. However, the result of | ||
634 | * the verify will *always* be less than 'n' so we don't check | ||
635 | * for absolute equality, just congruency. */ | ||
636 | if (!BN_sub(vrfy, vrfy, I)) goto err; | ||
637 | if (!BN_mod(vrfy, vrfy, rsa->n, ctx)) goto err; | ||
638 | if (BN_is_negative(vrfy)) | ||
639 | if (!BN_add(vrfy, vrfy, rsa->n)) goto err; | ||
640 | if (!BN_is_zero(vrfy)) | ||
641 | { | ||
642 | /* 'I' and 'vrfy' aren't congruent mod n. Don't leak | ||
643 | * miscalculated CRT output, just do a raw (slower) | ||
644 | * mod_exp and return that instead. */ | ||
645 | |||
646 | BIGNUM local_d; | ||
647 | BIGNUM *d = NULL; | ||
648 | |||
649 | if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) | ||
650 | { | ||
651 | d = &local_d; | ||
652 | BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME); | ||
653 | } | ||
654 | else | ||
655 | d = rsa->d; | ||
656 | if (!e_rsax_bn_mod_exp(r0,I,d,rsa->n,ctx, | ||
657 | rsa->_method_mod_n, e_rsax_get_ctx(rsa, 2, rsa->n) )) goto err; | ||
658 | } | ||
659 | } | ||
660 | ret=1; | ||
661 | |||
662 | err: | ||
663 | BN_CTX_end(ctx); | ||
664 | |||
665 | return ret; | ||
666 | } | ||
667 | #endif /* !OPENSSL_NO_RSA */ | ||
668 | #endif /* !COMPILE_RSAX */ | ||
diff --git a/src/lib/libcrypto/evp/evp_fips.c b/src/lib/libcrypto/evp/evp_fips.c new file mode 100644 index 0000000000..cb7f4fc0fa --- /dev/null +++ b/src/lib/libcrypto/evp/evp_fips.c | |||
@@ -0,0 +1,113 @@ | |||
1 | /* crypto/evp/evp_fips.c */ | ||
2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
3 | * project. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | */ | ||
53 | |||
54 | |||
55 | #include <openssl/evp.h> | ||
56 | |||
57 | #ifdef OPENSSL_FIPS | ||
58 | #include <openssl/fips.h> | ||
59 | |||
60 | const EVP_CIPHER *EVP_aes_128_cbc(void) { return FIPS_evp_aes_128_cbc(); } | ||
61 | const EVP_CIPHER *EVP_aes_128_ccm(void) { return FIPS_evp_aes_128_ccm(); } | ||
62 | const EVP_CIPHER *EVP_aes_128_cfb1(void) { return FIPS_evp_aes_128_cfb1(); } | ||
63 | const EVP_CIPHER *EVP_aes_128_cfb128(void) { return FIPS_evp_aes_128_cfb128(); } | ||
64 | const EVP_CIPHER *EVP_aes_128_cfb8(void) { return FIPS_evp_aes_128_cfb8(); } | ||
65 | const EVP_CIPHER *EVP_aes_128_ctr(void) { return FIPS_evp_aes_128_ctr(); } | ||
66 | const EVP_CIPHER *EVP_aes_128_ecb(void) { return FIPS_evp_aes_128_ecb(); } | ||
67 | const EVP_CIPHER *EVP_aes_128_gcm(void) { return FIPS_evp_aes_128_gcm(); } | ||
68 | const EVP_CIPHER *EVP_aes_128_ofb(void) { return FIPS_evp_aes_128_ofb(); } | ||
69 | const EVP_CIPHER *EVP_aes_128_xts(void) { return FIPS_evp_aes_128_xts(); } | ||
70 | const EVP_CIPHER *EVP_aes_192_cbc(void) { return FIPS_evp_aes_192_cbc(); } | ||
71 | const EVP_CIPHER *EVP_aes_192_ccm(void) { return FIPS_evp_aes_192_ccm(); } | ||
72 | const EVP_CIPHER *EVP_aes_192_cfb1(void) { return FIPS_evp_aes_192_cfb1(); } | ||
73 | const EVP_CIPHER *EVP_aes_192_cfb128(void) { return FIPS_evp_aes_192_cfb128(); } | ||
74 | const EVP_CIPHER *EVP_aes_192_cfb8(void) { return FIPS_evp_aes_192_cfb8(); } | ||
75 | const EVP_CIPHER *EVP_aes_192_ctr(void) { return FIPS_evp_aes_192_ctr(); } | ||
76 | const EVP_CIPHER *EVP_aes_192_ecb(void) { return FIPS_evp_aes_192_ecb(); } | ||
77 | const EVP_CIPHER *EVP_aes_192_gcm(void) { return FIPS_evp_aes_192_gcm(); } | ||
78 | const EVP_CIPHER *EVP_aes_192_ofb(void) { return FIPS_evp_aes_192_ofb(); } | ||
79 | const EVP_CIPHER *EVP_aes_256_cbc(void) { return FIPS_evp_aes_256_cbc(); } | ||
80 | const EVP_CIPHER *EVP_aes_256_ccm(void) { return FIPS_evp_aes_256_ccm(); } | ||
81 | const EVP_CIPHER *EVP_aes_256_cfb1(void) { return FIPS_evp_aes_256_cfb1(); } | ||
82 | const EVP_CIPHER *EVP_aes_256_cfb128(void) { return FIPS_evp_aes_256_cfb128(); } | ||
83 | const EVP_CIPHER *EVP_aes_256_cfb8(void) { return FIPS_evp_aes_256_cfb8(); } | ||
84 | const EVP_CIPHER *EVP_aes_256_ctr(void) { return FIPS_evp_aes_256_ctr(); } | ||
85 | const EVP_CIPHER *EVP_aes_256_ecb(void) { return FIPS_evp_aes_256_ecb(); } | ||
86 | const EVP_CIPHER *EVP_aes_256_gcm(void) { return FIPS_evp_aes_256_gcm(); } | ||
87 | const EVP_CIPHER *EVP_aes_256_ofb(void) { return FIPS_evp_aes_256_ofb(); } | ||
88 | const EVP_CIPHER *EVP_aes_256_xts(void) { return FIPS_evp_aes_256_xts(); } | ||
89 | const EVP_CIPHER *EVP_des_ede(void) { return FIPS_evp_des_ede(); } | ||
90 | const EVP_CIPHER *EVP_des_ede3(void) { return FIPS_evp_des_ede3(); } | ||
91 | const EVP_CIPHER *EVP_des_ede3_cbc(void) { return FIPS_evp_des_ede3_cbc(); } | ||
92 | const EVP_CIPHER *EVP_des_ede3_cfb1(void) { return FIPS_evp_des_ede3_cfb1(); } | ||
93 | const EVP_CIPHER *EVP_des_ede3_cfb64(void) { return FIPS_evp_des_ede3_cfb64(); } | ||
94 | const EVP_CIPHER *EVP_des_ede3_cfb8(void) { return FIPS_evp_des_ede3_cfb8(); } | ||
95 | const EVP_CIPHER *EVP_des_ede3_ecb(void) { return FIPS_evp_des_ede3_ecb(); } | ||
96 | const EVP_CIPHER *EVP_des_ede3_ofb(void) { return FIPS_evp_des_ede3_ofb(); } | ||
97 | const EVP_CIPHER *EVP_des_ede_cbc(void) { return FIPS_evp_des_ede_cbc(); } | ||
98 | const EVP_CIPHER *EVP_des_ede_cfb64(void) { return FIPS_evp_des_ede_cfb64(); } | ||
99 | const EVP_CIPHER *EVP_des_ede_ecb(void) { return FIPS_evp_des_ede_ecb(); } | ||
100 | const EVP_CIPHER *EVP_des_ede_ofb(void) { return FIPS_evp_des_ede_ofb(); } | ||
101 | const EVP_CIPHER *EVP_enc_null(void) { return FIPS_evp_enc_null(); } | ||
102 | |||
103 | const EVP_MD *EVP_sha1(void) { return FIPS_evp_sha1(); } | ||
104 | const EVP_MD *EVP_sha224(void) { return FIPS_evp_sha224(); } | ||
105 | const EVP_MD *EVP_sha256(void) { return FIPS_evp_sha256(); } | ||
106 | const EVP_MD *EVP_sha384(void) { return FIPS_evp_sha384(); } | ||
107 | const EVP_MD *EVP_sha512(void) { return FIPS_evp_sha512(); } | ||
108 | |||
109 | const EVP_MD *EVP_dss(void) { return FIPS_evp_dss(); } | ||
110 | const EVP_MD *EVP_dss1(void) { return FIPS_evp_dss1(); } | ||
111 | const EVP_MD *EVP_ecdsa(void) { return FIPS_evp_ecdsa(); } | ||
112 | |||
113 | #endif | ||
diff --git a/src/lib/libcrypto/fips_err.h b/src/lib/libcrypto/fips_err.h index b328616858..c671691b47 100644 --- a/src/lib/libcrypto/fips_err.h +++ b/src/lib/libcrypto/fips_err.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/fips_err.h */ | 1 | /* crypto/fips_err.h */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -71,53 +71,125 @@ | |||
71 | static ERR_STRING_DATA FIPS_str_functs[]= | 71 | static ERR_STRING_DATA FIPS_str_functs[]= |
72 | { | 72 | { |
73 | {ERR_FUNC(FIPS_F_DH_BUILTIN_GENPARAMS), "DH_BUILTIN_GENPARAMS"}, | 73 | {ERR_FUNC(FIPS_F_DH_BUILTIN_GENPARAMS), "DH_BUILTIN_GENPARAMS"}, |
74 | {ERR_FUNC(FIPS_F_DH_INIT), "DH_INIT"}, | ||
75 | {ERR_FUNC(FIPS_F_DRBG_RESEED), "DRBG_RESEED"}, | ||
74 | {ERR_FUNC(FIPS_F_DSA_BUILTIN_PARAMGEN), "DSA_BUILTIN_PARAMGEN"}, | 76 | {ERR_FUNC(FIPS_F_DSA_BUILTIN_PARAMGEN), "DSA_BUILTIN_PARAMGEN"}, |
77 | {ERR_FUNC(FIPS_F_DSA_BUILTIN_PARAMGEN2), "DSA_BUILTIN_PARAMGEN2"}, | ||
75 | {ERR_FUNC(FIPS_F_DSA_DO_SIGN), "DSA_do_sign"}, | 78 | {ERR_FUNC(FIPS_F_DSA_DO_SIGN), "DSA_do_sign"}, |
76 | {ERR_FUNC(FIPS_F_DSA_DO_VERIFY), "DSA_do_verify"}, | 79 | {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_DSA), "FIPS_CHECK_DSA"}, |
80 | {ERR_FUNC(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT), "FIPS_CHECK_INCORE_FINGERPRINT"}, | 81 | {ERR_FUNC(FIPS_F_FIPS_CHECK_DSA_PRNG), "fips_check_dsa_prng"}, |
81 | {ERR_FUNC(FIPS_F_FIPS_CHECK_RSA), "FIPS_CHECK_RSA"}, | 82 | {ERR_FUNC(FIPS_F_FIPS_CHECK_EC), "FIPS_CHECK_EC"}, |
82 | {ERR_FUNC(FIPS_F_FIPS_DSA_CHECK), "FIPS_DSA_CHECK"}, | 83 | {ERR_FUNC(FIPS_F_FIPS_CHECK_EC_PRNG), "fips_check_ec_prng"}, |
83 | {ERR_FUNC(FIPS_F_FIPS_MODE_SET), "FIPS_mode_set"}, | 84 | {ERR_FUNC(FIPS_F_FIPS_CHECK_INCORE_FINGERPRINT), "FIPS_check_incore_fingerprint"}, |
85 | {ERR_FUNC(FIPS_F_FIPS_CHECK_RSA), "fips_check_rsa"}, | ||
86 | {ERR_FUNC(FIPS_F_FIPS_CHECK_RSA_PRNG), "fips_check_rsa_prng"}, | ||
87 | {ERR_FUNC(FIPS_F_FIPS_CIPHER), "FIPS_cipher"}, | ||
88 | {ERR_FUNC(FIPS_F_FIPS_CIPHERINIT), "FIPS_cipherinit"}, | ||
89 | {ERR_FUNC(FIPS_F_FIPS_CIPHER_CTX_CTRL), "FIPS_CIPHER_CTX_CTRL"}, | ||
90 | {ERR_FUNC(FIPS_F_FIPS_DIGESTFINAL), "FIPS_digestfinal"}, | ||
91 | {ERR_FUNC(FIPS_F_FIPS_DIGESTINIT), "FIPS_digestinit"}, | ||
92 | {ERR_FUNC(FIPS_F_FIPS_DIGESTUPDATE), "FIPS_digestupdate"}, | ||
93 | {ERR_FUNC(FIPS_F_FIPS_DRBG_BYTES), "FIPS_DRBG_BYTES"}, | ||
94 | {ERR_FUNC(FIPS_F_FIPS_DRBG_CHECK), "FIPS_DRBG_CHECK"}, | ||
95 | {ERR_FUNC(FIPS_F_FIPS_DRBG_CPRNG_TEST), "FIPS_DRBG_CPRNG_TEST"}, | ||
96 | {ERR_FUNC(FIPS_F_FIPS_DRBG_ERROR_CHECK), "FIPS_DRBG_ERROR_CHECK"}, | ||
97 | {ERR_FUNC(FIPS_F_FIPS_DRBG_GENERATE), "FIPS_drbg_generate"}, | ||
98 | {ERR_FUNC(FIPS_F_FIPS_DRBG_INIT), "FIPS_drbg_init"}, | ||
99 | {ERR_FUNC(FIPS_F_FIPS_DRBG_INSTANTIATE), "FIPS_drbg_instantiate"}, | ||
100 | {ERR_FUNC(FIPS_F_FIPS_DRBG_NEW), "FIPS_drbg_new"}, | ||
101 | {ERR_FUNC(FIPS_F_FIPS_DRBG_RESEED), "FIPS_drbg_reseed"}, | ||
102 | {ERR_FUNC(FIPS_F_FIPS_DRBG_SINGLE_KAT), "FIPS_DRBG_SINGLE_KAT"}, | ||
103 | {ERR_FUNC(FIPS_F_FIPS_DSA_SIGN_DIGEST), "FIPS_dsa_sign_digest"}, | ||
104 | {ERR_FUNC(FIPS_F_FIPS_DSA_VERIFY_DIGEST), "FIPS_dsa_verify_digest"}, | ||
105 | {ERR_FUNC(FIPS_F_FIPS_GET_ENTROPY), "FIPS_GET_ENTROPY"}, | ||
106 | {ERR_FUNC(FIPS_F_FIPS_MODULE_MODE_SET), "FIPS_module_mode_set"}, | ||
84 | {ERR_FUNC(FIPS_F_FIPS_PKEY_SIGNATURE_TEST), "fips_pkey_signature_test"}, | 107 | {ERR_FUNC(FIPS_F_FIPS_PKEY_SIGNATURE_TEST), "fips_pkey_signature_test"}, |
108 | {ERR_FUNC(FIPS_F_FIPS_RAND_ADD), "FIPS_rand_add"}, | ||
109 | {ERR_FUNC(FIPS_F_FIPS_RAND_BYTES), "FIPS_rand_bytes"}, | ||
110 | {ERR_FUNC(FIPS_F_FIPS_RAND_PSEUDO_BYTES), "FIPS_rand_pseudo_bytes"}, | ||
111 | {ERR_FUNC(FIPS_F_FIPS_RAND_SEED), "FIPS_rand_seed"}, | ||
112 | {ERR_FUNC(FIPS_F_FIPS_RAND_SET_METHOD), "FIPS_rand_set_method"}, | ||
113 | {ERR_FUNC(FIPS_F_FIPS_RAND_STATUS), "FIPS_rand_status"}, | ||
114 | {ERR_FUNC(FIPS_F_FIPS_RSA_SIGN_DIGEST), "FIPS_rsa_sign_digest"}, | ||
115 | {ERR_FUNC(FIPS_F_FIPS_RSA_VERIFY_DIGEST), "FIPS_rsa_verify_digest"}, | ||
85 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES), "FIPS_selftest_aes"}, | 116 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES), "FIPS_selftest_aes"}, |
117 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES_CCM), "FIPS_selftest_aes_ccm"}, | ||
118 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES_GCM), "FIPS_selftest_aes_gcm"}, | ||
119 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_AES_XTS), "FIPS_selftest_aes_xts"}, | ||
120 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_CMAC), "FIPS_selftest_cmac"}, | ||
86 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DES), "FIPS_selftest_des"}, | 121 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DES), "FIPS_selftest_des"}, |
87 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DSA), "FIPS_selftest_dsa"}, | 122 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_DSA), "FIPS_selftest_dsa"}, |
123 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_ECDSA), "FIPS_selftest_ecdsa"}, | ||
88 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_HMAC), "FIPS_selftest_hmac"}, | 124 | {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"}, | 125 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_SHA1), "FIPS_selftest_sha1"}, |
126 | {ERR_FUNC(FIPS_F_FIPS_SELFTEST_X931), "FIPS_selftest_x931"}, | ||
127 | {ERR_FUNC(FIPS_F_FIPS_SET_PRNG_KEY), "FIPS_SET_PRNG_KEY"}, | ||
91 | {ERR_FUNC(FIPS_F_HASH_FINAL), "HASH_FINAL"}, | 128 | {ERR_FUNC(FIPS_F_HASH_FINAL), "HASH_FINAL"}, |
92 | {ERR_FUNC(FIPS_F_RSA_BUILTIN_KEYGEN), "RSA_BUILTIN_KEYGEN"}, | 129 | {ERR_FUNC(FIPS_F_RSA_BUILTIN_KEYGEN), "RSA_BUILTIN_KEYGEN"}, |
130 | {ERR_FUNC(FIPS_F_RSA_EAY_INIT), "RSA_EAY_INIT"}, | ||
93 | {ERR_FUNC(FIPS_F_RSA_EAY_PRIVATE_DECRYPT), "RSA_EAY_PRIVATE_DECRYPT"}, | 131 | {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"}, | 132 | {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"}, | 133 | {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"}, | 134 | {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"}, | 135 | {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} | 136 | {0,NULL} |
100 | }; | 137 | }; |
101 | 138 | ||
102 | static ERR_STRING_DATA FIPS_str_reasons[]= | 139 | static ERR_STRING_DATA FIPS_str_reasons[]= |
103 | { | 140 | { |
104 | {ERR_REASON(FIPS_R_CANNOT_READ_EXE) ,"cannot read exe"}, | 141 | {ERR_REASON(FIPS_R_ADDITIONAL_INPUT_ERROR_UNDETECTED),"additional input error undetected"}, |
105 | {ERR_REASON(FIPS_R_CANNOT_READ_EXE_DIGEST),"cannot read exe digest"}, | 142 | {ERR_REASON(FIPS_R_ADDITIONAL_INPUT_TOO_LONG),"additional input too long"}, |
143 | {ERR_REASON(FIPS_R_ALREADY_INSTANTIATED) ,"already instantiated"}, | ||
144 | {ERR_REASON(FIPS_R_AUTHENTICATION_FAILURE),"authentication failure"}, | ||
106 | {ERR_REASON(FIPS_R_CONTRADICTING_EVIDENCE),"contradicting evidence"}, | 145 | {ERR_REASON(FIPS_R_CONTRADICTING_EVIDENCE),"contradicting evidence"}, |
107 | {ERR_REASON(FIPS_R_EXE_DIGEST_DOES_NOT_MATCH),"exe digest does not match"}, | 146 | {ERR_REASON(FIPS_R_DRBG_NOT_INITIALISED) ,"drbg not initialised"}, |
147 | {ERR_REASON(FIPS_R_DRBG_STUCK) ,"drbg stuck"}, | ||
148 | {ERR_REASON(FIPS_R_ENTROPY_ERROR_UNDETECTED),"entropy error undetected"}, | ||
149 | {ERR_REASON(FIPS_R_ENTROPY_NOT_REQUESTED_FOR_RESEED),"entropy not requested for reseed"}, | ||
150 | {ERR_REASON(FIPS_R_ENTROPY_SOURCE_STUCK) ,"entropy source stuck"}, | ||
151 | {ERR_REASON(FIPS_R_ERROR_INITIALISING_DRBG),"error initialising drbg"}, | ||
152 | {ERR_REASON(FIPS_R_ERROR_INSTANTIATING_DRBG),"error instantiating drbg"}, | ||
153 | {ERR_REASON(FIPS_R_ERROR_RETRIEVING_ADDITIONAL_INPUT),"error retrieving additional input"}, | ||
154 | {ERR_REASON(FIPS_R_ERROR_RETRIEVING_ENTROPY),"error retrieving entropy"}, | ||
155 | {ERR_REASON(FIPS_R_ERROR_RETRIEVING_NONCE),"error retrieving nonce"}, | ||
108 | {ERR_REASON(FIPS_R_FINGERPRINT_DOES_NOT_MATCH),"fingerprint does not match"}, | 156 | {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"}, | 157 | {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"}, | 158 | {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"}, | 159 | {ERR_REASON(FIPS_R_FIPS_MODE_ALREADY_SET),"fips mode already set"}, |
112 | {ERR_REASON(FIPS_R_FIPS_SELFTEST_FAILED) ,"fips selftest failed"}, | 160 | {ERR_REASON(FIPS_R_FIPS_SELFTEST_FAILED) ,"fips selftest failed"}, |
161 | {ERR_REASON(FIPS_R_FUNCTION_ERROR) ,"function error"}, | ||
162 | {ERR_REASON(FIPS_R_GENERATE_ERROR) ,"generate error"}, | ||
163 | {ERR_REASON(FIPS_R_GENERATE_ERROR_UNDETECTED),"generate error undetected"}, | ||
164 | {ERR_REASON(FIPS_R_INSTANTIATE_ERROR) ,"instantiate error"}, | ||
165 | {ERR_REASON(FIPS_R_INSUFFICIENT_SECURITY_STRENGTH),"insufficient security strength"}, | ||
166 | {ERR_REASON(FIPS_R_INTERNAL_ERROR) ,"internal error"}, | ||
113 | {ERR_REASON(FIPS_R_INVALID_KEY_LENGTH) ,"invalid key length"}, | 167 | {ERR_REASON(FIPS_R_INVALID_KEY_LENGTH) ,"invalid key length"}, |
168 | {ERR_REASON(FIPS_R_INVALID_PARAMETERS) ,"invalid parameters"}, | ||
169 | {ERR_REASON(FIPS_R_IN_ERROR_STATE) ,"in error state"}, | ||
114 | {ERR_REASON(FIPS_R_KEY_TOO_SHORT) ,"key too short"}, | 170 | {ERR_REASON(FIPS_R_KEY_TOO_SHORT) ,"key too short"}, |
171 | {ERR_REASON(FIPS_R_NONCE_ERROR_UNDETECTED),"nonce error undetected"}, | ||
115 | {ERR_REASON(FIPS_R_NON_FIPS_METHOD) ,"non fips method"}, | 172 | {ERR_REASON(FIPS_R_NON_FIPS_METHOD) ,"non fips method"}, |
173 | {ERR_REASON(FIPS_R_NOPR_TEST1_FAILURE) ,"nopr test1 failure"}, | ||
174 | {ERR_REASON(FIPS_R_NOPR_TEST2_FAILURE) ,"nopr test2 failure"}, | ||
175 | {ERR_REASON(FIPS_R_NOT_INSTANTIATED) ,"not instantiated"}, | ||
116 | {ERR_REASON(FIPS_R_PAIRWISE_TEST_FAILED) ,"pairwise test failed"}, | 176 | {ERR_REASON(FIPS_R_PAIRWISE_TEST_FAILED) ,"pairwise test failed"}, |
117 | {ERR_REASON(FIPS_R_RSA_DECRYPT_ERROR) ,"rsa decrypt error"}, | 177 | {ERR_REASON(FIPS_R_PERSONALISATION_ERROR_UNDETECTED),"personalisation error undetected"}, |
118 | {ERR_REASON(FIPS_R_RSA_ENCRYPT_ERROR) ,"rsa encrypt error"}, | 178 | {ERR_REASON(FIPS_R_PERSONALISATION_STRING_TOO_LONG),"personalisation string too long"}, |
179 | {ERR_REASON(FIPS_R_PRNG_STRENGTH_TOO_LOW),"prng strength too low"}, | ||
180 | {ERR_REASON(FIPS_R_PR_TEST1_FAILURE) ,"pr test1 failure"}, | ||
181 | {ERR_REASON(FIPS_R_PR_TEST2_FAILURE) ,"pr test2 failure"}, | ||
182 | {ERR_REASON(FIPS_R_REQUEST_LENGTH_ERROR_UNDETECTED),"request length error undetected"}, | ||
183 | {ERR_REASON(FIPS_R_REQUEST_TOO_LARGE_FOR_DRBG),"request too large for drbg"}, | ||
184 | {ERR_REASON(FIPS_R_RESEED_COUNTER_ERROR) ,"reseed counter error"}, | ||
185 | {ERR_REASON(FIPS_R_RESEED_ERROR) ,"reseed error"}, | ||
119 | {ERR_REASON(FIPS_R_SELFTEST_FAILED) ,"selftest failed"}, | 186 | {ERR_REASON(FIPS_R_SELFTEST_FAILED) ,"selftest failed"}, |
187 | {ERR_REASON(FIPS_R_SELFTEST_FAILURE) ,"selftest failure"}, | ||
188 | {ERR_REASON(FIPS_R_STRENGTH_ERROR_UNDETECTED),"strength error undetected"}, | ||
120 | {ERR_REASON(FIPS_R_TEST_FAILURE) ,"test failure"}, | 189 | {ERR_REASON(FIPS_R_TEST_FAILURE) ,"test failure"}, |
190 | {ERR_REASON(FIPS_R_UNINSTANTIATE_ERROR) ,"uninstantiate error"}, | ||
191 | {ERR_REASON(FIPS_R_UNINSTANTIATE_ZEROISE_ERROR),"uninstantiate zeroise error"}, | ||
192 | {ERR_REASON(FIPS_R_UNSUPPORTED_DRBG_TYPE),"unsupported drbg type"}, | ||
121 | {ERR_REASON(FIPS_R_UNSUPPORTED_PLATFORM) ,"unsupported platform"}, | 193 | {ERR_REASON(FIPS_R_UNSUPPORTED_PLATFORM) ,"unsupported platform"}, |
122 | {0,NULL} | 194 | {0,NULL} |
123 | }; | 195 | }; |
diff --git a/src/lib/libcrypto/fips_ers.c b/src/lib/libcrypto/fips_ers.c new file mode 100644 index 0000000000..09f11748f6 --- /dev/null +++ b/src/lib/libcrypto/fips_ers.c | |||
@@ -0,0 +1,7 @@ | |||
1 | #include <openssl/opensslconf.h> | ||
2 | |||
3 | #ifdef OPENSSL_FIPS | ||
4 | # include "fips_err.h" | ||
5 | #else | ||
6 | static void *dummy=&dummy; | ||
7 | #endif | ||
diff --git a/src/lib/libcrypto/idea/idea_spd.c b/src/lib/libcrypto/idea/idea_spd.c new file mode 100644 index 0000000000..699353e871 --- /dev/null +++ b/src/lib/libcrypto/idea/idea_spd.c | |||
@@ -0,0 +1,299 @@ | |||
1 | /* crypto/idea/idea_spd.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ | ||
60 | /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ | ||
61 | |||
62 | #if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX) | ||
63 | #define TIMES | ||
64 | #endif | ||
65 | |||
66 | #include <stdio.h> | ||
67 | |||
68 | #include <openssl/e_os2.h> | ||
69 | #include OPENSSL_UNISTD_IO | ||
70 | OPENSSL_DECLARE_EXIT | ||
71 | |||
72 | #ifndef OPENSSL_SYS_NETWARE | ||
73 | #include <signal.h> | ||
74 | #endif | ||
75 | |||
76 | #ifndef _IRIX | ||
77 | #include <time.h> | ||
78 | #endif | ||
79 | #ifdef TIMES | ||
80 | #include <sys/types.h> | ||
81 | #include <sys/times.h> | ||
82 | #endif | ||
83 | |||
84 | /* Depending on the VMS version, the tms structure is perhaps defined. | ||
85 | The __TMS macro will show if it was. If it wasn't defined, we should | ||
86 | undefine TIMES, since that tells the rest of the program how things | ||
87 | should be handled. -- Richard Levitte */ | ||
88 | #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS) | ||
89 | #undef TIMES | ||
90 | #endif | ||
91 | |||
92 | #ifndef TIMES | ||
93 | #include <sys/timeb.h> | ||
94 | #endif | ||
95 | |||
96 | #if defined(sun) || defined(__ultrix) | ||
97 | #define _POSIX_SOURCE | ||
98 | #include <limits.h> | ||
99 | #include <sys/param.h> | ||
100 | #endif | ||
101 | |||
102 | #include <openssl/idea.h> | ||
103 | |||
104 | /* The following if from times(3) man page. It may need to be changed */ | ||
105 | #ifndef HZ | ||
106 | #ifndef CLK_TCK | ||
107 | #define HZ 100.0 | ||
108 | #else /* CLK_TCK */ | ||
109 | #define HZ ((double)CLK_TCK) | ||
110 | #endif | ||
111 | #endif | ||
112 | |||
113 | #define BUFSIZE ((long)1024) | ||
114 | long run=0; | ||
115 | |||
116 | double Time_F(int s); | ||
117 | #ifdef SIGALRM | ||
118 | #if defined(__STDC__) || defined(sgi) || defined(_AIX) | ||
119 | #define SIGRETTYPE void | ||
120 | #else | ||
121 | #define SIGRETTYPE int | ||
122 | #endif | ||
123 | |||
124 | SIGRETTYPE sig_done(int sig); | ||
125 | SIGRETTYPE sig_done(int sig) | ||
126 | { | ||
127 | signal(SIGALRM,sig_done); | ||
128 | run=0; | ||
129 | #ifdef LINT | ||
130 | sig=sig; | ||
131 | #endif | ||
132 | } | ||
133 | #endif | ||
134 | |||
135 | #define START 0 | ||
136 | #define STOP 1 | ||
137 | |||
138 | double Time_F(int s) | ||
139 | { | ||
140 | double ret; | ||
141 | #ifdef TIMES | ||
142 | static struct tms tstart,tend; | ||
143 | |||
144 | if (s == START) | ||
145 | { | ||
146 | times(&tstart); | ||
147 | return(0); | ||
148 | } | ||
149 | else | ||
150 | { | ||
151 | times(&tend); | ||
152 | ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ; | ||
153 | return((ret == 0.0)?1e-6:ret); | ||
154 | } | ||
155 | #else /* !times() */ | ||
156 | static struct timeb tstart,tend; | ||
157 | long i; | ||
158 | |||
159 | if (s == START) | ||
160 | { | ||
161 | ftime(&tstart); | ||
162 | return(0); | ||
163 | } | ||
164 | else | ||
165 | { | ||
166 | ftime(&tend); | ||
167 | i=(long)tend.millitm-(long)tstart.millitm; | ||
168 | ret=((double)(tend.time-tstart.time))+((double)i)/1e3; | ||
169 | return((ret == 0.0)?1e-6:ret); | ||
170 | } | ||
171 | #endif | ||
172 | } | ||
173 | |||
174 | int main(int argc, char **argv) | ||
175 | { | ||
176 | long count; | ||
177 | static unsigned char buf[BUFSIZE]; | ||
178 | static unsigned char key[] ={ | ||
179 | 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0, | ||
180 | 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10, | ||
181 | }; | ||
182 | IDEA_KEY_SCHEDULE sch; | ||
183 | double a,aa,b,c,d; | ||
184 | #ifndef SIGALRM | ||
185 | long ca,cca,cb,cc; | ||
186 | #endif | ||
187 | |||
188 | #ifndef TIMES | ||
189 | printf("To get the most accurate results, try to run this\n"); | ||
190 | printf("program when this computer is idle.\n"); | ||
191 | #endif | ||
192 | |||
193 | #ifndef SIGALRM | ||
194 | printf("First we calculate the approximate speed ...\n"); | ||
195 | idea_set_encrypt_key(key,&sch); | ||
196 | count=10; | ||
197 | do { | ||
198 | long i; | ||
199 | IDEA_INT data[2]; | ||
200 | |||
201 | count*=2; | ||
202 | Time_F(START); | ||
203 | for (i=count; i; i--) | ||
204 | idea_encrypt(data,&sch); | ||
205 | d=Time_F(STOP); | ||
206 | } while (d < 3.0); | ||
207 | ca=count/4; | ||
208 | cca=count/200; | ||
209 | cb=count; | ||
210 | cc=count*8/BUFSIZE+1; | ||
211 | printf("idea_set_encrypt_key %ld times\n",ca); | ||
212 | #define COND(d) (count <= (d)) | ||
213 | #define COUNT(d) (d) | ||
214 | #else | ||
215 | #define COND(c) (run) | ||
216 | #define COUNT(d) (count) | ||
217 | signal(SIGALRM,sig_done); | ||
218 | printf("Doing idea_set_encrypt_key for 10 seconds\n"); | ||
219 | alarm(10); | ||
220 | #endif | ||
221 | |||
222 | Time_F(START); | ||
223 | for (count=0,run=1; COND(ca); count+=4) | ||
224 | { | ||
225 | idea_set_encrypt_key(key,&sch); | ||
226 | idea_set_encrypt_key(key,&sch); | ||
227 | idea_set_encrypt_key(key,&sch); | ||
228 | idea_set_encrypt_key(key,&sch); | ||
229 | } | ||
230 | d=Time_F(STOP); | ||
231 | printf("%ld idea idea_set_encrypt_key's in %.2f seconds\n",count,d); | ||
232 | a=((double)COUNT(ca))/d; | ||
233 | |||
234 | #ifdef SIGALRM | ||
235 | printf("Doing idea_set_decrypt_key for 10 seconds\n"); | ||
236 | alarm(10); | ||
237 | #else | ||
238 | printf("Doing idea_set_decrypt_key %ld times\n",cca); | ||
239 | #endif | ||
240 | |||
241 | Time_F(START); | ||
242 | for (count=0,run=1; COND(cca); count+=4) | ||
243 | { | ||
244 | idea_set_decrypt_key(&sch,&sch); | ||
245 | idea_set_decrypt_key(&sch,&sch); | ||
246 | idea_set_decrypt_key(&sch,&sch); | ||
247 | idea_set_decrypt_key(&sch,&sch); | ||
248 | } | ||
249 | d=Time_F(STOP); | ||
250 | printf("%ld idea idea_set_decrypt_key's in %.2f seconds\n",count,d); | ||
251 | aa=((double)COUNT(cca))/d; | ||
252 | |||
253 | #ifdef SIGALRM | ||
254 | printf("Doing idea_encrypt's for 10 seconds\n"); | ||
255 | alarm(10); | ||
256 | #else | ||
257 | printf("Doing idea_encrypt %ld times\n",cb); | ||
258 | #endif | ||
259 | Time_F(START); | ||
260 | for (count=0,run=1; COND(cb); count+=4) | ||
261 | { | ||
262 | unsigned long data[2]; | ||
263 | |||
264 | idea_encrypt(data,&sch); | ||
265 | idea_encrypt(data,&sch); | ||
266 | idea_encrypt(data,&sch); | ||
267 | idea_encrypt(data,&sch); | ||
268 | } | ||
269 | d=Time_F(STOP); | ||
270 | printf("%ld idea_encrypt's in %.2f second\n",count,d); | ||
271 | b=((double)COUNT(cb)*8)/d; | ||
272 | |||
273 | #ifdef SIGALRM | ||
274 | printf("Doing idea_cbc_encrypt on %ld byte blocks for 10 seconds\n", | ||
275 | BUFSIZE); | ||
276 | alarm(10); | ||
277 | #else | ||
278 | printf("Doing idea_cbc_encrypt %ld times on %ld byte blocks\n",cc, | ||
279 | BUFSIZE); | ||
280 | #endif | ||
281 | Time_F(START); | ||
282 | for (count=0,run=1; COND(cc); count++) | ||
283 | idea_cbc_encrypt(buf,buf,BUFSIZE,&sch, | ||
284 | &(key[0]),IDEA_ENCRYPT); | ||
285 | d=Time_F(STOP); | ||
286 | printf("%ld idea_cbc_encrypt's of %ld byte blocks in %.2f second\n", | ||
287 | count,BUFSIZE,d); | ||
288 | c=((double)COUNT(cc)*BUFSIZE)/d; | ||
289 | |||
290 | printf("IDEA set_encrypt_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a); | ||
291 | printf("IDEA set_decrypt_key per sec = %12.2f (%9.3fuS)\n",aa,1.0e6/aa); | ||
292 | printf("IDEA raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b); | ||
293 | printf("IDEA cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c); | ||
294 | exit(0); | ||
295 | #if defined(LINT) || defined(OPENSSL_SYS_MSDOS) | ||
296 | return(0); | ||
297 | #endif | ||
298 | } | ||
299 | |||
diff --git a/src/lib/libcrypto/mdc2/mdc2dgst.c b/src/lib/libcrypto/mdc2/mdc2dgst.c index 4aa406edc3..b74bb1a759 100644 --- a/src/lib/libcrypto/mdc2/mdc2dgst.c +++ b/src/lib/libcrypto/mdc2/mdc2dgst.c | |||
@@ -61,6 +61,7 @@ | |||
61 | #include <string.h> | 61 | #include <string.h> |
62 | #include <openssl/des.h> | 62 | #include <openssl/des.h> |
63 | #include <openssl/mdc2.h> | 63 | #include <openssl/mdc2.h> |
64 | #include <openssl/crypto.h> | ||
64 | 65 | ||
65 | #undef c2l | 66 | #undef c2l |
66 | #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ | 67 | #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ |
@@ -75,7 +76,7 @@ | |||
75 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | 76 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) |
76 | 77 | ||
77 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); | 78 | static void mdc2_body(MDC2_CTX *c, const unsigned char *in, size_t len); |
78 | int MDC2_Init(MDC2_CTX *c) | 79 | fips_md_init(MDC2) |
79 | { | 80 | { |
80 | c->num=0; | 81 | c->num=0; |
81 | c->pad_type=1; | 82 | c->pad_type=1; |
diff --git a/src/lib/libcrypto/modes/Makefile b/src/lib/libcrypto/modes/Makefile index 6c85861b6c..c825b12f25 100644 --- a/src/lib/libcrypto/modes/Makefile +++ b/src/lib/libcrypto/modes/Makefile | |||
@@ -10,21 +10,27 @@ CFLAG=-g | |||
10 | MAKEFILE= Makefile | 10 | MAKEFILE= Makefile |
11 | AR= ar r | 11 | AR= ar r |
12 | 12 | ||
13 | MODES_ASM_OBJ= | ||
14 | |||
13 | CFLAGS= $(INCLUDES) $(CFLAG) | 15 | CFLAGS= $(INCLUDES) $(CFLAG) |
16 | ASFLAGS= $(INCLUDES) $(ASFLAG) | ||
17 | AFLAGS= $(ASFLAGS) | ||
14 | 18 | ||
15 | GENERAL=Makefile | 19 | GENERAL=Makefile |
16 | TEST= | 20 | TEST= |
17 | APPS= | 21 | APPS= |
18 | 22 | ||
19 | LIB=$(TOP)/libcrypto.a | 23 | LIB=$(TOP)/libcrypto.a |
20 | LIBSRC= cbc128.c ctr128.c cts128.c cfb128.c ofb128.c | 24 | LIBSRC= cbc128.c ctr128.c cts128.c cfb128.c ofb128.c gcm128.c \ |
21 | LIBOBJ= cbc128.o ctr128.o cts128.o cfb128.o ofb128.o | 25 | ccm128.c xts128.c |
26 | LIBOBJ= cbc128.o ctr128.o cts128.o cfb128.o ofb128.o gcm128.o \ | ||
27 | ccm128.o xts128.o $(MODES_ASM_OBJ) | ||
22 | 28 | ||
23 | SRC= $(LIBSRC) | 29 | SRC= $(LIBSRC) |
24 | 30 | ||
25 | #EXHEADER= store.h str_compat.h | 31 | #EXHEADER= store.h str_compat.h |
26 | EXHEADER= modes.h | 32 | EXHEADER= modes.h |
27 | HEADER= $(EXHEADER) | 33 | HEADER= modes_lcl.h $(EXHEADER) |
28 | 34 | ||
29 | ALL= $(GENERAL) $(SRC) $(HEADER) | 35 | ALL= $(GENERAL) $(SRC) $(HEADER) |
30 | 36 | ||
@@ -38,6 +44,24 @@ lib: $(LIBOBJ) | |||
38 | $(RANLIB) $(LIB) || echo Never mind. | 44 | $(RANLIB) $(LIB) || echo Never mind. |
39 | @touch lib | 45 | @touch lib |
40 | 46 | ||
47 | ghash-ia64.s: asm/ghash-ia64.pl | ||
48 | $(PERL) asm/ghash-ia64.pl $@ $(CFLAGS) | ||
49 | ghash-x86.s: asm/ghash-x86.pl | ||
50 | $(PERL) asm/ghash-x86.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@ | ||
51 | ghash-x86_64.s: asm/ghash-x86_64.pl | ||
52 | $(PERL) asm/ghash-x86_64.pl $(PERLASM_SCHEME) > $@ | ||
53 | ghash-sparcv9.s: asm/ghash-sparcv9.pl | ||
54 | $(PERL) asm/ghash-sparcv9.pl $@ $(CFLAGS) | ||
55 | ghash-alpha.s: asm/ghash-alpha.pl | ||
56 | $(PERL) $< | $(CC) -E - | tee $@ > /dev/null | ||
57 | ghash-parisc.s: asm/ghash-parisc.pl | ||
58 | $(PERL) asm/ghash-parisc.pl $(PERLASM_SCHEME) $@ | ||
59 | |||
60 | # GNU make "catch all" | ||
61 | ghash-%.S: asm/ghash-%.pl; $(PERL) $< $(PERLASM_SCHEME) $@ | ||
62 | |||
63 | ghash-armv4.o: ghash-armv4.S | ||
64 | |||
41 | files: | 65 | files: |
42 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | 66 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO |
43 | 67 | ||
@@ -71,12 +95,47 @@ dclean: | |||
71 | mv -f Makefile.new $(MAKEFILE) | 95 | mv -f Makefile.new $(MAKEFILE) |
72 | 96 | ||
73 | clean: | 97 | clean: |
74 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | 98 | rm -f *.s *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff |
75 | 99 | ||
76 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 100 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
77 | 101 | ||
78 | cbc128.o: cbc128.c modes.h | 102 | cbc128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h |
79 | cfb128.o: cfb128.c modes.h | 103 | cbc128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h |
80 | ctr128.o: ctr128.c modes.h | 104 | cbc128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h |
81 | cts128.o: cts128.c modes.h | 105 | cbc128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h |
82 | ofb128.o: modes.h ofb128.c | 106 | cbc128.o: ../../include/openssl/symhacks.h cbc128.c modes_lcl.h |
107 | ccm128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
108 | ccm128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
109 | ccm128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
110 | ccm128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
111 | ccm128.o: ../../include/openssl/symhacks.h ccm128.c modes_lcl.h | ||
112 | cfb128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
113 | cfb128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
114 | cfb128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
115 | cfb128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
116 | cfb128.o: ../../include/openssl/symhacks.h cfb128.c modes_lcl.h | ||
117 | ctr128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
118 | ctr128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
119 | ctr128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
120 | ctr128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
121 | ctr128.o: ../../include/openssl/symhacks.h ctr128.c modes_lcl.h | ||
122 | cts128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
123 | cts128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
124 | cts128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
125 | cts128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
126 | cts128.o: ../../include/openssl/symhacks.h cts128.c modes_lcl.h | ||
127 | gcm128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
128 | gcm128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
129 | gcm128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
130 | gcm128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
131 | gcm128.o: ../../include/openssl/symhacks.h gcm128.c modes_lcl.h | ||
132 | ofb128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
133 | ofb128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
134 | ofb128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
135 | ofb128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
136 | ofb128.o: ../../include/openssl/symhacks.h modes_lcl.h ofb128.c | ||
137 | xts128.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
138 | xts128.o: ../../include/openssl/modes.h ../../include/openssl/opensslconf.h | ||
139 | xts128.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
140 | xts128.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
141 | xts128.o: ../../include/openssl/symhacks.h modes_lcl.h xts128.c | ||
diff --git a/src/lib/libcrypto/o_fips.c b/src/lib/libcrypto/o_fips.c new file mode 100644 index 0000000000..f6d1b21855 --- /dev/null +++ b/src/lib/libcrypto/o_fips.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /* Written by Stephen henson (steve@openssl.org) for the OpenSSL | ||
2 | * project 2011. | ||
3 | */ | ||
4 | /* ==================================================================== | ||
5 | * Copyright (c) 2011 The OpenSSL Project. All rights reserved. | ||
6 | * | ||
7 | * Redistribution and use in source and binary forms, with or without | ||
8 | * modification, are permitted provided that the following conditions | ||
9 | * are met: | ||
10 | * | ||
11 | * 1. Redistributions of source code must retain the above copyright | ||
12 | * notice, this list of conditions and the following disclaimer. | ||
13 | * | ||
14 | * 2. Redistributions in binary form must reproduce the above copyright | ||
15 | * notice, this list of conditions and the following disclaimer in | ||
16 | * the documentation and/or other materials provided with the | ||
17 | * distribution. | ||
18 | * | ||
19 | * 3. All advertising materials mentioning features or use of this | ||
20 | * software must display the following acknowledgment: | ||
21 | * "This product includes software developed by the OpenSSL Project | ||
22 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
23 | * | ||
24 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
25 | * endorse or promote products derived from this software without | ||
26 | * prior written permission. For written permission, please contact | ||
27 | * openssl-core@openssl.org. | ||
28 | * | ||
29 | * 5. Products derived from this software may not be called "OpenSSL" | ||
30 | * nor may "OpenSSL" appear in their names without prior written | ||
31 | * permission of the OpenSSL Project. | ||
32 | * | ||
33 | * 6. Redistributions of any form whatsoever must retain the following | ||
34 | * acknowledgment: | ||
35 | * "This product includes software developed by the OpenSSL Project | ||
36 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
37 | * | ||
38 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
39 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
40 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
41 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
42 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
43 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
44 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
45 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
46 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
47 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
48 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
49 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
50 | * ==================================================================== | ||
51 | * | ||
52 | * This product includes cryptographic software written by Eric Young | ||
53 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
54 | * Hudson (tjh@cryptsoft.com). | ||
55 | * | ||
56 | */ | ||
57 | |||
58 | #include "cryptlib.h" | ||
59 | #ifdef OPENSSL_FIPS | ||
60 | #include <openssl/fips.h> | ||
61 | #include <openssl/fips_rand.h> | ||
62 | #include <openssl/rand.h> | ||
63 | #endif | ||
64 | |||
65 | int FIPS_mode(void) | ||
66 | { | ||
67 | OPENSSL_init(); | ||
68 | #ifdef OPENSSL_FIPS | ||
69 | return FIPS_module_mode(); | ||
70 | #else | ||
71 | return 0; | ||
72 | #endif | ||
73 | } | ||
74 | |||
75 | int FIPS_mode_set(int r) | ||
76 | { | ||
77 | OPENSSL_init(); | ||
78 | #ifdef OPENSSL_FIPS | ||
79 | #ifndef FIPS_AUTH_USER_PASS | ||
80 | #define FIPS_AUTH_USER_PASS "Default FIPS Crypto User Password" | ||
81 | #endif | ||
82 | if (!FIPS_module_mode_set(r, FIPS_AUTH_USER_PASS)) | ||
83 | return 0; | ||
84 | if (r) | ||
85 | RAND_set_rand_method(FIPS_rand_get_method()); | ||
86 | else | ||
87 | RAND_set_rand_method(NULL); | ||
88 | return 1; | ||
89 | #else | ||
90 | if (r == 0) | ||
91 | return 1; | ||
92 | CRYPTOerr(CRYPTO_F_FIPS_MODE_SET, CRYPTO_R_FIPS_MODE_NOT_SUPPORTED); | ||
93 | return 0; | ||
94 | #endif | ||
95 | } | ||
96 | |||
diff --git a/src/lib/libcrypto/perlasm/x86masm.pl b/src/lib/libcrypto/perlasm/x86masm.pl index 3d50e4a786..96b1b73e1a 100644 --- a/src/lib/libcrypto/perlasm/x86masm.pl +++ b/src/lib/libcrypto/perlasm/x86masm.pl | |||
@@ -14,9 +14,11 @@ sub ::generic | |||
14 | { my ($opcode,@arg)=@_; | 14 | { my ($opcode,@arg)=@_; |
15 | 15 | ||
16 | # fix hexadecimal constants | 16 | # fix hexadecimal constants |
17 | for (@arg) { s/0x([0-9a-f]+)/0$1h/oi; } | 17 | for (@arg) { s/(?<![\w\$\.])0x([0-9a-f]+)/0$1h/oi; } |
18 | 18 | ||
19 | if ($opcode !~ /movq/) | 19 | if ($opcode =~ /lea/ && @arg[1] =~ s/.*PTR\s+(\(.*\))$/OFFSET $1/) # no [] |
20 | { $opcode="mov"; } | ||
21 | elsif ($opcode !~ /movq/) | ||
20 | { # fix xmm references | 22 | { # fix xmm references |
21 | $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i); | 23 | $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i); |
22 | $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i); | 24 | $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i); |
@@ -65,6 +67,7 @@ sub get_mem | |||
65 | $ret; | 67 | $ret; |
66 | } | 68 | } |
67 | sub ::BP { &get_mem("BYTE",@_); } | 69 | sub ::BP { &get_mem("BYTE",@_); } |
70 | sub ::WP { &get_mem("WORD",@_); } | ||
68 | sub ::DWP { &get_mem("DWORD",@_); } | 71 | sub ::DWP { &get_mem("DWORD",@_); } |
69 | sub ::QWP { &get_mem("QWORD",@_); } | 72 | sub ::QWP { &get_mem("QWORD",@_); } |
70 | sub ::BC { "@_"; } | 73 | sub ::BC { "@_"; } |
@@ -129,7 +132,7 @@ ___ | |||
129 | if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) | 132 | if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out) |
130 | { my $comm=<<___; | 133 | { my $comm=<<___; |
131 | .bss SEGMENT 'BSS' | 134 | .bss SEGMENT 'BSS' |
132 | COMM ${nmdecor}OPENSSL_ia32cap_P:DWORD | 135 | COMM ${nmdecor}OPENSSL_ia32cap_P:QWORD |
133 | .bss ENDS | 136 | .bss ENDS |
134 | ___ | 137 | ___ |
135 | # comment out OPENSSL_ia32cap_P declarations | 138 | # comment out OPENSSL_ia32cap_P declarations |
@@ -156,6 +159,9 @@ sub ::public_label | |||
156 | sub ::data_byte | 159 | sub ::data_byte |
157 | { push(@out,("DB\t").join(',',@_)."\n"); } | 160 | { push(@out,("DB\t").join(',',@_)."\n"); } |
158 | 161 | ||
162 | sub ::data_short | ||
163 | { push(@out,("DW\t").join(',',@_)."\n"); } | ||
164 | |||
159 | sub ::data_word | 165 | sub ::data_word |
160 | { push(@out,("DD\t").join(',',@_)."\n"); } | 166 | { push(@out,("DD\t").join(',',@_)."\n"); } |
161 | 167 | ||
@@ -181,4 +187,11 @@ ___ | |||
181 | sub ::dataseg | 187 | sub ::dataseg |
182 | { push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; } | 188 | { push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; } |
183 | 189 | ||
190 | sub ::safeseh | ||
191 | { my $nm=shift; | ||
192 | push(@out,"IF \@Version GE 710\n"); | ||
193 | push(@out,".SAFESEH ".&::LABEL($nm,$nmdecor.$nm)."\n"); | ||
194 | push(@out,"ENDIF\n"); | ||
195 | } | ||
196 | |||
184 | 1; | 197 | 1; |
diff --git a/src/lib/libcrypto/rc4/rc4_utl.c b/src/lib/libcrypto/rc4/rc4_utl.c new file mode 100644 index 0000000000..ab3f02fe6a --- /dev/null +++ b/src/lib/libcrypto/rc4/rc4_utl.c | |||
@@ -0,0 +1,62 @@ | |||
1 | /* crypto/rc4/rc4_utl.c -*- mode:C; c-file-style: "eay" -*- */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2011 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 | */ | ||
51 | |||
52 | #include <openssl/opensslv.h> | ||
53 | #include <openssl/crypto.h> | ||
54 | #include <openssl/rc4.h> | ||
55 | |||
56 | void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) | ||
57 | { | ||
58 | #ifdef OPENSSL_FIPS | ||
59 | fips_cipher_abort(RC4); | ||
60 | #endif | ||
61 | private_RC4_set_key(key, len, data); | ||
62 | } | ||
diff --git a/src/lib/libcrypto/seed/seed.c b/src/lib/libcrypto/seed/seed.c index 2bc384a19f..3e675a8d75 100644 --- a/src/lib/libcrypto/seed/seed.c +++ b/src/lib/libcrypto/seed/seed.c | |||
@@ -32,9 +32,14 @@ | |||
32 | #include <memory.h> | 32 | #include <memory.h> |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #include <openssl/crypto.h> | ||
35 | #include <openssl/seed.h> | 36 | #include <openssl/seed.h> |
36 | #include "seed_locl.h" | 37 | #include "seed_locl.h" |
37 | 38 | ||
39 | #ifdef SS /* can get defined on Solaris by inclusion of <stdlib.h> */ | ||
40 | #undef SS | ||
41 | #endif | ||
42 | |||
38 | static const seed_word SS[4][256] = { { | 43 | static const seed_word SS[4][256] = { { |
39 | 0x2989a1a8, 0x05858184, 0x16c6d2d4, 0x13c3d3d0, 0x14445054, 0x1d0d111c, 0x2c8ca0ac, 0x25052124, | 44 | 0x2989a1a8, 0x05858184, 0x16c6d2d4, 0x13c3d3d0, 0x14445054, 0x1d0d111c, 0x2c8ca0ac, 0x25052124, |
40 | 0x1d4d515c, 0x03434340, 0x18081018, 0x1e0e121c, 0x11415150, 0x3cccf0fc, 0x0acac2c8, 0x23436360, | 45 | 0x1d4d515c, 0x03434340, 0x18081018, 0x1e0e121c, 0x11415150, 0x3cccf0fc, 0x0acac2c8, 0x23436360, |
@@ -192,8 +197,14 @@ static const seed_word KC[] = { | |||
192 | KC0, KC1, KC2, KC3, KC4, KC5, KC6, KC7, | 197 | KC0, KC1, KC2, KC3, KC4, KC5, KC6, KC7, |
193 | KC8, KC9, KC10, KC11, KC12, KC13, KC14, KC15 }; | 198 | KC8, KC9, KC10, KC11, KC12, KC13, KC14, KC15 }; |
194 | #endif | 199 | #endif |
195 | |||
196 | void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks) | 200 | void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks) |
201 | #ifdef OPENSSL_FIPS | ||
202 | { | ||
203 | fips_cipher_abort(SEED); | ||
204 | private_SEED_set_key(rawkey, ks); | ||
205 | } | ||
206 | void private_SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks) | ||
207 | #endif | ||
197 | { | 208 | { |
198 | seed_word x1, x2, x3, x4; | 209 | seed_word x1, x2, x3, x4; |
199 | seed_word t0, t1; | 210 | seed_word t0, t1; |
diff --git a/src/lib/libcrypto/seed/seed.h b/src/lib/libcrypto/seed/seed.h index 6ffa5f024e..c50fdd3607 100644 --- a/src/lib/libcrypto/seed/seed.h +++ b/src/lib/libcrypto/seed/seed.h | |||
@@ -116,7 +116,9 @@ typedef struct seed_key_st { | |||
116 | #endif | 116 | #endif |
117 | } SEED_KEY_SCHEDULE; | 117 | } SEED_KEY_SCHEDULE; |
118 | 118 | ||
119 | 119 | #ifdef OPENSSL_FIPS | |
120 | void private_SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks); | ||
121 | #endif | ||
120 | void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks); | 122 | void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks); |
121 | 123 | ||
122 | void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks); | 124 | void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks); |
diff --git a/src/lib/libcrypto/srp/Makefile b/src/lib/libcrypto/srp/Makefile new file mode 100644 index 0000000000..41859d46fa --- /dev/null +++ b/src/lib/libcrypto/srp/Makefile | |||
@@ -0,0 +1,98 @@ | |||
1 | DIR= srp | ||
2 | TOP= ../.. | ||
3 | CC= cc | ||
4 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
5 | CFLAG=-g | ||
6 | INSTALL_PREFIX= | ||
7 | OPENSSLDIR= /usr/local/ssl | ||
8 | INSTALLTOP=/usr/local/ssl | ||
9 | MAKE= make -f Makefile.ssl | ||
10 | MAKEDEPPROG= makedepend | ||
11 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
12 | MAKEFILE= Makefile.ssl | ||
13 | AR= ar r | ||
14 | |||
15 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
16 | |||
17 | GENERAL=Makefile | ||
18 | TEST=srptest.c | ||
19 | APPS= | ||
20 | |||
21 | LIB=$(TOP)/libcrypto.a | ||
22 | LIBSRC=srp_lib.c srp_vfy.c | ||
23 | LIBOBJ=srp_lib.o srp_vfy.o | ||
24 | |||
25 | SRC= $(LIBSRC) | ||
26 | |||
27 | EXHEADER= srp.h | ||
28 | HEADER= $(EXHEADER) | ||
29 | |||
30 | top: | ||
31 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
32 | |||
33 | all: lib | ||
34 | |||
35 | lib: $(LIBOBJ) | ||
36 | $(AR) $(LIB) $(LIBOBJ) | ||
37 | $(RANLIB) $(LIB) || echo Never mind. | ||
38 | @touch lib | ||
39 | |||
40 | links: | ||
41 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
42 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
43 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
44 | |||
45 | install: | ||
46 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
47 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
48 | do \ | ||
49 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
50 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
51 | done; | ||
52 | |||
53 | tags: | ||
54 | ctags $(SRC) | ||
55 | |||
56 | tests: | ||
57 | |||
58 | srptest: top srptest.c $(LIB) | ||
59 | $(CC) $(CFLAGS) -Wall -Werror -g -o srptest srptest.c $(LIB) | ||
60 | |||
61 | lint: | ||
62 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
63 | |||
64 | depend: | ||
65 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
66 | |||
67 | dclean: | ||
68 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
69 | mv -f Makefile.new $(MAKEFILE) | ||
70 | |||
71 | clean: | ||
72 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
73 | |||
74 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
75 | |||
76 | srp_lib.o: ../../e_os.h ../../include/openssl/asn1.h | ||
77 | srp_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
78 | srp_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
79 | srp_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
80 | srp_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
81 | srp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
82 | srp_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
83 | srp_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
84 | srp_lib.o: ../../include/openssl/sha.h ../../include/openssl/srp.h | ||
85 | srp_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
86 | srp_lib.o: ../cryptlib.h srp_grps.h srp_lcl.h srp_lib.c | ||
87 | srp_vfy.o: ../../e_os.h ../../include/openssl/asn1.h | ||
88 | srp_vfy.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
89 | srp_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
90 | srp_vfy.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
91 | srp_vfy.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h | ||
92 | srp_vfy.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h | ||
93 | srp_vfy.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
94 | srp_vfy.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
95 | srp_vfy.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
96 | srp_vfy.o: ../../include/openssl/srp.h ../../include/openssl/stack.h | ||
97 | srp_vfy.o: ../../include/openssl/symhacks.h ../../include/openssl/txt_db.h | ||
98 | srp_vfy.o: ../cryptlib.h srp_lcl.h srp_vfy.c | ||
diff --git a/src/lib/libcrypto/srp/srp.h b/src/lib/libcrypto/srp/srp.h new file mode 100644 index 0000000000..7ec7825cad --- /dev/null +++ b/src/lib/libcrypto/srp/srp.h | |||
@@ -0,0 +1,172 @@ | |||
1 | /* crypto/srp/srp.h */ | ||
2 | /* Written by Christophe Renou (christophe.renou@edelweb.fr) with | ||
3 | * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr) | ||
4 | * for the EdelKey project and contributed to the OpenSSL project 2004. | ||
5 | */ | ||
6 | /* ==================================================================== | ||
7 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in | ||
18 | * the documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * 3. All advertising materials mentioning features or use of this | ||
22 | * software must display the following acknowledgment: | ||
23 | * "This product includes software developed by the OpenSSL Project | ||
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
25 | * | ||
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
27 | * endorse or promote products derived from this software without | ||
28 | * prior written permission. For written permission, please contact | ||
29 | * licensing@OpenSSL.org. | ||
30 | * | ||
31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
32 | * nor may "OpenSSL" appear in their names without prior written | ||
33 | * permission of the OpenSSL Project. | ||
34 | * | ||
35 | * 6. Redistributions of any form whatsoever must retain the following | ||
36 | * acknowledgment: | ||
37 | * "This product includes software developed by the OpenSSL Project | ||
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
39 | * | ||
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
52 | * ==================================================================== | ||
53 | * | ||
54 | * This product includes cryptographic software written by Eric Young | ||
55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
56 | * Hudson (tjh@cryptsoft.com). | ||
57 | * | ||
58 | */ | ||
59 | #ifndef __SRP_H__ | ||
60 | #define __SRP_H__ | ||
61 | |||
62 | #ifndef OPENSSL_NO_SRP | ||
63 | |||
64 | #include <stdio.h> | ||
65 | #include <string.h> | ||
66 | |||
67 | #ifdef __cplusplus | ||
68 | extern "C" { | ||
69 | #endif | ||
70 | |||
71 | #include <openssl/safestack.h> | ||
72 | #include <openssl/bn.h> | ||
73 | #include <openssl/crypto.h> | ||
74 | |||
75 | typedef struct SRP_gN_cache_st | ||
76 | { | ||
77 | char *b64_bn; | ||
78 | BIGNUM *bn; | ||
79 | } SRP_gN_cache; | ||
80 | |||
81 | |||
82 | DECLARE_STACK_OF(SRP_gN_cache) | ||
83 | |||
84 | typedef struct SRP_user_pwd_st | ||
85 | { | ||
86 | char *id; | ||
87 | BIGNUM *s; | ||
88 | BIGNUM *v; | ||
89 | const BIGNUM *g; | ||
90 | const BIGNUM *N; | ||
91 | char *info; | ||
92 | } SRP_user_pwd; | ||
93 | |||
94 | DECLARE_STACK_OF(SRP_user_pwd) | ||
95 | |||
96 | typedef struct SRP_VBASE_st | ||
97 | { | ||
98 | STACK_OF(SRP_user_pwd) *users_pwd; | ||
99 | STACK_OF(SRP_gN_cache) *gN_cache; | ||
100 | /* to simulate a user */ | ||
101 | char *seed_key; | ||
102 | BIGNUM *default_g; | ||
103 | BIGNUM *default_N; | ||
104 | } SRP_VBASE; | ||
105 | |||
106 | |||
107 | /*Structure interne pour retenir les couples N et g*/ | ||
108 | typedef struct SRP_gN_st | ||
109 | { | ||
110 | char *id; | ||
111 | BIGNUM *g; | ||
112 | BIGNUM *N; | ||
113 | } SRP_gN; | ||
114 | |||
115 | DECLARE_STACK_OF(SRP_gN) | ||
116 | |||
117 | SRP_VBASE *SRP_VBASE_new(char *seed_key); | ||
118 | int SRP_VBASE_free(SRP_VBASE *vb); | ||
119 | int SRP_VBASE_init(SRP_VBASE *vb, char * verifier_file); | ||
120 | SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username); | ||
121 | char *SRP_create_verifier(const char *user, const char *pass, char **salt, | ||
122 | char **verifier, const char *N, const char *g); | ||
123 | int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g); | ||
124 | |||
125 | |||
126 | #define SRP_NO_ERROR 0 | ||
127 | #define SRP_ERR_VBASE_INCOMPLETE_FILE 1 | ||
128 | #define SRP_ERR_VBASE_BN_LIB 2 | ||
129 | #define SRP_ERR_OPEN_FILE 3 | ||
130 | #define SRP_ERR_MEMORY 4 | ||
131 | |||
132 | #define DB_srptype 0 | ||
133 | #define DB_srpverifier 1 | ||
134 | #define DB_srpsalt 2 | ||
135 | #define DB_srpid 3 | ||
136 | #define DB_srpgN 4 | ||
137 | #define DB_srpinfo 5 | ||
138 | #undef DB_NUMBER | ||
139 | #define DB_NUMBER 6 | ||
140 | |||
141 | #define DB_SRP_INDEX 'I' | ||
142 | #define DB_SRP_VALID 'V' | ||
143 | #define DB_SRP_REVOKED 'R' | ||
144 | #define DB_SRP_MODIF 'v' | ||
145 | |||
146 | |||
147 | /* see srp.c */ | ||
148 | char * SRP_check_known_gN_param(BIGNUM* g, BIGNUM* N); | ||
149 | SRP_gN *SRP_get_default_gN(const char * id) ; | ||
150 | |||
151 | /* server side .... */ | ||
152 | BIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b, BIGNUM *N); | ||
153 | BIGNUM *SRP_Calc_B(BIGNUM *b, BIGNUM *N, BIGNUM *g, BIGNUM *v); | ||
154 | int SRP_Verify_A_mod_N(BIGNUM *A, BIGNUM *N); | ||
155 | BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N) ; | ||
156 | |||
157 | |||
158 | |||
159 | /* client side .... */ | ||
160 | BIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass); | ||
161 | BIGNUM *SRP_Calc_A(BIGNUM *a, BIGNUM *N, BIGNUM *g); | ||
162 | BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *a, BIGNUM *u); | ||
163 | int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N); | ||
164 | |||
165 | #define SRP_MINIMAL_N 1024 | ||
166 | |||
167 | #ifdef __cplusplus | ||
168 | } | ||
169 | #endif | ||
170 | |||
171 | #endif | ||
172 | #endif | ||
diff --git a/src/lib/libcrypto/srp/srp_grps.h b/src/lib/libcrypto/srp/srp_grps.h new file mode 100644 index 0000000000..d77c9fff4b --- /dev/null +++ b/src/lib/libcrypto/srp/srp_grps.h | |||
@@ -0,0 +1,517 @@ | |||
1 | /* start of generated data */ | ||
2 | |||
3 | static BN_ULONG bn_group_1024_value[] = { | ||
4 | bn_pack4(9FC6,1D2F,C0EB,06E3), | ||
5 | bn_pack4(FD51,38FE,8376,435B), | ||
6 | bn_pack4(2FD4,CBF4,976E,AA9A), | ||
7 | bn_pack4(68ED,BC3C,0572,6CC0), | ||
8 | bn_pack4(C529,F566,660E,57EC), | ||
9 | bn_pack4(8255,9B29,7BCF,1885), | ||
10 | bn_pack4(CE8E,F4AD,69B1,5D49), | ||
11 | bn_pack4(5DC7,D7B4,6154,D6B6), | ||
12 | bn_pack4(8E49,5C1D,6089,DAD1), | ||
13 | bn_pack4(E0D5,D8E2,50B9,8BE4), | ||
14 | bn_pack4(383B,4813,D692,C6E0), | ||
15 | bn_pack4(D674,DF74,96EA,81D3), | ||
16 | bn_pack4(9EA2,314C,9C25,6576), | ||
17 | bn_pack4(6072,6187,75FF,3C0B), | ||
18 | bn_pack4(9C33,F80A,FA8F,C5E8), | ||
19 | bn_pack4(EEAF,0AB9,ADB3,8DD6) | ||
20 | }; | ||
21 | static BIGNUM bn_group_1024 = { | ||
22 | bn_group_1024_value, | ||
23 | (sizeof bn_group_1024_value)/sizeof(BN_ULONG), | ||
24 | (sizeof bn_group_1024_value)/sizeof(BN_ULONG), | ||
25 | 0, | ||
26 | BN_FLG_STATIC_DATA | ||
27 | }; | ||
28 | |||
29 | static BN_ULONG bn_group_1536_value[] = { | ||
30 | bn_pack4(CF76,E3FE,D135,F9BB), | ||
31 | bn_pack4(1518,0F93,499A,234D), | ||
32 | bn_pack4(8CE7,A28C,2442,C6F3), | ||
33 | bn_pack4(5A02,1FFF,5E91,479E), | ||
34 | bn_pack4(7F8A,2FE9,B8B5,292E), | ||
35 | bn_pack4(837C,264A,E3A9,BEB8), | ||
36 | bn_pack4(E442,734A,F7CC,B7AE), | ||
37 | bn_pack4(6577,2E43,7D6C,7F8C), | ||
38 | bn_pack4(DB2F,D53D,24B7,C486), | ||
39 | bn_pack4(6EDF,0195,3934,9627), | ||
40 | bn_pack4(158B,FD3E,2B9C,8CF5), | ||
41 | bn_pack4(764E,3F4B,53DD,9DA1), | ||
42 | bn_pack4(4754,8381,DBC5,B1FC), | ||
43 | bn_pack4(9B60,9E0B,E3BA,B63D), | ||
44 | bn_pack4(8134,B1C8,B979,8914), | ||
45 | bn_pack4(DF02,8A7C,EC67,F0D0), | ||
46 | bn_pack4(80B6,55BB,9A22,E8DC), | ||
47 | bn_pack4(1558,903B,A0D0,F843), | ||
48 | bn_pack4(51C6,A94B,E460,7A29), | ||
49 | bn_pack4(5F4F,5F55,6E27,CBDE), | ||
50 | bn_pack4(BEEE,A961,4B19,CC4D), | ||
51 | bn_pack4(DBA5,1DF4,99AC,4C80), | ||
52 | bn_pack4(B1F1,2A86,17A4,7BBB), | ||
53 | bn_pack4(9DEF,3CAF,B939,277A) | ||
54 | }; | ||
55 | static BIGNUM bn_group_1536 = { | ||
56 | bn_group_1536_value, | ||
57 | (sizeof bn_group_1536_value)/sizeof(BN_ULONG), | ||
58 | (sizeof bn_group_1536_value)/sizeof(BN_ULONG), | ||
59 | 0, | ||
60 | BN_FLG_STATIC_DATA | ||
61 | }; | ||
62 | |||
63 | static BN_ULONG bn_group_2048_value[] = { | ||
64 | bn_pack4(0FA7,111F,9E4A,FF73), | ||
65 | bn_pack4(9B65,E372,FCD6,8EF2), | ||
66 | bn_pack4(35DE,236D,525F,5475), | ||
67 | bn_pack4(94B5,C803,D89F,7AE4), | ||
68 | bn_pack4(71AE,35F8,E9DB,FBB6), | ||
69 | bn_pack4(2A56,98F3,A8D0,C382), | ||
70 | bn_pack4(9CCC,041C,7BC3,08D8), | ||
71 | bn_pack4(AF87,4E73,03CE,5329), | ||
72 | bn_pack4(6160,2790,04E5,7AE6), | ||
73 | bn_pack4(032C,FBDB,F52F,B378), | ||
74 | bn_pack4(5EA7,7A27,75D2,ECFA), | ||
75 | bn_pack4(5445,23B5,24B0,D57D), | ||
76 | bn_pack4(5B9D,32E6,88F8,7748), | ||
77 | bn_pack4(F1D2,B907,8717,461A), | ||
78 | bn_pack4(76BD,207A,436C,6481), | ||
79 | bn_pack4(CA97,B43A,23FB,8016), | ||
80 | bn_pack4(1D28,1E44,6B14,773B), | ||
81 | bn_pack4(7359,D041,D5C3,3EA7), | ||
82 | bn_pack4(A80D,740A,DBF4,FF74), | ||
83 | bn_pack4(55F9,7993,EC97,5EEA), | ||
84 | bn_pack4(2918,A996,2F0B,93B8), | ||
85 | bn_pack4(661A,05FB,D5FA,AAE8), | ||
86 | bn_pack4(CF60,9517,9A16,3AB3), | ||
87 | bn_pack4(E808,3969,EDB7,67B0), | ||
88 | bn_pack4(CD7F,48A9,DA04,FD50), | ||
89 | bn_pack4(D523,12AB,4B03,310D), | ||
90 | bn_pack4(8193,E075,7767,A13D), | ||
91 | bn_pack4(A373,29CB,B4A0,99ED), | ||
92 | bn_pack4(FC31,9294,3DB5,6050), | ||
93 | bn_pack4(AF72,B665,1987,EE07), | ||
94 | bn_pack4(F166,DE5E,1389,582F), | ||
95 | bn_pack4(AC6B,DB41,324A,9A9B) | ||
96 | }; | ||
97 | static BIGNUM bn_group_2048 = { | ||
98 | bn_group_2048_value, | ||
99 | (sizeof bn_group_2048_value)/sizeof(BN_ULONG), | ||
100 | (sizeof bn_group_2048_value)/sizeof(BN_ULONG), | ||
101 | 0, | ||
102 | BN_FLG_STATIC_DATA | ||
103 | }; | ||
104 | |||
105 | static BN_ULONG bn_group_3072_value[] = { | ||
106 | bn_pack4(FFFF,FFFF,FFFF,FFFF), | ||
107 | bn_pack4(4B82,D120,A93A,D2CA), | ||
108 | bn_pack4(43DB,5BFC,E0FD,108E), | ||
109 | bn_pack4(08E2,4FA0,74E5,AB31), | ||
110 | bn_pack4(7709,88C0,BAD9,46E2), | ||
111 | bn_pack4(BBE1,1757,7A61,5D6C), | ||
112 | bn_pack4(521F,2B18,177B,200C), | ||
113 | bn_pack4(D876,0273,3EC8,6A64), | ||
114 | bn_pack4(F12F,FA06,D98A,0864), | ||
115 | bn_pack4(CEE3,D226,1AD2,EE6B), | ||
116 | bn_pack4(1E8C,94E0,4A25,619D), | ||
117 | bn_pack4(ABF5,AE8C,DB09,33D7), | ||
118 | bn_pack4(B397,0F85,A6E1,E4C7), | ||
119 | bn_pack4(8AEA,7157,5D06,0C7D), | ||
120 | bn_pack4(ECFB,8504,58DB,EF0A), | ||
121 | bn_pack4(A855,21AB,DF1C,BA64), | ||
122 | bn_pack4(AD33,170D,0450,7A33), | ||
123 | bn_pack4(1572,8E5A,8AAA,C42D), | ||
124 | bn_pack4(15D2,2618,98FA,0510), | ||
125 | bn_pack4(3995,497C,EA95,6AE5), | ||
126 | bn_pack4(DE2B,CBF6,9558,1718), | ||
127 | bn_pack4(B5C5,5DF0,6F4C,52C9), | ||
128 | bn_pack4(9B27,83A2,EC07,A28F), | ||
129 | bn_pack4(E39E,772C,180E,8603), | ||
130 | bn_pack4(3290,5E46,2E36,CE3B), | ||
131 | bn_pack4(F174,6C08,CA18,217C), | ||
132 | bn_pack4(670C,354E,4ABC,9804), | ||
133 | bn_pack4(9ED5,2907,7096,966D), | ||
134 | bn_pack4(1C62,F356,2085,52BB), | ||
135 | bn_pack4(8365,5D23,DCA3,AD96), | ||
136 | bn_pack4(6916,3FA8,FD24,CF5F), | ||
137 | bn_pack4(98DA,4836,1C55,D39A), | ||
138 | bn_pack4(C200,7CB8,A163,BF05), | ||
139 | bn_pack4(4928,6651,ECE4,5B3D), | ||
140 | bn_pack4(AE9F,2411,7C4B,1FE6), | ||
141 | bn_pack4(EE38,6BFB,5A89,9FA5), | ||
142 | bn_pack4(0BFF,5CB6,F406,B7ED), | ||
143 | bn_pack4(F44C,42E9,A637,ED6B), | ||
144 | bn_pack4(E485,B576,625E,7EC6), | ||
145 | bn_pack4(4FE1,356D,6D51,C245), | ||
146 | bn_pack4(302B,0A6D,F25F,1437), | ||
147 | bn_pack4(EF95,19B3,CD3A,431B), | ||
148 | bn_pack4(514A,0879,8E34,04DD), | ||
149 | bn_pack4(020B,BEA6,3B13,9B22), | ||
150 | bn_pack4(2902,4E08,8A67,CC74), | ||
151 | bn_pack4(C4C6,628B,80DC,1CD1), | ||
152 | bn_pack4(C90F,DAA2,2168,C234), | ||
153 | bn_pack4(FFFF,FFFF,FFFF,FFFF) | ||
154 | }; | ||
155 | static BIGNUM bn_group_3072 = { | ||
156 | bn_group_3072_value, | ||
157 | (sizeof bn_group_3072_value)/sizeof(BN_ULONG), | ||
158 | (sizeof bn_group_3072_value)/sizeof(BN_ULONG), | ||
159 | 0, | ||
160 | BN_FLG_STATIC_DATA | ||
161 | }; | ||
162 | |||
163 | static BN_ULONG bn_group_4096_value[] = { | ||
164 | bn_pack4(FFFF,FFFF,FFFF,FFFF), | ||
165 | bn_pack4(4DF4,35C9,3406,3199), | ||
166 | bn_pack4(86FF,B7DC,90A6,C08F), | ||
167 | bn_pack4(93B4,EA98,8D8F,DDC1), | ||
168 | bn_pack4(D006,9127,D5B0,5AA9), | ||
169 | bn_pack4(B81B,DD76,2170,481C), | ||
170 | bn_pack4(1F61,2970,CEE2,D7AF), | ||
171 | bn_pack4(233B,A186,515B,E7ED), | ||
172 | bn_pack4(99B2,964F,A090,C3A2), | ||
173 | bn_pack4(287C,5947,4E6B,C05D), | ||
174 | bn_pack4(2E8E,FC14,1FBE,CAA6), | ||
175 | bn_pack4(DBBB,C2DB,04DE,8EF9), | ||
176 | bn_pack4(2583,E9CA,2AD4,4CE8), | ||
177 | bn_pack4(1A94,6834,B615,0BDA), | ||
178 | bn_pack4(99C3,2718,6AF4,E23C), | ||
179 | bn_pack4(8871,9A10,BDBA,5B26), | ||
180 | bn_pack4(1A72,3C12,A787,E6D7), | ||
181 | bn_pack4(4B82,D120,A921,0801), | ||
182 | bn_pack4(43DB,5BFC,E0FD,108E), | ||
183 | bn_pack4(08E2,4FA0,74E5,AB31), | ||
184 | bn_pack4(7709,88C0,BAD9,46E2), | ||
185 | bn_pack4(BBE1,1757,7A61,5D6C), | ||
186 | bn_pack4(521F,2B18,177B,200C), | ||
187 | bn_pack4(D876,0273,3EC8,6A64), | ||
188 | bn_pack4(F12F,FA06,D98A,0864), | ||
189 | bn_pack4(CEE3,D226,1AD2,EE6B), | ||
190 | bn_pack4(1E8C,94E0,4A25,619D), | ||
191 | bn_pack4(ABF5,AE8C,DB09,33D7), | ||
192 | bn_pack4(B397,0F85,A6E1,E4C7), | ||
193 | bn_pack4(8AEA,7157,5D06,0C7D), | ||
194 | bn_pack4(ECFB,8504,58DB,EF0A), | ||
195 | bn_pack4(A855,21AB,DF1C,BA64), | ||
196 | bn_pack4(AD33,170D,0450,7A33), | ||
197 | bn_pack4(1572,8E5A,8AAA,C42D), | ||
198 | bn_pack4(15D2,2618,98FA,0510), | ||
199 | bn_pack4(3995,497C,EA95,6AE5), | ||
200 | bn_pack4(DE2B,CBF6,9558,1718), | ||
201 | bn_pack4(B5C5,5DF0,6F4C,52C9), | ||
202 | bn_pack4(9B27,83A2,EC07,A28F), | ||
203 | bn_pack4(E39E,772C,180E,8603), | ||
204 | bn_pack4(3290,5E46,2E36,CE3B), | ||
205 | bn_pack4(F174,6C08,CA18,217C), | ||
206 | bn_pack4(670C,354E,4ABC,9804), | ||
207 | bn_pack4(9ED5,2907,7096,966D), | ||
208 | bn_pack4(1C62,F356,2085,52BB), | ||
209 | bn_pack4(8365,5D23,DCA3,AD96), | ||
210 | bn_pack4(6916,3FA8,FD24,CF5F), | ||
211 | bn_pack4(98DA,4836,1C55,D39A), | ||
212 | bn_pack4(C200,7CB8,A163,BF05), | ||
213 | bn_pack4(4928,6651,ECE4,5B3D), | ||
214 | bn_pack4(AE9F,2411,7C4B,1FE6), | ||
215 | bn_pack4(EE38,6BFB,5A89,9FA5), | ||
216 | bn_pack4(0BFF,5CB6,F406,B7ED), | ||
217 | bn_pack4(F44C,42E9,A637,ED6B), | ||
218 | bn_pack4(E485,B576,625E,7EC6), | ||
219 | bn_pack4(4FE1,356D,6D51,C245), | ||
220 | bn_pack4(302B,0A6D,F25F,1437), | ||
221 | bn_pack4(EF95,19B3,CD3A,431B), | ||
222 | bn_pack4(514A,0879,8E34,04DD), | ||
223 | bn_pack4(020B,BEA6,3B13,9B22), | ||
224 | bn_pack4(2902,4E08,8A67,CC74), | ||
225 | bn_pack4(C4C6,628B,80DC,1CD1), | ||
226 | bn_pack4(C90F,DAA2,2168,C234), | ||
227 | bn_pack4(FFFF,FFFF,FFFF,FFFF) | ||
228 | }; | ||
229 | static BIGNUM bn_group_4096 = { | ||
230 | bn_group_4096_value, | ||
231 | (sizeof bn_group_4096_value)/sizeof(BN_ULONG), | ||
232 | (sizeof bn_group_4096_value)/sizeof(BN_ULONG), | ||
233 | 0, | ||
234 | BN_FLG_STATIC_DATA | ||
235 | }; | ||
236 | |||
237 | static BN_ULONG bn_group_6144_value[] = { | ||
238 | bn_pack4(FFFF,FFFF,FFFF,FFFF), | ||
239 | bn_pack4(E694,F91E,6DCC,4024), | ||
240 | bn_pack4(12BF,2D5B,0B74,74D6), | ||
241 | bn_pack4(043E,8F66,3F48,60EE), | ||
242 | bn_pack4(387F,E8D7,6E3C,0468), | ||
243 | bn_pack4(DA56,C9EC,2EF2,9632), | ||
244 | bn_pack4(EB19,CCB1,A313,D55C), | ||
245 | bn_pack4(F550,AA3D,8A1F,BFF0), | ||
246 | bn_pack4(06A1,D58B,B7C5,DA76), | ||
247 | bn_pack4(A797,15EE,F29B,E328), | ||
248 | bn_pack4(14CC,5ED2,0F80,37E0), | ||
249 | bn_pack4(CC8F,6D7E,BF48,E1D8), | ||
250 | bn_pack4(4BD4,07B2,2B41,54AA), | ||
251 | bn_pack4(0F1D,45B7,FF58,5AC5), | ||
252 | bn_pack4(23A9,7A7E,36CC,88BE), | ||
253 | bn_pack4(59E7,C97F,BEC7,E8F3), | ||
254 | bn_pack4(B5A8,4031,900B,1C9E), | ||
255 | bn_pack4(D55E,702F,4698,0C82), | ||
256 | bn_pack4(F482,D7CE,6E74,FEF6), | ||
257 | bn_pack4(F032,EA15,D172,1D03), | ||
258 | bn_pack4(5983,CA01,C64B,92EC), | ||
259 | bn_pack4(6FB8,F401,378C,D2BF), | ||
260 | bn_pack4(3320,5151,2BD7,AF42), | ||
261 | bn_pack4(DB7F,1447,E6CC,254B), | ||
262 | bn_pack4(44CE,6CBA,CED4,BB1B), | ||
263 | bn_pack4(DA3E,DBEB,CF9B,14ED), | ||
264 | bn_pack4(1797,27B0,865A,8918), | ||
265 | bn_pack4(B06A,53ED,9027,D831), | ||
266 | bn_pack4(E5DB,382F,4130,01AE), | ||
267 | bn_pack4(F8FF,9406,AD9E,530E), | ||
268 | bn_pack4(C975,1E76,3DBA,37BD), | ||
269 | bn_pack4(C1D4,DCB2,6026,46DE), | ||
270 | bn_pack4(36C3,FAB4,D27C,7026), | ||
271 | bn_pack4(4DF4,35C9,3402,8492), | ||
272 | bn_pack4(86FF,B7DC,90A6,C08F), | ||
273 | bn_pack4(93B4,EA98,8D8F,DDC1), | ||
274 | bn_pack4(D006,9127,D5B0,5AA9), | ||
275 | bn_pack4(B81B,DD76,2170,481C), | ||
276 | bn_pack4(1F61,2970,CEE2,D7AF), | ||
277 | bn_pack4(233B,A186,515B,E7ED), | ||
278 | bn_pack4(99B2,964F,A090,C3A2), | ||
279 | bn_pack4(287C,5947,4E6B,C05D), | ||
280 | bn_pack4(2E8E,FC14,1FBE,CAA6), | ||
281 | bn_pack4(DBBB,C2DB,04DE,8EF9), | ||
282 | bn_pack4(2583,E9CA,2AD4,4CE8), | ||
283 | bn_pack4(1A94,6834,B615,0BDA), | ||
284 | bn_pack4(99C3,2718,6AF4,E23C), | ||
285 | bn_pack4(8871,9A10,BDBA,5B26), | ||
286 | bn_pack4(1A72,3C12,A787,E6D7), | ||
287 | bn_pack4(4B82,D120,A921,0801), | ||
288 | bn_pack4(43DB,5BFC,E0FD,108E), | ||
289 | bn_pack4(08E2,4FA0,74E5,AB31), | ||
290 | bn_pack4(7709,88C0,BAD9,46E2), | ||
291 | bn_pack4(BBE1,1757,7A61,5D6C), | ||
292 | bn_pack4(521F,2B18,177B,200C), | ||
293 | bn_pack4(D876,0273,3EC8,6A64), | ||
294 | bn_pack4(F12F,FA06,D98A,0864), | ||
295 | bn_pack4(CEE3,D226,1AD2,EE6B), | ||
296 | bn_pack4(1E8C,94E0,4A25,619D), | ||
297 | bn_pack4(ABF5,AE8C,DB09,33D7), | ||
298 | bn_pack4(B397,0F85,A6E1,E4C7), | ||
299 | bn_pack4(8AEA,7157,5D06,0C7D), | ||
300 | bn_pack4(ECFB,8504,58DB,EF0A), | ||
301 | bn_pack4(A855,21AB,DF1C,BA64), | ||
302 | bn_pack4(AD33,170D,0450,7A33), | ||
303 | bn_pack4(1572,8E5A,8AAA,C42D), | ||
304 | bn_pack4(15D2,2618,98FA,0510), | ||
305 | bn_pack4(3995,497C,EA95,6AE5), | ||
306 | bn_pack4(DE2B,CBF6,9558,1718), | ||
307 | bn_pack4(B5C5,5DF0,6F4C,52C9), | ||
308 | bn_pack4(9B27,83A2,EC07,A28F), | ||
309 | bn_pack4(E39E,772C,180E,8603), | ||
310 | bn_pack4(3290,5E46,2E36,CE3B), | ||
311 | bn_pack4(F174,6C08,CA18,217C), | ||
312 | bn_pack4(670C,354E,4ABC,9804), | ||
313 | bn_pack4(9ED5,2907,7096,966D), | ||
314 | bn_pack4(1C62,F356,2085,52BB), | ||
315 | bn_pack4(8365,5D23,DCA3,AD96), | ||
316 | bn_pack4(6916,3FA8,FD24,CF5F), | ||
317 | bn_pack4(98DA,4836,1C55,D39A), | ||
318 | bn_pack4(C200,7CB8,A163,BF05), | ||
319 | bn_pack4(4928,6651,ECE4,5B3D), | ||
320 | bn_pack4(AE9F,2411,7C4B,1FE6), | ||
321 | bn_pack4(EE38,6BFB,5A89,9FA5), | ||
322 | bn_pack4(0BFF,5CB6,F406,B7ED), | ||
323 | bn_pack4(F44C,42E9,A637,ED6B), | ||
324 | bn_pack4(E485,B576,625E,7EC6), | ||
325 | bn_pack4(4FE1,356D,6D51,C245), | ||
326 | bn_pack4(302B,0A6D,F25F,1437), | ||
327 | bn_pack4(EF95,19B3,CD3A,431B), | ||
328 | bn_pack4(514A,0879,8E34,04DD), | ||
329 | bn_pack4(020B,BEA6,3B13,9B22), | ||
330 | bn_pack4(2902,4E08,8A67,CC74), | ||
331 | bn_pack4(C4C6,628B,80DC,1CD1), | ||
332 | bn_pack4(C90F,DAA2,2168,C234), | ||
333 | bn_pack4(FFFF,FFFF,FFFF,FFFF) | ||
334 | }; | ||
335 | static BIGNUM bn_group_6144 = { | ||
336 | bn_group_6144_value, | ||
337 | (sizeof bn_group_6144_value)/sizeof(BN_ULONG), | ||
338 | (sizeof bn_group_6144_value)/sizeof(BN_ULONG), | ||
339 | 0, | ||
340 | BN_FLG_STATIC_DATA | ||
341 | }; | ||
342 | |||
343 | static BN_ULONG bn_group_8192_value[] = { | ||
344 | bn_pack4(FFFF,FFFF,FFFF,FFFF), | ||
345 | bn_pack4(60C9,80DD,98ED,D3DF), | ||
346 | bn_pack4(C81F,56E8,80B9,6E71), | ||
347 | bn_pack4(9E30,50E2,7656,94DF), | ||
348 | bn_pack4(9558,E447,5677,E9AA), | ||
349 | bn_pack4(C919,0DA6,FC02,6E47), | ||
350 | bn_pack4(889A,002E,D5EE,382B), | ||
351 | bn_pack4(4009,438B,481C,6CD7), | ||
352 | bn_pack4(3590,46F4,EB87,9F92), | ||
353 | bn_pack4(FAF3,6BC3,1ECF,A268), | ||
354 | bn_pack4(B1D5,10BD,7EE7,4D73), | ||
355 | bn_pack4(F9AB,4819,5DED,7EA1), | ||
356 | bn_pack4(64F3,1CC5,0846,851D), | ||
357 | bn_pack4(4597,E899,A025,5DC1), | ||
358 | bn_pack4(DF31,0EE0,74AB,6A36), | ||
359 | bn_pack4(6D2A,13F8,3F44,F82D), | ||
360 | bn_pack4(062B,3CF5,B3A2,78A6), | ||
361 | bn_pack4(7968,3303,ED5B,DD3A), | ||
362 | bn_pack4(FA9D,4B7F,A2C0,87E8), | ||
363 | bn_pack4(4BCB,C886,2F83,85DD), | ||
364 | bn_pack4(3473,FC64,6CEA,306B), | ||
365 | bn_pack4(13EB,57A8,1A23,F0C7), | ||
366 | bn_pack4(2222,2E04,A403,7C07), | ||
367 | bn_pack4(E3FD,B8BE,FC84,8AD9), | ||
368 | bn_pack4(238F,16CB,E39D,652D), | ||
369 | bn_pack4(3423,B474,2BF1,C978), | ||
370 | bn_pack4(3AAB,639C,5AE4,F568), | ||
371 | bn_pack4(2576,F693,6BA4,2466), | ||
372 | bn_pack4(741F,A7BF,8AFC,47ED), | ||
373 | bn_pack4(3BC8,32B6,8D9D,D300), | ||
374 | bn_pack4(D8BE,C4D0,73B9,31BA), | ||
375 | bn_pack4(3877,7CB6,A932,DF8C), | ||
376 | bn_pack4(74A3,926F,12FE,E5E4), | ||
377 | bn_pack4(E694,F91E,6DBE,1159), | ||
378 | bn_pack4(12BF,2D5B,0B74,74D6), | ||
379 | bn_pack4(043E,8F66,3F48,60EE), | ||
380 | bn_pack4(387F,E8D7,6E3C,0468), | ||
381 | bn_pack4(DA56,C9EC,2EF2,9632), | ||
382 | bn_pack4(EB19,CCB1,A313,D55C), | ||
383 | bn_pack4(F550,AA3D,8A1F,BFF0), | ||
384 | bn_pack4(06A1,D58B,B7C5,DA76), | ||
385 | bn_pack4(A797,15EE,F29B,E328), | ||
386 | bn_pack4(14CC,5ED2,0F80,37E0), | ||
387 | bn_pack4(CC8F,6D7E,BF48,E1D8), | ||
388 | bn_pack4(4BD4,07B2,2B41,54AA), | ||
389 | bn_pack4(0F1D,45B7,FF58,5AC5), | ||
390 | bn_pack4(23A9,7A7E,36CC,88BE), | ||
391 | bn_pack4(59E7,C97F,BEC7,E8F3), | ||
392 | bn_pack4(B5A8,4031,900B,1C9E), | ||
393 | bn_pack4(D55E,702F,4698,0C82), | ||
394 | bn_pack4(F482,D7CE,6E74,FEF6), | ||
395 | bn_pack4(F032,EA15,D172,1D03), | ||
396 | bn_pack4(5983,CA01,C64B,92EC), | ||
397 | bn_pack4(6FB8,F401,378C,D2BF), | ||
398 | bn_pack4(3320,5151,2BD7,AF42), | ||
399 | bn_pack4(DB7F,1447,E6CC,254B), | ||
400 | bn_pack4(44CE,6CBA,CED4,BB1B), | ||
401 | bn_pack4(DA3E,DBEB,CF9B,14ED), | ||
402 | bn_pack4(1797,27B0,865A,8918), | ||
403 | bn_pack4(B06A,53ED,9027,D831), | ||
404 | bn_pack4(E5DB,382F,4130,01AE), | ||
405 | bn_pack4(F8FF,9406,AD9E,530E), | ||
406 | bn_pack4(C975,1E76,3DBA,37BD), | ||
407 | bn_pack4(C1D4,DCB2,6026,46DE), | ||
408 | bn_pack4(36C3,FAB4,D27C,7026), | ||
409 | bn_pack4(4DF4,35C9,3402,8492), | ||
410 | bn_pack4(86FF,B7DC,90A6,C08F), | ||
411 | bn_pack4(93B4,EA98,8D8F,DDC1), | ||
412 | bn_pack4(D006,9127,D5B0,5AA9), | ||
413 | bn_pack4(B81B,DD76,2170,481C), | ||
414 | bn_pack4(1F61,2970,CEE2,D7AF), | ||
415 | bn_pack4(233B,A186,515B,E7ED), | ||
416 | bn_pack4(99B2,964F,A090,C3A2), | ||
417 | bn_pack4(287C,5947,4E6B,C05D), | ||
418 | bn_pack4(2E8E,FC14,1FBE,CAA6), | ||
419 | bn_pack4(DBBB,C2DB,04DE,8EF9), | ||
420 | bn_pack4(2583,E9CA,2AD4,4CE8), | ||
421 | bn_pack4(1A94,6834,B615,0BDA), | ||
422 | bn_pack4(99C3,2718,6AF4,E23C), | ||
423 | bn_pack4(8871,9A10,BDBA,5B26), | ||
424 | bn_pack4(1A72,3C12,A787,E6D7), | ||
425 | bn_pack4(4B82,D120,A921,0801), | ||
426 | bn_pack4(43DB,5BFC,E0FD,108E), | ||
427 | bn_pack4(08E2,4FA0,74E5,AB31), | ||
428 | bn_pack4(7709,88C0,BAD9,46E2), | ||
429 | bn_pack4(BBE1,1757,7A61,5D6C), | ||
430 | bn_pack4(521F,2B18,177B,200C), | ||
431 | bn_pack4(D876,0273,3EC8,6A64), | ||
432 | bn_pack4(F12F,FA06,D98A,0864), | ||
433 | bn_pack4(CEE3,D226,1AD2,EE6B), | ||
434 | bn_pack4(1E8C,94E0,4A25,619D), | ||
435 | bn_pack4(ABF5,AE8C,DB09,33D7), | ||
436 | bn_pack4(B397,0F85,A6E1,E4C7), | ||
437 | bn_pack4(8AEA,7157,5D06,0C7D), | ||
438 | bn_pack4(ECFB,8504,58DB,EF0A), | ||
439 | bn_pack4(A855,21AB,DF1C,BA64), | ||
440 | bn_pack4(AD33,170D,0450,7A33), | ||
441 | bn_pack4(1572,8E5A,8AAA,C42D), | ||
442 | bn_pack4(15D2,2618,98FA,0510), | ||
443 | bn_pack4(3995,497C,EA95,6AE5), | ||
444 | bn_pack4(DE2B,CBF6,9558,1718), | ||
445 | bn_pack4(B5C5,5DF0,6F4C,52C9), | ||
446 | bn_pack4(9B27,83A2,EC07,A28F), | ||
447 | bn_pack4(E39E,772C,180E,8603), | ||
448 | bn_pack4(3290,5E46,2E36,CE3B), | ||
449 | bn_pack4(F174,6C08,CA18,217C), | ||
450 | bn_pack4(670C,354E,4ABC,9804), | ||
451 | bn_pack4(9ED5,2907,7096,966D), | ||
452 | bn_pack4(1C62,F356,2085,52BB), | ||
453 | bn_pack4(8365,5D23,DCA3,AD96), | ||
454 | bn_pack4(6916,3FA8,FD24,CF5F), | ||
455 | bn_pack4(98DA,4836,1C55,D39A), | ||
456 | bn_pack4(C200,7CB8,A163,BF05), | ||
457 | bn_pack4(4928,6651,ECE4,5B3D), | ||
458 | bn_pack4(AE9F,2411,7C4B,1FE6), | ||
459 | bn_pack4(EE38,6BFB,5A89,9FA5), | ||
460 | bn_pack4(0BFF,5CB6,F406,B7ED), | ||
461 | bn_pack4(F44C,42E9,A637,ED6B), | ||
462 | bn_pack4(E485,B576,625E,7EC6), | ||
463 | bn_pack4(4FE1,356D,6D51,C245), | ||
464 | bn_pack4(302B,0A6D,F25F,1437), | ||
465 | bn_pack4(EF95,19B3,CD3A,431B), | ||
466 | bn_pack4(514A,0879,8E34,04DD), | ||
467 | bn_pack4(020B,BEA6,3B13,9B22), | ||
468 | bn_pack4(2902,4E08,8A67,CC74), | ||
469 | bn_pack4(C4C6,628B,80DC,1CD1), | ||
470 | bn_pack4(C90F,DAA2,2168,C234), | ||
471 | bn_pack4(FFFF,FFFF,FFFF,FFFF) | ||
472 | }; | ||
473 | static BIGNUM bn_group_8192 = { | ||
474 | bn_group_8192_value, | ||
475 | (sizeof bn_group_8192_value)/sizeof(BN_ULONG), | ||
476 | (sizeof bn_group_8192_value)/sizeof(BN_ULONG), | ||
477 | 0, | ||
478 | BN_FLG_STATIC_DATA | ||
479 | }; | ||
480 | |||
481 | static BN_ULONG bn_generator_19_value[] = {19} ; | ||
482 | static BIGNUM bn_generator_19 = { | ||
483 | bn_generator_19_value, | ||
484 | 1, | ||
485 | 1, | ||
486 | 0, | ||
487 | BN_FLG_STATIC_DATA | ||
488 | }; | ||
489 | static BN_ULONG bn_generator_5_value[] = {5} ; | ||
490 | static BIGNUM bn_generator_5 = { | ||
491 | bn_generator_5_value, | ||
492 | 1, | ||
493 | 1, | ||
494 | 0, | ||
495 | BN_FLG_STATIC_DATA | ||
496 | }; | ||
497 | static BN_ULONG bn_generator_2_value[] = {2} ; | ||
498 | static BIGNUM bn_generator_2 = { | ||
499 | bn_generator_2_value, | ||
500 | 1, | ||
501 | 1, | ||
502 | 0, | ||
503 | BN_FLG_STATIC_DATA | ||
504 | }; | ||
505 | |||
506 | static SRP_gN knowngN[] = { | ||
507 | {"8192",&bn_generator_19 , &bn_group_8192}, | ||
508 | {"6144",&bn_generator_5 , &bn_group_6144}, | ||
509 | {"4096",&bn_generator_5 , &bn_group_4096}, | ||
510 | {"3072",&bn_generator_5 , &bn_group_3072}, | ||
511 | {"2048",&bn_generator_2 , &bn_group_2048}, | ||
512 | {"1536",&bn_generator_2 , &bn_group_1536}, | ||
513 | {"1024",&bn_generator_2 , &bn_group_1024}, | ||
514 | }; | ||
515 | #define KNOWN_GN_NUMBER sizeof(knowngN) / sizeof(SRP_gN) | ||
516 | |||
517 | /* end of generated data */ | ||
diff --git a/src/lib/libcrypto/srp/srp_lcl.h b/src/lib/libcrypto/srp/srp_lcl.h new file mode 100644 index 0000000000..42bda3f148 --- /dev/null +++ b/src/lib/libcrypto/srp/srp_lcl.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* crypto/srp/srp_lcl.h */ | ||
2 | /* Written by Peter Sylvester (peter.sylvester@edelweb.fr) | ||
3 | * for the EdelKey project and contributed to the OpenSSL project 2004. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * licensing@OpenSSL.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | #ifndef HEADER_SRP_LCL_H | ||
59 | #define HEADER_SRP_LCL_H | ||
60 | |||
61 | #include <openssl/srp.h> | ||
62 | #include <openssl/sha.h> | ||
63 | |||
64 | #if 0 | ||
65 | #define srp_bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \ | ||
66 | fprintf(stderr,"\n");} | ||
67 | #else | ||
68 | #define srp_bn_print(a) | ||
69 | #endif | ||
70 | |||
71 | |||
72 | |||
73 | #ifdef __cplusplus | ||
74 | extern "C" { | ||
75 | #endif | ||
76 | |||
77 | |||
78 | |||
79 | #ifdef __cplusplus | ||
80 | } | ||
81 | #endif | ||
82 | |||
83 | #endif | ||
diff --git a/src/lib/libcrypto/srp/srp_lib.c b/src/lib/libcrypto/srp/srp_lib.c new file mode 100644 index 0000000000..92cea98dcd --- /dev/null +++ b/src/lib/libcrypto/srp/srp_lib.c | |||
@@ -0,0 +1,357 @@ | |||
1 | /* crypto/srp/srp_lib.c */ | ||
2 | /* Written by Christophe Renou (christophe.renou@edelweb.fr) with | ||
3 | * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr) | ||
4 | * for the EdelKey project and contributed to the OpenSSL project 2004. | ||
5 | */ | ||
6 | /* ==================================================================== | ||
7 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in | ||
18 | * the documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * 3. All advertising materials mentioning features or use of this | ||
22 | * software must display the following acknowledgment: | ||
23 | * "This product includes software developed by the OpenSSL Project | ||
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
25 | * | ||
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
27 | * endorse or promote products derived from this software without | ||
28 | * prior written permission. For written permission, please contact | ||
29 | * licensing@OpenSSL.org. | ||
30 | * | ||
31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
32 | * nor may "OpenSSL" appear in their names without prior written | ||
33 | * permission of the OpenSSL Project. | ||
34 | * | ||
35 | * 6. Redistributions of any form whatsoever must retain the following | ||
36 | * acknowledgment: | ||
37 | * "This product includes software developed by the OpenSSL Project | ||
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
39 | * | ||
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
52 | * ==================================================================== | ||
53 | * | ||
54 | * This product includes cryptographic software written by Eric Young | ||
55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
56 | * Hudson (tjh@cryptsoft.com). | ||
57 | * | ||
58 | */ | ||
59 | #ifndef OPENSSL_NO_SRP | ||
60 | #include "cryptlib.h" | ||
61 | #include "srp_lcl.h" | ||
62 | #include <openssl/srp.h> | ||
63 | #include <openssl/evp.h> | ||
64 | |||
65 | #if (BN_BYTES == 8) | ||
66 | #define bn_pack4(a1,a2,a3,a4) 0x##a1##a2##a3##a4##ul | ||
67 | #endif | ||
68 | #if (BN_BYTES == 4) | ||
69 | #define bn_pack4(a1,a2,a3,a4) 0x##a3##a4##ul, 0x##a1##a2##ul | ||
70 | #endif | ||
71 | #if (BN_BYTES == 2) | ||
72 | #define bn_pack4(a1,a2,a3,a4) 0x##a4##u,0x##a3##u,0x##a2##u,0x##a1##u | ||
73 | #endif | ||
74 | |||
75 | |||
76 | #include "srp_grps.h" | ||
77 | |||
78 | static BIGNUM *srp_Calc_k(BIGNUM *N, BIGNUM *g) | ||
79 | { | ||
80 | /* k = SHA1(N | PAD(g)) -- tls-srp draft 8 */ | ||
81 | |||
82 | unsigned char digest[SHA_DIGEST_LENGTH]; | ||
83 | unsigned char *tmp; | ||
84 | EVP_MD_CTX ctxt; | ||
85 | int longg ; | ||
86 | int longN = BN_num_bytes(N); | ||
87 | |||
88 | if ((tmp = OPENSSL_malloc(longN)) == NULL) | ||
89 | return NULL; | ||
90 | BN_bn2bin(N,tmp) ; | ||
91 | |||
92 | EVP_MD_CTX_init(&ctxt); | ||
93 | EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); | ||
94 | EVP_DigestUpdate(&ctxt, tmp, longN); | ||
95 | |||
96 | memset(tmp, 0, longN); | ||
97 | longg = BN_bn2bin(g,tmp) ; | ||
98 | /* use the zeros behind to pad on left */ | ||
99 | EVP_DigestUpdate(&ctxt, tmp + longg, longN-longg); | ||
100 | EVP_DigestUpdate(&ctxt, tmp, longg); | ||
101 | OPENSSL_free(tmp); | ||
102 | |||
103 | EVP_DigestFinal_ex(&ctxt, digest, NULL); | ||
104 | EVP_MD_CTX_cleanup(&ctxt); | ||
105 | return BN_bin2bn(digest, sizeof(digest), NULL); | ||
106 | } | ||
107 | |||
108 | BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N) | ||
109 | { | ||
110 | /* k = SHA1(PAD(A) || PAD(B) ) -- tls-srp draft 8 */ | ||
111 | |||
112 | BIGNUM *u; | ||
113 | unsigned char cu[SHA_DIGEST_LENGTH]; | ||
114 | unsigned char *cAB; | ||
115 | EVP_MD_CTX ctxt; | ||
116 | int longN; | ||
117 | if ((A == NULL) ||(B == NULL) || (N == NULL)) | ||
118 | return NULL; | ||
119 | |||
120 | longN= BN_num_bytes(N); | ||
121 | |||
122 | if ((cAB = OPENSSL_malloc(2*longN)) == NULL) | ||
123 | return NULL; | ||
124 | |||
125 | memset(cAB, 0, longN); | ||
126 | |||
127 | EVP_MD_CTX_init(&ctxt); | ||
128 | EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); | ||
129 | EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(A,cAB+longN), longN); | ||
130 | EVP_DigestUpdate(&ctxt, cAB + BN_bn2bin(B,cAB+longN), longN); | ||
131 | OPENSSL_free(cAB); | ||
132 | EVP_DigestFinal_ex(&ctxt, cu, NULL); | ||
133 | EVP_MD_CTX_cleanup(&ctxt); | ||
134 | |||
135 | if (!(u = BN_bin2bn(cu, sizeof(cu), NULL))) | ||
136 | return NULL; | ||
137 | if (!BN_is_zero(u)) | ||
138 | return u; | ||
139 | BN_free(u); | ||
140 | return NULL; | ||
141 | } | ||
142 | |||
143 | BIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b, BIGNUM *N) | ||
144 | { | ||
145 | BIGNUM *tmp = NULL, *S = NULL; | ||
146 | BN_CTX *bn_ctx; | ||
147 | |||
148 | if (u == NULL || A == NULL || v == NULL || b == NULL || N == NULL) | ||
149 | return NULL; | ||
150 | |||
151 | if ((bn_ctx = BN_CTX_new()) == NULL || | ||
152 | (tmp = BN_new()) == NULL || | ||
153 | (S = BN_new()) == NULL ) | ||
154 | goto err; | ||
155 | |||
156 | /* S = (A*v**u) ** b */ | ||
157 | |||
158 | if (!BN_mod_exp(tmp,v,u,N,bn_ctx)) | ||
159 | goto err; | ||
160 | if (!BN_mod_mul(tmp,A,tmp,N,bn_ctx)) | ||
161 | goto err; | ||
162 | if (!BN_mod_exp(S,tmp,b,N,bn_ctx)) | ||
163 | goto err; | ||
164 | err: | ||
165 | BN_CTX_free(bn_ctx); | ||
166 | BN_clear_free(tmp); | ||
167 | return S; | ||
168 | } | ||
169 | |||
170 | BIGNUM *SRP_Calc_B(BIGNUM *b, BIGNUM *N, BIGNUM *g, BIGNUM *v) | ||
171 | { | ||
172 | BIGNUM *kv = NULL, *gb = NULL; | ||
173 | BIGNUM *B = NULL, *k = NULL; | ||
174 | BN_CTX *bn_ctx; | ||
175 | |||
176 | if (b == NULL || N == NULL || g == NULL || v == NULL || | ||
177 | (bn_ctx = BN_CTX_new()) == NULL) | ||
178 | return NULL; | ||
179 | |||
180 | if ( (kv = BN_new()) == NULL || | ||
181 | (gb = BN_new()) == NULL || | ||
182 | (B = BN_new())== NULL) | ||
183 | goto err; | ||
184 | |||
185 | /* B = g**b + k*v */ | ||
186 | |||
187 | if (!BN_mod_exp(gb,g,b,N,bn_ctx) || | ||
188 | !(k = srp_Calc_k(N,g)) || | ||
189 | !BN_mod_mul(kv,v,k,N,bn_ctx) || | ||
190 | !BN_mod_add(B,gb,kv,N,bn_ctx)) | ||
191 | { | ||
192 | BN_free(B); | ||
193 | B = NULL; | ||
194 | } | ||
195 | err: | ||
196 | BN_CTX_free(bn_ctx); | ||
197 | BN_clear_free(kv); | ||
198 | BN_clear_free(gb); | ||
199 | BN_free(k); | ||
200 | return B; | ||
201 | } | ||
202 | |||
203 | BIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass) | ||
204 | { | ||
205 | unsigned char dig[SHA_DIGEST_LENGTH]; | ||
206 | EVP_MD_CTX ctxt; | ||
207 | unsigned char *cs; | ||
208 | |||
209 | if ((s == NULL) || | ||
210 | (user == NULL) || | ||
211 | (pass == NULL)) | ||
212 | return NULL; | ||
213 | |||
214 | if ((cs = OPENSSL_malloc(BN_num_bytes(s))) == NULL) | ||
215 | return NULL; | ||
216 | |||
217 | EVP_MD_CTX_init(&ctxt); | ||
218 | EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); | ||
219 | EVP_DigestUpdate(&ctxt, user, strlen(user)); | ||
220 | EVP_DigestUpdate(&ctxt, ":", 1); | ||
221 | EVP_DigestUpdate(&ctxt, pass, strlen(pass)); | ||
222 | EVP_DigestFinal_ex(&ctxt, dig, NULL); | ||
223 | |||
224 | EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); | ||
225 | BN_bn2bin(s,cs); | ||
226 | EVP_DigestUpdate(&ctxt, cs, BN_num_bytes(s)); | ||
227 | OPENSSL_free(cs); | ||
228 | EVP_DigestUpdate(&ctxt, dig, sizeof(dig)); | ||
229 | EVP_DigestFinal_ex(&ctxt, dig, NULL); | ||
230 | EVP_MD_CTX_cleanup(&ctxt); | ||
231 | |||
232 | return BN_bin2bn(dig, sizeof(dig), NULL); | ||
233 | } | ||
234 | |||
235 | BIGNUM *SRP_Calc_A(BIGNUM *a, BIGNUM *N, BIGNUM *g) | ||
236 | { | ||
237 | BN_CTX *bn_ctx; | ||
238 | BIGNUM * A = NULL; | ||
239 | |||
240 | if (a == NULL || N == NULL || g == NULL || | ||
241 | (bn_ctx = BN_CTX_new()) == NULL) | ||
242 | return NULL; | ||
243 | |||
244 | if ((A = BN_new()) != NULL && | ||
245 | !BN_mod_exp(A,g,a,N,bn_ctx)) | ||
246 | { | ||
247 | BN_free(A); | ||
248 | A = NULL; | ||
249 | } | ||
250 | BN_CTX_free(bn_ctx); | ||
251 | return A; | ||
252 | } | ||
253 | |||
254 | |||
255 | BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, BIGNUM *a, BIGNUM *u) | ||
256 | { | ||
257 | BIGNUM *tmp = NULL, *tmp2 = NULL, *tmp3 = NULL , *k = NULL, *K = NULL; | ||
258 | BN_CTX *bn_ctx; | ||
259 | |||
260 | if (u == NULL || B == NULL || N == NULL || g == NULL || x == NULL || a == NULL || | ||
261 | (bn_ctx = BN_CTX_new()) == NULL) | ||
262 | return NULL; | ||
263 | |||
264 | if ((tmp = BN_new()) == NULL || | ||
265 | (tmp2 = BN_new())== NULL || | ||
266 | (tmp3 = BN_new())== NULL || | ||
267 | (K = BN_new()) == NULL) | ||
268 | goto err; | ||
269 | |||
270 | if (!BN_mod_exp(tmp,g,x,N,bn_ctx)) | ||
271 | goto err; | ||
272 | if (!(k = srp_Calc_k(N,g))) | ||
273 | goto err; | ||
274 | if (!BN_mod_mul(tmp2,tmp,k,N,bn_ctx)) | ||
275 | goto err; | ||
276 | if (!BN_mod_sub(tmp,B,tmp2,N,bn_ctx)) | ||
277 | goto err; | ||
278 | |||
279 | if (!BN_mod_mul(tmp3,u,x,N,bn_ctx)) | ||
280 | goto err; | ||
281 | if (!BN_mod_add(tmp2,a,tmp3,N,bn_ctx)) | ||
282 | goto err; | ||
283 | if (!BN_mod_exp(K,tmp,tmp2,N,bn_ctx)) | ||
284 | goto err; | ||
285 | |||
286 | err : | ||
287 | BN_CTX_free(bn_ctx); | ||
288 | BN_clear_free(tmp); | ||
289 | BN_clear_free(tmp2); | ||
290 | BN_clear_free(tmp3); | ||
291 | BN_free(k); | ||
292 | return K; | ||
293 | } | ||
294 | |||
295 | int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N) | ||
296 | { | ||
297 | BIGNUM *r; | ||
298 | BN_CTX *bn_ctx; | ||
299 | int ret = 0; | ||
300 | |||
301 | if (B == NULL || N == NULL || | ||
302 | (bn_ctx = BN_CTX_new()) == NULL) | ||
303 | return 0; | ||
304 | |||
305 | if ((r = BN_new()) == NULL) | ||
306 | goto err; | ||
307 | /* Checks if B % N == 0 */ | ||
308 | if (!BN_nnmod(r,B,N,bn_ctx)) | ||
309 | goto err; | ||
310 | ret = !BN_is_zero(r); | ||
311 | err: | ||
312 | BN_CTX_free(bn_ctx); | ||
313 | BN_free(r); | ||
314 | return ret; | ||
315 | } | ||
316 | |||
317 | int SRP_Verify_A_mod_N(BIGNUM *A, BIGNUM *N) | ||
318 | { | ||
319 | /* Checks if A % N == 0 */ | ||
320 | return SRP_Verify_B_mod_N(A,N) ; | ||
321 | } | ||
322 | |||
323 | |||
324 | /* Check if G and N are kwown parameters. | ||
325 | The values have been generated from the ietf-tls-srp draft version 8 | ||
326 | */ | ||
327 | char *SRP_check_known_gN_param(BIGNUM *g, BIGNUM *N) | ||
328 | { | ||
329 | size_t i; | ||
330 | if ((g == NULL) || (N == NULL)) | ||
331 | return 0; | ||
332 | |||
333 | srp_bn_print(g); | ||
334 | srp_bn_print(N); | ||
335 | |||
336 | for(i = 0; i < KNOWN_GN_NUMBER; i++) | ||
337 | { | ||
338 | if (BN_cmp(knowngN[i].g, g) == 0 && BN_cmp(knowngN[i].N, N) == 0) | ||
339 | return knowngN[i].id; | ||
340 | } | ||
341 | return NULL; | ||
342 | } | ||
343 | |||
344 | SRP_gN *SRP_get_default_gN(const char *id) | ||
345 | { | ||
346 | size_t i; | ||
347 | |||
348 | if (id == NULL) | ||
349 | return knowngN; | ||
350 | for(i = 0; i < KNOWN_GN_NUMBER; i++) | ||
351 | { | ||
352 | if (strcmp(knowngN[i].id, id)==0) | ||
353 | return knowngN + i; | ||
354 | } | ||
355 | return NULL; | ||
356 | } | ||
357 | #endif | ||
diff --git a/src/lib/libcrypto/srp/srp_vfy.c b/src/lib/libcrypto/srp/srp_vfy.c new file mode 100644 index 0000000000..c8be907d7f --- /dev/null +++ b/src/lib/libcrypto/srp/srp_vfy.c | |||
@@ -0,0 +1,657 @@ | |||
1 | /* crypto/srp/srp_vfy.c */ | ||
2 | /* Written by Christophe Renou (christophe.renou@edelweb.fr) with | ||
3 | * the precious help of Peter Sylvester (peter.sylvester@edelweb.fr) | ||
4 | * for the EdelKey project and contributed to the OpenSSL project 2004. | ||
5 | */ | ||
6 | /* ==================================================================== | ||
7 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in | ||
18 | * the documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * 3. All advertising materials mentioning features or use of this | ||
22 | * software must display the following acknowledgment: | ||
23 | * "This product includes software developed by the OpenSSL Project | ||
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
25 | * | ||
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
27 | * endorse or promote products derived from this software without | ||
28 | * prior written permission. For written permission, please contact | ||
29 | * licensing@OpenSSL.org. | ||
30 | * | ||
31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
32 | * nor may "OpenSSL" appear in their names without prior written | ||
33 | * permission of the OpenSSL Project. | ||
34 | * | ||
35 | * 6. Redistributions of any form whatsoever must retain the following | ||
36 | * acknowledgment: | ||
37 | * "This product includes software developed by the OpenSSL Project | ||
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
39 | * | ||
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
52 | * ==================================================================== | ||
53 | * | ||
54 | * This product includes cryptographic software written by Eric Young | ||
55 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
56 | * Hudson (tjh@cryptsoft.com). | ||
57 | * | ||
58 | */ | ||
59 | #ifndef OPENSSL_NO_SRP | ||
60 | #include "cryptlib.h" | ||
61 | #include "srp_lcl.h" | ||
62 | #include <openssl/srp.h> | ||
63 | #include <openssl/evp.h> | ||
64 | #include <openssl/buffer.h> | ||
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/txt_db.h> | ||
67 | |||
68 | #define SRP_RANDOM_SALT_LEN 20 | ||
69 | #define MAX_LEN 2500 | ||
70 | |||
71 | static char b64table[] = | ||
72 | "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz./"; | ||
73 | |||
74 | /* the following two conversion routines have been inspired by code from Stanford */ | ||
75 | |||
76 | /* | ||
77 | * Convert a base64 string into raw byte array representation. | ||
78 | */ | ||
79 | static int t_fromb64(unsigned char *a, const char *src) | ||
80 | { | ||
81 | char *loc; | ||
82 | int i, j; | ||
83 | int size; | ||
84 | |||
85 | while(*src && (*src == ' ' || *src == '\t' || *src == '\n')) | ||
86 | ++src; | ||
87 | size = strlen(src); | ||
88 | i = 0; | ||
89 | while(i < size) | ||
90 | { | ||
91 | loc = strchr(b64table, src[i]); | ||
92 | if(loc == (char *) 0) break; | ||
93 | else a[i] = loc - b64table; | ||
94 | ++i; | ||
95 | } | ||
96 | size = i; | ||
97 | i = size - 1; | ||
98 | j = size; | ||
99 | while(1) | ||
100 | { | ||
101 | a[j] = a[i]; | ||
102 | if(--i < 0) break; | ||
103 | a[j] |= (a[i] & 3) << 6; | ||
104 | --j; | ||
105 | a[j] = (unsigned char) ((a[i] & 0x3c) >> 2); | ||
106 | if(--i < 0) break; | ||
107 | a[j] |= (a[i] & 0xf) << 4; | ||
108 | --j; | ||
109 | a[j] = (unsigned char) ((a[i] & 0x30) >> 4); | ||
110 | if(--i < 0) break; | ||
111 | a[j] |= (a[i] << 2); | ||
112 | |||
113 | a[--j] = 0; | ||
114 | if(--i < 0) break; | ||
115 | } | ||
116 | while(a[j] == 0 && j <= size) ++j; | ||
117 | i = 0; | ||
118 | while (j <= size) a[i++] = a[j++]; | ||
119 | return i; | ||
120 | } | ||
121 | |||
122 | |||
123 | /* | ||
124 | * Convert a raw byte string into a null-terminated base64 ASCII string. | ||
125 | */ | ||
126 | static char *t_tob64(char *dst, const unsigned char *src, int size) | ||
127 | { | ||
128 | int c, pos = size % 3; | ||
129 | unsigned char b0 = 0, b1 = 0, b2 = 0, notleading = 0; | ||
130 | char *olddst = dst; | ||
131 | |||
132 | switch(pos) | ||
133 | { | ||
134 | case 1: | ||
135 | b2 = src[0]; | ||
136 | break; | ||
137 | case 2: | ||
138 | b1 = src[0]; | ||
139 | b2 = src[1]; | ||
140 | break; | ||
141 | } | ||
142 | |||
143 | while(1) | ||
144 | { | ||
145 | c = (b0 & 0xfc) >> 2; | ||
146 | if(notleading || c != 0) | ||
147 | { | ||
148 | *dst++ = b64table[c]; | ||
149 | notleading = 1; | ||
150 | } | ||
151 | c = ((b0 & 3) << 4) | ((b1 & 0xf0) >> 4); | ||
152 | if(notleading || c != 0) | ||
153 | { | ||
154 | *dst++ = b64table[c]; | ||
155 | notleading = 1; | ||
156 | } | ||
157 | c = ((b1 & 0xf) << 2) | ((b2 & 0xc0) >> 6); | ||
158 | if(notleading || c != 0) | ||
159 | { | ||
160 | *dst++ = b64table[c]; | ||
161 | notleading = 1; | ||
162 | } | ||
163 | c = b2 & 0x3f; | ||
164 | if(notleading || c != 0) | ||
165 | { | ||
166 | *dst++ = b64table[c]; | ||
167 | notleading = 1; | ||
168 | } | ||
169 | if(pos >= size) break; | ||
170 | else | ||
171 | { | ||
172 | b0 = src[pos++]; | ||
173 | b1 = src[pos++]; | ||
174 | b2 = src[pos++]; | ||
175 | } | ||
176 | } | ||
177 | |||
178 | *dst++ = '\0'; | ||
179 | return olddst; | ||
180 | } | ||
181 | |||
182 | static void SRP_user_pwd_free(SRP_user_pwd *user_pwd) | ||
183 | { | ||
184 | if (user_pwd == NULL) | ||
185 | return; | ||
186 | BN_free(user_pwd->s); | ||
187 | BN_clear_free(user_pwd->v); | ||
188 | OPENSSL_free(user_pwd->id); | ||
189 | OPENSSL_free(user_pwd->info); | ||
190 | OPENSSL_free(user_pwd); | ||
191 | } | ||
192 | |||
193 | static SRP_user_pwd *SRP_user_pwd_new() | ||
194 | { | ||
195 | SRP_user_pwd *ret = OPENSSL_malloc(sizeof(SRP_user_pwd)); | ||
196 | if (ret == NULL) | ||
197 | return NULL; | ||
198 | ret->N = NULL; | ||
199 | ret->g = NULL; | ||
200 | ret->s = NULL; | ||
201 | ret->v = NULL; | ||
202 | ret->id = NULL ; | ||
203 | ret->info = NULL; | ||
204 | return ret; | ||
205 | } | ||
206 | |||
207 | static void SRP_user_pwd_set_gN(SRP_user_pwd *vinfo, const BIGNUM *g, | ||
208 | const BIGNUM *N) | ||
209 | { | ||
210 | vinfo->N = N; | ||
211 | vinfo->g = g; | ||
212 | } | ||
213 | |||
214 | static int SRP_user_pwd_set_ids(SRP_user_pwd *vinfo, const char *id, | ||
215 | const char *info) | ||
216 | { | ||
217 | if (id != NULL && NULL == (vinfo->id = BUF_strdup(id))) | ||
218 | return 0; | ||
219 | return (info == NULL || NULL != (vinfo->info = BUF_strdup(info))) ; | ||
220 | } | ||
221 | |||
222 | static int SRP_user_pwd_set_sv(SRP_user_pwd *vinfo, const char *s, | ||
223 | const char *v) | ||
224 | { | ||
225 | unsigned char tmp[MAX_LEN]; | ||
226 | int len; | ||
227 | |||
228 | if (strlen(s) > MAX_LEN || strlen(v) > MAX_LEN) | ||
229 | return 0; | ||
230 | len = t_fromb64(tmp, v); | ||
231 | if (NULL == (vinfo->v = BN_bin2bn(tmp, len, NULL)) ) | ||
232 | return 0; | ||
233 | len = t_fromb64(tmp, s); | ||
234 | return ((vinfo->s = BN_bin2bn(tmp, len, NULL)) != NULL) ; | ||
235 | } | ||
236 | |||
237 | static int SRP_user_pwd_set_sv_BN(SRP_user_pwd *vinfo, BIGNUM *s, BIGNUM *v) | ||
238 | { | ||
239 | vinfo->v = v; | ||
240 | vinfo->s = s; | ||
241 | return (vinfo->s != NULL && vinfo->v != NULL) ; | ||
242 | } | ||
243 | |||
244 | SRP_VBASE *SRP_VBASE_new(char *seed_key) | ||
245 | { | ||
246 | SRP_VBASE *vb = (SRP_VBASE *) OPENSSL_malloc(sizeof(SRP_VBASE)); | ||
247 | |||
248 | if (vb == NULL) | ||
249 | return NULL; | ||
250 | if (!(vb->users_pwd = sk_SRP_user_pwd_new_null()) || | ||
251 | !(vb->gN_cache = sk_SRP_gN_cache_new_null())) | ||
252 | { | ||
253 | OPENSSL_free(vb); | ||
254 | return NULL; | ||
255 | } | ||
256 | vb->default_g = NULL; | ||
257 | vb->default_N = NULL; | ||
258 | vb->seed_key = NULL; | ||
259 | if ((seed_key != NULL) && | ||
260 | (vb->seed_key = BUF_strdup(seed_key)) == NULL) | ||
261 | { | ||
262 | sk_SRP_user_pwd_free(vb->users_pwd); | ||
263 | sk_SRP_gN_cache_free(vb->gN_cache); | ||
264 | OPENSSL_free(vb); | ||
265 | return NULL; | ||
266 | } | ||
267 | return vb; | ||
268 | } | ||
269 | |||
270 | |||
271 | int SRP_VBASE_free(SRP_VBASE *vb) | ||
272 | { | ||
273 | sk_SRP_user_pwd_pop_free(vb->users_pwd,SRP_user_pwd_free); | ||
274 | sk_SRP_gN_cache_free(vb->gN_cache); | ||
275 | OPENSSL_free(vb->seed_key); | ||
276 | OPENSSL_free(vb); | ||
277 | return 0; | ||
278 | } | ||
279 | |||
280 | |||
281 | static SRP_gN_cache *SRP_gN_new_init(const char *ch) | ||
282 | { | ||
283 | unsigned char tmp[MAX_LEN]; | ||
284 | int len; | ||
285 | |||
286 | SRP_gN_cache *newgN = (SRP_gN_cache *)OPENSSL_malloc(sizeof(SRP_gN_cache)); | ||
287 | if (newgN == NULL) | ||
288 | return NULL; | ||
289 | |||
290 | if ((newgN->b64_bn = BUF_strdup(ch)) == NULL) | ||
291 | goto err; | ||
292 | |||
293 | len = t_fromb64(tmp, ch); | ||
294 | if ((newgN->bn = BN_bin2bn(tmp, len, NULL))) | ||
295 | return newgN; | ||
296 | |||
297 | OPENSSL_free(newgN->b64_bn); | ||
298 | err: | ||
299 | OPENSSL_free(newgN); | ||
300 | return NULL; | ||
301 | } | ||
302 | |||
303 | |||
304 | static void SRP_gN_free(SRP_gN_cache *gN_cache) | ||
305 | { | ||
306 | if (gN_cache == NULL) | ||
307 | return; | ||
308 | OPENSSL_free(gN_cache->b64_bn); | ||
309 | BN_free(gN_cache->bn); | ||
310 | OPENSSL_free(gN_cache); | ||
311 | } | ||
312 | |||
313 | static SRP_gN *SRP_get_gN_by_id(const char *id, STACK_OF(SRP_gN) *gN_tab) | ||
314 | { | ||
315 | int i; | ||
316 | |||
317 | SRP_gN *gN; | ||
318 | if (gN_tab != NULL) | ||
319 | for(i = 0; i < sk_SRP_gN_num(gN_tab); i++) | ||
320 | { | ||
321 | gN = sk_SRP_gN_value(gN_tab, i); | ||
322 | if (gN && (id == NULL || strcmp(gN->id,id)==0)) | ||
323 | return gN; | ||
324 | } | ||
325 | |||
326 | return SRP_get_default_gN(id); | ||
327 | } | ||
328 | |||
329 | static BIGNUM *SRP_gN_place_bn(STACK_OF(SRP_gN_cache) *gN_cache, char *ch) | ||
330 | { | ||
331 | int i; | ||
332 | if (gN_cache == NULL) | ||
333 | return NULL; | ||
334 | |||
335 | /* search if we have already one... */ | ||
336 | for(i = 0; i < sk_SRP_gN_cache_num(gN_cache); i++) | ||
337 | { | ||
338 | SRP_gN_cache *cache = sk_SRP_gN_cache_value(gN_cache, i); | ||
339 | if (strcmp(cache->b64_bn,ch)==0) | ||
340 | return cache->bn; | ||
341 | } | ||
342 | { /* it is the first time that we find it */ | ||
343 | SRP_gN_cache *newgN = SRP_gN_new_init(ch); | ||
344 | if (newgN) | ||
345 | { | ||
346 | if (sk_SRP_gN_cache_insert(gN_cache,newgN,0)>0) | ||
347 | return newgN->bn; | ||
348 | SRP_gN_free(newgN); | ||
349 | } | ||
350 | } | ||
351 | return NULL; | ||
352 | } | ||
353 | |||
354 | /* this function parses verifier file. Format is: | ||
355 | * string(index):base64(N):base64(g):0 | ||
356 | * string(username):base64(v):base64(salt):int(index) | ||
357 | */ | ||
358 | |||
359 | |||
360 | int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file) | ||
361 | { | ||
362 | int error_code ; | ||
363 | STACK_OF(SRP_gN) *SRP_gN_tab = sk_SRP_gN_new_null(); | ||
364 | char *last_index = NULL; | ||
365 | int i; | ||
366 | char **pp; | ||
367 | |||
368 | SRP_gN *gN = NULL; | ||
369 | SRP_user_pwd *user_pwd = NULL ; | ||
370 | |||
371 | TXT_DB *tmpdb = NULL; | ||
372 | BIO *in = BIO_new(BIO_s_file()); | ||
373 | |||
374 | error_code = SRP_ERR_OPEN_FILE; | ||
375 | |||
376 | if (in == NULL || BIO_read_filename(in,verifier_file) <= 0) | ||
377 | goto err; | ||
378 | |||
379 | error_code = SRP_ERR_VBASE_INCOMPLETE_FILE; | ||
380 | |||
381 | if ((tmpdb =TXT_DB_read(in,DB_NUMBER)) == NULL) | ||
382 | goto err; | ||
383 | |||
384 | error_code = SRP_ERR_MEMORY; | ||
385 | |||
386 | |||
387 | if (vb->seed_key) | ||
388 | { | ||
389 | last_index = SRP_get_default_gN(NULL)->id; | ||
390 | } | ||
391 | for (i = 0; i < sk_OPENSSL_PSTRING_num(tmpdb->data); i++) | ||
392 | { | ||
393 | pp = (char **)sk_OPENSSL_PSTRING_value(tmpdb->data,i); | ||
394 | if (pp[DB_srptype][0] == DB_SRP_INDEX) | ||
395 | { | ||
396 | /*we add this couple in the internal Stack */ | ||
397 | |||
398 | if ((gN = (SRP_gN *)OPENSSL_malloc(sizeof(SRP_gN))) == NULL) | ||
399 | goto err; | ||
400 | |||
401 | if (!(gN->id = BUF_strdup(pp[DB_srpid])) | ||
402 | || !(gN->N = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpverifier])) | ||
403 | || !(gN->g = SRP_gN_place_bn(vb->gN_cache,pp[DB_srpsalt])) | ||
404 | || sk_SRP_gN_insert(SRP_gN_tab,gN,0) == 0) | ||
405 | goto err; | ||
406 | |||
407 | gN = NULL; | ||
408 | |||
409 | if (vb->seed_key != NULL) | ||
410 | { | ||
411 | last_index = pp[DB_srpid]; | ||
412 | } | ||
413 | } | ||
414 | else if (pp[DB_srptype][0] == DB_SRP_VALID) | ||
415 | { | ||
416 | /* it is a user .... */ | ||
417 | SRP_gN *lgN; | ||
418 | if ((lgN = SRP_get_gN_by_id(pp[DB_srpgN],SRP_gN_tab))!=NULL) | ||
419 | { | ||
420 | error_code = SRP_ERR_MEMORY; | ||
421 | if ((user_pwd = SRP_user_pwd_new()) == NULL) | ||
422 | goto err; | ||
423 | |||
424 | SRP_user_pwd_set_gN(user_pwd,lgN->g,lgN->N); | ||
425 | if (!SRP_user_pwd_set_ids(user_pwd, pp[DB_srpid],pp[DB_srpinfo])) | ||
426 | goto err; | ||
427 | |||
428 | error_code = SRP_ERR_VBASE_BN_LIB; | ||
429 | if (!SRP_user_pwd_set_sv(user_pwd, pp[DB_srpsalt],pp[DB_srpverifier])) | ||
430 | goto err; | ||
431 | |||
432 | if (sk_SRP_user_pwd_insert(vb->users_pwd, user_pwd, 0) == 0) | ||
433 | goto err; | ||
434 | user_pwd = NULL; /* abandon responsability */ | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | |||
439 | if (last_index != NULL) | ||
440 | { | ||
441 | /* this means that we want to simulate a default user */ | ||
442 | |||
443 | if (((gN = SRP_get_gN_by_id(last_index,SRP_gN_tab))==NULL)) | ||
444 | { | ||
445 | error_code = SRP_ERR_VBASE_BN_LIB; | ||
446 | goto err; | ||
447 | } | ||
448 | vb->default_g = gN->g ; | ||
449 | vb->default_N = gN->N ; | ||
450 | gN = NULL ; | ||
451 | } | ||
452 | error_code = SRP_NO_ERROR; | ||
453 | |||
454 | err: | ||
455 | /* there may be still some leaks to fix, if this fails, the application terminates most likely */ | ||
456 | |||
457 | if (gN != NULL) | ||
458 | { | ||
459 | OPENSSL_free(gN->id); | ||
460 | OPENSSL_free(gN); | ||
461 | } | ||
462 | |||
463 | SRP_user_pwd_free(user_pwd); | ||
464 | |||
465 | if (tmpdb) TXT_DB_free(tmpdb); | ||
466 | if (in) BIO_free_all(in); | ||
467 | |||
468 | sk_SRP_gN_free(SRP_gN_tab); | ||
469 | |||
470 | return error_code; | ||
471 | |||
472 | } | ||
473 | |||
474 | |||
475 | SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username) | ||
476 | { | ||
477 | int i; | ||
478 | SRP_user_pwd *user; | ||
479 | unsigned char digv[SHA_DIGEST_LENGTH]; | ||
480 | unsigned char digs[SHA_DIGEST_LENGTH]; | ||
481 | EVP_MD_CTX ctxt; | ||
482 | |||
483 | if (vb == NULL) | ||
484 | return NULL; | ||
485 | for(i = 0; i < sk_SRP_user_pwd_num(vb->users_pwd); i++) | ||
486 | { | ||
487 | user = sk_SRP_user_pwd_value(vb->users_pwd, i); | ||
488 | if (strcmp(user->id,username)==0) | ||
489 | return user; | ||
490 | } | ||
491 | if ((vb->seed_key == NULL) || | ||
492 | (vb->default_g == NULL) || | ||
493 | (vb->default_N == NULL)) | ||
494 | return NULL; | ||
495 | |||
496 | /* if the user is unknown we set parameters as well if we have a seed_key */ | ||
497 | |||
498 | if ((user = SRP_user_pwd_new()) == NULL) | ||
499 | return NULL; | ||
500 | |||
501 | SRP_user_pwd_set_gN(user,vb->default_g,vb->default_N); | ||
502 | |||
503 | if (!SRP_user_pwd_set_ids(user,username,NULL)) | ||
504 | goto err; | ||
505 | |||
506 | RAND_pseudo_bytes(digv, SHA_DIGEST_LENGTH); | ||
507 | EVP_MD_CTX_init(&ctxt); | ||
508 | EVP_DigestInit_ex(&ctxt, EVP_sha1(), NULL); | ||
509 | EVP_DigestUpdate(&ctxt, vb->seed_key, strlen(vb->seed_key)); | ||
510 | EVP_DigestUpdate(&ctxt, username, strlen(username)); | ||
511 | EVP_DigestFinal_ex(&ctxt, digs, NULL); | ||
512 | EVP_MD_CTX_cleanup(&ctxt); | ||
513 | if (SRP_user_pwd_set_sv_BN(user, BN_bin2bn(digs,SHA_DIGEST_LENGTH,NULL), BN_bin2bn(digv,SHA_DIGEST_LENGTH, NULL))) | ||
514 | return user; | ||
515 | |||
516 | err: SRP_user_pwd_free(user); | ||
517 | return NULL; | ||
518 | } | ||
519 | |||
520 | |||
521 | /* | ||
522 | create a verifier (*salt,*verifier,g and N are in base64) | ||
523 | */ | ||
524 | char *SRP_create_verifier(const char *user, const char *pass, char **salt, | ||
525 | char **verifier, const char *N, const char *g) | ||
526 | { | ||
527 | int len; | ||
528 | char * result=NULL; | ||
529 | char *vf; | ||
530 | BIGNUM *N_bn = NULL, *g_bn = NULL, *s = NULL, *v = NULL; | ||
531 | unsigned char tmp[MAX_LEN]; | ||
532 | unsigned char tmp2[MAX_LEN]; | ||
533 | char * defgNid = NULL; | ||
534 | |||
535 | if ((user == NULL)|| | ||
536 | (pass == NULL)|| | ||
537 | (salt == NULL)|| | ||
538 | (verifier == NULL)) | ||
539 | goto err; | ||
540 | |||
541 | if (N) | ||
542 | { | ||
543 | if (!(len = t_fromb64(tmp, N))) goto err; | ||
544 | N_bn = BN_bin2bn(tmp, len, NULL); | ||
545 | if (!(len = t_fromb64(tmp, g))) goto err; | ||
546 | g_bn = BN_bin2bn(tmp, len, NULL); | ||
547 | defgNid = "*"; | ||
548 | } | ||
549 | else | ||
550 | { | ||
551 | SRP_gN * gN = SRP_get_gN_by_id(g, NULL) ; | ||
552 | if (gN == NULL) | ||
553 | goto err; | ||
554 | N_bn = gN->N; | ||
555 | g_bn = gN->g; | ||
556 | defgNid = gN->id; | ||
557 | } | ||
558 | |||
559 | if (*salt == NULL) | ||
560 | { | ||
561 | RAND_pseudo_bytes(tmp2, SRP_RANDOM_SALT_LEN); | ||
562 | |||
563 | s = BN_bin2bn(tmp2, SRP_RANDOM_SALT_LEN, NULL); | ||
564 | } | ||
565 | else | ||
566 | { | ||
567 | if (!(len = t_fromb64(tmp2, *salt))) | ||
568 | goto err; | ||
569 | s = BN_bin2bn(tmp2, len, NULL); | ||
570 | } | ||
571 | |||
572 | |||
573 | if(!SRP_create_verifier_BN(user, pass, &s, &v, N_bn, g_bn)) goto err; | ||
574 | |||
575 | BN_bn2bin(v,tmp); | ||
576 | if (((vf = OPENSSL_malloc(BN_num_bytes(v)*2)) == NULL)) | ||
577 | goto err; | ||
578 | t_tob64(vf, tmp, BN_num_bytes(v)); | ||
579 | |||
580 | *verifier = vf; | ||
581 | if (*salt == NULL) | ||
582 | { | ||
583 | char *tmp_salt; | ||
584 | if ((tmp_salt = (char *)OPENSSL_malloc(SRP_RANDOM_SALT_LEN * 2)) == NULL) | ||
585 | { | ||
586 | OPENSSL_free(vf); | ||
587 | goto err; | ||
588 | } | ||
589 | t_tob64(tmp_salt, tmp2, SRP_RANDOM_SALT_LEN); | ||
590 | *salt = tmp_salt; | ||
591 | } | ||
592 | |||
593 | result=defgNid; | ||
594 | |||
595 | err: | ||
596 | if(N) | ||
597 | { | ||
598 | BN_free(N_bn); | ||
599 | BN_free(g_bn); | ||
600 | } | ||
601 | return result; | ||
602 | } | ||
603 | |||
604 | /* | ||
605 | create a verifier (*salt,*verifier,g and N are BIGNUMs) | ||
606 | */ | ||
607 | int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, BIGNUM **verifier, BIGNUM *N, BIGNUM *g) | ||
608 | { | ||
609 | int result=0; | ||
610 | BIGNUM *x = NULL; | ||
611 | BN_CTX *bn_ctx = BN_CTX_new(); | ||
612 | unsigned char tmp2[MAX_LEN]; | ||
613 | |||
614 | if ((user == NULL)|| | ||
615 | (pass == NULL)|| | ||
616 | (salt == NULL)|| | ||
617 | (verifier == NULL)|| | ||
618 | (N == NULL)|| | ||
619 | (g == NULL)|| | ||
620 | (bn_ctx == NULL)) | ||
621 | goto err; | ||
622 | |||
623 | srp_bn_print(N); | ||
624 | srp_bn_print(g); | ||
625 | |||
626 | if (*salt == NULL) | ||
627 | { | ||
628 | RAND_pseudo_bytes(tmp2, SRP_RANDOM_SALT_LEN); | ||
629 | |||
630 | *salt = BN_bin2bn(tmp2,SRP_RANDOM_SALT_LEN,NULL); | ||
631 | } | ||
632 | |||
633 | x = SRP_Calc_x(*salt,user,pass); | ||
634 | |||
635 | *verifier = BN_new(); | ||
636 | if(*verifier == NULL) goto err; | ||
637 | |||
638 | if (!BN_mod_exp(*verifier,g,x,N,bn_ctx)) | ||
639 | { | ||
640 | BN_clear_free(*verifier); | ||
641 | goto err; | ||
642 | } | ||
643 | |||
644 | srp_bn_print(*verifier); | ||
645 | |||
646 | result=1; | ||
647 | |||
648 | err: | ||
649 | |||
650 | BN_clear_free(x); | ||
651 | BN_CTX_free(bn_ctx); | ||
652 | return result; | ||
653 | } | ||
654 | |||
655 | |||
656 | |||
657 | #endif | ||
diff --git a/src/lib/libcrypto/srp/srptest.c b/src/lib/libcrypto/srp/srptest.c new file mode 100644 index 0000000000..04b66b4544 --- /dev/null +++ b/src/lib/libcrypto/srp/srptest.c | |||
@@ -0,0 +1,162 @@ | |||
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/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); |
diff --git a/src/lib/libcrypto/whrlpool/Makefile b/src/lib/libcrypto/whrlpool/Makefile index 566b996290..f4d46e4d17 100644 --- a/src/lib/libcrypto/whrlpool/Makefile +++ b/src/lib/libcrypto/whrlpool/Makefile | |||
@@ -89,5 +89,8 @@ clean: | |||
89 | 89 | ||
90 | wp_block.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | 90 | wp_block.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h |
91 | wp_block.o: ../../include/openssl/whrlpool.h wp_block.c wp_locl.h | 91 | wp_block.o: ../../include/openssl/whrlpool.h wp_block.c wp_locl.h |
92 | wp_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | 92 | wp_dgst.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h |
93 | wp_dgst.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
94 | wp_dgst.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
95 | wp_dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
93 | wp_dgst.o: ../../include/openssl/whrlpool.h wp_dgst.c wp_locl.h | 96 | wp_dgst.o: ../../include/openssl/whrlpool.h wp_dgst.c wp_locl.h |
diff --git a/src/lib/libcrypto/x509v3/v3_asid.c b/src/lib/libcrypto/x509v3/v3_asid.c index 3f434c0603..1587e8ed72 100644 --- a/src/lib/libcrypto/x509v3/v3_asid.c +++ b/src/lib/libcrypto/x509v3/v3_asid.c | |||
@@ -358,6 +358,20 @@ static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice) | |||
358 | goto done; | 358 | goto done; |
359 | } | 359 | } |
360 | 360 | ||
361 | /* | ||
362 | * Check for inverted range. | ||
363 | */ | ||
364 | i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; | ||
365 | { | ||
366 | ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i); | ||
367 | ASN1_INTEGER *a_min, *a_max; | ||
368 | if (a != NULL && a->type == ASIdOrRange_range) { | ||
369 | extract_min_max(a, &a_min, &a_max); | ||
370 | if (ASN1_INTEGER_cmp(a_min, a_max) > 0) | ||
371 | goto done; | ||
372 | } | ||
373 | } | ||
374 | |||
361 | ret = 1; | 375 | ret = 1; |
362 | 376 | ||
363 | done: | 377 | done: |
@@ -392,9 +406,18 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice) | |||
392 | return 1; | 406 | return 1; |
393 | 407 | ||
394 | /* | 408 | /* |
395 | * We have a list. Sort it. | 409 | * If not a list, or if empty list, it's broken. |
410 | */ | ||
411 | if (choice->type != ASIdentifierChoice_asIdsOrRanges || | ||
412 | sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) { | ||
413 | X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, | ||
414 | X509V3_R_EXTENSION_VALUE_ERROR); | ||
415 | return 0; | ||
416 | } | ||
417 | |||
418 | /* | ||
419 | * We have a non-empty list. Sort it. | ||
396 | */ | 420 | */ |
397 | OPENSSL_assert(choice->type == ASIdentifierChoice_asIdsOrRanges); | ||
398 | sk_ASIdOrRange_sort(choice->u.asIdsOrRanges); | 421 | sk_ASIdOrRange_sort(choice->u.asIdsOrRanges); |
399 | 422 | ||
400 | /* | 423 | /* |
@@ -415,6 +438,13 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice) | |||
415 | OPENSSL_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0); | 438 | OPENSSL_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0); |
416 | 439 | ||
417 | /* | 440 | /* |
441 | * Punt inverted ranges. | ||
442 | */ | ||
443 | if (ASN1_INTEGER_cmp(a_min, a_max) > 0 || | ||
444 | ASN1_INTEGER_cmp(b_min, b_max) > 0) | ||
445 | goto done; | ||
446 | |||
447 | /* | ||
418 | * Check for overlaps. | 448 | * Check for overlaps. |
419 | */ | 449 | */ |
420 | if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) { | 450 | if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) { |
@@ -465,12 +495,26 @@ static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice) | |||
465 | break; | 495 | break; |
466 | } | 496 | } |
467 | ASIdOrRange_free(b); | 497 | ASIdOrRange_free(b); |
468 | sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1); | 498 | (void) sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1); |
469 | i--; | 499 | i--; |
470 | continue; | 500 | continue; |
471 | } | 501 | } |
472 | } | 502 | } |
473 | 503 | ||
504 | /* | ||
505 | * Check for final inverted range. | ||
506 | */ | ||
507 | i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; | ||
508 | { | ||
509 | ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i); | ||
510 | ASN1_INTEGER *a_min, *a_max; | ||
511 | if (a != NULL && a->type == ASIdOrRange_range) { | ||
512 | extract_min_max(a, &a_min, &a_max); | ||
513 | if (ASN1_INTEGER_cmp(a_min, a_max) > 0) | ||
514 | goto done; | ||
515 | } | ||
516 | } | ||
517 | |||
474 | OPENSSL_assert(ASIdentifierChoice_is_canonical(choice)); /* Paranoia */ | 518 | OPENSSL_assert(ASIdentifierChoice_is_canonical(choice)); /* Paranoia */ |
475 | 519 | ||
476 | ret = 1; | 520 | ret = 1; |
@@ -498,6 +542,7 @@ static void *v2i_ASIdentifiers(const struct v3_ext_method *method, | |||
498 | struct v3_ext_ctx *ctx, | 542 | struct v3_ext_ctx *ctx, |
499 | STACK_OF(CONF_VALUE) *values) | 543 | STACK_OF(CONF_VALUE) *values) |
500 | { | 544 | { |
545 | ASN1_INTEGER *min = NULL, *max = NULL; | ||
501 | ASIdentifiers *asid = NULL; | 546 | ASIdentifiers *asid = NULL; |
502 | int i; | 547 | int i; |
503 | 548 | ||
@@ -508,7 +553,6 @@ static void *v2i_ASIdentifiers(const struct v3_ext_method *method, | |||
508 | 553 | ||
509 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) { | 554 | for (i = 0; i < sk_CONF_VALUE_num(values); i++) { |
510 | CONF_VALUE *val = sk_CONF_VALUE_value(values, i); | 555 | CONF_VALUE *val = sk_CONF_VALUE_value(values, i); |
511 | ASN1_INTEGER *min = NULL, *max = NULL; | ||
512 | int i1, i2, i3, is_range, which; | 556 | int i1, i2, i3, is_range, which; |
513 | 557 | ||
514 | /* | 558 | /* |
@@ -578,18 +622,19 @@ static void *v2i_ASIdentifiers(const struct v3_ext_method *method, | |||
578 | max = s2i_ASN1_INTEGER(NULL, s + i2); | 622 | max = s2i_ASN1_INTEGER(NULL, s + i2); |
579 | OPENSSL_free(s); | 623 | OPENSSL_free(s); |
580 | if (min == NULL || max == NULL) { | 624 | if (min == NULL || max == NULL) { |
581 | ASN1_INTEGER_free(min); | ||
582 | ASN1_INTEGER_free(max); | ||
583 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); | 625 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); |
584 | goto err; | 626 | goto err; |
585 | } | 627 | } |
628 | if (ASN1_INTEGER_cmp(min, max) > 0) { | ||
629 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_EXTENSION_VALUE_ERROR); | ||
630 | goto err; | ||
631 | } | ||
586 | } | 632 | } |
587 | if (!v3_asid_add_id_or_range(asid, which, min, max)) { | 633 | if (!v3_asid_add_id_or_range(asid, which, min, max)) { |
588 | ASN1_INTEGER_free(min); | ||
589 | ASN1_INTEGER_free(max); | ||
590 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); | 634 | X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE); |
591 | goto err; | 635 | goto err; |
592 | } | 636 | } |
637 | min = max = NULL; | ||
593 | } | 638 | } |
594 | 639 | ||
595 | /* | 640 | /* |
@@ -601,6 +646,8 @@ static void *v2i_ASIdentifiers(const struct v3_ext_method *method, | |||
601 | 646 | ||
602 | err: | 647 | err: |
603 | ASIdentifiers_free(asid); | 648 | ASIdentifiers_free(asid); |
649 | ASN1_INTEGER_free(min); | ||
650 | ASN1_INTEGER_free(max); | ||
604 | return NULL; | 651 | return NULL; |
605 | } | 652 | } |
606 | 653 | ||