summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/dsa
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2016-07-23 19:31:36 +0000
committercvs2svn <admin@example.com>2016-07-23 19:31:36 +0000
commit86c49b31af735796dfde37aa29473a30d36367db (patch)
treee9a354a92a348338fe2b361e2eda703cae23cfab /src/lib/libcrypto/dsa
parent19d5fe348e8926bac4521c5807aa64c45b8f7a41 (diff)
downloadopenbsd-OPENBSD_6_0_BASE.tar.gz
openbsd-OPENBSD_6_0_BASE.tar.bz2
openbsd-OPENBSD_6_0_BASE.zip
This commit was manufactured by cvs2git to create tag 'OPENBSD_6_0_BASE'.OPENBSD_6_0_BASE
Diffstat (limited to 'src/lib/libcrypto/dsa')
-rw-r--r--src/lib/libcrypto/dsa/dsa.h323
-rw-r--r--src/lib/libcrypto/dsa/dsa_ameth.c698
-rw-r--r--src/lib/libcrypto/dsa/dsa_asn1.c439
-rw-r--r--src/lib/libcrypto/dsa/dsa_depr.c92
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c133
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c357
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c127
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c305
-rw-r--r--src/lib/libcrypto/dsa/dsa_locl.h61
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c385
-rw-r--r--src/lib/libcrypto/dsa/dsa_pmeth.c337
-rw-r--r--src/lib/libcrypto/dsa/dsa_prn.c123
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c97
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c67
14 files changed, 0 insertions, 3544 deletions
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
deleted file mode 100644
index b4d7c1ff0f..0000000000
--- a/src/lib/libcrypto/dsa/dsa.h
+++ /dev/null
@@ -1,323 +0,0 @@
1/* $OpenBSD: dsa.h,v 1.21 2016/06/30 02:02:06 bcook Exp $ */
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/opensslconf.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
93/* If this flag is set the DSA method is FIPS compliant and can be used
94 * in FIPS mode. This is set in the validated module method. If an
95 * application sets this flag in its own methods it is its reposibility
96 * to ensure the result is compliant.
97 */
98
99#define DSA_FLAG_FIPS_METHOD 0x0400
100
101/* If this flag is set the operations normally disabled in FIPS mode are
102 * permitted it is then the applications responsibility to ensure that the
103 * usage is compliant.
104 */
105
106#define DSA_FLAG_NON_FIPS_ALLOW 0x0400
107
108#ifdef __cplusplus
109extern "C" {
110#endif
111
112/* Already defined in ossl_typ.h */
113/* typedef struct dsa_st DSA; */
114/* typedef struct dsa_method DSA_METHOD; */
115
116typedef struct DSA_SIG_st
117 {
118 BIGNUM *r;
119 BIGNUM *s;
120 } DSA_SIG;
121
122struct dsa_method
123 {
124 const char *name;
125 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
126 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
127 BIGNUM **rp);
128 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
129 DSA_SIG *sig, DSA *dsa);
130 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
131 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
132 BN_MONT_CTX *in_mont);
133 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
134 const BIGNUM *m, BN_CTX *ctx,
135 BN_MONT_CTX *m_ctx); /* Can be null */
136 int (*init)(DSA *dsa);
137 int (*finish)(DSA *dsa);
138 int flags;
139 char *app_data;
140 /* If this is non-NULL, it is used to generate DSA parameters */
141 int (*dsa_paramgen)(DSA *dsa, int bits,
142 const unsigned char *seed, int seed_len,
143 int *counter_ret, unsigned long *h_ret,
144 BN_GENCB *cb);
145 /* If this is non-NULL, it is used to generate DSA keys */
146 int (*dsa_keygen)(DSA *dsa);
147 };
148
149struct dsa_st
150 {
151 /* This first variable is used to pick up errors where
152 * a DSA is passed instead of of a EVP_PKEY */
153 int pad;
154 long version;
155 int write_params;
156 BIGNUM *p;
157 BIGNUM *q; /* == 20 */
158 BIGNUM *g;
159
160 BIGNUM *pub_key; /* y public key */
161 BIGNUM *priv_key; /* x private key */
162
163 BIGNUM *kinv; /* Signing pre-calc */
164 BIGNUM *r; /* Signing pre-calc */
165
166 int flags;
167 /* Normally used to cache montgomery values */
168 BN_MONT_CTX *method_mont_p;
169 int references;
170 CRYPTO_EX_DATA ex_data;
171 const DSA_METHOD *meth;
172 /* functional reference if 'meth' is ENGINE-provided */
173 ENGINE *engine;
174 };
175
176#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
177 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
178#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
179 (unsigned char *)(x))
180#define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x)
181#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x)
182
183
184DSA *DSAparams_dup(DSA *x);
185DSA_SIG * DSA_SIG_new(void);
186void DSA_SIG_free(DSA_SIG *a);
187int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
188DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);
189
190DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
191int DSA_do_verify(const unsigned char *dgst,int dgst_len,
192 DSA_SIG *sig,DSA *dsa);
193
194const DSA_METHOD *DSA_OpenSSL(void);
195
196void DSA_set_default_method(const DSA_METHOD *);
197const DSA_METHOD *DSA_get_default_method(void);
198int DSA_set_method(DSA *dsa, const DSA_METHOD *);
199
200DSA * DSA_new(void);
201DSA * DSA_new_method(ENGINE *engine);
202void DSA_free(DSA *r);
203/* "up" the DSA object's reference count */
204int DSA_up_ref(DSA *r);
205int DSA_size(const DSA *);
206 /* next 4 return -1 on error */
207int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
208int DSA_sign(int type,const unsigned char *dgst,int dlen,
209 unsigned char *sig, unsigned int *siglen, DSA *dsa);
210int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
211 const unsigned char *sigbuf, int siglen, DSA *dsa);
212int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
213 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
214int DSA_set_ex_data(DSA *d, int idx, void *arg);
215void *DSA_get_ex_data(DSA *d, int idx);
216
217DSA *d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
218int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
219extern const ASN1_ITEM DSAPublicKey_it;
220
221DSA *d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
222int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
223extern const ASN1_ITEM DSAPrivateKey_it;
224
225DSA *d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
226int i2d_DSAparams(const DSA *a,unsigned char **pp);
227extern const ASN1_ITEM DSAparams_it;
228
229/* Deprecated version */
230#ifndef OPENSSL_NO_DEPRECATED
231DSA * DSA_generate_parameters(int bits,
232 unsigned char *seed,int seed_len,
233 int *counter_ret, unsigned long *h_ret,void
234 (*callback)(int, int, void *),void *cb_arg);
235#endif /* !defined(OPENSSL_NO_DEPRECATED) */
236
237/* New version */
238int DSA_generate_parameters_ex(DSA *dsa, int bits,
239 const unsigned char *seed,int seed_len,
240 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
241
242int DSA_generate_key(DSA *a);
243
244#ifndef OPENSSL_NO_BIO
245int DSAparams_print(BIO *bp, const DSA *x);
246int DSA_print(BIO *bp, const DSA *x, int off);
247#endif
248int DSAparams_print_fp(FILE *fp, const DSA *x);
249int DSA_print_fp(FILE *bp, const DSA *x, int off);
250
251#define DSS_prime_checks 50
252/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
253 * 50 rounds of Rabin-Miller */
254#define DSA_is_prime(n, callback, cb_arg) \
255 BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
256
257#ifndef OPENSSL_NO_DH
258/* Convert DSA structure (key or just parameters) into DH structure
259 * (be careful to avoid small subgroup attacks when using this!) */
260DH *DSA_dup_DH(const DSA *r);
261#endif
262
263#define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \
264 EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \
265 EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL)
266
267#define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1)
268#define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2)
269#define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3)
270
271/* BEGIN ERROR CODES */
272/* The following lines are auto generated by the script mkerr.pl. Any changes
273 * made after this point may be overwritten when the script is next run.
274 */
275void ERR_load_DSA_strings(void);
276
277/* Error codes for the DSA functions. */
278
279/* Function codes. */
280#define DSA_F_D2I_DSA_SIG 110
281#define DSA_F_DO_DSA_PRINT 104
282#define DSA_F_DSAPARAMS_PRINT 100
283#define DSA_F_DSAPARAMS_PRINT_FP 101
284#define DSA_F_DSA_DO_SIGN 112
285#define DSA_F_DSA_DO_VERIFY 113
286#define DSA_F_DSA_GENERATE_KEY 124
287#define DSA_F_DSA_GENERATE_PARAMETERS_EX 123
288#define DSA_F_DSA_NEW_METHOD 103
289#define DSA_F_DSA_PARAM_DECODE 119
290#define DSA_F_DSA_PRINT_FP 105
291#define DSA_F_DSA_PRIV_DECODE 115
292#define DSA_F_DSA_PRIV_ENCODE 116
293#define DSA_F_DSA_PUB_DECODE 117
294#define DSA_F_DSA_PUB_ENCODE 118
295#define DSA_F_DSA_SIGN 106
296#define DSA_F_DSA_SIGN_SETUP 107
297#define DSA_F_DSA_SIG_NEW 109
298#define DSA_F_DSA_SIG_PRINT 125
299#define DSA_F_DSA_VERIFY 108
300#define DSA_F_I2D_DSA_SIG 111
301#define DSA_F_OLD_DSA_PRIV_DECODE 122
302#define DSA_F_PKEY_DSA_CTRL 120
303#define DSA_F_PKEY_DSA_KEYGEN 121
304#define DSA_F_SIG_CB 114
305
306/* Reason codes. */
307#define DSA_R_BAD_Q_VALUE 102
308#define DSA_R_BN_DECODE_ERROR 108
309#define DSA_R_BN_ERROR 109
310#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
311#define DSA_R_DECODE_ERROR 104
312#define DSA_R_INVALID_DIGEST_TYPE 106
313#define DSA_R_MISSING_PARAMETERS 101
314#define DSA_R_MODULUS_TOO_LARGE 103
315#define DSA_R_NEED_NEW_SETUP_VALUES 110
316#define DSA_R_NON_FIPS_DSA_METHOD 111
317#define DSA_R_NO_PARAMETERS_SET 107
318#define DSA_R_PARAMETER_ENCODING_ERROR 105
319
320#ifdef __cplusplus
321}
322#endif
323#endif
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c
deleted file mode 100644
index a6e21a688e..0000000000
--- a/src/lib/libcrypto/dsa/dsa_ameth.c
+++ /dev/null
@@ -1,698 +0,0 @@
1/* $OpenBSD: dsa_ameth.c,v 1.19 2016/03/01 07:04:41 doug Exp $ */
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
61#include <openssl/opensslconf.h>
62
63#include <openssl/asn1.h>
64#include <openssl/bn.h>
65#include <openssl/dsa.h>
66#include <openssl/err.h>
67#include <openssl/x509.h>
68
69#ifndef OPENSSL_NO_CMS
70#include <openssl/cms.h>
71#endif
72
73#include "asn1_locl.h"
74
75static int
76dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
77{
78 const unsigned char *p, *pm;
79 int pklen, pmlen;
80 int ptype;
81 void *pval;
82 ASN1_STRING *pstr;
83 X509_ALGOR *palg;
84 ASN1_INTEGER *public_key = NULL;
85
86 DSA *dsa = NULL;
87
88 if (!X509_PUBKEY_get0_param(NULL, &p, &pklen, &palg, pubkey))
89 return 0;
90 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
91
92 if (ptype == V_ASN1_SEQUENCE) {
93 pstr = pval;
94 pm = pstr->data;
95 pmlen = pstr->length;
96
97 if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) {
98 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
99 goto err;
100 }
101 } else if (ptype == V_ASN1_NULL || ptype == V_ASN1_UNDEF) {
102 if (!(dsa = DSA_new())) {
103 DSAerr(DSA_F_DSA_PUB_DECODE, ERR_R_MALLOC_FAILURE);
104 goto err;
105 }
106 } else {
107 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_PARAMETER_ENCODING_ERROR);
108 goto err;
109 }
110
111 if (!(public_key=d2i_ASN1_INTEGER(NULL, &p, pklen))) {
112 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_DECODE_ERROR);
113 goto err;
114 }
115
116 if (!(dsa->pub_key = ASN1_INTEGER_to_BN(public_key, NULL))) {
117 DSAerr(DSA_F_DSA_PUB_DECODE, DSA_R_BN_DECODE_ERROR);
118 goto err;
119 }
120
121 ASN1_INTEGER_free(public_key);
122 EVP_PKEY_assign_DSA(pkey, dsa);
123 return 1;
124
125err:
126 if (public_key)
127 ASN1_INTEGER_free(public_key);
128 DSA_free(dsa);
129 return 0;
130}
131
132static int
133dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
134{
135 DSA *dsa;
136 void *pval = NULL;
137 int ptype;
138 unsigned char *penc = NULL;
139 int penclen;
140
141 dsa = pkey->pkey.dsa;
142 if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) {
143 ASN1_STRING *str;
144
145 str = ASN1_STRING_new();
146 if (str == NULL) {
147 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
148 goto err;
149 }
150 str->length = i2d_DSAparams(dsa, &str->data);
151 if (str->length <= 0) {
152 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
153 ASN1_STRING_free(str);
154 goto err;
155 }
156 pval = str;
157 ptype = V_ASN1_SEQUENCE;
158 } else
159 ptype = V_ASN1_UNDEF;
160
161 dsa->write_params = 0;
162
163 penclen = i2d_DSAPublicKey(dsa, &penc);
164
165 if (penclen <= 0) {
166 DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
167 goto err;
168 }
169
170 if (X509_PUBKEY_set0_param(pk, OBJ_nid2obj(EVP_PKEY_DSA), ptype, pval,
171 penc, penclen))
172 return 1;
173
174err:
175 free(penc);
176 ASN1_STRING_free(pval);
177
178 return 0;
179}
180
181/* In PKCS#8 DSA: you just get a private key integer and parameters in the
182 * AlgorithmIdentifier the pubkey must be recalculated.
183 */
184static int
185dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)
186{
187 const unsigned char *p, *pm;
188 int pklen, pmlen;
189 int ptype;
190 void *pval;
191 ASN1_STRING *pstr;
192 X509_ALGOR *palg;
193 ASN1_INTEGER *privkey = NULL;
194 BN_CTX *ctx = NULL;
195 DSA *dsa = NULL;
196
197 int ret = 0;
198
199 if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))
200 return 0;
201 X509_ALGOR_get0(NULL, &ptype, &pval, palg);
202 if (ptype != V_ASN1_SEQUENCE)
203 goto decerr;
204
205 if ((privkey = d2i_ASN1_INTEGER(NULL, &p, pklen)) == NULL)
206 goto decerr;
207 if (privkey->type == V_ASN1_NEG_INTEGER)
208 goto decerr;
209
210 pstr = pval;
211 pm = pstr->data;
212 pmlen = pstr->length;
213 if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen)))
214 goto decerr;
215 /* We have parameters now set private key */
216 if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) {
217 DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);
218 goto dsaerr;
219 }
220 /* Calculate public key */
221 if (!(dsa->pub_key = BN_new())) {
222 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
223 goto dsaerr;
224 }
225 if (!(ctx = BN_CTX_new())) {
226 DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE);
227 goto dsaerr;
228 }
229
230 if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) {
231 DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR);
232 goto dsaerr;
233 }
234
235 if (!EVP_PKEY_assign_DSA(pkey, dsa))
236 goto decerr;
237
238 ret = 1;
239 goto done;
240
241decerr:
242 DSAerr(DSA_F_DSA_PRIV_DECODE, DSA_R_DECODE_ERROR);
243dsaerr:
244 DSA_free(dsa);
245done:
246 BN_CTX_free(ctx);
247 ASN1_INTEGER_free(privkey);
248 return ret;
249}
250
251static int
252dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey)
253{
254 ASN1_STRING *params = NULL;
255 ASN1_INTEGER *prkey = NULL;
256 unsigned char *dp = NULL;
257 int dplen;
258
259 params = ASN1_STRING_new();
260 if (!params) {
261 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);
262 goto err;
263 }
264
265 params->length = i2d_DSAparams(pkey->pkey.dsa, &params->data);
266 if (params->length <= 0) {
267 DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE);
268 goto err;
269 }
270 params->type = V_ASN1_SEQUENCE;
271
272 /* Get private key into integer */
273 prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL);
274 if (!prkey) {
275 DSAerr(DSA_F_DSA_PRIV_ENCODE, DSA_R_BN_ERROR);
276 goto err;
277 }
278
279 dplen = i2d_ASN1_INTEGER(prkey, &dp);
280
281 ASN1_INTEGER_free(prkey);
282 prkey = NULL;
283
284 if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_dsa), 0, V_ASN1_SEQUENCE,
285 params, dp, dplen))
286 goto err;
287
288 return 1;
289
290err:
291 free(dp);
292 ASN1_STRING_free(params);
293 ASN1_INTEGER_free(prkey);
294 return 0;
295}
296
297static int
298int_dsa_size(const EVP_PKEY *pkey)
299{
300 return DSA_size(pkey->pkey.dsa);
301}
302
303static int
304dsa_bits(const EVP_PKEY *pkey)
305{
306 return BN_num_bits(pkey->pkey.dsa->p);
307}
308
309static int
310dsa_missing_parameters(const EVP_PKEY *pkey)
311{
312 DSA *dsa;
313
314 dsa = pkey->pkey.dsa;
315 if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL)
316 return 1;
317 return 0;
318}
319
320static int
321dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
322{
323 BIGNUM *a;
324
325 if ((a = BN_dup(from->pkey.dsa->p)) == NULL)
326 return 0;
327 BN_free(to->pkey.dsa->p);
328 to->pkey.dsa->p = a;
329
330 if ((a = BN_dup(from->pkey.dsa->q)) == NULL)
331 return 0;
332 BN_free(to->pkey.dsa->q);
333 to->pkey.dsa->q = a;
334
335 if ((a = BN_dup(from->pkey.dsa->g)) == NULL)
336 return 0;
337 BN_free(to->pkey.dsa->g);
338 to->pkey.dsa->g = a;
339 return 1;
340}
341
342static int
343dsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
344{
345 if (BN_cmp(a->pkey.dsa->p, b->pkey.dsa->p) ||
346 BN_cmp(a->pkey.dsa->q, b->pkey.dsa->q) ||
347 BN_cmp(a->pkey.dsa->g, b->pkey.dsa->g))
348 return 0;
349 else
350 return 1;
351}
352
353static int
354dsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
355{
356 if (BN_cmp(b->pkey.dsa->pub_key, a->pkey.dsa->pub_key) != 0)
357 return 0;
358 else
359 return 1;
360}
361
362static void
363int_dsa_free(EVP_PKEY *pkey)
364{
365 DSA_free(pkey->pkey.dsa);
366}
367
368static void
369update_buflen(const BIGNUM *b, size_t *pbuflen)
370{
371 size_t i;
372
373 if (!b)
374 return;
375 if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
376 *pbuflen = i;
377}
378
379static int
380do_dsa_print(BIO *bp, const DSA *x, int off, int ptype)
381{
382 unsigned char *m = NULL;
383 int ret = 0;
384 size_t buf_len = 0;
385 const char *ktype = NULL;
386 const BIGNUM *priv_key, *pub_key;
387
388 if (ptype == 2)
389 priv_key = x->priv_key;
390 else
391 priv_key = NULL;
392
393 if (ptype > 0)
394 pub_key = x->pub_key;
395 else
396 pub_key = NULL;
397
398 if (ptype == 2)
399 ktype = "Private-Key";
400 else if (ptype == 1)
401 ktype = "Public-Key";
402 else
403 ktype = "DSA-Parameters";
404
405 update_buflen(x->p, &buf_len);
406 update_buflen(x->q, &buf_len);
407 update_buflen(x->g, &buf_len);
408 update_buflen(priv_key, &buf_len);
409 update_buflen(pub_key, &buf_len);
410
411 m = malloc(buf_len + 10);
412 if (m == NULL) {
413 DSAerr(DSA_F_DO_DSA_PRINT, ERR_R_MALLOC_FAILURE);
414 goto err;
415 }
416
417 if (priv_key) {
418 if (!BIO_indent(bp, off, 128))
419 goto err;
420 if (BIO_printf(bp, "%s: (%d bit)\n", ktype,
421 BN_num_bits(x->p)) <= 0)
422 goto err;
423 }
424
425 if (!ASN1_bn_print(bp, "priv:", priv_key, m, off))
426 goto err;
427 if (!ASN1_bn_print(bp, "pub: ", pub_key, m, off))
428 goto err;
429 if (!ASN1_bn_print(bp, "P: ", x->p, m, off))
430 goto err;
431 if (!ASN1_bn_print(bp, "Q: ", x->q, m, off))
432 goto err;
433 if (!ASN1_bn_print(bp, "G: ", x->g, m, off))
434 goto err;
435 ret = 1;
436err:
437 free(m);
438 return(ret);
439}
440
441static int
442dsa_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
443{
444 DSA *dsa;
445
446 if (!(dsa = d2i_DSAparams(NULL, pder, derlen))) {
447 DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB);
448 return 0;
449 }
450 EVP_PKEY_assign_DSA(pkey, dsa);
451 return 1;
452}
453
454static int
455dsa_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
456{
457 return i2d_DSAparams(pkey->pkey.dsa, pder);
458}
459
460static int
461dsa_param_print(BIO *bp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx)
462{
463 return do_dsa_print(bp, pkey->pkey.dsa, indent, 0);
464}
465
466static int
467dsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx)
468{
469 return do_dsa_print(bp, pkey->pkey.dsa, indent, 1);
470}
471
472static int
473dsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx)
474{
475 return do_dsa_print(bp, pkey->pkey.dsa, indent, 2);
476}
477
478static int
479old_dsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
480{
481 DSA *dsa;
482 BN_CTX *ctx = NULL;
483 BIGNUM *j, *p1, *newp1;
484
485 if (!(dsa = d2i_DSAPrivateKey(NULL, pder, derlen))) {
486 DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB);
487 return 0;
488 }
489
490 ctx = BN_CTX_new();
491 if (ctx == NULL)
492 goto err;
493
494 /*
495 * Check that p and q are consistent with each other.
496 */
497
498 j = BN_CTX_get(ctx);
499 p1 = BN_CTX_get(ctx);
500 newp1 = BN_CTX_get(ctx);
501 if (j == NULL || p1 == NULL || newp1 == NULL)
502 goto err;
503 /* p1 = p - 1 */
504 if (BN_sub(p1, dsa->p, BN_value_one()) == 0)
505 goto err;
506 /* j = (p - 1) / q */
507 if (BN_div(j, NULL, p1, dsa->q, ctx) == 0)
508 goto err;
509 /* q * j should == p - 1 */
510 if (BN_mul(newp1, dsa->q, j, ctx) == 0)
511 goto err;
512 if (BN_cmp(newp1, p1) != 0) {
513 DSAerr(DSA_F_DSA_PARAM_DECODE, DSA_R_BAD_Q_VALUE);
514 goto err;
515 }
516
517 /*
518 * Check that q is not a composite number.
519 */
520
521 if (BN_is_prime_ex(dsa->q, BN_prime_checks, ctx, NULL) == 0) {
522 DSAerr(DSA_F_DSA_PARAM_DECODE, DSA_R_BAD_Q_VALUE);
523 goto err;
524 }
525
526 BN_CTX_free(ctx);
527
528 EVP_PKEY_assign_DSA(pkey, dsa);
529 return 1;
530
531err:
532 BN_CTX_free(ctx);
533 DSA_free(dsa);
534 return 0;
535}
536
537static int
538old_dsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder)
539{
540 return i2d_DSAPrivateKey(pkey->pkey.dsa, pder);
541}
542
543static int
544dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig,
545 int indent, ASN1_PCTX *pctx)
546{
547 DSA_SIG *dsa_sig;
548 const unsigned char *p;
549
550 if (!sig) {
551 if (BIO_puts(bp, "\n") <= 0)
552 return 0;
553 else
554 return 1;
555 }
556 p = sig->data;
557 dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length);
558 if (dsa_sig) {
559 int rv = 0;
560 size_t buf_len = 0;
561 unsigned char *m = NULL;
562
563 update_buflen(dsa_sig->r, &buf_len);
564 update_buflen(dsa_sig->s, &buf_len);
565 m = malloc(buf_len + 10);
566 if (m == NULL) {
567 DSAerr(DSA_F_DSA_SIG_PRINT, ERR_R_MALLOC_FAILURE);
568 goto err;
569 }
570
571 if (BIO_write(bp, "\n", 1) != 1)
572 goto err;
573
574 if (!ASN1_bn_print(bp, "r: ", dsa_sig->r, m, indent))
575 goto err;
576 if (!ASN1_bn_print(bp, "s: ", dsa_sig->s, m, indent))
577 goto err;
578 rv = 1;
579err:
580 free(m);
581 DSA_SIG_free(dsa_sig);
582 return rv;
583 }
584 return X509_signature_dump(bp, sig, indent);
585}
586
587static int
588dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2)
589{
590 switch (op) {
591 case ASN1_PKEY_CTRL_PKCS7_SIGN:
592 if (arg1 == 0) {
593 int snid, hnid;
594 X509_ALGOR *alg1, *alg2;
595
596 PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2);
597 if (alg1 == NULL || alg1->algorithm == NULL)
598 return -1;
599 hnid = OBJ_obj2nid(alg1->algorithm);
600 if (hnid == NID_undef)
601 return -1;
602 if (!OBJ_find_sigid_by_algs(&snid, hnid,
603 EVP_PKEY_id(pkey)))
604 return -1;
605 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF,
606 0);
607 }
608 return 1;
609#ifndef OPENSSL_NO_CMS
610 case ASN1_PKEY_CTRL_CMS_SIGN:
611 if (arg1 == 0) {
612 int snid, hnid;
613 X509_ALGOR *alg1, *alg2;
614
615 CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2);
616 if (alg1 == NULL || alg1->algorithm == NULL)
617 return -1;
618 hnid = OBJ_obj2nid(alg1->algorithm);
619 if (hnid == NID_undef)
620 return -1;
621 if (!OBJ_find_sigid_by_algs(&snid, hnid,
622 EVP_PKEY_id(pkey)))
623 return -1;
624 X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF,
625 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/* NB these are sorted in pkey_id order, lowest first */
640
641const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] = {
642 {
643 .pkey_id = EVP_PKEY_DSA2,
644 .pkey_base_id = EVP_PKEY_DSA,
645 .pkey_flags = ASN1_PKEY_ALIAS
646 },
647
648 {
649 .pkey_id = EVP_PKEY_DSA1,
650 .pkey_base_id = EVP_PKEY_DSA,
651 .pkey_flags = ASN1_PKEY_ALIAS
652 },
653
654 {
655 .pkey_id = EVP_PKEY_DSA4,
656 .pkey_base_id = EVP_PKEY_DSA,
657 .pkey_flags = ASN1_PKEY_ALIAS
658 },
659
660 {
661 .pkey_id = EVP_PKEY_DSA3,
662 .pkey_base_id = EVP_PKEY_DSA,
663 .pkey_flags = ASN1_PKEY_ALIAS
664 },
665
666 {
667 .pkey_id = EVP_PKEY_DSA,
668 .pkey_base_id = EVP_PKEY_DSA,
669
670 .pem_str = "DSA",
671 .info = "OpenSSL DSA method",
672
673 .pub_decode = dsa_pub_decode,
674 .pub_encode = dsa_pub_encode,
675 .pub_cmp = dsa_pub_cmp,
676 .pub_print = dsa_pub_print,
677
678 .priv_decode = dsa_priv_decode,
679 .priv_encode = dsa_priv_encode,
680 .priv_print = dsa_priv_print,
681
682 .pkey_size = int_dsa_size,
683 .pkey_bits = dsa_bits,
684
685 .param_decode = dsa_param_decode,
686 .param_encode = dsa_param_encode,
687 .param_missing = dsa_missing_parameters,
688 .param_copy = dsa_copy_parameters,
689 .param_cmp = dsa_cmp_parameters,
690 .param_print = dsa_param_print,
691 .sig_print = dsa_sig_print,
692
693 .pkey_free = int_dsa_free,
694 .pkey_ctrl = dsa_pkey_ctrl,
695 .old_priv_decode = old_dsa_priv_decode,
696 .old_priv_encode = old_dsa_priv_encode
697 }
698};
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c
deleted file mode 100644
index 8c5d93105c..0000000000
--- a/src/lib/libcrypto/dsa/dsa_asn1.c
+++ /dev/null
@@ -1,439 +0,0 @@
1/* $OpenBSD: dsa_asn1.c,v 1.16 2015/02/14 15:06:55 jsing Exp $ */
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 <string.h>
61
62#include <openssl/asn1.h>
63#include <openssl/asn1t.h>
64#include <openssl/dsa.h>
65#include <openssl/err.h>
66
67/* Override the default new methods */
68static int
69sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
70{
71 if (operation == ASN1_OP_NEW_PRE) {
72 DSA_SIG *sig;
73
74 sig = malloc(sizeof(DSA_SIG));
75 if (!sig) {
76 DSAerr(DSA_F_SIG_CB, ERR_R_MALLOC_FAILURE);
77 return 0;
78 }
79 sig->r = NULL;
80 sig->s = NULL;
81 *pval = (ASN1_VALUE *)sig;
82 return 2;
83 }
84 return 1;
85}
86
87static const ASN1_AUX DSA_SIG_aux = {
88 .app_data = NULL,
89 .flags = 0,
90 .ref_offset = 0,
91 .ref_lock = 0,
92 .asn1_cb = sig_cb,
93 .enc_offset = 0,
94};
95static const ASN1_TEMPLATE DSA_SIG_seq_tt[] = {
96 {
97 .flags = 0,
98 .tag = 0,
99 .offset = offsetof(DSA_SIG, r),
100 .field_name = "r",
101 .item = &CBIGNUM_it,
102 },
103 {
104 .flags = 0,
105 .tag = 0,
106 .offset = offsetof(DSA_SIG, s),
107 .field_name = "s",
108 .item = &CBIGNUM_it,
109 },
110};
111
112const ASN1_ITEM DSA_SIG_it = {
113 .itype = ASN1_ITYPE_SEQUENCE,
114 .utype = V_ASN1_SEQUENCE,
115 .templates = DSA_SIG_seq_tt,
116 .tcount = sizeof(DSA_SIG_seq_tt) / sizeof(ASN1_TEMPLATE),
117 .funcs = &DSA_SIG_aux,
118 .size = sizeof(DSA_SIG),
119 .sname = "DSA_SIG",
120};
121
122
123DSA_SIG *
124d2i_DSA_SIG(DSA_SIG **a, const unsigned char **in, long len)
125{
126 return (DSA_SIG *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
127 &DSA_SIG_it);
128}
129
130int
131i2d_DSA_SIG(const DSA_SIG *a, unsigned char **out)
132{
133 return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSA_SIG_it);
134}
135
136/* Override the default free and new methods */
137static int
138dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
139{
140 if (operation == ASN1_OP_NEW_PRE) {
141 *pval = (ASN1_VALUE *)DSA_new();
142 if (*pval)
143 return 2;
144 return 0;
145 } else if (operation == ASN1_OP_FREE_PRE) {
146 DSA_free((DSA *)*pval);
147 *pval = NULL;
148 return 2;
149 }
150 return 1;
151}
152
153static const ASN1_AUX DSAPrivateKey_aux = {
154 .app_data = NULL,
155 .flags = 0,
156 .ref_offset = 0,
157 .ref_lock = 0,
158 .asn1_cb = dsa_cb,
159 .enc_offset = 0,
160};
161static const ASN1_TEMPLATE DSAPrivateKey_seq_tt[] = {
162 {
163 .flags = 0,
164 .tag = 0,
165 .offset = offsetof(DSA, version),
166 .field_name = "version",
167 .item = &LONG_it,
168 },
169 {
170 .flags = 0,
171 .tag = 0,
172 .offset = offsetof(DSA, p),
173 .field_name = "p",
174 .item = &BIGNUM_it,
175 },
176 {
177 .flags = 0,
178 .tag = 0,
179 .offset = offsetof(DSA, q),
180 .field_name = "q",
181 .item = &BIGNUM_it,
182 },
183 {
184 .flags = 0,
185 .tag = 0,
186 .offset = offsetof(DSA, g),
187 .field_name = "g",
188 .item = &BIGNUM_it,
189 },
190 {
191 .flags = 0,
192 .tag = 0,
193 .offset = offsetof(DSA, pub_key),
194 .field_name = "pub_key",
195 .item = &BIGNUM_it,
196 },
197 {
198 .flags = 0,
199 .tag = 0,
200 .offset = offsetof(DSA, priv_key),
201 .field_name = "priv_key",
202 .item = &BIGNUM_it,
203 },
204};
205
206const ASN1_ITEM DSAPrivateKey_it = {
207 .itype = ASN1_ITYPE_SEQUENCE,
208 .utype = V_ASN1_SEQUENCE,
209 .templates = DSAPrivateKey_seq_tt,
210 .tcount = sizeof(DSAPrivateKey_seq_tt) / sizeof(ASN1_TEMPLATE),
211 .funcs = &DSAPrivateKey_aux,
212 .size = sizeof(DSA),
213 .sname = "DSA",
214};
215
216
217DSA *
218d2i_DSAPrivateKey(DSA **a, const unsigned char **in, long len)
219{
220 return (DSA *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
221 &DSAPrivateKey_it);
222}
223
224int
225i2d_DSAPrivateKey(const DSA *a, unsigned char **out)
226{
227 return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAPrivateKey_it);
228}
229
230static const ASN1_AUX DSAparams_aux = {
231 .app_data = NULL,
232 .flags = 0,
233 .ref_offset = 0,
234 .ref_lock = 0,
235 .asn1_cb = dsa_cb,
236 .enc_offset = 0,
237};
238static const ASN1_TEMPLATE DSAparams_seq_tt[] = {
239 {
240 .flags = 0,
241 .tag = 0,
242 .offset = offsetof(DSA, p),
243 .field_name = "p",
244 .item = &BIGNUM_it,
245 },
246 {
247 .flags = 0,
248 .tag = 0,
249 .offset = offsetof(DSA, q),
250 .field_name = "q",
251 .item = &BIGNUM_it,
252 },
253 {
254 .flags = 0,
255 .tag = 0,
256 .offset = offsetof(DSA, g),
257 .field_name = "g",
258 .item = &BIGNUM_it,
259 },
260};
261
262const ASN1_ITEM DSAparams_it = {
263 .itype = ASN1_ITYPE_SEQUENCE,
264 .utype = V_ASN1_SEQUENCE,
265 .templates = DSAparams_seq_tt,
266 .tcount = sizeof(DSAparams_seq_tt) / sizeof(ASN1_TEMPLATE),
267 .funcs = &DSAparams_aux,
268 .size = sizeof(DSA),
269 .sname = "DSA",
270};
271
272
273DSA *
274d2i_DSAparams(DSA **a, const unsigned char **in, long len)
275{
276 return (DSA *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
277 &DSAparams_it);
278}
279
280int
281i2d_DSAparams(const DSA *a, unsigned char **out)
282{
283 return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAparams_it);
284}
285
286/*
287 * DSA public key is a bit trickier... its effectively a CHOICE type
288 * decided by a field called write_params which can either write out
289 * just the public key as an INTEGER or the parameters and public key
290 * in a SEQUENCE
291 */
292
293static const ASN1_TEMPLATE dsa_pub_internal_seq_tt[] = {
294 {
295 .flags = 0,
296 .tag = 0,
297 .offset = offsetof(DSA, pub_key),
298 .field_name = "pub_key",
299 .item = &BIGNUM_it,
300 },
301 {
302 .flags = 0,
303 .tag = 0,
304 .offset = offsetof(DSA, p),
305 .field_name = "p",
306 .item = &BIGNUM_it,
307 },
308 {
309 .flags = 0,
310 .tag = 0,
311 .offset = offsetof(DSA, q),
312 .field_name = "q",
313 .item = &BIGNUM_it,
314 },
315 {
316 .flags = 0,
317 .tag = 0,
318 .offset = offsetof(DSA, g),
319 .field_name = "g",
320 .item = &BIGNUM_it,
321 },
322};
323
324const ASN1_ITEM dsa_pub_internal_it = {
325 .itype = ASN1_ITYPE_SEQUENCE,
326 .utype = V_ASN1_SEQUENCE,
327 .templates = dsa_pub_internal_seq_tt,
328 .tcount = sizeof(dsa_pub_internal_seq_tt) / sizeof(ASN1_TEMPLATE),
329 .funcs = NULL,
330 .size = sizeof(DSA),
331 .sname = "DSA",
332};
333
334static const ASN1_AUX DSAPublicKey_aux = {
335 .app_data = NULL,
336 .flags = 0,
337 .ref_offset = 0,
338 .ref_lock = 0,
339 .asn1_cb = dsa_cb,
340 .enc_offset = 0,
341};
342static const ASN1_TEMPLATE DSAPublicKey_ch_tt[] = {
343 {
344 .flags = 0,
345 .tag = 0,
346 .offset = offsetof(DSA, pub_key),
347 .field_name = "pub_key",
348 .item = &BIGNUM_it,
349 },
350 {
351 .flags = 0 | ASN1_TFLG_COMBINE,
352 .tag = 0,
353 .offset = 0,
354 .field_name = NULL,
355 .item = &dsa_pub_internal_it,
356 },
357};
358
359const ASN1_ITEM DSAPublicKey_it = {
360 .itype = ASN1_ITYPE_CHOICE,
361 .utype = offsetof(DSA, write_params),
362 .templates = DSAPublicKey_ch_tt,
363 .tcount = sizeof(DSAPublicKey_ch_tt) / sizeof(ASN1_TEMPLATE),
364 .funcs = &DSAPublicKey_aux,
365 .size = sizeof(DSA),
366 .sname = "DSA",
367};
368
369
370DSA *
371d2i_DSAPublicKey(DSA **a, const unsigned char **in, long len)
372{
373 return (DSA *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
374 &DSAPublicKey_it);
375}
376
377int
378i2d_DSAPublicKey(const DSA *a, unsigned char **out)
379{
380 return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAPublicKey_it);
381}
382
383DSA *
384DSAparams_dup(DSA *dsa)
385{
386 return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa);
387}
388
389int
390DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
391 unsigned int *siglen, DSA *dsa)
392{
393 DSA_SIG *s;
394
395 s = DSA_do_sign(dgst, dlen, dsa);
396 if (s == NULL) {
397 *siglen = 0;
398 return 0;
399 }
400 *siglen = i2d_DSA_SIG(s,&sig);
401 DSA_SIG_free(s);
402 return 1;
403}
404
405/*
406 * data has already been hashed (probably with SHA or SHA-1).
407 * returns
408 * 1: correct signature
409 * 0: incorrect signature
410 * -1: error
411 */
412int
413DSA_verify(int type, const unsigned char *dgst, int dgst_len,
414 const unsigned char *sigbuf, int siglen, DSA *dsa)
415{
416 DSA_SIG *s;
417 unsigned char *der = NULL;
418 const unsigned char *p = sigbuf;
419 int derlen = -1;
420 int ret = -1;
421
422 s = DSA_SIG_new();
423 if (s == NULL)
424 return ret;
425 if (d2i_DSA_SIG(&s, &p, siglen) == NULL)
426 goto err;
427 /* Ensure signature uses DER and doesn't have trailing garbage */
428 derlen = i2d_DSA_SIG(s, &der);
429 if (derlen != siglen || memcmp(sigbuf, der, derlen))
430 goto err;
431 ret = DSA_do_verify(dgst, dgst_len, s, dsa);
432err:
433 if (derlen > 0) {
434 explicit_bzero(der, derlen);
435 free(der);
436 }
437 DSA_SIG_free(s);
438 return ret;
439}
diff --git a/src/lib/libcrypto/dsa/dsa_depr.c b/src/lib/libcrypto/dsa/dsa_depr.c
deleted file mode 100644
index 269cd63450..0000000000
--- a/src/lib/libcrypto/dsa/dsa_depr.c
+++ /dev/null
@@ -1,92 +0,0 @@
1/* $OpenBSD: dsa_depr.c,v 1.7 2014/10/18 17:20:40 jsing Exp $ */
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#include <stdio.h>
60#include <time.h>
61
62#include <openssl/opensslconf.h>
63
64#ifndef OPENSSL_NO_SHA
65
66#include <openssl/bn.h>
67#include <openssl/dsa.h>
68#include <openssl/evp.h>
69#include <openssl/sha.h>
70
71#ifndef OPENSSL_NO_DEPRECATED
72DSA *
73DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len,
74 int *counter_ret, unsigned long *h_ret, void (*callback)(int, int, void *),
75 void *cb_arg)
76{
77 BN_GENCB cb;
78 DSA *ret;
79
80 if ((ret = DSA_new()) == NULL)
81 return NULL;
82
83 BN_GENCB_set_old(&cb, callback, cb_arg);
84
85 if (DSA_generate_parameters_ex(ret, bits, seed_in, seed_len,
86 counter_ret, h_ret, &cb))
87 return ret;
88 DSA_free(ret);
89 return NULL;
90}
91#endif
92#endif
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
deleted file mode 100644
index b116b643c3..0000000000
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ /dev/null
@@ -1,133 +0,0 @@
1/* $OpenBSD: dsa_err.c,v 1.14 2014/07/10 22:45:56 jsing Exp $ */
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
63#include <openssl/opensslconf.h>
64
65#include <openssl/err.h>
66#include <openssl/dsa.h>
67
68/* BEGIN ERROR CODES */
69#ifndef OPENSSL_NO_ERR
70
71#define ERR_FUNC(func) ERR_PACK(ERR_LIB_DSA,func,0)
72#define ERR_REASON(reason) ERR_PACK(ERR_LIB_DSA,0,reason)
73
74static ERR_STRING_DATA DSA_str_functs[]=
75 {
76{ERR_FUNC(DSA_F_D2I_DSA_SIG), "d2i_DSA_SIG"},
77{ERR_FUNC(DSA_F_DO_DSA_PRINT), "DO_DSA_PRINT"},
78{ERR_FUNC(DSA_F_DSAPARAMS_PRINT), "DSAparams_print"},
79{ERR_FUNC(DSA_F_DSAPARAMS_PRINT_FP), "DSAparams_print_fp"},
80{ERR_FUNC(DSA_F_DSA_DO_SIGN), "DSA_do_sign"},
81{ERR_FUNC(DSA_F_DSA_DO_VERIFY), "DSA_do_verify"},
82{ERR_FUNC(DSA_F_DSA_GENERATE_KEY), "DSA_generate_key"},
83{ERR_FUNC(DSA_F_DSA_GENERATE_PARAMETERS_EX), "DSA_generate_parameters_ex"},
84{ERR_FUNC(DSA_F_DSA_NEW_METHOD), "DSA_new_method"},
85{ERR_FUNC(DSA_F_DSA_PARAM_DECODE), "DSA_PARAM_DECODE"},
86{ERR_FUNC(DSA_F_DSA_PRINT_FP), "DSA_print_fp"},
87{ERR_FUNC(DSA_F_DSA_PRIV_DECODE), "DSA_PRIV_DECODE"},
88{ERR_FUNC(DSA_F_DSA_PRIV_ENCODE), "DSA_PRIV_ENCODE"},
89{ERR_FUNC(DSA_F_DSA_PUB_DECODE), "DSA_PUB_DECODE"},
90{ERR_FUNC(DSA_F_DSA_PUB_ENCODE), "DSA_PUB_ENCODE"},
91{ERR_FUNC(DSA_F_DSA_SIGN), "DSA_sign"},
92{ERR_FUNC(DSA_F_DSA_SIGN_SETUP), "DSA_sign_setup"},
93{ERR_FUNC(DSA_F_DSA_SIG_NEW), "DSA_SIG_new"},
94{ERR_FUNC(DSA_F_DSA_SIG_PRINT), "DSA_SIG_PRINT"},
95{ERR_FUNC(DSA_F_DSA_VERIFY), "DSA_verify"},
96{ERR_FUNC(DSA_F_I2D_DSA_SIG), "i2d_DSA_SIG"},
97{ERR_FUNC(DSA_F_OLD_DSA_PRIV_DECODE), "OLD_DSA_PRIV_DECODE"},
98{ERR_FUNC(DSA_F_PKEY_DSA_CTRL), "PKEY_DSA_CTRL"},
99{ERR_FUNC(DSA_F_PKEY_DSA_KEYGEN), "PKEY_DSA_KEYGEN"},
100{ERR_FUNC(DSA_F_SIG_CB), "SIG_CB"},
101{0,NULL}
102 };
103
104static ERR_STRING_DATA DSA_str_reasons[]=
105 {
106{ERR_REASON(DSA_R_BAD_Q_VALUE) ,"bad q value"},
107{ERR_REASON(DSA_R_BN_DECODE_ERROR) ,"bn decode error"},
108{ERR_REASON(DSA_R_BN_ERROR) ,"bn error"},
109{ERR_REASON(DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE),"data too large for key size"},
110{ERR_REASON(DSA_R_DECODE_ERROR) ,"decode error"},
111{ERR_REASON(DSA_R_INVALID_DIGEST_TYPE) ,"invalid digest type"},
112{ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"},
113{ERR_REASON(DSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
114{ERR_REASON(DSA_R_NEED_NEW_SETUP_VALUES) ,"need new setup values"},
115{ERR_REASON(DSA_R_NON_FIPS_DSA_METHOD) ,"non fips dsa method"},
116{ERR_REASON(DSA_R_NO_PARAMETERS_SET) ,"no parameters set"},
117{ERR_REASON(DSA_R_PARAMETER_ENCODING_ERROR),"parameter encoding error"},
118{0,NULL}
119 };
120
121#endif
122
123void ERR_load_DSA_strings(void)
124 {
125#ifndef OPENSSL_NO_ERR
126
127 if (ERR_func_error_string(DSA_str_functs[0].error) == NULL)
128 {
129 ERR_load_strings(0,DSA_str_functs);
130 ERR_load_strings(0,DSA_str_reasons);
131 }
132#endif
133 }
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
deleted file mode 100644
index 7ddb7fec5e..0000000000
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ /dev/null
@@ -1,357 +0,0 @@
1/* $OpenBSD: dsa_gen.c,v 1.22 2015/07/15 18:34:37 miod Exp $ */
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 <openssl/opensslconf.h> /* To see if OPENSSL_NO_SHA is defined */
60
61#ifndef OPENSSL_NO_SHA
62
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66
67#include <openssl/bn.h>
68#include <openssl/evp.h>
69#include <openssl/sha.h>
70
71#include "dsa_locl.h"
72
73int
74DSA_generate_parameters_ex(DSA *ret, int bits, const unsigned char *seed_in,
75 int seed_len, int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
76{
77 if (ret->meth->dsa_paramgen)
78 return ret->meth->dsa_paramgen(ret, bits, seed_in, seed_len,
79 counter_ret, h_ret, cb);
80 else {
81 const EVP_MD *evpmd;
82 size_t qbits;
83
84 if (bits >= 2048) {
85 qbits = 256;
86 evpmd = EVP_sha256();
87 } else {
88 qbits = 160;
89 evpmd = EVP_sha1();
90 }
91
92 return dsa_builtin_paramgen(ret, bits, qbits, evpmd, seed_in,
93 seed_len, NULL, counter_ret, h_ret, cb);
94 }
95}
96
97int
98dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits, const EVP_MD *evpmd,
99 const unsigned char *seed_in, size_t seed_len, unsigned char *seed_out,
100 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
101{
102 int ok = 0;
103 unsigned char seed[SHA256_DIGEST_LENGTH];
104 unsigned char md[SHA256_DIGEST_LENGTH];
105 unsigned char buf[SHA256_DIGEST_LENGTH], buf2[SHA256_DIGEST_LENGTH];
106 BIGNUM *r0, *W, *X, *c, *test;
107 BIGNUM *g = NULL, *q = NULL, *p = NULL;
108 BN_MONT_CTX *mont = NULL;
109 int i, k, n = 0, m = 0, qsize = qbits >> 3;
110 int counter = 0;
111 int r = 0;
112 BN_CTX *ctx = NULL;
113 unsigned int h = 2;
114
115 if (qsize != SHA_DIGEST_LENGTH && qsize != SHA224_DIGEST_LENGTH &&
116 qsize != SHA256_DIGEST_LENGTH)
117 /* invalid q size */
118 return 0;
119
120 if (evpmd == NULL)
121 /* use SHA1 as default */
122 evpmd = EVP_sha1();
123
124 if (bits < 512)
125 bits = 512;
126
127 bits = (bits + 63) / 64 * 64;
128
129 if (seed_len < (size_t)qsize) {
130 seed_in = NULL; /* seed buffer too small -- ignore */
131 seed_len = 0;
132 }
133 /*
134 * App. 2.2 of FIPS PUB 186 allows larger SEED,
135 * but our internal buffers are restricted to 160 bits
136 */
137 if (seed_len > (size_t)qsize)
138 seed_len = qsize;
139 if (seed_in != NULL)
140 memcpy(seed, seed_in, seed_len);
141 else if (seed_len != 0)
142 goto err;
143
144 if ((mont=BN_MONT_CTX_new()) == NULL)
145 goto err;
146
147 if ((ctx=BN_CTX_new()) == NULL)
148 goto err;
149 BN_CTX_start(ctx);
150
151 if ((r0 = BN_CTX_get(ctx)) == NULL)
152 goto err;
153 if ((g = BN_CTX_get(ctx)) == NULL)
154 goto err;
155 if ((W = BN_CTX_get(ctx)) == NULL)
156 goto err;
157 if ((q = BN_CTX_get(ctx)) == NULL)
158 goto err;
159 if ((X = BN_CTX_get(ctx)) == NULL)
160 goto err;
161 if ((c = BN_CTX_get(ctx)) == NULL)
162 goto err;
163 if ((p = BN_CTX_get(ctx)) == NULL)
164 goto err;
165 if ((test = BN_CTX_get(ctx)) == NULL)
166 goto err;
167
168 if (!BN_lshift(test, BN_value_one(), bits - 1))
169 goto err;
170
171 for (;;) {
172 for (;;) { /* find q */
173 int seed_is_random;
174
175 /* step 1 */
176 if (!BN_GENCB_call(cb, 0, m++))
177 goto err;
178
179 if (seed_len == 0) {
180 arc4random_buf(seed, qsize);
181 seed_is_random = 1;
182 } else {
183 seed_is_random = 0;
184 /* use random seed if 'seed_in' turns out
185 to be bad */
186 seed_len = 0;
187 }
188 memcpy(buf, seed, qsize);
189 memcpy(buf2, seed, qsize);
190 /* precompute "SEED + 1" for step 7: */
191 for (i = qsize - 1; i >= 0; i--) {
192 buf[i]++;
193 if (buf[i] != 0)
194 break;
195 }
196
197 /* step 2 */
198 if (!EVP_Digest(seed, qsize, md, NULL, evpmd, NULL))
199 goto err;
200 if (!EVP_Digest(buf, qsize, buf2, NULL, evpmd, NULL))
201 goto err;
202 for (i = 0; i < qsize; i++)
203 md[i] ^= buf2[i];
204
205 /* step 3 */
206 md[0] |= 0x80;
207 md[qsize - 1] |= 0x01;
208 if (!BN_bin2bn(md, qsize, q))
209 goto err;
210
211 /* step 4 */
212 r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx,
213 seed_is_random, cb);
214 if (r > 0)
215 break;
216 if (r != 0)
217 goto err;
218
219 /* do a callback call */
220 /* step 5 */
221 }
222
223 if (!BN_GENCB_call(cb, 2, 0))
224 goto err;
225 if (!BN_GENCB_call(cb, 3, 0))
226 goto err;
227
228 /* step 6 */
229 counter = 0;
230 /* "offset = 2" */
231
232 n = (bits - 1) / 160;
233
234 for (;;) {
235 if (counter != 0 && !BN_GENCB_call(cb, 0, counter))
236 goto err;
237
238 /* step 7 */
239 BN_zero(W);
240 /* now 'buf' contains "SEED + offset - 1" */
241 for (k = 0; k <= n; k++) {
242 /* obtain "SEED + offset + k" by incrementing: */
243 for (i = qsize - 1; i >= 0; i--) {
244 buf[i]++;
245 if (buf[i] != 0)
246 break;
247 }
248
249 if (!EVP_Digest(buf, qsize, md ,NULL, evpmd,
250 NULL))
251 goto err;
252
253 /* step 8 */
254 if (!BN_bin2bn(md, qsize, r0))
255 goto err;
256 if (!BN_lshift(r0, r0, (qsize << 3) * k))
257 goto err;
258 if (!BN_add(W, W, r0))
259 goto err;
260 }
261
262 /* more of step 8 */
263 if (!BN_mask_bits(W, bits - 1))
264 goto err;
265 if (!BN_copy(X, W))
266 goto err;
267 if (!BN_add(X, X, test))
268 goto err;
269
270 /* step 9 */
271 if (!BN_lshift1(r0, q))
272 goto err;
273 if (!BN_mod(c, X, r0, ctx))
274 goto err;
275 if (!BN_sub(r0, c, BN_value_one()))
276 goto err;
277 if (!BN_sub(p, X, r0))
278 goto err;
279
280 /* step 10 */
281 if (BN_cmp(p, test) >= 0) {
282 /* step 11 */
283 r = BN_is_prime_fasttest_ex(p, DSS_prime_checks,
284 ctx, 1, cb);
285 if (r > 0)
286 goto end; /* found it */
287 if (r != 0)
288 goto err;
289 }
290
291 /* step 13 */
292 counter++;
293 /* "offset = offset + n + 1" */
294
295 /* step 14 */
296 if (counter >= 4096)
297 break;
298 }
299 }
300end:
301 if (!BN_GENCB_call(cb, 2, 1))
302 goto err;
303
304 /* We now need to generate g */
305 /* Set r0=(p-1)/q */
306 if (!BN_sub(test, p, BN_value_one()))
307 goto err;
308 if (!BN_div(r0, NULL, test, q, ctx))
309 goto err;
310
311 if (!BN_set_word(test, h))
312 goto err;
313 if (!BN_MONT_CTX_set(mont, p, ctx))
314 goto err;
315
316 for (;;) {
317 /* g=test^r0%p */
318 if (!BN_mod_exp_mont(g, test, r0, p, ctx, mont))
319 goto err;
320 if (!BN_is_one(g))
321 break;
322 if (!BN_add(test, test, BN_value_one()))
323 goto err;
324 h++;
325 }
326
327 if (!BN_GENCB_call(cb, 3, 1))
328 goto err;
329
330 ok = 1;
331err:
332 if (ok) {
333 BN_free(ret->p);
334 BN_free(ret->q);
335 BN_free(ret->g);
336 ret->p = BN_dup(p);
337 ret->q = BN_dup(q);
338 ret->g = BN_dup(g);
339 if (ret->p == NULL || ret->q == NULL || ret->g == NULL) {
340 ok = 0;
341 goto err;
342 }
343 if (counter_ret != NULL)
344 *counter_ret = counter;
345 if (h_ret != NULL)
346 *h_ret = h;
347 if (seed_out != NULL)
348 memcpy(seed_out, seed, qsize);
349 }
350 if (ctx) {
351 BN_CTX_end(ctx);
352 BN_CTX_free(ctx);
353 }
354 BN_MONT_CTX_free(mont);
355 return ok;
356}
357#endif
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
deleted file mode 100644
index fc4eb9c433..0000000000
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ /dev/null
@@ -1,127 +0,0 @@
1/* $OpenBSD: dsa_key.c,v 1.22 2016/06/30 02:02:06 bcook Exp $ */
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
62#include <openssl/opensslconf.h>
63
64#ifndef OPENSSL_NO_SHA
65
66#include <openssl/bn.h>
67#include <openssl/dsa.h>
68
69static int dsa_builtin_keygen(DSA *dsa);
70
71int
72DSA_generate_key(DSA *dsa)
73{
74 if (dsa->meth->dsa_keygen)
75 return dsa->meth->dsa_keygen(dsa);
76 return dsa_builtin_keygen(dsa);
77}
78
79static int
80dsa_builtin_keygen(DSA *dsa)
81{
82 int ok = 0;
83 BN_CTX *ctx = NULL;
84 BIGNUM *pub_key = NULL, *priv_key = NULL;
85
86 if ((ctx = BN_CTX_new()) == NULL)
87 goto err;
88
89 if (dsa->priv_key == NULL) {
90 if ((priv_key = BN_new()) == NULL)
91 goto err;
92 } else
93 priv_key=dsa->priv_key;
94
95 do {
96 if (!BN_rand_range(priv_key, dsa->q))
97 goto err;
98 } while (BN_is_zero(priv_key));
99
100 if (dsa->pub_key == NULL) {
101 if ((pub_key = BN_new()) == NULL)
102 goto err;
103 } else
104 pub_key=dsa->pub_key;
105
106 {
107 BIGNUM prk;
108
109 BN_with_flags(&prk, priv_key, BN_FLG_CONSTTIME);
110
111 if (!BN_mod_exp(pub_key, dsa->g, &prk, dsa->p, ctx))
112 goto err;
113 }
114
115 dsa->priv_key = priv_key;
116 dsa->pub_key = pub_key;
117 ok = 1;
118
119err:
120 if (pub_key != NULL && dsa->pub_key == NULL)
121 BN_free(pub_key);
122 if (priv_key != NULL && dsa->priv_key == NULL)
123 BN_free(priv_key);
124 BN_CTX_free(ctx);
125 return ok;
126}
127#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
deleted file mode 100644
index 8016f2f7cb..0000000000
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ /dev/null
@@ -1,305 +0,0 @@
1/* $OpenBSD: dsa_lib.c,v 1.22 2015/02/11 03:19:37 doug Exp $ */
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
63#include <openssl/opensslconf.h>
64
65#include <openssl/asn1.h>
66#include <openssl/bn.h>
67#include <openssl/dsa.h>
68#include <openssl/err.h>
69
70#ifndef OPENSSL_NO_DH
71#include <openssl/dh.h>
72#endif
73#ifndef OPENSSL_NO_ENGINE
74#include <openssl/engine.h>
75#endif
76
77static const DSA_METHOD *default_DSA_method = NULL;
78
79void
80DSA_set_default_method(const DSA_METHOD *meth)
81{
82 default_DSA_method = meth;
83}
84
85const DSA_METHOD *
86DSA_get_default_method(void)
87{
88 if (!default_DSA_method)
89 default_DSA_method = DSA_OpenSSL();
90 return default_DSA_method;
91}
92
93DSA *
94DSA_new(void)
95{
96 return DSA_new_method(NULL);
97}
98
99int
100DSA_set_method(DSA *dsa, const DSA_METHOD *meth)
101{
102 /*
103 * NB: The caller is specifically setting a method, so it's not up to us
104 * to deal with which ENGINE it comes from.
105 */
106 const DSA_METHOD *mtmp;
107 mtmp = dsa->meth;
108 if (mtmp->finish)
109 mtmp->finish(dsa);
110#ifndef OPENSSL_NO_ENGINE
111 if (dsa->engine) {
112 ENGINE_finish(dsa->engine);
113 dsa->engine = NULL;
114 }
115#endif
116 dsa->meth = meth;
117 if (meth->init)
118 meth->init(dsa);
119 return 1;
120}
121
122DSA *
123DSA_new_method(ENGINE *engine)
124{
125 DSA *ret;
126
127 ret = malloc(sizeof(DSA));
128 if (ret == NULL) {
129 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_MALLOC_FAILURE);
130 return NULL;
131 }
132 ret->meth = DSA_get_default_method();
133#ifndef OPENSSL_NO_ENGINE
134 if (engine) {
135 if (!ENGINE_init(engine)) {
136 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
137 free(ret);
138 return NULL;
139 }
140 ret->engine = engine;
141 } else
142 ret->engine = ENGINE_get_default_DSA();
143 if (ret->engine) {
144 ret->meth = ENGINE_get_DSA(ret->engine);
145 if (!ret->meth) {
146 DSAerr(DSA_F_DSA_NEW_METHOD, ERR_R_ENGINE_LIB);
147 ENGINE_finish(ret->engine);
148 free(ret);
149 return NULL;
150 }
151 }
152#endif
153
154 ret->pad = 0;
155 ret->version = 0;
156 ret->write_params = 1;
157 ret->p = NULL;
158 ret->q = NULL;
159 ret->g = NULL;
160
161 ret->pub_key = NULL;
162 ret->priv_key = NULL;
163
164 ret->kinv = NULL;
165 ret->r = NULL;
166 ret->method_mont_p = NULL;
167
168 ret->references = 1;
169 ret->flags = ret->meth->flags & ~DSA_FLAG_NON_FIPS_ALLOW;
170 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
171 if (ret->meth->init != NULL && !ret->meth->init(ret)) {
172#ifndef OPENSSL_NO_ENGINE
173 if (ret->engine)
174 ENGINE_finish(ret->engine);
175#endif
176 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, ret, &ret->ex_data);
177 free(ret);
178 ret = NULL;
179 }
180
181 return ret;
182}
183
184void
185DSA_free(DSA *r)
186{
187 int i;
188
189 if (r == NULL)
190 return;
191
192 i = CRYPTO_add(&r->references, -1, CRYPTO_LOCK_DSA);
193 if (i > 0)
194 return;
195
196 if (r->meth->finish)
197 r->meth->finish(r);
198#ifndef OPENSSL_NO_ENGINE
199 if (r->engine)
200 ENGINE_finish(r->engine);
201#endif
202
203 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_DSA, r, &r->ex_data);
204
205 BN_clear_free(r->p);
206 BN_clear_free(r->q);
207 BN_clear_free(r->g);
208 BN_clear_free(r->pub_key);
209 BN_clear_free(r->priv_key);
210 BN_clear_free(r->kinv);
211 BN_clear_free(r->r);
212 free(r);
213}
214
215int
216DSA_up_ref(DSA *r)
217{
218 int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA);
219 return i > 1 ? 1 : 0;
220}
221
222int
223DSA_size(const DSA *r)
224{
225 int ret, i;
226 ASN1_INTEGER bs;
227 unsigned char buf[4]; /* 4 bytes looks really small.
228 However, i2d_ASN1_INTEGER() will not look
229 beyond the first byte, as long as the second
230 parameter is NULL. */
231
232 i = BN_num_bits(r->q);
233 bs.length = (i + 7) / 8;
234 bs.data = buf;
235 bs.type = V_ASN1_INTEGER;
236 /* If the top bit is set the asn1 encoding is 1 larger. */
237 buf[0] = 0xff;
238
239 i = i2d_ASN1_INTEGER(&bs, NULL);
240 i += i; /* r and s */
241 ret = ASN1_object_size(1, i, V_ASN1_SEQUENCE);
242 return ret;
243}
244
245int
246DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
247 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
248{
249 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, argl, argp,
250 new_func, dup_func, free_func);
251}
252
253int
254DSA_set_ex_data(DSA *d, int idx, void *arg)
255{
256 return CRYPTO_set_ex_data(&d->ex_data, idx, arg);
257}
258
259void *
260DSA_get_ex_data(DSA *d, int idx)
261{
262 return CRYPTO_get_ex_data(&d->ex_data, idx);
263}
264
265#ifndef OPENSSL_NO_DH
266DH *
267DSA_dup_DH(const DSA *r)
268{
269 /*
270 * DSA has p, q, g, optional pub_key, optional priv_key.
271 * DH has p, optional length, g, optional pub_key, optional priv_key,
272 * optional q.
273 */
274 DH *ret = NULL;
275
276 if (r == NULL)
277 goto err;
278 ret = DH_new();
279 if (ret == NULL)
280 goto err;
281 if (r->p != NULL)
282 if ((ret->p = BN_dup(r->p)) == NULL)
283 goto err;
284 if (r->q != NULL) {
285 ret->length = BN_num_bits(r->q);
286 if ((ret->q = BN_dup(r->q)) == NULL)
287 goto err;
288 }
289 if (r->g != NULL)
290 if ((ret->g = BN_dup(r->g)) == NULL)
291 goto err;
292 if (r->pub_key != NULL)
293 if ((ret->pub_key = BN_dup(r->pub_key)) == NULL)
294 goto err;
295 if (r->priv_key != NULL)
296 if ((ret->priv_key = BN_dup(r->priv_key)) == NULL)
297 goto err;
298
299 return ret;
300
301err:
302 DH_free(ret);
303 return NULL;
304}
305#endif
diff --git a/src/lib/libcrypto/dsa/dsa_locl.h b/src/lib/libcrypto/dsa/dsa_locl.h
deleted file mode 100644
index c65a2f20cf..0000000000
--- a/src/lib/libcrypto/dsa/dsa_locl.h
+++ /dev/null
@@ -1,61 +0,0 @@
1/* $OpenBSD: dsa_locl.h,v 1.2 2014/06/12 15:49:28 deraadt Exp $ */
2/* ====================================================================
3 * Copyright (c) 2007 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#include <openssl/dsa.h>
57
58int dsa_builtin_paramgen(DSA *ret, size_t bits, size_t qbits,
59 const EVP_MD *evpmd, const unsigned char *seed_in, size_t seed_len,
60 unsigned char *seed_out,
61 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 a28d3e9d1a..0000000000
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ /dev/null
@@ -1,385 +0,0 @@
1/* $OpenBSD: dsa_ossl.c,v 1.26 2016/06/21 04:16:53 bcook Exp $ */
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
63#include <openssl/asn1.h>
64#include <openssl/bn.h>
65#include <openssl/dsa.h>
66#include <openssl/err.h>
67#include <openssl/sha.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,
71 BIGNUM **rp);
72static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
73 DSA *dsa);
74static int dsa_init(DSA *dsa);
75static int dsa_finish(DSA *dsa);
76
77static DSA_METHOD openssl_dsa_meth = {
78 .name = "OpenSSL DSA method",
79 .dsa_do_sign = dsa_do_sign,
80 .dsa_sign_setup = dsa_sign_setup,
81 .dsa_do_verify = dsa_do_verify,
82 .init = dsa_init,
83 .finish = dsa_finish
84};
85
86const DSA_METHOD *
87DSA_OpenSSL(void)
88{
89 return &openssl_dsa_meth;
90}
91
92static DSA_SIG *
93dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
94{
95 BIGNUM *kinv = NULL, *r = NULL, *s = NULL;
96 BIGNUM m;
97 BIGNUM xr;
98 BN_CTX *ctx = NULL;
99 int reason = ERR_R_BN_LIB;
100 DSA_SIG *ret = NULL;
101 int noredo = 0;
102
103 BN_init(&m);
104 BN_init(&xr);
105
106 if (!dsa->p || !dsa->q || !dsa->g) {
107 reason = DSA_R_MISSING_PARAMETERS;
108 goto err;
109 }
110
111 s = BN_new();
112 if (s == NULL)
113 goto err;
114 ctx = BN_CTX_new();
115 if (ctx == NULL)
116 goto err;
117redo:
118 if (dsa->kinv == NULL || dsa->r == NULL) {
119 if (!DSA_sign_setup(dsa, ctx, &kinv, &r))
120 goto err;
121 } else {
122 kinv = dsa->kinv;
123 dsa->kinv = NULL;
124 r = dsa->r;
125 dsa->r = NULL;
126 noredo = 1;
127 }
128
129
130 /*
131 * If the digest length is greater than the size of q use the
132 * BN_num_bits(dsa->q) leftmost bits of the digest, see
133 * fips 186-3, 4.2
134 */
135 if (dlen > BN_num_bytes(dsa->q))
136 dlen = BN_num_bytes(dsa->q);
137 if (BN_bin2bn(dgst,dlen,&m) == NULL)
138 goto err;
139
140 /* Compute s = inv(k) (m + xr) mod q */
141 if (!BN_mod_mul(&xr, dsa->priv_key, r, dsa->q, ctx)) /* s = xr */
142 goto err;
143 if (!BN_add(s, &xr, &m)) /* s = m + xr */
144 goto err;
145 if (BN_cmp(s, dsa->q) > 0)
146 if (!BN_sub(s, s, dsa->q))
147 goto err;
148 if (!BN_mod_mul(s, s, kinv, dsa->q, ctx))
149 goto err;
150
151 ret = DSA_SIG_new();
152 if (ret == NULL)
153 goto err;
154 /*
155 * Redo if r or s is zero as required by FIPS 186-3: this is
156 * very unlikely.
157 */
158 if (BN_is_zero(r) || BN_is_zero(s)) {
159 if (noredo) {
160 reason = DSA_R_NEED_NEW_SETUP_VALUES;
161 goto err;
162 }
163 goto redo;
164 }
165 ret->r = r;
166 ret->s = s;
167
168err:
169 if (!ret) {
170 DSAerr(DSA_F_DSA_DO_SIGN, reason);
171 BN_free(r);
172 BN_free(s);
173 }
174 BN_CTX_free(ctx);
175 BN_clear_free(&m);
176 BN_clear_free(&xr);
177 BN_clear_free(kinv);
178 return ret;
179}
180
181static int
182dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
183{
184 BN_CTX *ctx;
185 BIGNUM k, *kinv = NULL, *r = NULL;
186 int ret = 0;
187
188 if (!dsa->p || !dsa->q || !dsa->g) {
189 DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);
190 return 0;
191 }
192
193 BN_init(&k);
194
195 if (ctx_in == NULL) {
196 if ((ctx = BN_CTX_new()) == NULL)
197 goto err;
198 } else
199 ctx = ctx_in;
200
201 if ((r = BN_new()) == NULL)
202 goto err;
203
204 /* Get random k */
205 do {
206 if (!BN_rand_range(&k, dsa->q))
207 goto err;
208 } while (BN_is_zero(&k));
209
210 BN_set_flags(&k, BN_FLG_CONSTTIME);
211
212 if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {
213 if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,
214 CRYPTO_LOCK_DSA, dsa->p, ctx))
215 goto err;
216 }
217
218 /* Compute r = (g^k mod p) mod q */
219
220 /*
221 * We do not want timing information to leak the length of k,
222 * so we compute g^k using an equivalent exponent of fixed
223 * length.
224 *
225 * (This is a kludge that we need because the BN_mod_exp_mont()
226 * does not let us specify the desired timing behaviour.)
227 */
228
229 if (!BN_add(&k, &k, dsa->q))
230 goto err;
231 if (BN_num_bits(&k) <= BN_num_bits(dsa->q)) {
232 if (!BN_add(&k, &k, dsa->q))
233 goto err;
234 }
235
236 if (dsa->meth->bn_mod_exp != NULL) {
237 if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, &k, dsa->p, ctx,
238 dsa->method_mont_p))
239 goto err;
240 } else {
241 if (!BN_mod_exp_mont(r, dsa->g, &k, dsa->p, ctx, dsa->method_mont_p))
242 goto err;
243 }
244
245 if (!BN_mod(r,r,dsa->q,ctx))
246 goto err;
247
248 /* Compute part of 's = inv(k) (m + xr) mod q' */
249 if ((kinv = BN_mod_inverse(NULL, &k, dsa->q, ctx)) == NULL)
250 goto err;
251
252 BN_clear_free(*kinvp);
253 *kinvp = kinv;
254 kinv = NULL;
255 BN_clear_free(*rp);
256 *rp = r;
257 ret = 1;
258err:
259 if (!ret) {
260 DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);
261 BN_clear_free(r);
262 }
263 if (ctx_in == NULL)
264 BN_CTX_free(ctx);
265 BN_clear_free(&k);
266 return ret;
267}
268
269static int
270dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa)
271{
272 BN_CTX *ctx;
273 BIGNUM u1, u2, t1;
274 BN_MONT_CTX *mont = NULL;
275 int ret = -1, i;
276
277 if (!dsa->p || !dsa->q || !dsa->g) {
278 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS);
279 return -1;
280 }
281
282 i = BN_num_bits(dsa->q);
283 /* fips 186-3 allows only different sizes for q */
284 if (i != 160 && i != 224 && i != 256) {
285 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE);
286 return -1;
287 }
288
289 if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) {
290 DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE);
291 return -1;
292 }
293 BN_init(&u1);
294 BN_init(&u2);
295 BN_init(&t1);
296
297 if ((ctx = BN_CTX_new()) == NULL)
298 goto err;
299
300 if (BN_is_zero(sig->r) || BN_is_negative(sig->r) ||
301 BN_ucmp(sig->r, dsa->q) >= 0) {
302 ret = 0;
303 goto err;
304 }
305 if (BN_is_zero(sig->s) || BN_is_negative(sig->s) ||
306 BN_ucmp(sig->s, dsa->q) >= 0) {
307 ret = 0;
308 goto err;
309 }
310
311 /* Calculate W = inv(S) mod Q
312 * save W in u2 */
313 if ((BN_mod_inverse(&u2, sig->s, dsa->q, ctx)) == NULL)
314 goto err;
315
316 /* save M in u1 */
317 /*
318 * If the digest length is greater than the size of q use the
319 * BN_num_bits(dsa->q) leftmost bits of the digest, see
320 * fips 186-3, 4.2
321 */
322 if (dgst_len > (i >> 3))
323 dgst_len = (i >> 3);
324 if (BN_bin2bn(dgst, dgst_len, &u1) == NULL)
325 goto err;
326
327 /* u1 = M * w mod q */
328 if (!BN_mod_mul(&u1, &u1, &u2, dsa->q, ctx))
329 goto err;
330
331 /* u2 = r * w mod q */
332 if (!BN_mod_mul(&u2, sig->r, &u2, dsa->q, ctx))
333 goto err;
334
335
336 if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {
337 mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p,
338 CRYPTO_LOCK_DSA, dsa->p, ctx);
339 if (!mont)
340 goto err;
341 }
342
343 if (dsa->meth->dsa_mod_exp != NULL) {
344 if (!dsa->meth->dsa_mod_exp(dsa, &t1, dsa->g, &u1, dsa->pub_key, &u2,
345 dsa->p, ctx, mont))
346 goto err;
347 } else {
348 if (!BN_mod_exp2_mont(&t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx,
349 mont))
350 goto err;
351 }
352
353 /* BN_copy(&u1,&t1); */
354 /* let u1 = u1 mod q */
355 if (!BN_mod(&u1, &t1, dsa->q, ctx))
356 goto err;
357
358 /* V is now in u1. If the signature is correct, it will be
359 * equal to R. */
360 ret = BN_ucmp(&u1, sig->r) == 0;
361
362err:
363 if (ret < 0)
364 DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB);
365 BN_CTX_free(ctx);
366 BN_free(&u1);
367 BN_free(&u2);
368 BN_free(&t1);
369 return ret;
370}
371
372static int
373dsa_init(DSA *dsa)
374{
375 dsa->flags |= DSA_FLAG_CACHE_MONT_P;
376 return 1;
377}
378
379static int
380dsa_finish(DSA *dsa)
381{
382 BN_MONT_CTX_free(dsa->method_mont_p);
383 return 1;
384}
385
diff --git a/src/lib/libcrypto/dsa/dsa_pmeth.c b/src/lib/libcrypto/dsa/dsa_pmeth.c
deleted file mode 100644
index c7a2edfc94..0000000000
--- a/src/lib/libcrypto/dsa/dsa_pmeth.c
+++ /dev/null
@@ -1,337 +0,0 @@
1/* $OpenBSD: dsa_pmeth.c,v 1.10 2014/07/11 08:44:48 jsing Exp $ */
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 <limits.h>
60#include <stdio.h>
61#include <string.h>
62
63#include <openssl/asn1t.h>
64#include <openssl/bn.h>
65#include <openssl/err.h>
66#include <openssl/evp.h>
67#include <openssl/x509.h>
68
69#include "dsa_locl.h"
70#include "evp_locl.h"
71
72/* DSA pkey context structure */
73
74typedef struct {
75 /* Parameter gen parameters */
76 int nbits; /* size of p in bits (default: 1024) */
77 int qbits; /* size of q in bits (default: 160) */
78 const EVP_MD *pmd; /* MD for parameter generation */
79 /* Keygen callback info */
80 int gentmp[2];
81 /* message digest */
82 const EVP_MD *md; /* MD for the signature */
83} DSA_PKEY_CTX;
84
85static int
86pkey_dsa_init(EVP_PKEY_CTX *ctx)
87{
88 DSA_PKEY_CTX *dctx;
89
90 dctx = malloc(sizeof(DSA_PKEY_CTX));
91 if (!dctx)
92 return 0;
93 dctx->nbits = 1024;
94 dctx->qbits = 160;
95 dctx->pmd = NULL;
96 dctx->md = NULL;
97
98 ctx->data = dctx;
99 ctx->keygen_info = dctx->gentmp;
100 ctx->keygen_info_count = 2;
101
102 return 1;
103}
104
105static int
106pkey_dsa_copy(EVP_PKEY_CTX *dst, EVP_PKEY_CTX *src)
107{
108 DSA_PKEY_CTX *dctx, *sctx;
109
110 if (!pkey_dsa_init(dst))
111 return 0;
112 sctx = src->data;
113 dctx = dst->data;
114 dctx->nbits = sctx->nbits;
115 dctx->qbits = sctx->qbits;
116 dctx->pmd = sctx->pmd;
117 dctx->md = sctx->md;
118 return 1;
119}
120
121static void
122pkey_dsa_cleanup(EVP_PKEY_CTX *ctx)
123{
124 DSA_PKEY_CTX *dctx = ctx->data;
125
126 free(dctx);
127}
128
129static int
130pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen,
131 const unsigned char *tbs, size_t tbslen)
132{
133 int ret, type;
134 unsigned int sltmp;
135 DSA_PKEY_CTX *dctx = ctx->data;
136 DSA *dsa = ctx->pkey->pkey.dsa;
137
138 if (dctx->md)
139 type = EVP_MD_type(dctx->md);
140 else
141 type = NID_sha1;
142
143 ret = DSA_sign(type, tbs, tbslen, sig, &sltmp, dsa);
144
145 if (ret <= 0)
146 return ret;
147 *siglen = sltmp;
148 return 1;
149}
150
151static int
152pkey_dsa_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen,
153 const unsigned char *tbs, size_t tbslen)
154{
155 int ret, type;
156 DSA_PKEY_CTX *dctx = ctx->data;
157 DSA *dsa = ctx->pkey->pkey.dsa;
158
159 if (dctx->md)
160 type = EVP_MD_type(dctx->md);
161 else
162 type = NID_sha1;
163
164 ret = DSA_verify(type, tbs, tbslen, sig, siglen, dsa);
165
166 return ret;
167}
168
169static int
170pkey_dsa_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2)
171{
172 DSA_PKEY_CTX *dctx = ctx->data;
173
174 switch (type) {
175 case EVP_PKEY_CTRL_DSA_PARAMGEN_BITS:
176 if (p1 < 256)
177 return -2;
178 dctx->nbits = p1;
179 return 1;
180
181 case EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS:
182 if (p1 != 160 && p1 != 224 && p1 && p1 != 256)
183 return -2;
184 dctx->qbits = p1;
185 return 1;
186
187 case EVP_PKEY_CTRL_DSA_PARAMGEN_MD:
188 switch (EVP_MD_type((const EVP_MD *)p2)) {
189 case NID_sha1:
190 case NID_sha224:
191 case NID_sha256:
192 break;
193 default:
194 DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
195 return 0;
196 }
197 dctx->md = p2;
198 return 1;
199
200 case EVP_PKEY_CTRL_MD:
201 switch (EVP_MD_type((const EVP_MD *)p2)) {
202 case NID_sha1:
203 case NID_dsa:
204 case NID_dsaWithSHA:
205 case NID_sha224:
206 case NID_sha256:
207 case NID_sha384:
208 case NID_sha512:
209 break;
210 default:
211 DSAerr(DSA_F_PKEY_DSA_CTRL, DSA_R_INVALID_DIGEST_TYPE);
212 return 0;
213 }
214 dctx->md = p2;
215 return 1;
216
217 case EVP_PKEY_CTRL_DIGESTINIT:
218 case EVP_PKEY_CTRL_PKCS7_SIGN:
219 case EVP_PKEY_CTRL_CMS_SIGN:
220 return 1;
221
222 case EVP_PKEY_CTRL_PEER_KEY:
223 DSAerr(DSA_F_PKEY_DSA_CTRL,
224 EVP_R_OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE);
225 return -2;
226 default:
227 return -2;
228 }
229}
230
231static int
232pkey_dsa_ctrl_str(EVP_PKEY_CTX *ctx, const char *type, const char *value)
233{
234 long lval;
235 char *ep;
236
237 if (!strcmp(type, "dsa_paramgen_bits")) {
238 int nbits;
239
240 errno = 0;
241 lval = strtol(value, &ep, 10);
242 if (value[0] == '\0' || *ep != '\0')
243 goto not_a_number;
244 if ((errno == ERANGE &&
245 (lval == LONG_MAX || lval == LONG_MIN)) ||
246 (lval > INT_MAX || lval < INT_MIN))
247 goto out_of_range;
248 nbits = lval;
249 return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits);
250 } else if (!strcmp(type, "dsa_paramgen_q_bits")) {
251 int qbits;
252
253 errno = 0;
254 lval = strtol(value, &ep, 10);
255 if (value[0] == '\0' || *ep != '\0')
256 goto not_a_number;
257 if ((errno == ERANGE &&
258 (lval == LONG_MAX || lval == LONG_MIN)) ||
259 (lval > INT_MAX || lval < INT_MIN))
260 goto out_of_range;
261 qbits = lval;
262 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA,
263 EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS,
264 qbits, NULL);
265 } else if (!strcmp(type, "dsa_paramgen_md")) {
266 return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA,
267 EVP_PKEY_OP_PARAMGEN, EVP_PKEY_CTRL_DSA_PARAMGEN_MD, 0,
268 (void *)EVP_get_digestbyname(value));
269 }
270not_a_number:
271out_of_range:
272 return -2;
273}
274
275static int
276pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
277{
278 DSA *dsa = NULL;
279 DSA_PKEY_CTX *dctx = ctx->data;
280 BN_GENCB *pcb, cb;
281 int ret;
282
283 if (ctx->pkey_gencb) {
284 pcb = &cb;
285 evp_pkey_set_cb_translate(pcb, ctx);
286 } else
287 pcb = NULL;
288 dsa = DSA_new();
289 if (!dsa)
290 return 0;
291 ret = dsa_builtin_paramgen(dsa, dctx->nbits, dctx->qbits, dctx->pmd,
292 NULL, 0, NULL, NULL, NULL, pcb);
293 if (ret)
294 EVP_PKEY_assign_DSA(pkey, dsa);
295 else
296 DSA_free(dsa);
297 return ret;
298}
299
300static int
301pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey)
302{
303 DSA *dsa = NULL;
304
305 if (ctx->pkey == NULL) {
306 DSAerr(DSA_F_PKEY_DSA_KEYGEN, DSA_R_NO_PARAMETERS_SET);
307 return 0;
308 }
309 dsa = DSA_new();
310 if (!dsa)
311 return 0;
312 EVP_PKEY_assign_DSA(pkey, dsa);
313 /* Note: if error return, pkey is freed by parent routine */
314 if (!EVP_PKEY_copy_parameters(pkey, ctx->pkey))
315 return 0;
316 return DSA_generate_key(pkey->pkey.dsa);
317}
318
319const EVP_PKEY_METHOD dsa_pkey_meth = {
320 .pkey_id = EVP_PKEY_DSA,
321 .flags = EVP_PKEY_FLAG_AUTOARGLEN,
322
323 .init = pkey_dsa_init,
324 .copy = pkey_dsa_copy,
325 .cleanup = pkey_dsa_cleanup,
326
327 .paramgen = pkey_dsa_paramgen,
328
329 .keygen = pkey_dsa_keygen,
330
331 .sign = pkey_dsa_sign,
332
333 .verify = pkey_dsa_verify,
334
335 .ctrl = pkey_dsa_ctrl,
336 .ctrl_str = pkey_dsa_ctrl_str
337};
diff --git a/src/lib/libcrypto/dsa/dsa_prn.c b/src/lib/libcrypto/dsa/dsa_prn.c
deleted file mode 100644
index 60f4e6c760..0000000000
--- a/src/lib/libcrypto/dsa/dsa_prn.c
+++ /dev/null
@@ -1,123 +0,0 @@
1/* $OpenBSD: dsa_prn.c,v 1.5 2014/07/11 08:44:48 jsing Exp $ */
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
61#include <openssl/dsa.h>
62#include <openssl/err.h>
63#include <openssl/evp.h>
64
65int
66DSA_print_fp(FILE *fp, const DSA *x, int off)
67{
68 BIO *b;
69 int ret;
70
71 if ((b = BIO_new(BIO_s_file())) == NULL) {
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
82DSAparams_print_fp(FILE *fp, const DSA *x)
83{
84 BIO *b;
85 int ret;
86
87 if ((b = BIO_new(BIO_s_file())) == NULL) {
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
97int
98DSA_print(BIO *bp, const DSA *x, int off)
99{
100 EVP_PKEY *pk;
101 int ret;
102
103 pk = EVP_PKEY_new();
104 if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
105 return 0;
106 ret = EVP_PKEY_print_private(bp, pk, off, NULL);
107 EVP_PKEY_free(pk);
108 return ret;
109}
110
111int
112DSAparams_print(BIO *bp, const DSA *x)
113{
114 EVP_PKEY *pk;
115 int ret;
116
117 pk = EVP_PKEY_new();
118 if (!pk || !EVP_PKEY_set1_DSA(pk, (DSA *)x))
119 return 0;
120 ret = EVP_PKEY_print_params(bp, pk, 4, NULL);
121 EVP_PKEY_free(pk);
122 return ret;
123}
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
deleted file mode 100644
index 355bdd20d6..0000000000
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ /dev/null
@@ -1,97 +0,0 @@
1/* $OpenBSD: dsa_sign.c,v 1.19 2014/10/18 17:20:40 jsing Exp $ */
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 <openssl/bn.h>
62#include <openssl/dsa.h>
63
64DSA_SIG *
65DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
66{
67 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
68}
69
70int
71DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
72{
73 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
74}
75
76DSA_SIG *
77DSA_SIG_new(void)
78{
79 DSA_SIG *sig;
80
81 sig = malloc(sizeof(DSA_SIG));
82 if (!sig)
83 return NULL;
84 sig->r = NULL;
85 sig->s = NULL;
86 return sig;
87}
88
89void
90DSA_SIG_free(DSA_SIG *sig)
91{
92 if (sig) {
93 BN_free(sig->r);
94 BN_free(sig->s);
95 free(sig);
96 }
97}
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
deleted file mode 100644
index 1965338f1f..0000000000
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ /dev/null
@@ -1,67 +0,0 @@
1/* $OpenBSD: dsa_vrf.c,v 1.16 2014/07/11 08:44:48 jsing Exp $ */
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 <openssl/dsa.h>
62
63int
64DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa)
65{
66 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
67}