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