Skip to content

Commit 4701f12

Browse files
committed
Update the crypto(4) and crypto(9) manpages.
There are probably bits that are still wrong, but this fixes some things at least: - Add named arguments to the functions in crypto(9). - Add missing algorithms. - Don't mention arguments that don't exist in crypto_register. - Add CIOGSESSION2. - Remove CIOCNFSESSION. - Clarify some stale language that assumed an fd had only one sesson. - Note that you have to use CRIOGET and add a note in BUGS lamenting that one has to use CRIOGET. - Various other cleanups. Reviewed by: cem (earlier version) MFC after: 2 weeks Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D22784
1 parent c69026b commit 4701f12

File tree

2 files changed

+169
-123
lines changed

2 files changed

+169
-123
lines changed

share/man/man4/crypto.4

Lines changed: 59 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
The
7979
.Nm
8080
driver gives user-mode applications access to hardware-accelerated
81-
cryptographic transforms, as implemented by the
81+
cryptographic transforms as implemented by the
8282
.Xr crypto 9
8383
in-kernel interface.
8484
.Pp
@@ -87,24 +87,24 @@ The
8787
special device provides an
8888
.Xr ioctl 2
8989
based interface.
90-
User-mode applications should open the special device,
90+
User-mode applications open the special device and
9191
then issue
9292
.Xr ioctl 2
9393
calls on the descriptor.
9494
User-mode access to
9595
.Pa /dev/crypto
96-
is controlled by three
96+
is controlled by two
9797
.Xr sysctl 8
98-
variables,
98+
variables:
9999
.Ic kern.userasymcrypto
100100
and
101101
.Ic kern.cryptodevallowsoft .
102102
.Pp
103103
The
104104
.Nm
105105
device provides two distinct modes of operation: one mode for
106-
symmetric-keyed cryptographic requests, and a second mode for
107-
both asymmetric-key (public-key/private-key) requests, and for
106+
symmetric-keyed cryptographic requests and digests, and a second mode for
107+
both asymmetric-key (public-key/private-key) requests and
108108
modular arithmetic (for Diffie-Hellman key exchange and other
109109
cryptographic protocols).
110110
The two modes are described separately below.
@@ -113,12 +113,22 @@ Regardless of whether symmetric-key or asymmetric-key operations are
113113
to be performed, use of the device requires a basic series of steps:
114114
.Bl -enum
115115
.It
116-
Open a file descriptor for the device.
117-
See
118-
.Xr open 2 .
116+
Open the
117+
.Pa /dev/crypto
118+
device.
119+
.It
120+
Create a new cryptography file descriptor via
121+
.Dv CRIOGET
122+
to use for all subsequent
123+
.Xr ioctl 2
124+
commands.
125+
.It
126+
Close the
127+
.Pa /dev/crypto
128+
device.
119129
.It
120-
If any symmetric operation will be performed,
121-
create one session, with
130+
If any symmetric-keyed cryptographic or digest operations will be performed,
131+
create a session with
122132
.Dv CIOCGSESSION .
123133
Most applications will require at least one symmetric session.
124134
Since cipher and MAC keys are tied to sessions, many
@@ -134,11 +144,13 @@ or
134144
.Dv CIOCKEY
135145
(asymmetric).
136146
.It
137-
Destroy one session with
147+
Optionally destroy a session with
138148
.Dv CIOCFSESSION .
139149
.It
140-
Close the device with
150+
Close the cryptography file descriptor with
141151
.Xr close 2 .
152+
This will automatically close any remaining sessions associated with the
153+
file desriptor.
142154
.El
143155
.Sh SYMMETRIC-KEY OPERATION
144156
The symmetric-key operation mode provides a context-based API
@@ -196,9 +208,9 @@ struct session_op {
196208
u_int32_t mac; /* e.g. CRYPTO_MD5_HMAC */
197209

198210
u_int32_t keylen; /* cipher key */
199-
void * key;
211+
const void *key;
200212
int mackeylen; /* mac key */
201-
void * mackey;
213+
const void *mackey;
202214

203215
u_int32_t ses; /* returns: ses # */
204216
};
@@ -241,12 +253,36 @@ and the key value in the octets addressed by
241253
.Fa sessp-\*[Gt]mackeylen .
242254
.\"
243255
.Pp
244-
Support for a specific combination of fused privacy and
256+
Support for a specific combination of fused privacy and
245257
integrity-check algorithms depends on whether the underlying
246258
hardware supports that combination.
247259
Not all combinations are supported
248260
by all hardware, even if the hardware supports each operation as a
249261
stand-alone non-fused operation.
262+
.It Dv CIOCGSESSION2 Fa struct session2_op *sessp
263+
.Bd -literal
264+
struct session2_op {
265+
u_int32_t cipher; /* e.g. CRYPTO_DES_CBC */
266+
u_int32_t mac; /* e.g. CRYPTO_MD5_HMAC */
267+
268+
u_int32_t keylen; /* cipher key */
269+
const void *key;
270+
int mackeylen; /* mac key */
271+
const void *mackey;
272+
273+
u_int32_t ses; /* returns: ses # */
274+
int crid; /* driver id + flags (rw) */
275+
int pad[4]; /* for future expansion */
276+
};
277+
278+
.Ed
279+
This request is similar to CIOGSESSION except that
280+
.Fa sessp-\*[Gt]crid
281+
requests either a specific crypto device or a class of devices (software vs
282+
hardware).
283+
The
284+
.Fa sessp-\*[Gt]pad
285+
field must be initialized to zero.
250286
.It Dv CIOCCRYPT Fa struct crypt_op *cr_op
251287
.Bd -literal
252288
struct crypt_op {
@@ -261,9 +297,6 @@ struct crypt_op {
261297

262298
.Ed
263299
Request a symmetric-key (or hash) operation.
264-
The file descriptor argument to
265-
.Xr ioctl 2
266-
must have been bound to a valid session.
267300
To encrypt, set
268301
.Fa cr_op-\*[Gt]op
269302
to
@@ -315,21 +348,8 @@ but provides additional data in
315348
.Fa cr_aead-\*[Gt]aad
316349
to include in the authentication mode.
317350
.It Dv CIOCFSESSION Fa u_int32_t ses_id
318-
Destroys the /dev/crypto session associated with the file-descriptor
319-
argument.
320-
.It Dv CIOCNFSESSION Fa struct crypt_sfop *sfop ;
321-
.Bd -literal
322-
struct crypt_sfop {
323-
size_t count;
324-
u_int32_t *sesid;
325-
};
326-
327-
.Ed
328-
Destroys the
329-
.Fa sfop-\*[Gt]count
330-
sessions specified by the
331-
.Fa sfop
332-
array of session identifiers.
351+
Destroys the session identified by
352+
.Fa ses_id .
333353
.El
334354
.\"
335355
.Sh ASYMMETRIC-KEY OPERATION
@@ -435,8 +455,10 @@ algorithm, you must supply a suitably-sized buffer.
435455
.Pp
436456
The scheme for passing arguments for asymmetric requests is baroque.
437457
.Pp
438-
The naming inconsistency between
439458
.Dv CRIOGET
440-
and the various
459+
should not exist.
460+
It should be possible to use the
441461
.Dv CIOC Ns \&*
442-
names is an unfortunate historical artifact.
462+
commands directly on a
463+
.Pa /dev/crypto
464+
file descriptor.

0 commit comments

Comments
 (0)