Home | History | Annotate | Line # | Download | only in libresolv
dst_internal.h revision 1.2.2.2
      1  1.2.2.2  joerg /*	$NetBSD: dst_internal.h,v 1.2.2.2 2012/11/16 02:11:06 joerg Exp $	*/
      2  1.2.2.2  joerg 
      3  1.2.2.2  joerg #ifndef DST_INTERNAL_H
      4  1.2.2.2  joerg #define DST_INTERNAL_H
      5  1.2.2.2  joerg 
      6  1.2.2.2  joerg /*
      7  1.2.2.2  joerg  * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
      8  1.2.2.2  joerg  *
      9  1.2.2.2  joerg  * Permission to use, copy modify, and distribute this software for any
     10  1.2.2.2  joerg  * purpose with or without fee is hereby granted, provided that the above
     11  1.2.2.2  joerg  * copyright notice and this permission notice appear in all copies.
     12  1.2.2.2  joerg  *
     13  1.2.2.2  joerg  * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS
     14  1.2.2.2  joerg  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
     15  1.2.2.2  joerg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL
     16  1.2.2.2  joerg  * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT,
     17  1.2.2.2  joerg  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
     18  1.2.2.2  joerg  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
     19  1.2.2.2  joerg  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
     20  1.2.2.2  joerg  * WITH THE USE OR PERFORMANCE OF THE SOFTWARE.
     21  1.2.2.2  joerg  */
     22  1.2.2.2  joerg #include <limits.h>
     23  1.2.2.2  joerg #include <sys/param.h>
     24  1.2.2.2  joerg #if (!defined(BSD)) || (BSD < 199306)
     25  1.2.2.2  joerg # include <sys/bitypes.h>
     26  1.2.2.2  joerg #else
     27  1.2.2.2  joerg # include <sys/types.h>
     28  1.2.2.2  joerg #endif
     29  1.2.2.2  joerg 
     30  1.2.2.2  joerg #ifndef PATH_MAX
     31  1.2.2.2  joerg # ifdef POSIX_PATH_MAX
     32  1.2.2.2  joerg #  define PATH_MAX POSIX_PATH_MAX
     33  1.2.2.2  joerg # else
     34  1.2.2.2  joerg #  define PATH_MAX 255 /*%< this is the value of POSIX_PATH_MAX */
     35  1.2.2.2  joerg # endif
     36  1.2.2.2  joerg #endif
     37  1.2.2.2  joerg 
     38  1.2.2.2  joerg typedef struct dst_key {
     39  1.2.2.2  joerg 	char	*dk_key_name;   /*%< name of the key */
     40  1.2.2.2  joerg 	int	dk_key_size;    /*%< this is the size of the key in bits */
     41  1.2.2.2  joerg 	int	dk_proto;       /*%< what protocols this key can be used for */
     42  1.2.2.2  joerg 	int	dk_alg;         /*%< algorithm number from key record */
     43  1.2.2.2  joerg 	u_int32_t dk_flags;     /*%< and the flags of the public key */
     44  1.2.2.2  joerg 	u_int16_t dk_id;        /*%< identifier of the key */
     45  1.2.2.2  joerg 	void	*dk_KEY_struct; /*%< pointer to key in crypto pkg fmt */
     46  1.2.2.2  joerg 	struct dst_func *dk_func; /*%< point to cryptto pgk specific function table */
     47  1.2.2.2  joerg } DST_KEY;
     48  1.2.2.2  joerg #define HAS_DST_KEY
     49  1.2.2.2  joerg 
     50  1.2.2.2  joerg #include <isc/dst.h>
     51  1.2.2.2  joerg /*
     52  1.2.2.2  joerg  * define what crypto systems are supported for RSA,
     53  1.2.2.2  joerg  * BSAFE is prefered over RSAREF; only one can be set at any time
     54  1.2.2.2  joerg  */
     55  1.2.2.2  joerg #if defined(BSAFE) && defined(RSAREF)
     56  1.2.2.2  joerg # error "Cannot have both BSAFE and RSAREF defined"
     57  1.2.2.2  joerg #endif
     58  1.2.2.2  joerg 
     59  1.2.2.2  joerg /* Declare dst_lib specific constants */
     60  1.2.2.2  joerg #define KEY_FILE_FORMAT "1.2"
     61  1.2.2.2  joerg 
     62  1.2.2.2  joerg /* suffixes for key file names */
     63  1.2.2.2  joerg #define PRIVATE_KEY		"private"
     64  1.2.2.2  joerg #define PUBLIC_KEY		"key"
     65  1.2.2.2  joerg 
     66  1.2.2.2  joerg /* error handling */
     67  1.2.2.2  joerg #ifdef DEBUG
     68  1.2.2.2  joerg #define EREPORT(str)		printf str
     69  1.2.2.2  joerg #else
     70  1.2.2.2  joerg #define EREPORT(str)		do {} while (/*CONSTCOND*/0)
     71  1.2.2.2  joerg #endif
     72  1.2.2.2  joerg 
     73  1.2.2.2  joerg /* use our own special macro to FRRE memory */
     74  1.2.2.2  joerg 
     75  1.2.2.2  joerg #ifndef SAFE_FREE2
     76  1.2.2.2  joerg #define SAFE_FREE2(a, s) do { \
     77  1.2.2.2  joerg 	if ((a) != NULL) { \
     78  1.2.2.2  joerg 		memset((a), 0, (s)); \
     79  1.2.2.2  joerg 		free((a)); \
     80  1.2.2.2  joerg 		(a) = NULL; \
     81  1.2.2.2  joerg 	} \
     82  1.2.2.2  joerg } while (/*CONSTCOND*/0)
     83  1.2.2.2  joerg #endif
     84  1.2.2.2  joerg 
     85  1.2.2.2  joerg #ifndef SAFE_FREE
     86  1.2.2.2  joerg #define SAFE_FREE(a) SAFE_FREE2((a), sizeof(*(a)))
     87  1.2.2.2  joerg #endif
     88  1.2.2.2  joerg 
     89  1.2.2.2  joerg typedef struct dst_func {
     90  1.2.2.2  joerg 	int (*sign)(const int mode, DST_KEY *key, void **context,
     91  1.2.2.2  joerg 		     const u_int8_t *data, const int len,
     92  1.2.2.2  joerg 		     u_int8_t *signature, const int sig_len);
     93  1.2.2.2  joerg 	int (*verify)(const int mode, DST_KEY *key, void **context,
     94  1.2.2.2  joerg 		       const u_int8_t *data, const int len,
     95  1.2.2.2  joerg 		       const u_int8_t *signature, const int sig_len);
     96  1.2.2.2  joerg 	int (*compare)(const DST_KEY *key1, const DST_KEY *key2);
     97  1.2.2.2  joerg 	int (*generate)(DST_KEY *key, int parms);
     98  1.2.2.2  joerg 	void *(*destroy)(void *key);
     99  1.2.2.2  joerg 	/* conversion functions */
    100  1.2.2.2  joerg 	int (*to_dns_key)(const DST_KEY *key, u_int8_t *out,
    101  1.2.2.2  joerg 			   const int out_len);
    102  1.2.2.2  joerg 	int (*from_dns_key)(DST_KEY *key, const u_int8_t *str,
    103  1.2.2.2  joerg 			     const int str_len);
    104  1.2.2.2  joerg 	int (*to_file_fmt)(const DST_KEY *key, char *out,
    105  1.2.2.2  joerg 			    const int out_len);
    106  1.2.2.2  joerg 	int (*from_file_fmt)(DST_KEY *key, const char *out,
    107  1.2.2.2  joerg 			      const int out_len);
    108  1.2.2.2  joerg 
    109  1.2.2.2  joerg } dst_func;
    110  1.2.2.2  joerg 
    111  1.2.2.2  joerg extern dst_func *dst_t_func[DST_MAX_ALGS];
    112  1.2.2.2  joerg extern const char *key_file_fmt_str;
    113  1.2.2.2  joerg extern const char *dst_path;
    114  1.2.2.2  joerg 
    115  1.2.2.2  joerg #ifndef DST_HASH_SIZE
    116  1.2.2.2  joerg #define DST_HASH_SIZE 20	/*%< RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */
    117  1.2.2.2  joerg #endif
    118  1.2.2.2  joerg 
    119  1.2.2.2  joerg int dst_bsafe_init(void);
    120  1.2.2.2  joerg 
    121  1.2.2.2  joerg int dst_rsaref_init(void);
    122  1.2.2.2  joerg 
    123  1.2.2.2  joerg int dst_hmac_md5_init(void);
    124  1.2.2.2  joerg 
    125  1.2.2.2  joerg int dst_cylink_init(void);
    126  1.2.2.2  joerg 
    127  1.2.2.2  joerg int dst_eay_dss_init(void);
    128  1.2.2.2  joerg 
    129  1.2.2.2  joerg /* from higher level support routines */
    130  1.2.2.2  joerg int       dst_s_calculate_bits( const u_int8_t *str, const int max_bits);
    131  1.2.2.2  joerg int       dst_s_verify_str( const char **buf, const char *str);
    132  1.2.2.2  joerg 
    133  1.2.2.2  joerg 
    134  1.2.2.2  joerg /* conversion between dns names and key file names */
    135  1.2.2.2  joerg size_t    dst_s_filename_length( const char *name, const char *suffix);
    136  1.2.2.2  joerg int       dst_s_build_filename(  char *filename, const char *name,
    137  1.2.2.2  joerg 			         u_int16_t id, int alg, const char *suffix,
    138  1.2.2.2  joerg 			         size_t filename_length);
    139  1.2.2.2  joerg 
    140  1.2.2.2  joerg FILE      *dst_s_fopen (const char *filename, const char *mode, int perm);
    141  1.2.2.2  joerg 
    142  1.2.2.2  joerg /*%
    143  1.2.2.2  joerg  * read and write network byte order into u_int?_t
    144  1.2.2.2  joerg  *  all of these should be retired
    145  1.2.2.2  joerg  */
    146  1.2.2.2  joerg u_int16_t dst_s_get_int16( const u_int8_t *buf);
    147  1.2.2.2  joerg void      dst_s_put_int16( u_int8_t *buf, const u_int16_t val);
    148  1.2.2.2  joerg 
    149  1.2.2.2  joerg u_int32_t dst_s_get_int32( const u_int8_t *buf);
    150  1.2.2.2  joerg void      dst_s_put_int32( u_int8_t *buf, const u_int32_t val);
    151  1.2.2.2  joerg 
    152  1.2.2.2  joerg #ifdef DUMP
    153  1.2.2.2  joerg # undef DUMP
    154  1.2.2.2  joerg # define DUMP(a,b,c,d) dst_s_dump(a,b,c,d)
    155  1.2.2.2  joerg #else
    156  1.2.2.2  joerg # define DUMP(a,b,c,d)
    157  1.2.2.2  joerg #endif
    158  1.2.2.2  joerg void
    159  1.2.2.2  joerg dst_s_dump(const int mode, const u_char *data, const int size,
    160  1.2.2.2  joerg             const char *msg);
    161  1.2.2.2  joerg 
    162  1.2.2.2  joerg #define  KEY_FILE_FMT_STR "Private-key-format: v%s\nAlgorithm: %d (%s)\n"
    163  1.2.2.2  joerg 
    164  1.2.2.2  joerg 
    165  1.2.2.2  joerg #endif /* DST_INTERNAL_H */
    166  1.2.2.2  joerg /*! \file */
    167