Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-15 09:17:49

0001 /*
0002  * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
0003  *
0004  * Licensed under the Apache License 2.0 (the "License").  You may not use
0005  * this file except in compliance with the License.  You can obtain a copy
0006  * in the file LICENSE in the source distribution or at
0007  * https://www.openssl.org/source/license.html
0008  */
0009 
0010 #ifndef OPENSSL_DSA_H
0011 #define OPENSSL_DSA_H
0012 #pragma once
0013 
0014 #include <openssl/macros.h>
0015 #ifndef OPENSSL_NO_DEPRECATED_3_0
0016 #define HEADER_DSA_H
0017 #endif
0018 
0019 #include <openssl/opensslconf.h>
0020 #include <openssl/types.h>
0021 
0022 #include <stdlib.h>
0023 
0024 #ifndef OPENSSL_NO_DSA
0025 #include <openssl/e_os2.h>
0026 #include <openssl/asn1.h>
0027 #include <openssl/bio.h>
0028 #include <openssl/crypto.h>
0029 #include <openssl/bn.h>
0030 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
0031 #include <openssl/dh.h>
0032 #endif
0033 #include <openssl/dsaerr.h>
0034 #ifndef OPENSSL_NO_STDIO
0035 #include <stdio.h>
0036 #endif
0037 #endif
0038 
0039 #ifdef __cplusplus
0040 extern "C" {
0041 #endif
0042 
0043 int EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits);
0044 int EVP_PKEY_CTX_set_dsa_paramgen_q_bits(EVP_PKEY_CTX *ctx, int qbits);
0045 int EVP_PKEY_CTX_set_dsa_paramgen_md_props(EVP_PKEY_CTX *ctx,
0046     const char *md_name,
0047     const char *md_properties);
0048 int EVP_PKEY_CTX_set_dsa_paramgen_gindex(EVP_PKEY_CTX *ctx, int gindex);
0049 int EVP_PKEY_CTX_set_dsa_paramgen_type(EVP_PKEY_CTX *ctx, const char *name);
0050 int EVP_PKEY_CTX_set_dsa_paramgen_seed(EVP_PKEY_CTX *ctx,
0051     const unsigned char *seed,
0052     size_t seedlen);
0053 int EVP_PKEY_CTX_set_dsa_paramgen_md(EVP_PKEY_CTX *ctx, const EVP_MD *md);
0054 
0055 #define EVP_PKEY_CTRL_DSA_PARAMGEN_BITS (EVP_PKEY_ALG_CTRL + 1)
0056 #define EVP_PKEY_CTRL_DSA_PARAMGEN_Q_BITS (EVP_PKEY_ALG_CTRL + 2)
0057 #define EVP_PKEY_CTRL_DSA_PARAMGEN_MD (EVP_PKEY_ALG_CTRL + 3)
0058 
0059 #ifndef OPENSSL_NO_DSA
0060 #ifndef OPENSSL_DSA_MAX_MODULUS_BITS
0061 #define OPENSSL_DSA_MAX_MODULUS_BITS 10000
0062 #endif
0063 
0064 #define OPENSSL_DSA_FIPS_MIN_MODULUS_BITS 1024
0065 
0066 typedef struct DSA_SIG_st DSA_SIG;
0067 DSA_SIG *DSA_SIG_new(void);
0068 void DSA_SIG_free(DSA_SIG *a);
0069 DECLARE_ASN1_ENCODE_FUNCTIONS_only(DSA_SIG, DSA_SIG)
0070 void DSA_SIG_get0(const DSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
0071 int DSA_SIG_set0(DSA_SIG *sig, BIGNUM *r, BIGNUM *s);
0072 
0073 #ifndef OPENSSL_NO_DEPRECATED_1_1_0
0074 /*
0075  * Does nothing. Previously this switched off constant time behaviour.
0076  */
0077 #define DSA_FLAG_NO_EXP_CONSTTIME 0x00
0078 #endif
0079 
0080 #ifndef OPENSSL_NO_DEPRECATED_3_0
0081 #define DSA_FLAG_CACHE_MONT_P 0x01
0082 
0083 /*
0084  * If this flag is set the DSA method is FIPS compliant and can be used in
0085  * FIPS mode. This is set in the validated module method. If an application
0086  * sets this flag in its own methods it is its responsibility to ensure the
0087  * result is compliant.
0088  */
0089 
0090 #define DSA_FLAG_FIPS_METHOD 0x0400
0091 
0092 /*
0093  * If this flag is set the operations normally disabled in FIPS mode are
0094  * permitted it is then the applications responsibility to ensure that the
0095  * usage is compliant.
0096  */
0097 
0098 #define DSA_FLAG_NON_FIPS_ALLOW 0x0400
0099 #define DSA_FLAG_FIPS_CHECKED 0x0800
0100 
0101 /* Already defined in ossl_typ.h */
0102 /* typedef struct dsa_st DSA; */
0103 /* typedef struct dsa_method DSA_METHOD; */
0104 
0105 #define d2i_DSAparams_fp(fp, x)                  \
0106     (DSA *)ASN1_d2i_fp((void *(*)(void))DSA_new, \
0107         (d2i_of_void *)d2i_DSAparams, (fp),      \
0108         (void **)(x))
0109 #define i2d_DSAparams_fp(fp, x) \
0110     ASN1_i2d_fp(i2d_DSAparams, (fp), (unsigned char *)(x))
0111 #define d2i_DSAparams_bio(bp, x) \
0112     ASN1_d2i_bio_of(DSA, DSA_new, d2i_DSAparams, bp, x)
0113 #define i2d_DSAparams_bio(bp, x) \
0114     ASN1_i2d_bio_of(DSA, i2d_DSAparams, bp, x)
0115 
0116 DECLARE_ASN1_DUP_FUNCTION_name_attr(OSSL_DEPRECATEDIN_3_0, DSA, DSAparams)
0117 OSSL_DEPRECATEDIN_3_0 DSA_SIG *DSA_do_sign(const unsigned char *dgst, int dlen,
0118     DSA *dsa);
0119 OSSL_DEPRECATEDIN_3_0 int DSA_do_verify(const unsigned char *dgst, int dgst_len,
0120     DSA_SIG *sig, DSA *dsa);
0121 
0122 OSSL_DEPRECATEDIN_3_0 const DSA_METHOD *DSA_OpenSSL(void);
0123 
0124 OSSL_DEPRECATEDIN_3_0 void DSA_set_default_method(const DSA_METHOD *);
0125 OSSL_DEPRECATEDIN_3_0 const DSA_METHOD *DSA_get_default_method(void);
0126 OSSL_DEPRECATEDIN_3_0 int DSA_set_method(DSA *dsa, const DSA_METHOD *);
0127 OSSL_DEPRECATEDIN_3_0 const DSA_METHOD *DSA_get_method(DSA *d);
0128 
0129 OSSL_DEPRECATEDIN_3_0 DSA *DSA_new(void);
0130 OSSL_DEPRECATEDIN_3_0 DSA *DSA_new_method(ENGINE *engine);
0131 OSSL_DEPRECATEDIN_3_0 void DSA_free(DSA *r);
0132 /* "up" the DSA object's reference count */
0133 OSSL_DEPRECATEDIN_3_0 int DSA_up_ref(DSA *r);
0134 OSSL_DEPRECATEDIN_3_0 int DSA_size(const DSA *);
0135 OSSL_DEPRECATEDIN_3_0 int DSA_bits(const DSA *d);
0136 OSSL_DEPRECATEDIN_3_0 int DSA_security_bits(const DSA *d);
0137 /* next 4 return -1 on error */
0138 OSSL_DEPRECATEDIN_3_0 int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in,
0139     BIGNUM **kinvp, BIGNUM **rp);
0140 OSSL_DEPRECATEDIN_3_0 int DSA_sign(int type, const unsigned char *dgst,
0141     int dlen, unsigned char *sig,
0142     unsigned int *siglen, DSA *dsa);
0143 OSSL_DEPRECATEDIN_3_0 int DSA_verify(int type, const unsigned char *dgst,
0144     int dgst_len, const unsigned char *sigbuf,
0145     int siglen, DSA *dsa);
0146 
0147 #define DSA_get_ex_new_index(l, p, newf, dupf, freef) \
0148     CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DSA, l, p, newf, dupf, freef)
0149 OSSL_DEPRECATEDIN_3_0 int DSA_set_ex_data(DSA *d, int idx, void *arg);
0150 OSSL_DEPRECATEDIN_3_0 void *DSA_get_ex_data(const DSA *d, int idx);
0151 
0152 DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0,
0153     DSA, DSAPublicKey)
0154 DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0,
0155     DSA, DSAPrivateKey)
0156 DECLARE_ASN1_ENCODE_FUNCTIONS_only_attr(OSSL_DEPRECATEDIN_3_0,
0157     DSA, DSAparams)
0158 #endif
0159 
0160 #ifndef OPENSSL_NO_DEPRECATED_0_9_8
0161 /* Deprecated version */
0162 OSSL_DEPRECATEDIN_0_9_8
0163 DSA *DSA_generate_parameters(int bits, unsigned char *seed, int seed_len,
0164     int *counter_ret, unsigned long *h_ret,
0165     void (*callback)(int, int, void *),
0166     void *cb_arg);
0167 #endif
0168 
0169 #ifndef OPENSSL_NO_DEPRECATED_3_0
0170 /* New version */
0171 OSSL_DEPRECATEDIN_3_0 int DSA_generate_parameters_ex(DSA *dsa, int bits,
0172     const unsigned char *seed,
0173     int seed_len,
0174     int *counter_ret,
0175     unsigned long *h_ret,
0176     BN_GENCB *cb);
0177 
0178 OSSL_DEPRECATEDIN_3_0 int DSA_generate_key(DSA *a);
0179 
0180 OSSL_DEPRECATEDIN_3_0 int DSAparams_print(BIO *bp, const DSA *x);
0181 OSSL_DEPRECATEDIN_3_0 int DSA_print(BIO *bp, const DSA *x, int off);
0182 #ifndef OPENSSL_NO_STDIO
0183 OSSL_DEPRECATEDIN_3_0 int DSAparams_print_fp(FILE *fp, const DSA *x);
0184 OSSL_DEPRECATEDIN_3_0 int DSA_print_fp(FILE *bp, const DSA *x, int off);
0185 #endif
0186 
0187 #define DSS_prime_checks 64
0188 /*
0189  * Primality test according to FIPS PUB 186-4, Appendix C.3. Since we only
0190  * have one value here we set the number of checks to 64 which is the 128 bit
0191  * security level that is the highest level and valid for creating a 3072 bit
0192  * DSA key.
0193  */
0194 #define DSA_is_prime(n, callback, cb_arg) \
0195     BN_is_prime(n, DSS_prime_checks, callback, NULL, cb_arg)
0196 
0197 #ifndef OPENSSL_NO_DH
0198 /*
0199  * Convert DSA structure (key or just parameters) into DH structure (be
0200  * careful to avoid small subgroup attacks when using this!)
0201  */
0202 OSSL_DEPRECATEDIN_3_0 DH *DSA_dup_DH(const DSA *r);
0203 #endif
0204 
0205 OSSL_DEPRECATEDIN_3_0 void DSA_get0_pqg(const DSA *d, const BIGNUM **p,
0206     const BIGNUM **q, const BIGNUM **g);
0207 OSSL_DEPRECATEDIN_3_0 int DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g);
0208 OSSL_DEPRECATEDIN_3_0 void DSA_get0_key(const DSA *d, const BIGNUM **pub_key,
0209     const BIGNUM **priv_key);
0210 OSSL_DEPRECATEDIN_3_0 int DSA_set0_key(DSA *d, BIGNUM *pub_key,
0211     BIGNUM *priv_key);
0212 OSSL_DEPRECATEDIN_3_0 const BIGNUM *DSA_get0_p(const DSA *d);
0213 OSSL_DEPRECATEDIN_3_0 const BIGNUM *DSA_get0_q(const DSA *d);
0214 OSSL_DEPRECATEDIN_3_0 const BIGNUM *DSA_get0_g(const DSA *d);
0215 OSSL_DEPRECATEDIN_3_0 const BIGNUM *DSA_get0_pub_key(const DSA *d);
0216 OSSL_DEPRECATEDIN_3_0 const BIGNUM *DSA_get0_priv_key(const DSA *d);
0217 OSSL_DEPRECATEDIN_3_0 void DSA_clear_flags(DSA *d, int flags);
0218 OSSL_DEPRECATEDIN_3_0 int DSA_test_flags(const DSA *d, int flags);
0219 OSSL_DEPRECATEDIN_3_0 void DSA_set_flags(DSA *d, int flags);
0220 OSSL_DEPRECATEDIN_3_0 ENGINE *DSA_get0_engine(DSA *d);
0221 
0222 OSSL_DEPRECATEDIN_3_0 DSA_METHOD *DSA_meth_new(const char *name, int flags);
0223 OSSL_DEPRECATEDIN_3_0 void DSA_meth_free(DSA_METHOD *dsam);
0224 OSSL_DEPRECATEDIN_3_0 DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam);
0225 OSSL_DEPRECATEDIN_3_0 const char *DSA_meth_get0_name(const DSA_METHOD *dsam);
0226 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set1_name(DSA_METHOD *dsam,
0227     const char *name);
0228 OSSL_DEPRECATEDIN_3_0 int DSA_meth_get_flags(const DSA_METHOD *dsam);
0229 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_flags(DSA_METHOD *dsam, int flags);
0230 OSSL_DEPRECATEDIN_3_0 void *DSA_meth_get0_app_data(const DSA_METHOD *dsam);
0231 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set0_app_data(DSA_METHOD *dsam,
0232     void *app_data);
0233 OSSL_DEPRECATEDIN_3_0 DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))(const unsigned char *, int, DSA *);
0234 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_sign(DSA_METHOD *dsam,
0235     DSA_SIG *(*sign)(const unsigned char *, int, DSA *));
0236 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))(DSA *, BN_CTX *, BIGNUM **, BIGNUM **);
0237 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
0238     int (*sign_setup)(DSA *, BN_CTX *, BIGNUM **, BIGNUM **));
0239 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_verify(const DSA_METHOD *dsam))(const unsigned char *, int, DSA_SIG *, DSA *);
0240 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_verify(DSA_METHOD *dsam,
0241     int (*verify)(const unsigned char *, int, DSA_SIG *, DSA *));
0242 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
0243     const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *);
0244 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
0245     int (*mod_exp)(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
0246         const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
0247         BN_MONT_CTX *));
0248 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
0249     BN_CTX *, BN_MONT_CTX *);
0250 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
0251     int (*bn_mod_exp)(DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
0252         const BIGNUM *, BN_CTX *, BN_MONT_CTX *));
0253 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *);
0254 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_init(DSA_METHOD *dsam,
0255     int (*init)(DSA *));
0256 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_finish(const DSA_METHOD *dsam))(DSA *);
0257 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_finish(DSA_METHOD *dsam,
0258     int (*finish)(DSA *));
0259 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))(DSA *, int, const unsigned char *, int, int *, unsigned long *,
0260     BN_GENCB *);
0261 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_paramgen(DSA_METHOD *dsam,
0262     int (*paramgen)(DSA *, int, const unsigned char *, int, int *,
0263         unsigned long *, BN_GENCB *));
0264 OSSL_DEPRECATEDIN_3_0 int (*DSA_meth_get_keygen(const DSA_METHOD *dsam))(DSA *);
0265 OSSL_DEPRECATEDIN_3_0 int DSA_meth_set_keygen(DSA_METHOD *dsam,
0266     int (*keygen)(DSA *));
0267 
0268 #endif
0269 #endif
0270 #ifdef __cplusplus
0271 }
0272 #endif
0273 #endif