]>
Commit | Line | Data |
---|---|---|
3c67d83a TH |
1 | /* |
2 | * CDDL HEADER START | |
3 | * | |
4 | * The contents of this file are subject to the terms of the | |
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://opensource.org/licenses/CDDL-1.0. | |
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 2013 Saso Kiselkov. All rights reserved. | |
a6255b7f | 23 | * Copyright (c) 2016 by Delphix. All rights reserved. |
3c67d83a TH |
24 | */ |
25 | #include <sys/zfs_context.h> | |
26 | #include <sys/zio.h> | |
27 | #include <sys/skein.h> | |
28 | ||
a6255b7f DQ |
29 | #include <sys/abd.h> |
30 | ||
31 | static int | |
32 | skein_incremental(void *buf, size_t size, void *arg) | |
33 | { | |
34 | Skein_512_Ctxt_t *ctx = arg; | |
35 | (void) Skein_512_Update(ctx, buf, size); | |
36 | return (0); | |
37 | } | |
3c67d83a TH |
38 | /* |
39 | * Computes a native 256-bit skein MAC checksum. Please note that this | |
40 | * function requires the presence of a ctx_template that should be allocated | |
a6255b7f | 41 | * using abd_checksum_skein_tmpl_init. |
3c67d83a TH |
42 | */ |
43 | /*ARGSUSED*/ | |
44 | void | |
a6255b7f | 45 | abd_checksum_skein_native(abd_t *abd, uint64_t size, |
3c67d83a TH |
46 | const void *ctx_template, zio_cksum_t *zcp) |
47 | { | |
48 | Skein_512_Ctxt_t ctx; | |
49 | ||
50 | ASSERT(ctx_template != NULL); | |
51 | bcopy(ctx_template, &ctx, sizeof (ctx)); | |
a6255b7f | 52 | (void) abd_iterate_func(abd, 0, size, skein_incremental, &ctx); |
3c67d83a TH |
53 | (void) Skein_512_Final(&ctx, (uint8_t *)zcp); |
54 | bzero(&ctx, sizeof (ctx)); | |
55 | } | |
56 | ||
57 | /* | |
a6255b7f | 58 | * Byteswapped version of abd_checksum_skein_native. This just invokes |
3c67d83a TH |
59 | * the native checksum function and byteswaps the resulting checksum (since |
60 | * skein is internally endian-insensitive). | |
61 | */ | |
62 | void | |
a6255b7f | 63 | abd_checksum_skein_byteswap(abd_t *abd, uint64_t size, |
3c67d83a TH |
64 | const void *ctx_template, zio_cksum_t *zcp) |
65 | { | |
66 | zio_cksum_t tmp; | |
67 | ||
a6255b7f | 68 | abd_checksum_skein_native(abd, size, ctx_template, &tmp); |
3c67d83a TH |
69 | zcp->zc_word[0] = BSWAP_64(tmp.zc_word[0]); |
70 | zcp->zc_word[1] = BSWAP_64(tmp.zc_word[1]); | |
71 | zcp->zc_word[2] = BSWAP_64(tmp.zc_word[2]); | |
72 | zcp->zc_word[3] = BSWAP_64(tmp.zc_word[3]); | |
73 | } | |
74 | ||
75 | /* | |
76 | * Allocates a skein MAC template suitable for using in skein MAC checksum | |
77 | * computations and returns a pointer to it. | |
78 | */ | |
79 | void * | |
a6255b7f | 80 | abd_checksum_skein_tmpl_init(const zio_cksum_salt_t *salt) |
3c67d83a TH |
81 | { |
82 | Skein_512_Ctxt_t *ctx; | |
83 | ||
84 | ctx = kmem_zalloc(sizeof (*ctx), KM_SLEEP); | |
85 | (void) Skein_512_InitExt(ctx, sizeof (zio_cksum_t) * 8, 0, | |
86 | salt->zcs_bytes, sizeof (salt->zcs_bytes)); | |
87 | return (ctx); | |
88 | } | |
89 | ||
90 | /* | |
91 | * Frees a skein context template previously allocated using | |
92 | * zio_checksum_skein_tmpl_init. | |
93 | */ | |
94 | void | |
a6255b7f | 95 | abd_checksum_skein_tmpl_free(void *ctx_template) |
3c67d83a TH |
96 | { |
97 | Skein_512_Ctxt_t *ctx = ctx_template; | |
98 | ||
99 | bzero(ctx, sizeof (*ctx)); | |
100 | kmem_free(ctx, sizeof (*ctx)); | |
101 | } |