summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dh
diff options
context:
space:
mode:
authorbeck <>1999-09-29 04:37:45 +0000
committerbeck <>1999-09-29 04:37:45 +0000
commitde8f24ea083384bb66b32ec105dc4743c5663cdf (patch)
tree1412176ae62a3cab2cf2b0b92150fcbceaac6092 /src/lib/libcrypto/dh
parentcb929d29896bcb87c2a97417fbd03e50078fc178 (diff)
downloadopenbsd-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.ssl66
-rw-r--r--src/lib/libcrypto/dh/dh.err12
-rw-r--r--src/lib/libcrypto/dh/dh.h44
-rw-r--r--src/lib/libcrypto/dh/dh_check.c8
-rw-r--r--src/lib/libcrypto/dh/dh_err.c118
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c18
-rw-r--r--src/lib/libcrypto/dh/dh_key.c52
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c19
-rw-r--r--src/lib/libcrypto/dh/dhtest.c36
-rw-r--r--src/lib/libcrypto/dh/p1024.c8
-rw-r--r--src/lib/libcrypto/dh/p192.c8
-rw-r--r--src/lib/libcrypto/dh/p512.c8
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= ../..
7CC= cc 7CC= cc
8INCLUDES= -I.. -I../../include 8INCLUDES= -I.. -I../../include
9CFLAG=-g 9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
10INSTALLTOP=/usr/local/ssl 12INSTALLTOP=/usr/local/ssl
11MAKE= make -f Makefile.ssl 13MAKE= make -f Makefile.ssl
12MAKEDEPEND= makedepend -f Makefile.ssl 14MAKEDEPEND= $(TOP)/util/domd $(TOP)
13MAKEFILE= Makefile.ssl 15MAKEFILE= Makefile.ssl
14AR= ar r 16AR= ar r
15 17
16CFLAGS= $(INCLUDES) $(CFLAG) 18CFLAGS= $(INCLUDES) $(CFLAG)
17 19
18ERR=dh
19ERRC=dh_err
20GENERAL=Makefile 20GENERAL=Makefile
21TEST= dhtest.c 21TEST= dhtest.c
22APPS= 22APPS=
23 23
24LIB=$(TOP)/libcrypto.a 24LIB=$(TOP)/libcrypto.a
25LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c $(ERRC).c 25LIBSRC= dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c
26LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o $(ERRC).o 26LIBOBJ= dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o
27 27
28SRC= $(LIBSRC) 28SRC= $(LIBSRC)
29 29
@@ -39,24 +39,23 @@ all: lib
39 39
40lib: $(LIBOBJ) 40lib: $(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
45files: 45files:
46 perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO 46 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
47 47
48links: 48links:
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
55install: 54install:
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
62tags: 61tags:
@@ -68,17 +67,42 @@ lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff 67 lint -DLINT $(INCLUDES) $(SRC)>fluff
69 68
70depend: 69depend:
71 $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) 70 $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC)
72 71
73dclean: 72dclean:
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
77clean: 76clean:
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
80errors:
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
81dh_check.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
82dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
83dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
84dh_check.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85dh_check.o: ../../include/openssl/opensslconf.h
86dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/stack.h
87dh_check.o: ../cryptlib.h
88dh_err.o: ../../include/openssl/bn.h ../../include/openssl/dh.h
89dh_err.o: ../../include/openssl/err.h ../../include/openssl/opensslconf.h
90dh_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
91dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
92dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
93dh_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95dh_gen.o: ../../include/openssl/stack.h ../cryptlib.h
96dh_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
97dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
98dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
99dh_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
100dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
101dh_key.o: ../../include/openssl/rand.h ../../include/openssl/stack.h
102dh_key.o: ../cryptlib.h
103dh_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
104dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
105dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os.h
106dh_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
107dh_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
108dh_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 @@
63extern "C" { 63extern "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
70typedef struct dh_st 74typedef 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
105DH * DH_new(void); 116DH * DH_new(void);
106void DH_free(DH *dh); 117void DH_free(DH *dh);
107int DH_size(DH *dh); 118int DH_size(DH *dh);
108DH * DH_generate_parameters(int prime_len,int generator, 119DH * 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);
110int DH_check(DH *dh,int *codes); 121int DH_check(DH *dh,int *codes);
111int DH_generate_key(DH *dh); 122int DH_generate_key(DH *dh);
112int DH_compute_key(unsigned char *key,BIGNUM *pub_key,DH *dh); 123int 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
123void ERR_load_DH_strings(void ); 134void ERR_load_DH_strings(void );
124 135
125#else
126
127DH * DH_new();
128void DH_free();
129int DH_size();
130DH * DH_generate_parameters();
131int DH_check();
132int DH_generate_key();
133int DH_compute_key();
134DH * d2i_DHparams();
135int i2d_DHparams();
136#ifndef NO_FP_API
137int DHparams_print_fp();
138#endif
139int DHparams_print();
140void 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
73int DH_check(dh,ret) 73int DH_check(DH *dh, int *ret)
74DH *dh;
75int *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
75static ERR_STRING_DATA DH_str_reasons[]= 77static 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
83void ERR_load_DH_strings() 85void 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
86DH *DH_generate_parameters(prime_len,generator,callback,cb_arg) 86DH *DH_generate_parameters(int prime_len, int generator,
87int prime_len; 87 void (*callback)(int,int,void *), void *cb_arg)
88int generator;
89void (*callback)(P_I_I_P);
90char *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
65int DH_generate_key(dh) 65int DH_generate_key(DH *dh)
66DH *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
114int DH_compute_key(key,pub_key,dh) 121int DH_compute_key(unsigned char *key, BIGNUM *pub_key, DH *dh)
115unsigned char *key;
116BIGNUM *pub_key;
117DH *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);
139err: 151err:
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
64char *DH_version="Diffie-Hellman part of SSLeay 0.9.0b 29-Jun-1998"; 64const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
65 65
66DH *DH_new() 66DH *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
86void DH_free(r) 88void DH_free(DH *r)
87DH *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
96int DH_size(dh) 100int DH_size(DH *dh)
97DH *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
70int 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 84static void MS_CALLBACK cb(int p, int n, void *arg);
77static void MS_CALLBACK cb(int p, int n, char *arg);
78#else
79static 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
87BIO *out=NULL; 90BIO *out=NULL;
88 91
89int main(argc,argv) 92int main(int argc, char *argv[])
90int argc;
91char *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
173static void MS_CALLBACK cb(p, n,arg) 174static void MS_CALLBACK cb(int p, int n, void *arg)
174int p;
175int n;
176char *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
65unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD, 65unsigned 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
65unsigned char data[]={ 65unsigned char data[]={
660xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E, 660xD4,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
65unsigned char data[]={ 65unsigned char data[]={
660xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89, 660xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,