diff options
Diffstat (limited to 'src/lib/libcrypto/dsa')
-rw-r--r-- | src/lib/libcrypto/dsa/dsa.h | 257 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 96 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_err.c | 107 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_gen.c | 294 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 108 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_lib.c | 296 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 393 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_sign.c | 93 | ||||
-rw-r--r-- | src/lib/libcrypto/dsa/dsa_vrf.c | 95 |
9 files changed, 0 insertions, 1739 deletions
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h deleted file mode 100644 index 12b60a8faa..0000000000 --- a/src/lib/libcrypto/dsa/dsa.h +++ /dev/null | |||
@@ -1,257 +0,0 @@ | |||
1 | /* crypto/dsa/dsa.h */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* | ||
60 | * The DSS routines are based on patches supplied by | ||
61 | * Steven Schoch <schoch@sheba.arc.nasa.gov>. He basically did the | ||
62 | * work and I have just tweaked them a little to fit into my | ||
63 | * stylistic vision for SSLeay :-) */ | ||
64 | |||
65 | #ifndef HEADER_DSA_H | ||
66 | #define HEADER_DSA_H | ||
67 | |||
68 | #ifdef NO_DSA | ||
69 | #error DSA is disabled. | ||
70 | #endif | ||
71 | |||
72 | #ifndef NO_BIO | ||
73 | #include <openssl/bio.h> | ||
74 | #endif | ||
75 | #include <openssl/bn.h> | ||
76 | #include <openssl/crypto.h> | ||
77 | #ifndef NO_DH | ||
78 | # include <openssl/dh.h> | ||
79 | #endif | ||
80 | |||
81 | #define DSA_FLAG_CACHE_MONT_P 0x01 | ||
82 | |||
83 | #ifdef __cplusplus | ||
84 | extern "C" { | ||
85 | #endif | ||
86 | |||
87 | typedef struct dsa_st DSA; | ||
88 | |||
89 | typedef struct DSA_SIG_st | ||
90 | { | ||
91 | BIGNUM *r; | ||
92 | BIGNUM *s; | ||
93 | } DSA_SIG; | ||
94 | |||
95 | typedef struct dsa_method { | ||
96 | const char *name; | ||
97 | DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa); | ||
98 | int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, | ||
99 | BIGNUM **rp); | ||
100 | int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len, | ||
101 | DSA_SIG *sig, DSA *dsa); | ||
102 | int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, | ||
103 | BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, | ||
104 | BN_MONT_CTX *in_mont); | ||
105 | int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
106 | const BIGNUM *m, BN_CTX *ctx, | ||
107 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
108 | int (*init)(DSA *dsa); | ||
109 | int (*finish)(DSA *dsa); | ||
110 | int flags; | ||
111 | char *app_data; | ||
112 | } DSA_METHOD; | ||
113 | |||
114 | struct dsa_st | ||
115 | { | ||
116 | /* This first variable is used to pick up errors where | ||
117 | * a DSA is passed instead of of a EVP_PKEY */ | ||
118 | int pad; | ||
119 | int version; | ||
120 | int write_params; | ||
121 | BIGNUM *p; | ||
122 | BIGNUM *q; /* == 20 */ | ||
123 | BIGNUM *g; | ||
124 | |||
125 | BIGNUM *pub_key; /* y public key */ | ||
126 | BIGNUM *priv_key; /* x private key */ | ||
127 | |||
128 | BIGNUM *kinv; /* Signing pre-calc */ | ||
129 | BIGNUM *r; /* Signing pre-calc */ | ||
130 | |||
131 | int flags; | ||
132 | /* Normally used to cache montgomery values */ | ||
133 | char *method_mont_p; | ||
134 | int references; | ||
135 | CRYPTO_EX_DATA ex_data; | ||
136 | #if 0 | ||
137 | DSA_METHOD *meth; | ||
138 | #else | ||
139 | struct engine_st *engine; | ||
140 | #endif | ||
141 | }; | ||
142 | |||
143 | #define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ | ||
144 | (char *(*)())d2i_DSAparams,(char *)(x)) | ||
145 | #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ | ||
146 | (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) | ||
147 | #define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ | ||
148 | (unsigned char *)(x)) | ||
149 | #define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \ | ||
150 | (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x)) | ||
151 | #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \ | ||
152 | (unsigned char *)(x)) | ||
153 | |||
154 | |||
155 | DSA_SIG * DSA_SIG_new(void); | ||
156 | void DSA_SIG_free(DSA_SIG *a); | ||
157 | int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp); | ||
158 | DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length); | ||
159 | |||
160 | DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa); | ||
161 | int DSA_do_verify(const unsigned char *dgst,int dgst_len, | ||
162 | DSA_SIG *sig,DSA *dsa); | ||
163 | |||
164 | DSA_METHOD *DSA_OpenSSL(void); | ||
165 | |||
166 | void DSA_set_default_openssl_method(DSA_METHOD *); | ||
167 | DSA_METHOD *DSA_get_default_openssl_method(void); | ||
168 | #if 0 | ||
169 | DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *); | ||
170 | #else | ||
171 | int DSA_set_method(DSA *dsa, struct engine_st *engine); | ||
172 | #endif | ||
173 | |||
174 | DSA * DSA_new(void); | ||
175 | #if 0 | ||
176 | DSA * DSA_new_method(DSA_METHOD *meth); | ||
177 | #else | ||
178 | DSA * DSA_new_method(struct engine_st *engine); | ||
179 | #endif | ||
180 | int DSA_size(DSA *); | ||
181 | /* next 4 return -1 on error */ | ||
182 | int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); | ||
183 | int DSA_sign(int type,const unsigned char *dgst,int dlen, | ||
184 | unsigned char *sig, unsigned int *siglen, DSA *dsa); | ||
185 | int DSA_verify(int type,const unsigned char *dgst,int dgst_len, | ||
186 | unsigned char *sigbuf, int siglen, DSA *dsa); | ||
187 | void DSA_free (DSA *r); | ||
188 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
189 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
190 | int DSA_set_ex_data(DSA *d, int idx, void *arg); | ||
191 | void *DSA_get_ex_data(DSA *d, int idx); | ||
192 | |||
193 | void ERR_load_DSA_strings(void ); | ||
194 | |||
195 | DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length); | ||
196 | DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); | ||
197 | DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length); | ||
198 | DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len, | ||
199 | int *counter_ret, unsigned long *h_ret,void | ||
200 | (*callback)(int, int, void *),void *cb_arg); | ||
201 | int DSA_generate_key(DSA *a); | ||
202 | int i2d_DSAPublicKey(DSA *a, unsigned char **pp); | ||
203 | int i2d_DSAPrivateKey(DSA *a, unsigned char **pp); | ||
204 | int i2d_DSAparams(DSA *a,unsigned char **pp); | ||
205 | |||
206 | #ifndef NO_BIO | ||
207 | int DSAparams_print(BIO *bp, DSA *x); | ||
208 | int DSA_print(BIO *bp, DSA *x, int off); | ||
209 | #endif | ||
210 | #ifndef NO_FP_API | ||
211 | int DSAparams_print_fp(FILE *fp, DSA *x); | ||
212 | int DSA_print_fp(FILE *bp, DSA *x, int off); | ||
213 | #endif | ||
214 | |||
215 | #define DSS_prime_checks 50 | ||
216 | /* Primality test according to FIPS PUB 186[-1], Appendix 2.1: | ||
217 | * 50 rounds of Rabin-Miller */ | ||
218 | #define DSA_is_prime(n, callback, cb_arg) \ | ||
219 | BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg) | ||
220 | |||
221 | #ifndef NO_DH | ||
222 | /* Convert DSA structure (key or just parameters) into DH structure | ||
223 | * (be careful to avoid small subgroup attacks when using this!) */ | ||
224 | DH *DSA_dup_DH(DSA *r); | ||
225 | #endif | ||
226 | |||
227 | /* BEGIN ERROR CODES */ | ||
228 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
229 | * made after this point may be overwritten when the script is next run. | ||
230 | */ | ||
231 | |||
232 | /* Error codes for the DSA functions. */ | ||
233 | |||
234 | /* Function codes. */ | ||
235 | #define DSA_F_D2I_DSA_SIG 110 | ||
236 | #define DSA_F_DSAPARAMS_PRINT 100 | ||
237 | #define DSA_F_DSAPARAMS_PRINT_FP 101 | ||
238 | #define DSA_F_DSA_DO_SIGN 112 | ||
239 | #define DSA_F_DSA_DO_VERIFY 113 | ||
240 | #define DSA_F_DSA_NEW 103 | ||
241 | #define DSA_F_DSA_PRINT 104 | ||
242 | #define DSA_F_DSA_PRINT_FP 105 | ||
243 | #define DSA_F_DSA_SIGN 106 | ||
244 | #define DSA_F_DSA_SIGN_SETUP 107 | ||
245 | #define DSA_F_DSA_SIG_NEW 109 | ||
246 | #define DSA_F_DSA_VERIFY 108 | ||
247 | #define DSA_F_I2D_DSA_SIG 111 | ||
248 | |||
249 | /* Reason codes. */ | ||
250 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 | ||
251 | #define DSA_R_MISSING_PARAMETERS 101 | ||
252 | |||
253 | #ifdef __cplusplus | ||
254 | } | ||
255 | #endif | ||
256 | #endif | ||
257 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c deleted file mode 100644 index a76c8f7c7e..0000000000 --- a/src/lib/libcrypto/dsa/dsa_asn1.c +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_asn1.c */ | ||
2 | |||
3 | #include <stdio.h> | ||
4 | #include "cryptlib.h" | ||
5 | #include <openssl/dsa.h> | ||
6 | #include <openssl/asn1.h> | ||
7 | #include <openssl/asn1_mac.h> | ||
8 | |||
9 | DSA_SIG *DSA_SIG_new(void) | ||
10 | { | ||
11 | DSA_SIG *ret; | ||
12 | |||
13 | ret = OPENSSL_malloc(sizeof(DSA_SIG)); | ||
14 | if (ret == NULL) | ||
15 | { | ||
16 | DSAerr(DSA_F_DSA_SIG_NEW,ERR_R_MALLOC_FAILURE); | ||
17 | return(NULL); | ||
18 | } | ||
19 | ret->r = NULL; | ||
20 | ret->s = NULL; | ||
21 | return(ret); | ||
22 | } | ||
23 | |||
24 | void DSA_SIG_free(DSA_SIG *r) | ||
25 | { | ||
26 | if (r == NULL) return; | ||
27 | if (r->r) BN_clear_free(r->r); | ||
28 | if (r->s) BN_clear_free(r->s); | ||
29 | OPENSSL_free(r); | ||
30 | } | ||
31 | |||
32 | int i2d_DSA_SIG(DSA_SIG *v, unsigned char **pp) | ||
33 | { | ||
34 | int t=0,len; | ||
35 | ASN1_INTEGER rbs,sbs; | ||
36 | unsigned char *p; | ||
37 | |||
38 | rbs.data=OPENSSL_malloc(BN_num_bits(v->r)/8+1); | ||
39 | if (rbs.data == NULL) | ||
40 | { | ||
41 | DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE); | ||
42 | return(0); | ||
43 | } | ||
44 | rbs.type=V_ASN1_INTEGER; | ||
45 | rbs.length=BN_bn2bin(v->r,rbs.data); | ||
46 | sbs.data=OPENSSL_malloc(BN_num_bits(v->s)/8+1); | ||
47 | if (sbs.data == NULL) | ||
48 | { | ||
49 | OPENSSL_free(rbs.data); | ||
50 | DSAerr(DSA_F_I2D_DSA_SIG, ERR_R_MALLOC_FAILURE); | ||
51 | return(0); | ||
52 | } | ||
53 | sbs.type=V_ASN1_INTEGER; | ||
54 | sbs.length=BN_bn2bin(v->s,sbs.data); | ||
55 | |||
56 | len=i2d_ASN1_INTEGER(&rbs,NULL); | ||
57 | len+=i2d_ASN1_INTEGER(&sbs,NULL); | ||
58 | |||
59 | if (pp) | ||
60 | { | ||
61 | p=*pp; | ||
62 | ASN1_put_object(&p,1,len,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL); | ||
63 | i2d_ASN1_INTEGER(&rbs,&p); | ||
64 | i2d_ASN1_INTEGER(&sbs,&p); | ||
65 | } | ||
66 | t=ASN1_object_size(1,len,V_ASN1_SEQUENCE); | ||
67 | OPENSSL_free(rbs.data); | ||
68 | OPENSSL_free(sbs.data); | ||
69 | return(t); | ||
70 | } | ||
71 | |||
72 | DSA_SIG *d2i_DSA_SIG(DSA_SIG **a, unsigned char **pp, long length) | ||
73 | { | ||
74 | int i=ERR_R_NESTED_ASN1_ERROR; | ||
75 | ASN1_INTEGER *bs=NULL; | ||
76 | M_ASN1_D2I_vars(a,DSA_SIG *,DSA_SIG_new); | ||
77 | |||
78 | M_ASN1_D2I_Init(); | ||
79 | M_ASN1_D2I_start_sequence(); | ||
80 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
81 | if ((ret->r=BN_bin2bn(bs->data,bs->length,ret->r)) == NULL) | ||
82 | goto err_bn; | ||
83 | M_ASN1_D2I_get(bs,d2i_ASN1_INTEGER); | ||
84 | if ((ret->s=BN_bin2bn(bs->data,bs->length,ret->s)) == NULL) | ||
85 | goto err_bn; | ||
86 | M_ASN1_BIT_STRING_free(bs); | ||
87 | M_ASN1_D2I_Finish_2(a); | ||
88 | |||
89 | err_bn: | ||
90 | i=ERR_R_BN_LIB; | ||
91 | err: | ||
92 | DSAerr(DSA_F_D2I_DSA_SIG,i); | ||
93 | if ((ret != NULL) && ((a == NULL) || (*a != ret))) DSA_SIG_free(ret); | ||
94 | if (bs != NULL) M_ASN1_BIT_STRING_free(bs); | ||
95 | return(NULL); | ||
96 | } | ||
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c deleted file mode 100644 index 736aeef7c4..0000000000 --- a/src/lib/libcrypto/dsa/dsa_err.c +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_err.c */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * openssl-core@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | /* NOTE: this file was auto generated by the mkerr.pl script: any changes | ||
57 | * made to it will be overwritten when the script next updates this file, | ||
58 | * only reason strings will be preserved. | ||
59 | */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include <openssl/err.h> | ||
63 | #include <openssl/dsa.h> | ||
64 | |||
65 | /* BEGIN ERROR CODES */ | ||
66 | #ifndef NO_ERR | ||
67 | static ERR_STRING_DATA DSA_str_functs[]= | ||
68 | { | ||
69 | {ERR_PACK(0,DSA_F_D2I_DSA_SIG,0), "d2i_DSA_SIG"}, | ||
70 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT,0), "DSAparams_print"}, | ||
71 | {ERR_PACK(0,DSA_F_DSAPARAMS_PRINT_FP,0), "DSAparams_print_fp"}, | ||
72 | {ERR_PACK(0,DSA_F_DSA_DO_SIGN,0), "DSA_do_sign"}, | ||
73 | {ERR_PACK(0,DSA_F_DSA_DO_VERIFY,0), "DSA_do_verify"}, | ||
74 | {ERR_PACK(0,DSA_F_DSA_NEW,0), "DSA_new"}, | ||
75 | {ERR_PACK(0,DSA_F_DSA_PRINT,0), "DSA_print"}, | ||
76 | {ERR_PACK(0,DSA_F_DSA_PRINT_FP,0), "DSA_print_fp"}, | ||
77 | {ERR_PACK(0,DSA_F_DSA_SIGN,0), "DSA_sign"}, | ||
78 | {ERR_PACK(0,DSA_F_DSA_SIGN_SETUP,0), "DSA_sign_setup"}, | ||
79 | {ERR_PACK(0,DSA_F_DSA_SIG_NEW,0), "DSA_SIG_new"}, | ||
80 | {ERR_PACK(0,DSA_F_DSA_VERIFY,0), "DSA_verify"}, | ||
81 | {ERR_PACK(0,DSA_F_I2D_DSA_SIG,0), "i2d_DSA_SIG"}, | ||
82 | {0,NULL} | ||
83 | }; | ||
84 | |||
85 | static ERR_STRING_DATA DSA_str_reasons[]= | ||
86 | { | ||
87 | {DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE ,"data too large for key size"}, | ||
88 | {DSA_R_MISSING_PARAMETERS ,"missing parameters"}, | ||
89 | {0,NULL} | ||
90 | }; | ||
91 | |||
92 | #endif | ||
93 | |||
94 | void ERR_load_DSA_strings(void) | ||
95 | { | ||
96 | static int init=1; | ||
97 | |||
98 | if (init) | ||
99 | { | ||
100 | init=0; | ||
101 | #ifndef NO_ERR | ||
102 | ERR_load_strings(ERR_LIB_DSA,DSA_str_functs); | ||
103 | ERR_load_strings(ERR_LIB_DSA,DSA_str_reasons); | ||
104 | #endif | ||
105 | |||
106 | } | ||
107 | } | ||
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c deleted file mode 100644 index 2294a362d9..0000000000 --- a/src/lib/libcrypto/dsa/dsa_gen.c +++ /dev/null | |||
@@ -1,294 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_gen.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #undef GENUINE_DSA | ||
60 | |||
61 | #ifdef GENUINE_DSA | ||
62 | /* Parameter generation follows the original release of FIPS PUB 186, | ||
63 | * Appendix 2.2 (i.e. use SHA as defined in FIPS PUB 180) */ | ||
64 | #define HASH SHA | ||
65 | #else | ||
66 | /* Parameter generation follows the updated Appendix 2.2 for FIPS PUB 186, | ||
67 | * also Appendix 2.2 of FIPS PUB 186-1 (i.e. use SHA as defined in | ||
68 | * FIPS PUB 180-1) */ | ||
69 | #define HASH SHA1 | ||
70 | #endif | ||
71 | |||
72 | #ifndef NO_SHA | ||
73 | |||
74 | #include <stdio.h> | ||
75 | #include <time.h> | ||
76 | #include "cryptlib.h" | ||
77 | #include <openssl/sha.h> | ||
78 | #include <openssl/bn.h> | ||
79 | #include <openssl/dsa.h> | ||
80 | #include <openssl/rand.h> | ||
81 | |||
82 | DSA *DSA_generate_parameters(int bits, unsigned char *seed_in, int seed_len, | ||
83 | int *counter_ret, unsigned long *h_ret, | ||
84 | void (*callback)(int, int, void *), | ||
85 | void *cb_arg) | ||
86 | { | ||
87 | int ok=0; | ||
88 | unsigned char seed[SHA_DIGEST_LENGTH]; | ||
89 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
90 | unsigned char buf[SHA_DIGEST_LENGTH],buf2[SHA_DIGEST_LENGTH]; | ||
91 | BIGNUM *r0,*W,*X,*c,*test; | ||
92 | BIGNUM *g=NULL,*q=NULL,*p=NULL; | ||
93 | BN_MONT_CTX *mont=NULL; | ||
94 | int k,n=0,i,b,m=0; | ||
95 | int counter=0; | ||
96 | int r=0; | ||
97 | BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL; | ||
98 | unsigned int h=2; | ||
99 | DSA *ret=NULL; | ||
100 | |||
101 | if (bits < 512) bits=512; | ||
102 | bits=(bits+63)/64*64; | ||
103 | |||
104 | if (seed_len < 20) | ||
105 | seed_in = NULL; /* seed buffer too small -- ignore */ | ||
106 | if (seed_len > 20) | ||
107 | seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED, | ||
108 | * but our internal buffers are restricted to 160 bits*/ | ||
109 | if ((seed_in != NULL) && (seed_len == 20)) | ||
110 | memcpy(seed,seed_in,seed_len); | ||
111 | |||
112 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
113 | if ((ctx2=BN_CTX_new()) == NULL) goto err; | ||
114 | if ((ctx3=BN_CTX_new()) == NULL) goto err; | ||
115 | if ((ret=DSA_new()) == NULL) goto err; | ||
116 | |||
117 | if ((mont=BN_MONT_CTX_new()) == NULL) goto err; | ||
118 | |||
119 | BN_CTX_start(ctx2); | ||
120 | r0 = BN_CTX_get(ctx2); | ||
121 | g = BN_CTX_get(ctx2); | ||
122 | W = BN_CTX_get(ctx2); | ||
123 | q = BN_CTX_get(ctx2); | ||
124 | X = BN_CTX_get(ctx2); | ||
125 | c = BN_CTX_get(ctx2); | ||
126 | p = BN_CTX_get(ctx2); | ||
127 | test = BN_CTX_get(ctx2); | ||
128 | |||
129 | BN_lshift(test,BN_value_one(),bits-1); | ||
130 | |||
131 | for (;;) | ||
132 | { | ||
133 | for (;;) /* find q */ | ||
134 | { | ||
135 | int seed_is_random; | ||
136 | |||
137 | /* step 1 */ | ||
138 | if (callback != NULL) callback(0,m++,cb_arg); | ||
139 | |||
140 | if (!seed_len) | ||
141 | { | ||
142 | RAND_pseudo_bytes(seed,SHA_DIGEST_LENGTH); | ||
143 | seed_is_random = 1; | ||
144 | } | ||
145 | else | ||
146 | { | ||
147 | seed_is_random = 0; | ||
148 | seed_len=0; /* use random seed if 'seed_in' turns out to be bad*/ | ||
149 | } | ||
150 | memcpy(buf,seed,SHA_DIGEST_LENGTH); | ||
151 | memcpy(buf2,seed,SHA_DIGEST_LENGTH); | ||
152 | /* precompute "SEED + 1" for step 7: */ | ||
153 | for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--) | ||
154 | { | ||
155 | buf[i]++; | ||
156 | if (buf[i] != 0) break; | ||
157 | } | ||
158 | |||
159 | /* step 2 */ | ||
160 | HASH(seed,SHA_DIGEST_LENGTH,md); | ||
161 | HASH(buf,SHA_DIGEST_LENGTH,buf2); | ||
162 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
163 | md[i]^=buf2[i]; | ||
164 | |||
165 | /* step 3 */ | ||
166 | md[0]|=0x80; | ||
167 | md[SHA_DIGEST_LENGTH-1]|=0x01; | ||
168 | if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err; | ||
169 | |||
170 | /* step 4 */ | ||
171 | r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random); | ||
172 | if (r > 0) | ||
173 | break; | ||
174 | if (r != 0) | ||
175 | goto err; | ||
176 | |||
177 | /* do a callback call */ | ||
178 | /* step 5 */ | ||
179 | } | ||
180 | |||
181 | if (callback != NULL) callback(2,0,cb_arg); | ||
182 | if (callback != NULL) callback(3,0,cb_arg); | ||
183 | |||
184 | /* step 6 */ | ||
185 | counter=0; | ||
186 | /* "offset = 2" */ | ||
187 | |||
188 | n=(bits-1)/160; | ||
189 | b=(bits-1)-n*160; | ||
190 | |||
191 | for (;;) | ||
192 | { | ||
193 | if (callback != NULL && counter != 0) | ||
194 | callback(0,counter,cb_arg); | ||
195 | |||
196 | /* step 7 */ | ||
197 | BN_zero(W); | ||
198 | /* now 'buf' contains "SEED + offset - 1" */ | ||
199 | for (k=0; k<=n; k++) | ||
200 | { | ||
201 | /* obtain "SEED + offset + k" by incrementing: */ | ||
202 | for (i=SHA_DIGEST_LENGTH-1; i >= 0; i--) | ||
203 | { | ||
204 | buf[i]++; | ||
205 | if (buf[i] != 0) break; | ||
206 | } | ||
207 | |||
208 | HASH(buf,SHA_DIGEST_LENGTH,md); | ||
209 | |||
210 | /* step 8 */ | ||
211 | if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,r0)) | ||
212 | goto err; | ||
213 | BN_lshift(r0,r0,160*k); | ||
214 | BN_add(W,W,r0); | ||
215 | } | ||
216 | |||
217 | /* more of step 8 */ | ||
218 | BN_mask_bits(W,bits-1); | ||
219 | BN_copy(X,W); /* this should be ok */ | ||
220 | BN_add(X,X,test); /* this should be ok */ | ||
221 | |||
222 | /* step 9 */ | ||
223 | BN_lshift1(r0,q); | ||
224 | BN_mod(c,X,r0,ctx); | ||
225 | BN_sub(r0,c,BN_value_one()); | ||
226 | BN_sub(p,X,r0); | ||
227 | |||
228 | /* step 10 */ | ||
229 | if (BN_cmp(p,test) >= 0) | ||
230 | { | ||
231 | /* step 11 */ | ||
232 | r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1); | ||
233 | if (r > 0) | ||
234 | goto end; /* found it */ | ||
235 | if (r != 0) | ||
236 | goto err; | ||
237 | } | ||
238 | |||
239 | /* step 13 */ | ||
240 | counter++; | ||
241 | /* "offset = offset + n + 1" */ | ||
242 | |||
243 | /* step 14 */ | ||
244 | if (counter >= 4096) break; | ||
245 | } | ||
246 | } | ||
247 | end: | ||
248 | if (callback != NULL) callback(2,1,cb_arg); | ||
249 | |||
250 | /* We now need to generate g */ | ||
251 | /* Set r0=(p-1)/q */ | ||
252 | BN_sub(test,p,BN_value_one()); | ||
253 | BN_div(r0,NULL,test,q,ctx); | ||
254 | |||
255 | BN_set_word(test,h); | ||
256 | BN_MONT_CTX_set(mont,p,ctx); | ||
257 | |||
258 | for (;;) | ||
259 | { | ||
260 | /* g=test^r0%p */ | ||
261 | BN_mod_exp_mont(g,test,r0,p,ctx,mont); | ||
262 | if (!BN_is_one(g)) break; | ||
263 | BN_add(test,test,BN_value_one()); | ||
264 | h++; | ||
265 | } | ||
266 | |||
267 | if (callback != NULL) callback(3,1,cb_arg); | ||
268 | |||
269 | ok=1; | ||
270 | err: | ||
271 | if (!ok) | ||
272 | { | ||
273 | if (ret != NULL) DSA_free(ret); | ||
274 | } | ||
275 | else | ||
276 | { | ||
277 | ret->p=BN_dup(p); | ||
278 | ret->q=BN_dup(q); | ||
279 | ret->g=BN_dup(g); | ||
280 | if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20); | ||
281 | if (counter_ret != NULL) *counter_ret=counter; | ||
282 | if (h_ret != NULL) *h_ret=h; | ||
283 | } | ||
284 | if (ctx != NULL) BN_CTX_free(ctx); | ||
285 | if (ctx2 != NULL) | ||
286 | { | ||
287 | BN_CTX_end(ctx2); | ||
288 | BN_CTX_free(ctx2); | ||
289 | } | ||
290 | if (ctx3 != NULL) BN_CTX_free(ctx3); | ||
291 | if (mont != NULL) BN_MONT_CTX_free(mont); | ||
292 | return(ok?ret:NULL); | ||
293 | } | ||
294 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c deleted file mode 100644 index a68d236e05..0000000000 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ /dev/null | |||
@@ -1,108 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_key.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | #ifndef NO_SHA | ||
60 | #include <stdio.h> | ||
61 | #include <time.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/sha.h> | ||
64 | #include <openssl/bn.h> | ||
65 | #include <openssl/dsa.h> | ||
66 | #include <openssl/rand.h> | ||
67 | |||
68 | extern int __BN_rand_range(BIGNUM *r, BIGNUM *range); | ||
69 | |||
70 | int DSA_generate_key(DSA *dsa) | ||
71 | { | ||
72 | int ok=0; | ||
73 | BN_CTX *ctx=NULL; | ||
74 | BIGNUM *pub_key=NULL,*priv_key=NULL; | ||
75 | |||
76 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
77 | |||
78 | if (dsa->priv_key == NULL) | ||
79 | { | ||
80 | if ((priv_key=BN_new()) == NULL) goto err; | ||
81 | } | ||
82 | else | ||
83 | priv_key=dsa->priv_key; | ||
84 | |||
85 | do | ||
86 | if (!__BN_rand_range(priv_key,dsa->q)) goto err; | ||
87 | while (BN_is_zero(priv_key)); | ||
88 | |||
89 | if (dsa->pub_key == NULL) | ||
90 | { | ||
91 | if ((pub_key=BN_new()) == NULL) goto err; | ||
92 | } | ||
93 | else | ||
94 | pub_key=dsa->pub_key; | ||
95 | |||
96 | if (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err; | ||
97 | |||
98 | dsa->priv_key=priv_key; | ||
99 | dsa->pub_key=pub_key; | ||
100 | ok=1; | ||
101 | |||
102 | err: | ||
103 | if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key); | ||
104 | if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key); | ||
105 | if (ctx != NULL) BN_CTX_free(ctx); | ||
106 | return(ok); | ||
107 | } | ||
108 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c deleted file mode 100644 index 15f667a203..0000000000 --- a/src/lib/libcrypto/dsa/dsa_lib.c +++ /dev/null | |||
@@ -1,296 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_lib.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/bn.h> | ||
64 | #include <openssl/dsa.h> | ||
65 | #include <openssl/asn1.h> | ||
66 | #include <openssl/engine.h> | ||
67 | |||
68 | const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; | ||
69 | |||
70 | static DSA_METHOD *default_DSA_method; | ||
71 | static int dsa_meth_num = 0; | ||
72 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dsa_meth = NULL; | ||
73 | |||
74 | void DSA_set_default_openssl_method(DSA_METHOD *meth) | ||
75 | { | ||
76 | ENGINE *e; | ||
77 | /* We'll need to notify the "openssl" ENGINE of this | ||
78 | * change too. We won't bother locking things down at | ||
79 | * our end as there was never any locking in these | ||
80 | * functions! */ | ||
81 | if(default_DSA_method != meth) | ||
82 | { | ||
83 | default_DSA_method = meth; | ||
84 | e = ENGINE_by_id("openssl"); | ||
85 | if(e) | ||
86 | { | ||
87 | ENGINE_set_DSA(e, meth); | ||
88 | ENGINE_free(e); | ||
89 | } | ||
90 | } | ||
91 | } | ||
92 | |||
93 | DSA_METHOD *DSA_get_default_openssl_method(void) | ||
94 | { | ||
95 | if(!default_DSA_method) default_DSA_method = DSA_OpenSSL(); | ||
96 | return default_DSA_method; | ||
97 | } | ||
98 | |||
99 | DSA *DSA_new(void) | ||
100 | { | ||
101 | return DSA_new_method(NULL); | ||
102 | } | ||
103 | |||
104 | #if 0 | ||
105 | DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth) | ||
106 | { | ||
107 | DSA_METHOD *mtmp; | ||
108 | mtmp = dsa->meth; | ||
109 | if (mtmp->finish) mtmp->finish(dsa); | ||
110 | dsa->meth = meth; | ||
111 | if (meth->init) meth->init(dsa); | ||
112 | return mtmp; | ||
113 | } | ||
114 | #else | ||
115 | int DSA_set_method(DSA *dsa, ENGINE *engine) | ||
116 | { | ||
117 | ENGINE *mtmp; | ||
118 | DSA_METHOD *meth; | ||
119 | mtmp = dsa->engine; | ||
120 | meth = ENGINE_get_DSA(mtmp); | ||
121 | if (!ENGINE_init(engine)) | ||
122 | return 0; | ||
123 | if (meth->finish) meth->finish(dsa); | ||
124 | dsa->engine = engine; | ||
125 | meth = ENGINE_get_DSA(engine); | ||
126 | if (meth->init) meth->init(dsa); | ||
127 | /* SHOULD ERROR CHECK THIS!!! */ | ||
128 | ENGINE_finish(mtmp); | ||
129 | return 1; | ||
130 | } | ||
131 | #endif | ||
132 | |||
133 | |||
134 | #if 0 | ||
135 | DSA *DSA_new_method(DSA_METHOD *meth) | ||
136 | #else | ||
137 | DSA *DSA_new_method(ENGINE *engine) | ||
138 | #endif | ||
139 | { | ||
140 | DSA_METHOD *meth; | ||
141 | DSA *ret; | ||
142 | |||
143 | ret=(DSA *)OPENSSL_malloc(sizeof(DSA)); | ||
144 | if (ret == NULL) | ||
145 | { | ||
146 | DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE); | ||
147 | return(NULL); | ||
148 | } | ||
149 | if(engine) | ||
150 | ret->engine = engine; | ||
151 | else | ||
152 | { | ||
153 | if((ret->engine=ENGINE_get_default_DSA()) == NULL) | ||
154 | { | ||
155 | OPENSSL_free(ret); | ||
156 | return NULL; | ||
157 | } | ||
158 | } | ||
159 | meth = ENGINE_get_DSA(ret->engine); | ||
160 | ret->pad=0; | ||
161 | ret->version=0; | ||
162 | ret->write_params=1; | ||
163 | ret->p=NULL; | ||
164 | ret->q=NULL; | ||
165 | ret->g=NULL; | ||
166 | |||
167 | ret->pub_key=NULL; | ||
168 | ret->priv_key=NULL; | ||
169 | |||
170 | ret->kinv=NULL; | ||
171 | ret->r=NULL; | ||
172 | ret->method_mont_p=NULL; | ||
173 | |||
174 | ret->references=1; | ||
175 | ret->flags=meth->flags; | ||
176 | CRYPTO_new_ex_data(dsa_meth,ret,&ret->ex_data); | ||
177 | if ((meth->init != NULL) && !meth->init(ret)) | ||
178 | { | ||
179 | CRYPTO_free_ex_data(dsa_meth,ret,&ret->ex_data); | ||
180 | OPENSSL_free(ret); | ||
181 | ret=NULL; | ||
182 | } | ||
183 | |||
184 | return(ret); | ||
185 | } | ||
186 | |||
187 | void DSA_free(DSA *r) | ||
188 | { | ||
189 | DSA_METHOD *meth; | ||
190 | int i; | ||
191 | |||
192 | if (r == NULL) return; | ||
193 | |||
194 | i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA); | ||
195 | #ifdef REF_PRINT | ||
196 | REF_PRINT("DSA",r); | ||
197 | #endif | ||
198 | if (i > 0) return; | ||
199 | #ifdef REF_CHECK | ||
200 | if (i < 0) | ||
201 | { | ||
202 | fprintf(stderr,"DSA_free, bad reference count\n"); | ||
203 | abort(); | ||
204 | } | ||
205 | #endif | ||
206 | |||
207 | meth = ENGINE_get_DSA(r->engine); | ||
208 | if(meth->finish) meth->finish(r); | ||
209 | ENGINE_finish(r->engine); | ||
210 | |||
211 | CRYPTO_free_ex_data(dsa_meth, r, &r->ex_data); | ||
212 | |||
213 | if (r->p != NULL) BN_clear_free(r->p); | ||
214 | if (r->q != NULL) BN_clear_free(r->q); | ||
215 | if (r->g != NULL) BN_clear_free(r->g); | ||
216 | if (r->pub_key != NULL) BN_clear_free(r->pub_key); | ||
217 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); | ||
218 | if (r->kinv != NULL) BN_clear_free(r->kinv); | ||
219 | if (r->r != NULL) BN_clear_free(r->r); | ||
220 | OPENSSL_free(r); | ||
221 | } | ||
222 | |||
223 | int DSA_size(DSA *r) | ||
224 | { | ||
225 | int ret,i; | ||
226 | ASN1_INTEGER bs; | ||
227 | unsigned char buf[4]; | ||
228 | |||
229 | i=BN_num_bits(r->q); | ||
230 | bs.length=(i+7)/8; | ||
231 | bs.data=buf; | ||
232 | bs.type=V_ASN1_INTEGER; | ||
233 | /* If the top bit is set the asn1 encoding is 1 larger. */ | ||
234 | buf[0]=0xff; | ||
235 | |||
236 | i=i2d_ASN1_INTEGER(&bs,NULL); | ||
237 | i+=i; /* r and s */ | ||
238 | ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE); | ||
239 | return(ret); | ||
240 | } | ||
241 | |||
242 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
243 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
244 | { | ||
245 | dsa_meth_num++; | ||
246 | return(CRYPTO_get_ex_new_index(dsa_meth_num-1, | ||
247 | &dsa_meth,argl,argp,new_func,dup_func,free_func)); | ||
248 | } | ||
249 | |||
250 | int DSA_set_ex_data(DSA *d, int idx, void *arg) | ||
251 | { | ||
252 | return(CRYPTO_set_ex_data(&d->ex_data,idx,arg)); | ||
253 | } | ||
254 | |||
255 | void *DSA_get_ex_data(DSA *d, int idx) | ||
256 | { | ||
257 | return(CRYPTO_get_ex_data(&d->ex_data,idx)); | ||
258 | } | ||
259 | |||
260 | #ifndef NO_DH | ||
261 | DH *DSA_dup_DH(DSA *r) | ||
262 | { | ||
263 | /* DSA has p, q, g, optional pub_key, optional priv_key. | ||
264 | * DH has p, optional length, g, optional pub_key, optional priv_key. | ||
265 | */ | ||
266 | |||
267 | DH *ret = NULL; | ||
268 | |||
269 | if (r == NULL) | ||
270 | goto err; | ||
271 | ret = DH_new(); | ||
272 | if (ret == NULL) | ||
273 | goto err; | ||
274 | if (r->p != NULL) | ||
275 | if ((ret->p = BN_dup(r->p)) == NULL) | ||
276 | goto err; | ||
277 | if (r->q != NULL) | ||
278 | ret->length = BN_num_bits(r->q); | ||
279 | if (r->g != NULL) | ||
280 | if ((ret->g = BN_dup(r->g)) == NULL) | ||
281 | goto err; | ||
282 | if (r->pub_key != NULL) | ||
283 | if ((ret->pub_key = BN_dup(r->pub_key)) == NULL) | ||
284 | goto err; | ||
285 | if (r->priv_key != NULL) | ||
286 | if ((ret->priv_key = BN_dup(r->priv_key)) == NULL) | ||
287 | goto err; | ||
288 | |||
289 | return ret; | ||
290 | |||
291 | err: | ||
292 | if (ret != NULL) | ||
293 | DH_free(ret); | ||
294 | return NULL; | ||
295 | } | ||
296 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c deleted file mode 100644 index 34c6e9a141..0000000000 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ /dev/null | |||
@@ -1,393 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_ossl.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/bn.h> | ||
64 | #include <openssl/dsa.h> | ||
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/asn1.h> | ||
67 | #include <openssl/engine.h> | ||
68 | |||
69 | int __BN_rand_range(BIGNUM *r, BIGNUM *range); | ||
70 | |||
71 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
72 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); | ||
73 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | ||
74 | DSA *dsa); | ||
75 | static int dsa_init(DSA *dsa); | ||
76 | static int dsa_finish(DSA *dsa); | ||
77 | static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, | ||
78 | BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, | ||
79 | BN_MONT_CTX *in_mont); | ||
80 | static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
81 | const BIGNUM *m, BN_CTX *ctx, | ||
82 | BN_MONT_CTX *m_ctx); | ||
83 | |||
84 | static DSA_METHOD openssl_dsa_meth = { | ||
85 | "OpenSSL DSA method", | ||
86 | dsa_do_sign, | ||
87 | dsa_sign_setup, | ||
88 | dsa_do_verify, | ||
89 | dsa_mod_exp, | ||
90 | dsa_bn_mod_exp, | ||
91 | dsa_init, | ||
92 | dsa_finish, | ||
93 | 0, | ||
94 | NULL | ||
95 | }; | ||
96 | |||
97 | DSA_METHOD *DSA_OpenSSL(void) | ||
98 | { | ||
99 | return &openssl_dsa_meth; | ||
100 | } | ||
101 | |||
102 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
103 | { | ||
104 | BIGNUM *kinv=NULL,*r=NULL,*s=NULL; | ||
105 | BIGNUM m; | ||
106 | BIGNUM xr; | ||
107 | BN_CTX *ctx=NULL; | ||
108 | int i,reason=ERR_R_BN_LIB; | ||
109 | DSA_SIG *ret=NULL; | ||
110 | |||
111 | if (!dsa->p || !dsa->q || !dsa->g) | ||
112 | { | ||
113 | reason=DSA_R_MISSING_PARAMETERS; | ||
114 | goto err; | ||
115 | } | ||
116 | BN_init(&m); | ||
117 | BN_init(&xr); | ||
118 | s=BN_new(); | ||
119 | if (s == NULL) goto err; | ||
120 | |||
121 | i=BN_num_bytes(dsa->q); /* should be 20 */ | ||
122 | if ((dlen > i) || (dlen > 50)) | ||
123 | { | ||
124 | reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE; | ||
125 | goto err; | ||
126 | } | ||
127 | |||
128 | ctx=BN_CTX_new(); | ||
129 | if (ctx == NULL) goto err; | ||
130 | |||
131 | if ((dsa->kinv == NULL) || (dsa->r == NULL)) | ||
132 | { | ||
133 | if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err; | ||
134 | } | ||
135 | else | ||
136 | { | ||
137 | kinv=dsa->kinv; | ||
138 | dsa->kinv=NULL; | ||
139 | r=dsa->r; | ||
140 | dsa->r=NULL; | ||
141 | } | ||
142 | |||
143 | if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err; | ||
144 | |||
145 | /* Compute s = inv(k) (m + xr) mod q */ | ||
146 | if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */ | ||
147 | if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */ | ||
148 | if (BN_cmp(s,dsa->q) > 0) | ||
149 | BN_sub(s,s,dsa->q); | ||
150 | if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err; | ||
151 | |||
152 | ret=DSA_SIG_new(); | ||
153 | if (ret == NULL) goto err; | ||
154 | ret->r = r; | ||
155 | ret->s = s; | ||
156 | |||
157 | err: | ||
158 | if (!ret) | ||
159 | { | ||
160 | DSAerr(DSA_F_DSA_DO_SIGN,reason); | ||
161 | BN_free(r); | ||
162 | BN_free(s); | ||
163 | } | ||
164 | if (ctx != NULL) BN_CTX_free(ctx); | ||
165 | BN_clear_free(&m); | ||
166 | BN_clear_free(&xr); | ||
167 | if (kinv != NULL) /* dsa->kinv is NULL now if we used it */ | ||
168 | BN_clear_free(kinv); | ||
169 | return(ret); | ||
170 | } | ||
171 | |||
172 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | ||
173 | { | ||
174 | BN_CTX *ctx; | ||
175 | BIGNUM k,*kinv=NULL,*r=NULL; | ||
176 | int ret=0; | ||
177 | |||
178 | if (!dsa->p || !dsa->q || !dsa->g) | ||
179 | { | ||
180 | DSAerr(DSA_F_DSA_SIGN_SETUP,DSA_R_MISSING_PARAMETERS); | ||
181 | return 0; | ||
182 | } | ||
183 | if (ctx_in == NULL) | ||
184 | { | ||
185 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
186 | } | ||
187 | else | ||
188 | ctx=ctx_in; | ||
189 | |||
190 | BN_init(&k); | ||
191 | if ((r=BN_new()) == NULL) goto err; | ||
192 | kinv=NULL; | ||
193 | |||
194 | /* Get random k */ | ||
195 | do | ||
196 | if (!__BN_rand_range(&k, dsa->q)) goto err; | ||
197 | while (BN_is_zero(&k)); | ||
198 | |||
199 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) | ||
200 | { | ||
201 | if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
202 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, | ||
203 | dsa->p,ctx)) goto err; | ||
204 | } | ||
205 | |||
206 | /* Compute r = (g^k mod p) mod q */ | ||
207 | if (!ENGINE_get_DSA(dsa->engine)->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx, | ||
208 | (BN_MONT_CTX *)dsa->method_mont_p)) goto err; | ||
209 | if (!BN_mod(r,r,dsa->q,ctx)) goto err; | ||
210 | |||
211 | /* Compute part of 's = inv(k) (m + xr) mod q' */ | ||
212 | if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err; | ||
213 | |||
214 | if (*kinvp != NULL) BN_clear_free(*kinvp); | ||
215 | *kinvp=kinv; | ||
216 | kinv=NULL; | ||
217 | if (*rp != NULL) BN_clear_free(*rp); | ||
218 | *rp=r; | ||
219 | ret=1; | ||
220 | err: | ||
221 | if (!ret) | ||
222 | { | ||
223 | DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB); | ||
224 | if (kinv != NULL) BN_clear_free(kinv); | ||
225 | if (r != NULL) BN_clear_free(r); | ||
226 | } | ||
227 | if (ctx_in == NULL) BN_CTX_free(ctx); | ||
228 | if (kinv != NULL) BN_clear_free(kinv); | ||
229 | BN_clear_free(&k); | ||
230 | return(ret); | ||
231 | } | ||
232 | |||
233 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | ||
234 | DSA *dsa) | ||
235 | { | ||
236 | BN_CTX *ctx; | ||
237 | BIGNUM u1,u2,t1; | ||
238 | BN_MONT_CTX *mont=NULL; | ||
239 | int ret = -1; | ||
240 | |||
241 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
242 | BN_init(&u1); | ||
243 | BN_init(&u2); | ||
244 | BN_init(&t1); | ||
245 | |||
246 | if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0) | ||
247 | { | ||
248 | ret = 0; | ||
249 | goto err; | ||
250 | } | ||
251 | if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0) | ||
252 | { | ||
253 | ret = 0; | ||
254 | goto err; | ||
255 | } | ||
256 | |||
257 | /* Calculate W = inv(S) mod Q | ||
258 | * save W in u2 */ | ||
259 | if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err; | ||
260 | |||
261 | /* save M in u1 */ | ||
262 | if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err; | ||
263 | |||
264 | /* u1 = M * w mod q */ | ||
265 | if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err; | ||
266 | |||
267 | /* u2 = r * w mod q */ | ||
268 | if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err; | ||
269 | |||
270 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) | ||
271 | { | ||
272 | if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
273 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, | ||
274 | dsa->p,ctx)) goto err; | ||
275 | } | ||
276 | mont=(BN_MONT_CTX *)dsa->method_mont_p; | ||
277 | |||
278 | #if 0 | ||
279 | { | ||
280 | BIGNUM t2; | ||
281 | |||
282 | BN_init(&t2); | ||
283 | /* v = ( g^u1 * y^u2 mod p ) mod q */ | ||
284 | /* let t1 = g ^ u1 mod p */ | ||
285 | if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err; | ||
286 | /* let t2 = y ^ u2 mod p */ | ||
287 | if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err; | ||
288 | /* let u1 = t1 * t2 mod p */ | ||
289 | if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn; | ||
290 | BN_free(&t2); | ||
291 | } | ||
292 | /* let u1 = u1 mod q */ | ||
293 | if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err; | ||
294 | #else | ||
295 | { | ||
296 | if (!ENGINE_get_DSA(dsa->engine)->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2, | ||
297 | dsa->p,ctx,mont)) goto err; | ||
298 | /* BN_copy(&u1,&t1); */ | ||
299 | /* let u1 = u1 mod q */ | ||
300 | if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err; | ||
301 | } | ||
302 | #endif | ||
303 | /* V is now in u1. If the signature is correct, it will be | ||
304 | * equal to R. */ | ||
305 | ret=(BN_ucmp(&u1, sig->r) == 0); | ||
306 | |||
307 | err: | ||
308 | if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB); | ||
309 | if (ctx != NULL) BN_CTX_free(ctx); | ||
310 | BN_free(&u1); | ||
311 | BN_free(&u2); | ||
312 | BN_free(&t1); | ||
313 | return(ret); | ||
314 | } | ||
315 | |||
316 | static int dsa_init(DSA *dsa) | ||
317 | { | ||
318 | dsa->flags|=DSA_FLAG_CACHE_MONT_P; | ||
319 | return(1); | ||
320 | } | ||
321 | |||
322 | static int dsa_finish(DSA *dsa) | ||
323 | { | ||
324 | if(dsa->method_mont_p) | ||
325 | BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p); | ||
326 | return(1); | ||
327 | } | ||
328 | |||
329 | static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, | ||
330 | BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, | ||
331 | BN_MONT_CTX *in_mont) | ||
332 | { | ||
333 | return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont); | ||
334 | } | ||
335 | |||
336 | static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
337 | const BIGNUM *m, BN_CTX *ctx, | ||
338 | BN_MONT_CTX *m_ctx) | ||
339 | { | ||
340 | return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx); | ||
341 | } | ||
342 | |||
343 | |||
344 | /* random number r: 0 <= r < range */ | ||
345 | int __BN_rand_range(BIGNUM *r, BIGNUM *range) | ||
346 | { | ||
347 | int n; | ||
348 | |||
349 | if (range->neg || BN_is_zero(range)) | ||
350 | { | ||
351 | /* BNerr(BN_F_BN_RAND_RANGE, BN_R_INVALID_RANGE); */ | ||
352 | return 0; | ||
353 | } | ||
354 | |||
355 | n = BN_num_bits(range); /* n > 0 */ | ||
356 | |||
357 | if (n == 1) | ||
358 | { | ||
359 | if (!BN_zero(r)) return 0; | ||
360 | } | ||
361 | else if (BN_is_bit_set(range, n - 2)) | ||
362 | { | ||
363 | do | ||
364 | { | ||
365 | /* range = 11..._2, so each iteration succeeds with probability >= .75 */ | ||
366 | if (!BN_rand(r, n, -1, 0)) return 0; | ||
367 | } | ||
368 | while (BN_cmp(r, range) >= 0); | ||
369 | } | ||
370 | else | ||
371 | { | ||
372 | /* range = 10..._2, | ||
373 | * so 3*range (= 11..._2) is exactly one bit longer than range */ | ||
374 | do | ||
375 | { | ||
376 | if (!BN_rand(r, n + 1, -1, 0)) return 0; | ||
377 | /* If r < 3*range, use r := r MOD range | ||
378 | * (which is either r, r - range, or r - 2*range). | ||
379 | * Otherwise, iterate once more. | ||
380 | * Since 3*range = 11..._2, each iteration succeeds with | ||
381 | * probability >= .75. */ | ||
382 | if (BN_cmp(r ,range) >= 0) | ||
383 | { | ||
384 | if (!BN_sub(r, r, range)) return 0; | ||
385 | if (BN_cmp(r, range) >= 0) | ||
386 | if (!BN_sub(r, r, range)) return 0; | ||
387 | } | ||
388 | } | ||
389 | while (BN_cmp(r, range) >= 0); | ||
390 | } | ||
391 | |||
392 | return 1; | ||
393 | } | ||
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c deleted file mode 100644 index dfe27bae47..0000000000 --- a/src/lib/libcrypto/dsa/dsa_sign.c +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_sign.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/bn.h> | ||
64 | #include <openssl/dsa.h> | ||
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/asn1.h> | ||
67 | #include <openssl/engine.h> | ||
68 | |||
69 | DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
70 | { | ||
71 | return ENGINE_get_DSA(dsa->engine)->dsa_do_sign(dgst, dlen, dsa); | ||
72 | } | ||
73 | |||
74 | int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | ||
75 | unsigned int *siglen, DSA *dsa) | ||
76 | { | ||
77 | DSA_SIG *s; | ||
78 | s=DSA_do_sign(dgst,dlen,dsa); | ||
79 | if (s == NULL) | ||
80 | { | ||
81 | *siglen=0; | ||
82 | return(0); | ||
83 | } | ||
84 | *siglen=i2d_DSA_SIG(s,&sig); | ||
85 | DSA_SIG_free(s); | ||
86 | return(1); | ||
87 | } | ||
88 | |||
89 | int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | ||
90 | { | ||
91 | return ENGINE_get_DSA(dsa->engine)->dsa_sign_setup(dsa, ctx_in, kinvp, rp); | ||
92 | } | ||
93 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c deleted file mode 100644 index 2e891ae491..0000000000 --- a/src/lib/libcrypto/dsa/dsa_vrf.c +++ /dev/null | |||
@@ -1,95 +0,0 @@ | |||
1 | /* crypto/dsa/dsa_vrf.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
60 | |||
61 | #include <stdio.h> | ||
62 | #include "cryptlib.h" | ||
63 | #include <openssl/bn.h> | ||
64 | #include <openssl/dsa.h> | ||
65 | #include <openssl/rand.h> | ||
66 | #include <openssl/asn1.h> | ||
67 | #include <openssl/asn1_mac.h> | ||
68 | #include <openssl/engine.h> | ||
69 | |||
70 | int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | ||
71 | DSA *dsa) | ||
72 | { | ||
73 | return ENGINE_get_DSA(dsa->engine)->dsa_do_verify(dgst, dgst_len, sig, dsa); | ||
74 | } | ||
75 | |||
76 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
77 | /* returns | ||
78 | * 1: correct signature | ||
79 | * 0: incorrect signature | ||
80 | * -1: error | ||
81 | */ | ||
82 | int DSA_verify(int type, const unsigned char *dgst, int dgst_len, | ||
83 | unsigned char *sigbuf, int siglen, DSA *dsa) | ||
84 | { | ||
85 | DSA_SIG *s; | ||
86 | int ret=-1; | ||
87 | |||
88 | s = DSA_SIG_new(); | ||
89 | if (s == NULL) return(ret); | ||
90 | if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; | ||
91 | ret=DSA_do_verify(dgst,dgst_len,s,dsa); | ||
92 | err: | ||
93 | DSA_SIG_free(s); | ||
94 | return(ret); | ||
95 | } | ||