xref: /onnv-gate/usr/src/lib/libresolv2/include/isc/dst.h (revision 11038:74b12212b8a2)
10Sstevel@tonic-gate #ifndef DST_H
20Sstevel@tonic-gate #define DST_H
30Sstevel@tonic-gate 
40Sstevel@tonic-gate #ifndef HAS_DST_KEY
50Sstevel@tonic-gate typedef struct dst_key {
6*11038SRao.Shoaib@Sun.COM 	char	*dk_key_name;   /*%< name of the key */
7*11038SRao.Shoaib@Sun.COM 	int	dk_key_size;    /*%< this is the size of the key in bits */
8*11038SRao.Shoaib@Sun.COM 	int	dk_proto;       /*%< what protocols this key can be used for */
9*11038SRao.Shoaib@Sun.COM 	int	dk_alg;         /*%< algorithm number from key record */
10*11038SRao.Shoaib@Sun.COM 	u_int32_t dk_flags;     /*%< and the flags of the public key */
11*11038SRao.Shoaib@Sun.COM 	u_int16_t dk_id;        /*%< identifier of the key */
120Sstevel@tonic-gate } DST_KEY;
130Sstevel@tonic-gate #endif /* HAS_DST_KEY */
140Sstevel@tonic-gate /*
150Sstevel@tonic-gate  * do not taint namespace
160Sstevel@tonic-gate  */
170Sstevel@tonic-gate #define	dst_bsafe_init		__dst_bsafe_init
180Sstevel@tonic-gate #define	dst_buffer_to_key	__dst_buffer_to_key
190Sstevel@tonic-gate #define	dst_check_algorithm	__dst_check_algorithm
200Sstevel@tonic-gate #define	dst_compare_keys	__dst_compare_keys
210Sstevel@tonic-gate #define	dst_cylink_init		__dst_cylink_init
220Sstevel@tonic-gate #define	dst_dnskey_to_key	__dst_dnskey_to_key
230Sstevel@tonic-gate #define	dst_eay_dss_init	__dst_eay_dss_init
240Sstevel@tonic-gate #define	dst_free_key		__dst_free_key
250Sstevel@tonic-gate #define	dst_generate_key	__dst_generate_key
260Sstevel@tonic-gate #define	dst_hmac_md5_init	__dst_hmac_md5_init
270Sstevel@tonic-gate #define	dst_init		__dst_init
280Sstevel@tonic-gate #define	dst_key_to_buffer	__dst_key_to_buffer
290Sstevel@tonic-gate #define	dst_key_to_dnskey	__dst_key_to_dnskey
300Sstevel@tonic-gate #define	dst_read_key		__dst_read_key
310Sstevel@tonic-gate #define	dst_rsaref_init		__dst_rsaref_init
320Sstevel@tonic-gate #define	dst_s_build_filename	__dst_s_build_filename
330Sstevel@tonic-gate #define	dst_s_calculate_bits	__dst_s_calculate_bits
340Sstevel@tonic-gate #define	dst_s_conv_bignum_b64_to_u8	__dst_s_conv_bignum_b64_to_u8
350Sstevel@tonic-gate #define	dst_s_conv_bignum_u8_to_b64	__dst_s_conv_bignum_u8_to_b64
360Sstevel@tonic-gate #define	dst_s_dns_key_id	__dst_s_dns_key_id
370Sstevel@tonic-gate #define	dst_s_dump		__dst_s_dump
380Sstevel@tonic-gate #define	dst_s_filename_length	__dst_s_filename_length
390Sstevel@tonic-gate #define	dst_s_fopen		__dst_s_fopen
400Sstevel@tonic-gate #define	dst_s_get_int16		__dst_s_get_int16
410Sstevel@tonic-gate #define	dst_s_get_int32		__dst_s_get_int32
420Sstevel@tonic-gate #define	dst_s_id_calc		__dst_s_id_calc
430Sstevel@tonic-gate #define	dst_s_put_int16		__dst_s_put_int16
440Sstevel@tonic-gate #define	dst_s_put_int32		__dst_s_put_int32
450Sstevel@tonic-gate #define	dst_s_quick_random	__dst_s_quick_random
460Sstevel@tonic-gate #define	dst_s_quick_random_set	__dst_s_quick_random_set
470Sstevel@tonic-gate #define	dst_s_random		__dst_s_random
480Sstevel@tonic-gate #define	dst_s_semi_random	__dst_s_semi_random
490Sstevel@tonic-gate #define	dst_s_verify_str	__dst_s_verify_str
500Sstevel@tonic-gate #define	dst_sig_size		__dst_sig_size
510Sstevel@tonic-gate #define	dst_sign_data		__dst_sign_data
520Sstevel@tonic-gate #define	dst_verify_data		__dst_verify_data
530Sstevel@tonic-gate #define	dst_write_key		__dst_write_key
540Sstevel@tonic-gate 
550Sstevel@tonic-gate /*
560Sstevel@tonic-gate  * DST Crypto API defintions
570Sstevel@tonic-gate  */
580Sstevel@tonic-gate void     dst_init(void);
590Sstevel@tonic-gate int      dst_check_algorithm(const int);
600Sstevel@tonic-gate 
610Sstevel@tonic-gate 
62*11038SRao.Shoaib@Sun.COM int dst_sign_data(const int,	 	/*!<   specifies INIT/UPDATE/FINAL/ALL  */
63*11038SRao.Shoaib@Sun.COM 		  DST_KEY *,	 	/*!<   the key to use  */
64*11038SRao.Shoaib@Sun.COM 		  void **,	 	/*!<   pointer to state structure  */
65*11038SRao.Shoaib@Sun.COM 		  const u_char *,	/*!<   data to be signed  */
66*11038SRao.Shoaib@Sun.COM 		  const int,	 	/*!<   length of input data  */
67*11038SRao.Shoaib@Sun.COM 		  u_char *,	 	/*!<   buffer to write signature to  */
68*11038SRao.Shoaib@Sun.COM 		  const int);	 	/*!<   size of output buffer  */
69*11038SRao.Shoaib@Sun.COM int dst_verify_data(const int,	 	/*!<   specifies INIT/UPDATE/FINAL/ALL  */
70*11038SRao.Shoaib@Sun.COM 		    DST_KEY *,	 	/*!<   the key to use  */
71*11038SRao.Shoaib@Sun.COM 		    void **,	 	/*!<   pointer to state structure  */
72*11038SRao.Shoaib@Sun.COM 		    const u_char *,	/*!<   data to be verified  */
73*11038SRao.Shoaib@Sun.COM 		    const int,	 	/*!<   length of input data  */
74*11038SRao.Shoaib@Sun.COM 		    const u_char *,	/*!<   buffer containing signature  */
75*11038SRao.Shoaib@Sun.COM 		    const int);	 	/*!<   length of signature  */
76*11038SRao.Shoaib@Sun.COM DST_KEY *dst_read_key(const char *,	/*!<   name of key  */
77*11038SRao.Shoaib@Sun.COM 		      const u_int16_t,	/*!<   key tag identifier  */
78*11038SRao.Shoaib@Sun.COM 		      const int,	/*!<   key algorithm  */
79*11038SRao.Shoaib@Sun.COM 		      const int);	/*!<   Private/PublicKey wanted */
80*11038SRao.Shoaib@Sun.COM int      dst_write_key(const DST_KEY *,	/*!<   key to write out  */
81*11038SRao.Shoaib@Sun.COM 		       const int); 	/*!<   Public/Private  */
82*11038SRao.Shoaib@Sun.COM DST_KEY *dst_dnskey_to_key(const char *,	/*!<   KEY record name  */
83*11038SRao.Shoaib@Sun.COM 			   const u_char *,	/*!<   KEY RDATA  */
84*11038SRao.Shoaib@Sun.COM 			   const int);		/*!<   size of input buffer */
85*11038SRao.Shoaib@Sun.COM int      dst_key_to_dnskey(const DST_KEY *,	/*!<   key to translate  */
86*11038SRao.Shoaib@Sun.COM 			   u_char *,		/*!<   output buffer  */
87*11038SRao.Shoaib@Sun.COM 			   const int);		/*!<   size of out_storage */
88*11038SRao.Shoaib@Sun.COM DST_KEY *dst_buffer_to_key(const char *,  	/*!<   name of the key  */
89*11038SRao.Shoaib@Sun.COM 			   const int,	  	/*!<   algorithm  */
90*11038SRao.Shoaib@Sun.COM 			   const int,	  	/*!<   dns flags  */
91*11038SRao.Shoaib@Sun.COM 			   const int,	  	/*!<   dns protocol  */
92*11038SRao.Shoaib@Sun.COM 			   const u_char *, 	/*!<   key in dns wire fmt  */
93*11038SRao.Shoaib@Sun.COM 			   const int);	  	/*!<   size of key  */
94*11038SRao.Shoaib@Sun.COM int     dst_key_to_buffer(DST_KEY *, u_char *, int);
950Sstevel@tonic-gate 
96*11038SRao.Shoaib@Sun.COM DST_KEY *dst_generate_key(const char *,    	/*!<   name of new key  */
97*11038SRao.Shoaib@Sun.COM 			  const int,       	/*!<   key algorithm to generate  */
98*11038SRao.Shoaib@Sun.COM 			  const int,      	/*!<   size of new key  */
99*11038SRao.Shoaib@Sun.COM 			  const int,       	/*!<   alg dependent parameter */
100*11038SRao.Shoaib@Sun.COM 			  const int,     	/*!<   key DNS flags  */
101*11038SRao.Shoaib@Sun.COM 			  const int);		/*!<   key DNS protocol  */
102*11038SRao.Shoaib@Sun.COM DST_KEY *dst_free_key(DST_KEY *);
103*11038SRao.Shoaib@Sun.COM int      dst_compare_keys(const DST_KEY *, const DST_KEY *);
1040Sstevel@tonic-gate 
105*11038SRao.Shoaib@Sun.COM int	dst_sig_size(DST_KEY *);
1060Sstevel@tonic-gate 
1070Sstevel@tonic-gate 
1080Sstevel@tonic-gate /* support for dns key tags/ids */
109*11038SRao.Shoaib@Sun.COM u_int16_t dst_s_dns_key_id(const u_char *, const int);
110*11038SRao.Shoaib@Sun.COM u_int16_t dst_s_id_calc(const u_char *, const int);
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /* Used by callers as well as by the library.  */
113*11038SRao.Shoaib@Sun.COM #define RAW_KEY_SIZE    8192        /*%< large enough to store any key */
1140Sstevel@tonic-gate /* DST_API control flags */
1150Sstevel@tonic-gate /* These are used used in functions dst_sign_data and dst_verify_data */
116*11038SRao.Shoaib@Sun.COM #define SIG_MODE_INIT		1  /*%< initialize digest */
117*11038SRao.Shoaib@Sun.COM #define SIG_MODE_UPDATE		2  /*%< add data to digest */
118*11038SRao.Shoaib@Sun.COM #define SIG_MODE_FINAL		4  /*%< generate/verify signature */
1190Sstevel@tonic-gate #define SIG_MODE_ALL		(SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate /* Flags for dst_read_private_key()  */
1220Sstevel@tonic-gate #define DST_FORCE_READ		0x1000000
1230Sstevel@tonic-gate #define DST_CAN_SIGN		0x010F
1240Sstevel@tonic-gate #define DST_NO_AUTHEN		0x8000
1250Sstevel@tonic-gate #define DST_EXTEND_FLAG         0x1000
1260Sstevel@tonic-gate #define DST_STANDARD		0
1270Sstevel@tonic-gate #define DST_PRIVATE             0x2000000
1280Sstevel@tonic-gate #define DST_PUBLIC              0x4000000
1290Sstevel@tonic-gate #define DST_RAND_SEMI           1
1300Sstevel@tonic-gate #define DST_RAND_STD            2
1310Sstevel@tonic-gate #define DST_RAND_KEY            3
1320Sstevel@tonic-gate #define DST_RAND_DSS            4
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate /* DST algorithm codes */
1360Sstevel@tonic-gate #define KEY_RSA			1
1370Sstevel@tonic-gate #define KEY_DH			2
1380Sstevel@tonic-gate #define KEY_DSA			3
1390Sstevel@tonic-gate #define KEY_PRIVATE		254
1400Sstevel@tonic-gate #define KEY_EXPAND		255
1410Sstevel@tonic-gate #define KEY_HMAC_MD5		157
1420Sstevel@tonic-gate #define KEY_HMAC_SHA1		158
1430Sstevel@tonic-gate #define UNKNOWN_KEYALG		0
1440Sstevel@tonic-gate #define DST_MAX_ALGS            KEY_HMAC_SHA1
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /* DST constants to locations in KEY record  changes in new KEY record */
1470Sstevel@tonic-gate #define DST_FLAGS_SIZE		2
1480Sstevel@tonic-gate #define DST_KEY_PROT		2
1490Sstevel@tonic-gate #define DST_KEY_ALG		3
1500Sstevel@tonic-gate #define DST_EXT_FLAG            4
1510Sstevel@tonic-gate #define DST_KEY_START		4
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate #ifndef SIGN_F_NOKEY
1540Sstevel@tonic-gate #define SIGN_F_NOKEY		0xC000
1550Sstevel@tonic-gate #endif
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate /* error codes from dst routines */
1580Sstevel@tonic-gate #define SIGN_INIT_FAILURE	(-23)
1590Sstevel@tonic-gate #define SIGN_UPDATE_FAILURE	(-24)
1600Sstevel@tonic-gate #define SIGN_FINAL_FAILURE	(-25)
1610Sstevel@tonic-gate #define VERIFY_INIT_FAILURE	(-26)
1620Sstevel@tonic-gate #define VERIFY_UPDATE_FAILURE	(-27)
1630Sstevel@tonic-gate #define VERIFY_FINAL_FAILURE	(-28)
1640Sstevel@tonic-gate #define MISSING_KEY_OR_SIGNATURE (-30)
1650Sstevel@tonic-gate #define UNSUPPORTED_KEYALG	(-31)
1660Sstevel@tonic-gate 
1670Sstevel@tonic-gate #endif /* DST_H */
168*11038SRao.Shoaib@Sun.COM /*! \file */
169