xref: /freebsd/sys/netipsec/xform.h (revision a0b9e2e854027e6ff61fb075a1309dbc71c42b54)
1 /*	$FreeBSD$	*/
2 /*	$OpenBSD: ip_ipsp.h,v 1.119 2002/03/14 01:27:11 millert Exp $	*/
3 /*-
4  * The authors of this code are John Ioannidis (ji@tla.org),
5  * Angelos D. Keromytis (kermit@csd.uch.gr),
6  * Niels Provos (provos@physnet.uni-hamburg.de) and
7  * Niklas Hallqvist (niklas@appli.se).
8  *
9  * The original version of this code was written by John Ioannidis
10  * for BSD/OS in Athens, Greece, in November 1995.
11  *
12  * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
13  * by Angelos D. Keromytis.
14  *
15  * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
16  * and Niels Provos.
17  *
18  * Additional features in 1999 by Angelos D. Keromytis and Niklas Hallqvist.
19  *
20  * Copyright (c) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
21  * Angelos D. Keromytis and Niels Provos.
22  * Copyright (c) 1999 Niklas Hallqvist.
23  * Copyright (c) 2001, Angelos D. Keromytis.
24  *
25  * Permission to use, copy, and modify this software with or without fee
26  * is hereby granted, provided that this entire notice is included in
27  * all copies of any software which is or includes a copy or
28  * modification of this software.
29  * You may use this code under the GNU public license if you so wish. Please
30  * contribute changes back to the authors under this freer than GPL license
31  * so that we may further the use of strong encryption without limitations to
32  * all.
33  *
34  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
35  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
36  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
37  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
38  * PURPOSE.
39  */
40 
41 #ifndef _NETIPSEC_XFORM_H_
42 #define _NETIPSEC_XFORM_H_
43 
44 #include <sys/types.h>
45 #include <sys/queue.h>
46 #include <netinet/in.h>
47 #include <opencrypto/xform.h>
48 
49 #define	AH_HMAC_HASHLEN		12	/* 96 bits of authenticator */
50 #define	AH_HMAC_MAXHASHLEN	(SHA2_512_HASH_LEN/2)	/* Keep this updated */
51 #define	AH_HMAC_INITIAL_RPL	1	/* replay counter initial value */
52 
53 #ifdef _KERNEL
54 struct secpolicy;
55 struct secasvar;
56 
57 /*
58  * Packet tag assigned on completion of IPsec processing; used
59  * to speedup security policy checking for INBOUND packets.
60  */
61 struct xform_history {
62 	union sockaddr_union	dst;		/* destination address */
63 	uint32_t		spi;		/* Security Parameters Index */
64 	uint8_t			proto;		/* IPPROTO_ESP or IPPROTO_AH */
65 	uint8_t			mode;		/* transport or tunnel */
66 };
67 
68 /*
69  * Opaque data structure hung off a crypto operation descriptor.
70  */
71 struct xform_data {
72 	struct secpolicy	*sp;		/* security policy */
73 	struct secasvar		*sav;		/* related SA */
74 	crypto_session_t	cryptoid;	/* used crypto session */
75 	u_int			idx;		/* IPsec request index */
76 	int			protoff;	/* current protocol offset */
77 	int			skip;		/* data offset */
78 	uint8_t			nxt;		/* next protocol, e.g. IPV4 */
79 	struct vnet		*vnet;
80 };
81 
82 #define	XF_IP4		1	/* unused */
83 #define	XF_AH		2	/* AH */
84 #define	XF_ESP		3	/* ESP */
85 #define	XF_TCPSIGNATURE	5	/* TCP MD5 Signature option, RFC 2358 */
86 #define	XF_IPCOMP	6	/* IPCOMP */
87 
88 struct xformsw {
89 	u_short			xf_type;	/* xform ID */
90 	const char		*xf_name;	/* human-readable name */
91 	int	(*xf_init)(struct secasvar*, struct xformsw*);	/* setup */
92 	void	(*xf_cleanup)(struct secasvar*);		/* cleanup */
93 	int	(*xf_input)(struct mbuf*, struct secasvar*,	/* input */
94 			int, int);
95 	int	(*xf_output)(struct mbuf*,			/* output */
96 	    struct secpolicy *, struct secasvar *, u_int, int, int);
97 
98 	volatile u_int		xf_cntr;
99 	LIST_ENTRY(xformsw)	chain;
100 };
101 
102 const struct enc_xform * enc_algorithm_lookup(int);
103 const struct auth_hash * auth_algorithm_lookup(int);
104 const struct comp_algo * comp_algorithm_lookup(int);
105 
106 void xform_attach(void *);
107 void xform_detach(void *);
108 int xform_init(struct secasvar *, u_short);
109 
110 struct crypto_session_params;
111 /* XF_AH */
112 int xform_ah_authsize(const struct auth_hash *);
113 int ah_init0(struct secasvar *, struct xformsw *,
114     struct crypto_session_params *);
115 extern size_t ah_hdrsiz(struct secasvar *);
116 
117 /* XF_ESP */
118 extern size_t esp_hdrsiz(struct secasvar *sav);
119 
120 #endif /* _KERNEL */
121 #endif /* _NETIPSEC_XFORM_H_ */
122