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