xref: /titanic_52/usr/src/lib/libresolv2/common/dst/dst_internal.h (revision 55f5292c612446ce6f93ddd248c0019b5974618b)
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 typedef struct dst_key {
37 	char	*dk_key_name;   /*%< name of the key */
38 	int	dk_key_size;    /*%< this is the size of the key in bits */
39 	int	dk_proto;       /*%< what protocols this key can be used for */
40 	int	dk_alg;         /*%< algorithm number from key record */
41 	u_int32_t dk_flags;     /*%< and the flags of the public key */
42 	u_int16_t dk_id;        /*%< identifier of the key */
43 	void	*dk_KEY_struct; /*%< pointer to key in crypto pkg fmt */
44 	struct dst_func *dk_func; /*%< point to cryptto pgk specific function table */
45 } DST_KEY;
46 #define HAS_DST_KEY
47 
48 #include <isc/dst.h>
49 /*
50  * define what crypto systems are supported for RSA,
51  * BSAFE is prefered over RSAREF; only one can be set at any time
52  */
53 #if defined(BSAFE) && defined(RSAREF)
54 # error "Cannot have both BSAFE and RSAREF defined"
55 #endif
56 
57 /* Declare dst_lib specific constants */
58 #define KEY_FILE_FORMAT "1.2"
59 
60 /* suffixes for key file names */
61 #define PRIVATE_KEY		"private"
62 #define PUBLIC_KEY		"key"
63 
64 /* error handling */
65 #ifdef REPORT_ERRORS
66 #define EREPORT(str)		printf str
67 #else
68 #define EREPORT(str)		(void)0
69 #endif
70 
71 /* use our own special macro to FRRE memory */
72 
73 #ifndef SAFE_FREE
74 #define SAFE_FREE(a) \
75 do{if(a != NULL){memset(a,0, sizeof(*a)); free(a); a=NULL;}} while (0)
76 #define SAFE_FREE2(a,s) if (a != NULL && (long)s > 0){memset(a,0, s);free(a); a=NULL;}
77 #endif
78 
79 typedef struct dst_func {
80 	int (*sign)(const int mode, DST_KEY *key, void **context,
81 		     const u_int8_t *data, const int len,
82 		     u_int8_t *signature, const int sig_len);
83 	int (*verify)(const int mode, DST_KEY *key, void **context,
84 		       const u_int8_t *data, const int len,
85 		       const u_int8_t *signature, const int sig_len);
86 	int (*compare)(const DST_KEY *key1, const DST_KEY *key2);
87 	int (*generate)(DST_KEY *key, int parms);
88 	void *(*destroy)(void *key);
89 	/* conversion functions */
90 	int (*to_dns_key)(const DST_KEY *key, u_int8_t *out,
91 			   const int out_len);
92 	int (*from_dns_key)(DST_KEY *key, const u_int8_t *str,
93 			     const int str_len);
94 	int (*to_file_fmt)(const DST_KEY *key, char *out,
95 			    const int out_len);
96 	int (*from_file_fmt)(DST_KEY *key, const char *out,
97 			      const int out_len);
98 
99 } dst_func;
100 
101 extern dst_func *dst_t_func[DST_MAX_ALGS];
102 extern const char *key_file_fmt_str;
103 extern const char *dst_path;
104 
105 #ifndef DST_HASH_SIZE
106 #define DST_HASH_SIZE 20	/*%< RIPEMD160 and SHA-1 are 20 bytes MD5 is 16 */
107 #endif
108 
109 int dst_bsafe_init(void);
110 
111 int dst_rsaref_init(void);
112 
113 int dst_hmac_md5_init(void);
114 
115 int dst_cylink_init(void);
116 
117 int dst_eay_dss_init(void);
118 
119 /* from higher level support routines */
120 int       dst_s_calculate_bits( const u_int8_t *str, const int max_bits);
121 int       dst_s_verify_str( const char **buf, const char *str);
122 
123 
124 /* conversion between dns names and key file names */
125 size_t    dst_s_filename_length( const char *name, const char *suffix);
126 int       dst_s_build_filename(  char *filename, const char *name,
127 			         u_int16_t id, int alg, const char *suffix,
128 			         size_t filename_length);
129 
130 FILE      *dst_s_fopen (const char *filename, const char *mode, int perm);
131 
132 /*%
133  * read and write network byte order into u_int?_t
134  *  all of these should be retired
135  */
136 u_int16_t dst_s_get_int16( const u_int8_t *buf);
137 void      dst_s_put_int16( u_int8_t *buf, const u_int16_t val);
138 
139 u_int32_t dst_s_get_int32( const u_int8_t *buf);
140 void      dst_s_put_int32( u_int8_t *buf, const u_int32_t val);
141 
142 #ifdef DUMP
143 # undef DUMP
144 # define DUMP(a,b,c,d) dst_s_dump(a,b,c,d)
145 #else
146 # define DUMP(a,b,c,d)
147 #endif
148 void
149 dst_s_dump(const int mode, const u_char *data, const int size,
150             const char *msg);
151 
152 
153 
154 #endif /* DST_INTERNAL_H */
155 /*! \file */
156