xref: /netbsd-src/external/bsd/libbind/dist/include/isc/dst.h (revision b5677b36047b601b9addaaa494a58ceae82c2a6c)
1*b5677b36Schristos /*	$NetBSD: dst.h,v 1.1.1.1 2009/04/12 15:33:33 christos Exp $	*/
2*b5677b36Schristos 
3*b5677b36Schristos #ifndef DST_H
4*b5677b36Schristos #define DST_H
5*b5677b36Schristos 
6*b5677b36Schristos #ifndef HAS_DST_KEY
7*b5677b36Schristos typedef struct dst_key {
8*b5677b36Schristos 	char	*dk_key_name;   /*%< name of the key */
9*b5677b36Schristos 	int	dk_key_size;    /*%< this is the size of the key in bits */
10*b5677b36Schristos 	int	dk_proto;       /*%< what protocols this key can be used for */
11*b5677b36Schristos 	int	dk_alg;         /*%< algorithm number from key record */
12*b5677b36Schristos 	u_int32_t dk_flags;     /*%< and the flags of the public key */
13*b5677b36Schristos 	u_int16_t dk_id;        /*%< identifier of the key */
14*b5677b36Schristos } DST_KEY;
15*b5677b36Schristos #endif /* HAS_DST_KEY */
16*b5677b36Schristos /*
17*b5677b36Schristos  * do not taint namespace
18*b5677b36Schristos  */
19*b5677b36Schristos #define	dst_bsafe_init		__dst_bsafe_init
20*b5677b36Schristos #define	dst_buffer_to_key	__dst_buffer_to_key
21*b5677b36Schristos #define	dst_check_algorithm	__dst_check_algorithm
22*b5677b36Schristos #define	dst_compare_keys	__dst_compare_keys
23*b5677b36Schristos #define	dst_cylink_init		__dst_cylink_init
24*b5677b36Schristos #define	dst_dnskey_to_key	__dst_dnskey_to_key
25*b5677b36Schristos #define	dst_eay_dss_init	__dst_eay_dss_init
26*b5677b36Schristos #define	dst_free_key		__dst_free_key
27*b5677b36Schristos #define	dst_generate_key	__dst_generate_key
28*b5677b36Schristos #define	dst_hmac_md5_init	__dst_hmac_md5_init
29*b5677b36Schristos #define	dst_init		__dst_init
30*b5677b36Schristos #define	dst_key_to_buffer	__dst_key_to_buffer
31*b5677b36Schristos #define	dst_key_to_dnskey	__dst_key_to_dnskey
32*b5677b36Schristos #define	dst_read_key		__dst_read_key
33*b5677b36Schristos #define	dst_rsaref_init		__dst_rsaref_init
34*b5677b36Schristos #define	dst_s_build_filename	__dst_s_build_filename
35*b5677b36Schristos #define	dst_s_calculate_bits	__dst_s_calculate_bits
36*b5677b36Schristos #define	dst_s_conv_bignum_b64_to_u8	__dst_s_conv_bignum_b64_to_u8
37*b5677b36Schristos #define	dst_s_conv_bignum_u8_to_b64	__dst_s_conv_bignum_u8_to_b64
38*b5677b36Schristos #define	dst_s_dns_key_id	__dst_s_dns_key_id
39*b5677b36Schristos #define	dst_s_dump		__dst_s_dump
40*b5677b36Schristos #define	dst_s_filename_length	__dst_s_filename_length
41*b5677b36Schristos #define	dst_s_fopen		__dst_s_fopen
42*b5677b36Schristos #define	dst_s_get_int16		__dst_s_get_int16
43*b5677b36Schristos #define	dst_s_get_int32		__dst_s_get_int32
44*b5677b36Schristos #define	dst_s_id_calc		__dst_s_id_calc
45*b5677b36Schristos #define	dst_s_put_int16		__dst_s_put_int16
46*b5677b36Schristos #define	dst_s_put_int32		__dst_s_put_int32
47*b5677b36Schristos #define	dst_s_quick_random	__dst_s_quick_random
48*b5677b36Schristos #define	dst_s_quick_random_set	__dst_s_quick_random_set
49*b5677b36Schristos #define	dst_s_random		__dst_s_random
50*b5677b36Schristos #define	dst_s_semi_random	__dst_s_semi_random
51*b5677b36Schristos #define	dst_s_verify_str	__dst_s_verify_str
52*b5677b36Schristos #define	dst_sig_size		__dst_sig_size
53*b5677b36Schristos #define	dst_sign_data		__dst_sign_data
54*b5677b36Schristos #define	dst_verify_data		__dst_verify_data
55*b5677b36Schristos #define	dst_write_key		__dst_write_key
56*b5677b36Schristos 
57*b5677b36Schristos /*
58*b5677b36Schristos  * DST Crypto API defintions
59*b5677b36Schristos  */
60*b5677b36Schristos void     dst_init(void);
61*b5677b36Schristos int      dst_check_algorithm(const int);
62*b5677b36Schristos 
63*b5677b36Schristos 
64*b5677b36Schristos int dst_sign_data(const int,	 	/*!<   specifies INIT/UPDATE/FINAL/ALL  */
65*b5677b36Schristos 		  DST_KEY *,	 	/*!<   the key to use  */
66*b5677b36Schristos 		  void **,	 	/*!<   pointer to state structure  */
67*b5677b36Schristos 		  const u_char *,	/*!<   data to be signed  */
68*b5677b36Schristos 		  const int,	 	/*!<   length of input data  */
69*b5677b36Schristos 		  u_char *,	 	/*!<   buffer to write signature to  */
70*b5677b36Schristos 		  const int);	 	/*!<   size of output buffer  */
71*b5677b36Schristos int dst_verify_data(const int,	 	/*!<   specifies INIT/UPDATE/FINAL/ALL  */
72*b5677b36Schristos 		    DST_KEY *,	 	/*!<   the key to use  */
73*b5677b36Schristos 		    void **,	 	/*!<   pointer to state structure  */
74*b5677b36Schristos 		    const u_char *,	/*!<   data to be verified  */
75*b5677b36Schristos 		    const int,	 	/*!<   length of input data  */
76*b5677b36Schristos 		    const u_char *,	/*!<   buffer containing signature  */
77*b5677b36Schristos 		    const int);	 	/*!<   length of signature  */
78*b5677b36Schristos DST_KEY *dst_read_key(const char *,	/*!<   name of key  */
79*b5677b36Schristos 		      const u_int16_t,	/*!<   key tag identifier  */
80*b5677b36Schristos 		      const int,	/*!<   key algorithm  */
81*b5677b36Schristos 		      const int);	/*!<   Private/PublicKey wanted */
82*b5677b36Schristos int      dst_write_key(const DST_KEY *,	/*!<   key to write out  */
83*b5677b36Schristos 		       const int); 	/*!<   Public/Private  */
84*b5677b36Schristos DST_KEY *dst_dnskey_to_key(const char *,	/*!<   KEY record name  */
85*b5677b36Schristos 			   const u_char *,	/*!<   KEY RDATA  */
86*b5677b36Schristos 			   const int);		/*!<   size of input buffer */
87*b5677b36Schristos int      dst_key_to_dnskey(const DST_KEY *,	/*!<   key to translate  */
88*b5677b36Schristos 			   u_char *,		/*!<   output buffer  */
89*b5677b36Schristos 			   const int);		/*!<   size of out_storage */
90*b5677b36Schristos DST_KEY *dst_buffer_to_key(const char *,  	/*!<   name of the key  */
91*b5677b36Schristos 			   const int,	  	/*!<   algorithm  */
92*b5677b36Schristos 			   const int,	  	/*!<   dns flags  */
93*b5677b36Schristos 			   const int,	  	/*!<   dns protocol  */
94*b5677b36Schristos 			   const u_char *, 	/*!<   key in dns wire fmt  */
95*b5677b36Schristos 			   const int);	  	/*!<   size of key  */
96*b5677b36Schristos int     dst_key_to_buffer(DST_KEY *, u_char *, int);
97*b5677b36Schristos 
98*b5677b36Schristos DST_KEY *dst_generate_key(const char *,    	/*!<   name of new key  */
99*b5677b36Schristos 			  const int,       	/*!<   key algorithm to generate  */
100*b5677b36Schristos 			  const int,      	/*!<   size of new key  */
101*b5677b36Schristos 			  const int,       	/*!<   alg dependent parameter */
102*b5677b36Schristos 			  const int,     	/*!<   key DNS flags  */
103*b5677b36Schristos 			  const int);		/*!<   key DNS protocol  */
104*b5677b36Schristos DST_KEY *dst_free_key(DST_KEY *);
105*b5677b36Schristos int      dst_compare_keys(const DST_KEY *, const DST_KEY *);
106*b5677b36Schristos 
107*b5677b36Schristos int	dst_sig_size(DST_KEY *);
108*b5677b36Schristos 
109*b5677b36Schristos 
110*b5677b36Schristos /* support for dns key tags/ids */
111*b5677b36Schristos u_int16_t dst_s_dns_key_id(const u_char *, const int);
112*b5677b36Schristos u_int16_t dst_s_id_calc(const u_char *, const int);
113*b5677b36Schristos 
114*b5677b36Schristos /* Used by callers as well as by the library.  */
115*b5677b36Schristos #define RAW_KEY_SIZE    8192        /*%< large enough to store any key */
116*b5677b36Schristos /* DST_API control flags */
117*b5677b36Schristos /* These are used used in functions dst_sign_data and dst_verify_data */
118*b5677b36Schristos #define SIG_MODE_INIT		1  /*%< initialize digest */
119*b5677b36Schristos #define SIG_MODE_UPDATE		2  /*%< add data to digest */
120*b5677b36Schristos #define SIG_MODE_FINAL		4  /*%< generate/verify signature */
121*b5677b36Schristos #define SIG_MODE_ALL		(SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
122*b5677b36Schristos 
123*b5677b36Schristos /* Flags for dst_read_private_key()  */
124*b5677b36Schristos #define DST_FORCE_READ		0x1000000
125*b5677b36Schristos #define DST_CAN_SIGN		0x010F
126*b5677b36Schristos #define DST_NO_AUTHEN		0x8000
127*b5677b36Schristos #define DST_EXTEND_FLAG         0x1000
128*b5677b36Schristos #define DST_STANDARD		0
129*b5677b36Schristos #define DST_PRIVATE             0x2000000
130*b5677b36Schristos #define DST_PUBLIC              0x4000000
131*b5677b36Schristos #define DST_RAND_SEMI           1
132*b5677b36Schristos #define DST_RAND_STD            2
133*b5677b36Schristos #define DST_RAND_KEY            3
134*b5677b36Schristos #define DST_RAND_DSS            4
135*b5677b36Schristos 
136*b5677b36Schristos 
137*b5677b36Schristos /* DST algorithm codes */
138*b5677b36Schristos #define KEY_RSA			1
139*b5677b36Schristos #define KEY_DH			2
140*b5677b36Schristos #define KEY_DSA			3
141*b5677b36Schristos #define KEY_PRIVATE		254
142*b5677b36Schristos #define KEY_EXPAND		255
143*b5677b36Schristos #define KEY_HMAC_MD5		157
144*b5677b36Schristos #define KEY_HMAC_SHA1		158
145*b5677b36Schristos #define UNKNOWN_KEYALG		0
146*b5677b36Schristos #define DST_MAX_ALGS            KEY_HMAC_SHA1
147*b5677b36Schristos 
148*b5677b36Schristos /* DST constants to locations in KEY record  changes in new KEY record */
149*b5677b36Schristos #define DST_FLAGS_SIZE		2
150*b5677b36Schristos #define DST_KEY_PROT		2
151*b5677b36Schristos #define DST_KEY_ALG		3
152*b5677b36Schristos #define DST_EXT_FLAG            4
153*b5677b36Schristos #define DST_KEY_START		4
154*b5677b36Schristos 
155*b5677b36Schristos #ifndef SIGN_F_NOKEY
156*b5677b36Schristos #define SIGN_F_NOKEY		0xC000
157*b5677b36Schristos #endif
158*b5677b36Schristos 
159*b5677b36Schristos /* error codes from dst routines */
160*b5677b36Schristos #define SIGN_INIT_FAILURE	(-23)
161*b5677b36Schristos #define SIGN_UPDATE_FAILURE	(-24)
162*b5677b36Schristos #define SIGN_FINAL_FAILURE	(-25)
163*b5677b36Schristos #define VERIFY_INIT_FAILURE	(-26)
164*b5677b36Schristos #define VERIFY_UPDATE_FAILURE	(-27)
165*b5677b36Schristos #define VERIFY_FINAL_FAILURE	(-28)
166*b5677b36Schristos #define MISSING_KEY_OR_SIGNATURE (-30)
167*b5677b36Schristos #define UNSUPPORTED_KEYALG	(-31)
168*b5677b36Schristos 
169*b5677b36Schristos #endif /* DST_H */
170*b5677b36Schristos /*! \file */
171