5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 #include <sys/strsun.h>
27 #include <sys/systm.h>
28 #include <sys/sysmacros.h>
29 #include <sys/kmem.h>
30 #include <sys/md5.h>
31 #include <sys/sha1.h>
32 #include <sys/sha2.h>
33 #include <modes/modes.h>
34 #include <sys/crypto/common.h>
35 #include <sys/crypto/impl.h>
36
37 /*
38 * Utility routine to apply the command, 'cmd', to the
39 * data in the uio structure.
40 */
41 int
42 crypto_uio_data(crypto_data_t *data, uchar_t *buf, int len, cmd_type_t cmd,
43 void *digest_ctx, void (*update)())
44 {
379 SHA2_DIGEST_DATA, dctx, update);
380
381 if (rv != CRYPTO_SUCCESS)
382 return (rv);
383
384 break;
385 }
386 }
387
388 dofinal:
389 if (flag & CRYPTO_DO_FINAL) {
390 final(digest, dctx);
391 }
392
393 return (CRYPTO_SUCCESS);
394 }
395
396 int
397 crypto_update_iov(void *ctx, crypto_data_t *input, crypto_data_t *output,
398 int (*cipher)(void *, caddr_t, size_t, crypto_data_t *),
399 void (*copy_block)(uint8_t *, uint64_t *))
400 {
401 common_ctx_t *common_ctx = ctx;
402 int rv;
403
404 if (input->cd_miscdata != NULL) {
405 copy_block((uint8_t *)input->cd_miscdata,
406 &common_ctx->cc_iv[0]);
407 }
408
409 if (input->cd_raw.iov_len < input->cd_length)
410 return (CRYPTO_ARGUMENTS_BAD);
411
412 rv = (cipher)(ctx, input->cd_raw.iov_base + input->cd_offset,
413 input->cd_length, (input == output) ? NULL : output);
414
415 return (rv);
416 }
417
418 int
419 crypto_update_uio(void *ctx, crypto_data_t *input, crypto_data_t *output,
420 int (*cipher)(void *, caddr_t, size_t, crypto_data_t *),
421 void (*copy_block)(uint8_t *, uint64_t *))
422 {
423 common_ctx_t *common_ctx = ctx;
424 uio_t *uiop = input->cd_uio;
425 off_t offset = input->cd_offset;
426 size_t length = input->cd_length;
427 uint_t vec_idx;
428 size_t cur_len;
429
430 if (input->cd_miscdata != NULL) {
431 copy_block((uint8_t *)input->cd_miscdata,
432 &common_ctx->cc_iv[0]);
433 }
434
435 if (input->cd_uio->uio_segflg != UIO_SYSSPACE) {
436 return (CRYPTO_ARGUMENTS_BAD);
437 }
438
439 /*
440 * Jump to the first iovec containing data to be
441 * processed.
466 vec_idx++;
467 offset = 0;
468 }
469
470 if (vec_idx == uiop->uio_iovcnt && length > 0) {
471 /*
472 * The end of the specified iovec's was reached but
473 * the length requested could not be processed, i.e.
474 * The caller requested to digest more data than it provided.
475 */
476
477 return (CRYPTO_DATA_LEN_RANGE);
478 }
479
480 return (CRYPTO_SUCCESS);
481 }
482
483 int
484 crypto_update_mp(void *ctx, crypto_data_t *input, crypto_data_t *output,
485 int (*cipher)(void *, caddr_t, size_t, crypto_data_t *),
486 void (*copy_block)(uint8_t *, uint64_t *))
487 {
488 common_ctx_t *common_ctx = ctx;
489 off_t offset = input->cd_offset;
490 size_t length = input->cd_length;
491 mblk_t *mp;
492 size_t cur_len;
493
494 if (input->cd_miscdata != NULL) {
495 copy_block((uint8_t *)input->cd_miscdata,
496 &common_ctx->cc_iv[0]);
497 }
498
499 /*
500 * Jump to the first mblk_t containing data to be processed.
501 */
502 for (mp = input->cd_mp; mp != NULL && offset >= MBLKL(mp);
503 offset -= MBLKL(mp), mp = mp->b_cont)
504 ;
505 if (mp == NULL) {
506 /*
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25 /*
26 * Copyright 2015 by Saso Kiselkov. All rights reserved.
27 */
28
29 #include <sys/strsun.h>
30 #include <sys/systm.h>
31 #include <sys/sysmacros.h>
32 #include <sys/kmem.h>
33 #include <sys/md5.h>
34 #include <sys/sha1.h>
35 #include <sys/sha2.h>
36 #include <modes/modes.h>
37 #include <sys/crypto/common.h>
38 #include <sys/crypto/impl.h>
39
40 /*
41 * Utility routine to apply the command, 'cmd', to the
42 * data in the uio structure.
43 */
44 int
45 crypto_uio_data(crypto_data_t *data, uchar_t *buf, int len, cmd_type_t cmd,
46 void *digest_ctx, void (*update)())
47 {
382 SHA2_DIGEST_DATA, dctx, update);
383
384 if (rv != CRYPTO_SUCCESS)
385 return (rv);
386
387 break;
388 }
389 }
390
391 dofinal:
392 if (flag & CRYPTO_DO_FINAL) {
393 final(digest, dctx);
394 }
395
396 return (CRYPTO_SUCCESS);
397 }
398
399 int
400 crypto_update_iov(void *ctx, crypto_data_t *input, crypto_data_t *output,
401 int (*cipher)(void *, caddr_t, size_t, crypto_data_t *),
402 void (*copy_block)(const uint8_t *, uint64_t *))
403 {
404 common_ctx_t *common_ctx = ctx;
405 int rv;
406
407 if (input->cd_miscdata != NULL) {
408 copy_block((uint8_t *)input->cd_miscdata,
409 &common_ctx->cc_iv[0]);
410 }
411
412 if (input->cd_raw.iov_len < input->cd_length)
413 return (CRYPTO_ARGUMENTS_BAD);
414
415 rv = (cipher)(ctx, input->cd_raw.iov_base + input->cd_offset,
416 input->cd_length, (input == output) ? NULL : output);
417
418 return (rv);
419 }
420
421 int
422 crypto_update_uio(void *ctx, crypto_data_t *input, crypto_data_t *output,
423 int (*cipher)(void *, caddr_t, size_t, crypto_data_t *),
424 void (*copy_block)(const uint8_t *, uint64_t *))
425 {
426 common_ctx_t *common_ctx = ctx;
427 uio_t *uiop = input->cd_uio;
428 off_t offset = input->cd_offset;
429 size_t length = input->cd_length;
430 uint_t vec_idx;
431 size_t cur_len;
432
433 if (input->cd_miscdata != NULL) {
434 copy_block((uint8_t *)input->cd_miscdata,
435 &common_ctx->cc_iv[0]);
436 }
437
438 if (input->cd_uio->uio_segflg != UIO_SYSSPACE) {
439 return (CRYPTO_ARGUMENTS_BAD);
440 }
441
442 /*
443 * Jump to the first iovec containing data to be
444 * processed.
469 vec_idx++;
470 offset = 0;
471 }
472
473 if (vec_idx == uiop->uio_iovcnt && length > 0) {
474 /*
475 * The end of the specified iovec's was reached but
476 * the length requested could not be processed, i.e.
477 * The caller requested to digest more data than it provided.
478 */
479
480 return (CRYPTO_DATA_LEN_RANGE);
481 }
482
483 return (CRYPTO_SUCCESS);
484 }
485
486 int
487 crypto_update_mp(void *ctx, crypto_data_t *input, crypto_data_t *output,
488 int (*cipher)(void *, caddr_t, size_t, crypto_data_t *),
489 void (*copy_block)(const uint8_t *, uint64_t *))
490 {
491 common_ctx_t *common_ctx = ctx;
492 off_t offset = input->cd_offset;
493 size_t length = input->cd_length;
494 mblk_t *mp;
495 size_t cur_len;
496
497 if (input->cd_miscdata != NULL) {
498 copy_block((uint8_t *)input->cd_miscdata,
499 &common_ctx->cc_iv[0]);
500 }
501
502 /*
503 * Jump to the first mblk_t containing data to be processed.
504 */
505 for (mp = input->cd_mp; mp != NULL && offset >= MBLKL(mp);
506 offset -= MBLKL(mp), mp = mp->b_cont)
507 ;
508 if (mp == NULL) {
509 /*
|