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