summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
committercvs2svn <admin@example.com>2014-02-27 21:04:58 +0000
commit726818f36b5221c023cd04c4b90bdbc08e94cd96 (patch)
treecf8221f3aa5bf5a578ddf1ecf5677ad08c04d342 /src/lib/libcrypto/dsa
parent3b6d92e82b1421b811bcdec7f7fdfb31eeef18de (diff)
downloadopenbsd-OPENBSD_5_5_BASE.tar.gz
openbsd-OPENBSD_5_5_BASE.tar.bz2
openbsd-OPENBSD_5_5_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_5_5_BASE'.OPENBSD_5_5_BASE
Diffstat (limited to '')
-rw-r--r--src/lib/libcrypto/dsa/dsa.h327
-rw-r--r--src/lib/libcrypto/dsa/dsa_ameth.c704
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c188
-rw-r--r--src/lib/libcrypto/dsa/dsa_depr.c106
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c130
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c371
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c144
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c329
-rw-r--r--src/lib/libcrypto/dsa/dsa_locl.h60
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c412
-rw-r--r--src/lib/libcrypto/dsa/dsa_pmeth.c318
-rw-r--r--src/lib/libcrypto/dsa/dsa_prn.c121
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c114
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c76
14 files changed, 0 insertions, 3400 deletions
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
deleted file mode 100644
index a6f6d0b0b2..0000000000
--- a/src/lib/libcrypto/dsa/dsa.h
+++ /dev/null
@@ -1,327 +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#include <openssl/e_os2.h>
69
70#ifdef OPENSSL_NO_DSA
71#error DSA is disabled.
72#endif
73
74#ifndef OPENSSL_NO_BIO
75#include <openssl/bio.h>
76#endif
77#include <openssl/crypto.h>
78#include <openssl/ossl_typ.h>
79
80#ifndef OPENSSL_NO_DEPRECATED
81#include <openssl/bn.h>
82#ifndef OPENSSL_NO_DH
83# include <openssl/dh.h>
84#endif
85#endif
86
87#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
88# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
89#endif
90
91#define DSA_FLAG_CACHE_MONT_P 0x01
92#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA
93 * implementation now uses constant time
94 * modular exponentiation for secret exponents
95 * by default. This flag causes the
96 * faster variable sliding window method to
97 * be used for all exponents.
98 */
99
100/* If this flag is set the DSA method is FIPS compliant and can be used
101 * in FIPS mode. This is set in the validated module method. If an
102 * application sets this flag in its own methods it is its reposibility
103 * to ensure the result is compliant.
104 */
105
106#define DSA_FLAG_FIPS_METHOD 0x0400
107
108/* If this flag is set the operations normally disabled in FIPS mode are
109 * permitted it is then the applications responsibility to ensure that the
110 * usage is compliant.
111 */
112
113#define DSA_FLAG_NON_FIPS_ALLOW 0x0400
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119/* Already defined in ossl_typ.h */
120/* typedef struct dsa_st DSA; */
121/* typedef struct dsa_method DSA_METHOD; */
122
123typedef struct DSA_SIG_st
124 {
125 BIGNUM *r;
126 BIGNUM *s;
127 } DSA_SIG;
128
129struct dsa_method
130 {
131 const char *name;
132 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
133 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
134 BIGNUM **rp);
135 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
136 DSA_SIG *sig, DSA *dsa);
137 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
138 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
139 BN_MONT_CTX *in_mont);
140 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
141 const BIGNUM *m, BN_CTX *ctx,
142 BN_MONT_CTX *m_ctx); /* Can be null */
143 int (*init)(DSA *dsa);
144 int (*finish)(DSA *dsa);
145 int flags;
146 char *app_data;
147 /* If this is non-NULL, it is used to generate DSA parameters */
148 int (*dsa_paramgen)(DSA *dsa, int bits,
149 const unsigned char *seed, int seed_len,
150 int *counter_ret, unsigned long *h_ret,
151 BN_GENCB *cb);
152 /* If this is non-NULL, it is used to generate DSA keys */
153 int (*dsa_keygen)(DSA *dsa);
154 };
155
156struct dsa_st
157 {
158 /* This first variable is used to pick up errors where
159 * a DSA is passed instead of of a EVP_PKEY */
160 int pad;
161 long version;
162 int write_params;
163 BIGNUM *p;
164 BIGNUM *q; /* == 20 */
165 BIGNUM *g;
166
167 BIGNUM *pub_key; /* y public key */
168 BIGNUM *priv_key; /* x private key */
169
170 BIGNUM *kinv; /* Signing pre-calc */
171 BIGNUM *r; /* Signing pre-calc */
172
173 int flags;
174 /* Normally used to cache montgomery values */
175 BN_MONT_CTX *method_mont_p;
176 int references;
177 CRYPTO_EX_DATA ex_data;
178 const DSA_METHOD *meth;
179 /* functional reference if 'meth' is ENGINE-provided */
180 ENGINE *engine;
181 };
182
183#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
184 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
185#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
186 (unsigned char *)(x))
187#define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x)
188#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x)
189
190
191DSA *DSAparams_dup(DSA *x);
192DSA_SIG * DSA_SIG_new(void);
193void DSA_SIG_free(DSA_SIG *a);
194int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
195DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);
196
197DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
198int DSA_do_verify(const unsigned char *dgst,int dgst_len,
199 DSA_SIG *sig,DSA *dsa);
200
201const DSA_METHOD *DSA_OpenSSL(void);
202
203void DSA_set_default_method(const DSA_METHOD *);
204const DSA_METHOD *DSA_get_default_method(void);
205int DSA_set_method(DSA *dsa, const DSA_METHOD *);
206
207DSA * DSA_new(void);
208DSA * DSA_new_method(ENGINE *engine);
209void DSA_free (DSA *r);
210/* "up" the DSA object's reference count */
211int DSA_up_ref(DSA *r);
212int DSA_size(const DSA *);
213 /* next 4 return -1 on error */
214int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
215int DSA_sign(int type,const unsigned char *dgst,int dlen,
216 unsigned char *sig, unsigned int *siglen, DSA *dsa);
217int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
218 const unsigned char *sigbuf, int siglen, DSA *dsa);
219int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
220 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
221int DSA_set_ex_data(DSA *d, int idx, void *arg);
222void *DSA_get_ex_data(DSA *d, int idx);
223
224DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
225DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
226DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
227
228/* Deprecated version */
229#ifndef OPENSSL_NO_DEPRECATED
230DSA * DSA_generate_parameters(int bits,
231 unsigned char *seed,int seed_len,
232 int *counter_ret, unsigned long *h_ret,void
233 (*callback)(int, int, void *),void *cb_arg);
234#endif /* !defined(OPENSSL_NO_DEPRECATED) */
235
236/* New version */
237int DSA_generate_parameters_ex(DSA *dsa, int bits,
238 const unsigned char *seed,int seed_len,
239 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
240
241int DSA_generate_key(DSA *a);
242int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
243int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
244int i2d_DSAparams(const DSA *a,unsigned char **pp);
245
246#ifndef OPENSSL_NO_BIO
247int DSAparams_print(BIO *bp, const DSA *x);
248int DSA_print(BIO *bp, const DSA *x, int off);
249#endif
250#ifndef OPENSSL_NO_FP_API
251int DSAparams_print_fp(FILE *fp, const DSA *x);
252int DSA_print_fp(FILE *bp, const DSA *x, int off);
253#endif
254
255#define DSS_prime_checks 50
256/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
257 * 50 rounds of Rabin-Miller */
258#define DSA_is_prime(n, callback, cb_arg) \
259 BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
260
261#ifndef OPENSSL_NO_DH
262/* Convert DSA structure (key or just parameters) into DH structure
263 * (be careful to avoid small subgroup attacks when using this!) */
264DH *DSA_dup_DH(const DSA *r);
265#endif
266
267#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
268 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
269 EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL)
270
271#define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1)
272#define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2)
273#define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3)
274
275/* BEGIN ERROR CODES */
276/* The following lines are auto generated by the script mkerr.pl. Any changes
277 * made after this point may be overwritten when the script is next run.
278 */
279void ERR_load_DSA_strings(void);
280
281/* Error codes for the DSA functions. */
282
283/* Function codes. */
284#define DSA_F_D2I_DSA_SIG 110
285#define DSA_F_DO_DSA_PRINT 104
286#define DSA_F_DSAPARAMS_PRINT 100
287#define DSA_F_DSAPARAMS_PRINT_FP 101
288#define DSA_F_DSA_DO_SIGN 112
289#define DSA_F_DSA_DO_VERIFY 113
290#define DSA_F_DSA_GENERATE_KEY 124
291#define DSA_F_DSA_GENERATE_PARAMETERS_EX 123
292#define DSA_F_DSA_NEW_METHOD 103
293#define DSA_F_DSA_PARAM_DECODE 119
294#define DSA_F_DSA_PRINT_FP 105
295#define DSA_F_DSA_PRIV_DECODE 115
296#define DSA_F_DSA_PRIV_ENCODE 116
297#define DSA_F_DSA_PUB_DECODE 117
298#define DSA_F_DSA_PUB_ENCODE 118
299#define DSA_F_DSA_SIGN 106
300#define DSA_F_DSA_SIGN_SETUP 107
301#define DSA_F_DSA_SIG_NEW 109
302#define DSA_F_DSA_SIG_PRINT 125
303#define DSA_F_DSA_VERIFY 108
304#define DSA_F_I2D_DSA_SIG 111
305#define DSA_F_OLD_DSA_PRIV_DECODE 122
306#define DSA_F_PKEY_DSA_CTRL 120
307#define DSA_F_PKEY_DSA_KEYGEN 121
308#define DSA_F_SIG_CB 114
309
310/* Reason codes. */
311#define DSA_R_BAD_Q_VALUE 102
312#define DSA_R_BN_DECODE_ERROR 108
313#define DSA_R_BN_ERROR 109
314#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
315#define DSA_R_DECODE_ERROR 104
316#define DSA_R_INVALID_DIGEST_TYPE 106
317#define DSA_R_MISSING_PARAMETERS 101
318#define DSA_R_MODULUS_TOO_LARGE 103
319#define DSA_R_NEED_NEW_SETUP_VALUES 110
320#define DSA_R_NON_FIPS_DSA_METHOD 111
321#define DSA_R_NO_PARAMETERS_SET 107
322#define DSA_R_PARAMETER_ENCODING_ERROR 105
323
324#ifdef __cplusplus
325}
326#endif
327#endif
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c
deleted file mode 100644
index 376156ec5e..0000000000
--- a/src/lib/libcrypto/dsa/dsa_ameth.c
+++ /dev/null
@@ -1,704 +0,0 @@
1/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
2 * project 2006.
3 */
4/* ====================================================================
5 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <stdio.h>
59#include "cryptlib.h"
60#include <openssl/x509.h>
61#include <openssl/asn1.h>
62#include <openssl/dsa.h>
63#include <openssl/bn.h>
64#ifndef OPENSSL_NO_CMS
65#include <openssl/cms.h>
66#endif
67#include "asn1_locl.h"
68
69static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
70 {
71 const unsigned char *p, *pm;
72 int pklen, pmlen;
73 int ptype;
74 void *pval;
75 ASN1_STRING *pstr;
76 X509_ALGOR *palg;
77 ASN1_INTEGER *public_key = NULL;
78
79 DSA *dsa = NULL;
80
81 if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
82 return 0;
83 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
84
85
86 if (ptype == V_ASN1_SEQUENCE)
87 {
88 pstr = pval;
89 pm = pstr->data;
90 pmlen = pstr->length;
91
92 if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen)))
93 {
94 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
95 goto err;
96 }
97
98 }
99 else if ((ptype == V_ASN1_NULL) || (ptype == V_ASN1_UNDEF))
100 {
101 if (!(dsa = DSA_new()))
102 {
103 DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE);
104 goto err;
105 }
106 }
107 else
108 {
109 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_PARAMETER_ENCODING_ERROR);
110 goto err;
111 }
112
113 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen)))
114 {
115 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
116 goto err;
117 }
118
119 if (!(dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL)))
120 {
121 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR);
122 goto err;
123 }
124
125 ASN1_INTEGER_free(public_key);
126 EVP_PKEY_assign_DSA(pkey, dsa);
127 return 1;
128
129 err:
130 if (public_key)
131 ASN1_INTEGER_free(public_key);
132 if (dsa)
133 DSA_free(dsa);
134 return 0;
135
136 }
137
138static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
139 {
140 DSA *dsa;
141 void *pval = NULL;
142 int ptype;
143 unsigned char *penc = NULL;
144 int penclen;
145
146 dsa=pkey->pkey.dsa;
147 if (pkey->save_parameters && dsa->p && dsa->q && dsa->g)
148 {
149 ASN1_STRING *str;
150 str = ASN1_STRING_new();
151 str->length = i2d_DSAparams(dsa, &str->data);
152 if (str->length <= 0)
153 {
154 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
155 goto err;
156 }
157 pval = str;
158 ptype = V_ASN1_SEQUENCE;
159 }
160 else
161 ptype = V_ASN1_UNDEF;
162
163 dsa->write_params=0;
164
165 penclen = i2d_DSAPublicKey(dsa, &penc);
166
167 if (penclen <= 0)
168 {
169 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
170 goto err;
171 }
172
173 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA),
174 ptype, pval, penc, penclen))
175 return 1;
176
177 err:
178 if (penc)
179 OPENSSL_free(penc);
180 if (pval)
181 ASN1_STRING_free(pval);
182
183 return 0;
184 }
185
186/* In PKCS#8 DSA: you just get a private key integer and parameters in the
187 * AlgorithmIdentifier the pubkey must be recalculated.
188 */
189
190static int dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
191 {
192 const unsigned char *p, *pm;
193 int pklen, pmlen;
194 int ptype;
195 void *pval;
196 ASN1_STRING *pstr;
197 X509_ALGOR *palg;
198 ASN1_INTEGER *privkey = NULL;
199 BN_CTX *ctx = NULL;
200
201 STACK_OF(ASN1_TYPE) *ndsa = NULL;
202 DSA *dsa = NULL;
203
204 if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))
205 return 0;
206 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
207
208 /* Check for broken DSA PKCS#8, UGH! */
209 if (*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))
210 {
211 ASN1_TYPE *t1, *t2;
212 if(!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen)))
213 goto decerr;
214 if (sk_ASN1_TYPE_num(ndsa) != 2)
215 goto decerr;
216 /* Handle Two broken types:
217 * SEQUENCE {parameters, priv_key}
218 * SEQUENCE {pub_key, priv_key}
219 */
220
221 t1 = sk_ASN1_TYPE_value(ndsa, 0);
222 t2 = sk_ASN1_TYPE_value(ndsa, 1);
223 if (t1->type == V_ASN1_SEQUENCE)
224 {
225 p8->broken = PKCS8_EMBEDDED_PARAM;
226 pval = t1->value.ptr;
227 }
228 else if (ptype == V_ASN1_SEQUENCE)
229 p8->broken = PKCS8_NS_DB;
230 else
231 goto decerr;
232
233 if (t2->type != V_ASN1_INTEGER)
234 goto decerr;
235
236 privkey = t2->value.integer;
237 }
238 else
239 {
240 const unsigned char *q = p;
241 if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen)))
242 goto decerr;
243 if (privkey->type == V_ASN1_NEG_INTEGER)
244 {
245 p8->broken = PKCS8_NEG_PRIVKEY;
246 ASN1_INTEGER_free(privkey);
247 if (!(privkey=d2i_ASN1_UINTEGER(NULL, &q, pklen)))
248 goto decerr;
249 }
250 if (ptype != V_ASN1_SEQUENCE)
251 goto decerr;
252 }
253
254 pstr = pval;
255 pm = pstr->data;
256 pmlen = pstr->length;
257 if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen)))
258 goto decerr;
259 /* We have parameters now set private key */
260 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL)))
261 {
262 DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);
263 goto dsaerr;
264 }
265 /* Calculate public key */
266 if (!(dsa->pub_key = BN_new()))
267 {
268 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
269 goto dsaerr;
270 }
271 if (!(ctx = BN_CTX_new()))
272 {
273 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
274 goto dsaerr;
275 }
276
277 if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx))
278 {
279 DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);
280 goto dsaerr;
281 }
282
283 EVP_PKEY_assign_DSA(pkey, dsa);
284 BN_CTX_free (ctx);
285 if(ndsa)
286 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
287 else
288 ASN1_INTEGER_free(privkey);
289
290 return 1;
291
292 decerr:
293 DSAerr(DSA_F_DSA_PRIV_DECODE, EVP_R_DECODE_ERROR);
294 dsaerr:
295 BN_CTX_free (ctx);
296 if (privkey)
297 ASN1_INTEGER_free(privkey);
298 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
299 DSA_free(dsa);
300 return 0;
301 }
302
303static int dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
304{
305 ASN1_STRING *params = NULL;
306 ASN1_INTEGER *prkey = NULL;
307 unsigned char *dp = NULL;
308 int dplen;
309
310 params = ASN1_STRING_new();
311
312 if (!params)
313 {
314 DSAerr(DSA_F_DSA_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
315 goto err;
316 }
317
318 params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data);
319 if (params->length <= 0)
320 {
321 DSAerr(DSA_F_DSA_PRIV_ENCODE,ERR_R_MALLOC_FAILURE);
322 goto err;
323 }
324 params->type = V_ASN1_SEQUENCE;
325
326 /* Get private key into integer */
327 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL);
328
329 if (!prkey)
330 {
331 DSAerr(DSA_F_DSA_PRIV_ENCODE,DSA_R_BN_ERROR);
332 goto err;
333 }
334
335 dplen = i2d_ASN1_INTEGER(prkey, &dp);
336
337 ASN1_INTEGER_free(prkey);
338
339 if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_dsa), 0,
340 V_ASN1_SEQUENCE, params, dp, dplen))
341 goto err;
342
343 return 1;
344
345err:
346 if (dp != NULL)
347 OPENSSL_free(dp);
348 if (params != NULL)
349 ASN1_STRING_free(params);
350 if (prkey != NULL)
351 ASN1_INTEGER_free(prkey);
352 return 0;
353}
354
355static int int_dsa_size(const EVP_PKEY *pkey)
356 {
357 return(DSA_size(pkey->pkey.dsa));
358 }
359
360static int dsa_bits(const EVP_PKEY *pkey)
361 {
362 return BN_num_bits(pkey->pkey.dsa->p);
363 }
364
365static int dsa_missing_parameters(const EVP_PKEY *pkey)
366 {
367 DSA *dsa;
368 dsa=pkey->pkey.dsa;
369 if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL))
370 return 1;
371 return 0;
372 }
373
374static int dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
375 {
376 BIGNUM *a;
377
378 if ((a=BN_dup(from->pkey.dsa->p)) == NULL)
379 return 0;
380 if (to->pkey.dsa->p != NULL)
381 BN_free(to->pkey.dsa->p);
382 to->pkey.dsa->p=a;
383
384 if ((a=BN_dup(from->pkey.dsa->q)) == NULL)
385 return 0;
386 if (to->pkey.dsa->q != NULL)
387 BN_free(to->pkey.dsa->q);
388 to->pkey.dsa->q=a;
389
390 if ((a=BN_dup(from->pkey.dsa->g)) == NULL)
391 return 0;
392 if (to->pkey.dsa->g != NULL)
393 BN_free(to->pkey.dsa->g);
394 to->pkey.dsa->g=a;
395 return 1;
396 }
397
398static int dsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
399 {
400 if ( BN_cmp(a->pkey.dsa->p,b->pkey.dsa->p) ||
401 BN_cmp(a->pkey.dsa->q,b->pkey.dsa->q) ||
402 BN_cmp(a->pkey.dsa->g,b->pkey.dsa->g))
403 return 0;
404 else
405 return 1;
406 }
407
408static int dsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
409 {
410 if (BN_cmp(b->pkey.dsa->pub_key,a->pkey.dsa->pub_key) != 0)
411 return 0;
412 else
413 return 1;
414 }
415
416static void int_dsa_free(EVP_PKEY *pkey)
417 {
418 DSA_free(pkey->pkey.dsa);
419 }
420
421static void update_buflen(const BIGNUM *b, size_t *pbuflen)
422 {
423 size_t i;
424 if (!b)
425 return;
426 if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
427 *pbuflen = i;
428 }
429
430static int do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
431 {
432 unsigned char *m=NULL;
433 int ret=0;
434 size_t buf_len=0;
435 const char *ktype = NULL;
436
437 const BIGNUM *priv_key, *pub_key;
438
439 if (ptype == 2)
440 priv_key = x->priv_key;
441 else
442 priv_key = NULL;
443
444 if (ptype > 0)
445 pub_key = x->pub_key;
446 else
447 pub_key = NULL;
448
449 if (ptype == 2)
450 ktype = "Private-Key";
451 else if (ptype == 1)
452 ktype = "Public-Key";
453 else
454 ktype = "DSA-Parameters";
455
456 update_buflen(x->p, &buf_len);
457 update_buflen(x->q, &buf_len);
458 update_buflen(x->g, &buf_len);
459 update_buflen(priv_key, &buf_len);
460 update_buflen(pub_key, &buf_len);
461
462 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
463 if (m == NULL)
464 {
465 DSAerr(DSA_F_DO_DSA_PRINT,ERR_R_MALLOC_FAILURE);
466 goto err;
467 }
468
469 if (priv_key)
470 {
471 if(!BIO_indent(bp,off,128))
472 goto err;
473 if (BIO_printf(bp,"%s: (%d bit)\n",ktype, BN_num_bits(x->p))
474 <= 0) goto err;
475 }
476
477 if (!ASN1_bn_print(bp,"priv:",priv_key,m,off))
478 goto err;
479 if (!ASN1_bn_print(bp,"pub: ",pub_key,m,off))
480 goto err;
481 if (!ASN1_bn_print(bp,"P: ",x->p,m,off)) goto err;
482 if (!ASN1_bn_print(bp,"Q: ",x->q,m,off)) goto err;
483 if (!ASN1_bn_print(bp,"G: ",x->g,m,off)) goto err;
484 ret=1;
485err:
486 if (m != NULL) OPENSSL_free(m);
487 return(ret);
488 }
489
490static int dsa_param_decode(EVP_PKEY *pkey,
491 const unsigned char **pder, int derlen)
492 {
493 DSA *dsa;
494 if (!(dsa = d2i_DSAparams(NULL, pder, derlen)))
495 {
496 DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB);
497 return 0;
498 }
499 EVP_PKEY_assign_DSA(pkey, dsa);
500 return 1;
501 }
502
503static int dsa_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
504 {
505 return i2d_DSAparams(pkey->pkey.dsa, pder);
506 }
507
508static int dsa_param_print(BIO *bp, const EVP_PKEY *pkey, int indent,
509 ASN1_PCTX *ctx)
510 {
511 return do_dsa_print(bp, pkey->pkey.dsa, indent, 0);
512 }
513
514static int dsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent,
515 ASN1_PCTX *ctx)
516 {
517 return do_dsa_print(bp, pkey->pkey.dsa, indent, 1);
518 }
519
520
521static int dsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent,
522 ASN1_PCTX *ctx)
523 {
524 return do_dsa_print(bp, pkey->pkey.dsa, indent, 2);
525 }
526
527static int old_dsa_priv_decode(EVP_PKEY *pkey,
528 const unsigned char **pder, int derlen)
529 {
530 DSA *dsa;
531 if (!(dsa = d2i_DSAPrivateKey (NULL, pder, derlen)))
532 {
533 DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB);
534 return 0;
535 }
536 EVP_PKEY_assign_DSA(pkey, dsa);
537 return 1;
538 }
539
540static int old_dsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
541 {
542 return i2d_DSAPrivateKey(pkey->pkey.dsa, pder);
543 }
544
545static int dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg,
546 const ASN1_STRING *sig,
547 int indent, ASN1_PCTX *pctx)
548 {
549 DSA_SIG *dsa_sig;
550 const unsigned char *p;
551 if (!sig)
552 {
553 if (BIO_puts(bp, "\n") <= 0)
554 return 0;
555 else
556 return 1;
557 }
558 p = sig->data;
559 dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);
560 if (dsa_sig)
561 {
562 int rv = 0;
563 size_t buf_len = 0;
564 unsigned char *m=NULL;
565 update_buflen(dsa_sig->r, &buf_len);
566 update_buflen(dsa_sig->s, &buf_len);
567 m = OPENSSL_malloc(buf_len+10);
568 if (m == NULL)
569 {
570 DSAerr(DSA_F_DSA_SIG_PRINT,ERR_R_MALLOC_FAILURE);
571 goto err;
572 }
573
574 if (BIO_write(bp, "\n", 1) != 1)
575 goto err;
576
577 if (!ASN1_bn_print(bp,"r: ",dsa_sig->r,m,indent))
578 goto err;
579 if (!ASN1_bn_print(bp,"s: ",dsa_sig->s,m,indent))
580 goto err;
581 rv = 1;
582 err:
583 if (m)
584 OPENSSL_free(m);
585 DSA_SIG_free(dsa_sig);
586 return rv;
587 }
588 return X509_signature_dump(bp, sig, indent);
589 }
590
591static int dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
592 {
593 switch (op)
594 {
595 case ASN1_PKEY_CTRL_PKCS7_SIGN:
596 if (arg1 == 0)
597 {
598 int snid, hnid;
599 X509_ALGOR *alg1, *alg2;
600 PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);
601 if (alg1 == NULL || alg1->algorithm == NULL)
602 return -1;
603 hnid = OBJ_obj2nid(alg1->algorithm);
604 if (hnid == NID_undef)
605 return -1;
606 if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
607 return -1;
608 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
609 }
610 return 1;
611#ifndef OPENSSL_NO_CMS
612 case ASN1_PKEY_CTRL_CMS_SIGN:
613 if (arg1 == 0)
614 {
615 int snid, hnid;
616 X509_ALGOR *alg1, *alg2;
617 CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2);
618 if (alg1 == NULL || alg1->algorithm == NULL)
619 return -1;
620 hnid = OBJ_obj2nid(alg1->algorithm);
621 if (hnid == NID_undef)
622 return -1;
623 if (!OBJ_find_sigid_by_algs(&snid, hnid, EVP_PKEY_id(pkey)))
624 return -1;
625 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, 0);
626 }
627 return 1;
628#endif
629
630 case ASN1_PKEY_CTRL_DEFAULT_MD_NID:
631 *(int *)arg2 = NID_sha1;
632 return 2;
633
634 default:
635 return -2;
636
637 }
638
639 }
640
641/* NB these are sorted in pkey_id order, lowest first */
642
643const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] =
644 {
645
646 {
647 EVP_PKEY_DSA2,
648 EVP_PKEY_DSA,
649 ASN1_PKEY_ALIAS
650 },
651
652 {
653 EVP_PKEY_DSA1,
654 EVP_PKEY_DSA,
655 ASN1_PKEY_ALIAS
656 },
657
658 {
659 EVP_PKEY_DSA4,
660 EVP_PKEY_DSA,
661 ASN1_PKEY_ALIAS
662 },
663
664 {
665 EVP_PKEY_DSA3,
666 EVP_PKEY_DSA,
667 ASN1_PKEY_ALIAS
668 },
669
670 {
671 EVP_PKEY_DSA,
672 EVP_PKEY_DSA,
673 0,
674
675 "DSA",
676 "OpenSSL DSA method",
677
678 dsa_pub_decode,
679 dsa_pub_encode,
680 dsa_pub_cmp,
681 dsa_pub_print,
682
683 dsa_priv_decode,
684 dsa_priv_encode,
685 dsa_priv_print,
686
687 int_dsa_size,
688 dsa_bits,
689
690 dsa_param_decode,
691 dsa_param_encode,
692 dsa_missing_parameters,
693 dsa_copy_parameters,
694 dsa_cmp_parameters,
695 dsa_param_print,
696 dsa_sig_print,
697
698 int_dsa_free,
699 dsa_pkey_ctrl,
700 old_dsa_priv_decode,
701 old_dsa_priv_encode
702 }
703 };
704
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
deleted file mode 100644
index 6058534374..0000000000
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ /dev/null
@@ -1,188 +0,0 @@
1/* dsa_asn1.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2005 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#include <openssl/rand.h>
65
66/* Override the default new methods */
67static int sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
68 void *exarg)
69{
70 if(operation == ASN1_OP_NEW_PRE) {
71 DSA_SIG *sig;
72 sig = OPENSSL_malloc(sizeof(DSA_SIG));
73 if (!sig)
74 {
75 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
76 return 0;
77 }
78 sig->r = NULL;
79 sig->s = NULL;
80 *pval = (ASN1_VALUE *)sig;
81 return 2;
82 }
83 return 1;
84}
85
86ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = {
87 ASN1_SIMPLE(DSA_SIG, r, CBIGNUM),
88 ASN1_SIMPLE(DSA_SIG, s, CBIGNUM)
89} ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG)
90
91IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA_SIG, DSA_SIG, DSA_SIG)
92
93/* Override the default free and new methods */
94static int dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it,
95 void *exarg)
96{
97 if(operation == ASN1_OP_NEW_PRE) {
98 *pval = (ASN1_VALUE *)DSA_new();
99 if(*pval) return 2;
100 return 0;
101 } else if(operation == ASN1_OP_FREE_PRE) {
102 DSA_free((DSA *)*pval);
103 *pval = NULL;
104 return 2;
105 }
106 return 1;
107}
108
109ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = {
110 ASN1_SIMPLE(DSA, version, LONG),
111 ASN1_SIMPLE(DSA, p, BIGNUM),
112 ASN1_SIMPLE(DSA, q, BIGNUM),
113 ASN1_SIMPLE(DSA, g, BIGNUM),
114 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
115 ASN1_SIMPLE(DSA, priv_key, BIGNUM)
116} ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey)
117
118IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPrivateKey, DSAPrivateKey)
119
120ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = {
121 ASN1_SIMPLE(DSA, p, BIGNUM),
122 ASN1_SIMPLE(DSA, q, BIGNUM),
123 ASN1_SIMPLE(DSA, g, BIGNUM),
124} ASN1_SEQUENCE_END_cb(DSA, DSAparams)
125
126IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams)
127
128/* DSA public key is a bit trickier... its effectively a CHOICE type
129 * decided by a field called write_params which can either write out
130 * just the public key as an INTEGER or the parameters and public key
131 * in a SEQUENCE
132 */
133
134ASN1_SEQUENCE(dsa_pub_internal) = {
135 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
136 ASN1_SIMPLE(DSA, p, BIGNUM),
137 ASN1_SIMPLE(DSA, q, BIGNUM),
138 ASN1_SIMPLE(DSA, g, BIGNUM)
139} ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal)
140
141ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
142 ASN1_SIMPLE(DSA, pub_key, BIGNUM),
143 ASN1_EX_COMBINE(0, 0, dsa_pub_internal)
144} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)
145
146IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
147
148DSA *DSAparams_dup(DSA *dsa)
149 {
150 return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa);
151 }
152
153int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
154 unsigned int *siglen, DSA *dsa)
155 {
156 DSA_SIG *s;
157 RAND_seed(dgst, dlen);
158 s=DSA_do_sign(dgst,dlen,dsa);
159 if (s == NULL)
160 {
161 *siglen=0;
162 return(0);
163 }
164 *siglen=i2d_DSA_SIG(s,&sig);
165 DSA_SIG_free(s);
166 return(1);
167 }
168
169/* data has already been hashed (probably with SHA or SHA-1). */
170/* returns
171 * 1: correct signature
172 * 0: incorrect signature
173 * -1: error
174 */
175int DSA_verify(int type, const unsigned char *dgst, int dgst_len,
176 const unsigned char *sigbuf, int siglen, DSA *dsa)
177 {
178 DSA_SIG *s;
179 int ret=-1;
180
181 s = DSA_SIG_new();
182 if (s == NULL) return(ret);
183 if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err;
184 ret=DSA_do_verify(dgst,dgst_len,s,dsa);
185err:
186 DSA_SIG_free(s);
187 return(ret);
188 }
diff --git a/src/lib/libcrypto/dsa/dsa_depr.c b/src/lib/libcrypto/dsa/dsa_depr.c
deleted file mode 100644
index f2da680eb4..0000000000
--- a/src/lib/libcrypto/dsa/dsa_depr.c
+++ /dev/null
@@ -1,106 +0,0 @@
1/* crypto/dsa/dsa_depr.c */
2/* ====================================================================
3 * Copyright (c) 1998-2002 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/* This file contains deprecated function(s) that are now wrappers to the new
57 * version(s). */
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
72static void *dummy=&dummy;
73
74#ifndef OPENSSL_NO_SHA
75
76#include <stdio.h>
77#include <time.h>
78#include "cryptlib.h"
79#include <openssl/evp.h>
80#include <openssl/bn.h>
81#include <openssl/dsa.h>
82#include <openssl/rand.h>
83#include <openssl/sha.h>
84
85#ifndef OPENSSL_NO_DEPRECATED
86DSA *DSA_generate_parameters(int bits,
87 unsigned char *seed_in, int seed_len,
88 int *counter_ret, unsigned long *h_ret,
89 void (*callback)(int, int, void *),
90 void *cb_arg)
91 {
92 BN_GENCB cb;
93 DSA *ret;
94
95 if ((ret=DSA_new()) == NULL) return NULL;
96
97 BN_GENCB_set_old(&cb, callback, cb_arg);
98
99 if(DSA_generate_parameters_ex(ret, bits, seed_in, seed_len,
100 counter_ret, h_ret, &cb))
101 return ret;
102 DSA_free(ret);
103 return NULL;
104 }
105#endif
106#endif
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
deleted file mode 100644
index 00545b7b9f..0000000000
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ /dev/null
@@ -1,130 +0,0 @@
1/* crypto/dsa/dsa_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * 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_DO_DSA_PRINT), "DO_DSA_PRINT"},
75{ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"},
76{ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"},
77{ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"},
78{ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"},
79{ERR_FUNC(DSA_F_DSA_GENERATE_KEY), "DSA_generate_key"},
80{ERR_FUNC(DSA_F_DSA_GENERATE_PARAMETERS_EX), "DSA_generate_parameters_ex"},
81{ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"},
82{ERR_FUNC(DSA_F_DSA_PARAM_DECODE), "DSA_PARAM_DECODE"},
83{ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"},
84{ERR_FUNC(DSA_F_DSA_PRIV_DECODE), "DSA_PRIV_DECODE"},
85{ERR_FUNC(DSA_F_DSA_PRIV_ENCODE), "DSA_PRIV_ENCODE"},
86{ERR_FUNC(DSA_F_DSA_PUB_DECODE), "DSA_PUB_DECODE"},
87{ERR_FUNC(DSA_F_DSA_PUB_ENCODE), "DSA_PUB_ENCODE"},
88{ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"},
89{ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"},
90{ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"},
91{ERR_FUNC(DSA_F_DSA_SIG_PRINT), "DSA_SIG_PRINT"},
92{ERR_FUNC(DSA_F_DSA_VERIFY), "DSA_verify"},
93{ERR_FUNC(DSA_F_I2D_DSA_SIG), "i2d_DSA_SIG"},
94{ERR_FUNC(DSA_F_OLD_DSA_PRIV_DECODE), "OLD_DSA_PRIV_DECODE"},
95{ERR_FUNC(DSA_F_PKEY_DSA_CTRL), "PKEY_DSA_CTRL"},
96{ERR_FUNC(DSA_F_PKEY_DSA_KEYGEN), "PKEY_DSA_KEYGEN"},
97{ERR_FUNC(DSA_F_SIG_CB), "SIG_CB"},
98{0,NULL}
99 };
100
101static ERR_STRING_DATA DSA_str_reasons[]=
102 {
103{ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"},
104{ERR_REASON(DSA_R_BN_DECODE_ERROR) ,"bn decode error"},
105{ERR_REASON(DSA_R_BN_ERROR) ,"bn error"},
106{ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"},
107{ERR_REASON(DSA_R_DECODE_ERROR) ,"decode error"},
108{ERR_REASON(DSA_R_INVALID_DIGEST_TYPE) ,"invalid digest type"},
109{ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"},
110{ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
111{ERR_REASON(DSA_R_NEED_NEW_SETUP_VALUES) ,"need new setup values"},
112{ERR_REASON(DSA_R_NON_FIPS_DSA_METHOD) ,"non fips dsa method"},
113{ERR_REASON(DSA_R_NO_PARAMETERS_SET) ,"no parameters set"},
114{ERR_REASON(DSA_R_PARAMETER_ENCODING_ERROR),"parameter encoding error"},
115{0,NULL}
116 };
117
118#endif
119
120void ERR_load_DSA_strings(void)
121 {
122#ifndef OPENSSL_NO_ERR
123
124 if (ERR_func_error_string(DSA_str_functs[0].error) == NULL)
125 {
126 ERR_load_strings(0,DSA_str_functs);
127 ERR_load_strings(0,DSA_str_reasons);
128 }
129#endif
130 }
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
deleted file mode 100644
index c398761d0d..0000000000
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ /dev/null
@@ -1,371 +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#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_SHA is defined */
73
74#ifndef OPENSSL_NO_SHA
75
76#include <stdio.h>
77#include "cryptlib.h"
78#include <openssl/evp.h>
79#include <openssl/bn.h>
80#include <openssl/rand.h>
81#include <openssl/sha.h>
82#include "dsa_locl.h"
83
84#ifdef OPENSSL_FIPS
85#include <openssl/fips.h>
86#endif
87
88int DSA_generate_parameters_ex(DSA *ret, int bits,
89 const unsigned char *seed_in, int seed_len,
90 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
91 {
92#ifdef OPENSSL_FIPS
93 if (FIPS_mode() && !(ret->meth->flags & DSA_FLAG_FIPS_METHOD)
94 && !(ret->flags & DSA_FLAG_NON_FIPS_ALLOW))
95 {
96 DSAerr(DSA_F_DSA_GENERATE_PARAMETERS_EX, DSA_R_NON_FIPS_DSA_METHOD);
97 return 0;
98 }
99#endif
100 if(ret->meth->dsa_paramgen)
101 return ret->meth->dsa_paramgen(ret, bits, seed_in, seed_len,
102 counter_ret, h_ret, cb);
103#ifdef OPENSSL_FIPS
104 else if (FIPS_mode())
105 {
106 return FIPS_dsa_generate_parameters_ex(ret, bits,
107 seed_in, seed_len,
108 counter_ret, h_ret, cb);
109 }
110#endif
111 else
112 {
113 const EVP_MD *evpmd;
114 size_t qbits = bits >= 2048 ? 256 : 160;
115
116 if (bits >= 2048)
117 {
118 qbits = 256;
119 evpmd = EVP_sha256();
120 }
121 else
122 {
123 qbits = 160;
124 evpmd = EVP_sha1();
125 }
126
127 return dsa_builtin_paramgen(ret, bits, qbits, evpmd,
128 seed_in, seed_len, NULL, counter_ret, h_ret, cb);
129 }
130 }
131
132int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
133 const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
134 unsigned char *seed_out,
135 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
136 {
137 int ok=0;
138 unsigned char seed[SHA256_DIGEST_LENGTH];
139 unsigned char md[SHA256_DIGEST_LENGTH];
140 unsigned char buf[SHA256_DIGEST_LENGTH],buf2[SHA256_DIGEST_LENGTH];
141 BIGNUM *r0,*W,*X,*c,*test;
142 BIGNUM *g=NULL,*q=NULL,*p=NULL;
143 BN_MONT_CTX *mont=NULL;
144 int i, k, n=0, m=0, qsize = qbits >> 3;
145 int counter=0;
146 int r=0;
147 BN_CTX *ctx=NULL;
148 unsigned int h=2;
149
150 if (qsize != SHA_DIGEST_LENGTH && qsize != SHA224_DIGEST_LENGTH &&
151 qsize != SHA256_DIGEST_LENGTH)
152 /* invalid q size */
153 return 0;
154
155 if (evpmd == NULL)
156 /* use SHA1 as default */
157 evpmd = EVP_sha1();
158
159 if (bits < 512)
160 bits = 512;
161
162 bits = (bits+63)/64*64;
163
164 /* NB: seed_len == 0 is special case: copy generated seed to
165 * seed_in if it is not NULL.
166 */
167 if (seed_len && (seed_len < (size_t)qsize))
168 seed_in = NULL; /* seed buffer too small -- ignore */
169 if (seed_len > (size_t)qsize)
170 seed_len = qsize; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
171 * but our internal buffers are restricted to 160 bits*/
172 if (seed_in != NULL)
173 memcpy(seed, seed_in, seed_len);
174
175 if ((ctx=BN_CTX_new()) == NULL)
176 goto err;
177
178 if ((mont=BN_MONT_CTX_new()) == NULL)
179 goto err;
180
181 BN_CTX_start(ctx);
182 r0 = BN_CTX_get(ctx);
183 g = BN_CTX_get(ctx);
184 W = BN_CTX_get(ctx);
185 q = BN_CTX_get(ctx);
186 X = BN_CTX_get(ctx);
187 c = BN_CTX_get(ctx);
188 p = BN_CTX_get(ctx);
189 test = BN_CTX_get(ctx);
190
191 if (!BN_lshift(test,BN_value_one(),bits-1))
192 goto err;
193
194 for (;;)
195 {
196 for (;;) /* find q */
197 {
198 int seed_is_random;
199
200 /* step 1 */
201 if(!BN_GENCB_call(cb, 0, m++))
202 goto err;
203
204 if (!seed_len)
205 {
206 RAND_pseudo_bytes(seed, qsize);
207 seed_is_random = 1;
208 }
209 else
210 {
211 seed_is_random = 0;
212 seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/
213 }
214 memcpy(buf , seed, qsize);
215 memcpy(buf2, seed, qsize);
216 /* precompute "SEED + 1" for step 7: */
217 for (i = qsize-1; i >= 0; i--)
218 {
219 buf[i]++;
220 if (buf[i] != 0)
221 break;
222 }
223
224 /* step 2 */
225 if (!EVP_Digest(seed, qsize, md, NULL, evpmd, NULL))
226 goto err;
227 if (!EVP_Digest(buf, qsize, buf2, NULL, evpmd, NULL))
228 goto err;
229 for (i = 0; i < qsize; i++)
230 md[i]^=buf2[i];
231
232 /* step 3 */
233 md[0] |= 0x80;
234 md[qsize-1] |= 0x01;
235 if (!BN_bin2bn(md, qsize, q))
236 goto err;
237
238 /* step 4 */
239 r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,
240 seed_is_random, cb);
241 if (r > 0)
242 break;
243 if (r != 0)
244 goto err;
245
246 /* do a callback call */
247 /* step 5 */
248 }
249
250 if(!BN_GENCB_call(cb, 2, 0)) goto err;
251 if(!BN_GENCB_call(cb, 3, 0)) goto err;
252
253 /* step 6 */
254 counter=0;
255 /* "offset = 2" */
256
257 n=(bits-1)/160;
258
259 for (;;)
260 {
261 if ((counter != 0) && !BN_GENCB_call(cb, 0, counter))
262 goto err;
263
264 /* step 7 */
265 BN_zero(W);
266 /* now 'buf' contains "SEED + offset - 1" */
267 for (k=0; k<=n; k++)
268 {
269 /* obtain "SEED + offset + k" by incrementing: */
270 for (i = qsize-1; i >= 0; i--)
271 {
272 buf[i]++;
273 if (buf[i] != 0)
274 break;
275 }
276
277 if (!EVP_Digest(buf, qsize, md ,NULL, evpmd,
278 NULL))
279 goto err;
280
281 /* step 8 */
282 if (!BN_bin2bn(md, qsize, r0))
283 goto err;
284 if (!BN_lshift(r0,r0,(qsize << 3)*k)) goto err;
285 if (!BN_add(W,W,r0)) goto err;
286 }
287
288 /* more of step 8 */
289 if (!BN_mask_bits(W,bits-1)) goto err;
290 if (!BN_copy(X,W)) goto err;
291 if (!BN_add(X,X,test)) goto err;
292
293 /* step 9 */
294 if (!BN_lshift1(r0,q)) goto err;
295 if (!BN_mod(c,X,r0,ctx)) goto err;
296 if (!BN_sub(r0,c,BN_value_one())) goto err;
297 if (!BN_sub(p,X,r0)) goto err;
298
299 /* step 10 */
300 if (BN_cmp(p,test) >= 0)
301 {
302 /* step 11 */
303 r = BN_is_prime_fasttest_ex(p, DSS_prime_checks,
304 ctx, 1, cb);
305 if (r > 0)
306 goto end; /* found it */
307 if (r != 0)
308 goto err;
309 }
310
311 /* step 13 */
312 counter++;
313 /* "offset = offset + n + 1" */
314
315 /* step 14 */
316 if (counter >= 4096) break;
317 }
318 }
319end:
320 if(!BN_GENCB_call(cb, 2, 1))
321 goto err;
322
323 /* We now need to generate g */
324 /* Set r0=(p-1)/q */
325 if (!BN_sub(test,p,BN_value_one())) goto err;
326 if (!BN_div(r0,NULL,test,q,ctx)) goto err;
327
328 if (!BN_set_word(test,h)) goto err;
329 if (!BN_MONT_CTX_set(mont,p,ctx)) goto err;
330
331 for (;;)
332 {
333 /* g=test^r0%p */
334 if (!BN_mod_exp_mont(g,test,r0,p,ctx,mont)) goto err;
335 if (!BN_is_one(g)) break;
336 if (!BN_add(test,test,BN_value_one())) goto err;
337 h++;
338 }
339
340 if(!BN_GENCB_call(cb, 3, 1))
341 goto err;
342
343 ok=1;
344err:
345 if (ok)
346 {
347 if(ret->p) BN_free(ret->p);
348 if(ret->q) BN_free(ret->q);
349 if(ret->g) BN_free(ret->g);
350 ret->p=BN_dup(p);
351 ret->q=BN_dup(q);
352 ret->g=BN_dup(g);
353 if (ret->p == NULL || ret->q == NULL || ret->g == NULL)
354 {
355 ok=0;
356 goto err;
357 }
358 if (counter_ret != NULL) *counter_ret=counter;
359 if (h_ret != NULL) *h_ret=h;
360 if (seed_out)
361 memcpy(seed_out, seed, qsize);
362 }
363 if(ctx)
364 {
365 BN_CTX_end(ctx);
366 BN_CTX_free(ctx);
367 }
368 if (mont != NULL) BN_MONT_CTX_free(mont);
369 return ok;
370 }
371#endif
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
deleted file mode 100644
index 9cf669b921..0000000000
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ /dev/null
@@ -1,144 +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#include <stdio.h>
60#include <time.h>
61#include "cryptlib.h"
62#ifndef OPENSSL_NO_SHA
63#include <openssl/bn.h>
64#include <openssl/dsa.h>
65#include <openssl/rand.h>
66
67#ifdef OPENSSL_FIPS
68#include <openssl/fips.h>
69#endif
70
71static int dsa_builtin_keygen(DSA *dsa);
72
73int DSA_generate_key(DSA *dsa)
74 {
75#ifdef OPENSSL_FIPS
76 if (FIPS_mode() && !(dsa->meth->flags & DSA_FLAG_FIPS_METHOD)
77 && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
78 {
79 DSAerr(DSA_F_DSA_GENERATE_KEY, DSA_R_NON_FIPS_DSA_METHOD);
80 return 0;
81 }
82#endif
83 if(dsa->meth->dsa_keygen)
84 return dsa->meth->dsa_keygen(dsa);
85#ifdef OPENSSL_FIPS
86 if (FIPS_mode())
87 return FIPS_dsa_generate_key(dsa);
88#endif
89 return dsa_builtin_keygen(dsa);
90 }
91
92static int dsa_builtin_keygen(DSA *dsa)
93 {
94 int ok=0;
95 BN_CTX *ctx=NULL;
96 BIGNUM *pub_key=NULL,*priv_key=NULL;
97
98 if ((ctx=BN_CTX_new()) == NULL) goto err;
99
100 if (dsa->priv_key == NULL)
101 {
102 if ((priv_key=BN_new()) == NULL) goto err;
103 }
104 else
105 priv_key=dsa->priv_key;
106
107 do
108 if (!BN_rand_range(priv_key,dsa->q)) goto err;
109 while (BN_is_zero(priv_key));
110
111 if (dsa->pub_key == NULL)
112 {
113 if ((pub_key=BN_new()) == NULL) goto err;
114 }
115 else
116 pub_key=dsa->pub_key;
117
118 {
119 BIGNUM local_prk;
120 BIGNUM *prk;
121
122 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
123 {
124 BN_init(&local_prk);
125 prk = &local_prk;
126 BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME);
127 }
128 else
129 prk = priv_key;
130
131 if (!BN_mod_exp(pub_key,dsa->g,prk,dsa->p,ctx)) goto err;
132 }
133
134 dsa->priv_key=priv_key;
135 dsa->pub_key=pub_key;
136 ok=1;
137
138err:
139 if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key);
140 if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key);
141 if (ctx != NULL) BN_CTX_free(ctx);
142 return(ok);
143 }
144#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
deleted file mode 100644
index 96d8d0c4b4..0000000000
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ /dev/null
@@ -1,329 +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#ifndef OPENSSL_NO_DH
70#include <openssl/dh.h>
71#endif
72
73#ifdef OPENSSL_FIPS
74#include <openssl/fips.h>
75#endif
76
77const char DSA_version[]="DSA" OPENSSL_VERSION_PTEXT;
78
79static const DSA_METHOD *default_DSA_method = NULL;
80
81void DSA_set_default_method(const DSA_METHOD *meth)
82 {
83 default_DSA_method = meth;
84 }
85
86const DSA_METHOD *DSA_get_default_method(void)
87 {
88 if(!default_DSA_method)
89 {
90#ifdef OPENSSL_FIPS
91 if (FIPS_mode())
92 return FIPS_dsa_openssl();
93 else
94 return DSA_OpenSSL();
95#else
96 default_DSA_method = DSA_OpenSSL();
97#endif
98 }
99 return default_DSA_method;
100 }
101
102DSA *DSA_new(void)
103 {
104 return DSA_new_method(NULL);
105 }
106
107int DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
108 {
109 /* NB: The caller is specifically setting a method, so it's not up to us
110 * to deal with which ENGINE it comes from. */
111 const DSA_METHOD *mtmp;
112 mtmp = dsa->meth;
113 if (mtmp->finish) mtmp->finish(dsa);
114#ifndef OPENSSL_NO_ENGINE
115 if (dsa->engine)
116 {
117 ENGINE_finish(dsa->engine);
118 dsa->engine = NULL;
119 }
120#endif
121 dsa->meth = meth;
122 if (meth->init) meth->init(dsa);
123 return 1;
124 }
125
126DSA *DSA_new_method(ENGINE *engine)
127 {
128 DSA *ret;
129
130 ret=(DSA *)OPENSSL_malloc(sizeof(DSA));
131 if (ret == NULL)
132 {
133 DSAerr(DSA_F_DSA_NEW_METHOD,ERR_R_MALLOC_FAILURE);
134 return(NULL);
135 }
136 ret->meth = DSA_get_default_method();
137#ifndef OPENSSL_NO_ENGINE
138 if (engine)
139 {
140 if (!ENGINE_init(engine))
141 {
142 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
143 OPENSSL_free(ret);
144 return NULL;
145 }
146 ret->engine = engine;
147 }
148 else
149 ret->engine = ENGINE_get_default_DSA();
150 if(ret->engine)
151 {
152 ret->meth = ENGINE_get_DSA(ret->engine);
153 if(!ret->meth)
154 {
155 DSAerr(DSA_F_DSA_NEW_METHOD,
156 ERR_R_ENGINE_LIB);
157 ENGINE_finish(ret->engine);
158 OPENSSL_free(ret);
159 return NULL;
160 }
161 }
162#endif
163
164 ret->pad=0;
165 ret->version=0;
166 ret->write_params=1;
167 ret->p=NULL;
168 ret->q=NULL;
169 ret->g=NULL;
170
171 ret->pub_key=NULL;
172 ret->priv_key=NULL;
173
174 ret->kinv=NULL;
175 ret->r=NULL;
176 ret->method_mont_p=NULL;
177
178 ret->references=1;
179 ret->flags=ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW;
180 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
181 if ((ret->meth->init != NULL) && !ret->meth->init(ret))
182 {
183#ifndef OPENSSL_NO_ENGINE
184 if (ret->engine)
185 ENGINE_finish(ret->engine);
186#endif
187 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
188 OPENSSL_free(ret);
189 ret=NULL;
190 }
191
192 return(ret);
193 }
194
195void DSA_free(DSA *r)
196 {
197 int i;
198
199 if (r == NULL) return;
200
201 i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA);
202#ifdef REF_PRINT
203 REF_PRINT("DSA",r);
204#endif
205 if (i > 0) return;
206#ifdef REF_CHECK
207 if (i < 0)
208 {
209 fprintf(stderr,"DSA_free, bad reference count\n");
210 abort();
211 }
212#endif
213
214 if(r->meth->finish)
215 r->meth->finish(r);
216#ifndef OPENSSL_NO_ENGINE
217 if(r->engine)
218 ENGINE_finish(r->engine);
219#endif
220
221 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
222
223 if (r->p != NULL) BN_clear_free(r->p);
224 if (r->q != NULL) BN_clear_free(r->q);
225 if (r->g != NULL) BN_clear_free(r->g);
226 if (r->pub_key != NULL) BN_clear_free(r->pub_key);
227 if (r->priv_key != NULL) BN_clear_free(r->priv_key);
228 if (r->kinv != NULL) BN_clear_free(r->kinv);
229 if (r->r != NULL) BN_clear_free(r->r);
230 OPENSSL_free(r);
231 }
232
233int DSA_up_ref(DSA *r)
234 {
235 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA);
236#ifdef REF_PRINT
237 REF_PRINT("DSA",r);
238#endif
239#ifdef REF_CHECK
240 if (i < 2)
241 {
242 fprintf(stderr, "DSA_up_ref, bad reference count\n");
243 abort();
244 }
245#endif
246 return ((i > 1) ? 1 : 0);
247 }
248
249int DSA_size(const DSA *r)
250 {
251 int ret,i;
252 ASN1_INTEGER bs;
253 unsigned char buf[4]; /* 4 bytes looks really small.
254 However, i2d_ASN1_INTEGER() will not look
255 beyond the first byte, as long as the second
256 parameter is NULL. */
257
258 i=BN_num_bits(r->q);
259 bs.length=(i+7)/8;
260 bs.data=buf;
261 bs.type=V_ASN1_INTEGER;
262 /* If the top bit is set the asn1 encoding is 1 larger. */
263 buf[0]=0xff;
264
265 i=i2d_ASN1_INTEGER(&bs,NULL);
266 i+=i; /* r and s */
267 ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
268 return(ret);
269 }
270
271int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
272 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
273 {
274 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, argl, argp,
275 new_func, dup_func, free_func);
276 }
277
278int DSA_set_ex_data(DSA *d, int idx, void *arg)
279 {
280 return(CRYPTO_set_ex_data(&d->ex_data,idx,arg));
281 }
282
283void *DSA_get_ex_data(DSA *d, int idx)
284 {
285 return(CRYPTO_get_ex_data(&d->ex_data,idx));
286 }
287
288#ifndef OPENSSL_NO_DH
289DH *DSA_dup_DH(const DSA *r)
290 {
291 /* DSA has p, q, g, optional pub_key, optional priv_key.
292 * DH has p, optional length, g, optional pub_key, optional priv_key,
293 * optional q.
294 */
295
296 DH *ret = NULL;
297
298 if (r == NULL)
299 goto err;
300 ret = DH_new();
301 if (ret == NULL)
302 goto err;
303 if (r->p != NULL)
304 if ((ret->p = BN_dup(r->p)) == NULL)
305 goto err;
306 if (r->q != NULL)
307 {
308 ret->length = BN_num_bits(r->q);
309 if ((ret->q = BN_dup(r->q)) == NULL)
310 goto err;
311 }
312 if (r->g != NULL)
313 if ((ret->g = BN_dup(r->g)) == NULL)
314 goto err;
315 if (r->pub_key != NULL)
316 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
317 goto err;
318 if (r->priv_key != NULL)
319 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
320 goto err;
321
322 return ret;
323
324 err:
325 if (ret != NULL)
326 DH_free(ret);
327 return NULL;
328 }
329#endif
diff --git a/src/lib/libcrypto/dsa/dsa_locl.h b/src/lib/libcrypto/dsa/dsa_locl.h
deleted file mode 100644
index 21e2e45242..0000000000
--- a/src/lib/libcrypto/dsa/dsa_locl.h
+++ /dev/null
@@ -1,60 +0,0 @@
1/* ====================================================================
2 * Copyright (c) 2007 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * This product includes cryptographic software written by Eric Young
50 * (eay@cryptsoft.com). This product includes software written by Tim
51 * Hudson (tjh@cryptsoft.com).
52 *
53 */
54
55#include <openssl/dsa.h>
56
57int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
58 const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
59 unsigned char *seed_out,
60 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
deleted file mode 100644
index b3d78e524c..0000000000
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ /dev/null
@@ -1,412 +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/sha.h>
65#include <openssl/dsa.h>
66#include <openssl/rand.h>
67#include <openssl/asn1.h>
68
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);
75
76static DSA_METHOD openssl_dsa_meth = {
77"OpenSSL DSA method",
78dsa_do_sign,
79dsa_sign_setup,
80dsa_do_verify,
81NULL, /* dsa_mod_exp, */
82NULL, /* dsa_bn_mod_exp, */
83dsa_init,
84dsa_finish,
850,
86NULL,
87NULL,
88NULL
89};
90
91/* These macro wrappers replace attempts to use the dsa_mod_exp() and
92 * bn_mod_exp() handlers in the DSA_METHOD structure. We avoid the problem of
93 * having a the macro work as an expression by bundling an "err_instr". So;
94 *
95 * if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx,
96 * dsa->method_mont_p)) goto err;
97 *
98 * can be replaced by;
99 *
100 * DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, &k, dsa->p, ctx,
101 * dsa->method_mont_p);
102 */
103
104#define DSA_MOD_EXP(err_instr,dsa,rr,a1,p1,a2,p2,m,ctx,in_mont) \
105 do { \
106 int _tmp_res53; \
107 if((dsa)->meth->dsa_mod_exp) \
108 _tmp_res53 = (dsa)->meth->dsa_mod_exp((dsa), (rr), (a1), (p1), \
109 (a2), (p2), (m), (ctx), (in_mont)); \
110 else \
111 _tmp_res53 = BN_mod_exp2_mont((rr), (a1), (p1), (a2), (p2), \
112 (m), (ctx), (in_mont)); \
113 if(!_tmp_res53) err_instr; \
114 } while(0)
115#define DSA_BN_MOD_EXP(err_instr,dsa,r,a,p,m,ctx,m_ctx) \
116 do { \
117 int _tmp_res53; \
118 if((dsa)->meth->bn_mod_exp) \
119 _tmp_res53 = (dsa)->meth->bn_mod_exp((dsa), (r), (a), (p), \
120 (m), (ctx), (m_ctx)); \
121 else \
122 _tmp_res53 = BN_mod_exp_mont((r), (a), (p), (m), (ctx), (m_ctx)); \
123 if(!_tmp_res53) err_instr; \
124 } while(0)
125
126const DSA_METHOD *DSA_OpenSSL(void)
127{
128 return &openssl_dsa_meth;
129}
130
131static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
132 {
133 BIGNUM *kinv=NULL,*r=NULL,*s=NULL;
134 BIGNUM m;
135 BIGNUM xr;
136 BN_CTX *ctx=NULL;
137 int reason=ERR_R_BN_LIB;
138 DSA_SIG *ret=NULL;
139 int noredo = 0;
140
141 BN_init(&m);
142 BN_init(&xr);
143
144 if (!dsa->p || !dsa->q || !dsa->g)
145 {
146 reason=DSA_R_MISSING_PARAMETERS;
147 goto err;
148 }
149
150 s=BN_new();
151 if (s == NULL) goto err;
152 ctx=BN_CTX_new();
153 if (ctx == NULL) goto err;
154redo:
155 if ((dsa->kinv == NULL) || (dsa->r == NULL))
156 {
157 if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err;
158 }
159 else
160 {
161 kinv=dsa->kinv;
162 dsa->kinv=NULL;
163 r=dsa->r;
164 dsa->r=NULL;
165 noredo = 1;
166 }
167
168
169 if (dlen > BN_num_bytes(dsa->q))
170 /* if the digest length is greater than the size of q use the
171 * BN_num_bits(dsa->q) leftmost bits of the digest, see
172 * fips 186-3, 4.2 */
173 dlen = BN_num_bytes(dsa->q);
174 if (BN_bin2bn(dgst,dlen,&m) == NULL)
175 goto err;
176
177 /* Compute s = inv(k) (m + xr) mod q */
178 if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */
179 if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */
180 if (BN_cmp(s,dsa->q) > 0)
181 if (!BN_sub(s,s,dsa->q)) goto err;
182 if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err;
183
184 ret=DSA_SIG_new();
185 if (ret == NULL) goto err;
186 /* Redo if r or s is zero as required by FIPS 186-3: this is
187 * very unlikely.
188 */
189 if (BN_is_zero(r) || BN_is_zero(s))
190 {
191 if (noredo)
192 {
193 reason = DSA_R_NEED_NEW_SETUP_VALUES;
194 goto err;
195 }
196 goto redo;
197 }
198 ret->r = r;
199 ret->s = s;
200
201err:
202 if (!ret)
203 {
204 DSAerr(DSA_F_DSA_DO_SIGN,reason);
205 BN_free(r);
206 BN_free(s);
207 }
208 if (ctx != NULL) BN_CTX_free(ctx);
209 BN_clear_free(&m);
210 BN_clear_free(&xr);
211 if (kinv != NULL) /* dsa->kinv is NULL now if we used it */
212 BN_clear_free(kinv);
213 return(ret);
214 }
215
216static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
217 {
218 BN_CTX *ctx;
219 BIGNUM k,kq,*K,*kinv=NULL,*r=NULL;
220 int ret=0;
221
222 if (!dsa->p || !dsa->q || !dsa->g)
223 {
224 DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS);
225 return 0;
226 }
227
228 BN_init(&k);
229 BN_init(&kq);
230
231 if (ctx_in == NULL)
232 {
233 if ((ctx=BN_CTX_new()) == NULL) goto err;
234 }
235 else
236 ctx=ctx_in;
237
238 if ((r=BN_new()) == NULL) goto err;
239
240 /* Get random k */
241 do
242 if (!BN_rand_range(&k, dsa->q)) goto err;
243 while (BN_is_zero(&k));
244 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
245 {
246 BN_set_flags(&k, BN_FLG_CONSTTIME);
247 }
248
249 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
250 {
251 if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,
252 CRYPTO_LOCK_DSA,
253 dsa->p, ctx))
254 goto err;
255 }
256
257 /* Compute r = (g^k mod p) mod q */
258
259 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
260 {
261 if (!BN_copy(&kq, &k)) goto err;
262
263 /* We do not want timing information to leak the length of k,
264 * so we compute g^k using an equivalent exponent of fixed length.
265 *
266 * (This is a kludge that we need because the BN_mod_exp_mont()
267 * does not let us specify the desired timing behaviour.) */
268
269 if (!BN_add(&kq, &kq, dsa->q)) goto err;
270 if (BN_num_bits(&kq) <= BN_num_bits(dsa->q))
271 {
272 if (!BN_add(&kq, &kq, dsa->q)) goto err;
273 }
274
275 K = &kq;
276 }
277 else
278 {
279 K = &k;
280 }
281 DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx,
282 dsa->method_mont_p);
283 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
284
285 /* Compute part of 's = inv(k) (m + xr) mod q' */
286 if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err;
287
288 if (*kinvp != NULL) BN_clear_free(*kinvp);
289 *kinvp=kinv;
290 kinv=NULL;
291 if (*rp != NULL) BN_clear_free(*rp);
292 *rp=r;
293 ret=1;
294err:
295 if (!ret)
296 {
297 DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB);
298 if (r != NULL)
299 BN_clear_free(r);
300 }
301 if (ctx_in == NULL) BN_CTX_free(ctx);
302 BN_clear_free(&k);
303 BN_clear_free(&kq);
304 return(ret);
305 }
306
307static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
308 DSA *dsa)
309 {
310 BN_CTX *ctx;
311 BIGNUM u1,u2,t1;
312 BN_MONT_CTX *mont=NULL;
313 int ret = -1, i;
314 if (!dsa->p || !dsa->q || !dsa->g)
315 {
316 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MISSING_PARAMETERS);
317 return -1;
318 }
319
320 i = BN_num_bits(dsa->q);
321 /* fips 186-3 allows only different sizes for q */
322 if (i != 160 && i != 224 && i != 256)
323 {
324 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_BAD_Q_VALUE);
325 return -1;
326 }
327
328 if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS)
329 {
330 DSAerr(DSA_F_DSA_DO_VERIFY,DSA_R_MODULUS_TOO_LARGE);
331 return -1;
332 }
333 BN_init(&u1);
334 BN_init(&u2);
335 BN_init(&t1);
336
337 if ((ctx=BN_CTX_new()) == NULL) goto err;
338
339 if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||
340 BN_ucmp(sig->r, dsa->q) >= 0)
341 {
342 ret = 0;
343 goto err;
344 }
345 if (BN_is_zero(sig->s) || BN_is_negative(sig->s) ||
346 BN_ucmp(sig->s, dsa->q) >= 0)
347 {
348 ret = 0;
349 goto err;
350 }
351
352 /* Calculate W = inv(S) mod Q
353 * save W in u2 */
354 if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err;
355
356 /* save M in u1 */
357 if (dgst_len > (i >> 3))
358 /* if the digest length is greater than the size of q use the
359 * BN_num_bits(dsa->q) leftmost bits of the digest, see
360 * fips 186-3, 4.2 */
361 dgst_len = (i >> 3);
362 if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err;
363
364 /* u1 = M * w mod q */
365 if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err;
366
367 /* u2 = r * w mod q */
368 if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err;
369
370
371 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
372 {
373 mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p,
374 CRYPTO_LOCK_DSA, dsa->p, ctx);
375 if (!mont)
376 goto err;
377 }
378
379
380 DSA_MOD_EXP(goto err, dsa, &t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx, mont);
381 /* BN_copy(&u1,&t1); */
382 /* let u1 = u1 mod q */
383 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
384
385 /* V is now in u1. If the signature is correct, it will be
386 * equal to R. */
387 ret=(BN_ucmp(&u1, sig->r) == 0);
388
389 err:
390 /* XXX: surely this is wrong - if ret is 0, it just didn't verify;
391 there is no error in BN. Test should be ret == -1 (Ben) */
392 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
393 if (ctx != NULL) BN_CTX_free(ctx);
394 BN_free(&u1);
395 BN_free(&u2);
396 BN_free(&t1);
397 return(ret);
398 }
399
400static int dsa_init(DSA *dsa)
401{
402 dsa->flags|=DSA_FLAG_CACHE_MONT_P;
403 return(1);
404}
405
406static int dsa_finish(DSA *dsa)
407{
408 if(dsa->method_mont_p)
409 BN_MONT_CTX_free(dsa->method_mont_p);
410 return(1);
411}
412
diff --git a/src/lib/libcrypto/dsa/dsa_pmeth.c b/src/lib/libcrypto/dsa/dsa_pmeth.c
deleted file mode 100644
index 715d8d675b..0000000000
--- a/src/lib/libcrypto/dsa/dsa_pmeth.c
+++ /dev/null
@@ -1,318 +0,0 @@
1/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
2 * project 2006.
3 */
4/* ====================================================================
5 * Copyright (c) 2006 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <stdio.h>
59#include "cryptlib.h"
60#include <openssl/asn1t.h>
61#include <openssl/x509.h>
62#include <openssl/evp.h>
63#include <openssl/bn.h>
64#include "evp_locl.h"
65#include "dsa_locl.h"
66
67/* DSA pkey context structure */
68
69typedef struct
70 {
71 /* Parameter gen parameters */
72 int nbits; /* size of p in bits (default: 1024) */
73 int qbits; /* size of q in bits (default: 160) */
74 const EVP_MD *pmd; /* MD for parameter generation */
75 /* Keygen callback info */
76 int gentmp[2];
77 /* message digest */
78 const EVP_MD *md; /* MD for the signature */
79 } DSA_PKEY_CTX;
80
81static int pkey_dsa_init(EVP_PKEY_CTX *ctx)
82 {
83 DSA_PKEY_CTX *dctx;
84 dctx = OPENSSL_malloc(sizeof(DSA_PKEY_CTX));
85 if (!dctx)
86 return 0;
87 dctx->nbits = 1024;
88 dctx->qbits = 160;
89 dctx->pmd = NULL;
90 dctx->md = NULL;
91
92 ctx->data = dctx;
93 ctx->keygen_info = dctx->gentmp;
94 ctx->keygen_info_count = 2;
95
96 return 1;
97 }
98
99static int pkey_dsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
100 {
101 DSA_PKEY_CTX *dctx, *sctx;
102 if (!pkey_dsa_init(dst))
103 return 0;
104 sctx = src->data;
105 dctx = dst->data;
106 dctx->nbits = sctx->nbits;
107 dctx->qbits = sctx->qbits;
108 dctx->pmd = sctx->pmd;
109 dctx->md = sctx->md;
110 return 1;
111 }
112
113static void pkey_dsa_cleanup(EVP_PKEY_CTX *ctx)
114 {
115 DSA_PKEY_CTX *dctx = ctx->data;
116 if (dctx)
117 OPENSSL_free(dctx);
118 }
119
120static int pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
121 const unsigned char *tbs, size_t tbslen)
122 {
123 int ret, type;
124 unsigned int sltmp;
125 DSA_PKEY_CTX *dctx = ctx->data;
126 DSA *dsa = ctx->pkey->pkey.dsa;
127
128 if (dctx->md)
129 type = EVP_MD_type(dctx->md);
130 else
131 type = NID_sha1;
132
133 ret = DSA_sign(type, tbs, tbslen, sig, &sltmp, dsa);
134
135 if (ret <= 0)
136 return ret;
137 *siglen = sltmp;
138 return 1;
139 }
140
141static int pkey_dsa_verify(EVP_PKEY_CTX *ctx,
142 const unsigned char *sig, size_t siglen,
143 const unsigned char *tbs, size_t tbslen)
144 {
145 int ret, type;
146 DSA_PKEY_CTX *dctx = ctx->data;
147 DSA *dsa = ctx->pkey->pkey.dsa;
148
149 if (dctx->md)
150 type = EVP_MD_type(dctx->md);
151 else
152 type = NID_sha1;
153
154 ret = DSA_verify(type, tbs, tbslen, sig, siglen, dsa);
155
156 return ret;
157 }
158
159static int pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
160 {
161 DSA_PKEY_CTX *dctx = ctx->data;
162 switch (type)
163 {
164 case EVP_PKEY_CTRL_DSA_PARAMGEN_BITS:
165 if (p1 < 256)
166 return -2;
167 dctx->nbits = p1;
168 return 1;
169
170 case EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS:
171 if (p1 != 160 && p1 != 224 && p1 && p1 != 256)
172 return -2;
173 dctx->qbits = p1;
174 return 1;
175
176 case EVP_PKEY_CTRL_DSA_PARAMGEN_MD:
177 if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 &&
178 EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
179 EVP_MD_type((const EVP_MD *)p2) != NID_sha256)
180 {
181 DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
182 return 0;
183 }
184 dctx->md = p2;
185 return 1;
186
187 case EVP_PKEY_CTRL_MD:
188 if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 &&
189 EVP_MD_type((const EVP_MD *)p2) != NID_dsa &&
190 EVP_MD_type((const EVP_MD *)p2) != NID_dsaWithSHA &&
191 EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
192 EVP_MD_type((const EVP_MD *)p2) != NID_sha256 &&
193 EVP_MD_type((const EVP_MD *)p2) != NID_sha384 &&
194 EVP_MD_type((const EVP_MD *)p2) != NID_sha512)
195 {
196 DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
197 return 0;
198 }
199 dctx->md = p2;
200 return 1;
201
202 case EVP_PKEY_CTRL_DIGESTINIT:
203 case EVP_PKEY_CTRL_PKCS7_SIGN:
204 case EVP_PKEY_CTRL_CMS_SIGN:
205 return 1;
206
207 case EVP_PKEY_CTRL_PEER_KEY:
208 DSAerr(DSA_F_PKEY_DSA_CTRL,
209 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
210 return -2;
211 default:
212 return -2;
213
214 }
215 }
216
217static int pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx,
218 const char *type, const char *value)
219 {
220 if (!strcmp(type, "dsa_paramgen_bits"))
221 {
222 int nbits;
223 nbits = atoi(value);
224 return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits);
225 }
226 if (!strcmp(type, "dsa_paramgen_q_bits"))
227 {
228 int qbits = atoi(value);
229 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
230 EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS, qbits, NULL);
231 }
232 if (!strcmp(type, "dsa_paramgen_md"))
233 {
234 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN,
235 EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0,
236 (void *)EVP_get_digestbyname(value));
237 }
238 return -2;
239 }
240
241static int pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
242 {
243 DSA *dsa = NULL;
244 DSA_PKEY_CTX *dctx = ctx->data;
245 BN_GENCB *pcb, cb;
246 int ret;
247 if (ctx->pkey_gencb)
248 {
249 pcb = &cb;
250 evp_pkey_set_cb_translate(pcb, ctx);
251 }
252 else
253 pcb = NULL;
254 dsa = DSA_new();
255 if (!dsa)
256 return 0;
257 ret = dsa_builtin_paramgen(dsa, dctx->nbits, dctx->qbits, dctx->pmd,
258 NULL, 0, NULL, NULL, NULL, pcb);
259 if (ret)
260 EVP_PKEY_assign_DSA(pkey, dsa);
261 else
262 DSA_free(dsa);
263 return ret;
264 }
265
266static int pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
267 {
268 DSA *dsa = NULL;
269 if (ctx->pkey == NULL)
270 {
271 DSAerr(DSA_F_PKEY_DSA_KEYGEN, DSA_R_NO_PARAMETERS_SET);
272 return 0;
273 }
274 dsa = DSA_new();
275 if (!dsa)
276 return 0;
277 EVP_PKEY_assign_DSA(pkey, dsa);
278 /* Note: if error return, pkey is freed by parent routine */
279 if (!EVP_PKEY_copy_parameters(pkey, ctx->pkey))
280 return 0;
281 return DSA_generate_key(pkey->pkey.dsa);
282 }
283
284const EVP_PKEY_METHOD dsa_pkey_meth =
285 {
286 EVP_PKEY_DSA,
287 EVP_PKEY_FLAG_AUTOARGLEN,
288 pkey_dsa_init,
289 pkey_dsa_copy,
290 pkey_dsa_cleanup,
291
292 0,
293 pkey_dsa_paramgen,
294
295 0,
296 pkey_dsa_keygen,
297
298 0,
299 pkey_dsa_sign,
300
301 0,
302 pkey_dsa_verify,
303
304 0,0,
305
306 0,0,0,0,
307
308 0,0,
309
310 0,0,
311
312 0,0,
313
314 pkey_dsa_ctrl,
315 pkey_dsa_ctrl_str
316
317
318 };
diff --git a/src/lib/libcrypto/dsa/dsa_prn.c b/src/lib/libcrypto/dsa/dsa_prn.c
deleted file mode 100644
index 6f29f5e240..0000000000
--- a/src/lib/libcrypto/dsa/dsa_prn.c
+++ /dev/null
@@ -1,121 +0,0 @@
1/* crypto/dsa/dsa_prn.c */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2006.
4 */
5/* ====================================================================
6 * Copyright (c) 2006 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/evp.h>
62#include <openssl/dsa.h>
63
64#ifndef OPENSSL_NO_FP_API
65int DSA_print_fp(FILE *fp, const DSA *x, int off)
66 {
67 BIO *b;
68 int ret;
69
70 if ((b=BIO_new(BIO_s_file())) == NULL)
71 {
72 DSAerr(DSA_F_DSA_PRINT_FP,ERR_R_BUF_LIB);
73 return(0);
74 }
75 BIO_set_fp(b,fp,BIO_NOCLOSE);
76 ret=DSA_print(b,x,off);
77 BIO_free(b);
78 return(ret);
79 }
80
81int DSAparams_print_fp(FILE *fp, const DSA *x)
82 {
83 BIO *b;
84 int ret;
85
86 if ((b=BIO_new(BIO_s_file())) == NULL)
87 {
88 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
89 return(0);
90 }
91 BIO_set_fp(b,fp,BIO_NOCLOSE);
92 ret=DSAparams_print(b, x);
93 BIO_free(b);
94 return(ret);
95 }
96#endif
97
98int DSA_print(BIO *bp, const DSA *x, int off)
99 {
100 EVP_PKEY *pk;
101 int ret;
102 pk = EVP_PKEY_new();
103 if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
104 return 0;
105 ret = EVP_PKEY_print_private(bp, pk, off, NULL);
106 EVP_PKEY_free(pk);
107 return ret;
108 }
109
110int DSAparams_print(BIO *bp, const DSA *x)
111 {
112 EVP_PKEY *pk;
113 int ret;
114 pk = EVP_PKEY_new();
115 if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
116 return 0;
117 ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
118 EVP_PKEY_free(pk);
119 return ret;
120 }
121
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
deleted file mode 100644
index c3cc3642ce..0000000000
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ /dev/null
@@ -1,114 +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 "cryptlib.h"
62#include <openssl/dsa.h>
63#include <openssl/rand.h>
64#include <openssl/bn.h>
65
66DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
67 {
68#ifdef OPENSSL_FIPS
69 if (FIPS_mode() && !(dsa->meth->flags & DSA_FLAG_FIPS_METHOD)
70 && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
71 {
72 DSAerr(DSA_F_DSA_DO_SIGN, DSA_R_NON_FIPS_DSA_METHOD);
73 return NULL;
74 }
75#endif
76 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
77 }
78
79int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
80 {
81#ifdef OPENSSL_FIPS
82 if (FIPS_mode() && !(dsa->meth->flags & DSA_FLAG_FIPS_METHOD)
83 && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
84 {
85 DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_NON_FIPS_DSA_METHOD);
86 return 0;
87 }
88#endif
89 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
90 }
91
92DSA_SIG *DSA_SIG_new(void)
93 {
94 DSA_SIG *sig;
95 sig = OPENSSL_malloc(sizeof(DSA_SIG));
96 if (!sig)
97 return NULL;
98 sig->r = NULL;
99 sig->s = NULL;
100 return sig;
101 }
102
103void DSA_SIG_free(DSA_SIG *sig)
104 {
105 if (sig)
106 {
107 if (sig->r)
108 BN_free(sig->r);
109 if (sig->s)
110 BN_free(sig->s);
111 OPENSSL_free(sig);
112 }
113 }
114
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
deleted file mode 100644
index 674cb5fa5f..0000000000
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ /dev/null
@@ -1,76 +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 "cryptlib.h"
62#include <openssl/dsa.h>
63
64int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
65 DSA *dsa)
66 {
67#ifdef OPENSSL_FIPS
68 if (FIPS_mode() && !(dsa->meth->flags & DSA_FLAG_FIPS_METHOD)
69 && !(dsa->flags & DSA_FLAG_NON_FIPS_ALLOW))
70 {
71 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_NON_FIPS_DSA_METHOD);
72 return -1;
73 }
74#endif
75 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
76 }