1/* 2 * Copyright (c) 2011-12 Apple Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23#ifndef _OSSL_DSA_H_ 24#define _OSSL_DSA_H_ 1 25 26/* symbol renaming */ 27#define DSA_null_method ossl_DSA_null_method 28#define DSA_cdsa_method ossl_DSA_cdsa_method 29#define DSA_SIG_free ossl_DSA_SIG_free 30#define DSA_SIG_new ossl_DSA_SIG_new 31#define DSA_do_sign ossl_DSA_do_sign 32#define DSA_do_verify ossl_DSA_do_verify 33#define DSA_free ossl_DSA_free 34#define DSA_generate_key ossl_DSA_generate_key 35#define DSA_generate_parameters_ex ossl_DSA_generate_parameters_ex 36#define DSA_new ossl_DSA_new 37#define DSA_new_method ossl_DSA_new_new_method 38#define DSA_up_ref ossl_DSA_up_ref 39#define DSA_get_default_method ossl_DSA_get_default_method 40#define DSA_set_method ossl_DSA_set_method 41#define DSA_sign_setup ossl_DSA_sign_setup 42#define DSA_sign ossl_DSA_sign 43#define DSA_verify ossl_DSA_verify 44#define DSA_up_ref ossl_DSA_up_ref 45 46#define d2i_DSAPrivateKey ossl_d2i_DSAPrivateKey 47#define i2d_DSAPrivateKey ossl_i2d_DSAPrivateKey 48 49#define DSA_PKCS1_PADDING 1 50#define DSA_PKCS1_PADDING_SIZE 11 51 52#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 53 54/* 55 * 56 */ 57typedef struct DSA_SIG_st DSA_SIG; 58typedef struct dsa_method DSA_METHOD; 59typedef struct dsa_st DSA; 60 61#include "ossl-bn.h" 62#include "ossl-engine.h" 63 64struct DSA_SIG_st { 65 BIGNUM *r; 66 BIGNUM *s; 67}; 68 69struct dsa_method { 70 const char * name; 71 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa); 72 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, 73 BIGNUM **rp); 74 int (*dsa_do_verify)(const unsigned char *dgst, int dgst_len, 75 DSA_SIG *sig, DSA *dsa); 76 int (*dsa_mod_exp)(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1, 77 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx, 78 BN_MONT_CTX *in_mont); 79 int (*bn_mod_exp)(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p, 80 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); 81 int (*init)(DSA *dsa); 82 int (*finish)(DSA *dsa); 83 int flags; 84 char * app_data; 85 int (*dsa_paramgen)(DSA *dsa, int bits, unsigned char *seed, int seed_len, 86 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); 87 int (*dsa_keygen)(DSA *dsa); 88}; 89 90struct dsa_st { 91 int pad; 92 long version; 93 int write_params; 94 BIGNUM * p; 95 BIGNUM * q; 96 BIGNUM * g; 97 98 BIGNUM * pub_key; 99 BIGNUM * priv_key; 100 101 BIGNUM * kinv; /* Signing pre-calc */ 102 BIGNUM * r; /* Signing pre-calc */ 103 104 int flags; 105 BN_MONT_CTX * method_mont_p; 106 int references; 107 struct dsa_CRYPTO_EX_DATA { 108 void * sk; 109 int dummy; 110 } 111 ex_data; 112 const DSA_METHOD * meth; 113 ENGINE * engine; 114}; 115 116 117/* 118 * 119 */ 120 121const DSA_METHOD *DSA_null_method(void); 122const DSA_METHOD *DSA_eay_method(void); 123 124/* 125 * 126 */ 127 128DSA *DSA_new(void); 129DSA *DSA_new_method(ENGINE *); 130void DSA_free(DSA *); 131int DSA_up_ref(DSA *); 132 133DSA_SIG *DSA_SIG_new(void); 134void DSA_SIG_free(DSA_SIG *a); 135 136DSA_SIG *DSA_do_sign(const unsigned char *dgst, unsigned int dlen, DSA *dsa); 137int DSA_do_verify(const unsigned char *dgst, int dgst_len, 138 DSA_SIG *sig, DSA *dsa); 139int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); 140int DSA_sign(int type, const unsigned char *dgst, int dlen, 141 unsigned char *sig, unsigned int *siglen, DSA *dsa); 142int DSA_verify(int type, const unsigned char *dgst, int dgst_len, 143 const unsigned char *sigbuf, int siglen, DSA *dsa); 144 145int DSA_generate_parameters_ex(DSA *dsa, int bits, 146 unsigned char *seed, int seed_len, 147 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb); 148int DSA_generate_key(DSA *a); 149 150const DSA_METHOD *DSA_get_default_method(void); 151void DSA_set_default_method(const DSA_METHOD *meth); 152int DSA_set_method(DSA *dsa, const DSA_METHOD *method); 153 154DSA *d2i_DSAPrivateKey(DSA **, const unsigned char **, long len); 155int i2d_DSAPrivateKey(const DSA *, unsigned char **); 156 157int i2d_DSAPublicKey(const DSA *, unsigned char **); 158DSA *d2i_DSAPublicKey(DSA **, const unsigned char **, long); 159 160#endif /* _OSSL_DSA_H_ */ 161