1#ifndef DST_INTERNAL_H
2#define DST_INTERNAL_H
3
4/*
5 * Portions Copyright (c) 1995-1998 by Trusted Information Systems, Inc.
6 *
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.
10 *
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.
19 */
20#include <limits.h>
21#include <sys/param.h>
22#if (!defined(BSD)) || (BSD < 199306)
23# include <sys/bitypes.h>
24#else
25# include <sys/types.h>
26#endif
27
28#ifndef PATH_MAX
29# ifdef POSIX_PATH_MAX
30#  define PATH_MAX POSIX_PATH_MAX
31# else
32#  define PATH_MAX 255 /* this is the value of POSIX_PATH_MAX */
33# endif
34#endif
35
36#ifndef dst_func
37#define dst_func res_9_dst_func
38#endif
39#define DST_KEY res_9_DST_KEY
40typedef struct dst_key {
41	char	*dk_key_name;   /* name of the key */
42	int	dk_key_size;    /* this is the size of the key in bits */
43	int	dk_proto;       /* what protocols this key can be used for */
44	int	dk_alg;         /* algorithm number from key record */
45	u_int32_t dk_flags;     /* and the flags of the public key */
46	u_int16_t dk_id;        /* identifier of the key */
47	void	*dk_KEY_struct; /* pointer to key in crypto pkg fmt */
48	struct dst_func *dk_func; /* point to cryptto pgk specific function table */
49} DST_KEY;
50#define HAS_DST_KEY
51
52#ifdef __APPLE__
53#include "dst.h"
54#else
55#include <isc/dst.h>
56#endif
57
58/*
59 * define what crypto systems are supported for RSA,
60 * BSAFE is prefered over RSAREF; only one can be set at any time
61 */
62#if defined(BSAFE) && defined(RSAREF)
63# error "Cannot have both BSAFE and RSAREF defined"
64#endif
65
66/* Declare dst_lib specific constants */
67#define KEY_FILE_FORMAT "1.2"
68
69/* suffixes for key file names */
70#define PRIVATE_KEY		"private"
71#define PUBLIC_KEY		"key"
72
73/* error handling */
74#ifdef REPORT_ERRORS
75#define EREPORT(str)		printf str
76#else
77#define EREPORT(str)		(void)0
78#endif
79
80/* use our own special macro to FRRE memory */
81
82#ifndef SAFE_FREE
83#define SAFE_FREE(a) \
84do{if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;}} while (0)
85#define SAFE_FREE2(a,s) if (a != NULL && s > 0){memset(a,0, s);free(a); a=NULL;}
86#endif
87
88#define dst_func res_9_dst_func
89typedef struct dst_func {
90	int (*sign)(const int mode, DST_KEY *key, void **context,
91		     const u_int8_t *data, const int len,
92		     u_int8_t *signature, const int sig_len);
93	int (*verify)(const int mode, DST_KEY *key, void **context,
94		       const u_int8_t *data, const int len,
95		       const u_int8_t *signature, const int sig_len);
96	int (*compare)(const DST_KEY *key1, const DST_KEY *key2);
97	int (*generate)(DST_KEY *key, int parms);
98	void *(*destroy)(void *key);
99	/* conversion functions */
100	int (*to_dns_key)(const DST_KEY *key, u_int8_t *out,
101			   const int out_len);
102	int (*from_dns_key)(DST_KEY *key, const u_int8_t *str,
103			     const int str_len);
104	int (*to_file_fmt)(const DST_KEY *key, char *out,
105			    const int out_len);
106	int (*from_file_fmt)(DST_KEY *key, const char *out,
107			      const int out_len);
108
109} dst_func;
110
111#define dst_t_func res_9_dst_t_func
112extern dst_func *dst_t_func[DST_MAX_ALGS];
113
114#define key_file_fmt_str res_9_key_file_fmt_str
115extern const char *key_file_fmt_str;
116
117#define dst_path res_9_dst_path
118extern const char *dst_path;
119
120#ifndef DST_HASH_SIZE
121#define DST_HASH_SIZE 20	/* RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */
122#endif
123
124#define dst_bsafe_init res_9_dst_bsafe_init
125int dst_bsafe_init(void);
126
127#define dst_rsaref_init res_9_dst_rsaref_init
128int dst_rsaref_init(void);
129
130#define dst_hmac_md5_init res_9_dst_hmac_md5_init
131int dst_hmac_md5_init(void);
132
133#define dst_cylink_init res_9_dst_cylink_init
134int dst_cylink_init(void);
135
136#define dst_eay_dss_init res_9_dst_eay_dss_init
137int dst_eay_dss_init(void);
138
139/* from higher level support routines */
140#define dst_s_calculate_bits res_9_dst_s_calculate_bits
141int       dst_s_calculate_bits( const u_int8_t *str, const int max_bits);
142
143#define dst_s_verify_str res_9_dst_s_verify_str
144int       dst_s_verify_str( const char **buf, const char *str);
145
146
147/* conversion between dns names and key file names */
148#define dst_s_filename_length res_9_dst_s_filename_length
149size_t    dst_s_filename_length( const char *name, const char *suffix);
150
151#define dst_s_build_filename res_9_dst_s_build_filename
152int       dst_s_build_filename(  char *filename, const char *name,
153			         u_int16_t id, int alg, const char *suffix,
154			         size_t filename_length);
155
156#define dst_s_fopen res_9_dst_s_fopen
157FILE      *dst_s_fopen (const char *filename, const char *mode, int perm);
158
159/*
160 * read and write network byte order into u_int?_t
161 *  all of these should be retired
162 */
163#define dst_s_get_int16 res_9_dst_s_get_int16
164u_int16_t dst_s_get_int16( const u_int8_t *buf);
165
166#define dst_s_put_int16 res_9_dst_s_put_int16
167void      dst_s_put_int16( u_int8_t *buf, const u_int16_t val);
168
169#define dst_s_get_int32 res_9_dst_s_get_int32
170u_int32_t dst_s_get_int32( const u_int8_t *buf);
171
172#define dst_s_put_int32 res_9_dst_s_put_int32
173void      dst_s_put_int32( u_int8_t *buf, const u_int32_t val);
174
175#ifdef DUMP
176# undef DUMP
177# define DUMP(a,b,c,d) dst_s_dump(a,b,c,d)
178#else
179# define DUMP(a,b,c,d)
180#endif
181#define dst_s_dump res_9_dst_s_dump
182void
183dst_s_dump(const int mode, const u_char *data, const int size,
184            const char *msg);
185
186
187
188#endif /* DST_INTERNAL_H */
189