diff options
author | beck <> | 1999-09-29 04:37:45 +0000 |
---|---|---|
committer | beck <> | 1999-09-29 04:37:45 +0000 |
commit | de8f24ea083384bb66b32ec105dc4743c5663cdf (patch) | |
tree | 1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libcrypto/dh | |
parent | cb929d29896bcb87c2a97417fbd03e50078fc178 (diff) | |
download | openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.gz openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.tar.bz2 openbsd-de8f24ea083384bb66b32ec105dc4743c5663cdf.zip |
OpenSSL 0.9.4 merge
Diffstat (limited to 'src/lib/libcrypto/dh')
-rw-r--r-- | src/lib/libcrypto/dh/Makefile.ssl | 66 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh.err | 12 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh.h | 44 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_check.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_err.c | 118 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_gen.c | 18 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_key.c | 52 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dh_lib.c | 19 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/dhtest.c | 36 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/p1024.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/p192.c | 8 | ||||
-rw-r--r-- | src/lib/libcrypto/dh/p512.c | 8 |
12 files changed, 209 insertions, 188 deletions
diff --git a/src/lib/libcrypto/dh/Makefile.ssl b/src/lib/libcrypto/dh/Makefile.ssl index dfa7e4525d..37e388d1b4 100644 --- a/src/lib/libcrypto/dh/Makefile.ssl +++ b/src/lib/libcrypto/dh/Makefile.ssl | |||
@@ -7,23 +7,23 @@ TOP= ../.. | |||
7 | CC= cc | 7 | CC= cc |
8 | INCLUDES= -I.. -I../../include | 8 | INCLUDES= -I.. -I../../include |
9 | CFLAG=-g | 9 | CFLAG=-g |
10 | INSTALL_PREFIX= | ||
11 | OPENSSLDIR= /usr/local/ssl | ||
10 | INSTALLTOP=/usr/local/ssl | 12 | INSTALLTOP=/usr/local/ssl |
11 | MAKE= make -f Makefile.ssl | 13 | MAKE= make -f Makefile.ssl |
12 | MAKEDEPEND= makedepend -f Makefile.ssl | 14 | MAKEDEPEND= $(TOP)/util/domd $(TOP) |
13 | MAKEFILE= Makefile.ssl | 15 | MAKEFILE= Makefile.ssl |
14 | AR= ar r | 16 | AR= ar r |
15 | 17 | ||
16 | CFLAGS= $(INCLUDES) $(CFLAG) | 18 | CFLAGS= $(INCLUDES) $(CFLAG) |
17 | 19 | ||
18 | ERR=dh | ||
19 | ERRC=dh_err | ||
20 | GENERAL=Makefile | 20 | GENERAL=Makefile |
21 | TEST= dhtest.c | 21 | TEST= dhtest.c |
22 | APPS= | 22 | APPS= |
23 | 23 | ||
24 | LIB=$(TOP)/libcrypto.a | 24 | LIB=$(TOP)/libcrypto.a |
25 | LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c $(ERRC).c | 25 | LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c |
26 | LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o $(ERRC).o | 26 | LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o |
27 | 27 | ||
28 | SRC= $(LIBSRC) | 28 | SRC= $(LIBSRC) |
29 | 29 | ||
@@ -39,24 +39,23 @@ all: lib | |||
39 | 39 | ||
40 | lib: $(LIBOBJ) | 40 | lib: $(LIBOBJ) |
41 | $(AR) $(LIB) $(LIBOBJ) | 41 | $(AR) $(LIB) $(LIBOBJ) |
42 | sh $(TOP)/util/ranlib.sh $(LIB) | 42 | $(RANLIB) $(LIB) |
43 | @touch lib | 43 | @touch lib |
44 | 44 | ||
45 | files: | 45 | files: |
46 | perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | 46 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO |
47 | 47 | ||
48 | links: | 48 | links: |
49 | /bin/rm -f Makefile | 49 | @$(TOP)/util/point.sh Makefile.ssl Makefile |
50 | $(TOP)/util/point.sh Makefile.ssl Makefile ; | 50 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) |
51 | $(TOP)/util/mklink.sh ../../include $(EXHEADER) | 51 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) |
52 | $(TOP)/util/mklink.sh ../../test $(TEST) | 52 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) |
53 | $(TOP)/util/mklink.sh ../../apps $(APPS) | ||
54 | 53 | ||
55 | install: | 54 | install: |
56 | @for i in $(EXHEADER) ; \ | 55 | @for i in $(EXHEADER) ; \ |
57 | do \ | 56 | do \ |
58 | (cp $$i $(INSTALLTOP)/include/$$i; \ | 57 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ |
59 | chmod 644 $(INSTALLTOP)/include/$$i ); \ | 58 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ |
60 | done; | 59 | done; |
61 | 60 | ||
62 | tags: | 61 | tags: |
@@ -68,17 +67,42 @@ lint: | |||
68 | lint -DLINT $(INCLUDES) $(SRC)>fluff | 67 | lint -DLINT $(INCLUDES) $(SRC)>fluff |
69 | 68 | ||
70 | depend: | 69 | depend: |
71 | $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) | 70 | $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) |
72 | 71 | ||
73 | dclean: | 72 | dclean: |
74 | perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | 73 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new |
75 | mv -f Makefile.new $(MAKEFILE) | 74 | mv -f Makefile.new $(MAKEFILE) |
76 | 75 | ||
77 | clean: | 76 | clean: |
78 | /bin/rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | 77 | rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff |
79 | |||
80 | errors: | ||
81 | perl $(TOP)/util/err-ins.pl $(ERR).err $(ERR).h | ||
82 | perl ../err/err_genc.pl -s $(ERR).h $(ERRC).c | ||
83 | 78 | ||
84 | # DO NOT DELETE THIS LINE -- make depend depends on it. | 79 | # DO NOT DELETE THIS LINE -- make depend depends on it. |
80 | |||
81 | dh_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
82 | dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
83 | dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | ||
84 | dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
85 | dh_check.o: ../../include/openssl/opensslconf.h | ||
86 | dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h | ||
87 | dh_check.o: ../cryptlib.h | ||
88 | dh_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h | ||
89 | dh_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h | ||
90 | dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
91 | dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
92 | dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | ||
93 | dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
94 | dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
95 | dh_gen.o: ../../include/openssl/stack.h ../cryptlib.h | ||
96 | dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
97 | dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
98 | dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | ||
99 | dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
100 | dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
101 | dh_key.o: ../../include/openssl/rand.h ../../include/openssl/stack.h | ||
102 | dh_key.o: ../cryptlib.h | ||
103 | dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
104 | dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
105 | dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h | ||
106 | dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
107 | dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
108 | dh_lib.o: ../../include/openssl/stack.h ../cryptlib.h | ||
diff --git a/src/lib/libcrypto/dh/dh.err b/src/lib/libcrypto/dh/dh.err deleted file mode 100644 index a4fe746985..0000000000 --- a/src/lib/libcrypto/dh/dh.err +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | /* Error codes for the DH functions. */ | ||
2 | |||
3 | /* Function codes. */ | ||
4 | #define DH_F_DHPARAMS_PRINT 100 | ||
5 | #define DH_F_DHPARAMS_PRINT_FP 101 | ||
6 | #define DH_F_DH_COMPUTE_KEY 102 | ||
7 | #define DH_F_DH_GENERATE_KEY 103 | ||
8 | #define DH_F_DH_GENERATE_PARAMETERS 104 | ||
9 | #define DH_F_DH_NEW 105 | ||
10 | |||
11 | /* Reason codes. */ | ||
12 | #define DH_R_NO_PRIVATE_VALUE 100 | ||
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h index 4cc1df2650..2cc3797a94 100644 --- a/src/lib/libcrypto/dh/dh.h +++ b/src/lib/libcrypto/dh/dh.h | |||
@@ -63,10 +63,14 @@ | |||
63 | extern "C" { | 63 | extern "C" { |
64 | #endif | 64 | #endif |
65 | 65 | ||
66 | #ifndef HEADER_BN_H | 66 | #ifdef NO_DH |
67 | #define BIGNUM char | 67 | #error DH is disabled. |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | #include <openssl/bn.h> | ||
71 | |||
72 | #define DH_FLAG_CACHE_MONT_P 0x01 | ||
73 | |||
70 | typedef struct dh_st | 74 | typedef struct dh_st |
71 | { | 75 | { |
72 | /* This first argument is used to pick up errors when | 76 | /* This first argument is used to pick up errors when |
@@ -78,6 +82,9 @@ typedef struct dh_st | |||
78 | int length; /* optional */ | 82 | int length; /* optional */ |
79 | BIGNUM *pub_key; /* y */ | 83 | BIGNUM *pub_key; /* y */ |
80 | BIGNUM *priv_key; /* x */ | 84 | BIGNUM *priv_key; /* x */ |
85 | |||
86 | int flags; | ||
87 | char *method_mont_p; | ||
81 | } DH; | 88 | } DH; |
82 | 89 | ||
83 | #define DH_GENERATOR_2 2 | 90 | #define DH_GENERATOR_2 2 |
@@ -98,15 +105,19 @@ typedef struct dh_st | |||
98 | (unsigned char *)(x)) | 105 | (unsigned char *)(x)) |
99 | #define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \ | 106 | #define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \ |
100 | (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x)) | 107 | (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x)) |
108 | #ifdef __cplusplus | ||
109 | #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \ | ||
110 | (unsigned char *)(x)) | ||
111 | #else | ||
101 | #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \ | 112 | #define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \ |
102 | (unsigned char *)(x)) | 113 | (unsigned char *)(x)) |
114 | #endif | ||
103 | 115 | ||
104 | #ifndef NOPROTO | ||
105 | DH * DH_new(void); | 116 | DH * DH_new(void); |
106 | void DH_free(DH *dh); | 117 | void DH_free(DH *dh); |
107 | int DH_size(DH *dh); | 118 | int DH_size(DH *dh); |
108 | DH * DH_generate_parameters(int prime_len,int generator, | 119 | DH * DH_generate_parameters(int prime_len,int generator, |
109 | void (*callback)(int,int,char *),char *cb_arg); | 120 | void (*callback)(int,int,void *),void *cb_arg); |
110 | int DH_check(DH *dh,int *codes); | 121 | int DH_check(DH *dh,int *codes); |
111 | int DH_generate_key(DH *dh); | 122 | int DH_generate_key(DH *dh); |
112 | int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh); | 123 | int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh); |
@@ -122,26 +133,11 @@ int DHparams_print(char *bp, DH *x); | |||
122 | #endif | 133 | #endif |
123 | void ERR_load_DH_strings(void ); | 134 | void ERR_load_DH_strings(void ); |
124 | 135 | ||
125 | #else | ||
126 | |||
127 | DH * DH_new(); | ||
128 | void DH_free(); | ||
129 | int DH_size(); | ||
130 | DH * DH_generate_parameters(); | ||
131 | int DH_check(); | ||
132 | int DH_generate_key(); | ||
133 | int DH_compute_key(); | ||
134 | DH * d2i_DHparams(); | ||
135 | int i2d_DHparams(); | ||
136 | #ifndef NO_FP_API | ||
137 | int DHparams_print_fp(); | ||
138 | #endif | ||
139 | int DHparams_print(); | ||
140 | void ERR_load_DH_strings(); | ||
141 | |||
142 | #endif | ||
143 | |||
144 | /* BEGIN ERROR CODES */ | 136 | /* BEGIN ERROR CODES */ |
137 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
138 | * made after this point may be overwritten when the script is next run. | ||
139 | */ | ||
140 | |||
145 | /* Error codes for the DH functions. */ | 141 | /* Error codes for the DH functions. */ |
146 | 142 | ||
147 | /* Function codes. */ | 143 | /* Function codes. */ |
@@ -154,7 +150,7 @@ void ERR_load_DH_strings(); | |||
154 | 150 | ||
155 | /* Reason codes. */ | 151 | /* Reason codes. */ |
156 | #define DH_R_NO_PRIVATE_VALUE 100 | 152 | #define DH_R_NO_PRIVATE_VALUE 100 |
157 | 153 | ||
158 | #ifdef __cplusplus | 154 | #ifdef __cplusplus |
159 | } | 155 | } |
160 | #endif | 156 | #endif |
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c index 65602e494f..95ce9cfad0 100644 --- a/src/lib/libcrypto/dh/dh_check.c +++ b/src/lib/libcrypto/dh/dh_check.c | |||
@@ -58,8 +58,8 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "bn.h" | 61 | #include <openssl/bn.h> |
62 | #include "dh.h" | 62 | #include <openssl/dh.h> |
63 | 63 | ||
64 | /* Check that p is a strong prime and | 64 | /* Check that p is a strong prime and |
65 | * if g is 2, 3 or 5, check that is is a suitable generator | 65 | * if g is 2, 3 or 5, check that is is a suitable generator |
@@ -70,9 +70,7 @@ | |||
70 | * should hold. | 70 | * should hold. |
71 | */ | 71 | */ |
72 | 72 | ||
73 | int DH_check(dh,ret) | 73 | int DH_check(DH *dh, int *ret) |
74 | DH *dh; | ||
75 | int *ret; | ||
76 | { | 74 | { |
77 | int ok=0; | 75 | int ok=0; |
78 | BN_CTX *ctx=NULL; | 76 | BN_CTX *ctx=NULL; |
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c index 9d5c06ac24..0348bd24a2 100644 --- a/src/lib/libcrypto/dh/dh_err.c +++ b/src/lib/libcrypto/dh/dh_err.c | |||
@@ -1,63 +1,65 @@ | |||
1 | /* lib/dh/dh_err.c */ | 1 | /* crypto/dh/dh_err.c */ |
2 | /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | 2 | /* ==================================================================== |
3 | * All rights reserved. | 3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. |
4 | * | 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 | 5 | * Redistribution and use in source and binary forms, with or without |
24 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
25 | * are met: | 7 | * are met: |
26 | * 1. Redistributions of source code must retain the copyright | 8 | * |
27 | * notice, this list of conditions and the following disclaimer. | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
29 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in |
30 | * documentation and/or other materials provided with the distribution. | 14 | * the documentation and/or other materials provided with the |
31 | * 3. All advertising materials mentioning features or use of this software | 15 | * distribution. |
32 | * must display the following acknowledgement: | 16 | * |
33 | * "This product includes cryptographic software written by | 17 | * 3. All advertising materials mentioning features or use of this |
34 | * Eric Young (eay@cryptsoft.com)" | 18 | * software must display the following acknowledgment: |
35 | * The word 'cryptographic' can be left out if the rouines from the library | 19 | * "This product includes software developed by the OpenSSL Project |
36 | * being used are not cryptographic related :-). | 20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" |
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | 21 | * |
38 | * the apps directory (application code) you must include an acknowledgement: | 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | 23 | * endorse or promote products derived from this software without |
40 | * | 24 | * prior written permission. For written permission, please contact |
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | 25 | * openssl-core@OpenSSL.org. |
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 26 | * |
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 27 | * 5. Products derived from this software may not be called "OpenSSL" |
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | 28 | * nor may "OpenSSL" appear in their names without prior written |
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 29 | * permission of the OpenSSL Project. |
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 30 | * |
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 31 | * 6. Redistributions of any form whatsoever must retain the following |
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 32 | * acknowledgment: |
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 33 | * "This product includes software developed by the OpenSSL Project |
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" |
51 | * SUCH DAMAGE. | 35 | * |
52 | * | 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
53 | * The licence and distribution terms for any publically available version or | 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
55 | * copied and put under another distribution licence | 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
56 | * [including the GNU Public Licence.] | 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
57 | */ | 54 | */ |
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file. | ||
58 | */ | ||
59 | |||
58 | #include <stdio.h> | 60 | #include <stdio.h> |
59 | #include "err.h" | 61 | #include <openssl/err.h> |
60 | #include "dh.h" | 62 | #include <openssl/dh.h> |
61 | 63 | ||
62 | /* BEGIN ERROR CODES */ | 64 | /* BEGIN ERROR CODES */ |
63 | #ifndef NO_ERR | 65 | #ifndef NO_ERR |
@@ -69,23 +71,23 @@ static ERR_STRING_DATA DH_str_functs[]= | |||
69 | {ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"}, | 71 | {ERR_PACK(0,DH_F_DH_GENERATE_KEY,0), "DH_generate_key"}, |
70 | {ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"}, | 72 | {ERR_PACK(0,DH_F_DH_GENERATE_PARAMETERS,0), "DH_generate_parameters"}, |
71 | {ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"}, | 73 | {ERR_PACK(0,DH_F_DH_NEW,0), "DH_new"}, |
72 | {0,NULL}, | 74 | {0,NULL} |
73 | }; | 75 | }; |
74 | 76 | ||
75 | static ERR_STRING_DATA DH_str_reasons[]= | 77 | static ERR_STRING_DATA DH_str_reasons[]= |
76 | { | 78 | { |
77 | {DH_R_NO_PRIVATE_VALUE ,"no private value"}, | 79 | {DH_R_NO_PRIVATE_VALUE ,"no private value"}, |
78 | {0,NULL}, | 80 | {0,NULL} |
79 | }; | 81 | }; |
80 | 82 | ||
81 | #endif | 83 | #endif |
82 | 84 | ||
83 | void ERR_load_DH_strings() | 85 | void ERR_load_DH_strings(void) |
84 | { | 86 | { |
85 | static int init=1; | 87 | static int init=1; |
86 | 88 | ||
87 | if (init); | 89 | if (init) |
88 | {; | 90 | { |
89 | init=0; | 91 | init=0; |
90 | #ifndef NO_ERR | 92 | #ifndef NO_ERR |
91 | ERR_load_strings(ERR_LIB_DH,DH_str_functs); | 93 | ERR_load_strings(ERR_LIB_DH,DH_str_functs); |
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c index 04c7046a7b..b7bcd2c7a4 100644 --- a/src/lib/libcrypto/dh/dh_gen.c +++ b/src/lib/libcrypto/dh/dh_gen.c | |||
@@ -58,8 +58,8 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "bn.h" | 61 | #include <openssl/bn.h> |
62 | #include "dh.h" | 62 | #include <openssl/dh.h> |
63 | 63 | ||
64 | /* We generate DH parameters as follows | 64 | /* We generate DH parameters as follows |
65 | * find a prime q which is prime_len/2 bits long. | 65 | * find a prime q which is prime_len/2 bits long. |
@@ -83,11 +83,8 @@ | |||
83 | * this generator function can take a very very long time to run. | 83 | * this generator function can take a very very long time to run. |
84 | */ | 84 | */ |
85 | 85 | ||
86 | DH *DH_generate_parameters(prime_len,generator,callback,cb_arg) | 86 | DH *DH_generate_parameters(int prime_len, int generator, |
87 | int prime_len; | 87 | void (*callback)(int,int,void *), void *cb_arg) |
88 | int generator; | ||
89 | void (*callback)(P_I_I_P); | ||
90 | char *cb_arg; | ||
91 | { | 88 | { |
92 | BIGNUM *p=NULL,*t1,*t2; | 89 | BIGNUM *p=NULL,*t1,*t2; |
93 | DH *ret=NULL; | 90 | DH *ret=NULL; |
@@ -95,10 +92,11 @@ char *cb_arg; | |||
95 | BN_CTX *ctx=NULL; | 92 | BN_CTX *ctx=NULL; |
96 | 93 | ||
97 | ret=DH_new(); | 94 | ret=DH_new(); |
95 | if (ret == NULL) goto err; | ||
98 | ctx=BN_CTX_new(); | 96 | ctx=BN_CTX_new(); |
99 | if (ctx == NULL) goto err; | 97 | if (ctx == NULL) goto err; |
100 | t1=ctx->bn[0]; | 98 | t1= &(ctx->bn[0]); |
101 | t2=ctx->bn[1]; | 99 | t2= &(ctx->bn[1]); |
102 | ctx->tos=2; | 100 | ctx->tos=2; |
103 | 101 | ||
104 | if (generator == DH_GENERATOR_2) | 102 | if (generator == DH_GENERATOR_2) |
@@ -126,7 +124,7 @@ char *cb_arg; | |||
126 | else | 124 | else |
127 | g=generator; | 125 | g=generator; |
128 | 126 | ||
129 | p=BN_generate_prime(prime_len,1,t1,t2,callback,cb_arg); | 127 | p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg); |
130 | if (p == NULL) goto err; | 128 | if (p == NULL) goto err; |
131 | if (callback != NULL) callback(3,0,cb_arg); | 129 | if (callback != NULL) callback(3,0,cb_arg); |
132 | ret->p=p; | 130 | ret->p=p; |
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c index 7576772bcd..cede53bfc1 100644 --- a/src/lib/libcrypto/dh/dh_key.c +++ b/src/lib/libcrypto/dh/dh_key.c | |||
@@ -58,20 +58,19 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "bn.h" | 61 | #include <openssl/bn.h> |
62 | #include "rand.h" | 62 | #include <openssl/rand.h> |
63 | #include "dh.h" | 63 | #include <openssl/dh.h> |
64 | 64 | ||
65 | int DH_generate_key(dh) | 65 | int DH_generate_key(DH *dh) |
66 | DH *dh; | ||
67 | { | 66 | { |
68 | int ok=0; | 67 | int ok=0; |
69 | unsigned int i; | 68 | unsigned int i; |
70 | BN_CTX *ctx=NULL; | 69 | BN_CTX ctx; |
70 | BN_MONT_CTX *mont; | ||
71 | BIGNUM *pub_key=NULL,*priv_key=NULL; | 71 | BIGNUM *pub_key=NULL,*priv_key=NULL; |
72 | 72 | ||
73 | ctx=BN_CTX_new(); | 73 | BN_CTX_init(&ctx); |
74 | if (ctx == NULL) goto err; | ||
75 | 74 | ||
76 | if (dh->priv_key == NULL) | 75 | if (dh->priv_key == NULL) |
77 | { | 76 | { |
@@ -96,7 +95,15 @@ DH *dh; | |||
96 | else | 95 | else |
97 | pub_key=dh->pub_key; | 96 | pub_key=dh->pub_key; |
98 | 97 | ||
99 | if (!BN_mod_exp(pub_key,dh->g,priv_key,dh->p,ctx)) goto err; | 98 | if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P)) |
99 | { | ||
100 | if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
101 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p, | ||
102 | dh->p,&ctx)) goto err; | ||
103 | } | ||
104 | mont=(BN_MONT_CTX *)dh->method_mont_p; | ||
105 | |||
106 | if (!BN_mod_exp_mont(pub_key,dh->g,priv_key,dh->p,&ctx,mont)) goto err; | ||
100 | 107 | ||
101 | dh->pub_key=pub_key; | 108 | dh->pub_key=pub_key; |
102 | dh->priv_key=priv_key; | 109 | dh->priv_key=priv_key; |
@@ -107,29 +114,34 @@ err: | |||
107 | 114 | ||
108 | if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); | 115 | if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); |
109 | if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); | 116 | if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); |
110 | if (ctx != NULL) BN_CTX_free(ctx); | 117 | BN_CTX_free(&ctx); |
111 | return(ok); | 118 | return(ok); |
112 | } | 119 | } |
113 | 120 | ||
114 | int DH_compute_key(key,pub_key,dh) | 121 | int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh) |
115 | unsigned char *key; | ||
116 | BIGNUM *pub_key; | ||
117 | DH *dh; | ||
118 | { | 122 | { |
119 | BN_CTX *ctx; | 123 | BN_CTX ctx; |
124 | BN_MONT_CTX *mont; | ||
120 | BIGNUM *tmp; | 125 | BIGNUM *tmp; |
121 | int ret= -1; | 126 | int ret= -1; |
122 | 127 | ||
123 | ctx=BN_CTX_new(); | 128 | BN_CTX_init(&ctx); |
124 | if (ctx == NULL) goto err; | 129 | tmp= &(ctx.bn[ctx.tos++]); |
125 | tmp=ctx->bn[ctx->tos++]; | ||
126 | 130 | ||
127 | if (dh->priv_key == NULL) | 131 | if (dh->priv_key == NULL) |
128 | { | 132 | { |
129 | DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); | 133 | DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); |
130 | goto err; | 134 | goto err; |
131 | } | 135 | } |
132 | if (!BN_mod_exp(tmp,pub_key,dh->priv_key,dh->p,ctx)) | 136 | if ((dh->method_mont_p == NULL) && (dh->flags & DH_FLAG_CACHE_MONT_P)) |
137 | { | ||
138 | if ((dh->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
139 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dh->method_mont_p, | ||
140 | dh->p,&ctx)) goto err; | ||
141 | } | ||
142 | |||
143 | mont=(BN_MONT_CTX *)dh->method_mont_p; | ||
144 | if (!BN_mod_exp_mont(tmp,pub_key,dh->priv_key,dh->p,&ctx,mont)) | ||
133 | { | 145 | { |
134 | DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); | 146 | DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB); |
135 | goto err; | 147 | goto err; |
@@ -137,6 +149,6 @@ DH *dh; | |||
137 | 149 | ||
138 | ret=BN_bn2bin(tmp,key); | 150 | ret=BN_bn2bin(tmp,key); |
139 | err: | 151 | err: |
140 | if (ctx != NULL) BN_CTX_free(ctx); | 152 | BN_CTX_free(&ctx); |
141 | return(ret); | 153 | return(ret); |
142 | } | 154 | } |
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c index a300b38396..61e0720e8a 100644 --- a/src/lib/libcrypto/dh/dh_lib.c +++ b/src/lib/libcrypto/dh/dh_lib.c | |||
@@ -58,12 +58,12 @@ | |||
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "cryptlib.h" | 60 | #include "cryptlib.h" |
61 | #include "bn.h" | 61 | #include <openssl/bn.h> |
62 | #include "dh.h" | 62 | #include <openssl/dh.h> |
63 | 63 | ||
64 | char *DH_version="Diffie-Hellman part of SSLeay 0.9.0b 29-Jun-1998"; | 64 | const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT; |
65 | 65 | ||
66 | DH *DH_new() | 66 | DH *DH_new(void) |
67 | { | 67 | { |
68 | DH *ret; | 68 | DH *ret; |
69 | 69 | ||
@@ -80,21 +80,24 @@ DH *DH_new() | |||
80 | ret->length=0; | 80 | ret->length=0; |
81 | ret->pub_key=NULL; | 81 | ret->pub_key=NULL; |
82 | ret->priv_key=NULL; | 82 | ret->priv_key=NULL; |
83 | ret->flags=DH_FLAG_CACHE_MONT_P; | ||
84 | ret->method_mont_p=NULL; | ||
83 | return(ret); | 85 | return(ret); |
84 | } | 86 | } |
85 | 87 | ||
86 | void DH_free(r) | 88 | void DH_free(DH *r) |
87 | DH *r; | ||
88 | { | 89 | { |
90 | if(r == NULL) return; | ||
89 | if (r->p != NULL) BN_clear_free(r->p); | 91 | if (r->p != NULL) BN_clear_free(r->p); |
90 | if (r->g != NULL) BN_clear_free(r->g); | 92 | if (r->g != NULL) BN_clear_free(r->g); |
91 | if (r->pub_key != NULL) BN_clear_free(r->pub_key); | 93 | if (r->pub_key != NULL) BN_clear_free(r->pub_key); |
92 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); | 94 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); |
95 | if (r->method_mont_p != NULL) | ||
96 | BN_MONT_CTX_free((BN_MONT_CTX *)r->method_mont_p); | ||
93 | Free(r); | 97 | Free(r); |
94 | } | 98 | } |
95 | 99 | ||
96 | int DH_size(dh) | 100 | int DH_size(DH *dh) |
97 | DH *dh; | ||
98 | { | 101 | { |
99 | return(BN_num_bytes(dh->p)); | 102 | return(BN_num_bytes(dh->p)); |
100 | } | 103 | } |
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c index 488f10fd41..770331971f 100644 --- a/src/lib/libcrypto/dh/dhtest.c +++ b/src/lib/libcrypto/dh/dhtest.c | |||
@@ -62,10 +62,18 @@ | |||
62 | #ifdef WINDOWS | 62 | #ifdef WINDOWS |
63 | #include "../bio/bss_file.c" | 63 | #include "../bio/bss_file.c" |
64 | #endif | 64 | #endif |
65 | #include "crypto.h" | 65 | #include <openssl/crypto.h> |
66 | #include "bio.h" | 66 | #include <openssl/bio.h> |
67 | #include "bn.h" | 67 | #include <openssl/bn.h> |
68 | #include "dh.h" | 68 | |
69 | #ifdef NO_DH | ||
70 | int main(int argc, char *argv[]) | ||
71 | { | ||
72 | printf("No DH support\n"); | ||
73 | return(0); | ||
74 | } | ||
75 | #else | ||
76 | #include <openssl/dh.h> | ||
69 | 77 | ||
70 | #ifdef WIN16 | 78 | #ifdef WIN16 |
71 | #define MS_CALLBACK _far _loadds | 79 | #define MS_CALLBACK _far _loadds |
@@ -73,12 +81,7 @@ | |||
73 | #define MS_CALLBACK | 81 | #define MS_CALLBACK |
74 | #endif | 82 | #endif |
75 | 83 | ||
76 | #ifndef NOPROTO | 84 | static void MS_CALLBACK cb(int p, int n, void *arg); |
77 | static void MS_CALLBACK cb(int p, int n, char *arg); | ||
78 | #else | ||
79 | static void MS_CALLBACK cb(); | ||
80 | #endif | ||
81 | |||
82 | #ifdef NO_STDIO | 85 | #ifdef NO_STDIO |
83 | #define APPS_WIN16 | 86 | #define APPS_WIN16 |
84 | #include "bss_file.c" | 87 | #include "bss_file.c" |
@@ -86,9 +89,7 @@ static void MS_CALLBACK cb(); | |||
86 | 89 | ||
87 | BIO *out=NULL; | 90 | BIO *out=NULL; |
88 | 91 | ||
89 | int main(argc,argv) | 92 | int main(int argc, char *argv[]) |
90 | int argc; | ||
91 | char *argv[]; | ||
92 | { | 93 | { |
93 | DH *a,*b; | 94 | DH *a,*b; |
94 | char buf[12]; | 95 | char buf[12]; |
@@ -103,7 +104,7 @@ char *argv[]; | |||
103 | if (out == NULL) exit(1); | 104 | if (out == NULL) exit(1); |
104 | BIO_set_fp(out,stdout,BIO_NOCLOSE); | 105 | BIO_set_fp(out,stdout,BIO_NOCLOSE); |
105 | 106 | ||
106 | a=DH_generate_parameters(64,DH_GENERATOR_5,cb,(char *)out); | 107 | a=DH_generate_parameters(64,DH_GENERATOR_5,cb,out); |
107 | if (a == NULL) goto err; | 108 | if (a == NULL) goto err; |
108 | 109 | ||
109 | BIO_puts(out,"\np ="); | 110 | BIO_puts(out,"\np ="); |
@@ -170,10 +171,7 @@ err: | |||
170 | return(ret); | 171 | return(ret); |
171 | } | 172 | } |
172 | 173 | ||
173 | static void MS_CALLBACK cb(p, n,arg) | 174 | static void MS_CALLBACK cb(int p, int n, void *arg) |
174 | int p; | ||
175 | int n; | ||
176 | char *arg; | ||
177 | { | 175 | { |
178 | char c='*'; | 176 | char c='*'; |
179 | 177 | ||
@@ -182,7 +180,9 @@ char *arg; | |||
182 | if (p == 2) c='*'; | 180 | if (p == 2) c='*'; |
183 | if (p == 3) c='\n'; | 181 | if (p == 3) c='\n'; |
184 | BIO_write((BIO *)arg,&c,1); | 182 | BIO_write((BIO *)arg,&c,1); |
183 | (void)BIO_flush((BIO *)arg); | ||
185 | #ifdef LINT | 184 | #ifdef LINT |
186 | p=n; | 185 | p=n; |
187 | #endif | 186 | #endif |
188 | } | 187 | } |
188 | #endif | ||
diff --git a/src/lib/libcrypto/dh/p1024.c b/src/lib/libcrypto/dh/p1024.c index 0c50c24cfb..368ceca4eb 100644 --- a/src/lib/libcrypto/dh/p1024.c +++ b/src/lib/libcrypto/dh/p1024.c | |||
@@ -57,10 +57,10 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "bn.h" | 60 | #include <openssl/bn.h> |
61 | #include "asn1.h" | 61 | #include <openssl/asn1.h> |
62 | #include "dh.h" | 62 | #include <openssl/dh.h> |
63 | #include "pem.h" | 63 | #include <openssl/pem.h> |
64 | 64 | ||
65 | unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD, | 65 | unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD, |
66 | 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3, | 66 | 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3, |
diff --git a/src/lib/libcrypto/dh/p192.c b/src/lib/libcrypto/dh/p192.c index 881908169a..7bdf40410e 100644 --- a/src/lib/libcrypto/dh/p192.c +++ b/src/lib/libcrypto/dh/p192.c | |||
@@ -57,10 +57,10 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "bn.h" | 60 | #include <openssl/bn.h> |
61 | #include "asn1.h" | 61 | #include <openssl/asn1.h> |
62 | #include "dh.h" | 62 | #include <openssl/dh.h> |
63 | #include "pem.h" | 63 | #include <openssl/pem.h> |
64 | 64 | ||
65 | unsigned char data[]={ | 65 | unsigned char data[]={ |
66 | 0xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E, | 66 | 0xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E, |
diff --git a/src/lib/libcrypto/dh/p512.c b/src/lib/libcrypto/dh/p512.c index cc84e8e50e..a9b6aa83f0 100644 --- a/src/lib/libcrypto/dh/p512.c +++ b/src/lib/libcrypto/dh/p512.c | |||
@@ -57,10 +57,10 @@ | |||
57 | */ | 57 | */ |
58 | 58 | ||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include "bn.h" | 60 | #include <openssl/bn.h> |
61 | #include "asn1.h" | 61 | #include <openssl/asn1.h> |
62 | #include "dh.h" | 62 | #include <openssl/dh.h> |
63 | #include "pem.h" | 63 | #include <openssl/pem.h> |
64 | 64 | ||
65 | unsigned char data[]={ | 65 | unsigned char data[]={ |
66 | 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89, | 66 | 0xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89, |