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