summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2007-03-01 16:29:10 +0000
committercvs2svn <admin@example.com>2007-03-01 16:29:10 +0000
commitd92cde8050488a0c87c357c4756a89026b6659ee (patch)
tree737670254ff24eff6f6dddb0b97cae8c0ba8c571 /src/lib/libcrypto/dsa
parent9c4b4ca341957016adebec4e1eb2446cf0261241 (diff)
downloadopenbsd-OPENBSD_4_1_BASE.tar.gz
openbsd-OPENBSD_4_1_BASE.tar.bz2
openbsd-OPENBSD_4_1_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_4_1_BASE'.OPENBSD_4_1_BASE
Diffstat (limited to 'src/lib/libcrypto/dsa')
-rw-r--r--src/lib/libcrypto/dsa/dsa.h272
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c140
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c114
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c305
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c121
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c308
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c393
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c106
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c103
9 files changed, 0 insertions, 1862 deletions
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
deleted file mode 100644
index aa0669eb7a..0000000000
--- a/src/lib/libcrypto/dsa/dsa.h
+++ /dev/null
@@ -1,272 +0,0 @@
1/* crypto/dsa/dsa.h */
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/*
60 * The DSS routines are based on patches supplied by
61 * Steven Schoch <schoch@sheba.arc.nasa.gov>. He basically did the
62 * work and I have just tweaked them a little to fit into my
63 * stylistic vision for SSLeay :-) */
64
65#ifndef HEADER_DSA_H
66#define HEADER_DSA_H
67
68#ifdef OPENSSL_NO_DSA
69#error DSA is disabled.
70#endif
71
72#ifndef OPENSSL_NO_BIO
73#include <openssl/bio.h>
74#endif
75#include <openssl/bn.h>
76#include <openssl/crypto.h>
77#include <openssl/ossl_typ.h>
78#ifndef OPENSSL_NO_DH
79# include <openssl/dh.h>
80#endif
81
82#define OPENSSL_DSA_MAX_MODULUS_BITS 3072
83
84#define DSA_FLAG_CACHE_MONT_P 0x01
85#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA
86 * implementation now uses constant time
87 * modular exponentiation for secret exponents
88 * by default. This flag causes the
89 * faster variable sliding window method to
90 * be used for all exponents.
91 */
92
93/* If this flag is set external DSA_METHOD callbacks are allowed in FIPS mode
94 * it is then the applications responsibility to ensure the external method
95 * is compliant.
96 */
97
98#define DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW 0x04
99
100#if defined(OPENSSL_FIPS)
101#define FIPS_DSA_SIZE_T int
102#endif
103
104#ifdef __cplusplus
105extern "C" {
106#endif
107
108typedef struct dsa_st DSA;
109
110typedef struct DSA_SIG_st
111 {
112 BIGNUM *r;
113 BIGNUM *s;
114 } DSA_SIG;
115
116typedef struct dsa_method {
117 const char *name;
118 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
119 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
120 BIGNUM **rp);
121 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
122 DSA_SIG *sig, DSA *dsa);
123 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
124 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
125 BN_MONT_CTX *in_mont);
126 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
127 const BIGNUM *m, BN_CTX *ctx,
128 BN_MONT_CTX *m_ctx); /* Can be null */
129 int (*init)(DSA *dsa);
130 int (*finish)(DSA *dsa);
131 int flags;
132 char *app_data;
133} DSA_METHOD;
134
135struct dsa_st
136 {
137 /* This first variable is used to pick up errors where
138 * a DSA is passed instead of of a EVP_PKEY */
139 int pad;
140 long version;
141 int write_params;
142 BIGNUM *p;
143 BIGNUM *q; /* == 20 */
144 BIGNUM *g;
145
146 BIGNUM *pub_key; /* y public key */
147 BIGNUM *priv_key; /* x private key */
148
149 BIGNUM *kinv; /* Signing pre-calc */
150 BIGNUM *r; /* Signing pre-calc */
151
152 int flags;
153 /* Normally used to cache montgomery values */
154 char *method_mont_p;
155 int references;
156 CRYPTO_EX_DATA ex_data;
157 const DSA_METHOD *meth;
158 /* functional reference if 'meth' is ENGINE-provided */
159 ENGINE *engine;
160 };
161
162#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
163 (char *(*)())d2i_DSAparams,(char *)(x))
164#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
165 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
166#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
167 (unsigned char *)(x))
168#define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \
169 (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x))
170#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
171 (unsigned char *)(x))
172
173
174DSA_SIG * DSA_SIG_new(void);
175void DSA_SIG_free(DSA_SIG *a);
176int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
177DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);
178
179DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
180int DSA_do_verify(const unsigned char *dgst,int dgst_len,
181 DSA_SIG *sig,DSA *dsa);
182
183const DSA_METHOD *DSA_OpenSSL(void);
184
185void DSA_set_default_method(const DSA_METHOD *);
186const DSA_METHOD *DSA_get_default_method(void);
187int DSA_set_method(DSA *dsa, const DSA_METHOD *);
188
189DSA * DSA_new(void);
190DSA * DSA_new_method(ENGINE *engine);
191void DSA_free (DSA *r);
192/* "up" the DSA object's reference count */
193int DSA_up_ref(DSA *r);
194int DSA_size(const DSA *);
195 /* next 4 return -1 on error */
196int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
197int DSA_sign(int type,const unsigned char *dgst,int dlen,
198 unsigned char *sig, unsigned int *siglen, DSA *dsa);
199int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
200 const unsigned char *sigbuf, int siglen, DSA *dsa);
201int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
202 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
203int DSA_set_ex_data(DSA *d, int idx, void *arg);
204void *DSA_get_ex_data(DSA *d, int idx);
205
206DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
207DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
208DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
209DSA * DSA_generate_parameters(int bits,
210 unsigned char *seed,int seed_len,
211 int *counter_ret, unsigned long *h_ret,void
212 (*callback)(int, int, void *),void *cb_arg);
213int DSA_generate_key(DSA *a);
214int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
215int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
216int i2d_DSAparams(const DSA *a,unsigned char **pp);
217
218#ifndef OPENSSL_NO_BIO
219int DSAparams_print(BIO *bp, const DSA *x);
220int DSA_print(BIO *bp, const DSA *x, int off);
221#endif
222#ifndef OPENSSL_NO_FP_API
223int DSAparams_print_fp(FILE *fp, const DSA *x);
224int DSA_print_fp(FILE *bp, const DSA *x, int off);
225#endif
226
227#define DSS_prime_checks 50
228/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
229 * 50 rounds of Rabin-Miller */
230#define DSA_is_prime(n, callback, cb_arg) \
231 BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
232
233#ifndef OPENSSL_NO_DH
234/* Convert DSA structure (key or just parameters) into DH structure
235 * (be careful to avoid small subgroup attacks when using this!) */
236DH *DSA_dup_DH(const DSA *r);
237#endif
238
239/* BEGIN ERROR CODES */
240/* The following lines are auto generated by the script mkerr.pl. Any changes
241 * made after this point may be overwritten when the script is next run.
242 */
243void ERR_load_DSA_strings(void);
244
245/* Error codes for the DSA functions. */
246
247/* Function codes. */
248#define DSA_F_D2I_DSA_SIG 110
249#define DSA_F_DSAPARAMS_PRINT 100
250#define DSA_F_DSAPARAMS_PRINT_FP 101
251#define DSA_F_DSA_DO_SIGN 112
252#define DSA_F_DSA_DO_VERIFY 113
253#define DSA_F_DSA_NEW_METHOD 103
254#define DSA_F_DSA_PRINT 104
255#define DSA_F_DSA_PRINT_FP 105
256#define DSA_F_DSA_SIGN 106
257#define DSA_F_DSA_SIGN_SETUP 107
258#define DSA_F_DSA_SIG_NEW 109
259#define DSA_F_DSA_VERIFY 108
260#define DSA_F_I2D_DSA_SIG 111
261#define DSA_F_SIG_CB 114
262
263/* Reason codes. */
264#define DSA_R_BAD_Q_VALUE 102
265#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
266#define DSA_R_MISSING_PARAMETERS 101
267#define DSA_R_MODULUS_TOO_LARGE 103
268
269#ifdef __cplusplus
270}
271#endif
272#endif
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
deleted file mode 100644
index 23fce555aa..0000000000
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ /dev/null
@@ -1,140 +0,0 @@
1/* dsa_asn1.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 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
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dsa.h>
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64
65/* Override the default new methods */
66static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
67{
68 if(operation == ASN1_OP_NEW_PRE) {
69 DSA_SIG *sig;
70 sig = OPENSSL_malloc(sizeof(DSA_SIG));
71 sig->r = NULL;
72 sig->s = NULL;
73 *pval = (ASN1_VALUE *)sig;
74 if(sig) return 2;
75 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
76 return 0;
77 }
78 return 1;
79}
80
81ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
82 ASN1_SIMPLE(DSA_SIG, r, CBIGNUM),
83 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
84} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
85
86IMPLEMENT_ASN1_FUNCTIONS_const(DSA_SIG)
87
88/* Override the default free and new methods */
89static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
90{
91 if(operation == ASN1_OP_NEW_PRE) {
92 *pval = (ASN1_VALUE *)DSA_new();
93 if(*pval) return 2;
94 return 0;
95 } else if(operation == ASN1_OP_FREE_PRE) {
96 DSA_free((DSA *)*pval);
97 *pval = NULL;
98 return 2;
99 }
100 return 1;
101}
102
103ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
104 ASN1_SIMPLE(DSA, version, LONG),
105 ASN1_SIMPLE(DSA, p, BIGNUM),
106 ASN1_SIMPLE(DSA, q, BIGNUM),
107 ASN1_SIMPLE(DSA, g, BIGNUM),
108 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
109 ASN1_SIMPLE(DSA, priv_key, BIGNUM)
110} ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
111
112IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPrivateKey, DSAPrivateKey)
113
114ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
115 ASN1_SIMPLE(DSA, p, BIGNUM),
116 ASN1_SIMPLE(DSA, q, BIGNUM),
117 ASN1_SIMPLE(DSA, g, BIGNUM),
118} ASN1_SEQUENCE_END_cb(DSA, DSAparams)
119
120IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams)
121
122/* DSA public key is a bit trickier... its effectively a CHOICE type
123 * decided by a field called write_params which can either write out
124 * just the public key as an INTEGER or the parameters and public key
125 * in a SEQUENCE
126 */
127
128ASN1_SEQUENCE(dsa_pub_internal) = {
129 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
130 ASN1_SIMPLE(DSA, p, BIGNUM),
131 ASN1_SIMPLE(DSA, q, BIGNUM),
132 ASN1_SIMPLE(DSA, g, BIGNUM)
133} ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal)
134
135ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
136 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
137 ASN1_EX_COMBINE(0, 0, dsa_pub_internal)
138} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)
139
140IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
deleted file mode 100644
index d7fac69154..0000000000
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ /dev/null
@@ -1,114 +0,0 @@
1/* crypto/dsa/dsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/dsa.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSA,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSA,0,reason)
70
71static ERR_STRING_DATA DSA_str_functs[]=
72 {
73{ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"},
74{ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"},
75{ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"},
76{ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"},
77{ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"},
78{ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"},
79{ERR_FUNC(DSA_F_DSA_PRINT), "DSA_print"},
80{ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"},
81{ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"},
82{ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"},
83{ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"},
84{ERR_FUNC(DSA_F_DSA_VERIFY), "DSA_verify"},
85{ERR_FUNC(DSA_F_I2D_DSA_SIG), "i2d_DSA_SIG"},
86{ERR_FUNC(DSA_F_SIG_CB), "SIG_CB"},
87{0,NULL}
88 };
89
90static ERR_STRING_DATA DSA_str_reasons[]=
91 {
92{ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"},
93{ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"},
94{ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"},
95{ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
96{0,NULL}
97 };
98
99#endif
100
101void ERR_load_DSA_strings(void)
102 {
103 static int init=1;
104
105 if (init)
106 {
107 init=0;
108#ifndef OPENSSL_NO_ERR
109 ERR_load_strings(0,DSA_str_functs);
110 ERR_load_strings(0,DSA_str_reasons);
111#endif
112
113 }
114 }
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
deleted file mode 100644
index e40afeea51..0000000000
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ /dev/null
@@ -1,305 +0,0 @@
1/* crypto/dsa/dsa_gen.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#undef GENUINE_DSA
60
61#ifdef GENUINE_DSA
62/* Parameter generation follows the original release of FIPS PUB 186,
63 * Appendix 2.2 (i.e. use SHA as defined in FIPS PUB 180) */
64#define HASH EVP_sha()
65#else
66/* Parameter generation follows the updated Appendix 2.2 for FIPS PUB 186,
67 * also Appendix 2.2 of FIPS PUB 186-1 (i.e. use SHA as defined in
68 * FIPS PUB 180-1) */
69#define HASH EVP_sha1()
70#endif
71
72#ifndef OPENSSL_NO_SHA
73
74#include <stdio.h>
75#include <time.h>
76#include "cryptlib.h"
77#include <openssl/evp.h>
78#include <openssl/bn.h>
79#include <openssl/dsa.h>
80#include <openssl/rand.h>
81#include <openssl/sha.h>
82
83#ifndef OPENSSL_FIPS
84DSA *DSA_generate_parameters(int bits,
85 unsigned char *seed_in, int seed_len,
86 int *counter_ret, unsigned long *h_ret,
87 void (*callback)(int, int, void *),
88 void *cb_arg)
89 {
90 int ok=0;
91 unsigned char seed[SHA_DIGEST_LENGTH];
92 unsigned char md[SHA_DIGEST_LENGTH];
93 unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH];
94 BIGNUM *r0,*W,*X,*c,*test;
95 BIGNUM *g=NULL,*q=NULL,*p=NULL;
96 BN_MONT_CTX *mont=NULL;
97 int k,n=0,i,b,m=0;
98 int counter=0;
99 int r=0;
100 BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL;
101 unsigned int h=2;
102 DSA *ret=NULL;
103
104 if (bits < 512) bits=512;
105 bits=(bits+63)/64*64;
106
107 if (seed_len < 20)
108 seed_in = NULL; /* seed buffer too small -- ignore */
109 if (seed_len > 20)
110 seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
111 * but our internal buffers are restricted to 160 bits*/
112 if ((seed_in != NULL) && (seed_len == 20))
113 memcpy(seed,seed_in,seed_len);
114
115 if ((ctx=BN_CTX_new()) == NULL) goto err;
116 if ((ctx2=BN_CTX_new()) == NULL) goto err;
117 if ((ctx3=BN_CTX_new()) == NULL) goto err;
118 if ((ret=DSA_new()) == NULL) goto err;
119
120 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
121
122 BN_CTX_start(ctx2);
123 r0 = BN_CTX_get(ctx2);
124 g = BN_CTX_get(ctx2);
125 W = BN_CTX_get(ctx2);
126 q = BN_CTX_get(ctx2);
127 X = BN_CTX_get(ctx2);
128 c = BN_CTX_get(ctx2);
129 p = BN_CTX_get(ctx2);
130 test = BN_CTX_get(ctx2);
131 if (test == NULL) goto err;
132
133 if (!BN_lshift(test,BN_value_one(),bits-1)) goto err;
134
135 for (;;)
136 {
137 for (;;) /* find q */
138 {
139 int seed_is_random;
140
141 /* step 1 */
142 if (callback != NULL) callback(0,m++,cb_arg);
143
144 if (!seed_len)
145 {
146 RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH);
147 seed_is_random = 1;
148 }
149 else
150 {
151 seed_is_random = 0;
152 seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
153 }
154 memcpy(buf,seed,SHA_DIGEST_LENGTH);
155 memcpy(buf2,seed,SHA_DIGEST_LENGTH);
156 /* precompute "SEED + 1" for step 7: */
157 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
158 {
159 buf[i]++;
160 if (buf[i] != 0) break;
161 }
162
163 /* step 2 */
164 EVP_Digest(seed,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
165 EVP_Digest(buf,SHA_DIGEST_LENGTH,buf2,NULL,HASH, NULL);
166 for (i=0; i<SHA_DIGEST_LENGTH; i++)
167 md[i]^=buf2[i];
168
169 /* step 3 */
170 md[0]|=0x80;
171 md[SHA_DIGEST_LENGTH-1]|=0x01;
172 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
173
174 /* step 4 */
175 r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random);
176 if (r > 0)
177 break;
178 if (r != 0)
179 goto err;
180
181 /* do a callback call */
182 /* step 5 */
183 }
184
185 if (callback != NULL) callback(2,0,cb_arg);
186 if (callback != NULL) callback(3,0,cb_arg);
187
188 /* step 6 */
189 counter=0;
190 /* "offset = 2" */
191
192 n=(bits-1)/160;
193 b=(bits-1)-n*160;
194
195 for (;;)
196 {
197 if (callback != NULL && counter != 0)
198 callback(0,counter,cb_arg);
199
200 /* step 7 */
201 if (!BN_zero(W)) goto err;
202 /* now 'buf' contains "SEED + offset - 1" */
203 for (k=0; k<=n; k++)
204 {
205 /* obtain "SEED + offset + k" by incrementing: */
206 for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--)
207 {
208 buf[i]++;
209 if (buf[i] != 0) break;
210 }
211
212 EVP_Digest(buf,SHA_DIGEST_LENGTH,md,NULL,HASH, NULL);
213
214 /* step 8 */
215 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0))
216 goto err;
217 if (!BN_lshift(r0,r0,160*k)) goto err;
218 if (!BN_add(W,W,r0)) goto err;
219 }
220
221 /* more of step 8 */
222 if (!BN_mask_bits(W,bits-1)) goto err;
223 if (!BN_copy(X,W)) goto err;
224 if (!BN_add(X,X,test)) goto err;
225
226 /* step 9 */
227 if (!BN_lshift1(r0,q)) goto err;
228 if (!BN_mod(c,X,r0,ctx)) goto err;
229 if (!BN_sub(r0,c,BN_value_one())) goto err;
230 if (!BN_sub(p,X,r0)) goto err;
231
232 /* step 10 */
233 if (BN_cmp(p,test) >= 0)
234 {
235 /* step 11 */
236 r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1);
237 if (r > 0)
238 goto end; /* found it */
239 if (r != 0)
240 goto err;
241 }
242
243 /* step 13 */
244 counter++;
245 /* "offset = offset + n + 1" */
246
247 /* step 14 */
248 if (counter >= 4096) break;
249 }
250 }
251end:
252 if (callback != NULL) callback(2,1,cb_arg);
253
254 /* We now need to generate g */
255 /* Set r0=(p-1)/q */
256 if (!BN_sub(test,p,BN_value_one())) goto err;
257 if (!BN_div(r0,NULL,test,q,ctx)) goto err;
258
259 if (!BN_set_word(test,h)) goto err;
260 if (!BN_MONT_CTX_set(mont,p,ctx)) goto err;
261
262 for (;;)
263 {
264 /* g=test^r0%p */
265 if (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;
266 if (!BN_is_one(g)) break;
267 if (!BN_add(test,test,BN_value_one())) goto err;
268 h++;
269 }
270
271 if (callback != NULL) callback(3,1,cb_arg);
272
273 ok=1;
274err:
275 if (!ok)
276 {
277 if (ret != NULL) DSA_free(ret);
278 }
279 else
280 {
281 ret->p=BN_dup(p);
282 ret->q=BN_dup(q);
283 ret->g=BN_dup(g);
284 if (ret->p == NULL || ret->q == NULL || ret->g == NULL)
285 {
286 ok=0;
287 goto err;
288 }
289 if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
290 if (counter_ret != NULL) *counter_ret=counter;
291 if (h_ret != NULL) *h_ret=h;
292 }
293 if (ctx != NULL) BN_CTX_free(ctx);
294 if (ctx2 != NULL)
295 {
296 BN_CTX_end(ctx2);
297 BN_CTX_free(ctx2);
298 }
299 if (ctx3 != NULL) BN_CTX_free(ctx3);
300 if (mont != NULL) BN_MONT_CTX_free(mont);
301 return(ok?ret:NULL);
302 }
303#endif /* ndef OPENSSL_FIPS */
304#endif /* ndef OPENSSL_NO_SHA */
305
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
deleted file mode 100644
index 980b6dc2d3..0000000000
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* crypto/dsa/dsa_key.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#ifndef OPENSSL_NO_SHA
60#include <stdio.h>
61#include <time.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66
67#ifndef OPENSSL_FIPS
68int DSA_generate_key(DSA *dsa)
69 {
70 int ok=0;
71 BN_CTX *ctx=NULL;
72 BIGNUM *pub_key=NULL,*priv_key=NULL;
73
74 if ((ctx=BN_CTX_new()) == NULL) goto err;
75
76 if (dsa->priv_key == NULL)
77 {
78 if ((priv_key=BN_new()) == NULL) goto err;
79 }
80 else
81 priv_key=dsa->priv_key;
82
83 do
84 if (!BN_rand_range(priv_key,dsa->q)) goto err;
85 while (BN_is_zero(priv_key));
86
87 if (dsa->pub_key == NULL)
88 {
89 if ((pub_key=BN_new()) == NULL) goto err;
90 }
91 else
92 pub_key=dsa->pub_key;
93
94 {
95 BIGNUM local_prk;
96 BIGNUM *prk;
97
98 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
99 {
100 BN_init(&local_prk);
101 prk = &local_prk;
102 BN_with_flags(prk, priv_key, BN_FLG_EXP_CONSTTIME);
103 }
104 else
105 prk = priv_key;
106
107 if (!BN_mod_exp(pub_key,dsa->g,prk,dsa->p,ctx)) goto err;
108 }
109
110 dsa->priv_key=priv_key;
111 dsa->pub_key=pub_key;
112 ok=1;
113
114err:
115 if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
116 if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
117 if (ctx != NULL) BN_CTX_free(ctx);
118 return(ok);
119 }
120#endif
121#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
deleted file mode 100644
index 4171af24c6..0000000000
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ /dev/null
@@ -1,308 +0,0 @@
1/* crypto/dsa/dsa_lib.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/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/asn1.h>
66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h>
68#endif
69
70const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT;
71
72static const DSA_METHOD *default_DSA_method = NULL;
73
74void DSA_set_default_method(const DSA_METHOD *meth)
75 {
76 default_DSA_method = meth;
77 }
78
79const DSA_METHOD *DSA_get_default_method(void)
80 {
81 if(!default_DSA_method)
82 default_DSA_method = DSA_OpenSSL();
83 return default_DSA_method;
84 }
85
86DSA *DSA_new(void)
87 {
88 return DSA_new_method(NULL);
89 }
90
91int DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
92 {
93 /* NB: The caller is specifically setting a method, so it's not up to us
94 * to deal with which ENGINE it comes from. */
95 const DSA_METHOD *mtmp;
96 mtmp = dsa->meth;
97 if (mtmp->finish) mtmp->finish(dsa);
98#ifndef OPENSSL_NO_ENGINE
99 if (dsa->engine)
100 {
101 ENGINE_finish(dsa->engine);
102 dsa->engine = NULL;
103 }
104#endif
105 dsa->meth = meth;
106 if (meth->init) meth->init(dsa);
107 return 1;
108 }
109
110DSA *DSA_new_method(ENGINE *engine)
111 {
112 DSA *ret;
113
114 ret=(DSA *)OPENSSL_malloc(sizeof(DSA));
115 if (ret == NULL)
116 {
117 DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
118 return(NULL);
119 }
120 ret->meth = DSA_get_default_method();
121#ifndef OPENSSL_NO_ENGINE
122 if (engine)
123 {
124 if (!ENGINE_init(engine))
125 {
126 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
127 OPENSSL_free(ret);
128 return NULL;
129 }
130 ret->engine = engine;
131 }
132 else
133 ret->engine = ENGINE_get_default_DSA();
134 if(ret->engine)
135 {
136 ret->meth = ENGINE_get_DSA(ret->engine);
137 if(!ret->meth)
138 {
139 DSAerr(DSA_F_DSA_NEW_METHOD,
140 ERR_R_ENGINE_LIB);
141 ENGINE_finish(ret->engine);
142 OPENSSL_free(ret);
143 return NULL;
144 }
145 }
146#endif
147
148 ret->pad=0;
149 ret->version=0;
150 ret->write_params=1;
151 ret->p=NULL;
152 ret->q=NULL;
153 ret->g=NULL;
154
155 ret->pub_key=NULL;
156 ret->priv_key=NULL;
157
158 ret->kinv=NULL;
159 ret->r=NULL;
160 ret->method_mont_p=NULL;
161
162 ret->references=1;
163 ret->flags=ret->meth->flags;
164 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
165 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
166 {
167#ifndef OPENSSL_NO_ENGINE
168 if (ret->engine)
169 ENGINE_finish(ret->engine);
170#endif
171 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
172 OPENSSL_free(ret);
173 ret=NULL;
174 }
175
176 return(ret);
177 }
178
179void DSA_free(DSA *r)
180 {
181 int i;
182
183 if (r == NULL) return;
184
185 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA);
186#ifdef REF_PRINT
187 REF_PRINT("DSA",r);
188#endif
189 if (i > 0) return;
190#ifdef REF_CHECK
191 if (i < 0)
192 {
193 fprintf(stderr,"DSA_free, bad reference count\n");
194 abort();
195 }
196#endif
197
198 if(r->meth->finish)
199 r->meth->finish(r);
200#ifndef OPENSSL_NO_ENGINE
201 if(r->engine)
202 ENGINE_finish(r->engine);
203#endif
204
205 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
206
207 if (r->p != NULL) BN_clear_free(r->p);
208 if (r->q != NULL) BN_clear_free(r->q);
209 if (r->g != NULL) BN_clear_free(r->g);
210 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
211 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
212 if (r->kinv != NULL) BN_clear_free(r->kinv);
213 if (r->r != NULL) BN_clear_free(r->r);
214 OPENSSL_free(r);
215 }
216
217int DSA_up_ref(DSA *r)
218 {
219 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA);
220#ifdef REF_PRINT
221 REF_PRINT("DSA",r);
222#endif
223#ifdef REF_CHECK
224 if (i < 2)
225 {
226 fprintf(stderr, "DSA_up_ref, bad reference count\n");
227 abort();
228 }
229#endif
230 return ((i > 1) ? 1 : 0);
231 }
232
233int DSA_size(const DSA *r)
234 {
235 int ret,i;
236 ASN1_INTEGER bs;
237 unsigned char buf[4]; /* 4 bytes looks really small.
238 However, i2d_ASN1_INTEGER() will not look
239 beyond the first byte, as long as the second
240 parameter is NULL. */
241
242 i=BN_num_bits(r->q);
243 bs.length=(i+7)/8;
244 bs.data=buf;
245 bs.type=V_ASN1_INTEGER;
246 /* If the top bit is set the asn1 encoding is 1 larger. */
247 buf[0]=0xff;
248
249 i=i2d_ASN1_INTEGER(&bs,NULL);
250 i+=i; /* r and s */
251 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
252 return(ret);
253 }
254
255int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
256 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
257 {
258 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, argl, argp,
259 new_func, dup_func, free_func);
260 }
261
262int DSA_set_ex_data(DSA *d, int idx, void *arg)
263 {
264 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
265 }
266
267void *DSA_get_ex_data(DSA *d, int idx)
268 {
269 return(CRYPTO_get_ex_data(&d->ex_data,idx));
270 }
271
272#ifndef OPENSSL_NO_DH
273DH *DSA_dup_DH(const DSA *r)
274 {
275 /* DSA has p, q, g, optional pub_key, optional priv_key.
276 * DH has p, optional length, g, optional pub_key, optional priv_key.
277 */
278
279 DH *ret = NULL;
280
281 if (r == NULL)
282 goto err;
283 ret = DH_new();
284 if (ret == NULL)
285 goto err;
286 if (r->p != NULL)
287 if ((ret->p = BN_dup(r->p)) == NULL)
288 goto err;
289 if (r->q != NULL)
290 ret->length = BN_num_bits(r->q);
291 if (r->g != NULL)
292 if ((ret->g = BN_dup(r->g)) == NULL)
293 goto err;
294 if (r->pub_key != NULL)
295 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
296 goto err;
297 if (r->priv_key != NULL)
298 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
299 goto err;
300
301 return ret;
302
303 err:
304 if (ret != NULL)
305 DH_free(ret);
306 return NULL;
307 }
308#endif
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
deleted file mode 100644
index 5de5fc7e91..0000000000
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ /dev/null
@@ -1,393 +0,0 @@
1/* crypto/dsa/dsa_ossl.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/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67
68#ifndef OPENSSL_FIPS
69static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
70static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
71static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
72 DSA *dsa);
73static int dsa_init(DSA *dsa);
74static int dsa_finish(DSA *dsa);
75static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
76 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
77 BN_MONT_CTX *in_mont);
78static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
79 const BIGNUM *m, BN_CTX *ctx,
80 BN_MONT_CTX *m_ctx);
81
82static DSA_METHOD openssl_dsa_meth = {
83"OpenSSL DSA method",
84dsa_do_sign,
85dsa_sign_setup,
86dsa_do_verify,
87dsa_mod_exp,
88dsa_bn_mod_exp,
89dsa_init,
90dsa_finish,
910,
92NULL
93};
94
95const DSA_METHOD *DSA_OpenSSL(void)
96{
97 return &openssl_dsa_meth;
98}
99
100static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
101 {
102 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
103 BIGNUM m;
104 BIGNUM xr;
105 BN_CTX *ctx=NULL;
106 int i,reason=ERR_R_BN_LIB;
107 DSA_SIG *ret=NULL;
108
109 BN_init(&m);
110 BN_init(&xr);
111
112 if (!dsa->p || !dsa->q || !dsa->g)
113 {
114 reason=DSA_R_MISSING_PARAMETERS;
115 goto err;
116 }
117
118 s=BN_new();
119 if (s == NULL) goto err;
120
121 i=BN_num_bytes(dsa->q); /* should be 20 */
122 if ((dlen > i) || (dlen > 50))
123 {
124 reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE;
125 goto err;
126 }
127
128 ctx=BN_CTX_new();
129 if (ctx == NULL) goto err;
130
131 if ((dsa->kinv == NULL) || (dsa->r == NULL))
132 {
133 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
134 }
135 else
136 {
137 kinv=dsa->kinv;
138 dsa->kinv=NULL;
139 r=dsa->r;
140 dsa->r=NULL;
141 }
142
143 if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err;
144
145 /* Compute s = inv(k) (m + xr) mod q */
146 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
147 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
148 if (BN_cmp(s,dsa->q) > 0)
149 BN_sub(s,s,dsa->q);
150 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
151
152 ret=DSA_SIG_new();
153 if (ret == NULL) goto err;
154 ret->r = r;
155 ret->s = s;
156
157err:
158 if (!ret)
159 {
160 DSAerr(DSA_F_DSA_DO_SIGN,reason);
161 BN_free(r);
162 BN_free(s);
163 }
164 if (ctx != NULL) BN_CTX_free(ctx);
165 BN_clear_free(&m);
166 BN_clear_free(&xr);
167 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
168 BN_clear_free(kinv);
169 return(ret);
170 }
171
172static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
173 {
174 BN_CTX *ctx;
175 BIGNUM k,kq,*K,*kinv=NULL,*r=NULL;
176 int ret=0;
177
178 if (!dsa->p || !dsa->q || !dsa->g)
179 {
180 DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);
181 return 0;
182 }
183
184 BN_init(&k);
185 BN_init(&kq);
186
187 if (ctx_in == NULL)
188 {
189 if ((ctx=BN_CTX_new()) == NULL) goto err;
190 }
191 else
192 ctx=ctx_in;
193
194 if ((r=BN_new()) == NULL) goto err;
195
196 /* Get random k */
197 do
198 if (!BN_rand_range(&k, dsa->q)) goto err;
199 while (BN_is_zero(&k));
200 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
201 {
202 BN_set_flags(&k, BN_FLG_EXP_CONSTTIME);
203 }
204
205 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
206 {
207 if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p,
208 CRYPTO_LOCK_DSA,
209 dsa->p, ctx))
210 goto err;
211 }
212
213 /* Compute r = (g^k mod p) mod q */
214
215 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
216 {
217 if (!BN_copy(&kq, &k)) goto err;
218
219 /* We do not want timing information to leak the length of k,
220 * so we compute g^k using an equivalent exponent of fixed length.
221 *
222 * (This is a kludge that we need because the BN_mod_exp_mont()
223 * does not let us specify the desired timing behaviour.) */
224
225 if (!BN_add(&kq, &kq, dsa->q)) goto err;
226 if (BN_num_bits(&kq) <= BN_num_bits(dsa->q))
227 {
228 if (!BN_add(&kq, &kq, dsa->q)) goto err;
229 }
230
231 K = &kq;
232 }
233 else
234 {
235 K = &k;
236 }
237 if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,K,dsa->p,ctx,
238 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
239 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
240
241 /* Compute part of 's = inv(k) (m + xr) mod q' */
242 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
243
244 if (*kinvp != NULL) BN_clear_free(*kinvp);
245 *kinvp=kinv;
246 kinv=NULL;
247 if (*rp != NULL) BN_clear_free(*rp);
248 *rp=r;
249 ret=1;
250err:
251 if (!ret)
252 {
253 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
254 if (kinv != NULL) BN_clear_free(kinv);
255 if (r != NULL) BN_clear_free(r);
256 }
257 if (ctx_in == NULL) BN_CTX_free(ctx);
258 if (kinv != NULL) BN_clear_free(kinv);
259 BN_clear_free(&k);
260 BN_clear_free(&kq);
261 return(ret);
262 }
263
264static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
265 DSA *dsa)
266 {
267 BN_CTX *ctx;
268 BIGNUM u1,u2,t1;
269 BN_MONT_CTX *mont=NULL;
270 int ret = -1;
271 if (!dsa->p || !dsa->q || !dsa->g)
272 {
273 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MISSING_PARAMETERS);
274 return -1;
275 }
276
277 if (BN_num_bits(dsa->q) != 160)
278 {
279 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
280 return -1;
281 }
282
283 if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS)
284 {
285 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
286 return -1;
287 }
288
289 BN_init(&u1);
290 BN_init(&u2);
291 BN_init(&t1);
292
293 if ((ctx=BN_CTX_new()) == NULL) goto err;
294
295 if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0)
296 {
297 ret = 0;
298 goto err;
299 }
300 if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0)
301 {
302 ret = 0;
303 goto err;
304 }
305
306 /* Calculate W = inv(S) mod Q
307 * save W in u2 */
308 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
309
310 /* save M in u1 */
311 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
312
313 /* u1 = M * w mod q */
314 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
315
316 /* u2 = r * w mod q */
317 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
318
319
320 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
321 {
322 mont = BN_MONT_CTX_set_locked(
323 (BN_MONT_CTX **)&dsa->method_mont_p,
324 CRYPTO_LOCK_DSA, dsa->p, ctx);
325 if (!mont)
326 goto err;
327 }
328
329#if 0
330 {
331 BIGNUM t2;
332
333 BN_init(&t2);
334 /* v = ( g^u1 * y^u2 mod p ) mod q */
335 /* let t1 = g ^ u1 mod p */
336 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
337 /* let t2 = y ^ u2 mod p */
338 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
339 /* let u1 = t1 * t2 mod p */
340 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
341 BN_free(&t2);
342 }
343 /* let u1 = u1 mod q */
344 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
345#else
346 {
347 if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
348 dsa->p,ctx,mont)) goto err;
349 /* BN_copy(&u1,&t1); */
350 /* let u1 = u1 mod q */
351 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
352 }
353#endif
354 /* V is now in u1. If the signature is correct, it will be
355 * equal to R. */
356 ret=(BN_ucmp(&u1, sig->r) == 0);
357
358 err:
359 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
360 if (ctx != NULL) BN_CTX_free(ctx);
361 BN_free(&u1);
362 BN_free(&u2);
363 BN_free(&t1);
364 return(ret);
365 }
366
367static int dsa_init(DSA *dsa)
368{
369 dsa->flags|=DSA_FLAG_CACHE_MONT_P;
370 return(1);
371}
372
373static int dsa_finish(DSA *dsa)
374{
375 if(dsa->method_mont_p)
376 BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
377 return(1);
378}
379
380static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
381 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
382 BN_MONT_CTX *in_mont)
383{
384 return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
385}
386
387static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
388 const BIGNUM *m, BN_CTX *ctx,
389 BN_MONT_CTX *m_ctx)
390{
391 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
392}
393#endif
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
deleted file mode 100644
index 37c65efb20..0000000000
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* crypto/dsa/dsa_sign.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/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67#ifndef OPENSSL_NO_ENGINE
68#include <openssl/engine.h>
69#endif
70#include <openssl/fips.h>
71
72DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
73 {
74#ifdef OPENSSL_FIPS
75 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
76 && !FIPS_dsa_check(dsa))
77 return NULL;
78#endif
79 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
80 }
81
82int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
83 unsigned int *siglen, DSA *dsa)
84 {
85 DSA_SIG *s;
86 s=DSA_do_sign(dgst,dlen,dsa);
87 if (s == NULL)
88 {
89 *siglen=0;
90 return(0);
91 }
92 *siglen=i2d_DSA_SIG(s,&sig);
93 DSA_SIG_free(s);
94 return(1);
95 }
96
97int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
98 {
99#ifdef OPENSSL_FIPS
100 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
101 && !FIPS_dsa_check(dsa))
102 return 0;
103#endif
104 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
105 }
106
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
deleted file mode 100644
index c9784bed48..0000000000
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/* crypto/dsa/dsa_vrf.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/* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66#include <openssl/asn1.h>
67#include <openssl/asn1_mac.h>
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71#include <openssl/fips.h>
72
73int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
74 DSA *dsa)
75 {
76#ifdef OPENSSL_FIPS
77 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
78 && !FIPS_dsa_check(dsa))
79 return -1;
80#endif
81 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
82 }
83
84/* data has already been hashed (probably with SHA or SHA-1). */
85/* returns
86 * 1: correct signature
87 * 0: incorrect signature
88 * -1: error
89 */
90int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
91 const unsigned char *sigbuf, int siglen, DSA *dsa)
92 {
93 DSA_SIG *s;
94 int ret=-1;
95
96 s = DSA_SIG_new();
97 if (s == NULL) return(ret);
98 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
99 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
100err:
101 DSA_SIG_free(s);
102 return(ret);
103 }