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