diff options
Diffstat (limited to 'src/lib/libcrypto/dsa')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa.h | 325 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ameth.c | 692 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 439 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_depr.c | 92 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_err.c | 133 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_gen.c | 357 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 133 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_lib.c | 305 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_locl.h | 61 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 423 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_pmeth.c | 337 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_prn.c | 123 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_sign.c | 97 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_vrf.c | 67 |
14 files changed, 0 insertions, 3584 deletions
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h deleted file mode 100644 index bd7b26070d..0000000000 --- a/src/lib/libcrypto/dsa/dsa.h +++ /dev/null | |||
@@ -1,325 +0,0 @@ | |||
1 | /* $OpenBSD: dsa.h,v 1.18 2014/07/12 16:03: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 | /* | ||
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 | #define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA | ||
93 | * implementation now uses constant time | ||
94 | * modular exponentiation for secret exponents | ||
95 | * by default. This flag causes the | ||
96 | * faster variable sliding window method to | ||
97 | * be used for all exponents. | ||
98 | */ | ||
99 | |||
100 | /* If this flag is set the DSA method is FIPS compliant and can be used | ||
101 | * in FIPS mode. This is set in the validated module method. If an | ||
102 | * application sets this flag in its own methods it is its reposibility | ||
103 | * to ensure the result is compliant. | ||
104 | */ | ||
105 | |||
106 | #define DSA_FLAG_FIPS_METHOD 0x0400 | ||
107 | |||
108 | /* If this flag is set the operations normally disabled in FIPS mode are | ||
109 | * permitted it is then the applications responsibility to ensure that the | ||
110 | * usage is compliant. | ||
111 | */ | ||
112 | |||
113 | #define DSA_FLAG_NON_FIPS_ALLOW 0x0400 | ||
114 | |||
115 | #ifdef __cplusplus | ||
116 | extern "C" { | ||
117 | #endif | ||
118 | |||
119 | /* Already defined in ossl_typ.h */ | ||
120 | /* typedef struct dsa_st DSA; */ | ||
121 | /* typedef struct dsa_method DSA_METHOD; */ | ||
122 | |||
123 | typedef struct DSA_SIG_st | ||
124 | { | ||
125 | BIGNUM *r; | ||
126 | BIGNUM *s; | ||
127 | } DSA_SIG; | ||
128 | |||
129 | struct dsa_method | ||
130 | { | ||
131 | const char *name; | ||
132 | DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa); | ||
133 | int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, | ||
134 | BIGNUM **rp); | ||
135 | int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len, | ||
136 | DSA_SIG *sig, DSA *dsa); | ||
137 | int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, | ||
138 | BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, | ||
139 | BN_MONT_CTX *in_mont); | ||
140 | int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
141 | const BIGNUM *m, BN_CTX *ctx, | ||
142 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
143 | int (*init)(DSA *dsa); | ||
144 | int (*finish)(DSA *dsa); | ||
145 | int flags; | ||
146 | char *app_data; | ||
147 | /* If this is non-NULL, it is used to generate DSA parameters */ | ||
148 | int (*dsa_paramgen)(DSA *dsa, int bits, | ||
149 | const unsigned char *seed, int seed_len, | ||
150 | int *counter_ret, unsigned long *h_ret, | ||
151 | BN_GENCB *cb); | ||
152 | /* If this is non-NULL, it is used to generate DSA keys */ | ||
153 | int (*dsa_keygen)(DSA *dsa); | ||
154 | }; | ||
155 | |||
156 | struct dsa_st | ||
157 | { | ||
158 | /* This first variable is used to pick up errors where | ||
159 | * a DSA is passed instead of of a EVP_PKEY */ | ||
160 | int pad; | ||
161 | long version; | ||
162 | int write_params; | ||
163 | BIGNUM *p; | ||
164 | BIGNUM *q; /* == 20 */ | ||
165 | BIGNUM *g; | ||
166 | |||
167 | BIGNUM *pub_key; /* y public key */ | ||
168 | BIGNUM *priv_key; /* x private key */ | ||
169 | |||
170 | BIGNUM *kinv; /* Signing pre-calc */ | ||
171 | BIGNUM *r; /* Signing pre-calc */ | ||
172 | |||
173 | int flags; | ||
174 | /* Normally used to cache montgomery values */ | ||
175 | BN_MONT_CTX *method_mont_p; | ||
176 | int references; | ||
177 | CRYPTO_EX_DATA ex_data; | ||
178 | const DSA_METHOD *meth; | ||
179 | /* functional reference if 'meth' is ENGINE-provided */ | ||
180 | ENGINE *engine; | ||
181 | }; | ||
182 | |||
183 | #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ | ||
184 | (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) | ||
185 | #define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ | ||
186 | (unsigned char *)(x)) | ||
187 | #define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x) | ||
188 | #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x) | ||
189 | |||
190 | |||
191 | DSA *DSAparams_dup(DSA *x); | ||
192 | DSA_SIG * DSA_SIG_new(void); | ||
193 | void DSA_SIG_free(DSA_SIG *a); | ||
194 | int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp); | ||
195 | DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length); | ||
196 | |||
197 | DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa); | ||
198 | int DSA_do_verify(const unsigned char *dgst,int dgst_len, | ||
199 | DSA_SIG *sig,DSA *dsa); | ||
200 | |||
201 | const DSA_METHOD *DSA_OpenSSL(void); | ||
202 | |||
203 | void DSA_set_default_method(const DSA_METHOD *); | ||
204 | const DSA_METHOD *DSA_get_default_method(void); | ||
205 | int DSA_set_method(DSA *dsa, const DSA_METHOD *); | ||
206 | |||
207 | DSA * DSA_new(void); | ||
208 | DSA * DSA_new_method(ENGINE *engine); | ||
209 | void DSA_free(DSA *r); | ||
210 | /* "up" the DSA object's reference count */ | ||
211 | int DSA_up_ref(DSA *r); | ||
212 | int DSA_size(const DSA *); | ||
213 | /* next 4 return -1 on error */ | ||
214 | int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); | ||
215 | int DSA_sign(int type,const unsigned char *dgst,int dlen, | ||
216 | unsigned char *sig, unsigned int *siglen, DSA *dsa); | ||
217 | int DSA_verify(int type,const unsigned char *dgst,int dgst_len, | ||
218 | const unsigned char *sigbuf, int siglen, DSA *dsa); | ||
219 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
220 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
221 | int DSA_set_ex_data(DSA *d, int idx, void *arg); | ||
222 | void *DSA_get_ex_data(DSA *d, int idx); | ||
223 | |||
224 | DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length); | ||
225 | DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length); | ||
226 | DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length); | ||
227 | |||
228 | /* Deprecated version */ | ||
229 | #ifndef OPENSSL_NO_DEPRECATED | ||
230 | DSA * DSA_generate_parameters(int bits, | ||
231 | unsigned char *seed,int seed_len, | ||
232 | int *counter_ret, unsigned long *h_ret,void | ||
233 | (*callback)(int, int, void *),void *cb_arg); | ||
234 | #endif /* !defined(OPENSSL_NO_DEPRECATED) */ | ||
235 | |||
236 | /* New version */ | ||
237 | int DSA_generate_parameters_ex(DSA *dsa, int bits, | ||
238 | const unsigned char *seed,int seed_len, | ||
239 | int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); | ||
240 | |||
241 | int DSA_generate_key(DSA *a); | ||
242 | int i2d_DSAPublicKey(const DSA *a, unsigned char **pp); | ||
243 | int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp); | ||
244 | int i2d_DSAparams(const DSA *a,unsigned char **pp); | ||
245 | |||
246 | #ifndef OPENSSL_NO_BIO | ||
247 | int DSAparams_print(BIO *bp, const DSA *x); | ||
248 | int DSA_print(BIO *bp, const DSA *x, int off); | ||
249 | #endif | ||
250 | int DSAparams_print_fp(FILE *fp, const DSA *x); | ||
251 | int DSA_print_fp(FILE *bp, const DSA *x, int off); | ||
252 | |||
253 | #define DSS_prime_checks 50 | ||
254 | /* Primality test according to FIPS PUB 186[-1], Appendix 2.1: | ||
255 | * 50 rounds of Rabin-Miller */ | ||
256 | #define DSA_is_prime(n, callback, cb_arg) \ | ||
257 | BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg) | ||
258 | |||
259 | #ifndef OPENSSL_NO_DH | ||
260 | /* Convert DSA structure (key or just parameters) into DH structure | ||
261 | * (be careful to avoid small subgroup attacks when using this!) */ | ||
262 | DH *DSA_dup_DH(const DSA *r); | ||
263 | #endif | ||
264 | |||
265 | #define EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits) \ | ||
266 | EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DSA, EVP_PKEY_OP_PARAMGEN, \ | ||
267 | EVP_PKEY_CTRL_DSA_PARAMGEN_BITS, nbits, NULL) | ||
268 | |||
269 | #define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1) | ||
270 | #define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2) | ||
271 | #define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3) | ||
272 | |||
273 | /* BEGIN ERROR CODES */ | ||
274 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
275 | * made after this point may be overwritten when the script is next run. | ||
276 | */ | ||
277 | void ERR_load_DSA_strings(void); | ||
278 | |||
279 | /* Error codes for the DSA functions. */ | ||
280 | |||
281 | /* Function codes. */ | ||
282 | #define DSA_F_D2I_DSA_SIG 110 | ||
283 | #define DSA_F_DO_DSA_PRINT 104 | ||
284 | #define DSA_F_DSAPARAMS_PRINT 100 | ||
285 | #define DSA_F_DSAPARAMS_PRINT_FP 101 | ||
286 | #define DSA_F_DSA_DO_SIGN 112 | ||
287 | #define DSA_F_DSA_DO_VERIFY 113 | ||
288 | #define DSA_F_DSA_GENERATE_KEY 124 | ||
289 | #define DSA_F_DSA_GENERATE_PARAMETERS_EX 123 | ||
290 | #define DSA_F_DSA_NEW_METHOD 103 | ||
291 | #define DSA_F_DSA_PARAM_DECODE 119 | ||
292 | #define DSA_F_DSA_PRINT_FP 105 | ||
293 | #define DSA_F_DSA_PRIV_DECODE 115 | ||
294 | #define DSA_F_DSA_PRIV_ENCODE 116 | ||
295 | #define DSA_F_DSA_PUB_DECODE 117 | ||
296 | #define DSA_F_DSA_PUB_ENCODE 118 | ||
297 | #define DSA_F_DSA_SIGN 106 | ||
298 | #define DSA_F_DSA_SIGN_SETUP 107 | ||
299 | #define DSA_F_DSA_SIG_NEW 109 | ||
300 | #define DSA_F_DSA_SIG_PRINT 125 | ||
301 | #define DSA_F_DSA_VERIFY 108 | ||
302 | #define DSA_F_I2D_DSA_SIG 111 | ||
303 | #define DSA_F_OLD_DSA_PRIV_DECODE 122 | ||
304 | #define DSA_F_PKEY_DSA_CTRL 120 | ||
305 | #define DSA_F_PKEY_DSA_KEYGEN 121 | ||
306 | #define DSA_F_SIG_CB 114 | ||
307 | |||
308 | /* Reason codes. */ | ||
309 | #define DSA_R_BAD_Q_VALUE 102 | ||
310 | #define DSA_R_BN_DECODE_ERROR 108 | ||
311 | #define DSA_R_BN_ERROR 109 | ||
312 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 | ||
313 | #define DSA_R_DECODE_ERROR 104 | ||
314 | #define DSA_R_INVALID_DIGEST_TYPE 106 | ||
315 | #define DSA_R_MISSING_PARAMETERS 101 | ||
316 | #define DSA_R_MODULUS_TOO_LARGE 103 | ||
317 | #define DSA_R_NEED_NEW_SETUP_VALUES 110 | ||
318 | #define DSA_R_NON_FIPS_DSA_METHOD 111 | ||
319 | #define DSA_R_NO_PARAMETERS_SET 107 | ||
320 | #define DSA_R_PARAMETER_ENCODING_ERROR 105 | ||
321 | |||
322 | #ifdef __cplusplus | ||
323 | } | ||
324 | #endif | ||
325 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_ameth.c b/src/lib/libcrypto/dsa/dsa_ameth.c deleted file mode 100644 index b9ee49f055..0000000000 --- a/src/lib/libcrypto/dsa/dsa_ameth.c +++ /dev/null | |||
@@ -1,692 +0,0 @@ | |||
1 | /* $OpenBSD: dsa_ameth.c,v 1.17 2015/02/14 15:11:22 miod 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 | |||
75 | static int | ||
76 | dsa_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 | |||
125 | err: | ||
126 | if (public_key) | ||
127 | ASN1_INTEGER_free(public_key); | ||
128 | DSA_free(dsa); | ||
129 | return 0; | ||
130 | } | ||
131 | |||
132 | static int | ||
133 | dsa_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 | |||
174 | err: | ||
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 | */ | ||
184 | |||
185 | static int | ||
186 | dsa_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8) | ||
187 | { | ||
188 | const unsigned char *p, *pm; | ||
189 | int pklen, pmlen; | ||
190 | int ptype; | ||
191 | void *pval; | ||
192 | ASN1_STRING *pstr; | ||
193 | X509_ALGOR *palg; | ||
194 | ASN1_INTEGER *privkey = NULL; | ||
195 | BN_CTX *ctx = NULL; | ||
196 | STACK_OF(ASN1_TYPE) *ndsa = NULL; | ||
197 | DSA *dsa = NULL; | ||
198 | |||
199 | if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8)) | ||
200 | return 0; | ||
201 | X509_ALGOR_get0(NULL, &ptype, &pval, palg); | ||
202 | |||
203 | /* Check for broken DSA PKCS#8, UGH! */ | ||
204 | if (*p == (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED)) { | ||
205 | ASN1_TYPE *t1, *t2; | ||
206 | if (!(ndsa = d2i_ASN1_SEQUENCE_ANY(NULL, &p, pklen))) | ||
207 | goto decerr; | ||
208 | if (sk_ASN1_TYPE_num(ndsa) != 2) | ||
209 | goto decerr; | ||
210 | /* | ||
211 | * Handle Two broken types: | ||
212 | * SEQUENCE {parameters, priv_key} | ||
213 | * SEQUENCE {pub_key, priv_key} | ||
214 | */ | ||
215 | |||
216 | t1 = sk_ASN1_TYPE_value(ndsa, 0); | ||
217 | t2 = sk_ASN1_TYPE_value(ndsa, 1); | ||
218 | if (t1->type == V_ASN1_SEQUENCE) { | ||
219 | p8->broken = PKCS8_EMBEDDED_PARAM; | ||
220 | pval = t1->value.ptr; | ||
221 | } else if (ptype == V_ASN1_SEQUENCE) | ||
222 | p8->broken = PKCS8_NS_DB; | ||
223 | else | ||
224 | goto decerr; | ||
225 | |||
226 | if (t2->type != V_ASN1_INTEGER) | ||
227 | goto decerr; | ||
228 | |||
229 | privkey = t2->value.integer; | ||
230 | } else { | ||
231 | const unsigned char *q = p; | ||
232 | |||
233 | if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen))) | ||
234 | goto decerr; | ||
235 | if (privkey->type == V_ASN1_NEG_INTEGER) { | ||
236 | p8->broken = PKCS8_NEG_PRIVKEY; | ||
237 | ASN1_INTEGER_free(privkey); | ||
238 | if (!(privkey = d2i_ASN1_UINTEGER(NULL, &q, pklen))) | ||
239 | goto decerr; | ||
240 | } | ||
241 | if (ptype != V_ASN1_SEQUENCE) | ||
242 | goto decerr; | ||
243 | } | ||
244 | |||
245 | pstr = pval; | ||
246 | pm = pstr->data; | ||
247 | pmlen = pstr->length; | ||
248 | if (!(dsa = d2i_DSAparams(NULL, &pm, pmlen))) | ||
249 | goto decerr; | ||
250 | /* We have parameters now set private key */ | ||
251 | if (!(dsa->priv_key = ASN1_INTEGER_to_BN(privkey, NULL))) { | ||
252 | DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); | ||
253 | goto dsaerr; | ||
254 | } | ||
255 | /* Calculate public key */ | ||
256 | if (!(dsa->pub_key = BN_new())) { | ||
257 | DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); | ||
258 | goto dsaerr; | ||
259 | } | ||
260 | if (!(ctx = BN_CTX_new())) { | ||
261 | DSAerr(DSA_F_DSA_PRIV_DECODE, ERR_R_MALLOC_FAILURE); | ||
262 | goto dsaerr; | ||
263 | } | ||
264 | |||
265 | if (!BN_mod_exp(dsa->pub_key, dsa->g, dsa->priv_key, dsa->p, ctx)) { | ||
266 | DSAerr(DSA_F_DSA_PRIV_DECODE,DSA_R_BN_ERROR); | ||
267 | goto dsaerr; | ||
268 | } | ||
269 | |||
270 | EVP_PKEY_assign_DSA(pkey, dsa); | ||
271 | BN_CTX_free(ctx); | ||
272 | if (ndsa) | ||
273 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
274 | else | ||
275 | ASN1_INTEGER_free(privkey); | ||
276 | |||
277 | return 1; | ||
278 | |||
279 | decerr: | ||
280 | DSAerr(DSA_F_DSA_PRIV_DECODE, EVP_R_DECODE_ERROR); | ||
281 | dsaerr: | ||
282 | BN_CTX_free(ctx); | ||
283 | if (ndsa) | ||
284 | sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); | ||
285 | else | ||
286 | ASN1_INTEGER_free(privkey); | ||
287 | DSA_free(dsa); | ||
288 | return 0; | ||
289 | } | ||
290 | |||
291 | static int | ||
292 | dsa_priv_encode(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pkey) | ||
293 | { | ||
294 | ASN1_STRING *params = NULL; | ||
295 | ASN1_INTEGER *prkey = NULL; | ||
296 | unsigned char *dp = NULL; | ||
297 | int dplen; | ||
298 | |||
299 | params = ASN1_STRING_new(); | ||
300 | if (!params) { | ||
301 | DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); | ||
302 | goto err; | ||
303 | } | ||
304 | |||
305 | params->length = i2d_DSAparams(pkey->pkey.dsa, ¶ms->data); | ||
306 | if (params->length <= 0) { | ||
307 | DSAerr(DSA_F_DSA_PRIV_ENCODE, ERR_R_MALLOC_FAILURE); | ||
308 | goto err; | ||
309 | } | ||
310 | params->type = V_ASN1_SEQUENCE; | ||
311 | |||
312 | /* Get private key into integer */ | ||
313 | prkey = BN_to_ASN1_INTEGER(pkey->pkey.dsa->priv_key, NULL); | ||
314 | if (!prkey) { | ||
315 | DSAerr(DSA_F_DSA_PRIV_ENCODE, DSA_R_BN_ERROR); | ||
316 | goto err; | ||
317 | } | ||
318 | |||
319 | dplen = i2d_ASN1_INTEGER(prkey, &dp); | ||
320 | |||
321 | ASN1_INTEGER_free(prkey); | ||
322 | prkey = NULL; | ||
323 | |||
324 | if (!PKCS8_pkey_set0(p8, OBJ_nid2obj(NID_dsa), 0, V_ASN1_SEQUENCE, | ||
325 | params, dp, dplen)) | ||
326 | goto err; | ||
327 | |||
328 | return 1; | ||
329 | |||
330 | err: | ||
331 | free(dp); | ||
332 | ASN1_STRING_free(params); | ||
333 | ASN1_INTEGER_free(prkey); | ||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | static int | ||
338 | int_dsa_size(const EVP_PKEY *pkey) | ||
339 | { | ||
340 | return DSA_size(pkey->pkey.dsa); | ||
341 | } | ||
342 | |||
343 | static int | ||
344 | dsa_bits(const EVP_PKEY *pkey) | ||
345 | { | ||
346 | return BN_num_bits(pkey->pkey.dsa->p); | ||
347 | } | ||
348 | |||
349 | static int | ||
350 | dsa_missing_parameters(const EVP_PKEY *pkey) | ||
351 | { | ||
352 | DSA *dsa; | ||
353 | |||
354 | dsa = pkey->pkey.dsa; | ||
355 | if (dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) | ||
356 | return 1; | ||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | static int | ||
361 | dsa_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) | ||
362 | { | ||
363 | BIGNUM *a; | ||
364 | |||
365 | if ((a = BN_dup(from->pkey.dsa->p)) == NULL) | ||
366 | return 0; | ||
367 | BN_free(to->pkey.dsa->p); | ||
368 | to->pkey.dsa->p = a; | ||
369 | |||
370 | if ((a = BN_dup(from->pkey.dsa->q)) == NULL) | ||
371 | return 0; | ||
372 | BN_free(to->pkey.dsa->q); | ||
373 | to->pkey.dsa->q = a; | ||
374 | |||
375 | if ((a = BN_dup(from->pkey.dsa->g)) == NULL) | ||
376 | return 0; | ||
377 | BN_free(to->pkey.dsa->g); | ||
378 | to->pkey.dsa->g = a; | ||
379 | return 1; | ||
380 | } | ||
381 | |||
382 | static int | ||
383 | dsa_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) | ||
384 | { | ||
385 | if (BN_cmp(a->pkey.dsa->p, b->pkey.dsa->p) || | ||
386 | BN_cmp(a->pkey.dsa->q, b->pkey.dsa->q) || | ||
387 | BN_cmp(a->pkey.dsa->g, b->pkey.dsa->g)) | ||
388 | return 0; | ||
389 | else | ||
390 | return 1; | ||
391 | } | ||
392 | |||
393 | static int | ||
394 | dsa_pub_cmp(const EVP_PKEY *a, const EVP_PKEY *b) | ||
395 | { | ||
396 | if (BN_cmp(b->pkey.dsa->pub_key, a->pkey.dsa->pub_key) != 0) | ||
397 | return 0; | ||
398 | else | ||
399 | return 1; | ||
400 | } | ||
401 | |||
402 | static void | ||
403 | int_dsa_free(EVP_PKEY *pkey) | ||
404 | { | ||
405 | DSA_free(pkey->pkey.dsa); | ||
406 | } | ||
407 | |||
408 | static void | ||
409 | update_buflen(const BIGNUM *b, size_t *pbuflen) | ||
410 | { | ||
411 | size_t i; | ||
412 | |||
413 | if (!b) | ||
414 | return; | ||
415 | if (*pbuflen < (i = (size_t)BN_num_bytes(b))) | ||
416 | *pbuflen = i; | ||
417 | } | ||
418 | |||
419 | static int | ||
420 | do_dsa_print(BIO *bp, const DSA *x, int off, int ptype) | ||
421 | { | ||
422 | unsigned char *m = NULL; | ||
423 | int ret = 0; | ||
424 | size_t buf_len = 0; | ||
425 | const char *ktype = NULL; | ||
426 | const BIGNUM *priv_key, *pub_key; | ||
427 | |||
428 | if (ptype == 2) | ||
429 | priv_key = x->priv_key; | ||
430 | else | ||
431 | priv_key = NULL; | ||
432 | |||
433 | if (ptype > 0) | ||
434 | pub_key = x->pub_key; | ||
435 | else | ||
436 | pub_key = NULL; | ||
437 | |||
438 | if (ptype == 2) | ||
439 | ktype = "Private-Key"; | ||
440 | else if (ptype == 1) | ||
441 | ktype = "Public-Key"; | ||
442 | else | ||
443 | ktype = "DSA-Parameters"; | ||
444 | |||
445 | update_buflen(x->p, &buf_len); | ||
446 | update_buflen(x->q, &buf_len); | ||
447 | update_buflen(x->g, &buf_len); | ||
448 | update_buflen(priv_key, &buf_len); | ||
449 | update_buflen(pub_key, &buf_len); | ||
450 | |||
451 | m = malloc(buf_len + 10); | ||
452 | if (m == NULL) { | ||
453 | DSAerr(DSA_F_DO_DSA_PRINT, ERR_R_MALLOC_FAILURE); | ||
454 | goto err; | ||
455 | } | ||
456 | |||
457 | if (priv_key) { | ||
458 | if (!BIO_indent(bp, off, 128)) | ||
459 | goto err; | ||
460 | if (BIO_printf(bp, "%s: (%d bit)\n", ktype, | ||
461 | BN_num_bits(x->p)) <= 0) | ||
462 | goto err; | ||
463 | } | ||
464 | |||
465 | if (!ASN1_bn_print(bp, "priv:", priv_key, m, off)) | ||
466 | goto err; | ||
467 | if (!ASN1_bn_print(bp, "pub: ", pub_key, m, off)) | ||
468 | goto err; | ||
469 | if (!ASN1_bn_print(bp, "P: ", x->p, m, off)) | ||
470 | goto err; | ||
471 | if (!ASN1_bn_print(bp, "Q: ", x->q, m, off)) | ||
472 | goto err; | ||
473 | if (!ASN1_bn_print(bp, "G: ", x->g, m, off)) | ||
474 | goto err; | ||
475 | ret = 1; | ||
476 | err: | ||
477 | free(m); | ||
478 | return(ret); | ||
479 | } | ||
480 | |||
481 | static int | ||
482 | dsa_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) | ||
483 | { | ||
484 | DSA *dsa; | ||
485 | |||
486 | if (!(dsa = d2i_DSAparams(NULL, pder, derlen))) { | ||
487 | DSAerr(DSA_F_DSA_PARAM_DECODE, ERR_R_DSA_LIB); | ||
488 | return 0; | ||
489 | } | ||
490 | EVP_PKEY_assign_DSA(pkey, dsa); | ||
491 | return 1; | ||
492 | } | ||
493 | |||
494 | static int | ||
495 | dsa_param_encode(const EVP_PKEY *pkey, unsigned char **pder) | ||
496 | { | ||
497 | return i2d_DSAparams(pkey->pkey.dsa, pder); | ||
498 | } | ||
499 | |||
500 | static int | ||
501 | dsa_param_print(BIO *bp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx) | ||
502 | { | ||
503 | return do_dsa_print(bp, pkey->pkey.dsa, indent, 0); | ||
504 | } | ||
505 | |||
506 | static int | ||
507 | dsa_pub_print(BIO *bp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx) | ||
508 | { | ||
509 | return do_dsa_print(bp, pkey->pkey.dsa, indent, 1); | ||
510 | } | ||
511 | |||
512 | static int | ||
513 | dsa_priv_print(BIO *bp, const EVP_PKEY *pkey, int indent, ASN1_PCTX *ctx) | ||
514 | { | ||
515 | return do_dsa_print(bp, pkey->pkey.dsa, indent, 2); | ||
516 | } | ||
517 | |||
518 | static int | ||
519 | old_dsa_priv_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen) | ||
520 | { | ||
521 | DSA *dsa; | ||
522 | |||
523 | if (!(dsa = d2i_DSAPrivateKey (NULL, pder, derlen))) { | ||
524 | DSAerr(DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB); | ||
525 | return 0; | ||
526 | } | ||
527 | EVP_PKEY_assign_DSA(pkey, dsa); | ||
528 | return 1; | ||
529 | } | ||
530 | |||
531 | static int | ||
532 | old_dsa_priv_encode(const EVP_PKEY *pkey, unsigned char **pder) | ||
533 | { | ||
534 | return i2d_DSAPrivateKey(pkey->pkey.dsa, pder); | ||
535 | } | ||
536 | |||
537 | static int | ||
538 | dsa_sig_print(BIO *bp, const X509_ALGOR *sigalg, const ASN1_STRING *sig, | ||
539 | int indent, ASN1_PCTX *pctx) | ||
540 | { | ||
541 | DSA_SIG *dsa_sig; | ||
542 | const unsigned char *p; | ||
543 | |||
544 | if (!sig) { | ||
545 | if (BIO_puts(bp, "\n") <= 0) | ||
546 | return 0; | ||
547 | else | ||
548 | return 1; | ||
549 | } | ||
550 | p = sig->data; | ||
551 | dsa_sig = d2i_DSA_SIG(NULL, &p, sig->length); | ||
552 | if (dsa_sig) { | ||
553 | int rv = 0; | ||
554 | size_t buf_len = 0; | ||
555 | unsigned char *m = NULL; | ||
556 | |||
557 | update_buflen(dsa_sig->r, &buf_len); | ||
558 | update_buflen(dsa_sig->s, &buf_len); | ||
559 | m = malloc(buf_len + 10); | ||
560 | if (m == NULL) { | ||
561 | DSAerr(DSA_F_DSA_SIG_PRINT, ERR_R_MALLOC_FAILURE); | ||
562 | goto err; | ||
563 | } | ||
564 | |||
565 | if (BIO_write(bp, "\n", 1) != 1) | ||
566 | goto err; | ||
567 | |||
568 | if (!ASN1_bn_print(bp, "r: ", dsa_sig->r, m, indent)) | ||
569 | goto err; | ||
570 | if (!ASN1_bn_print(bp, "s: ", dsa_sig->s, m, indent)) | ||
571 | goto err; | ||
572 | rv = 1; | ||
573 | err: | ||
574 | free(m); | ||
575 | DSA_SIG_free(dsa_sig); | ||
576 | return rv; | ||
577 | } | ||
578 | return X509_signature_dump(bp, sig, indent); | ||
579 | } | ||
580 | |||
581 | static int | ||
582 | dsa_pkey_ctrl(EVP_PKEY *pkey, int op, long arg1, void *arg2) | ||
583 | { | ||
584 | switch (op) { | ||
585 | case ASN1_PKEY_CTRL_PKCS7_SIGN: | ||
586 | if (arg1 == 0) { | ||
587 | int snid, hnid; | ||
588 | X509_ALGOR *alg1, *alg2; | ||
589 | |||
590 | PKCS7_SIGNER_INFO_get0_algs(arg2, NULL, &alg1, &alg2); | ||
591 | if (alg1 == NULL || alg1->algorithm == NULL) | ||
592 | return -1; | ||
593 | hnid = OBJ_obj2nid(alg1->algorithm); | ||
594 | if (hnid == NID_undef) | ||
595 | return -1; | ||
596 | if (!OBJ_find_sigid_by_algs(&snid, hnid, | ||
597 | EVP_PKEY_id(pkey))) | ||
598 | return -1; | ||
599 | X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, | ||
600 | 0); | ||
601 | } | ||
602 | return 1; | ||
603 | #ifndef OPENSSL_NO_CMS | ||
604 | case ASN1_PKEY_CTRL_CMS_SIGN: | ||
605 | if (arg1 == 0) { | ||
606 | int snid, hnid; | ||
607 | X509_ALGOR *alg1, *alg2; | ||
608 | |||
609 | CMS_SignerInfo_get0_algs(arg2, NULL, NULL, &alg1, &alg2); | ||
610 | if (alg1 == NULL || alg1->algorithm == NULL) | ||
611 | return -1; | ||
612 | hnid = OBJ_obj2nid(alg1->algorithm); | ||
613 | if (hnid == NID_undef) | ||
614 | return -1; | ||
615 | if (!OBJ_find_sigid_by_algs(&snid, hnid, | ||
616 | EVP_PKEY_id(pkey))) | ||
617 | return -1; | ||
618 | X509_ALGOR_set0(alg2, OBJ_nid2obj(snid), V_ASN1_UNDEF, | ||
619 | 0); | ||
620 | } | ||
621 | return 1; | ||
622 | #endif | ||
623 | |||
624 | case ASN1_PKEY_CTRL_DEFAULT_MD_NID: | ||
625 | *(int *)arg2 = NID_sha1; | ||
626 | return 2; | ||
627 | |||
628 | default: | ||
629 | return -2; | ||
630 | } | ||
631 | } | ||
632 | |||
633 | /* NB these are sorted in pkey_id order, lowest first */ | ||
634 | |||
635 | const EVP_PKEY_ASN1_METHOD dsa_asn1_meths[] = { | ||
636 | { | ||
637 | .pkey_id = EVP_PKEY_DSA2, | ||
638 | .pkey_base_id = EVP_PKEY_DSA, | ||
639 | .pkey_flags = ASN1_PKEY_ALIAS | ||
640 | }, | ||
641 | |||
642 | { | ||
643 | .pkey_id = EVP_PKEY_DSA1, | ||
644 | .pkey_base_id = EVP_PKEY_DSA, | ||
645 | .pkey_flags = ASN1_PKEY_ALIAS | ||
646 | }, | ||
647 | |||
648 | { | ||
649 | .pkey_id = EVP_PKEY_DSA4, | ||
650 | .pkey_base_id = EVP_PKEY_DSA, | ||
651 | .pkey_flags = ASN1_PKEY_ALIAS | ||
652 | }, | ||
653 | |||
654 | { | ||
655 | .pkey_id = EVP_PKEY_DSA3, | ||
656 | .pkey_base_id = EVP_PKEY_DSA, | ||
657 | .pkey_flags = ASN1_PKEY_ALIAS | ||
658 | }, | ||
659 | |||
660 | { | ||
661 | .pkey_id = EVP_PKEY_DSA, | ||
662 | .pkey_base_id = EVP_PKEY_DSA, | ||
663 | |||
664 | .pem_str = "DSA", | ||
665 | .info = "OpenSSL DSA method", | ||
666 | |||
667 | .pub_decode = dsa_pub_decode, | ||
668 | .pub_encode = dsa_pub_encode, | ||
669 | .pub_cmp = dsa_pub_cmp, | ||
670 | .pub_print = dsa_pub_print, | ||
671 | |||
672 | .priv_decode = dsa_priv_decode, | ||
673 | .priv_encode = dsa_priv_encode, | ||
674 | .priv_print = dsa_priv_print, | ||
675 | |||
676 | .pkey_size = int_dsa_size, | ||
677 | .pkey_bits = dsa_bits, | ||
678 | |||
679 | .param_decode = dsa_param_decode, | ||
680 | .param_encode = dsa_param_encode, | ||
681 | .param_missing = dsa_missing_parameters, | ||
682 | .param_copy = dsa_copy_parameters, | ||
683 | .param_cmp = dsa_cmp_parameters, | ||
684 | .param_print = dsa_param_print, | ||
685 | .sig_print = dsa_sig_print, | ||
686 | |||
687 | .pkey_free = int_dsa_free, | ||
688 | .pkey_ctrl = dsa_pkey_ctrl, | ||
689 | .old_priv_decode = old_dsa_priv_decode, | ||
690 | .old_priv_encode = old_dsa_priv_encode | ||
691 | } | ||
692 | }; | ||
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 */ | ||
68 | static int | ||
69 | sig_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 | |||
87 | static 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 | }; | ||
95 | static 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 | |||
112 | const 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 | |||
123 | DSA_SIG * | ||
124 | d2i_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 | |||
130 | int | ||
131 | i2d_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 */ | ||
137 | static int | ||
138 | dsa_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 | |||
153 | static 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 | }; | ||
161 | static 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 | |||
206 | const 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 | |||
217 | DSA * | ||
218 | d2i_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 | |||
224 | int | ||
225 | i2d_DSAPrivateKey(const DSA *a, unsigned char **out) | ||
226 | { | ||
227 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAPrivateKey_it); | ||
228 | } | ||
229 | |||
230 | static 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 | }; | ||
238 | static 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 | |||
262 | const 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 | |||
273 | DSA * | ||
274 | d2i_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 | |||
280 | int | ||
281 | i2d_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 | |||
293 | static 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 | |||
324 | const 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 | |||
334 | static 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 | }; | ||
342 | static 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 | |||
359 | const 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 | |||
370 | DSA * | ||
371 | d2i_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 | |||
377 | int | ||
378 | i2d_DSAPublicKey(const DSA *a, unsigned char **out) | ||
379 | { | ||
380 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAPublicKey_it); | ||
381 | } | ||
382 | |||
383 | DSA * | ||
384 | DSAparams_dup(DSA *dsa) | ||
385 | { | ||
386 | return ASN1_item_dup(ASN1_ITEM_rptr(DSAparams), dsa); | ||
387 | } | ||
388 | |||
389 | int | ||
390 | DSA_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 | */ | ||
412 | int | ||
413 | DSA_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); | ||
432 | err: | ||
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 | ||
72 | DSA * | ||
73 | DSA_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 | |||
74 | static 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 | |||
104 | static 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 | |||
123 | void 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 | |||
73 | int | ||
74 | DSA_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 | |||
97 | int | ||
98 | dsa_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 | } | ||
300 | end: | ||
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; | ||
331 | err: | ||
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 eaf6da8de7..0000000000 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | /* $OpenBSD: dsa_key.c,v 1.20 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 | #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 | |||
69 | static int dsa_builtin_keygen(DSA *dsa); | ||
70 | |||
71 | int | ||
72 | DSA_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 | |||
79 | static int | ||
80 | dsa_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 local_prk; | ||
108 | BIGNUM *prk; | ||
109 | |||
110 | if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) { | ||
111 | BN_init(&local_prk); | ||
112 | prk = &local_prk; | ||
113 | BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); | ||
114 | } else | ||
115 | prk = priv_key; | ||
116 | |||
117 | if (!BN_mod_exp(pub_key, dsa->g, prk, dsa->p, ctx)) | ||
118 | goto err; | ||
119 | } | ||
120 | |||
121 | dsa->priv_key = priv_key; | ||
122 | dsa->pub_key = pub_key; | ||
123 | ok = 1; | ||
124 | |||
125 | err: | ||
126 | if (pub_key != NULL && dsa->pub_key == NULL) | ||
127 | BN_free(pub_key); | ||
128 | if (priv_key != NULL && dsa->priv_key == NULL) | ||
129 | BN_free(priv_key); | ||
130 | BN_CTX_free(ctx); | ||
131 | return ok; | ||
132 | } | ||
133 | #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 | |||
77 | static const DSA_METHOD *default_DSA_method = NULL; | ||
78 | |||
79 | void | ||
80 | DSA_set_default_method(const DSA_METHOD *meth) | ||
81 | { | ||
82 | default_DSA_method = meth; | ||
83 | } | ||
84 | |||
85 | const DSA_METHOD * | ||
86 | DSA_get_default_method(void) | ||
87 | { | ||
88 | if (!default_DSA_method) | ||
89 | default_DSA_method = DSA_OpenSSL(); | ||
90 | return default_DSA_method; | ||
91 | } | ||
92 | |||
93 | DSA * | ||
94 | DSA_new(void) | ||
95 | { | ||
96 | return DSA_new_method(NULL); | ||
97 | } | ||
98 | |||
99 | int | ||
100 | DSA_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 | |||
122 | DSA * | ||
123 | DSA_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 | |||
184 | void | ||
185 | DSA_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 | |||
215 | int | ||
216 | DSA_up_ref(DSA *r) | ||
217 | { | ||
218 | int i = CRYPTO_add(&r->references, 1, CRYPTO_LOCK_DSA); | ||
219 | return i > 1 ? 1 : 0; | ||
220 | } | ||
221 | |||
222 | int | ||
223 | DSA_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 | |||
245 | int | ||
246 | DSA_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 | |||
253 | int | ||
254 | DSA_set_ex_data(DSA *d, int idx, void *arg) | ||
255 | { | ||
256 | return CRYPTO_set_ex_data(&d->ex_data, idx, arg); | ||
257 | } | ||
258 | |||
259 | void * | ||
260 | DSA_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 | ||
266 | DH * | ||
267 | DSA_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 | |||
301 | err: | ||
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 | |||
58 | int 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 03124c87a0..0000000000 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ /dev/null | |||
@@ -1,423 +0,0 @@ | |||
1 | /* $OpenBSD: dsa_ossl.c,v 1.22 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 <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 | |||
69 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
70 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, | ||
71 | BIGNUM **rp); | ||
72 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | ||
73 | DSA *dsa); | ||
74 | static int dsa_init(DSA *dsa); | ||
75 | static int dsa_finish(DSA *dsa); | ||
76 | |||
77 | static 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 | |||
86 | /* | ||
87 | * These macro wrappers replace attempts to use the dsa_mod_exp() and | ||
88 | * bn_mod_exp() handlers in the DSA_METHOD structure. We avoid the problem of | ||
89 | * having a the macro work as an expression by bundling an "err_instr". So; | ||
90 | * | ||
91 | * if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx, | ||
92 | * dsa->method_mont_p)) goto err; | ||
93 | * | ||
94 | * can be replaced by; | ||
95 | * | ||
96 | * DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, &k, dsa->p, ctx, | ||
97 | * dsa->method_mont_p); | ||
98 | */ | ||
99 | |||
100 | #define DSA_MOD_EXP(err_instr,dsa,rr,a1,p1,a2,p2,m,ctx,in_mont) \ | ||
101 | do { \ | ||
102 | int _tmp_res53; \ | ||
103 | if ((dsa)->meth->dsa_mod_exp) \ | ||
104 | _tmp_res53 = (dsa)->meth->dsa_mod_exp((dsa), (rr), \ | ||
105 | (a1), (p1), (a2), (p2), (m), (ctx), (in_mont)); \ | ||
106 | else \ | ||
107 | _tmp_res53 = BN_mod_exp2_mont((rr), (a1), \ | ||
108 | (p1), (a2), (p2), (m), (ctx), (in_mont)); \ | ||
109 | if (!_tmp_res53) \ | ||
110 | err_instr; \ | ||
111 | } while(0) | ||
112 | |||
113 | #define DSA_BN_MOD_EXP(err_instr,dsa,r,a,p,m,ctx,m_ctx) \ | ||
114 | do { \ | ||
115 | int _tmp_res53; \ | ||
116 | if ((dsa)->meth->bn_mod_exp) \ | ||
117 | _tmp_res53 = (dsa)->meth->bn_mod_exp((dsa), (r), \ | ||
118 | (a), (p), (m), (ctx), (m_ctx)); \ | ||
119 | else \ | ||
120 | _tmp_res53 = BN_mod_exp_mont((r), (a), (p), (m), \ | ||
121 | (ctx), (m_ctx)); \ | ||
122 | if (!_tmp_res53) \ | ||
123 | err_instr; \ | ||
124 | } while(0) | ||
125 | |||
126 | const DSA_METHOD * | ||
127 | DSA_OpenSSL(void) | ||
128 | { | ||
129 | return &openssl_dsa_meth; | ||
130 | } | ||
131 | |||
132 | static DSA_SIG * | ||
133 | dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
134 | { | ||
135 | BIGNUM *kinv = NULL, *r = NULL, *s = NULL; | ||
136 | BIGNUM m; | ||
137 | BIGNUM xr; | ||
138 | BN_CTX *ctx = NULL; | ||
139 | int reason = ERR_R_BN_LIB; | ||
140 | DSA_SIG *ret = NULL; | ||
141 | int noredo = 0; | ||
142 | |||
143 | BN_init(&m); | ||
144 | BN_init(&xr); | ||
145 | |||
146 | if (!dsa->p || !dsa->q || !dsa->g) { | ||
147 | reason = DSA_R_MISSING_PARAMETERS; | ||
148 | goto err; | ||
149 | } | ||
150 | |||
151 | s = BN_new(); | ||
152 | if (s == NULL) | ||
153 | goto err; | ||
154 | ctx = BN_CTX_new(); | ||
155 | if (ctx == NULL) | ||
156 | goto err; | ||
157 | redo: | ||
158 | if (dsa->kinv == NULL || dsa->r == NULL) { | ||
159 | if (!DSA_sign_setup(dsa, ctx, &kinv, &r)) | ||
160 | goto err; | ||
161 | } else { | ||
162 | kinv = dsa->kinv; | ||
163 | dsa->kinv = NULL; | ||
164 | r = dsa->r; | ||
165 | dsa->r = NULL; | ||
166 | noredo = 1; | ||
167 | } | ||
168 | |||
169 | |||
170 | /* | ||
171 | * If the digest length is greater than the size of q use the | ||
172 | * BN_num_bits(dsa->q) leftmost bits of the digest, see | ||
173 | * fips 186-3, 4.2 | ||
174 | */ | ||
175 | if (dlen > BN_num_bytes(dsa->q)) | ||
176 | dlen = BN_num_bytes(dsa->q); | ||
177 | if (BN_bin2bn(dgst,dlen,&m) == NULL) | ||
178 | goto err; | ||
179 | |||
180 | /* Compute s = inv(k) (m + xr) mod q */ | ||
181 | if (!BN_mod_mul(&xr, dsa->priv_key, r, dsa->q, ctx)) /* s = xr */ | ||
182 | goto err; | ||
183 | if (!BN_add(s, &xr, &m)) /* s = m + xr */ | ||
184 | goto err; | ||
185 | if (BN_cmp(s, dsa->q) > 0) | ||
186 | if (!BN_sub(s, s, dsa->q)) | ||
187 | goto err; | ||
188 | if (!BN_mod_mul(s, s, kinv, dsa->q, ctx)) | ||
189 | goto err; | ||
190 | |||
191 | ret = DSA_SIG_new(); | ||
192 | if (ret == NULL) | ||
193 | goto err; | ||
194 | /* | ||
195 | * Redo if r or s is zero as required by FIPS 186-3: this is | ||
196 | * very unlikely. | ||
197 | */ | ||
198 | if (BN_is_zero(r) || BN_is_zero(s)) { | ||
199 | if (noredo) { | ||
200 | reason = DSA_R_NEED_NEW_SETUP_VALUES; | ||
201 | goto err; | ||
202 | } | ||
203 | goto redo; | ||
204 | } | ||
205 | ret->r = r; | ||
206 | ret->s = s; | ||
207 | |||
208 | err: | ||
209 | if (!ret) { | ||
210 | DSAerr(DSA_F_DSA_DO_SIGN, reason); | ||
211 | BN_free(r); | ||
212 | BN_free(s); | ||
213 | } | ||
214 | BN_CTX_free(ctx); | ||
215 | BN_clear_free(&m); | ||
216 | BN_clear_free(&xr); | ||
217 | BN_clear_free(kinv); | ||
218 | return ret; | ||
219 | } | ||
220 | |||
221 | static int | ||
222 | dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | ||
223 | { | ||
224 | BN_CTX *ctx; | ||
225 | BIGNUM k, kq, *K, *kinv = NULL, *r = NULL; | ||
226 | int ret = 0; | ||
227 | |||
228 | if (!dsa->p || !dsa->q || !dsa->g) { | ||
229 | DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS); | ||
230 | return 0; | ||
231 | } | ||
232 | |||
233 | BN_init(&k); | ||
234 | BN_init(&kq); | ||
235 | |||
236 | if (ctx_in == NULL) { | ||
237 | if ((ctx = BN_CTX_new()) == NULL) | ||
238 | goto err; | ||
239 | } else | ||
240 | ctx = ctx_in; | ||
241 | |||
242 | if ((r = BN_new()) == NULL) | ||
243 | goto err; | ||
244 | |||
245 | /* Get random k */ | ||
246 | do { | ||
247 | if (!BN_rand_range(&k, dsa->q)) | ||
248 | goto err; | ||
249 | } while (BN_is_zero(&k)); | ||
250 | if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) { | ||
251 | BN_set_flags(&k, BN_FLG_CONSTTIME); | ||
252 | } | ||
253 | |||
254 | if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { | ||
255 | if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p, | ||
256 | CRYPTO_LOCK_DSA, dsa->p, ctx)) | ||
257 | goto err; | ||
258 | } | ||
259 | |||
260 | /* Compute r = (g^k mod p) mod q */ | ||
261 | |||
262 | if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) { | ||
263 | if (!BN_copy(&kq, &k)) | ||
264 | goto err; | ||
265 | |||
266 | /* | ||
267 | * We do not want timing information to leak the length of k, | ||
268 | * so we compute g^k using an equivalent exponent of fixed | ||
269 | * length. | ||
270 | * | ||
271 | * (This is a kludge that we need because the BN_mod_exp_mont() | ||
272 | * does not let us specify the desired timing behaviour.) | ||
273 | */ | ||
274 | |||
275 | if (!BN_add(&kq, &kq, dsa->q)) | ||
276 | goto err; | ||
277 | if (BN_num_bits(&kq) <= BN_num_bits(dsa->q)) { | ||
278 | if (!BN_add(&kq, &kq, dsa->q)) | ||
279 | goto err; | ||
280 | } | ||
281 | |||
282 | K = &kq; | ||
283 | } else { | ||
284 | K = &k; | ||
285 | } | ||
286 | DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx, | ||
287 | dsa->method_mont_p); | ||
288 | if (!BN_mod(r,r,dsa->q,ctx)) | ||
289 | goto err; | ||
290 | |||
291 | /* Compute part of 's = inv(k) (m + xr) mod q' */ | ||
292 | if ((kinv = BN_mod_inverse(NULL, &k, dsa->q, ctx)) == NULL) | ||
293 | goto err; | ||
294 | |||
295 | BN_clear_free(*kinvp); | ||
296 | *kinvp = kinv; | ||
297 | kinv = NULL; | ||
298 | BN_clear_free(*rp); | ||
299 | *rp = r; | ||
300 | ret = 1; | ||
301 | err: | ||
302 | if (!ret) { | ||
303 | DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB); | ||
304 | BN_clear_free(r); | ||
305 | } | ||
306 | if (ctx_in == NULL) | ||
307 | BN_CTX_free(ctx); | ||
308 | BN_clear_free(&k); | ||
309 | BN_clear_free(&kq); | ||
310 | return ret; | ||
311 | } | ||
312 | |||
313 | static int | ||
314 | dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, DSA *dsa) | ||
315 | { | ||
316 | BN_CTX *ctx; | ||
317 | BIGNUM u1, u2, t1; | ||
318 | BN_MONT_CTX *mont = NULL; | ||
319 | int ret = -1, i; | ||
320 | |||
321 | if (!dsa->p || !dsa->q || !dsa->g) { | ||
322 | DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MISSING_PARAMETERS); | ||
323 | return -1; | ||
324 | } | ||
325 | |||
326 | i = BN_num_bits(dsa->q); | ||
327 | /* fips 186-3 allows only different sizes for q */ | ||
328 | if (i != 160 && i != 224 && i != 256) { | ||
329 | DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_BAD_Q_VALUE); | ||
330 | return -1; | ||
331 | } | ||
332 | |||
333 | if (BN_num_bits(dsa->p) > OPENSSL_DSA_MAX_MODULUS_BITS) { | ||
334 | DSAerr(DSA_F_DSA_DO_VERIFY, DSA_R_MODULUS_TOO_LARGE); | ||
335 | return -1; | ||
336 | } | ||
337 | BN_init(&u1); | ||
338 | BN_init(&u2); | ||
339 | BN_init(&t1); | ||
340 | |||
341 | if ((ctx = BN_CTX_new()) == NULL) | ||
342 | goto err; | ||
343 | |||
344 | if (BN_is_zero(sig->r) || BN_is_negative(sig->r) || | ||
345 | BN_ucmp(sig->r, dsa->q) >= 0) { | ||
346 | ret = 0; | ||
347 | goto err; | ||
348 | } | ||
349 | if (BN_is_zero(sig->s) || BN_is_negative(sig->s) || | ||
350 | BN_ucmp(sig->s, dsa->q) >= 0) { | ||
351 | ret = 0; | ||
352 | goto err; | ||
353 | } | ||
354 | |||
355 | /* Calculate W = inv(S) mod Q | ||
356 | * save W in u2 */ | ||
357 | if ((BN_mod_inverse(&u2, sig->s, dsa->q, ctx)) == NULL) | ||
358 | goto err; | ||
359 | |||
360 | /* save M in u1 */ | ||
361 | /* | ||
362 | * If the digest length is greater than the size of q use the | ||
363 | * BN_num_bits(dsa->q) leftmost bits of the digest, see | ||
364 | * fips 186-3, 4.2 | ||
365 | */ | ||
366 | if (dgst_len > (i >> 3)) | ||
367 | dgst_len = (i >> 3); | ||
368 | if (BN_bin2bn(dgst, dgst_len, &u1) == NULL) | ||
369 | goto err; | ||
370 | |||
371 | /* u1 = M * w mod q */ | ||
372 | if (!BN_mod_mul(&u1, &u1, &u2, dsa->q, ctx)) | ||
373 | goto err; | ||
374 | |||
375 | /* u2 = r * w mod q */ | ||
376 | if (!BN_mod_mul(&u2, sig->r, &u2, dsa->q, ctx)) | ||
377 | goto err; | ||
378 | |||
379 | |||
380 | if (dsa->flags & DSA_FLAG_CACHE_MONT_P) { | ||
381 | mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, | ||
382 | CRYPTO_LOCK_DSA, dsa->p, ctx); | ||
383 | if (!mont) | ||
384 | goto err; | ||
385 | } | ||
386 | |||
387 | DSA_MOD_EXP(goto err, dsa, &t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, | ||
388 | ctx, mont); | ||
389 | /* BN_copy(&u1,&t1); */ | ||
390 | /* let u1 = u1 mod q */ | ||
391 | if (!BN_mod(&u1, &t1, dsa->q, ctx)) | ||
392 | goto err; | ||
393 | |||
394 | /* V is now in u1. If the signature is correct, it will be | ||
395 | * equal to R. */ | ||
396 | ret = BN_ucmp(&u1, sig->r) == 0; | ||
397 | |||
398 | err: | ||
399 | /* XXX: surely this is wrong - if ret is 0, it just didn't verify; | ||
400 | there is no error in BN. Test should be ret == -1 (Ben) */ | ||
401 | if (ret != 1) | ||
402 | DSAerr(DSA_F_DSA_DO_VERIFY, ERR_R_BN_LIB); | ||
403 | BN_CTX_free(ctx); | ||
404 | BN_free(&u1); | ||
405 | BN_free(&u2); | ||
406 | BN_free(&t1); | ||
407 | return ret; | ||
408 | } | ||
409 | |||
410 | static int | ||
411 | dsa_init(DSA *dsa) | ||
412 | { | ||
413 | dsa->flags |= DSA_FLAG_CACHE_MONT_P; | ||
414 | return 1; | ||
415 | } | ||
416 | |||
417 | static int | ||
418 | dsa_finish(DSA *dsa) | ||
419 | { | ||
420 | BN_MONT_CTX_free(dsa->method_mont_p); | ||
421 | return 1; | ||
422 | } | ||
423 | |||
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 | |||
74 | typedef 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 | |||
85 | static int | ||
86 | pkey_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 | |||
105 | static int | ||
106 | pkey_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 | |||
121 | static void | ||
122 | pkey_dsa_cleanup(EVP_PKEY_CTX *ctx) | ||
123 | { | ||
124 | DSA_PKEY_CTX *dctx = ctx->data; | ||
125 | |||
126 | free(dctx); | ||
127 | } | ||
128 | |||
129 | static int | ||
130 | pkey_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 | |||
151 | static int | ||
152 | pkey_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 | |||
169 | static int | ||
170 | pkey_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 | |||
231 | static int | ||
232 | pkey_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 | } | ||
270 | not_a_number: | ||
271 | out_of_range: | ||
272 | return -2; | ||
273 | } | ||
274 | |||
275 | static int | ||
276 | pkey_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 | |||
300 | static int | ||
301 | pkey_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 | |||
319 | const 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 | |||
65 | int | ||
66 | DSA_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 | |||
81 | int | ||
82 | DSAparams_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 | |||
97 | int | ||
98 | DSA_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 | |||
111 | int | ||
112 | DSAparams_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 | |||
64 | DSA_SIG * | ||
65 | DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
66 | { | ||
67 | return dsa->meth->dsa_do_sign(dgst, dlen, dsa); | ||
68 | } | ||
69 | |||
70 | int | ||
71 | DSA_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 | |||
76 | DSA_SIG * | ||
77 | DSA_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 | |||
89 | void | ||
90 | DSA_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 | |||
63 | int | ||
64 | DSA_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 | } | ||