xref: /netbsd-src/sys/netipsec/xform.h (revision c38e7cc395b1472a774ff828e46123de44c628e9)
1 /*	$NetBSD: xform.h,v 1.16 2018/05/01 08:08:46 maxv Exp $	*/
2 /*	$FreeBSD: xform.h,v 1.1.4.1 2003/01/24 05:11:36 sam Exp $	*/
3 /*	$OpenBSD: ip_ipsp.h,v 1.119 2002/03/14 01:27:11 millert Exp $	*/
4 /*
5  * The authors of this code are John Ioannidis (ji@tla.org),
6  * Angelos D. Keromytis (kermit@csd.uch.gr),
7  * Niels Provos (provos@physnet.uni-hamburg.de) and
8  * Niklas Hallqvist (niklas@appli.se).
9  *
10  * The original version of this code was written by John Ioannidis
11  * for BSD/OS in Athens, Greece, in November 1995.
12  *
13  * Ported to OpenBSD and NetBSD, with additional transforms, in December 1996,
14  * by Angelos D. Keromytis.
15  *
16  * Additional transforms and features in 1997 and 1998 by Angelos D. Keromytis
17  * and Niels Provos.
18  *
19  * Additional features in 1999 by Angelos D. Keromytis and Niklas Hallqvist.
20  *
21  * Copyright (c) 1995, 1996, 1997, 1998, 1999 by John Ioannidis,
22  * Angelos D. Keromytis and Niels Provos.
23  * Copyright (c) 1999 Niklas Hallqvist.
24  * Copyright (c) 2001, Angelos D. Keromytis.
25  *
26  * Permission to use, copy, and modify this software with or without fee
27  * is hereby granted, provided that this entire notice is included in
28  * all copies of any software which is or includes a copy or
29  * modification of this software.
30  * You may use this code under the GNU public license if you so wish. Please
31  * contribute changes back to the authors under this freer than GPL license
32  * so that we may further the use of strong encryption without limitations to
33  * all.
34  *
35  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
36  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
37  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
38  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
39  * PURPOSE.
40  */
41 
42 #ifndef _NETIPSEC_XFORM_H_
43 #define _NETIPSEC_XFORM_H_
44 
45 #include <sys/types.h>
46 #include <netinet/in.h>
47 #include <opencrypto/xform.h>
48 
49 /*
50  * Opaque data structure hung off a crypto operation descriptor.
51  */
52 struct secasvar;
53 struct tdb_crypto {
54 	const struct ipsecrequest *tc_isr;	/* ipsec request state */
55 	u_int32_t		tc_spi;		/* associated SPI */
56 	union sockaddr_union	tc_dst;		/* dst addr of packet */
57 	u_int8_t		tc_proto;	/* current protocol, e.g. AH */
58 	u_int8_t		tc_nxt;		/* next protocol, e.g. IPV4 */
59 	int			tc_protoff;	/* current protocol offset */
60 	int			tc_skip;	/* data offset */
61 	struct secasvar		*tc_sav;	/* ipsec SA */
62 };
63 
64 struct ipescrequest;
65 
66 struct xformsw {
67 	u_short	xf_type;		/* xform ID */
68 #define	XF_IP4		1	/* IP inside IP */
69 #define	XF_AH		2	/* AH */
70 #define	XF_ESP		3	/* ESP */
71 #define	XF_TCPSIGNATURE	5	/* TCP MD5 Signature option, RFC 2358 */
72 #define	XF_IPCOMP	6	/* IPCOMP */
73 	u_short	xf_flags;
74 #define	XFT_AUTH	0x0001
75 #define	XFT_CONF	0x0100
76 #define	XFT_COMP	0x1000
77 	const char	*xf_name;		/* human-readable name */
78 	int	(*xf_init)(struct secasvar*, const struct xformsw*);/* setup */
79 	int	(*xf_zeroize)(struct secasvar*);		/* cleanup */
80 	int	(*xf_input)(struct mbuf*, struct secasvar*, /* input */
81 			int, int);
82 	int	(*xf_output)(struct mbuf*,	       		/* output */
83 			const struct ipsecrequest *, struct secasvar *,
84 			struct mbuf **, int, int);
85 	struct xformsw *xf_next;		/* list of registered xforms */
86 };
87 
88 #ifdef _KERNEL
89 extern void xform_register(struct xformsw*);
90 extern int xform_init(struct secasvar *sav, int xftype);
91 
92 struct cryptoini;
93 
94 /* XF_IP4 */
95 int ip4_input6(struct mbuf **m, int *offp, int proto, void *);
96 void ip4_input(struct mbuf *m, int, int, void *);
97 int ipip_output(struct mbuf *, const struct ipsecrequest *, struct secasvar *,
98     struct mbuf **, int, int);
99 
100 /* XF_AH */
101 int ah_init0(struct secasvar *, const struct xformsw *, struct cryptoini *);
102 int ah_zeroize(struct secasvar *sav);
103 const struct auth_hash *ah_algorithm_lookup(int alg);
104 size_t ah_hdrsiz(const struct secasvar *);
105 
106 /* XF_ESP */
107 const struct enc_xform *esp_algorithm_lookup(int alg);
108 size_t esp_hdrsiz(const struct secasvar *sav);
109 
110 /* XF_COMP */
111 const struct comp_algo *ipcomp_algorithm_lookup(int alg);
112 
113 #endif /* _KERNEL */
114 #endif /* !_NETIPSEC_XFORM_H_ */
115