1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ssl/libcrypto/src/crypto/dsa/dsa.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,290 @@
1.4 +/* crypto/dsa/dsa.h */
1.5 +/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
1.6 + * All rights reserved.
1.7 + *
1.8 + * This package is an SSL implementation written
1.9 + * by Eric Young (eay@cryptsoft.com).
1.10 + * The implementation was written so as to conform with Netscapes SSL.
1.11 + *
1.12 + * This library is free for commercial and non-commercial use as long as
1.13 + * the following conditions are aheared to. The following conditions
1.14 + * apply to all code found in this distribution, be it the RC4, RSA,
1.15 + * lhash, DES, etc., code; not just the SSL code. The SSL documentation
1.16 + * included with this distribution is covered by the same copyright terms
1.17 + * except that the holder is Tim Hudson (tjh@cryptsoft.com).
1.18 + *
1.19 + * Copyright remains Eric Young's, and as such any Copyright notices in
1.20 + * the code are not to be removed.
1.21 + * If this package is used in a product, Eric Young should be given attribution
1.22 + * as the author of the parts of the library used.
1.23 + * This can be in the form of a textual message at program startup or
1.24 + * in documentation (online or textual) provided with the package.
1.25 + *
1.26 + * Redistribution and use in source and binary forms, with or without
1.27 + * modification, are permitted provided that the following conditions
1.28 + * are met:
1.29 + * 1. Redistributions of source code must retain the copyright
1.30 + * notice, this list of conditions and the following disclaimer.
1.31 + * 2. Redistributions in binary form must reproduce the above copyright
1.32 + * notice, this list of conditions and the following disclaimer in the
1.33 + * documentation and/or other materials provided with the distribution.
1.34 + * 3. All advertising materials mentioning features or use of this software
1.35 + * must display the following acknowledgement:
1.36 + * "This product includes cryptographic software written by
1.37 + * Eric Young (eay@cryptsoft.com)"
1.38 + * The word 'cryptographic' can be left out if the rouines from the library
1.39 + * being used are not cryptographic related :-).
1.40 + * 4. If you include any Windows specific code (or a derivative thereof) from
1.41 + * the apps directory (application code) you must include an acknowledgement:
1.42 + * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
1.43 + *
1.44 + * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
1.45 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.46 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.47 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.48 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.49 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.50 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.51 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.52 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.53 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.54 + * SUCH DAMAGE.
1.55 + *
1.56 + * The licence and distribution terms for any publically available version or
1.57 + * derivative of this code cannot be changed. i.e. this code cannot simply be
1.58 + * copied and put under another distribution licence
1.59 + * [including the GNU Public Licence.]
1.60 + */
1.61 +/*
1.62 + © Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.63 + */
1.64 +
1.65 +/*
1.66 + * The DSS routines are based on patches supplied by
1.67 + * Steven Schoch <schoch@sheba.arc.nasa.gov>. He basically did the
1.68 + * work and I have just tweaked them a little to fit into my
1.69 + * stylistic vision for SSLeay :-) */
1.70 +
1.71 +#ifndef HEADER_DSA_H
1.72 +#define HEADER_DSA_H
1.73 +#ifdef SYMBIAN
1.74 +#include <e32def.h>
1.75 +#endif
1.76 +#include <openssl/e_os2.h>
1.77 +
1.78 +#ifdef OPENSSL_NO_DSA
1.79 +#error DSA is disabled.
1.80 +#endif
1.81 +
1.82 +#ifndef OPENSSL_NO_BIO
1.83 +#include <openssl/bio.h>
1.84 +#endif
1.85 +#include <openssl/crypto.h>
1.86 +#include <openssl/ossl_typ.h>
1.87 +
1.88 +#ifndef OPENSSL_NO_DEPRECATED
1.89 +#include <openssl/bn.h>
1.90 +#ifndef OPENSSL_NO_DH
1.91 +# include <openssl/dh.h>
1.92 +#endif
1.93 +#endif
1.94 +#ifndef OPENSSL_DSA_MAX_MODULUS_BITS
1.95 +# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
1.96 +#endif
1.97 +
1.98 +#define DSA_FLAG_CACHE_MONT_P 0x01
1.99 +#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA
1.100 + * implementation now uses constant time
1.101 + * modular exponentiation for secret exponents
1.102 + * by default. This flag causes the
1.103 + * faster variable sliding window method to
1.104 + * be used for all exponents.
1.105 + */
1.106 +
1.107 +#ifdef __cplusplus
1.108 +extern "C" {
1.109 +#endif
1.110 +
1.111 +/* Already defined in ossl_typ.h */
1.112 +/* typedef struct dsa_st DSA; */
1.113 +/* typedef struct dsa_method DSA_METHOD; */
1.114 +
1.115 +typedef struct DSA_SIG_st
1.116 + {
1.117 + BIGNUM *r;
1.118 + BIGNUM *s;
1.119 + } DSA_SIG;
1.120 +
1.121 +struct dsa_method
1.122 + {
1.123 + const char *name;
1.124 + DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
1.125 + int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
1.126 + BIGNUM **rp);
1.127 + int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len,
1.128 + DSA_SIG *sig, DSA *dsa);
1.129 + int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
1.130 + BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
1.131 + BN_MONT_CTX *in_mont);
1.132 + int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
1.133 + const BIGNUM *m, BN_CTX *ctx,
1.134 + BN_MONT_CTX *m_ctx); /* Can be null */
1.135 + int (*init)(DSA *dsa);
1.136 + int (*finish)(DSA *dsa);
1.137 + int flags;
1.138 + char *app_data;
1.139 + /* If this is non-NULL, it is used to generate DSA parameters */
1.140 + int (*dsa_paramgen)(DSA *dsa, int bits,
1.141 + unsigned char *seed, int seed_len,
1.142 + int *counter_ret, unsigned long *h_ret,
1.143 + BN_GENCB *cb);
1.144 + /* If this is non-NULL, it is used to generate DSA keys */
1.145 + int (*dsa_keygen)(DSA *dsa);
1.146 + };
1.147 +
1.148 +struct dsa_st
1.149 + {
1.150 + /* This first variable is used to pick up errors where
1.151 + * a DSA is passed instead of of a EVP_PKEY */
1.152 + int pad;
1.153 + long version;
1.154 + int write_params;
1.155 + BIGNUM *p;
1.156 + BIGNUM *q; /* == 20 */
1.157 + BIGNUM *g;
1.158 +
1.159 + BIGNUM *pub_key; /* y public key */
1.160 + BIGNUM *priv_key; /* x private key */
1.161 +
1.162 + BIGNUM *kinv; /* Signing pre-calc */
1.163 + BIGNUM *r; /* Signing pre-calc */
1.164 +
1.165 + int flags;
1.166 + /* Normally used to cache montgomery values */
1.167 + BN_MONT_CTX *method_mont_p;
1.168 + int references;
1.169 + CRYPTO_EX_DATA ex_data;
1.170 + const DSA_METHOD *meth;
1.171 + /* functional reference if 'meth' is ENGINE-provided */
1.172 + ENGINE *engine;
1.173 + };
1.174 +
1.175 +#define DSAparams_dup(x) ASN1_dup_of_const(DSA,i2d_DSAparams,d2i_DSAparams,x)
1.176 +#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
1.177 + (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
1.178 +#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
1.179 + (unsigned char *)(x))
1.180 +#define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x)
1.181 +#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x)
1.182 +
1.183 +
1.184 +IMPORT_C DSA_SIG * DSA_SIG_new(void);
1.185 +IMPORT_C void DSA_SIG_free(DSA_SIG *a);
1.186 +IMPORT_C int i2d_DSA_SIG(const DSA_SIG *a, unsigned char **pp);
1.187 +IMPORT_C DSA_SIG * d2i_DSA_SIG(DSA_SIG **v, const unsigned char **pp, long length);
1.188 +
1.189 +IMPORT_C DSA_SIG * DSA_do_sign(const unsigned char *dgst,int dlen,DSA *dsa);
1.190 +IMPORT_C int DSA_do_verify(const unsigned char *dgst,int dgst_len,
1.191 + DSA_SIG *sig,DSA *dsa);
1.192 +
1.193 +IMPORT_C const DSA_METHOD *DSA_OpenSSL(void);
1.194 +
1.195 +IMPORT_C void DSA_set_default_method(const DSA_METHOD *);
1.196 +IMPORT_C const DSA_METHOD *DSA_get_default_method(void);
1.197 +IMPORT_C int DSA_set_method(DSA *dsa, const DSA_METHOD *);
1.198 +
1.199 +IMPORT_C DSA * DSA_new(void);
1.200 +IMPORT_C DSA * DSA_new_method(ENGINE *engine);
1.201 +IMPORT_C void DSA_free (DSA *r);
1.202 +/* "up" the DSA object's reference count */
1.203 +IMPORT_C int DSA_up_ref(DSA *r);
1.204 +IMPORT_C int DSA_size(const DSA *);
1.205 + /* next 4 return -1 on error */
1.206 +IMPORT_C int DSA_sign_setup( DSA *dsa,BN_CTX *ctx_in,BIGNUM **kinvp,BIGNUM **rp);
1.207 +IMPORT_C int DSA_sign(int type,const unsigned char *dgst,int dlen,
1.208 + unsigned char *sig, unsigned int *siglen, DSA *dsa);
1.209 +IMPORT_C int DSA_verify(int type,const unsigned char *dgst,int dgst_len,
1.210 + const unsigned char *sigbuf, int siglen, DSA *dsa);
1.211 +IMPORT_C int DSA_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
1.212 + CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
1.213 +IMPORT_C int DSA_set_ex_data(DSA *d, int idx, void *arg);
1.214 +IMPORT_C void *DSA_get_ex_data(DSA *d, int idx);
1.215 +
1.216 +IMPORT_C DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
1.217 +IMPORT_C DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
1.218 +IMPORT_C DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
1.219 +
1.220 +/* Deprecated version */
1.221 +#ifndef OPENSSL_NO_DEPRECATED
1.222 +IMPORT_C DSA * DSA_generate_parameters(int bits,
1.223 + unsigned char *seed,int seed_len,
1.224 + int *counter_ret, unsigned long *h_ret,void
1.225 + (*callback)(int, int, void *),void *cb_arg);
1.226 +#endif /* !defined(OPENSSL_NO_DEPRECATED) */
1.227 +
1.228 +/* New version */
1.229 +IMPORT_C int DSA_generate_parameters_ex(DSA *dsa, int bits,
1.230 + unsigned char *seed,int seed_len,
1.231 + int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
1.232 +
1.233 +IMPORT_C int DSA_generate_key(DSA *a);
1.234 +IMPORT_C int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
1.235 +IMPORT_C int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
1.236 +IMPORT_C int i2d_DSAparams(const DSA *a,unsigned char **pp);
1.237 +
1.238 +#ifndef OPENSSL_NO_BIO
1.239 +IMPORT_C int DSAparams_print(BIO *bp, const DSA *x);
1.240 +IMPORT_C int DSA_print(BIO *bp, const DSA *x, int off);
1.241 +#endif
1.242 +#ifndef OPENSSL_NO_FP_API
1.243 +IMPORT_C int DSAparams_print_fp(FILE *fp, const DSA *x);
1.244 +IMPORT_C int DSA_print_fp(FILE *bp, const DSA *x, int off);
1.245 +#endif
1.246 +
1.247 +#define DSS_prime_checks 50
1.248 +/* Primality test according to FIPS PUB 186[-1], Appendix 2.1:
1.249 + * 50 rounds of Rabin-Miller */
1.250 +#define DSA_is_prime(n, callback, cb_arg) \
1.251 + BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
1.252 +
1.253 +#ifndef OPENSSL_NO_DH
1.254 +/* Convert DSA structure (key or just parameters) into DH structure
1.255 + * (be careful to avoid small subgroup attacks when using this!) */
1.256 +IMPORT_C DH *DSA_dup_DH(const DSA *r);
1.257 +#endif
1.258 +
1.259 +/* BEGIN ERROR CODES */
1.260 +/* The following lines are auto generated by the script mkerr.pl. Any changes
1.261 + * made after this point may be overwritten when the script is next run.
1.262 + */
1.263 +IMPORT_C void ERR_load_DSA_strings(void);
1.264 +
1.265 +/* Error codes for the DSA functions. */
1.266 +
1.267 +/* Function codes. */
1.268 +#define DSA_F_D2I_DSA_SIG 110
1.269 +#define DSA_F_DSAPARAMS_PRINT 100
1.270 +#define DSA_F_DSAPARAMS_PRINT_FP 101
1.271 +#define DSA_F_DSA_DO_SIGN 112
1.272 +#define DSA_F_DSA_DO_VERIFY 113
1.273 +#define DSA_F_DSA_NEW_METHOD 103
1.274 +#define DSA_F_DSA_PRINT 104
1.275 +#define DSA_F_DSA_PRINT_FP 105
1.276 +#define DSA_F_DSA_SIGN 106
1.277 +#define DSA_F_DSA_SIGN_SETUP 107
1.278 +#define DSA_F_DSA_SIG_NEW 109
1.279 +#define DSA_F_DSA_VERIFY 108
1.280 +#define DSA_F_I2D_DSA_SIG 111
1.281 +#define DSA_F_SIG_CB 114
1.282 +
1.283 +/* Reason codes. */
1.284 +#define DSA_R_BAD_Q_VALUE 102
1.285 +#define DSA_R_DATA_TOO_LARGE_FOR_KEY_SIZE 100
1.286 +#define DSA_R_MISSING_PARAMETERS 101
1.287 +#define DSA_R_MODULUS_TOO_LARGE 103
1.288 +
1.289 +
1.290 +#ifdef __cplusplus
1.291 +}
1.292 +#endif
1.293 +#endif