xref: /netbsd-src/sys/opencrypto/ocryptodev.h (revision d91f98a8715141154279122ae81737cb65179572)
1*d91f98a8Spgoyette /*	$NetBSD: ocryptodev.h,v 1.4 2019/01/27 02:08:48 pgoyette Exp $ */
236ea3668Sdarran /*	$FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $	*/
336ea3668Sdarran /*	$OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $	*/
436ea3668Sdarran 
536ea3668Sdarran /*-
636ea3668Sdarran  * Copyright (c) 2008 The NetBSD Foundation, Inc.
736ea3668Sdarran  * All rights reserved.
836ea3668Sdarran  *
936ea3668Sdarran  * This code is derived from software contributed to The NetBSD Foundation
1036ea3668Sdarran  * by Coyote Point Systems, Inc.
1136ea3668Sdarran  *
1236ea3668Sdarran  * Redistribution and use in source and binary forms, with or without
1336ea3668Sdarran  * modification, are permitted provided that the following conditions
1436ea3668Sdarran  * are met:
1536ea3668Sdarran  * 1. Redistributions of source code must retain the above copyright
1636ea3668Sdarran  *    notice, this list of conditions and the following disclaimer.
1736ea3668Sdarran  * 2. Redistributions in binary form must reproduce the above copyright
1836ea3668Sdarran  *    notice, this list of conditions and the following disclaimer in the
1936ea3668Sdarran  *    documentation and/or other materials provided with the distribution.
2036ea3668Sdarran  *
2136ea3668Sdarran  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2236ea3668Sdarran  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2336ea3668Sdarran  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2436ea3668Sdarran  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2536ea3668Sdarran  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2636ea3668Sdarran  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2736ea3668Sdarran  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2836ea3668Sdarran  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2936ea3668Sdarran  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3036ea3668Sdarran  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3136ea3668Sdarran  * POSSIBILITY OF SUCH DAMAGE.
3236ea3668Sdarran  */
3336ea3668Sdarran 
3436ea3668Sdarran /*
3536ea3668Sdarran  * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
3636ea3668Sdarran  *
3736ea3668Sdarran  * This code was written by Angelos D. Keromytis in Athens, Greece, in
3836ea3668Sdarran  * February 2000. Network Security Technologies Inc. (NSTI) kindly
3936ea3668Sdarran  * supported the development of this code.
4036ea3668Sdarran  *
4136ea3668Sdarran  * Copyright (c) 2000 Angelos D. Keromytis
4236ea3668Sdarran  *
4336ea3668Sdarran  * Permission to use, copy, and modify this software with or without fee
4436ea3668Sdarran  * is hereby granted, provided that this entire notice is included in
4536ea3668Sdarran  * all source code copies of any software which is or includes a copy or
4636ea3668Sdarran  * modification of this software.
4736ea3668Sdarran  *
4836ea3668Sdarran  * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
4936ea3668Sdarran  * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
5036ea3668Sdarran  * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
5136ea3668Sdarran  * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
5236ea3668Sdarran  * PURPOSE.
5336ea3668Sdarran  *
5436ea3668Sdarran  * Copyright (c) 2001 Theo de Raadt
5536ea3668Sdarran  *
5636ea3668Sdarran  * Redistribution and use in source and binary forms, with or without
5736ea3668Sdarran  * modification, are permitted provided that the following conditions
5836ea3668Sdarran  * are met:
5936ea3668Sdarran  *
6036ea3668Sdarran  * 1. Redistributions of source code must retain the above copyright
6136ea3668Sdarran  *   notice, this list of conditions and the following disclaimer.
6236ea3668Sdarran  * 2. Redistributions in binary form must reproduce the above copyright
6336ea3668Sdarran  *   notice, this list of conditions and the following disclaimer in the
6436ea3668Sdarran  *   documentation and/or other materials provided with the distribution.
6536ea3668Sdarran  * 3. The name of the author may not be used to endorse or promote products
6636ea3668Sdarran  *   derived from this software without specific prior written permission.
6736ea3668Sdarran  *
6836ea3668Sdarran  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
6936ea3668Sdarran  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7036ea3668Sdarran  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
7136ea3668Sdarran  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
7236ea3668Sdarran  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
7336ea3668Sdarran  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
7436ea3668Sdarran  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
7536ea3668Sdarran  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
7636ea3668Sdarran  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
7736ea3668Sdarran  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
7836ea3668Sdarran  *
7936ea3668Sdarran  * Effort sponsored in part by the Defense Advanced Research Projects
8036ea3668Sdarran  * Agency (DARPA) and Air Force Research Laboratory, Air Force
8136ea3668Sdarran  * Materiel Command, USAF, under agreement number F30602-01-2-0537.
8236ea3668Sdarran  *
8336ea3668Sdarran  */
8436ea3668Sdarran 
8536ea3668Sdarran #ifndef _CRYPTO_OCRYPTODEV_H_
8636ea3668Sdarran #define _CRYPTO_OCRYPTODEV_H_
8736ea3668Sdarran 
881fbab01aSdholland #include <sys/ioccom.h>
891fbab01aSdholland 
9036ea3668Sdarran struct osession_op {	/* backwards compatible */
9136ea3668Sdarran 	u_int32_t	cipher;		/* ie. CRYPTO_DES_CBC */
9236ea3668Sdarran 	u_int32_t	mac;		/* ie. CRYPTO_MD5_HMAC */
9336ea3668Sdarran 	u_int32_t	keylen;		/* cipher key */
9436ea3668Sdarran 	void *		key;
9536ea3668Sdarran 	int		mackeylen;	/* mac key */
9636ea3668Sdarran 	void *		mackey;
9736ea3668Sdarran 
9836ea3668Sdarran   	u_int32_t	ses;		/* returns: session # */
9936ea3668Sdarran };
10036ea3668Sdarran 
10136ea3668Sdarran struct osession_n_op {
10236ea3668Sdarran 	u_int32_t	cipher;		/* ie. CRYPTO_DES_CBC */
10336ea3668Sdarran 	u_int32_t	mac;		/* ie. CRYPTO_MD5_HMAC */
10436ea3668Sdarran 
10536ea3668Sdarran 	u_int32_t	keylen;		/* cipher key */
10636ea3668Sdarran 	void *		key;
10736ea3668Sdarran 	int		mackeylen;	/* mac key */
10836ea3668Sdarran 	void *		mackey;
10936ea3668Sdarran 
11036ea3668Sdarran 	u_int32_t	ses;		/* returns: session # */
11136ea3668Sdarran 	int		status;
11236ea3668Sdarran };
11336ea3668Sdarran 
11436ea3668Sdarran struct ocrypt_op {
11536ea3668Sdarran 	u_int32_t	ses;
11636ea3668Sdarran 	u_int16_t	op;		/* i.e. COP_ENCRYPT */
11736ea3668Sdarran 	u_int16_t	flags;
11836ea3668Sdarran 	u_int		len;
11936ea3668Sdarran 	void *		src, *dst;	/* become iov[] inside kernel */
12036ea3668Sdarran 	void *		mac;		/* must be big enough for chosen MAC */
12136ea3668Sdarran 	void *		iv;
12236ea3668Sdarran };
12336ea3668Sdarran 
12436ea3668Sdarran /* to support multiple session creation */
12536ea3668Sdarran /*
12636ea3668Sdarran  *
12736ea3668Sdarran  * The reqid field is filled when the operation has
12836ea3668Sdarran  * been accepted and started, and can be used to later retrieve
12936ea3668Sdarran  * the operation results via CIOCNCRYPTRET or identify the
13036ea3668Sdarran  * request in the completion list returned by CIOCNCRYPTRETM.
13136ea3668Sdarran  *
13236ea3668Sdarran  * The opaque pointer can be set arbitrarily by the user
13336ea3668Sdarran  * and it is passed back in the crypt_result structure
13436ea3668Sdarran  * when the request completes.  This field can be used for example
13536ea3668Sdarran  * to track context for the request and avoid lookups in the
13636ea3668Sdarran  * user application.
13736ea3668Sdarran  */
13836ea3668Sdarran 
13936ea3668Sdarran struct ocrypt_n_op {
14036ea3668Sdarran 	u_int32_t	ses;
14136ea3668Sdarran 	u_int16_t	op;		/* i.e. COP_ENCRYPT */
14236ea3668Sdarran 	u_int16_t	flags;
14336ea3668Sdarran 	u_int		len;		/* src & dst len */
14436ea3668Sdarran 
14536ea3668Sdarran 	u_int32_t	reqid;		/* request id */
14636ea3668Sdarran 	int		status;		/* status of request -accepted or not */
14736ea3668Sdarran 	void		*opaque;	/* opaque pointer returned to user */
14836ea3668Sdarran 	u_int32_t	keylen;		/* cipher key - optional */
14936ea3668Sdarran 	void *		key;
15036ea3668Sdarran 	u_int32_t	mackeylen;	/* also optional */
15136ea3668Sdarran 	void *		mackey;
15236ea3668Sdarran 
15336ea3668Sdarran 	void *		src, *dst;	/* become iov[] inside kernel */
15436ea3668Sdarran 	void *		mac;		/* must be big enough for chosen MAC */
15536ea3668Sdarran 	void *		iv;
15636ea3668Sdarran };
15736ea3668Sdarran 
15836ea3668Sdarran struct ocrypt_sgop {
15936ea3668Sdarran 	size_t		count;
16036ea3668Sdarran 	struct osession_n_op * sessions;
16136ea3668Sdarran };
16236ea3668Sdarran 
16336ea3668Sdarran struct ocrypt_mop {
16436ea3668Sdarran 	size_t 		count;		/* how many */
16536ea3668Sdarran 	struct ocrypt_n_op *	reqs;	/* where to get them */
16636ea3668Sdarran };
16736ea3668Sdarran 
16836ea3668Sdarran #define	OCIOCGSESSION	_IOWR('c', 101, struct osession_op)
16936ea3668Sdarran #define	OCIOCNGSESSION	_IOWR('c', 106, struct ocrypt_sgop)
17036ea3668Sdarran #define OCIOCCRYPT	_IOWR('c', 103, struct ocrypt_op)
17136ea3668Sdarran #define OCIOCNCRYPTM	_IOWR('c', 107, struct ocrypt_mop)
17236ea3668Sdarran 
173*d91f98a8Spgoyette struct fcrypt;
174*d91f98a8Spgoyette struct session_op;
175*d91f98a8Spgoyette struct csession;
176*d91f98a8Spgoyette struct crypt_op;
177*d91f98a8Spgoyette struct crypt_n_op;
178*d91f98a8Spgoyette 
17936ea3668Sdarran int ocryptof_ioctl(struct file *, u_long, void *);
18036ea3668Sdarran 
18136ea3668Sdarran #endif /* _CRYPTO_OCRYPTODEV_H_ */
182