1 /* $NetBSD: dsa.h,v 1.2 2017/01/28 21:31:47 christos 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 hc_DSA 47 #define DSA_METHOD hc_DSA_METHOD 48 #define DSA_null_method hc_DSA_null_method 49 #define DSA_new hc_DSA_new 50 #define DSA_free hc_DSA_free 51 #define DSA_up_ref hc_DSA_up_ref 52 #define DSA_set_default_method hc_DSA_set_default_method 53 #define DSA_get_default_method hc_DSA_get_default_method 54 #define DSA_set_method hc_DSA_set_method 55 #define DSA_get_method hc_DSA_get_method 56 #define DSA_set_app_data hc_DSA_set_app_data 57 #define DSA_get_app_data hc_DSA_get_app_data 58 #define DSA_size hc_DSA_size 59 #define DSA_verify hc_DSA_verify 60 61 /* 62 * 63 */ 64 65 66 typedef struct DSA DSA; 67 typedef struct DSA_METHOD DSA_METHOD; 68 typedef struct DSA_SIG DSA_SIG; 69 70 struct DSA_SIG { 71 BIGNUM *r; 72 BIGNUM *s; 73 }; 74 75 struct DSA_METHOD { 76 const char *name; 77 DSA_SIG * (*dsa_do_sign)(const unsigned char *, int, DSA *); 78 int (*dsa_sign_setup)(DSA *, BN_CTX *, BIGNUM **, BIGNUM **); 79 int (*dsa_do_verify)(const unsigned char *, int, DSA_SIG *, DSA *); 80 int (*dsa_mod_exp)(DSA *, BIGNUM *, BIGNUM *, BIGNUM *, 81 BIGNUM *, BIGNUM *, BIGNUM *, BN_CTX *, 82 BN_MONT_CTX *); 83 int (*bn_mod_exp)(DSA *, BIGNUM *, BIGNUM *, const BIGNUM *, 84 const BIGNUM *, BN_CTX *, 85 BN_MONT_CTX *); 86 int (*init)(DSA *); 87 int (*finish)(DSA *); 88 int flags; 89 void *app_data; 90 }; 91 92 struct DSA { 93 int pad; 94 long version; 95 int write_params; 96 BIGNUM *p; 97 BIGNUM *q; 98 BIGNUM *g; 99 100 BIGNUM *pub_key; 101 BIGNUM *priv_key; 102 103 BIGNUM *kinv; 104 BIGNUM *r; 105 int flags; 106 void *method_mont_p; 107 int references; 108 struct dsa_CRYPTO_EX_DATA { 109 void *sk; 110 int dummy; 111 } ex_data; 112 const DSA_METHOD *meth; 113 void *engine; 114 }; 115 116 /* 117 * 118 */ 119 120 const DSA_METHOD *DSA_null_method(void); 121 122 /* 123 * 124 */ 125 126 DSA * DSA_new(void); 127 void DSA_free(DSA *); 128 int DSA_up_ref(DSA *); 129 130 void DSA_set_default_method(const DSA_METHOD *); 131 const DSA_METHOD * DSA_get_default_method(void); 132 133 const DSA_METHOD * DSA_get_method(const DSA *); 134 int DSA_set_method(DSA *, const DSA_METHOD *); 135 136 void DSA_set_app_data(DSA *, void *arg); 137 void * DSA_get_app_data(DSA *); 138 139 int DSA_size(const DSA *); 140 141 int DSA_verify(int, const unsigned char *, int, 142 const unsigned char *, int, DSA *); 143 144 #endif /* _HEIM_DSA_H */ 145