5 * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
7 * Permission to use, copy modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND TRUSTED INFORMATION SYSTEMS
12 * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
13 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
14 * TRUSTED INFORMATION SYSTEMS BE LIABLE FOR ANY SPECIAL, DIRECT,
15 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
16 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
17 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
18 * WITH THE USE OR PERFORMANCE OF THE SOFTWARE.
21 #include <sys/param.h>
24 # ifdef POSIX_PATH_MAX
25 # define PATH_MAX POSIX_PATH_MAX
27 # define PATH_MAX 255 /* this is the value of POSIX_PATH_MAX */
31 typedef struct dst_key
{
32 char *dk_key_name
; /* name of the key */
33 int dk_key_size
; /* this is the size of the key in bits */
34 int dk_proto
; /* what protocols this key can be used for */
35 int dk_alg
; /* algorithm number from key record */
36 unsigned dk_flags
; /* and the flags of the public key */
37 unsigned dk_id
; /* identifier of the key */
38 void *dk_KEY_struct
; /* pointer to key in crypto pkg fmt */
39 struct dst_func
*dk_func
; /* point to cryptto pgk specific function table */
43 #include <isc-dhcp/dst.h>
45 * define what crypto systems are supported for RSA,
46 * BSAFE is prefered over RSAREF; only one can be set at any time
48 #if defined(BSAFE) && defined(RSAREF)
49 # error "Cannot have both BSAFE and RSAREF defined"
52 /* Declare dst_lib specific constants */
53 #define KEY_FILE_FORMAT "1.2"
55 /* suffixes for key file names */
56 #define PRIVATE_KEY "private"
57 #define PUBLIC_KEY "key"
61 #define EREPORT(str) printf str
66 /* use our own special macro to FRRE memory */
69 #define SAFE_FREE(a) if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;}
70 #define SAFE_FREE2(a,s) if (a != NULL && s > 0){memset(a,0, s);free(a); a=NULL;}
73 typedef struct dst_func
{
74 int (*sign
)(const int mode
, DST_KEY
*key
, void **context
,
75 const u_int8_t
*data
, const unsigned len
,
76 u_int8_t
*signature
, const unsigned sig_len
);
77 int (*verify
)(const int mode
, DST_KEY
*key
, void **context
,
78 const u_int8_t
*data
, const unsigned len
,
79 const u_int8_t
*signature
, const unsigned sig_len
);
80 int (*compare
)(const DST_KEY
*key1
, const DST_KEY
*key2
);
81 int (*generate
)(DST_KEY
*key
, int parms
);
82 void *(*destroy
)(void *key
);
83 /* conversion functions */
84 int (*to_dns_key
)(const DST_KEY
*key
, u_int8_t
*out
,
85 const unsigned out_len
);
86 int (*from_dns_key
)(DST_KEY
*key
, const u_int8_t
*str
,
87 const unsigned str_len
);
88 int (*to_file_fmt
)(const DST_KEY
*key
, char *out
,
89 const unsigned out_len
);
90 int (*from_file_fmt
)(DST_KEY
*key
, const char *out
,
91 const unsigned out_len
);
95 extern dst_func
*dst_t_func
[DST_MAX_ALGS
];
96 extern const char *key_file_fmt_str
;
97 extern const char *dst_path
;
100 #define DST_HASH_SIZE 20 /* RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */
104 int dst_bsafe_init(void);
105 int dst_rsaref_init(void);
108 int dst_hmac_md5_init(void);
111 int dst_cylink_init(void);
112 int dst_eay_dss_init(void);
115 /* support functions */
116 /* base64 to bignum conversion routines */
117 int dst_s_conv_bignum_u8_to_b64( char *out_buf
, const unsigned out_len
,
119 const u_int8_t
*bin_data
,
120 const unsigned bin_len
);
121 int dst_s_conv_bignum_b64_to_u8( const char **buf
, u_int8_t
*loc
,
122 const unsigned loclen
) ;
123 /* from higher level support routines */
124 int dst_s_calculate_bits( const u_int8_t
*str
, const int max_bits
);
125 int dst_s_verify_str( const char **buf
, const char *str
);
128 /* conversion between dns names and key file names */
129 size_t dst_s_filename_length( const char *name
, const char *suffix
);
130 int dst_s_build_filename( char *filename
, const char *name
,
131 unsigned id
, int alg
, const char *suffix
,
132 size_t filename_length
);
134 FILE *dst_s_fopen (const char *filename
, const char *mode
, unsigned perm
);
136 /* from file prandom.c */
137 int dst_s_random( u_int8_t
*output
, unsigned size
);
138 int dst_s_semi_random( u_int8_t
*output
, unsigned size
);
139 u_int32_t
dst_s_quick_random( int inc
);
140 void dst_s_quick_random_set( u_int32_t val
, u_int32_t cnt
);
143 * read and write network byte order into u_int?_t
144 * all of these should be retired
146 u_int16_t
dst_s_get_int16( const u_int8_t
*buf
);
147 void dst_s_put_int16( u_int8_t
*buf
, const u_int16_t val
);
149 u_int32_t
dst_s_get_int32( const u_int8_t
*buf
);
150 void dst_s_put_int32( u_int8_t
*buf
, const u_int32_t val
);
154 # define DUMP(a,b,c,d) dst_s_dump(a,b,c,d)
156 # define DUMP(a,b,c,d)
160 #endif /* DST_INTERNAL_H */