xref: /netbsd-src/sys/dev/cgdvar.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /* $NetBSD: cgdvar.h,v 1.17 2014/03/18 15:44:37 skrll Exp $ */
2 
3 /*-
4  * Copyright (c) 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Roland C. Dowdeswell.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _DEV_CGDVAR_H_
33 #define	_DEV_CGDVAR_H_
34 
35 /* ioctl(2) code: used by CGDIOCSET and CGDIOCCLR */
36 struct cgd_ioctl {
37 	const char	*ci_disk;
38 	int		 ci_flags;
39 	int		 ci_unit;
40 	size_t		 ci_size;
41 	const char	*ci_alg;
42 	const char	*ci_ivmethod;
43 	size_t		 ci_keylen;
44 	const char	*ci_key;
45 	size_t		 ci_blocksize;
46 };
47 
48 /* ioctl(2) code: used by CGDIOCGET */
49 struct cgd_user {
50 	int		cgu_unit;	/* which cgd unit */
51 	dev_t		cgu_dev;	/* target device */
52 	char		cgu_alg[32];	/* algorithm name */
53 	size_t		cgu_blocksize;	/* block size (in bytes) */
54 	int		cgu_mode;	/* Cipher Mode and IV Gen method */
55 #define CGD_CIPHER_CBC_ENCBLKNO8 1	/* CBC Mode w/ Enc Block Number
56 					 * 8 passes (compat only)
57 					 */
58 #define CGD_CIPHER_CBC_ENCBLKNO1 2	/* CBC Mode w/ Enc Block Number
59 					 * 1 pass (default)
60 					 */
61 	int		cgu_keylen;	/* keylength */
62 };
63 
64 #ifdef _KERNEL
65 
66 #include <dev/cgd_crypto.h>
67 
68 /* This cryptdata structure is here rather than cgd_crypto.h, since
69  * it stores local state which will not be generalised beyond the
70  * cgd driver.
71  */
72 
73 struct cryptdata {
74 	size_t		 cf_blocksize;	/* block size (in bytes) */
75 	int		 cf_keylen;	/* key length */
76 	int		 cf_mode;	/* Cipher Mode and IV Gen method
77 					 * (see cgu_mode above for defines) */
78 	void		*cf_priv;	/* enc alg private data */
79 };
80 
81 struct cgd_softc {
82 	struct dk_softc		 sc_dksc;	/* generic disk interface */
83 	struct vnode		*sc_tvn;	/* target device's vnode */
84 	dev_t			 sc_tdev;	/* target device */
85 	char			*sc_tpath;	/* target device's path */
86 	void *			 sc_data;	/* emergency buffer */
87 	int			 sc_data_used;	/* Really lame, we'll change */
88 	size_t			 sc_tpathlen;	/* length of prior string */
89 	struct cryptdata	 sc_cdata;	/* crypto data */
90 	const struct cryptfuncs	*sc_cfuncs;	/* encryption functions */
91 	kmutex_t		 sc_lock;	/* our lock */
92 };
93 #endif
94 
95 /* XXX XAX XXX elric:  check these out properly. */
96 #define CGDIOCSET	_IOWR('F', 18, struct cgd_ioctl)
97 #define CGDIOCCLR	_IOW('F', 19, struct cgd_ioctl)
98 #define CGDIOCGET	_IOWR('F', 20, struct cgd_user)
99 
100 /* Maximum block sized to be used by the ciphers */
101 #define CGD_MAXBLOCKSIZE	128
102 
103 #endif /* _DEV_CGDVAR_H_ */
104