1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License (the "License").
6168404Spjd * You may not use this file except in compliance with the License.
7168404Spjd *
8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9168404Spjd * or http://www.opensolaris.org/os/licensing.
10168404Spjd * See the License for the specific language governing permissions
11168404Spjd * and limitations under the License.
12168404Spjd *
13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15168404Spjd * If applicable, add the following below this CDDL HEADER, with the
16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18168404Spjd *
19168404Spjd * CDDL HEADER END
20168404Spjd */
21168404Spjd/*
22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23290757Smav * Copyright (c) 2014, 2015 by Delphix. All rights reserved.
24290757Smav * Copyright Saso Kiselkov 2013, All rights reserved.
25168404Spjd */
26168404Spjd
27168404Spjd#ifndef _SYS_ZIO_CHECKSUM_H
28168404Spjd#define	_SYS_ZIO_CHECKSUM_H
29168404Spjd
30168404Spjd#include <sys/zio.h>
31290757Smav#include <zfeature_common.h>
32168404Spjd
33168404Spjd#ifdef	__cplusplus
34168404Spjdextern "C" {
35168404Spjd#endif
36168404Spjd
37168404Spjd/*
38168404Spjd * Signature for checksum functions.
39168404Spjd */
40290757Smavtypedef void zio_checksum_t(const void *data, uint64_t size,
41290757Smav    const void *ctx_template, zio_cksum_t *zcp);
42290757Smavtypedef void *zio_checksum_tmpl_init_t(const zio_cksum_salt_t *salt);
43290757Smavtypedef void zio_checksum_tmpl_free_t(void *ctx_template);
44168404Spjd
45290757Smavtypedef enum zio_checksum_flags {
46290757Smav	/* Strong enough for metadata? */
47290757Smav	ZCHECKSUM_FLAG_METADATA = (1 << 1),
48290757Smav	/* ZIO embedded checksum */
49290757Smav	ZCHECKSUM_FLAG_EMBEDDED = (1 << 2),
50290757Smav	/* Strong enough for dedup (without verification)? */
51290757Smav	ZCHECKSUM_FLAG_DEDUP = (1 << 3),
52290757Smav	/* Uses salt value */
53290757Smav	ZCHECKSUM_FLAG_SALTED = (1 << 4),
54290757Smav	/* Strong enough for nopwrite? */
55290757Smav	ZCHECKSUM_FLAG_NOPWRITE = (1 << 5)
56290757Smav} zio_checksum_flags_t;
57290757Smav
58168404Spjd/*
59168404Spjd * Information about each checksum function.
60168404Spjd */
61168404Spjdtypedef struct zio_checksum_info {
62290757Smav	/* checksum function for each byteorder */
63290757Smav	zio_checksum_t			*ci_func[2];
64290757Smav	zio_checksum_tmpl_init_t	*ci_tmpl_init;
65290757Smav	zio_checksum_tmpl_free_t	*ci_tmpl_free;
66290757Smav	zio_checksum_flags_t		ci_flags;
67290757Smav	char				*ci_name;	/* descriptive name */
68168404Spjd} zio_checksum_info_t;
69168404Spjd
70219089Spjdtypedef struct zio_bad_cksum {
71219089Spjd	zio_cksum_t		zbc_expected;
72219089Spjd	zio_cksum_t		zbc_actual;
73219089Spjd	const char		*zbc_checksum_name;
74219089Spjd	uint8_t			zbc_byteswapped;
75219089Spjd	uint8_t			zbc_injected;
76219089Spjd	uint8_t			zbc_has_cksum;	/* expected/actual valid */
77219089Spjd} zio_bad_cksum_t;
78219089Spjd
79168404Spjdextern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
80168404Spjd
81168404Spjd/*
82168404Spjd * Checksum routines.
83168404Spjd */
84290757Smavextern zio_checksum_t zio_checksum_SHA256;
85290757Smav#ifdef illumos
86290757Smavextern zio_checksum_t zio_checksum_SHA512_native;
87290757Smavextern zio_checksum_t zio_checksum_SHA512_byteswap;
88168404Spjd
89290757Smav/* Skein */
90290757Smavextern zio_checksum_t zio_checksum_skein_native;
91290757Smavextern zio_checksum_t zio_checksum_skein_byteswap;
92290757Smavextern zio_checksum_tmpl_init_t zio_checksum_skein_tmpl_init;
93290757Smavextern zio_checksum_tmpl_free_t zio_checksum_skein_tmpl_free;
94290757Smav
95290757Smav/* Edon-R */
96290757Smavextern zio_checksum_t zio_checksum_edonr_native;
97290757Smavextern zio_checksum_t zio_checksum_edonr_byteswap;
98290757Smavextern zio_checksum_tmpl_init_t zio_checksum_edonr_tmpl_init;
99290757Smavextern zio_checksum_tmpl_free_t zio_checksum_edonr_tmpl_free;
100290757Smav#endif
101290757Smav
102307266Smavextern int zio_checksum_equal(spa_t *, blkptr_t *, enum zio_checksum,
103307266Smav    void *, uint64_t, uint64_t, zio_bad_cksum_t *);
104185029Spjdextern void zio_checksum_compute(zio_t *zio, enum zio_checksum checksum,
105168404Spjd    void *data, uint64_t size);
106307266Smavextern int zio_checksum_error_impl(spa_t *, blkptr_t *, enum zio_checksum,
107307266Smav    void *, uint64_t, uint64_t, zio_bad_cksum_t *);
108219089Spjdextern int zio_checksum_error(zio_t *zio, zio_bad_cksum_t *out);
109219089Spjdextern enum zio_checksum spa_dedup_checksum(spa_t *spa);
110290757Smavextern void zio_checksum_templates_free(spa_t *spa);
111290757Smavextern spa_feature_t zio_checksum_to_feature(enum zio_checksum cksum);
112168404Spjd
113168404Spjd#ifdef	__cplusplus
114168404Spjd}
115168404Spjd#endif
116168404Spjd
117168404Spjd#endif	/* _SYS_ZIO_CHECKSUM_H */
118