1 /* $NetBSD: oakley.h,v 1.5 2006/10/06 12:02:27 manu Exp $ */
3 /* Id: oakley.h,v 1.13 2005/05/30 20:12:43 fredsen Exp */
6 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the project nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include <Security/SecDH.h>
44 /* refer to RFC 2409 */
46 /* Attribute Classes */
47 #define OAKLEY_ATTR_ENC_ALG 1 /* B */
48 #define OAKLEY_ATTR_ENC_ALG_DES 1
49 #define OAKLEY_ATTR_ENC_ALG_IDEA 2
50 #define OAKLEY_ATTR_ENC_ALG_BLOWFISH 3
51 #define OAKLEY_ATTR_ENC_ALG_RC5 4
52 #define OAKLEY_ATTR_ENC_ALG_3DES 5
53 #define OAKLEY_ATTR_ENC_ALG_CAST 6
54 #define OAKLEY_ATTR_ENC_ALG_AES 7
55 /* 65001 - 65535 Private Use */
56 #define OAKLEY_ATTR_HASH_ALG 2 /* B */
57 #define OAKLEY_ATTR_HASH_ALG_MD5 1
58 #define OAKLEY_ATTR_HASH_ALG_SHA 2
59 #define OAKLEY_ATTR_HASH_ALG_TIGER 3
60 #if defined(WITH_SHA2)
61 #define OAKLEY_ATTR_HASH_ALG_SHA2_256 4
62 #define OAKLEY_ATTR_HASH_ALG_SHA2_384 5
63 #define OAKLEY_ATTR_HASH_ALG_SHA2_512 6
65 /* 65001 - 65535 Private Use */
66 #define OAKLEY_ATTR_AUTH_METHOD 3 /* B */
67 #define OAKLEY_ATTR_AUTH_METHOD_PSKEY 1
68 #define OAKLEY_ATTR_AUTH_METHOD_DSSSIG 2
69 #define OAKLEY_ATTR_AUTH_METHOD_RSASIG 3
70 #define OAKLEY_ATTR_AUTH_METHOD_RSAENC 4
71 #define OAKLEY_ATTR_AUTH_METHOD_RSAREV 5
72 #define OAKLEY_ATTR_AUTH_METHOD_EGENC 6
73 #define OAKLEY_ATTR_AUTH_METHOD_EGREV 7
76 #define OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_I 64221
77 #define OAKLEY_ATTR_AUTH_METHOD_HYBRID_RSA_R 64222
78 #define OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_I 64223
79 #define OAKLEY_ATTR_AUTH_METHOD_HYBRID_DSS_R 64224
81 /* 65001 - 65535 Private Use */
84 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I 65001
85 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_R 65002
86 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_I 65003
87 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_DSSSIG_R 65004
88 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_I 65005
89 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSASIG_R 65006
90 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_I 65007
91 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAENC_R 65008
92 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_I 65009
93 #define OAKLEY_ATTR_AUTH_METHOD_XAUTH_RSAREV_R 65010
96 /* 65500 -> still private
97 * to avoid clash with GSSAPI_KRB below
99 #define FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I 65500
103 * The following are valid when the Vendor ID is one of
106 * MD5("A GSS-API Authentication Method for IKE")
107 * MD5("GSSAPI") (recognized by Windows 2000)
108 * MD5("MS NT5 ISAKMPOAKLEY") (sent by Windows 2000)
110 #define OAKLEY_ATTR_AUTH_METHOD_GSSAPI_KRB 65001
111 #define OAKLEY_ATTR_GRP_DESC 4 /* B */
112 #define OAKLEY_ATTR_GRP_DESC_MODP768 1
113 #define OAKLEY_ATTR_GRP_DESC_MODP1024 2
114 #define OAKLEY_ATTR_GRP_DESC_EC2N155 3
115 #define OAKLEY_ATTR_GRP_DESC_EC2N185 4
116 #define OAKLEY_ATTR_GRP_DESC_MODP1536 5
117 #define OAKLEY_ATTR_GRP_DESC_MODP2048 14
118 #define OAKLEY_ATTR_GRP_DESC_MODP3072 15
119 #define OAKLEY_ATTR_GRP_DESC_MODP4096 16
120 #define OAKLEY_ATTR_GRP_DESC_MODP6144 17
121 #define OAKLEY_ATTR_GRP_DESC_MODP8192 18
122 /* 32768 - 65535 Private Use */
123 #define OAKLEY_ATTR_GRP_TYPE 5 /* B */
124 #define OAKLEY_ATTR_GRP_TYPE_MODP 1
125 #define OAKLEY_ATTR_GRP_TYPE_ECP 2
126 #define OAKLEY_ATTR_GRP_TYPE_EC2N 3
127 /* 65001 - 65535 Private Use */
128 #define OAKLEY_ATTR_GRP_PI 6 /* V */
129 #define OAKLEY_ATTR_GRP_GEN_ONE 7 /* V */
130 #define OAKLEY_ATTR_GRP_GEN_TWO 8 /* V */
131 #define OAKLEY_ATTR_GRP_CURVE_A 9 /* V */
132 #define OAKLEY_ATTR_GRP_CURVE_B 10 /* V */
133 #define OAKLEY_ATTR_SA_LD_TYPE 11 /* B */
134 #define OAKLEY_ATTR_SA_LD_TYPE_DEFAULT 1
135 #define OAKLEY_ATTR_SA_LD_TYPE_SEC 1
136 #define OAKLEY_ATTR_SA_LD_TYPE_KB 2
137 #define OAKLEY_ATTR_SA_LD_TYPE_MAX 3
138 /* 65001 - 65535 Private Use */
139 #define OAKLEY_ATTR_SA_LD 12 /* V */
140 #define OAKLEY_ATTR_SA_LD_SEC_DEFAULT 28800 /* 8 hours */
141 #define OAKLEY_ATTR_PRF 13 /* B */
142 #define OAKLEY_ATTR_KEY_LEN 14 /* B */
143 #define OAKLEY_ATTR_FIELD_SIZE 15 /* B */
144 #define OAKLEY_ATTR_GRP_ORDER 16 /* V */
145 #define OAKLEY_ATTR_BLOCK_SIZE 17 /* B */
146 /* 16384 - 32767 Private Use */
149 * The following are valid when the Vendor ID is one of
152 * MD5("A GSS-API Authentication Method for IKE")
153 * MD5("GSSAPI") (recognized by Windows 2000)
154 * MD5("MS NT5 ISAKMPOAKLEY") (sent by Windows 2000)
156 #define OAKLEY_ATTR_GSS_ID 16384
158 #define MAXPADLWORD 20
173 typedef enum cert_status
{
175 CERT_STATUS_PREMATURE
,
177 CERT_STATUS_INVALID_SUBJNAME
,
178 CERT_STATUS_INVALID_SUBJALTNAME
,
182 #define IS_CERT_STATUS_ERROR(status) (status > CERT_STATUS_OK && status < CERT_STATUS_INVALID)
184 /* certificate holder */
185 typedef struct cert_t_tag
{
186 u_int8_t type
; /* type of CERT, must be same to pl->v[0]*/
187 vchar_t cert
; /* pointer to the CERT */
188 vchar_t
*pl
; /* CERT payload minus isakmp general header */
189 cert_status_t status
;
190 struct cert_t_tag
*chain
;
197 extern int oakley_get_defaultlifetime
__P((void));
199 extern int oakley_dhinit
__P((void));
200 extern void oakley_dhgrp_free
__P((struct dhgroup
*));
202 extern int oakley_dh_compute
__P((const struct dhgroup
*, vchar_t
*, vchar_t
*, vchar_t
*, vchar_t
**));
203 extern int oakley_dh_generate
__P((const struct dhgroup
*, vchar_t
**, vchar_t
**));
205 extern int oakley_dh_compute
__P((const struct dhgroup
*, vchar_t
*, size_t, vchar_t
**, SecDHContext
));
206 extern int oakley_dh_generate
__P((const struct dhgroup
*, vchar_t
**, size_t *, SecDHContext
*));
208 extern int oakley_setdhgroup
__P((int, struct dhgroup
**));
210 extern vchar_t
*oakley_prf
__P((vchar_t
*, vchar_t
*, struct ph1handle
*));
211 extern vchar_t
*oakley_hash
__P((vchar_t
*, struct ph1handle
*));
213 extern int oakley_compute_keymat
__P((struct ph2handle
*, int));
216 extern vchar_t
*oakley_compute_hashx
__P((void));
218 extern vchar_t
*oakley_compute_hash3
__P((struct ph1handle
*,
219 u_int32_t
, vchar_t
*));
220 extern vchar_t
*oakley_compute_hash1
__P((struct ph1handle
*,
221 u_int32_t
, vchar_t
*));
222 extern vchar_t
*oakley_ph1hash_common
__P((struct ph1handle
*, int));
223 extern vchar_t
*oakley_ph1hash_base_i
__P((struct ph1handle
*, int));
224 extern vchar_t
*oakley_ph1hash_base_r
__P((struct ph1handle
*, int));
226 extern int oakley_validate_auth
__P((struct ph1handle
*));
227 extern int oakley_getmycert
__P((struct ph1handle
*));
228 extern int oakley_getsign
__P((struct ph1handle
*));
229 extern cert_t
* oakley_get_peer_cert_from_certchain
__P((struct ph1handle
*));
230 extern int oakley_find_status_in_certchain
__P((cert_t
*, cert_status_t
));
231 extern void oakley_verify_certid
__P((struct ph1handle
*));
232 extern vchar_t
*oakley_getcr
__P((struct ph1handle
*));
233 extern int oakley_checkcr
__P((struct ph1handle
*));
234 extern int oakley_needcr
__P((int));
236 extern int oakley_savecert
__P((struct ph1handle
*, struct isakmp_gen
*));
237 extern int oakley_savecr
__P((struct ph1handle
*, struct isakmp_gen
*));
239 extern vchar_t
* oakley_getpskall
__P((struct ph1handle
*));
240 extern int oakley_skeyid
__P((struct ph1handle
*));
241 extern int oakley_skeyid_dae
__P((struct ph1handle
*));
243 extern int oakley_compute_enckey
__P((struct ph1handle
*));
244 extern cert_t
*oakley_newcert
__P((void));
245 extern void oakley_delcert
__P((cert_t
*));
246 extern int oakley_newiv
__P((struct ph1handle
*));
247 extern struct isakmp_ivm
*oakley_newiv2
__P((struct ph1handle
*, u_int32_t
));
248 extern void oakley_delivm
__P((struct isakmp_ivm
*));
249 extern vchar_t
*oakley_do_decrypt
__P((struct ph1handle
*,
250 vchar_t
*, vchar_t
*, vchar_t
*));
251 extern vchar_t
*oakley_do_encrypt
__P((struct ph1handle
*,
252 vchar_t
*, vchar_t
*, vchar_t
*));
255 #define AUTHMETHOD(iph1) \
256 (((iph1)->rmconf->xauth && \
257 (iph1)->approval->authmethod == OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I) ? \
258 FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I : (iph1)->approval->authmethod)
259 #define RMAUTHMETHOD(iph1) \
260 (((iph1)->rmconf->xauth && \
261 (iph1)->rmconf->proposal->authmethod == \
262 OAKLEY_ATTR_AUTH_METHOD_XAUTH_PSKEY_I) ? \
263 FICTIVE_AUTH_METHOD_XAUTH_PSKEY_I : \
264 (iph1)->rmconf->proposal->authmethod)
266 #define AUTHMETHOD(iph1) (iph1)->approval->authmethod
267 #define RMAUTHMETHOD(iph1) (iph1)->rmconf->proposal->authmethod
268 #endif /* ENABLE_HYBRID */
270 #endif /* _OAKLEY_H */