1fa9e4066Sahrens /*
2fa9e4066Sahrens * CDDL HEADER START
3fa9e4066Sahrens *
4fa9e4066Sahrens * The contents of this file are subject to the terms of the
517f17c2dSbonwick * Common Development and Distribution License (the "License").
617f17c2dSbonwick * You may not use this file except in compliance with the License.
7fa9e4066Sahrens *
8fa9e4066Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens * See the License for the specific language governing permissions
11fa9e4066Sahrens * and limitations under the License.
12fa9e4066Sahrens *
13fa9e4066Sahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens *
19fa9e4066Sahrens * CDDL HEADER END
20fa9e4066Sahrens */
21fa9e4066Sahrens /*
22b24ab676SJeff Bonwick * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23fa9e4066Sahrens * Use is subject to license terms.
24fa9e4066Sahrens */
25fa9e4066Sahrens #include <sys/zfs_context.h>
26fa9e4066Sahrens #include <sys/zio.h>
27*97322426SDarren J Moffat #include <sys/sha2.h>
28fa9e4066Sahrens
29fa9e4066Sahrens void
zio_checksum_SHA256(const void * buf,uint64_t size,zio_cksum_t * zcp)30fa9e4066Sahrens zio_checksum_SHA256(const void *buf, uint64_t size, zio_cksum_t *zcp)
31fa9e4066Sahrens {
32*97322426SDarren J Moffat SHA2_CTX ctx;
33*97322426SDarren J Moffat zio_cksum_t tmp;
34fa9e4066Sahrens
35*97322426SDarren J Moffat SHA2Init(SHA256, &ctx);
36*97322426SDarren J Moffat SHA2Update(&ctx, buf, size);
37*97322426SDarren J Moffat SHA2Final(&tmp, &ctx);
38fa9e4066Sahrens
39*97322426SDarren J Moffat /*
40*97322426SDarren J Moffat * A prior implementation of this function had a
41*97322426SDarren J Moffat * private SHA256 implementation always wrote things out in
42*97322426SDarren J Moffat * Big Endian and there wasn't a byteswap variant of it.
43*97322426SDarren J Moffat * To preseve on disk compatibility we need to force that
44*97322426SDarren J Moffat * behaviour.
45*97322426SDarren J Moffat */
46*97322426SDarren J Moffat zcp->zc_word[0] = BE_64(tmp.zc_word[0]);
47*97322426SDarren J Moffat zcp->zc_word[1] = BE_64(tmp.zc_word[1]);
48*97322426SDarren J Moffat zcp->zc_word[2] = BE_64(tmp.zc_word[2]);
49*97322426SDarren J Moffat zcp->zc_word[3] = BE_64(tmp.zc_word[3]);
50fa9e4066Sahrens }
51