1 /* $NetBSD: dsa.h,v 1.1.1.2 2011/04/14 14:08:31 elric Exp $ */ 2 3 /* 4 * Copyright (c) 2006 Kungliga Tekniska Högskolan 5 * (Royal Institute of Technology, Stockholm, Sweden). 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * 3. Neither the name of the Institute nor the names of its contributors 20 * may be used to endorse or promote products derived from this software 21 * without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 * SUCH DAMAGE. 34 */ 35 36 /* 37 * Id 38 */ 39 40 #ifndef _HEIM_DSA_H 41 #define _HEIM_DSA_H 1 42 43 #include <hcrypto/bn.h> 44 45 /* symbol renaming */ 46 #define DSA_null_method hc_DSA_null_method 47 #define DSA_new hc_DSA_new 48 #define DSA_free hc_DSA_free 49 #define DSA_up_ref hc_DSA_up_ref 50 #define DSA_set_default_method hc_DSA_set_default_method 51 #define DSA_get_default_method hc_DSA_get_default_method 52 #define DSA_set_method hc_DSA_set_method 53 #define DSA_get_method hc_DSA_get_method 54 #define DSA_set_app_data hc_DSA_set_app_data 55 #define DSA_get_app_data hc_DSA_get_app_data 56 #define DSA_size hc_DSA_size 57 #define DSA_verify hc_DSA_verify 58 59 /* 60 * 61 */ 62 63 64 typedef struct DSA DSA; 65 typedef struct DSA_METHOD DSA_METHOD; 66 typedef struct DSA_SIG DSA_SIG; 67 68 struct DSA_SIG { 69 BIGNUM *r; 70 BIGNUM *s; 71 }; 72 73 struct DSA_METHOD { 74 const char *name; 75 DSA_SIG * (*dsa_do_sign)(const unsigned char *, int, DSA *); 76 int (*dsa_sign_setup)(DSA *, BN_CTX *, BIGNUM **, BIGNUM **); 77 int (*dsa_do_verify)(const unsigned char *, int, DSA_SIG *, DSA *); 78 int (*dsa_mod_exp)(DSA *, BIGNUM *, BIGNUM *, BIGNUM *, 79 BIGNUM *, BIGNUM *, BIGNUM *, BN_CTX *, 80 BN_MONT_CTX *); 81 int (*bn_mod_exp)(DSA *, BIGNUM *, BIGNUM *, const BIGNUM *, 82 const BIGNUM *, BN_CTX *, 83 BN_MONT_CTX *); 84 int (*init)(DSA *); 85 int (*finish)(DSA *); 86 int flags; 87 void *app_data; 88 }; 89 90 struct DSA { 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; 102 BIGNUM *r; 103 int flags; 104 void *method_mont_p; 105 int references; 106 struct dsa_CRYPTO_EX_DATA { 107 void *sk; 108 int dummy; 109 } ex_data; 110 const DSA_METHOD *meth; 111 void *engine; 112 }; 113 114 /* 115 * 116 */ 117 118 const DSA_METHOD *DSA_null_method(void); 119 120 /* 121 * 122 */ 123 124 DSA * DSA_new(void); 125 void DSA_free(DSA *); 126 int DSA_up_ref(DSA *); 127 128 void DSA_set_default_method(const DSA_METHOD *); 129 const DSA_METHOD * DSA_get_default_method(void); 130 131 const DSA_METHOD * DSA_get_method(const DSA *); 132 int DSA_set_method(DSA *, const DSA_METHOD *); 133 134 void DSA_set_app_data(DSA *, void *arg); 135 void * DSA_get_app_data(DSA *); 136 137 int DSA_size(const DSA *); 138 139 int DSA_verify(int, const unsigned char *, int, 140 const unsigned char *, int, DSA *); 141 142 #endif /* _HEIM_DSA_H */ 143