| 1 | /* $NetBSD: ocryptodev.h,v 1.3 2015/09/06 06:01:02 dholland Exp $ */ |
| 2 | /* $FreeBSD: src/sys/opencrypto/cryptodev.h,v 1.2.2.6 2003/07/02 17:04:50 sam Exp $ */ |
| 3 | /* $OpenBSD: cryptodev.h,v 1.33 2002/07/17 23:52:39 art Exp $ */ |
| 4 | |
| 5 | /*- |
| 6 | * Copyright (c) 2008 The NetBSD Foundation, Inc. |
| 7 | * All rights reserved. |
| 8 | * |
| 9 | * This code is derived from software contributed to The NetBSD Foundation |
| 10 | * by Coyote Point Systems, Inc. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions and the following disclaimer. |
| 17 | * 2. Redistributions in binary form must reproduce the above copyright |
| 18 | * notice, this list of conditions and the following disclaimer in the |
| 19 | * documentation and/or other materials provided with the distribution. |
| 20 | * |
| 21 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
| 22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
| 23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 24 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 31 | * POSSIBILITY OF SUCH DAMAGE. |
| 32 | */ |
| 33 | |
| 34 | /* |
| 35 | * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) |
| 36 | * |
| 37 | * This code was written by Angelos D. Keromytis in Athens, Greece, in |
| 38 | * February 2000. Network Security Technologies Inc. (NSTI) kindly |
| 39 | * supported the development of this code. |
| 40 | * |
| 41 | * Copyright (c) 2000 Angelos D. Keromytis |
| 42 | * |
| 43 | * Permission to use, copy, and modify this software with or without fee |
| 44 | * is hereby granted, provided that this entire notice is included in |
| 45 | * all source code copies of any software which is or includes a copy or |
| 46 | * modification of this software. |
| 47 | * |
| 48 | * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR |
| 49 | * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY |
| 50 | * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE |
| 51 | * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR |
| 52 | * PURPOSE. |
| 53 | * |
| 54 | * Copyright (c) 2001 Theo de Raadt |
| 55 | * |
| 56 | * Redistribution and use in source and binary forms, with or without |
| 57 | * modification, are permitted provided that the following conditions |
| 58 | * are met: |
| 59 | * |
| 60 | * 1. Redistributions of source code must retain the above copyright |
| 61 | * notice, this list of conditions and the following disclaimer. |
| 62 | * 2. Redistributions in binary form must reproduce the above copyright |
| 63 | * notice, this list of conditions and the following disclaimer in the |
| 64 | * documentation and/or other materials provided with the distribution. |
| 65 | * 3. The name of the author may not be used to endorse or promote products |
| 66 | * derived from this software without specific prior written permission. |
| 67 | * |
| 68 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 69 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 70 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 71 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 72 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 73 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 74 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 75 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 76 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 77 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 78 | * |
| 79 | * Effort sponsored in part by the Defense Advanced Research Projects |
| 80 | * Agency (DARPA) and Air Force Research Laboratory, Air Force |
| 81 | * Materiel Command, USAF, under agreement number F30602-01-2-0537. |
| 82 | * |
| 83 | */ |
| 84 | |
| 85 | #ifndef _CRYPTO_OCRYPTODEV_H_ |
| 86 | #define _CRYPTO_OCRYPTODEV_H_ |
| 87 | |
| 88 | #include <sys/ioccom.h> |
| 89 | |
| 90 | struct osession_op { /* backwards compatible */ |
| 91 | u_int32_t cipher; /* ie. CRYPTO_DES_CBC */ |
| 92 | u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */ |
| 93 | u_int32_t keylen; /* cipher key */ |
| 94 | void * key; |
| 95 | int mackeylen; /* mac key */ |
| 96 | void * mackey; |
| 97 | |
| 98 | u_int32_t ses; /* returns: session # */ |
| 99 | }; |
| 100 | |
| 101 | struct osession_n_op { |
| 102 | u_int32_t cipher; /* ie. CRYPTO_DES_CBC */ |
| 103 | u_int32_t mac; /* ie. CRYPTO_MD5_HMAC */ |
| 104 | |
| 105 | u_int32_t keylen; /* cipher key */ |
| 106 | void * key; |
| 107 | int mackeylen; /* mac key */ |
| 108 | void * mackey; |
| 109 | |
| 110 | u_int32_t ses; /* returns: session # */ |
| 111 | int status; |
| 112 | }; |
| 113 | |
| 114 | struct ocrypt_op { |
| 115 | u_int32_t ses; |
| 116 | u_int16_t op; /* i.e. COP_ENCRYPT */ |
| 117 | u_int16_t flags; |
| 118 | u_int len; |
| 119 | void * src, *dst; /* become iov[] inside kernel */ |
| 120 | void * mac; /* must be big enough for chosen MAC */ |
| 121 | void * iv; |
| 122 | }; |
| 123 | |
| 124 | /* to support multiple session creation */ |
| 125 | /* |
| 126 | * |
| 127 | * The reqid field is filled when the operation has |
| 128 | * been accepted and started, and can be used to later retrieve |
| 129 | * the operation results via CIOCNCRYPTRET or identify the |
| 130 | * request in the completion list returned by CIOCNCRYPTRETM. |
| 131 | * |
| 132 | * The opaque pointer can be set arbitrarily by the user |
| 133 | * and it is passed back in the crypt_result structure |
| 134 | * when the request completes. This field can be used for example |
| 135 | * to track context for the request and avoid lookups in the |
| 136 | * user application. |
| 137 | */ |
| 138 | |
| 139 | struct ocrypt_n_op { |
| 140 | u_int32_t ses; |
| 141 | u_int16_t op; /* i.e. COP_ENCRYPT */ |
| 142 | u_int16_t flags; |
| 143 | u_int len; /* src & dst len */ |
| 144 | |
| 145 | u_int32_t reqid; /* request id */ |
| 146 | int status; /* status of request -accepted or not */ |
| 147 | void *opaque; /* opaque pointer returned to user */ |
| 148 | u_int32_t keylen; /* cipher key - optional */ |
| 149 | void * key; |
| 150 | u_int32_t mackeylen; /* also optional */ |
| 151 | void * mackey; |
| 152 | |
| 153 | void * src, *dst; /* become iov[] inside kernel */ |
| 154 | void * mac; /* must be big enough for chosen MAC */ |
| 155 | void * iv; |
| 156 | }; |
| 157 | |
| 158 | struct ocrypt_sgop { |
| 159 | size_t count; |
| 160 | struct osession_n_op * sessions; |
| 161 | }; |
| 162 | |
| 163 | struct ocrypt_mop { |
| 164 | size_t count; /* how many */ |
| 165 | struct ocrypt_n_op * reqs; /* where to get them */ |
| 166 | }; |
| 167 | |
| 168 | #define OCIOCGSESSION _IOWR('c', 101, struct osession_op) |
| 169 | #define OCIOCNGSESSION _IOWR('c', 106, struct ocrypt_sgop) |
| 170 | #define OCIOCCRYPT _IOWR('c', 103, struct ocrypt_op) |
| 171 | #define OCIOCNCRYPTM _IOWR('c', 107, struct ocrypt_mop) |
| 172 | |
| 173 | int ocryptof_ioctl(struct file *, u_long, void *); |
| 174 | |
| 175 | #endif /* _CRYPTO_OCRYPTODEV_H_ */ |
| 176 | |