xref: /freebsd/sys/contrib/openzfs/include/sys/spa_checksum.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * The contents of this file are subject to the terms of the
6  * Common Development and Distribution License (the "License").
7  * You may not use this file except in compliance with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or https://opensource.org/licenses/CDDL-1.0.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SPA_CHECKSUM_H
28 #define	_SPA_CHECKSUM_H
29 
30 #include <sys/types.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
38  */
39 typedef struct zio_cksum {
40 	uint64_t	zc_word[4];
41 } zio_cksum_t;
42 
43 #define	ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3)	\
44 {						\
45 	(zcp)->zc_word[0] = w0;			\
46 	(zcp)->zc_word[1] = w1;			\
47 	(zcp)->zc_word[2] = w2;			\
48 	(zcp)->zc_word[3] = w3;			\
49 }
50 
51 #define	ZIO_CHECKSUM_EQUAL(zc1, zc2) \
52 	(0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
53 	((zc1).zc_word[1] - (zc2).zc_word[1]) | \
54 	((zc1).zc_word[2] - (zc2).zc_word[2]) | \
55 	((zc1).zc_word[3] - (zc2).zc_word[3])))
56 
57 #define	ZIO_CHECKSUM_IS_ZERO(zc) \
58 	(0 == ((zc)->zc_word[0] | (zc)->zc_word[1] | \
59 	(zc)->zc_word[2] | (zc)->zc_word[3]))
60 
61 #define	ZIO_CHECKSUM_BSWAP(zcp)					\
62 {								\
63 	(zcp)->zc_word[0] = BSWAP_64((zcp)->zc_word[0]);	\
64 	(zcp)->zc_word[1] = BSWAP_64((zcp)->zc_word[1]);	\
65 	(zcp)->zc_word[2] = BSWAP_64((zcp)->zc_word[2]);	\
66 	(zcp)->zc_word[3] = BSWAP_64((zcp)->zc_word[3]);	\
67 }
68 
69 #ifdef	__cplusplus
70 }
71 #endif
72 
73 #endif
74