1 .\" $NetBSD: crypto.4,v 1.24 2014/01/27 21:23:59 pgoyette Exp $
3 .\" Copyright (c) 2008 The NetBSD Foundation, Inc.
4 .\" Copyright (c) 2014 The FreeBSD Foundation
5 .\" All rights reserved.
7 .\" Portions of this documentation were written by John-Mark Gurney
8 .\" under sponsorship of the FreeBSD Foundation and
9 .\" Rubicon Communications, LLC (Netgate).
11 .\" This code is derived from software contributed to The NetBSD Foundation
12 .\" by Coyote Point Systems, Inc.
14 .\" Redistribution and use in source and binary forms, with or without
15 .\" modification, are permitted provided that the following conditions
17 .\" 1. Redistributions of source code must retain the above copyright
18 .\" notice, this list of conditions and the following disclaimer.
19 .\" 2. Redistributions in binary form must reproduce the above copyright
20 .\" notice, this list of conditions and the following disclaimer in the
21 .\" documentation and/or other materials provided with the distribution.
23 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
24 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
27 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 .\" POSSIBILITY OF SUCH DAMAGE.
37 .\" Copyright (c) 2004
38 .\" Jonathan Stone <jonathan@dsg.stanford.edu>. All rights reserved.
40 .\" Redistribution and use in source and binary forms, with or without
41 .\" modification, are permitted provided that the following conditions
43 .\" 1. Redistributions of source code must retain the above copyright
44 .\" notice, this list of conditions and the following disclaimer.
45 .\" 2. Redistributions in binary form must reproduce the above copyright
46 .\" notice, this list of conditions and the following disclaimer in the
47 .\" documentation and/or other materials provided with the distribution.
49 .\" THIS SOFTWARE IS PROVIDED BY Jonathan Stone AND CONTRIBUTORS ``AS IS'' AND
50 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 .\" ARE DISCLAIMED. IN NO EVENT SHALL Jonathan Stone OR THE VOICES IN HIS HEAD
53 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
54 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
55 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
56 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
57 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
58 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
59 .\" THE POSSIBILITY OF SUCH DAMAGE.
69 .Nd user-mode access to hardware-accelerated cryptography
76 .In crypto/cryptodev.h
80 driver gives user-mode applications access to hardware-accelerated
81 cryptographic transforms as implemented by the
87 special device provides an
90 User-mode applications open the special device and
93 calls on the descriptor.
99 .Ic kern.userasymcrypto
101 .Ic kern.cryptodevallowsoft .
105 device provides two distinct modes of operation: one mode for
106 symmetric-keyed cryptographic requests and digests, and a second mode for
107 both asymmetric-key (public-key/private-key) requests and
108 modular arithmetic (for Diffie-Hellman key exchange and other
109 cryptographic protocols).
110 The two modes are described separately below.
111 .Sh DEPRECATION NOTICE
112 The asymmetric-key operations supported by this interface will not be
116 .Sh THEORY OF OPERATION
117 Regardless of whether symmetric-key or asymmetric-key operations are
118 to be performed, use of the device requires a basic series of steps:
125 If any symmetric-keyed cryptographic or digest operations will be performed,
126 create a session with
130 Most applications will require at least one symmetric session.
131 Since cipher and MAC keys are tied to sessions, many
132 applications will require more.
133 Asymmetric operations do not use sessions.
135 Submit requests, synchronously with
144 Optionally destroy a session with
150 This will automatically close any remaining sessions associated with the
153 .Sh SYMMETRIC-KEY OPERATION
154 The symmetric-key operation mode provides a context-based API
155 to traditional symmetric-key encryption (or privacy) algorithms,
156 or to keyed and unkeyed one-way hash (HMAC and MAC) algorithms.
157 The symmetric-key mode also permits encrypt-then-authenticate fused operation,
158 where the hardware performs both a privacy algorithm and an integrity-check
159 algorithm in a single pass over the data: either a fused
160 encrypt/HMAC-generate operation, or a fused HMAC-verify/decrypt operation.
162 To use symmetric mode, you must first create a session specifying
163 the algorithm(s) and key(s) to use; then issue encrypt or decrypt
164 requests against the session.
166 For a list of supported algorithms, see
170 .Ss IOCTL Request Descriptions
172 .Bl -tag -width CIOCGSESSION
174 .It Dv CIOCFINDDEV Fa struct crypt_find_op *fop
176 struct crypt_find_op {
177 int crid; /* driver id + flags */
178 char name[32]; /* device/driver name */
184 is -1, then find the driver named
190 is not -1, return the name of the driver with
194 In either case, if the driver is not found,
197 .It Dv CIOCGSESSION Fa struct session_op *sessp
200 uint32_t cipher; /* e.g. CRYPTO_AES_CBC */
201 uint32_t mac; /* e.g. CRYPTO_SHA2_256_HMAC */
203 uint32_t keylen; /* cipher key */
205 int mackeylen; /* mac key */
208 uint32_t ses; /* returns: ses # */
212 Create a new cryptographic session on a file descriptor for the device;
213 that is, a persistent object specific to the chosen
214 privacy algorithm, integrity algorithm, and keys specified in
216 The special value 0 for either privacy or integrity
217 is reserved to indicate that the indicated operation (privacy or integrity)
218 is not desired for this session.
220 Multiple sessions may be bound to a single file descriptor.
221 The session ID returned in
223 is supplied as a required field in the symmetric-operation structure
225 for future encryption or hashing requests.
227 .\" This implementation will never return a session ID of 0 for a successful
228 .\" creation of a session, which is a
232 For non-zero symmetric-key privacy algorithms, the privacy algorithm
234 .Fa sessp-\*[Gt]cipher ,
236 .Fa sessp-\*[Gt]keylen ,
237 and the key value in the octets addressed by
238 .Fa sessp-\*[Gt]key .
240 For keyed one-way hash algorithms, the one-way hash must be specified
242 .Fa sessp-\*[Gt]mac ,
244 .Fa sessp-\*[Gt]mackey ,
245 and the key value in the octets addressed by
246 .Fa sessp-\*[Gt]mackeylen .
249 Support for a specific combination of fused privacy and
250 integrity-check algorithms depends on whether the underlying
251 hardware supports that combination.
252 Not all combinations are supported
253 by all hardware, even if the hardware supports each operation as a
254 stand-alone non-fused operation.
255 .It Dv CIOCGSESSION2 Fa struct session2_op *sessp
258 uint32_t cipher; /* e.g. CRYPTO_AES_CBC */
259 uint32_t mac; /* e.g. CRYPTO_SHA2_256_HMAC */
261 uint32_t keylen; /* cipher key */
263 int mackeylen; /* mac key */
266 uint32_t ses; /* returns: ses # */
267 int crid; /* driver id + flags (rw) */
268 int pad[4]; /* for future expansion */
272 This request is similar to CIOGSESSION except that
274 requests either a specific crypto device or a class of devices (software vs
278 field must be initialized to zero.
279 .It Dv CIOCCRYPT Fa struct crypt_op *cr_op
283 uint16_t op; /* e.g. COP_ENCRYPT */
288 void *mac; /* must be large enough for result */
293 Request a symmetric-key (or hash) operation.
304 supplies the length of the input buffer; the fields
305 .Fa cr_op-\*[Gt]src ,
306 .Fa cr_op-\*[Gt]dst ,
307 .Fa cr_op-\*[Gt]mac ,
309 supply the addresses of the input buffer, output buffer,
310 one-way hash, and initialization vector, respectively.
312 If a session is using either fused encrypt-then-authenticate or
314 decryption operations require the associated hash as an input.
315 If the hash is incorrect, the
316 operation will fail with
318 and the output buffer will remain unchanged.
319 .It Dv CIOCCRYPTAEAD Fa struct crypt_aead *cr_aead
323 uint16_t op; /* e.g. COP_ENCRYPT */
330 const void *aad; /* additional authenticated data */
331 void *tag; /* must fit for chosen TAG length */
340 but provides additional data in
341 .Fa cr_aead-\*[Gt]aad
342 to include in the authentication mode.
343 .It Dv CIOCFSESSION Fa u_int32_t ses_id
344 Destroys the session identified by
348 .Sh ASYMMETRIC-KEY OPERATION
349 .Ss Asymmetric-key algorithms
350 Contingent upon hardware support, the following asymmetric
351 (public-key/private-key; or key-exchange subroutine) operations may
354 .Bl -column "CRK_DH_COMPUTE_KEY" "Input parameter" "Output parameter" -offset indent -compact
355 .It Em "Algorithm" Ta "Input parameter" Ta "Output parameter"
356 .It Em " " Ta "Count" Ta "Count"
357 .It Dv CRK_MOD_EXP Ta 3 Ta 1
358 .It Dv CRK_MOD_EXP_CRT Ta 6 Ta 1
359 .It Dv CRK_DSA_SIGN Ta 5 Ta 2
360 .It Dv CRK_DSA_VERIFY Ta 7 Ta 0
361 .It Dv CRK_DH_COMPUTE_KEY Ta 3 Ta 1
364 See below for discussion of the input and output parameter counts.
365 .Ss Asymmetric-key commands
366 .Bl -tag -width CIOCKEY
367 .It Dv CIOCASYMFEAT Fa int *feature_mask
368 Returns a bitmask of supported asymmetric-key operations.
369 Each of the above-listed asymmetric operations is present
370 if and only if the bit position numbered by the code for that operation
374 is available if and only if the bit
375 .Pq 1 \*[Lt]\*[Lt] Dv CRK_MOD_EXP
377 .It Dv CIOCKEY Fa struct crypt_kop *kop
380 u_int crk_op; /* e.g. CRK_MOD_EXP */
381 u_int crk_status; /* return status */
382 u_short crk_iparams; /* # of input params */
383 u_short crk_oparams; /* # of output params */
385 struct crparam crk_param[CRK_MAXPARAM];
388 /* Bignum parameter, in packed bytes. */
395 Performs an asymmetric-key operation from the list above.
396 The specific operation is supplied in
397 .Fa kop-\*[Gt]crk_op ;
398 final status for the operation is returned in
399 .Fa kop-\*[Gt]crk_status .
400 The number of input arguments and the number of output arguments
402 .Fa kop-\*[Gt]crk_iparams
404 .Fa kop-\*[Gt]crk_iparams ,
408 must be filled in with exactly
409 .Fa kop-\*[Gt]crk_iparams + kop-\*[Gt]crk_oparams
410 arguments, each encoded as a
412 (address, bitlength) pair.
414 The semantics of these arguments are currently undocumented.
428 driver first appeared in
432 driver was imported to
435 Error checking and reporting is weak.
437 The values specified for symmetric-key key sizes to
439 must exactly match the values expected by
441 The output buffer and MAC buffers supplied to
443 must follow whether privacy or integrity algorithms were specified for
444 session: if you request a
446 algorithm, you must supply a suitably-sized buffer.
448 The scheme for passing arguments for asymmetric requests is baroque.