17c478bd9Sstevel@tonic-gate #ifndef DST_H
27c478bd9Sstevel@tonic-gate #define DST_H
47c478bd9Sstevel@tonic-gate #ifndef HAS_DST_KEY
57c478bd9Sstevel@tonic-gate typedef struct dst_key {
6*9525b14bSRao Shoaib 	char	*dk_key_name;   /*%< name of the key */
7*9525b14bSRao Shoaib 	int	dk_key_size;    /*%< this is the size of the key in bits */
8*9525b14bSRao Shoaib 	int	dk_proto;       /*%< what protocols this key can be used for */
9*9525b14bSRao Shoaib 	int	dk_alg;         /*%< algorithm number from key record */
10*9525b14bSRao Shoaib 	u_int32_t dk_flags;     /*%< and the flags of the public key */
11*9525b14bSRao Shoaib 	u_int16_t dk_id;        /*%< identifier of the key */
127c478bd9Sstevel@tonic-gate } DST_KEY;
137c478bd9Sstevel@tonic-gate #endif /* HAS_DST_KEY */
147c478bd9Sstevel@tonic-gate /*
157c478bd9Sstevel@tonic-gate  * do not taint namespace
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate #define	dst_bsafe_init		__dst_bsafe_init
187c478bd9Sstevel@tonic-gate #define	dst_buffer_to_key	__dst_buffer_to_key
197c478bd9Sstevel@tonic-gate #define	dst_check_algorithm	__dst_check_algorithm
207c478bd9Sstevel@tonic-gate #define	dst_compare_keys	__dst_compare_keys
217c478bd9Sstevel@tonic-gate #define	dst_cylink_init		__dst_cylink_init
227c478bd9Sstevel@tonic-gate #define	dst_dnskey_to_key	__dst_dnskey_to_key
237c478bd9Sstevel@tonic-gate #define	dst_eay_dss_init	__dst_eay_dss_init
247c478bd9Sstevel@tonic-gate #define	dst_free_key		__dst_free_key
257c478bd9Sstevel@tonic-gate #define	dst_generate_key	__dst_generate_key
267c478bd9Sstevel@tonic-gate #define	dst_hmac_md5_init	__dst_hmac_md5_init
277c478bd9Sstevel@tonic-gate #define	dst_init		__dst_init
287c478bd9Sstevel@tonic-gate #define	dst_key_to_buffer	__dst_key_to_buffer
297c478bd9Sstevel@tonic-gate #define	dst_key_to_dnskey	__dst_key_to_dnskey
307c478bd9Sstevel@tonic-gate #define	dst_read_key		__dst_read_key
317c478bd9Sstevel@tonic-gate #define	dst_rsaref_init		__dst_rsaref_init
327c478bd9Sstevel@tonic-gate #define	dst_s_build_filename	__dst_s_build_filename
337c478bd9Sstevel@tonic-gate #define	dst_s_calculate_bits	__dst_s_calculate_bits
347c478bd9Sstevel@tonic-gate #define	dst_s_conv_bignum_b64_to_u8	__dst_s_conv_bignum_b64_to_u8
357c478bd9Sstevel@tonic-gate #define	dst_s_conv_bignum_u8_to_b64	__dst_s_conv_bignum_u8_to_b64
367c478bd9Sstevel@tonic-gate #define	dst_s_dns_key_id	__dst_s_dns_key_id
377c478bd9Sstevel@tonic-gate #define	dst_s_dump		__dst_s_dump
387c478bd9Sstevel@tonic-gate #define	dst_s_filename_length	__dst_s_filename_length
397c478bd9Sstevel@tonic-gate #define	dst_s_fopen		__dst_s_fopen
407c478bd9Sstevel@tonic-gate #define	dst_s_get_int16		__dst_s_get_int16
417c478bd9Sstevel@tonic-gate #define	dst_s_get_int32		__dst_s_get_int32
427c478bd9Sstevel@tonic-gate #define	dst_s_id_calc		__dst_s_id_calc
437c478bd9Sstevel@tonic-gate #define	dst_s_put_int16		__dst_s_put_int16
447c478bd9Sstevel@tonic-gate #define	dst_s_put_int32		__dst_s_put_int32
457c478bd9Sstevel@tonic-gate #define	dst_s_quick_random	__dst_s_quick_random
467c478bd9Sstevel@tonic-gate #define	dst_s_quick_random_set	__dst_s_quick_random_set
477c478bd9Sstevel@tonic-gate #define	dst_s_random		__dst_s_random
487c478bd9Sstevel@tonic-gate #define	dst_s_semi_random	__dst_s_semi_random
497c478bd9Sstevel@tonic-gate #define	dst_s_verify_str	__dst_s_verify_str
507c478bd9Sstevel@tonic-gate #define	dst_sig_size		__dst_sig_size
517c478bd9Sstevel@tonic-gate #define	dst_sign_data		__dst_sign_data
527c478bd9Sstevel@tonic-gate #define	dst_verify_data		__dst_verify_data
537c478bd9Sstevel@tonic-gate #define	dst_write_key		__dst_write_key
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * DST Crypto API defintions
577c478bd9Sstevel@tonic-gate  */
587c478bd9Sstevel@tonic-gate void     dst_init(void);
597c478bd9Sstevel@tonic-gate int      dst_check_algorithm(const int);
62*9525b14bSRao Shoaib int dst_sign_data(const int,	 	/*!<   specifies INIT/UPDATE/FINAL/ALL  */
63*9525b14bSRao Shoaib 		  DST_KEY *,	 	/*!<   the key to use  */
64*9525b14bSRao Shoaib 		  void **,	 	/*!<   pointer to state structure  */
65*9525b14bSRao Shoaib 		  const u_char *,	/*!<   data to be signed  */
66*9525b14bSRao Shoaib 		  const int,	 	/*!<   length of input data  */
67*9525b14bSRao Shoaib 		  u_char *,	 	/*!<   buffer to write signature to  */
68*9525b14bSRao Shoaib 		  const int);	 	/*!<   size of output buffer  */
69*9525b14bSRao Shoaib int dst_verify_data(const int,	 	/*!<   specifies INIT/UPDATE/FINAL/ALL  */
70*9525b14bSRao Shoaib 		    DST_KEY *,	 	/*!<   the key to use  */
71*9525b14bSRao Shoaib 		    void **,	 	/*!<   pointer to state structure  */
72*9525b14bSRao Shoaib 		    const u_char *,	/*!<   data to be verified  */
73*9525b14bSRao Shoaib 		    const int,	 	/*!<   length of input data  */
74*9525b14bSRao Shoaib 		    const u_char *,	/*!<   buffer containing signature  */
75*9525b14bSRao Shoaib 		    const int);	 	/*!<   length of signature  */
76*9525b14bSRao Shoaib DST_KEY *dst_read_key(const char *,	/*!<   name of key  */
77*9525b14bSRao Shoaib 		      const u_int16_t,	/*!<   key tag identifier  */
78*9525b14bSRao Shoaib 		      const int,	/*!<   key algorithm  */
79*9525b14bSRao Shoaib 		      const int);	/*!<   Private/PublicKey wanted */
80*9525b14bSRao Shoaib int      dst_write_key(const DST_KEY *,	/*!<   key to write out  */
81*9525b14bSRao Shoaib 		       const int); 	/*!<   Public/Private  */
82*9525b14bSRao Shoaib DST_KEY *dst_dnskey_to_key(const char *,	/*!<   KEY record name  */
83*9525b14bSRao Shoaib 			   const u_char *,	/*!<   KEY RDATA  */
84*9525b14bSRao Shoaib 			   const int);		/*!<   size of input buffer */
85*9525b14bSRao Shoaib int      dst_key_to_dnskey(const DST_KEY *,	/*!<   key to translate  */
86*9525b14bSRao Shoaib 			   u_char *,		/*!<   output buffer  */
87*9525b14bSRao Shoaib 			   const int);		/*!<   size of out_storage */
88*9525b14bSRao Shoaib DST_KEY *dst_buffer_to_key(const char *,  	/*!<   name of the key  */
89*9525b14bSRao Shoaib 			   const int,	  	/*!<   algorithm  */
90*9525b14bSRao Shoaib 			   const int,	  	/*!<   dns flags  */
91*9525b14bSRao Shoaib 			   const int,	  	/*!<   dns protocol  */
92*9525b14bSRao Shoaib 			   const u_char *, 	/*!<   key in dns wire fmt  */
93*9525b14bSRao Shoaib 			   const int);	  	/*!<   size of key  */
94*9525b14bSRao Shoaib int     dst_key_to_buffer(DST_KEY *, u_char *, int);
95*9525b14bSRao Shoaib 
96*9525b14bSRao Shoaib DST_KEY *dst_generate_key(const char *,    	/*!<   name of new key  */
97*9525b14bSRao Shoaib 			  const int,       	/*!<   key algorithm to generate  */
98*9525b14bSRao Shoaib 			  const int,      	/*!<   size of new key  */
99*9525b14bSRao Shoaib 			  const int,       	/*!<   alg dependent parameter */
100*9525b14bSRao Shoaib 			  const int,     	/*!<   key DNS flags  */
101*9525b14bSRao Shoaib 			  const int);		/*!<   key DNS protocol  */
102*9525b14bSRao Shoaib DST_KEY *dst_free_key(DST_KEY *);
103*9525b14bSRao Shoaib int      dst_compare_keys(const DST_KEY *, const DST_KEY *);
104*9525b14bSRao Shoaib 
105*9525b14bSRao Shoaib int	dst_sig_size(DST_KEY *);
1087c478bd9Sstevel@tonic-gate /* support for dns key tags/ids */
109*9525b14bSRao Shoaib u_int16_t dst_s_dns_key_id(const u_char *, const int);
110*9525b14bSRao Shoaib u_int16_t dst_s_id_calc(const u_char *, const int);
1127c478bd9Sstevel@tonic-gate /* Used by callers as well as by the library.  */
113*9525b14bSRao Shoaib #define RAW_KEY_SIZE    8192        /*%< large enough to store any key */
1147c478bd9Sstevel@tonic-gate /* DST_API control flags */
1157c478bd9Sstevel@tonic-gate /* These are used used in functions dst_sign_data and dst_verify_data */
116*9525b14bSRao Shoaib #define SIG_MODE_INIT		1  /*%< initialize digest */
117*9525b14bSRao Shoaib #define SIG_MODE_UPDATE		2  /*%< add data to digest */
118*9525b14bSRao Shoaib #define SIG_MODE_FINAL		4  /*%< generate/verify signature */
1197c478bd9Sstevel@tonic-gate #define SIG_MODE_ALL		(SIG_MODE_INIT|SIG_MODE_UPDATE|SIG_MODE_FINAL)
1217c478bd9Sstevel@tonic-gate /* Flags for dst_read_private_key()  */
1227c478bd9Sstevel@tonic-gate #define DST_FORCE_READ		0x1000000
1237c478bd9Sstevel@tonic-gate #define DST_CAN_SIGN		0x010F
1247c478bd9Sstevel@tonic-gate #define DST_NO_AUTHEN		0x8000
1257c478bd9Sstevel@tonic-gate #define DST_EXTEND_FLAG         0x1000
1267c478bd9Sstevel@tonic-gate #define DST_STANDARD		0
1277c478bd9Sstevel@tonic-gate #define DST_PRIVATE             0x2000000
1287c478bd9Sstevel@tonic-gate #define DST_PUBLIC              0x4000000
1297c478bd9Sstevel@tonic-gate #define DST_RAND_SEMI           1
1307c478bd9Sstevel@tonic-gate #define DST_RAND_STD            2
1317c478bd9Sstevel@tonic-gate #define DST_RAND_KEY            3
1327c478bd9Sstevel@tonic-gate #define DST_RAND_DSS            4
1357c478bd9Sstevel@tonic-gate /* DST algorithm codes */
1367c478bd9Sstevel@tonic-gate #define KEY_RSA			1
1377c478bd9Sstevel@tonic-gate #define KEY_DH			2
1387c478bd9Sstevel@tonic-gate #define KEY_DSA			3
1397c478bd9Sstevel@tonic-gate #define KEY_PRIVATE		254
1407c478bd9Sstevel@tonic-gate #define KEY_EXPAND		255
1417c478bd9Sstevel@tonic-gate #define KEY_HMAC_MD5		157
1427c478bd9Sstevel@tonic-gate #define KEY_HMAC_SHA1		158
1437c478bd9Sstevel@tonic-gate #define UNKNOWN_KEYALG		0
1447c478bd9Sstevel@tonic-gate #define DST_MAX_ALGS            KEY_HMAC_SHA1
1467c478bd9Sstevel@tonic-gate /* DST constants to locations in KEY record  changes in new KEY record */
1477c478bd9Sstevel@tonic-gate #define DST_FLAGS_SIZE		2
1487c478bd9Sstevel@tonic-gate #define DST_KEY_PROT		2
1497c478bd9Sstevel@tonic-gate #define DST_KEY_ALG		3
1507c478bd9Sstevel@tonic-gate #define DST_EXT_FLAG            4
1517c478bd9Sstevel@tonic-gate #define DST_KEY_START		4
1537c478bd9Sstevel@tonic-gate #ifndef SIGN_F_NOKEY
1547c478bd9Sstevel@tonic-gate #define SIGN_F_NOKEY		0xC000
1557c478bd9Sstevel@tonic-gate #endif
1577c478bd9Sstevel@tonic-gate /* error codes from dst routines */
1587c478bd9Sstevel@tonic-gate #define SIGN_INIT_FAILURE	(-23)
1597c478bd9Sstevel@tonic-gate #define SIGN_UPDATE_FAILURE	(-24)
1607c478bd9Sstevel@tonic-gate #define SIGN_FINAL_FAILURE	(-25)
1617c478bd9Sstevel@tonic-gate #define VERIFY_INIT_FAILURE	(-26)
1627c478bd9Sstevel@tonic-gate #define VERIFY_UPDATE_FAILURE	(-27)
1637c478bd9Sstevel@tonic-gate #define VERIFY_FINAL_FAILURE	(-28)
1647c478bd9Sstevel@tonic-gate #define MISSING_KEY_OR_SIGNATURE (-30)
1657c478bd9Sstevel@tonic-gate #define UNSUPPORTED_KEYALG	(-31)
1677c478bd9Sstevel@tonic-gate #endif /* DST_H */
168*9525b14bSRao Shoaib /*! \file */