78
78
The
79
79
.Nm
80
80
driver gives user-mode applications access to hardware-accelerated
81
- cryptographic transforms, as implemented by the
81
+ cryptographic transforms as implemented by the
82
82
.Xr crypto 9
83
83
in-kernel interface.
84
84
.Pp
87
87
special device provides an
88
88
.Xr ioctl 2
89
89
based interface.
90
- User-mode applications should open the special device,
90
+ User-mode applications open the special device and
91
91
then issue
92
92
.Xr ioctl 2
93
93
calls on the descriptor.
94
94
User-mode access to
95
95
.Pa /dev/crypto
96
- is controlled by three
96
+ is controlled by two
97
97
.Xr sysctl 8
98
- variables,
98
+ variables:
99
99
.Ic kern.userasymcrypto
100
100
and
101
101
.Ic kern.cryptodevallowsoft .
102
102
.Pp
103
103
The
104
104
.Nm
105
105
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
108
108
modular arithmetic (for Diffie-Hellman key exchange and other
109
109
cryptographic protocols).
110
110
The two modes are described separately below.
@@ -113,12 +113,22 @@ Regardless of whether symmetric-key or asymmetric-key operations are
113
113
to be performed, use of the device requires a basic series of steps:
114
114
.Bl -enum
115
115
.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.
119
129
.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
122
132
.Dv CIOCGSESSION .
123
133
Most applications will require at least one symmetric session.
124
134
Since cipher and MAC keys are tied to sessions, many
134
144
.Dv CIOCKEY
135
145
(asymmetric).
136
146
.It
137
- Destroy one session with
147
+ Optionally destroy a session with
138
148
.Dv CIOCFSESSION .
139
149
.It
140
- Close the device with
150
+ Close the cryptography file descriptor with
141
151
.Xr close 2 .
152
+ This will automatically close any remaining sessions associated with the
153
+ file desriptor.
142
154
.El
143
155
.Sh SYMMETRIC-KEY OPERATION
144
156
The symmetric-key operation mode provides a context-based API
@@ -196,9 +208,9 @@ struct session_op {
196
208
u_int32_t mac; /* e.g. CRYPTO_MD5_HMAC */
197
209
198
210
u_int32_t keylen; /* cipher key */
199
- void * key;
211
+ const void *key;
200
212
int mackeylen; /* mac key */
201
- void * mackey;
213
+ const void *mackey;
202
214
203
215
u_int32_t ses; /* returns: ses # */
204
216
};
@@ -241,12 +253,36 @@ and the key value in the octets addressed by
241
253
.Fa sessp- \*[ Gt ]mackeylen .
242
254
.\"
243
255
.Pp
244
- Support for a specific combination of fused privacy and
256
+ Support for a specific combination of fused privacy and
245
257
integrity-check algorithms depends on whether the underlying
246
258
hardware supports that combination.
247
259
Not all combinations are supported
248
260
by all hardware, even if the hardware supports each operation as a
249
261
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.
250
286
.It Dv CIOCCRYPT Fa struct crypt_op *cr_op
251
287
.Bd -literal
252
288
struct crypt_op {
@@ -261,9 +297,6 @@ struct crypt_op {
261
297
262
298
.Ed
263
299
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.
267
300
To encrypt, set
268
301
.Fa cr_op- \*[ Gt ]op
269
302
to
@@ -315,21 +348,8 @@ but provides additional data in
315
348
.Fa cr_aead- \*[ Gt ]aad
316
349
to include in the authentication mode.
317
350
.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 .
333
353
.El
334
354
.\"
335
355
.Sh ASYMMETRIC-KEY OPERATION
@@ -435,8 +455,10 @@ algorithm, you must supply a suitably-sized buffer.
435
455
.Pp
436
456
The scheme for passing arguments for asymmetric requests is baroque.
437
457
.Pp
438
- The naming inconsistency between
439
458
.Dv CRIOGET
440
- and the various
459
+ should not exist.
460
+ It should be possible to use the
441
461
.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