diff options
| author | cvs2svn <admin@example.com> | 2000-04-30 04:58:23 +0000 |
|---|---|---|
| committer | cvs2svn <admin@example.com> | 2000-04-30 04:58:23 +0000 |
| commit | 9cc1eacd8366faaa248a9aca9120fb7427c2a58e (patch) | |
| tree | 9304b7a65ac1d9eeb42cdd518d69fd21eb2b47af /src/lib/libcrypto/dsa | |
| parent | e71289f71fad3f153975fd8fbf1f0f35dbda7f28 (diff) | |
| download | openbsd-OPENBSD_2_7_BASE.tar.gz openbsd-OPENBSD_2_7_BASE.tar.bz2 openbsd-OPENBSD_2_7_BASE.zip | |
This commit was manufactured by cvs2git to create tag 'OPENBSD_2_7_BASE'.OPENBSD_2_7_BASE
Diffstat (limited to 'src/lib/libcrypto/dsa')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa.h | 241 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 96 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_err.c | 106 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_gen.c | 294 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_key.c | 113 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_lib.c | 246 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_ossl.c | 321 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_sign.c | 92 | ||||
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_vrf.c | 94 |
9 files changed, 0 insertions, 1603 deletions
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h deleted file mode 100644 index 68d9912cbc..0000000000 --- a/src/lib/libcrypto/dsa/dsa.h +++ /dev/null | |||
| @@ -1,241 +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 __cplusplus | ||
| 69 | extern "C" { | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #ifdef NO_DSA | ||
| 73 | #error DSA is disabled. | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #include <openssl/bn.h> | ||
| 77 | #include <openssl/crypto.h> | ||
| 78 | #ifndef NO_DH | ||
| 79 | # include <openssl/dh.h> | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #define DSA_FLAG_CACHE_MONT_P 0x01 | ||
| 83 | |||
| 84 | typedef struct dsa_st DSA; | ||
| 85 | |||
| 86 | typedef struct DSA_SIG_st | ||
| 87 | { | ||
| 88 | BIGNUM *r; | ||
| 89 | BIGNUM *s; | ||
| 90 | } DSA_SIG; | ||
| 91 | |||
| 92 | typedef struct dsa_method { | ||
| 93 | const char *name; | ||
| 94 | DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa); | ||
| 95 | int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, | ||
| 96 | BIGNUM **rp); | ||
| 97 | int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len, | ||
| 98 | DSA_SIG *sig, DSA *dsa); | ||
| 99 | int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, | ||
| 100 | BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, | ||
| 101 | BN_MONT_CTX *in_mont); | ||
| 102 | int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 103 | const BIGNUM *m, BN_CTX *ctx, | ||
| 104 | BN_MONT_CTX *m_ctx); /* Can be null */ | ||
| 105 | int (*init)(DSA *dsa); | ||
| 106 | int (*finish)(DSA *dsa); | ||
| 107 | int flags; | ||
| 108 | char *app_data; | ||
| 109 | } DSA_METHOD; | ||
| 110 | |||
| 111 | struct dsa_st | ||
| 112 | { | ||
| 113 | /* This first variable is used to pick up errors where | ||
| 114 | * a DSA is passed instead of of a EVP_PKEY */ | ||
| 115 | int pad; | ||
| 116 | int version; | ||
| 117 | int write_params; | ||
| 118 | BIGNUM *p; | ||
| 119 | BIGNUM *q; /* == 20 */ | ||
| 120 | BIGNUM *g; | ||
| 121 | |||
| 122 | BIGNUM *pub_key; /* y public key */ | ||
| 123 | BIGNUM *priv_key; /* x private key */ | ||
| 124 | |||
| 125 | BIGNUM *kinv; /* Signing pre-calc */ | ||
| 126 | BIGNUM *r; /* Signing pre-calc */ | ||
| 127 | |||
| 128 | int flags; | ||
| 129 | /* Normally used to cache montgomery values */ | ||
| 130 | char *method_mont_p; | ||
| 131 | int references; | ||
| 132 | CRYPTO_EX_DATA ex_data; | ||
| 133 | DSA_METHOD *meth; | ||
| 134 | }; | ||
| 135 | |||
| 136 | #define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \ | ||
| 137 | (char *(*)())d2i_DSAparams,(char *)(x)) | ||
| 138 | #define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ | ||
| 139 | (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) | ||
| 140 | #define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ | ||
| 141 | (unsigned char *)(x)) | ||
| 142 | #define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \ | ||
| 143 | (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x)) | ||
| 144 | #define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \ | ||
| 145 | (unsigned char *)(x)) | ||
| 146 | |||
| 147 | |||
| 148 | DSA_SIG * DSA_SIG_new(void); | ||
| 149 | void DSA_SIG_free(DSA_SIG *a); | ||
| 150 | int i2d_DSA_SIG(DSA_SIG *a, unsigned char **pp); | ||
| 151 | DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, unsigned char **pp, long length); | ||
| 152 | |||
| 153 | DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa); | ||
| 154 | int DSA_do_verify(const unsigned char *dgst,int dgst_len, | ||
| 155 | DSA_SIG *sig,DSA *dsa); | ||
| 156 | |||
| 157 | DSA_METHOD *DSA_OpenSSL(void); | ||
| 158 | |||
| 159 | void DSA_set_default_method(DSA_METHOD *); | ||
| 160 | DSA_METHOD *DSA_get_default_method(void); | ||
| 161 | DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *); | ||
| 162 | |||
| 163 | DSA * DSA_new(void); | ||
| 164 | DSA * DSA_new_method(DSA_METHOD *meth); | ||
| 165 | int DSA_size(DSA *); | ||
| 166 | /* next 4 return -1 on error */ | ||
| 167 | int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp); | ||
| 168 | int DSA_sign(int type,const unsigned char *dgst,int dlen, | ||
| 169 | unsigned char *sig, unsigned int *siglen, DSA *dsa); | ||
| 170 | int DSA_verify(int type,const unsigned char *dgst,int dgst_len, | ||
| 171 | unsigned char *sigbuf, int siglen, DSA *dsa); | ||
| 172 | void DSA_free (DSA *r); | ||
| 173 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 174 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); | ||
| 175 | int DSA_set_ex_data(DSA *d, int idx, void *arg); | ||
| 176 | void *DSA_get_ex_data(DSA *d, int idx); | ||
| 177 | |||
| 178 | void ERR_load_DSA_strings(void ); | ||
| 179 | |||
| 180 | DSA * d2i_DSAPublicKey(DSA **a, unsigned char **pp, long length); | ||
| 181 | DSA * d2i_DSAPrivateKey(DSA **a, unsigned char **pp, long length); | ||
| 182 | DSA * d2i_DSAparams(DSA **a, unsigned char **pp, long length); | ||
| 183 | DSA * DSA_generate_parameters(int bits, unsigned char *seed,int seed_len, | ||
| 184 | int *counter_ret, unsigned long *h_ret,void | ||
| 185 | (*callback)(int, int, void *),void *cb_arg); | ||
| 186 | int DSA_generate_key(DSA *a); | ||
| 187 | int i2d_DSAPublicKey(DSA *a, unsigned char **pp); | ||
| 188 | int i2d_DSAPrivateKey(DSA *a, unsigned char **pp); | ||
| 189 | int i2d_DSAparams(DSA *a,unsigned char **pp); | ||
| 190 | |||
| 191 | #ifdef HEADER_BIO_H | ||
| 192 | int DSAparams_print(BIO *bp, DSA *x); | ||
| 193 | int DSA_print(BIO *bp, DSA *x, int off); | ||
| 194 | #endif | ||
| 195 | #ifndef NO_FP_API | ||
| 196 | int DSAparams_print_fp(FILE *fp, DSA *x); | ||
| 197 | int DSA_print_fp(FILE *bp, DSA *x, int off); | ||
| 198 | #endif | ||
| 199 | |||
| 200 | #define DSS_prime_checks 50 | ||
| 201 | /* Primality test according to FIPS PUB 186[-1], Appendix 2.1: | ||
| 202 | * 50 rounds of Rabin-Miller */ | ||
| 203 | #define DSA_is_prime(n, callback, cb_arg) \ | ||
| 204 | BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg) | ||
| 205 | |||
| 206 | #ifndef NO_DH | ||
| 207 | /* Convert DSA structure (key or just parameters) into DH structure | ||
| 208 | * (be careful to avoid small subgroup attacks when using this!) */ | ||
| 209 | DH *DSA_dup_DH(DSA *r); | ||
| 210 | #endif | ||
| 211 | |||
| 212 | /* BEGIN ERROR CODES */ | ||
| 213 | /* The following lines are auto generated by the script mkerr.pl. Any changes | ||
| 214 | * made after this point may be overwritten when the script is next run. | ||
| 215 | */ | ||
| 216 | |||
| 217 | /* Error codes for the DSA functions. */ | ||
| 218 | |||
| 219 | /* Function codes. */ | ||
| 220 | #define DSA_F_D2I_DSA_SIG 110 | ||
| 221 | #define DSA_F_DSAPARAMS_PRINT 100 | ||
| 222 | #define DSA_F_DSAPARAMS_PRINT_FP 101 | ||
| 223 | #define DSA_F_DSA_DO_SIGN 112 | ||
| 224 | #define DSA_F_DSA_DO_VERIFY 113 | ||
| 225 | #define DSA_F_DSA_NEW 103 | ||
| 226 | #define DSA_F_DSA_PRINT 104 | ||
| 227 | #define DSA_F_DSA_PRINT_FP 105 | ||
| 228 | #define DSA_F_DSA_SIGN 106 | ||
| 229 | #define DSA_F_DSA_SIGN_SETUP 107 | ||
| 230 | #define DSA_F_DSA_SIG_NEW 109 | ||
| 231 | #define DSA_F_DSA_VERIFY 108 | ||
| 232 | #define DSA_F_I2D_DSA_SIG 111 | ||
| 233 | |||
| 234 | /* Reason codes. */ | ||
| 235 | #define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100 | ||
| 236 | |||
| 237 | #ifdef __cplusplus | ||
| 238 | } | ||
| 239 | #endif | ||
| 240 | #endif | ||
| 241 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c deleted file mode 100644 index c9b32b4db7..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 = 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 | 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=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=Malloc(BN_num_bits(v->s)/8+1); | ||
| 47 | if (sbs.data == NULL) | ||
| 48 | { | ||
| 49 | 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 | Free(rbs.data); | ||
| 68 | 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 2b3ab3a9ad..0000000000 --- a/src/lib/libcrypto/dsa/dsa_err.c +++ /dev/null | |||
| @@ -1,106 +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 | {0,NULL} | ||
| 89 | }; | ||
| 90 | |||
| 91 | #endif | ||
| 92 | |||
| 93 | void ERR_load_DSA_strings(void) | ||
| 94 | { | ||
| 95 | static int init=1; | ||
| 96 | |||
| 97 | if (init) | ||
| 98 | { | ||
| 99 | init=0; | ||
| 100 | #ifndef NO_ERR | ||
| 101 | ERR_load_strings(ERR_LIB_DSA,DSA_str_functs); | ||
| 102 | ERR_load_strings(ERR_LIB_DSA,DSA_str_reasons); | ||
| 103 | #endif | ||
| 104 | |||
| 105 | } | ||
| 106 | } | ||
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 5aef2d5fcf..0000000000 --- a/src/lib/libcrypto/dsa/dsa_key.c +++ /dev/null | |||
| @@ -1,113 +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 | int DSA_generate_key(DSA *dsa) | ||
| 69 | { | ||
| 70 | int ok=0; | ||
| 71 | unsigned int i; | ||
| 72 | BN_CTX *ctx=NULL; | ||
| 73 | BIGNUM *pub_key=NULL,*priv_key=NULL; | ||
| 74 | |||
| 75 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 76 | |||
| 77 | if (dsa->priv_key == NULL) | ||
| 78 | { | ||
| 79 | if ((priv_key=BN_new()) == NULL) goto err; | ||
| 80 | } | ||
| 81 | else | ||
| 82 | priv_key=dsa->priv_key; | ||
| 83 | |||
| 84 | i=BN_num_bits(dsa->q); | ||
| 85 | for (;;) | ||
| 86 | { | ||
| 87 | if (!BN_rand(priv_key,i,1,0)) | ||
| 88 | goto err; | ||
| 89 | if (BN_cmp(priv_key,dsa->q) >= 0) | ||
| 90 | BN_sub(priv_key,priv_key,dsa->q); | ||
| 91 | if (!BN_is_zero(priv_key)) break; | ||
| 92 | } | ||
| 93 | |||
| 94 | if (dsa->pub_key == NULL) | ||
| 95 | { | ||
| 96 | if ((pub_key=BN_new()) == NULL) goto err; | ||
| 97 | } | ||
| 98 | else | ||
| 99 | pub_key=dsa->pub_key; | ||
| 100 | |||
| 101 | if (!BN_mod_exp(pub_key,dsa->g,priv_key,dsa->p,ctx)) goto err; | ||
| 102 | |||
| 103 | dsa->priv_key=priv_key; | ||
| 104 | dsa->pub_key=pub_key; | ||
| 105 | ok=1; | ||
| 106 | |||
| 107 | err: | ||
| 108 | if ((pub_key != NULL) && (dsa->pub_key == NULL)) BN_free(pub_key); | ||
| 109 | if ((priv_key != NULL) && (dsa->priv_key == NULL)) BN_free(priv_key); | ||
| 110 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 111 | return(ok); | ||
| 112 | } | ||
| 113 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c deleted file mode 100644 index 224e412afc..0000000000 --- a/src/lib/libcrypto/dsa/dsa_lib.c +++ /dev/null | |||
| @@ -1,246 +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 | |||
| 67 | const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT; | ||
| 68 | |||
| 69 | static DSA_METHOD *default_DSA_method; | ||
| 70 | static int dsa_meth_num = 0; | ||
| 71 | static STACK_OF(CRYPTO_EX_DATA_FUNCS) *dsa_meth = NULL; | ||
| 72 | |||
| 73 | void DSA_set_default_method(DSA_METHOD *meth) | ||
| 74 | { | ||
| 75 | default_DSA_method = meth; | ||
| 76 | } | ||
| 77 | |||
| 78 | DSA_METHOD *DSA_get_default_method(void) | ||
| 79 | { | ||
| 80 | if(!default_DSA_method) default_DSA_method = DSA_OpenSSL(); | ||
| 81 | return default_DSA_method; | ||
| 82 | } | ||
| 83 | |||
| 84 | DSA *DSA_new(void) | ||
| 85 | { | ||
| 86 | return DSA_new_method(NULL); | ||
| 87 | } | ||
| 88 | |||
| 89 | DSA_METHOD *DSA_set_method(DSA *dsa, DSA_METHOD *meth) | ||
| 90 | { | ||
| 91 | DSA_METHOD *mtmp; | ||
| 92 | mtmp = dsa->meth; | ||
| 93 | if (mtmp->finish) mtmp->finish(dsa); | ||
| 94 | dsa->meth = meth; | ||
| 95 | if (meth->init) meth->init(dsa); | ||
| 96 | return mtmp; | ||
| 97 | } | ||
| 98 | |||
| 99 | |||
| 100 | DSA *DSA_new_method(DSA_METHOD *meth) | ||
| 101 | { | ||
| 102 | DSA *ret; | ||
| 103 | |||
| 104 | ret=(DSA *)Malloc(sizeof(DSA)); | ||
| 105 | if (ret == NULL) | ||
| 106 | { | ||
| 107 | DSAerr(DSA_F_DSA_NEW,ERR_R_MALLOC_FAILURE); | ||
| 108 | return(NULL); | ||
| 109 | } | ||
| 110 | if(!default_DSA_method) default_DSA_method = DSA_OpenSSL(); | ||
| 111 | if(meth) ret->meth = meth; | ||
| 112 | else ret->meth = default_DSA_method; | ||
| 113 | ret->pad=0; | ||
| 114 | ret->version=0; | ||
| 115 | ret->write_params=1; | ||
| 116 | ret->p=NULL; | ||
| 117 | ret->q=NULL; | ||
| 118 | ret->g=NULL; | ||
| 119 | |||
| 120 | ret->pub_key=NULL; | ||
| 121 | ret->priv_key=NULL; | ||
| 122 | |||
| 123 | ret->kinv=NULL; | ||
| 124 | ret->r=NULL; | ||
| 125 | ret->method_mont_p=NULL; | ||
| 126 | |||
| 127 | ret->references=1; | ||
| 128 | ret->flags=ret->meth->flags; | ||
| 129 | if ((ret->meth->init != NULL) && !ret->meth->init(ret)) | ||
| 130 | { | ||
| 131 | Free(ret); | ||
| 132 | ret=NULL; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | CRYPTO_new_ex_data(dsa_meth,ret,&ret->ex_data); | ||
| 136 | |||
| 137 | return(ret); | ||
| 138 | } | ||
| 139 | |||
| 140 | void DSA_free(DSA *r) | ||
| 141 | { | ||
| 142 | int i; | ||
| 143 | |||
| 144 | if (r == NULL) return; | ||
| 145 | |||
| 146 | i=CRYPTO_add(&r->references,-1,CRYPTO_LOCK_DSA); | ||
| 147 | #ifdef REF_PRINT | ||
| 148 | REF_PRINT("DSA",r); | ||
| 149 | #endif | ||
| 150 | if (i > 0) return; | ||
| 151 | #ifdef REF_CHECK | ||
| 152 | if (i < 0) | ||
| 153 | { | ||
| 154 | fprintf(stderr,"DSA_free, bad reference count\n"); | ||
| 155 | abort(); | ||
| 156 | } | ||
| 157 | #endif | ||
| 158 | |||
| 159 | CRYPTO_free_ex_data(dsa_meth, r, &r->ex_data); | ||
| 160 | |||
| 161 | if(r->meth->finish) r->meth->finish(r); | ||
| 162 | |||
| 163 | if (r->p != NULL) BN_clear_free(r->p); | ||
| 164 | if (r->q != NULL) BN_clear_free(r->q); | ||
| 165 | if (r->g != NULL) BN_clear_free(r->g); | ||
| 166 | if (r->pub_key != NULL) BN_clear_free(r->pub_key); | ||
| 167 | if (r->priv_key != NULL) BN_clear_free(r->priv_key); | ||
| 168 | if (r->kinv != NULL) BN_clear_free(r->kinv); | ||
| 169 | if (r->r != NULL) BN_clear_free(r->r); | ||
| 170 | Free(r); | ||
| 171 | } | ||
| 172 | |||
| 173 | int DSA_size(DSA *r) | ||
| 174 | { | ||
| 175 | int ret,i; | ||
| 176 | ASN1_INTEGER bs; | ||
| 177 | unsigned char buf[4]; | ||
| 178 | |||
| 179 | i=BN_num_bits(r->q); | ||
| 180 | bs.length=(i+7)/8; | ||
| 181 | bs.data=buf; | ||
| 182 | bs.type=V_ASN1_INTEGER; | ||
| 183 | /* If the top bit is set the asn1 encoding is 1 larger. */ | ||
| 184 | buf[0]=0xff; | ||
| 185 | |||
| 186 | i=i2d_ASN1_INTEGER(&bs,NULL); | ||
| 187 | i+=i; /* r and s */ | ||
| 188 | ret=ASN1_object_size(1,i,V_ASN1_SEQUENCE); | ||
| 189 | return(ret); | ||
| 190 | } | ||
| 191 | |||
| 192 | int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, | ||
| 193 | CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func) | ||
| 194 | { | ||
| 195 | dsa_meth_num++; | ||
| 196 | return(CRYPTO_get_ex_new_index(dsa_meth_num-1, | ||
| 197 | &dsa_meth,argl,argp,new_func,dup_func,free_func)); | ||
| 198 | } | ||
| 199 | |||
| 200 | int DSA_set_ex_data(DSA *d, int idx, void *arg) | ||
| 201 | { | ||
| 202 | return(CRYPTO_set_ex_data(&d->ex_data,idx,arg)); | ||
| 203 | } | ||
| 204 | |||
| 205 | void *DSA_get_ex_data(DSA *d, int idx) | ||
| 206 | { | ||
| 207 | return(CRYPTO_get_ex_data(&d->ex_data,idx)); | ||
| 208 | } | ||
| 209 | |||
| 210 | #ifndef NO_DH | ||
| 211 | DH *DSA_dup_DH(DSA *r) | ||
| 212 | { | ||
| 213 | /* DSA has p, q, g, optional pub_key, optional priv_key. | ||
| 214 | * DH has p, optional length, g, optional pub_key, optional priv_key. | ||
| 215 | */ | ||
| 216 | |||
| 217 | DH *ret = NULL; | ||
| 218 | |||
| 219 | if (r == NULL) | ||
| 220 | goto err; | ||
| 221 | ret = DH_new(); | ||
| 222 | if (ret == NULL) | ||
| 223 | goto err; | ||
| 224 | if (r->p != NULL) | ||
| 225 | if ((ret->p = BN_dup(r->p)) == NULL) | ||
| 226 | goto err; | ||
| 227 | if (r->q != NULL) | ||
| 228 | ret->length = BN_num_bits(r->q); | ||
| 229 | if (r->g != NULL) | ||
| 230 | if ((ret->g = BN_dup(r->g)) == NULL) | ||
| 231 | goto err; | ||
| 232 | if (r->pub_key != NULL) | ||
| 233 | if ((ret->pub_key = BN_dup(r->pub_key)) == NULL) | ||
| 234 | goto err; | ||
| 235 | if (r->priv_key != NULL) | ||
| 236 | if ((ret->priv_key = BN_dup(r->priv_key)) == NULL) | ||
| 237 | goto err; | ||
| 238 | |||
| 239 | return ret; | ||
| 240 | |||
| 241 | err: | ||
| 242 | if (ret != NULL) | ||
| 243 | DH_free(ret); | ||
| 244 | return NULL; | ||
| 245 | } | ||
| 246 | #endif | ||
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c deleted file mode 100644 index b51cf6ad8d..0000000000 --- a/src/lib/libcrypto/dsa/dsa_ossl.c +++ /dev/null | |||
| @@ -1,321 +0,0 @@ | |||
| 1 | /* crypto/dsa/dsa_ossl.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* Original version from Steven Schoch <schoch@sheba.arc.nasa.gov> */ | ||
| 60 | |||
| 61 | #include <stdio.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include <openssl/bn.h> | ||
| 64 | #include <openssl/dsa.h> | ||
| 65 | #include <openssl/rand.h> | ||
| 66 | #include <openssl/asn1.h> | ||
| 67 | |||
| 68 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); | ||
| 69 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); | ||
| 70 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | ||
| 71 | DSA *dsa); | ||
| 72 | static int dsa_init(DSA *dsa); | ||
| 73 | static int dsa_finish(DSA *dsa); | ||
| 74 | static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, | ||
| 75 | BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, | ||
| 76 | BN_MONT_CTX *in_mont); | ||
| 77 | static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 78 | const BIGNUM *m, BN_CTX *ctx, | ||
| 79 | BN_MONT_CTX *m_ctx); | ||
| 80 | |||
| 81 | static DSA_METHOD openssl_dsa_meth = { | ||
| 82 | "OpenSSL DSA method", | ||
| 83 | dsa_do_sign, | ||
| 84 | dsa_sign_setup, | ||
| 85 | dsa_do_verify, | ||
| 86 | dsa_mod_exp, | ||
| 87 | dsa_bn_mod_exp, | ||
| 88 | dsa_init, | ||
| 89 | dsa_finish, | ||
| 90 | 0, | ||
| 91 | NULL | ||
| 92 | }; | ||
| 93 | |||
| 94 | DSA_METHOD *DSA_OpenSSL(void) | ||
| 95 | { | ||
| 96 | return &openssl_dsa_meth; | ||
| 97 | } | ||
| 98 | |||
| 99 | static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
| 100 | { | ||
| 101 | BIGNUM *kinv=NULL,*r=NULL,*s=NULL; | ||
| 102 | BIGNUM m; | ||
| 103 | BIGNUM xr; | ||
| 104 | BN_CTX *ctx=NULL; | ||
| 105 | int i,reason=ERR_R_BN_LIB; | ||
| 106 | DSA_SIG *ret=NULL; | ||
| 107 | |||
| 108 | BN_init(&m); | ||
| 109 | BN_init(&xr); | ||
| 110 | s=BN_new(); | ||
| 111 | if (s == NULL) goto err; | ||
| 112 | |||
| 113 | i=BN_num_bytes(dsa->q); /* should be 20 */ | ||
| 114 | if ((dlen > i) || (dlen > 50)) | ||
| 115 | { | ||
| 116 | reason=DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE; | ||
| 117 | goto err; | ||
| 118 | } | ||
| 119 | |||
| 120 | ctx=BN_CTX_new(); | ||
| 121 | if (ctx == NULL) goto err; | ||
| 122 | |||
| 123 | if ((dsa->kinv == NULL) || (dsa->r == NULL)) | ||
| 124 | { | ||
| 125 | if (!DSA_sign_setup(dsa,ctx,&kinv,&r)) goto err; | ||
| 126 | } | ||
| 127 | else | ||
| 128 | { | ||
| 129 | kinv=dsa->kinv; | ||
| 130 | dsa->kinv=NULL; | ||
| 131 | r=dsa->r; | ||
| 132 | dsa->r=NULL; | ||
| 133 | } | ||
| 134 | |||
| 135 | if (BN_bin2bn(dgst,dlen,&m) == NULL) goto err; | ||
| 136 | |||
| 137 | /* Compute s = inv(k) (m + xr) mod q */ | ||
| 138 | if (!BN_mod_mul(&xr,dsa->priv_key,r,dsa->q,ctx)) goto err;/* s = xr */ | ||
| 139 | if (!BN_add(s, &xr, &m)) goto err; /* s = m + xr */ | ||
| 140 | if (BN_cmp(s,dsa->q) > 0) | ||
| 141 | BN_sub(s,s,dsa->q); | ||
| 142 | if (!BN_mod_mul(s,s,kinv,dsa->q,ctx)) goto err; | ||
| 143 | |||
| 144 | ret=DSA_SIG_new(); | ||
| 145 | if (ret == NULL) goto err; | ||
| 146 | ret->r = r; | ||
| 147 | ret->s = s; | ||
| 148 | |||
| 149 | err: | ||
| 150 | if (!ret) | ||
| 151 | { | ||
| 152 | DSAerr(DSA_F_DSA_DO_SIGN,reason); | ||
| 153 | BN_free(r); | ||
| 154 | BN_free(s); | ||
| 155 | } | ||
| 156 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 157 | BN_clear_free(&m); | ||
| 158 | BN_clear_free(&xr); | ||
| 159 | if (kinv != NULL) /* dsa->kinv is NULL now if we used it */ | ||
| 160 | BN_clear_free(kinv); | ||
| 161 | return(ret); | ||
| 162 | } | ||
| 163 | |||
| 164 | static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | ||
| 165 | { | ||
| 166 | BN_CTX *ctx; | ||
| 167 | BIGNUM k,*kinv=NULL,*r=NULL; | ||
| 168 | int ret=0; | ||
| 169 | |||
| 170 | if (ctx_in == NULL) | ||
| 171 | { | ||
| 172 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 173 | } | ||
| 174 | else | ||
| 175 | ctx=ctx_in; | ||
| 176 | |||
| 177 | BN_init(&k); | ||
| 178 | if ((r=BN_new()) == NULL) goto err; | ||
| 179 | kinv=NULL; | ||
| 180 | |||
| 181 | /* Get random k */ | ||
| 182 | for (;;) | ||
| 183 | { | ||
| 184 | if (!BN_rand(&k, BN_num_bits(dsa->q), 1, 0)) goto err; | ||
| 185 | if (BN_cmp(&k,dsa->q) >= 0) | ||
| 186 | BN_sub(&k,&k,dsa->q); | ||
| 187 | if (!BN_is_zero(&k)) break; | ||
| 188 | } | ||
| 189 | |||
| 190 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) | ||
| 191 | { | ||
| 192 | if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
| 193 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, | ||
| 194 | dsa->p,ctx)) goto err; | ||
| 195 | } | ||
| 196 | |||
| 197 | /* Compute r = (g^k mod p) mod q */ | ||
| 198 | if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx, | ||
| 199 | (BN_MONT_CTX *)dsa->method_mont_p)) goto err; | ||
| 200 | if (!BN_mod(r,r,dsa->q,ctx)) goto err; | ||
| 201 | |||
| 202 | /* Compute part of 's = inv(k) (m + xr) mod q' */ | ||
| 203 | if ((kinv=BN_mod_inverse(NULL,&k,dsa->q,ctx)) == NULL) goto err; | ||
| 204 | |||
| 205 | if (*kinvp != NULL) BN_clear_free(*kinvp); | ||
| 206 | *kinvp=kinv; | ||
| 207 | kinv=NULL; | ||
| 208 | if (*rp != NULL) BN_clear_free(*rp); | ||
| 209 | *rp=r; | ||
| 210 | ret=1; | ||
| 211 | err: | ||
| 212 | if (!ret) | ||
| 213 | { | ||
| 214 | DSAerr(DSA_F_DSA_SIGN_SETUP,ERR_R_BN_LIB); | ||
| 215 | if (kinv != NULL) BN_clear_free(kinv); | ||
| 216 | if (r != NULL) BN_clear_free(r); | ||
| 217 | } | ||
| 218 | if (ctx_in == NULL) BN_CTX_free(ctx); | ||
| 219 | if (kinv != NULL) BN_clear_free(kinv); | ||
| 220 | BN_clear_free(&k); | ||
| 221 | return(ret); | ||
| 222 | } | ||
| 223 | |||
| 224 | static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | ||
| 225 | DSA *dsa) | ||
| 226 | { | ||
| 227 | BN_CTX *ctx; | ||
| 228 | BIGNUM u1,u2,t1; | ||
| 229 | BN_MONT_CTX *mont=NULL; | ||
| 230 | int ret = -1; | ||
| 231 | |||
| 232 | if ((ctx=BN_CTX_new()) == NULL) goto err; | ||
| 233 | BN_init(&u1); | ||
| 234 | BN_init(&u2); | ||
| 235 | BN_init(&t1); | ||
| 236 | |||
| 237 | /* Calculate W = inv(S) mod Q | ||
| 238 | * save W in u2 */ | ||
| 239 | if ((BN_mod_inverse(&u2,sig->s,dsa->q,ctx)) == NULL) goto err; | ||
| 240 | |||
| 241 | /* save M in u1 */ | ||
| 242 | if (BN_bin2bn(dgst,dgst_len,&u1) == NULL) goto err; | ||
| 243 | |||
| 244 | /* u1 = M * w mod q */ | ||
| 245 | if (!BN_mod_mul(&u1,&u1,&u2,dsa->q,ctx)) goto err; | ||
| 246 | |||
| 247 | /* u2 = r * w mod q */ | ||
| 248 | if (!BN_mod_mul(&u2,sig->r,&u2,dsa->q,ctx)) goto err; | ||
| 249 | |||
| 250 | if ((dsa->method_mont_p == NULL) && (dsa->flags & DSA_FLAG_CACHE_MONT_P)) | ||
| 251 | { | ||
| 252 | if ((dsa->method_mont_p=(char *)BN_MONT_CTX_new()) != NULL) | ||
| 253 | if (!BN_MONT_CTX_set((BN_MONT_CTX *)dsa->method_mont_p, | ||
| 254 | dsa->p,ctx)) goto err; | ||
| 255 | } | ||
| 256 | mont=(BN_MONT_CTX *)dsa->method_mont_p; | ||
| 257 | |||
| 258 | #if 0 | ||
| 259 | { | ||
| 260 | BIGNUM t2; | ||
| 261 | |||
| 262 | BN_init(&t2); | ||
| 263 | /* v = ( g^u1 * y^u2 mod p ) mod q */ | ||
| 264 | /* let t1 = g ^ u1 mod p */ | ||
| 265 | if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err; | ||
| 266 | /* let t2 = y ^ u2 mod p */ | ||
| 267 | if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err; | ||
| 268 | /* let u1 = t1 * t2 mod p */ | ||
| 269 | if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn; | ||
| 270 | BN_free(&t2); | ||
| 271 | } | ||
| 272 | /* let u1 = u1 mod q */ | ||
| 273 | if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err; | ||
| 274 | #else | ||
| 275 | { | ||
| 276 | if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2, | ||
| 277 | dsa->p,ctx,mont)) goto err; | ||
| 278 | /* BN_copy(&u1,&t1); */ | ||
| 279 | /* let u1 = u1 mod q */ | ||
| 280 | if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err; | ||
| 281 | } | ||
| 282 | #endif | ||
| 283 | /* V is now in u1. If the signature is correct, it will be | ||
| 284 | * equal to R. */ | ||
| 285 | ret=(BN_ucmp(&u1, sig->r) == 0); | ||
| 286 | |||
| 287 | err: | ||
| 288 | if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB); | ||
| 289 | if (ctx != NULL) BN_CTX_free(ctx); | ||
| 290 | BN_free(&u1); | ||
| 291 | BN_free(&u2); | ||
| 292 | BN_free(&t1); | ||
| 293 | return(ret); | ||
| 294 | } | ||
| 295 | |||
| 296 | static int dsa_init(DSA *dsa) | ||
| 297 | { | ||
| 298 | dsa->flags|=DSA_FLAG_CACHE_MONT_P; | ||
| 299 | return(1); | ||
| 300 | } | ||
| 301 | |||
| 302 | static int dsa_finish(DSA *dsa) | ||
| 303 | { | ||
| 304 | if(dsa->method_mont_p) | ||
| 305 | BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p); | ||
| 306 | return(1); | ||
| 307 | } | ||
| 308 | |||
| 309 | static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, | ||
| 310 | BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, | ||
| 311 | BN_MONT_CTX *in_mont) | ||
| 312 | { | ||
| 313 | return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont); | ||
| 314 | } | ||
| 315 | |||
| 316 | static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, | ||
| 317 | const BIGNUM *m, BN_CTX *ctx, | ||
| 318 | BN_MONT_CTX *m_ctx) | ||
| 319 | { | ||
| 320 | return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx); | ||
| 321 | } | ||
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c deleted file mode 100644 index 89205026f0..0000000000 --- a/src/lib/libcrypto/dsa/dsa_sign.c +++ /dev/null | |||
| @@ -1,92 +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 | |||
| 68 | DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) | ||
| 69 | { | ||
| 70 | return dsa->meth->dsa_do_sign(dgst, dlen, dsa); | ||
| 71 | } | ||
| 72 | |||
| 73 | int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, | ||
| 74 | unsigned int *siglen, DSA *dsa) | ||
| 75 | { | ||
| 76 | DSA_SIG *s; | ||
| 77 | s=DSA_do_sign(dgst,dlen,dsa); | ||
| 78 | if (s == NULL) | ||
| 79 | { | ||
| 80 | *siglen=0; | ||
| 81 | return(0); | ||
| 82 | } | ||
| 83 | *siglen=i2d_DSA_SIG(s,&sig); | ||
| 84 | DSA_SIG_free(s); | ||
| 85 | return(1); | ||
| 86 | } | ||
| 87 | |||
| 88 | int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) | ||
| 89 | { | ||
| 90 | return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp); | ||
| 91 | } | ||
| 92 | |||
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c deleted file mode 100644 index 03277f80fd..0000000000 --- a/src/lib/libcrypto/dsa/dsa_vrf.c +++ /dev/null | |||
| @@ -1,94 +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 | |||
| 69 | int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, | ||
| 70 | DSA *dsa) | ||
| 71 | { | ||
| 72 | return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa); | ||
| 73 | } | ||
| 74 | |||
| 75 | /* data has already been hashed (probably with SHA or SHA-1). */ | ||
| 76 | /* returns | ||
| 77 | * 1: correct signature | ||
| 78 | * 0: incorrect signature | ||
| 79 | * -1: error | ||
| 80 | */ | ||
| 81 | int DSA_verify(int type, const unsigned char *dgst, int dgst_len, | ||
| 82 | unsigned char *sigbuf, int siglen, DSA *dsa) | ||
| 83 | { | ||
| 84 | DSA_SIG *s; | ||
| 85 | int ret=-1; | ||
| 86 | |||
| 87 | s = DSA_SIG_new(); | ||
| 88 | if (s == NULL) return(ret); | ||
| 89 | if (d2i_DSA_SIG(&s,&sigbuf,siglen) == NULL) goto err; | ||
| 90 | ret=DSA_do_verify(dgst,dgst_len,s,dsa); | ||
| 91 | err: | ||
| 92 | DSA_SIG_free(s); | ||
| 93 | return(ret); | ||
| 94 | } | ||
