xref: /onnv-gate/usr/src/uts/common/fs/zfs/sha256.c (revision 11328:9e61ee22688a)
1789Sahrens /*
2789Sahrens  * CDDL HEADER START
3789Sahrens  *
4789Sahrens  * The contents of this file are subject to the terms of the
55688Sbonwick  * Common Development and Distribution License (the "License").
65688Sbonwick  * You may not use this file except in compliance with the License.
7789Sahrens  *
8789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens  * or http://www.opensolaris.org/os/licensing.
10789Sahrens  * See the License for the specific language governing permissions
11789Sahrens  * and limitations under the License.
12789Sahrens  *
13789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens  *
19789Sahrens  * CDDL HEADER END
20789Sahrens  */
21789Sahrens /*
2210922SJeff.Bonwick@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens #include <sys/zfs_context.h>
26789Sahrens #include <sys/zio.h>
27*11328SDarren.Moffat@Sun.COM #include <sys/sha2.h>
28789Sahrens 
29789Sahrens void
zio_checksum_SHA256(const void * buf,uint64_t size,zio_cksum_t * zcp)30789Sahrens zio_checksum_SHA256(const void *buf, uint64_t size, zio_cksum_t *zcp)
31789Sahrens {
32*11328SDarren.Moffat@Sun.COM 	SHA2_CTX ctx;
33*11328SDarren.Moffat@Sun.COM 	zio_cksum_t tmp;
34789Sahrens 
35*11328SDarren.Moffat@Sun.COM 	SHA2Init(SHA256, &ctx);
36*11328SDarren.Moffat@Sun.COM 	SHA2Update(&ctx, buf, size);
37*11328SDarren.Moffat@Sun.COM 	SHA2Final(&tmp, &ctx);
38789Sahrens 
39*11328SDarren.Moffat@Sun.COM 	/*
40*11328SDarren.Moffat@Sun.COM 	 * A prior implementation of this function had a
41*11328SDarren.Moffat@Sun.COM 	 * private SHA256 implementation always wrote things out in
42*11328SDarren.Moffat@Sun.COM 	 * Big Endian and there wasn't a byteswap variant of it.
43*11328SDarren.Moffat@Sun.COM 	 * To preseve on disk compatibility we need to force that
44*11328SDarren.Moffat@Sun.COM 	 * behaviour.
45*11328SDarren.Moffat@Sun.COM 	 */
46*11328SDarren.Moffat@Sun.COM 	zcp->zc_word[0] = BE_64(tmp.zc_word[0]);
47*11328SDarren.Moffat@Sun.COM 	zcp->zc_word[1] = BE_64(tmp.zc_word[1]);
48*11328SDarren.Moffat@Sun.COM 	zcp->zc_word[2] = BE_64(tmp.zc_word[2]);
49*11328SDarren.Moffat@Sun.COM 	zcp->zc_word[3] = BE_64(tmp.zc_word[3]);
50789Sahrens }
51