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