1 /* $OpenBSD: cryptosoft.c,v 1.35 2002/04/26 08:43:50 deraadt Exp $ */
4 * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu)
5 * Copyright (c) 2002-2006 Sam Leffler, Errno Consulting
7 * This code was written by Angelos D. Keromytis in Athens, Greece, in
8 * February 2000. Network Security Technologies Inc. (NSTI) kindly
9 * supported the development of this code.
11 * Copyright (c) 2000, 2001 Angelos D. Keromytis
12 * Copyright (c) 2014-2021 The FreeBSD Foundation
13 * All rights reserved.
15 * Portions of this software were developed by John-Mark Gurney
16 * under sponsorship of the FreeBSD Foundation and
17 * Rubicon Communications, LLC (Netgate).
19 * Portions of this software were developed by Ararat River
20 * Consulting, LLC under sponsorship of the FreeBSD Foundation.
22 * Permission to use, copy, and modify this software with or without fee
23 * is hereby granted, provided that this entire notice is included in
24 * all source code copies of any software which is or includes a copy or
25 * modification of this software.
27 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR
28 * IMPLIED WARRANTY. IN PARTICULAR, NONE OF THE AUTHORS MAKES ANY
29 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE
30 * MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/malloc.h>
41 #include <sys/module.h>
42 #include <sys/sysctl.h>
43 #include <sys/errno.h>
44 #include <sys/random.h>
45 #include <sys/kernel.h>
47 #include <sys/endian.h>
48 #include <sys/limits.h>
50 #include <crypto/sha1.h>
51 #include <opencrypto/rmd160.h>
53 #include <opencrypto/cryptodev.h>
54 #include <opencrypto/xform.h>
58 #include "cryptodev_if.h"
63 const struct auth_hash *sw_axf;
70 const struct enc_xform *sw_exf;
74 const struct comp_algo *sw_cxf;
78 int (*swcr_process)(const struct swcr_session *, struct cryptop *);
80 struct swcr_auth swcr_auth;
81 struct swcr_encdec swcr_encdec;
82 struct swcr_compdec swcr_compdec;
85 static int32_t swcr_id;
87 static void swcr_freesession(device_t dev, crypto_session_t cses);
89 /* Used for CRYPTO_NULL_CBC. */
91 swcr_null(const struct swcr_session *ses, struct cryptop *crp)
98 * Apply a symmetric encryption/decryption algorithm.
101 swcr_encdec(const struct swcr_session *ses, struct cryptop *crp)
103 unsigned char blk[EALG_MAX_BLOCK_LEN];
104 const struct crypto_session_params *csp;
105 const struct enc_xform *exf;
106 const struct swcr_encdec *sw;
108 size_t inlen, outlen, todo;
110 struct crypto_buffer_cursor cc_in, cc_out;
111 const unsigned char *inblk;
112 unsigned char *outblk;
118 sw = &ses->swcr_encdec;
120 csp = crypto_get_params(crp->crp_session);
122 if (exf->native_blocksize == 0) {
123 /* Check for non-padded data */
124 if ((crp->crp_payload_length % exf->blocksize) != 0)
127 blksz = exf->blocksize;
129 blksz = exf->native_blocksize;
131 if (exf == &enc_xform_aes_icm &&
132 (crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0)
135 ctx = __builtin_alloca(exf->ctxsize);
136 if (crp->crp_cipher_key != NULL) {
137 error = exf->setkey(ctx, crp->crp_cipher_key,
138 csp->csp_cipher_klen);
142 memcpy(ctx, sw->sw_ctx, exf->ctxsize);
144 crypto_read_iv(crp, blk);
145 exf->reinit(ctx, blk, csp->csp_ivlen);
147 crypto_cursor_init(&cc_in, &crp->crp_buf);
148 crypto_cursor_advance(&cc_in, crp->crp_payload_start);
149 if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
150 crypto_cursor_init(&cc_out, &crp->crp_obuf);
151 crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
155 encrypting = CRYPTO_OP_IS_ENCRYPT(crp->crp_op);
158 * Loop through encrypting blocks. 'inlen' is the remaining
159 * length of the current segment in the input buffer.
160 * 'outlen' is the remaining length of current segment in the
164 for (resid = crp->crp_payload_length; resid >= blksz; resid -= todo) {
166 inblk = crypto_cursor_segment(&cc_in, &inlen);
168 outblk = crypto_cursor_segment(&cc_out, &outlen);
171 * If the current block is not contained within the
172 * current input/output segment, use 'blk' as a local
176 crypto_cursor_copydata(&cc_in, blksz, blk);
180 if (outlen < blksz) {
185 todo = rounddown2(MIN(resid, MIN(inlen, outlen)), blksz);
188 exf->encrypt_multi(ctx, inblk, outblk, todo);
190 exf->decrypt_multi(ctx, inblk, outblk, todo);
193 inblk = crypto_cursor_segment(&cc_in, &inlen);
195 crypto_cursor_advance(&cc_in, todo);
201 crypto_cursor_copyback(&cc_out, blksz, blk);
202 outblk = crypto_cursor_segment(&cc_out, &outlen);
204 crypto_cursor_advance(&cc_out, todo);
210 /* Handle trailing partial block for stream ciphers. */
212 KASSERT(exf->native_blocksize != 0,
213 ("%s: partial block of %d bytes for cipher %s",
214 __func__, resid, exf->name));
215 KASSERT(resid < blksz, ("%s: partial block too big", __func__));
217 inblk = crypto_cursor_segment(&cc_in, &inlen);
218 outblk = crypto_cursor_segment(&cc_out, &outlen);
220 crypto_cursor_copydata(&cc_in, resid, blk);
226 exf->encrypt_last(ctx, inblk, outblk,
229 exf->decrypt_last(ctx, inblk, outblk,
232 crypto_cursor_copyback(&cc_out, resid, blk);
235 explicit_bzero(ctx, exf->ctxsize);
236 explicit_bzero(blk, sizeof(blk));
241 * Compute or verify hash.
244 swcr_authcompute(const struct swcr_session *ses, struct cryptop *crp)
248 u_char aalg[HASH_MAX_LEN];
249 u_char uaalg[HASH_MAX_LEN];
251 const struct crypto_session_params *csp;
252 const struct swcr_auth *sw;
253 const struct auth_hash *axf;
256 sw = &ses->swcr_auth;
260 csp = crypto_get_params(crp->crp_session);
261 if (crp->crp_auth_key != NULL) {
263 hmac_init_ipad(axf, crp->crp_auth_key,
264 csp->csp_auth_klen, &s.ctx);
267 axf->Setkey(&s.ctx, crp->crp_auth_key,
271 memcpy(&s.ctx, sw->sw_ictx, axf->ctxsize);
273 if (crp->crp_aad != NULL)
274 err = axf->Update(&s.ctx, crp->crp_aad, crp->crp_aad_length);
276 err = crypto_apply(crp, crp->crp_aad_start, crp->crp_aad_length,
277 axf->Update, &s.ctx);
281 if (CRYPTO_HAS_OUTPUT_BUFFER(crp) &&
282 CRYPTO_OP_IS_ENCRYPT(crp->crp_op))
283 err = crypto_apply_buf(&crp->crp_obuf,
284 crp->crp_payload_output_start, crp->crp_payload_length,
285 axf->Update, &s.ctx);
287 err = crypto_apply(crp, crp->crp_payload_start,
288 crp->crp_payload_length, axf->Update, &s.ctx);
292 if (csp->csp_flags & CSP_F_ESN)
293 axf->Update(&s.ctx, crp->crp_esn, 4);
295 axf->Final(s.aalg, &s.ctx);
297 if (crp->crp_auth_key != NULL)
298 hmac_init_opad(axf, crp->crp_auth_key,
299 csp->csp_auth_klen, &s.ctx);
301 memcpy(&s.ctx, sw->sw_octx, axf->ctxsize);
302 axf->Update(&s.ctx, s.aalg, axf->hashsize);
303 axf->Final(s.aalg, &s.ctx);
306 if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
307 crypto_copydata(crp, crp->crp_digest_start, sw->sw_mlen, s.uaalg);
308 if (timingsafe_bcmp(s.aalg, s.uaalg, sw->sw_mlen) != 0)
311 /* Inject the authentication data */
312 crypto_copyback(crp, crp->crp_digest_start, sw->sw_mlen, s.aalg);
315 explicit_bzero(&s, sizeof(s));
319 CTASSERT(INT_MAX <= (1ll<<39) - 256); /* GCM: plain text < 2^39-256 */
320 CTASSERT(INT_MAX <= (uint64_t)-1); /* GCM: associated data <= 2^64-1 */
323 swcr_gmac(const struct swcr_session *ses, struct cryptop *crp)
327 uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))];
328 u_char tag[GMAC_DIGEST_LEN];
329 u_char tag2[GMAC_DIGEST_LEN];
331 u_char *blk = (u_char *)s.blkbuf;
332 struct crypto_buffer_cursor cc;
334 const struct swcr_auth *swa;
335 const struct auth_hash *axf;
338 int blksz, error, ivlen, resid;
340 swa = &ses->swcr_auth;
342 blksz = GMAC_BLOCK_LEN;
343 KASSERT(axf->blocksize == blksz, ("%s: axf block size mismatch",
346 if (crp->crp_auth_key != NULL) {
348 axf->Setkey(&s.ctx, crp->crp_auth_key,
349 crypto_get_params(crp->crp_session)->csp_auth_klen);
351 memcpy(&s.ctx, swa->sw_ictx, axf->ctxsize);
353 /* Initialize the IV */
354 ivlen = AES_GCM_IV_LEN;
355 crypto_read_iv(crp, blk);
357 axf->Reinit(&s.ctx, blk, ivlen);
358 crypto_cursor_init(&cc, &crp->crp_buf);
359 crypto_cursor_advance(&cc, crp->crp_payload_start);
360 for (resid = crp->crp_payload_length; resid >= blksz; resid -= len) {
361 inblk = crypto_cursor_segment(&cc, &len);
363 len = rounddown(MIN(len, resid), blksz);
364 crypto_cursor_advance(&cc, len);
367 crypto_cursor_copydata(&cc, len, blk);
370 axf->Update(&s.ctx, inblk, len);
373 memset(blk, 0, blksz);
374 crypto_cursor_copydata(&cc, resid, blk);
375 axf->Update(&s.ctx, blk, blksz);
379 memset(blk, 0, blksz);
380 blkp = (uint32_t *)blk + 1;
381 *blkp = htobe32(crp->crp_payload_length * 8);
382 axf->Update(&s.ctx, blk, blksz);
385 axf->Final(s.tag, &s.ctx);
388 if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
389 crypto_copydata(crp, crp->crp_digest_start, swa->sw_mlen,
391 if (timingsafe_bcmp(s.tag, s.tag2, swa->sw_mlen) != 0)
394 /* Inject the authentication data */
395 crypto_copyback(crp, crp->crp_digest_start, swa->sw_mlen, s.tag);
397 explicit_bzero(&s, sizeof(s));
402 swcr_gcm(const struct swcr_session *ses, struct cryptop *crp)
405 uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))];
406 u_char tag[GMAC_DIGEST_LEN];
407 u_char tag2[GMAC_DIGEST_LEN];
409 u_char *blk = (u_char *)s.blkbuf;
410 struct crypto_buffer_cursor cc_in, cc_out;
413 size_t inlen, outlen, todo;
414 const struct swcr_auth *swa;
415 const struct swcr_encdec *swe;
416 const struct enc_xform *exf;
419 int blksz, error, ivlen, r, resid;
421 swa = &ses->swcr_auth;
422 swe = &ses->swcr_encdec;
424 blksz = GMAC_BLOCK_LEN;
425 KASSERT(blksz == exf->native_blocksize,
426 ("%s: blocksize mismatch", __func__));
428 if ((crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0)
431 ivlen = AES_GCM_IV_LEN;
433 ctx = __builtin_alloca(exf->ctxsize);
434 if (crp->crp_cipher_key != NULL)
435 exf->setkey(ctx, crp->crp_cipher_key,
436 crypto_get_params(crp->crp_session)->csp_cipher_klen);
438 memcpy(ctx, swe->sw_ctx, exf->ctxsize);
439 exf->reinit(ctx, crp->crp_iv, ivlen);
441 /* Supply MAC with AAD */
442 if (crp->crp_aad != NULL) {
443 inlen = rounddown2(crp->crp_aad_length, blksz);
445 exf->update(ctx, crp->crp_aad, inlen);
446 if (crp->crp_aad_length != inlen) {
447 memset(blk, 0, blksz);
448 memcpy(blk, (char *)crp->crp_aad + inlen,
449 crp->crp_aad_length - inlen);
450 exf->update(ctx, blk, blksz);
453 crypto_cursor_init(&cc_in, &crp->crp_buf);
454 crypto_cursor_advance(&cc_in, crp->crp_aad_start);
455 for (resid = crp->crp_aad_length; resid >= blksz;
457 inblk = crypto_cursor_segment(&cc_in, &inlen);
458 if (inlen >= blksz) {
459 inlen = rounddown2(MIN(inlen, resid), blksz);
460 crypto_cursor_advance(&cc_in, inlen);
463 crypto_cursor_copydata(&cc_in, inlen, blk);
466 exf->update(ctx, inblk, inlen);
469 memset(blk, 0, blksz);
470 crypto_cursor_copydata(&cc_in, resid, blk);
471 exf->update(ctx, blk, blksz);
475 /* Do encryption with MAC */
476 crypto_cursor_init(&cc_in, &crp->crp_buf);
477 crypto_cursor_advance(&cc_in, crp->crp_payload_start);
478 if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
479 crypto_cursor_init(&cc_out, &crp->crp_obuf);
480 crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
485 for (resid = crp->crp_payload_length; resid >= blksz; resid -= todo) {
487 inblk = crypto_cursor_segment(&cc_in, &inlen);
489 outblk = crypto_cursor_segment(&cc_out, &outlen);
492 crypto_cursor_copydata(&cc_in, blksz, blk);
497 if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
498 if (outlen < blksz) {
503 todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
506 exf->encrypt_multi(ctx, inblk, outblk, todo);
507 exf->update(ctx, outblk, todo);
510 crypto_cursor_copyback(&cc_out, blksz, blk);
511 outblk = crypto_cursor_segment(&cc_out, &outlen);
513 crypto_cursor_advance(&cc_out, todo);
518 todo = rounddown2(MIN(resid, inlen), blksz);
519 exf->update(ctx, inblk, todo);
523 inblk = crypto_cursor_segment(&cc_in, &inlen);
525 crypto_cursor_advance(&cc_in, todo);
531 crypto_cursor_copydata(&cc_in, resid, blk);
532 if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
533 exf->encrypt_last(ctx, blk, blk, resid);
534 crypto_cursor_copyback(&cc_out, resid, blk);
536 exf->update(ctx, blk, resid);
540 memset(blk, 0, blksz);
541 blkp = (uint32_t *)blk + 1;
542 *blkp = htobe32(crp->crp_aad_length * 8);
543 blkp = (uint32_t *)blk + 3;
544 *blkp = htobe32(crp->crp_payload_length * 8);
545 exf->update(ctx, blk, blksz);
548 exf->final(s.tag, ctx);
552 if (!CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
553 crypto_copydata(crp, crp->crp_digest_start, swa->sw_mlen,
555 r = timingsafe_bcmp(s.tag, s.tag2, swa->sw_mlen);
561 /* tag matches, decrypt data */
562 crypto_cursor_init(&cc_in, &crp->crp_buf);
563 crypto_cursor_advance(&cc_in, crp->crp_payload_start);
566 for (resid = crp->crp_payload_length; resid > blksz;
569 inblk = crypto_cursor_segment(&cc_in, &inlen);
571 outblk = crypto_cursor_segment(&cc_out, &outlen);
573 crypto_cursor_copydata(&cc_in, blksz, blk);
577 if (outlen < blksz) {
582 todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
585 exf->decrypt_multi(ctx, inblk, outblk, todo);
588 inblk = crypto_cursor_segment(&cc_in, &inlen);
590 crypto_cursor_advance(&cc_in, todo);
596 crypto_cursor_copyback(&cc_out, blksz, blk);
597 outblk = crypto_cursor_segment(&cc_out,
600 crypto_cursor_advance(&cc_out, todo);
606 crypto_cursor_copydata(&cc_in, resid, blk);
607 exf->decrypt_last(ctx, blk, blk, resid);
608 crypto_cursor_copyback(&cc_out, resid, blk);
611 /* Inject the authentication data */
612 crypto_copyback(crp, crp->crp_digest_start, swa->sw_mlen,
617 explicit_bzero(ctx, exf->ctxsize);
618 explicit_bzero(&s, sizeof(s));
624 build_ccm_b0(const char *nonce, u_int nonce_length, u_int aad_length,
625 u_int data_length, u_int tag_length, uint8_t *b0)
630 KASSERT(nonce_length >= 7 && nonce_length <= 13,
631 ("nonce_length must be between 7 and 13 bytes"));
634 * Need to determine the L field value. This is the number of
635 * bytes needed to specify the length of the message; the length
636 * is whatever is left in the 16 bytes after specifying flags and
639 L = 15 - nonce_length;
641 flags = ((aad_length > 0) << 6) +
642 (((tag_length - 2) / 2) << 3) +
646 * Now we need to set up the first block, which has flags, nonce,
647 * and the message length.
650 memcpy(b0 + 1, nonce, nonce_length);
651 bp = b0 + 1 + nonce_length;
653 /* Need to copy L' [aka L-1] bytes of data_length */
654 for (uint8_t *dst = b0 + CCM_CBC_BLOCK_LEN - 1; dst >= bp; dst--) {
660 /* NB: OCF only supports AAD lengths < 2^32. */
662 build_ccm_aad_length(u_int aad_length, uint8_t *blk)
664 if (aad_length < ((1 << 16) - (1 << 8))) {
665 be16enc(blk, aad_length);
666 return (sizeof(uint16_t));
670 be32enc(blk + 2, aad_length);
671 return (2 + sizeof(uint32_t));
676 swcr_ccm_cbc_mac(const struct swcr_session *ses, struct cryptop *crp)
680 u_char blk[CCM_CBC_BLOCK_LEN];
681 u_char tag[AES_CBC_MAC_HASH_LEN];
682 u_char tag2[AES_CBC_MAC_HASH_LEN];
684 const struct crypto_session_params *csp;
685 const struct swcr_auth *swa;
686 const struct auth_hash *axf;
687 int error, ivlen, len;
689 csp = crypto_get_params(crp->crp_session);
690 swa = &ses->swcr_auth;
693 if (crp->crp_auth_key != NULL) {
695 axf->Setkey(&s.ctx, crp->crp_auth_key, csp->csp_auth_klen);
697 memcpy(&s.ctx, swa->sw_ictx, axf->ctxsize);
699 /* Initialize the IV */
700 ivlen = csp->csp_ivlen;
702 /* Supply MAC with IV */
703 axf->Reinit(&s.ctx, crp->crp_iv, ivlen);
705 /* Supply MAC with b0. */
706 build_ccm_b0(crp->crp_iv, ivlen, crp->crp_payload_length, 0,
707 swa->sw_mlen, s.blk);
708 axf->Update(&s.ctx, s.blk, CCM_CBC_BLOCK_LEN);
710 len = build_ccm_aad_length(crp->crp_payload_length, s.blk);
711 axf->Update(&s.ctx, s.blk, len);
713 crypto_apply(crp, crp->crp_payload_start, crp->crp_payload_length,
714 axf->Update, &s.ctx);
717 axf->Final(s.tag, &s.ctx);
720 if (crp->crp_op & CRYPTO_OP_VERIFY_DIGEST) {
721 crypto_copydata(crp, crp->crp_digest_start, swa->sw_mlen,
723 if (timingsafe_bcmp(s.tag, s.tag2, swa->sw_mlen) != 0)
726 /* Inject the authentication data */
727 crypto_copyback(crp, crp->crp_digest_start, swa->sw_mlen,
730 explicit_bzero(&s, sizeof(s));
735 swcr_ccm(const struct swcr_session *ses, struct cryptop *crp)
737 const struct crypto_session_params *csp;
739 uint32_t blkbuf[howmany(AES_BLOCK_LEN, sizeof(uint32_t))];
740 u_char tag[AES_CBC_MAC_HASH_LEN];
741 u_char tag2[AES_CBC_MAC_HASH_LEN];
743 u_char *blk = (u_char *)s.blkbuf;
744 struct crypto_buffer_cursor cc_in, cc_out;
747 size_t inlen, outlen, todo;
748 const struct swcr_auth *swa;
749 const struct swcr_encdec *swe;
750 const struct enc_xform *exf;
753 int blksz, error, ivlen, r, resid;
755 csp = crypto_get_params(crp->crp_session);
756 swa = &ses->swcr_auth;
757 swe = &ses->swcr_encdec;
759 blksz = AES_BLOCK_LEN;
760 KASSERT(blksz == exf->native_blocksize,
761 ("%s: blocksize mismatch", __func__));
763 if (crp->crp_payload_length > ccm_max_payload_length(csp))
766 if ((crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0)
769 ivlen = csp->csp_ivlen;
771 ctx = __builtin_alloca(exf->ctxsize);
772 if (crp->crp_cipher_key != NULL)
773 exf->setkey(ctx, crp->crp_cipher_key,
774 crypto_get_params(crp->crp_session)->csp_cipher_klen);
776 memcpy(ctx, swe->sw_ctx, exf->ctxsize);
777 exf->reinit(ctx, crp->crp_iv, ivlen);
779 /* Supply MAC with b0. */
780 _Static_assert(sizeof(s.blkbuf) >= CCM_CBC_BLOCK_LEN,
781 "blkbuf too small for b0");
782 build_ccm_b0(crp->crp_iv, ivlen, crp->crp_aad_length,
783 crp->crp_payload_length, swa->sw_mlen, blk);
784 exf->update(ctx, blk, CCM_CBC_BLOCK_LEN);
786 /* Supply MAC with AAD */
787 if (crp->crp_aad_length != 0) {
788 len = build_ccm_aad_length(crp->crp_aad_length, blk);
789 exf->update(ctx, blk, len);
790 if (crp->crp_aad != NULL)
791 exf->update(ctx, crp->crp_aad, crp->crp_aad_length);
793 crypto_apply(crp, crp->crp_aad_start,
794 crp->crp_aad_length, exf->update, ctx);
796 /* Pad the AAD (including length field) to a full block. */
797 len = (len + crp->crp_aad_length) % CCM_CBC_BLOCK_LEN;
799 len = CCM_CBC_BLOCK_LEN - len;
800 memset(blk, 0, CCM_CBC_BLOCK_LEN);
801 exf->update(ctx, blk, len);
805 /* Do encryption/decryption with MAC */
806 crypto_cursor_init(&cc_in, &crp->crp_buf);
807 crypto_cursor_advance(&cc_in, crp->crp_payload_start);
808 if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
809 crypto_cursor_init(&cc_out, &crp->crp_obuf);
810 crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
815 for (resid = crp->crp_payload_length; resid >= blksz; resid -= todo) {
817 inblk = crypto_cursor_segment(&cc_in, &inlen);
819 outblk = crypto_cursor_segment(&cc_out, &outlen);
822 crypto_cursor_copydata(&cc_in, blksz, blk);
827 if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
828 if (outlen < blksz) {
833 todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
836 exf->update(ctx, inblk, todo);
837 exf->encrypt_multi(ctx, inblk, outblk, todo);
840 crypto_cursor_copyback(&cc_out, blksz, blk);
841 outblk = crypto_cursor_segment(&cc_out, &outlen);
843 crypto_cursor_advance(&cc_out, todo);
849 * One of the problems with CCM+CBC is that
850 * the authentication is done on the
851 * unencrypted data. As a result, we have to
852 * decrypt the data twice: once to generate
853 * the tag and a second time after the tag is
857 exf->decrypt(ctx, inblk, blk);
858 exf->update(ctx, blk, todo);
862 inblk = crypto_cursor_segment(&cc_in, &inlen);
864 crypto_cursor_advance(&cc_in, todo);
870 crypto_cursor_copydata(&cc_in, resid, blk);
871 if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
872 exf->update(ctx, blk, resid);
873 exf->encrypt_last(ctx, blk, blk, resid);
874 crypto_cursor_copyback(&cc_out, resid, blk);
876 exf->decrypt_last(ctx, blk, blk, resid);
877 exf->update(ctx, blk, resid);
882 exf->final(s.tag, ctx);
886 if (!CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
887 crypto_copydata(crp, crp->crp_digest_start, swa->sw_mlen,
889 r = timingsafe_bcmp(s.tag, s.tag2, swa->sw_mlen);
895 /* tag matches, decrypt data */
896 exf->reinit(ctx, crp->crp_iv, ivlen);
897 crypto_cursor_init(&cc_in, &crp->crp_buf);
898 crypto_cursor_advance(&cc_in, crp->crp_payload_start);
901 for (resid = crp->crp_payload_length; resid >= blksz;
904 inblk = crypto_cursor_segment(&cc_in, &inlen);
906 outblk = crypto_cursor_segment(&cc_out,
910 crypto_cursor_copydata(&cc_in, blksz, blk);
914 if (outlen < blksz) {
919 todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
922 exf->decrypt_multi(ctx, inblk, outblk, todo);
925 inblk = crypto_cursor_segment(&cc_in, &inlen);
927 crypto_cursor_advance(&cc_in, todo);
933 crypto_cursor_copyback(&cc_out, blksz, blk);
934 outblk = crypto_cursor_segment(&cc_out,
937 crypto_cursor_advance(&cc_out, todo);
943 crypto_cursor_copydata(&cc_in, resid, blk);
944 exf->decrypt_last(ctx, blk, blk, resid);
945 crypto_cursor_copyback(&cc_out, resid, blk);
948 /* Inject the authentication data */
949 crypto_copyback(crp, crp->crp_digest_start, swa->sw_mlen,
954 explicit_bzero(ctx, exf->ctxsize);
955 explicit_bzero(&s, sizeof(s));
960 swcr_chacha20_poly1305(const struct swcr_session *ses, struct cryptop *crp)
962 const struct crypto_session_params *csp;
964 uint64_t blkbuf[howmany(CHACHA20_NATIVE_BLOCK_LEN, sizeof(uint64_t))];
965 u_char tag[POLY1305_HASH_LEN];
966 u_char tag2[POLY1305_HASH_LEN];
968 u_char *blk = (u_char *)s.blkbuf;
969 struct crypto_buffer_cursor cc_in, cc_out;
972 size_t inlen, outlen, todo;
974 const struct swcr_auth *swa;
975 const struct swcr_encdec *swe;
976 const struct enc_xform *exf;
978 int blksz, error, r, resid;
980 swa = &ses->swcr_auth;
981 swe = &ses->swcr_encdec;
983 blksz = exf->native_blocksize;
984 KASSERT(blksz <= sizeof(s.blkbuf), ("%s: blocksize mismatch", __func__));
986 if ((crp->crp_flags & CRYPTO_F_IV_SEPARATE) == 0)
989 csp = crypto_get_params(crp->crp_session);
991 ctx = __builtin_alloca(exf->ctxsize);
992 if (crp->crp_cipher_key != NULL)
993 exf->setkey(ctx, crp->crp_cipher_key,
994 csp->csp_cipher_klen);
996 memcpy(ctx, swe->sw_ctx, exf->ctxsize);
997 exf->reinit(ctx, crp->crp_iv, csp->csp_ivlen);
999 /* Supply MAC with AAD */
1000 if (crp->crp_aad != NULL)
1001 exf->update(ctx, crp->crp_aad, crp->crp_aad_length);
1003 crypto_apply(crp, crp->crp_aad_start, crp->crp_aad_length,
1005 if (crp->crp_aad_length % POLY1305_BLOCK_LEN != 0) {
1007 memset(blk, 0, POLY1305_BLOCK_LEN);
1008 exf->update(ctx, blk, POLY1305_BLOCK_LEN -
1009 crp->crp_aad_length % POLY1305_BLOCK_LEN);
1012 /* Do encryption with MAC */
1013 crypto_cursor_init(&cc_in, &crp->crp_buf);
1014 crypto_cursor_advance(&cc_in, crp->crp_payload_start);
1015 if (CRYPTO_HAS_OUTPUT_BUFFER(crp)) {
1016 crypto_cursor_init(&cc_out, &crp->crp_obuf);
1017 crypto_cursor_advance(&cc_out, crp->crp_payload_output_start);
1022 if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
1023 for (resid = crp->crp_payload_length; resid >= blksz;
1026 inblk = crypto_cursor_segment(&cc_in, &inlen);
1028 outblk = crypto_cursor_segment(&cc_out,
1031 if (inlen < blksz) {
1032 crypto_cursor_copydata(&cc_in, blksz, blk);
1037 if (outlen < blksz) {
1042 todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
1045 exf->encrypt_multi(ctx, inblk, outblk, todo);
1046 exf->update(ctx, outblk, todo);
1049 inblk = crypto_cursor_segment(&cc_in, &inlen);
1051 crypto_cursor_advance(&cc_in, todo);
1056 if (outblk == blk) {
1057 crypto_cursor_copyback(&cc_out, blksz, blk);
1058 outblk = crypto_cursor_segment(&cc_out, &outlen);
1060 crypto_cursor_advance(&cc_out, todo);
1066 crypto_cursor_copydata(&cc_in, resid, blk);
1067 exf->encrypt_last(ctx, blk, blk, resid);
1068 crypto_cursor_copyback(&cc_out, resid, blk);
1069 exf->update(ctx, blk, resid);
1072 crypto_apply(crp, crp->crp_payload_start,
1073 crp->crp_payload_length, exf->update, ctx);
1074 if (crp->crp_payload_length % POLY1305_BLOCK_LEN != 0) {
1076 memset(blk, 0, POLY1305_BLOCK_LEN);
1077 exf->update(ctx, blk, POLY1305_BLOCK_LEN -
1078 crp->crp_payload_length % POLY1305_BLOCK_LEN);
1082 blkp = (uint64_t *)blk;
1083 blkp[0] = htole64(crp->crp_aad_length);
1084 blkp[1] = htole64(crp->crp_payload_length);
1085 exf->update(ctx, blk, sizeof(uint64_t) * 2);
1088 exf->final(s.tag, ctx);
1092 if (!CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
1093 crypto_copydata(crp, crp->crp_digest_start, swa->sw_mlen,
1095 r = timingsafe_bcmp(s.tag, s.tag2, swa->sw_mlen);
1101 /* tag matches, decrypt data */
1102 crypto_cursor_init(&cc_in, &crp->crp_buf);
1103 crypto_cursor_advance(&cc_in, crp->crp_payload_start);
1106 for (resid = crp->crp_payload_length; resid > blksz;
1109 inblk = crypto_cursor_segment(&cc_in, &inlen);
1111 outblk = crypto_cursor_segment(&cc_out,
1113 if (inlen < blksz) {
1114 crypto_cursor_copydata(&cc_in, blksz, blk);
1118 if (outlen < blksz) {
1123 todo = rounddown2(MIN(resid, MIN(inlen, outlen)),
1126 exf->decrypt_multi(ctx, inblk, outblk, todo);
1129 inblk = crypto_cursor_segment(&cc_in, &inlen);
1131 crypto_cursor_advance(&cc_in, todo);
1136 if (outblk == blk) {
1137 crypto_cursor_copyback(&cc_out, blksz, blk);
1138 outblk = crypto_cursor_segment(&cc_out,
1141 crypto_cursor_advance(&cc_out, todo);
1147 crypto_cursor_copydata(&cc_in, resid, blk);
1148 exf->decrypt_last(ctx, blk, blk, resid);
1149 crypto_cursor_copyback(&cc_out, resid, blk);
1152 /* Inject the authentication data */
1153 crypto_copyback(crp, crp->crp_digest_start, swa->sw_mlen,
1158 explicit_bzero(ctx, exf->ctxsize);
1159 explicit_bzero(&s, sizeof(s));
1164 * Apply a cipher and a digest to perform EtA.
1167 swcr_eta(const struct swcr_session *ses, struct cryptop *crp)
1171 if (CRYPTO_OP_IS_ENCRYPT(crp->crp_op)) {
1172 error = swcr_encdec(ses, crp);
1174 error = swcr_authcompute(ses, crp);
1176 error = swcr_authcompute(ses, crp);
1178 error = swcr_encdec(ses, crp);
1184 * Apply a compression/decompression algorithm
1187 swcr_compdec(const struct swcr_session *ses, struct cryptop *crp)
1189 const struct comp_algo *cxf;
1190 uint8_t *data, *out;
1194 cxf = ses->swcr_compdec.sw_cxf;
1196 /* We must handle the whole buffer of data in one time
1197 * then if there is not all the data in the mbuf, we must
1201 data = malloc(crp->crp_payload_length, M_CRYPTO_DATA, M_NOWAIT);
1204 crypto_copydata(crp, crp->crp_payload_start, crp->crp_payload_length,
1207 if (CRYPTO_OP_IS_COMPRESS(crp->crp_op))
1208 result = cxf->compress(data, crp->crp_payload_length, &out);
1210 result = cxf->decompress(data, crp->crp_payload_length, &out);
1212 free(data, M_CRYPTO_DATA);
1215 crp->crp_olen = result;
1217 /* Check the compressed size when doing compression */
1218 if (CRYPTO_OP_IS_COMPRESS(crp->crp_op)) {
1219 if (result >= crp->crp_payload_length) {
1220 /* Compression was useless, we lost time */
1221 free(out, M_CRYPTO_DATA);
1226 /* Copy back the (de)compressed data. m_copyback is
1227 * extending the mbuf as necessary.
1229 crypto_copyback(crp, crp->crp_payload_start, result, out);
1230 if (result < crp->crp_payload_length) {
1231 switch (crp->crp_buf.cb_type) {
1232 case CRYPTO_BUF_MBUF:
1233 case CRYPTO_BUF_SINGLE_MBUF:
1234 adj = result - crp->crp_payload_length;
1235 m_adj(crp->crp_buf.cb_mbuf, adj);
1237 case CRYPTO_BUF_UIO: {
1238 struct uio *uio = crp->crp_buf.cb_uio;
1241 adj = crp->crp_payload_length - result;
1242 ind = uio->uio_iovcnt - 1;
1244 while (adj > 0 && ind >= 0) {
1245 if (adj < uio->uio_iov[ind].iov_len) {
1246 uio->uio_iov[ind].iov_len -= adj;
1250 adj -= uio->uio_iov[ind].iov_len;
1251 uio->uio_iov[ind].iov_len = 0;
1257 case CRYPTO_BUF_VMPAGE:
1258 adj = crp->crp_payload_length - result;
1259 crp->crp_buf.cb_vm_page_len -= adj;
1265 free(out, M_CRYPTO_DATA);
1270 swcr_setup_cipher(struct swcr_session *ses,
1271 const struct crypto_session_params *csp)
1273 struct swcr_encdec *swe;
1274 const struct enc_xform *txf;
1277 swe = &ses->swcr_encdec;
1278 txf = crypto_cipher(csp);
1279 if (csp->csp_cipher_key != NULL) {
1280 if (txf->ctxsize != 0) {
1281 swe->sw_ctx = malloc(txf->ctxsize, M_CRYPTO_DATA,
1283 if (swe->sw_ctx == NULL)
1286 error = txf->setkey(swe->sw_ctx,
1287 csp->csp_cipher_key, csp->csp_cipher_klen);
1296 swcr_setup_auth(struct swcr_session *ses,
1297 const struct crypto_session_params *csp)
1299 struct swcr_auth *swa;
1300 const struct auth_hash *axf;
1302 swa = &ses->swcr_auth;
1304 axf = crypto_auth_hash(csp);
1306 if (csp->csp_auth_mlen < 0 || csp->csp_auth_mlen > axf->hashsize)
1308 if (csp->csp_auth_mlen == 0)
1309 swa->sw_mlen = axf->hashsize;
1311 swa->sw_mlen = csp->csp_auth_mlen;
1312 if (csp->csp_auth_klen == 0 || csp->csp_auth_key != NULL) {
1313 swa->sw_ictx = malloc(axf->ctxsize, M_CRYPTO_DATA,
1315 if (swa->sw_ictx == NULL)
1319 switch (csp->csp_auth_alg) {
1320 case CRYPTO_SHA1_HMAC:
1321 case CRYPTO_SHA2_224_HMAC:
1322 case CRYPTO_SHA2_256_HMAC:
1323 case CRYPTO_SHA2_384_HMAC:
1324 case CRYPTO_SHA2_512_HMAC:
1325 case CRYPTO_RIPEMD160_HMAC:
1326 swa->sw_hmac = true;
1327 if (csp->csp_auth_key != NULL) {
1328 swa->sw_octx = malloc(axf->ctxsize, M_CRYPTO_DATA,
1330 if (swa->sw_octx == NULL)
1332 hmac_init_ipad(axf, csp->csp_auth_key,
1333 csp->csp_auth_klen, swa->sw_ictx);
1334 hmac_init_opad(axf, csp->csp_auth_key,
1335 csp->csp_auth_klen, swa->sw_octx);
1338 case CRYPTO_RIPEMD160:
1340 case CRYPTO_SHA2_224:
1341 case CRYPTO_SHA2_256:
1342 case CRYPTO_SHA2_384:
1343 case CRYPTO_SHA2_512:
1344 case CRYPTO_NULL_HMAC:
1345 axf->Init(swa->sw_ictx);
1347 case CRYPTO_AES_NIST_GMAC:
1348 case CRYPTO_AES_CCM_CBC_MAC:
1349 case CRYPTO_POLY1305:
1350 if (csp->csp_auth_key != NULL) {
1351 axf->Init(swa->sw_ictx);
1352 axf->Setkey(swa->sw_ictx, csp->csp_auth_key,
1353 csp->csp_auth_klen);
1356 case CRYPTO_BLAKE2B:
1357 case CRYPTO_BLAKE2S:
1359 * Blake2b and Blake2s support an optional key but do
1362 if (csp->csp_auth_klen == 0)
1363 axf->Init(swa->sw_ictx);
1364 else if (csp->csp_auth_key != NULL)
1365 axf->Setkey(swa->sw_ictx, csp->csp_auth_key,
1366 csp->csp_auth_klen);
1370 if (csp->csp_mode == CSP_MODE_DIGEST) {
1371 switch (csp->csp_auth_alg) {
1372 case CRYPTO_AES_NIST_GMAC:
1373 ses->swcr_process = swcr_gmac;
1375 case CRYPTO_AES_CCM_CBC_MAC:
1376 ses->swcr_process = swcr_ccm_cbc_mac;
1379 ses->swcr_process = swcr_authcompute;
1387 swcr_setup_aead(struct swcr_session *ses,
1388 const struct crypto_session_params *csp)
1390 struct swcr_auth *swa;
1393 error = swcr_setup_cipher(ses, csp);
1397 swa = &ses->swcr_auth;
1398 if (csp->csp_auth_mlen == 0)
1399 swa->sw_mlen = ses->swcr_encdec.sw_exf->macsize;
1401 swa->sw_mlen = csp->csp_auth_mlen;
1406 swcr_auth_supported(const struct crypto_session_params *csp)
1408 const struct auth_hash *axf;
1410 axf = crypto_auth_hash(csp);
1413 switch (csp->csp_auth_alg) {
1414 case CRYPTO_SHA1_HMAC:
1415 case CRYPTO_SHA2_224_HMAC:
1416 case CRYPTO_SHA2_256_HMAC:
1417 case CRYPTO_SHA2_384_HMAC:
1418 case CRYPTO_SHA2_512_HMAC:
1419 case CRYPTO_NULL_HMAC:
1420 case CRYPTO_RIPEMD160_HMAC:
1422 case CRYPTO_AES_NIST_GMAC:
1423 switch (csp->csp_auth_klen * 8) {
1431 if (csp->csp_auth_key == NULL)
1433 if (csp->csp_ivlen != AES_GCM_IV_LEN)
1436 case CRYPTO_POLY1305:
1437 if (csp->csp_auth_klen != POLY1305_KEY_LEN)
1440 case CRYPTO_AES_CCM_CBC_MAC:
1441 switch (csp->csp_auth_klen * 8) {
1449 if (csp->csp_auth_key == NULL)
1457 swcr_cipher_supported(const struct crypto_session_params *csp)
1459 const struct enc_xform *txf;
1461 txf = crypto_cipher(csp);
1464 if (csp->csp_cipher_alg != CRYPTO_NULL_CBC &&
1465 txf->ivsize != csp->csp_ivlen)
1470 #define SUPPORTED_SES (CSP_F_SEPARATE_OUTPUT | CSP_F_SEPARATE_AAD | CSP_F_ESN)
1473 swcr_probesession(device_t dev, const struct crypto_session_params *csp)
1475 if ((csp->csp_flags & ~(SUPPORTED_SES)) != 0)
1477 switch (csp->csp_mode) {
1478 case CSP_MODE_COMPRESS:
1479 switch (csp->csp_cipher_alg) {
1480 case CRYPTO_DEFLATE_COMP:
1486 case CSP_MODE_CIPHER:
1487 switch (csp->csp_cipher_alg) {
1488 case CRYPTO_AES_NIST_GCM_16:
1489 case CRYPTO_AES_CCM_16:
1490 case CRYPTO_CHACHA20_POLY1305:
1491 case CRYPTO_XCHACHA20_POLY1305:
1494 if (!swcr_cipher_supported(csp))
1499 case CSP_MODE_DIGEST:
1500 if (!swcr_auth_supported(csp))
1504 switch (csp->csp_cipher_alg) {
1505 case CRYPTO_AES_NIST_GCM_16:
1506 case CRYPTO_AES_CCM_16:
1507 switch (csp->csp_cipher_klen * 8) {
1516 case CRYPTO_CHACHA20_POLY1305:
1517 case CRYPTO_XCHACHA20_POLY1305:
1524 /* AEAD algorithms cannot be used for EtA. */
1525 switch (csp->csp_cipher_alg) {
1526 case CRYPTO_AES_NIST_GCM_16:
1527 case CRYPTO_AES_CCM_16:
1528 case CRYPTO_CHACHA20_POLY1305:
1529 case CRYPTO_XCHACHA20_POLY1305:
1532 switch (csp->csp_auth_alg) {
1533 case CRYPTO_AES_NIST_GMAC:
1534 case CRYPTO_AES_CCM_CBC_MAC:
1538 if (!swcr_cipher_supported(csp) ||
1539 !swcr_auth_supported(csp))
1546 return (CRYPTODEV_PROBE_SOFTWARE);
1550 * Generate a new software session.
1553 swcr_newsession(device_t dev, crypto_session_t cses,
1554 const struct crypto_session_params *csp)
1556 struct swcr_session *ses;
1557 const struct comp_algo *cxf;
1560 ses = crypto_get_driver_session(cses);
1563 switch (csp->csp_mode) {
1564 case CSP_MODE_COMPRESS:
1565 switch (csp->csp_cipher_alg) {
1566 case CRYPTO_DEFLATE_COMP:
1567 cxf = &comp_algo_deflate;
1571 panic("bad compression algo");
1574 ses->swcr_compdec.sw_cxf = cxf;
1575 ses->swcr_process = swcr_compdec;
1577 case CSP_MODE_CIPHER:
1578 switch (csp->csp_cipher_alg) {
1579 case CRYPTO_NULL_CBC:
1580 ses->swcr_process = swcr_null;
1583 case CRYPTO_AES_NIST_GCM_16:
1584 case CRYPTO_AES_CCM_16:
1585 case CRYPTO_CHACHA20_POLY1305:
1586 case CRYPTO_XCHACHA20_POLY1305:
1587 panic("bad cipher algo");
1590 error = swcr_setup_cipher(ses, csp);
1592 ses->swcr_process = swcr_encdec;
1595 case CSP_MODE_DIGEST:
1596 error = swcr_setup_auth(ses, csp);
1599 switch (csp->csp_cipher_alg) {
1600 case CRYPTO_AES_NIST_GCM_16:
1601 error = swcr_setup_aead(ses, csp);
1603 ses->swcr_process = swcr_gcm;
1605 case CRYPTO_AES_CCM_16:
1606 error = swcr_setup_aead(ses, csp);
1608 ses->swcr_process = swcr_ccm;
1610 case CRYPTO_CHACHA20_POLY1305:
1611 case CRYPTO_XCHACHA20_POLY1305:
1612 error = swcr_setup_aead(ses, csp);
1614 ses->swcr_process = swcr_chacha20_poly1305;
1618 panic("bad aead algo");
1624 switch (csp->csp_cipher_alg) {
1625 case CRYPTO_AES_NIST_GCM_16:
1626 case CRYPTO_AES_CCM_16:
1627 case CRYPTO_CHACHA20_POLY1305:
1628 case CRYPTO_XCHACHA20_POLY1305:
1629 panic("bad eta cipher algo");
1631 switch (csp->csp_auth_alg) {
1632 case CRYPTO_AES_NIST_GMAC:
1633 case CRYPTO_AES_CCM_CBC_MAC:
1634 panic("bad eta auth algo");
1638 error = swcr_setup_auth(ses, csp);
1641 if (csp->csp_cipher_alg == CRYPTO_NULL_CBC) {
1642 /* Effectively degrade to digest mode. */
1643 ses->swcr_process = swcr_authcompute;
1647 error = swcr_setup_cipher(ses, csp);
1649 ses->swcr_process = swcr_eta;
1656 swcr_freesession(dev, cses);
1661 swcr_freesession(device_t dev, crypto_session_t cses)
1663 struct swcr_session *ses;
1665 ses = crypto_get_driver_session(cses);
1667 zfree(ses->swcr_encdec.sw_ctx, M_CRYPTO_DATA);
1668 zfree(ses->swcr_auth.sw_ictx, M_CRYPTO_DATA);
1669 zfree(ses->swcr_auth.sw_octx, M_CRYPTO_DATA);
1673 * Process a software request.
1676 swcr_process(device_t dev, struct cryptop *crp, int hint)
1678 struct swcr_session *ses;
1680 ses = crypto_get_driver_session(crp->crp_session);
1682 crp->crp_etype = ses->swcr_process(ses, crp);
1689 swcr_identify(driver_t *drv, device_t parent)
1691 /* NB: order 10 is so we get attached after h/w devices */
1692 if (device_find_child(parent, "cryptosoft", -1) == NULL &&
1693 BUS_ADD_CHILD(parent, 10, "cryptosoft", 0) == 0)
1694 panic("cryptosoft: could not attach");
1698 swcr_probe(device_t dev)
1700 device_set_desc(dev, "software crypto");
1702 return (BUS_PROBE_NOWILDCARD);
1706 swcr_attach(device_t dev)
1709 swcr_id = crypto_get_driverid(dev, sizeof(struct swcr_session),
1710 CRYPTOCAP_F_SOFTWARE | CRYPTOCAP_F_SYNC);
1712 device_printf(dev, "cannot initialize!");
1720 swcr_detach(device_t dev)
1722 crypto_unregister_all(swcr_id);
1726 static device_method_t swcr_methods[] = {
1727 DEVMETHOD(device_identify, swcr_identify),
1728 DEVMETHOD(device_probe, swcr_probe),
1729 DEVMETHOD(device_attach, swcr_attach),
1730 DEVMETHOD(device_detach, swcr_detach),
1732 DEVMETHOD(cryptodev_probesession, swcr_probesession),
1733 DEVMETHOD(cryptodev_newsession, swcr_newsession),
1734 DEVMETHOD(cryptodev_freesession,swcr_freesession),
1735 DEVMETHOD(cryptodev_process, swcr_process),
1740 static driver_t swcr_driver = {
1743 0, /* NB: no softc */
1745 static devclass_t swcr_devclass;
1748 * NB: We explicitly reference the crypto module so we
1749 * get the necessary ordering when built as a loadable
1750 * module. This is required because we bundle the crypto
1751 * module code together with the cryptosoft driver (otherwise
1752 * normal module dependencies would handle things).
1754 extern int crypto_modevent(struct module *, int, void *);
1755 /* XXX where to attach */
1756 DRIVER_MODULE(cryptosoft, nexus, swcr_driver, swcr_devclass, crypto_modevent,0);
1757 MODULE_VERSION(cryptosoft, 1);
1758 MODULE_DEPEND(cryptosoft, crypto, 1, 1, 1);