10SN/A/*
215381Svaleriep * CDDL HEADER START
30SN/A *
40SN/A * The contents of this file are subject to the terms of the
50SN/A * Common Development and Distribution License (the "License").
60SN/A * You may not use this file except in compliance with the License.
72362SN/A *
80SN/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
92362SN/A * or http://www.opensolaris.org/os/licensing.
100SN/A * See the License for the specific language governing permissions
110SN/A * and limitations under the License.
120SN/A *
130SN/A * When distributing Covered Code, include this CDDL HEADER in each
140SN/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150SN/A * If applicable, add the following below this CDDL HEADER, with the
160SN/A * fields enclosed by brackets "[]" replaced with your own identifying
170SN/A * information: Portions Copyright [yyyy] [name of copyright owner]
180SN/A *
190SN/A * CDDL HEADER END
200SN/A */
212362SN/A/*
222362SN/A * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
232362SN/A * Copyright (c) 2014, 2015 by Delphix. All rights reserved.
240SN/A * Copyright Saso Kiselkov 2013, All rights reserved.
250SN/A */
260SN/A
270SN/A#ifndef _SYS_ZIO_CHECKSUM_H
280SN/A#define	_SYS_ZIO_CHECKSUM_H
290SN/A
300SN/A#include <sys/zio.h>
3115381Svaleriep#include <zfeature_common.h>
320SN/A
330SN/A#ifdef	__cplusplus
340SN/Aextern "C" {
350SN/A#endif
360SN/A
370SN/A/*
380SN/A * Signature for checksum functions.
390SN/A */
400SN/Atypedef void zio_checksum_t(const void *data, uint64_t size,
410SN/A    const void *ctx_template, zio_cksum_t *zcp);
420SN/Atypedef void *zio_checksum_tmpl_init_t(const zio_cksum_salt_t *salt);
430SN/Atypedef void zio_checksum_tmpl_free_t(void *ctx_template);
440SN/A
450SN/Atypedef enum zio_checksum_flags {
460SN/A	/* Strong enough for metadata? */
470SN/A	ZCHECKSUM_FLAG_METADATA = (1 << 1),
485396SN/A	/* ZIO embedded checksum */
490SN/A	ZCHECKSUM_FLAG_EMBEDDED = (1 << 2),
505396SN/A	/* Strong enough for dedup (without verification)? */
510SN/A	ZCHECKSUM_FLAG_DEDUP = (1 << 3),
520SN/A	/* Uses salt value */
530SN/A	ZCHECKSUM_FLAG_SALTED = (1 << 4),
540SN/A	/* Strong enough for nopwrite? */
550SN/A	ZCHECKSUM_FLAG_NOPWRITE = (1 << 5)
560SN/A} zio_checksum_flags_t;
570SN/A
580SN/A/*
590SN/A * Information about each checksum function.
600SN/A */
610SN/Atypedef struct zio_checksum_info {
620SN/A	/* checksum function for each byteorder */
630SN/A	zio_checksum_t			*ci_func[2];
640SN/A	zio_checksum_tmpl_init_t	*ci_tmpl_init;
650SN/A	zio_checksum_tmpl_free_t	*ci_tmpl_free;
6612745Smartin	zio_checksum_flags_t		ci_flags;
670SN/A	char				*ci_name;	/* descriptive name */
680SN/A} zio_checksum_info_t;
6915381Svaleriep
7015381Svalerieptypedef struct zio_bad_cksum {
714487SN/A	zio_cksum_t		zbc_expected;
724487SN/A	zio_cksum_t		zbc_actual;
730SN/A	const char		*zbc_checksum_name;
740SN/A	uint8_t			zbc_byteswapped;
750SN/A	uint8_t			zbc_injected;
760SN/A	uint8_t			zbc_has_cksum;	/* expected/actual valid */
770SN/A} zio_bad_cksum_t;
780SN/A
790SN/Aextern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
800SN/A
810SN/A/*
820SN/A * Checksum routines.
830SN/A */
840SN/Aextern zio_checksum_t zio_checksum_SHA256;
850SN/A#ifndef __NetBSD__
860SN/Aextern zio_checksum_t zio_checksum_SHA512_native;
870SN/Aextern zio_checksum_t zio_checksum_SHA512_byteswap;
880SN/A
890SN/A/* Skein */
900SN/Aextern zio_checksum_t zio_checksum_skein_native;
910SN/Aextern zio_checksum_t zio_checksum_skein_byteswap;
920SN/Aextern zio_checksum_tmpl_init_t zio_checksum_skein_tmpl_init;
930SN/Aextern zio_checksum_tmpl_free_t zio_checksum_skein_tmpl_free;
940SN/A#endif
950SN/A
960SN/A#ifdef illumos
970SN/A/* Edon-R */
980SN/Aextern zio_checksum_t zio_checksum_edonr_native;
995396SN/Aextern zio_checksum_t zio_checksum_edonr_byteswap;
1005396SN/Aextern zio_checksum_tmpl_init_t zio_checksum_edonr_tmpl_init;
1015396SN/Aextern zio_checksum_tmpl_free_t zio_checksum_edonr_tmpl_free;
1025396SN/A#endif
1035396SN/A
1040SN/Aextern int zio_checksum_equal(spa_t *, blkptr_t *, enum zio_checksum,
1050SN/A    void *, uint64_t, uint64_t, zio_bad_cksum_t *);
1060SN/Aextern void zio_checksum_compute(zio_t *zio, enum zio_checksum checksum,
1070SN/A    void *data, uint64_t size);
1080SN/Aextern int zio_checksum_error_impl(spa_t *, blkptr_t *, enum zio_checksum,
1090SN/A    void *, uint64_t, uint64_t, zio_bad_cksum_t *);
1100SN/Aextern int zio_checksum_error(zio_t *zio, zio_bad_cksum_t *out);
1110SN/Aextern enum zio_checksum spa_dedup_checksum(spa_t *spa);
1120SN/Aextern void zio_checksum_templates_free(spa_t *spa);
1130SN/Aextern spa_feature_t zio_checksum_to_feature(enum zio_checksum cksum);
1140SN/A
1150SN/A#ifdef	__cplusplus
1160SN/A}
1170SN/A#endif
1180SN/A
1190SN/A#endif	/* _SYS_ZIO_CHECKSUM_H */
1200SN/A