Connect the SHA-512t256 and Skein hashing algorithms to ZFS

Support for the new hashing algorithms in ZFS was introduced in r289422
However it was disconnected because FreeBSD lacked implementations of
SHA-512 (truncated to 256 bits), and Skein.

These implementations were introduced in r300921 and r300966 respectively

This commit connects them to ZFS and enabled these new checksum algorithms

This new algorithms are not supported by the boot blocks, so do not use them
on your root dataset if you boot from ZFS.

Relnotes:	yes
Sponsored by:	ScaleEngine Inc.
This commit is contained in:
Allan Jude 2016-05-31 04:12:14 +00:00
parent 387d355588
commit 0144ad3e78
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=301010
12 changed files with 30 additions and 17 deletions

View File

@ -232,8 +232,6 @@ zpool_feature_init(void)
"org.open-zfs:large_blocks", "large_blocks",
"Support for blocks larger than 128KB.",
ZFEATURE_FLAG_PER_DATASET, large_blocks_deps);
#ifdef illumos
zfeature_register(SPA_FEATURE_SHA512,
"org.illumos:sha512", "sha512",
"SHA-512/256 hash algorithm.",
@ -242,6 +240,8 @@ zpool_feature_init(void)
"org.illumos:skein", "skein",
"Skein hash algorithm.",
ZFEATURE_FLAG_PER_DATASET, NULL);
#ifdef illumos
zfeature_register(SPA_FEATURE_EDONR,
"org.illumos:edonr", "edonr",
"Edon-R hash algorithm.",

View File

@ -52,9 +52,9 @@ typedef enum spa_feature {
SPA_FEATURE_BOOKMARKS,
SPA_FEATURE_FS_SS_LIMIT,
SPA_FEATURE_LARGE_BLOCKS,
#ifdef illumos
SPA_FEATURE_SHA512,
SPA_FEATURE_SKEIN,
#ifdef illumos
SPA_FEATURE_EDONR,
#endif
SPA_FEATURES

View File

@ -72,9 +72,9 @@ zfs_prop_init(void)
{ "fletcher4", ZIO_CHECKSUM_FLETCHER_4 },
{ "sha256", ZIO_CHECKSUM_SHA256 },
{ "noparity", ZIO_CHECKSUM_NOPARITY },
#ifdef illumos
{ "sha512", ZIO_CHECKSUM_SHA512 },
{ "skein", ZIO_CHECKSUM_SKEIN },
#ifdef illumos
{ "edonr", ZIO_CHECKSUM_EDONR },
#endif
{ NULL }
@ -87,13 +87,13 @@ zfs_prop_init(void)
{ "sha256", ZIO_CHECKSUM_SHA256 },
{ "sha256,verify",
ZIO_CHECKSUM_SHA256 | ZIO_CHECKSUM_VERIFY },
#ifdef illumos
{ "sha512", ZIO_CHECKSUM_SHA512 },
{ "sha512,verify",
ZIO_CHECKSUM_SHA512 | ZIO_CHECKSUM_VERIFY },
{ "skein", ZIO_CHECKSUM_SKEIN },
{ "skein,verify",
ZIO_CHECKSUM_SKEIN | ZIO_CHECKSUM_VERIFY },
#ifdef illumos
{ "edonr,verify",
ZIO_CHECKSUM_EDONR | ZIO_CHECKSUM_VERIFY },
#endif

View File

@ -74,6 +74,7 @@ ZFS_COMMON_OBJS += \
rrwlock.o \
sa.o \
sha256.o \
skein_zfs.o \
spa.o \
spa_config.o \
spa_errlog.o \

View File

@ -29,8 +29,10 @@
#include <sys/zio.h>
#ifdef _KERNEL
#include <crypto/sha2/sha256.h>
#include <crypto/sha2/sha512t.h>
#else
#include <sha256.h>
#include <sha512t.h>
#endif
/*ARGSUSED*/
@ -58,17 +60,16 @@ zio_checksum_SHA256(const void *buf, uint64_t size,
zcp->zc_word[3] = BE_64(tmp.zc_word[3]);
}
#ifdef illumos
/*ARGSUSED*/
void
zio_checksum_SHA512_native(const void *buf, uint64_t size,
const void *ctx_template, zio_cksum_t *zcp)
{
SHA2_CTX ctx;
SHA512_CTX ctx;
SHA2Init(SHA512_256, &ctx);
SHA2Update(&ctx, buf, size);
SHA2Final(zcp, &ctx);
SHA512_256_Init(&ctx);
SHA512_256_Update(&ctx, buf, size);
SHA512_256_Final((unsigned char *)zcp, &ctx);
}
/*ARGSUSED*/
@ -84,4 +85,3 @@ zio_checksum_SHA512_byteswap(const void *buf, uint64_t size,
zcp->zc_word[2] = BSWAP_64(tmp.zc_word[2]);
zcp->zc_word[3] = BSWAP_64(tmp.zc_word[3]);
}
#endif

View File

@ -23,7 +23,11 @@
*/
#include <sys/zfs_context.h>
#include <sys/zio.h>
#include <sys/skein.h>
#ifdef _KERNEL
#include <crypto/skein/skein.h>
#else
#include <skein.h>
#endif
/*
* Computes a native 256-bit skein MAC checksum. Please note that this

View File

@ -82,9 +82,9 @@ enum zio_checksum {
ZIO_CHECKSUM_SHA256,
ZIO_CHECKSUM_ZILOG2,
ZIO_CHECKSUM_NOPARITY,
#ifdef illumos
ZIO_CHECKSUM_SHA512,
ZIO_CHECKSUM_SKEIN,
#ifdef illumos
ZIO_CHECKSUM_EDONR,
#endif
ZIO_CHECKSUM_FUNCTIONS

View File

@ -82,7 +82,6 @@ extern zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS];
* Checksum routines.
*/
extern zio_checksum_t zio_checksum_SHA256;
#ifdef illumos
extern zio_checksum_t zio_checksum_SHA512_native;
extern zio_checksum_t zio_checksum_SHA512_byteswap;
@ -92,6 +91,7 @@ extern zio_checksum_t zio_checksum_skein_byteswap;
extern zio_checksum_tmpl_init_t zio_checksum_skein_tmpl_init;
extern zio_checksum_tmpl_free_t zio_checksum_skein_tmpl_free;
#ifdef illumos
/* Edon-R */
extern zio_checksum_t zio_checksum_edonr_native;
extern zio_checksum_t zio_checksum_edonr_byteswap;

View File

@ -123,7 +123,6 @@ zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = {
NULL, NULL, ZCHECKSUM_FLAG_EMBEDDED, "zilog2"},
{{zio_checksum_off, zio_checksum_off},
NULL, NULL, 0, "noparity"},
#ifdef illumos
{{zio_checksum_SHA512_native, zio_checksum_SHA512_byteswap},
NULL, NULL, ZCHECKSUM_FLAG_METADATA | ZCHECKSUM_FLAG_DEDUP |
ZCHECKSUM_FLAG_NOPWRITE, "sha512"},
@ -131,6 +130,7 @@ zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = {
zio_checksum_skein_tmpl_init, zio_checksum_skein_tmpl_free,
ZCHECKSUM_FLAG_METADATA | ZCHECKSUM_FLAG_DEDUP |
ZCHECKSUM_FLAG_SALTED | ZCHECKSUM_FLAG_NOPWRITE, "skein"},
#ifdef illumos
{{zio_checksum_edonr_native, zio_checksum_edonr_byteswap},
zio_checksum_edonr_tmpl_init, zio_checksum_edonr_tmpl_free,
ZCHECKSUM_FLAG_METADATA | ZCHECKSUM_FLAG_SALTED |
@ -145,7 +145,6 @@ zio_checksum_info_t zio_checksum_table[ZIO_CHECKSUM_FUNCTIONS] = {
spa_feature_t
zio_checksum_to_feature(enum zio_checksum cksum)
{
#ifdef illumos
VERIFY((cksum & ~ZIO_CHECKSUM_MASK) == 0);
switch (cksum) {
@ -153,10 +152,11 @@ zio_checksum_to_feature(enum zio_checksum cksum)
return (SPA_FEATURE_SHA512);
case ZIO_CHECKSUM_SKEIN:
return (SPA_FEATURE_SKEIN);
#ifdef illumos
case ZIO_CHECKSUM_EDONR:
return (SPA_FEATURE_EDONR);
}
#endif
}
return (SPA_FEATURE_NONE);
}

View File

@ -197,6 +197,7 @@ cddl/contrib/opensolaris/uts/common/fs/zfs/refcount.c optional zfs compile-wit
cddl/contrib/opensolaris/uts/common/fs/zfs/rrwlock.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/fs/zfs/sa.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/fs/zfs/sha256.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/fs/zfs/skein_zfs.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/fs/zfs/spa.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/fs/zfs/spa_config.c optional zfs compile-with "${ZFS_C}"
cddl/contrib/opensolaris/uts/common/fs/zfs/spa_errlog.c optional zfs compile-with "${ZFS_C}"
@ -577,6 +578,8 @@ crypto/sha1.c optional carp | crypto | ipsec | \
crypto/sha2/sha256c.c optional crypto | geom_bde | ipsec | random !random_loadable | \
sctp | zfs
crypto/sha2/sha512c.c optional crypto | geom_bde | ipsec | zfs
crypto/skein/skein.c optional crypto | zfs
crypto/skein/skein_block.c optional crypto | zfs
crypto/siphash/siphash.c optional inet | inet6
crypto/siphash/siphash_test.c optional inet | inet6
ddb/db_access.c optional ddb

View File

@ -19,7 +19,9 @@
#include <sys/endian.h>
#include <sys/types.h>
#ifndef _OPENSOLARIS_SYS_TYPES_H_ /* Avoid redefining this typedef */
typedef unsigned int uint_t; /* native unsigned integer */
#endif
typedef u_int8_t u08b_t; /* 8-bit unsigned integer */
typedef u_int32_t uint_32t; /* 32-bit unsigned integer */
typedef u_int64_t u64b_t; /* 64-bit unsigned integer */

View File

@ -70,6 +70,9 @@ SRCS+= zutil.c
.PATH: ${SYSDIR}/crypto/sha2
SRCS+= sha256c.c sha512c.c
.PATH: ${SYSDIR}/crypto/skein
SRCS+= skein.c skein_block.c
.PATH: ${SUNW}/common/zfs
.include "${SUNW}/uts/common/Makefile.files"
.PATH: ${SUNW}/uts/common/fs/zfs