From 0144ad3e7873a3b8904f2d8f8c0429029d45993a Mon Sep 17 00:00:00 2001 From: Allan Jude Date: Tue, 31 May 2016 04:12:14 +0000 Subject: [PATCH] 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. --- .../contrib/opensolaris/common/zfs/zfeature_common.c | 4 ++-- .../contrib/opensolaris/common/zfs/zfeature_common.h | 2 +- sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c | 4 ++-- .../contrib/opensolaris/uts/common/Makefile.files | 1 + .../contrib/opensolaris/uts/common/fs/zfs/sha256.c | 12 ++++++------ .../opensolaris/uts/common/fs/zfs/skein_zfs.c | 6 +++++- .../contrib/opensolaris/uts/common/fs/zfs/sys/zio.h | 2 +- .../opensolaris/uts/common/fs/zfs/sys/zio_checksum.h | 2 +- .../opensolaris/uts/common/fs/zfs/zio_checksum.c | 6 +++--- sys/conf/files | 3 +++ sys/crypto/skein/skein_port.h | 2 ++ sys/modules/zfs/Makefile | 3 +++ 12 files changed, 30 insertions(+), 17 deletions(-) diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c b/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c index 57e5f5e579dc..8736424f2cc5 100644 --- a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c +++ b/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.c @@ -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.", diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h b/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h index eea60f37e9bd..fa7e93612e59 100644 --- a/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h +++ b/sys/cddl/contrib/opensolaris/common/zfs/zfeature_common.h @@ -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 diff --git a/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c b/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c index c310a67b2721..079d86043f4d 100644 --- a/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c +++ b/sys/cddl/contrib/opensolaris/common/zfs/zfs_prop.c @@ -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 diff --git a/sys/cddl/contrib/opensolaris/uts/common/Makefile.files b/sys/cddl/contrib/opensolaris/uts/common/Makefile.files index 77c7b1d0c22d..086dd05901fc 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/Makefile.files +++ b/sys/cddl/contrib/opensolaris/uts/common/Makefile.files @@ -74,6 +74,7 @@ ZFS_COMMON_OBJS += \ rrwlock.o \ sa.o \ sha256.o \ + skein_zfs.o \ spa.o \ spa_config.o \ spa_errlog.o \ diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sha256.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sha256.c index e684b21b3dd2..f3630a320e7c 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sha256.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sha256.c @@ -29,8 +29,10 @@ #include #ifdef _KERNEL #include +#include #else #include +#include #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 diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/skein_zfs.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/skein_zfs.c index 65923403968d..f8d1cf9dd1a6 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/skein_zfs.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/skein_zfs.c @@ -23,7 +23,11 @@ */ #include #include -#include +#ifdef _KERNEL +#include +#else +#include +#endif /* * Computes a native 256-bit skein MAC checksum. Please note that this diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h index 56c821a0a96e..bda9afa14e9c 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio.h @@ -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 diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_checksum.h b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_checksum.h index 0a9d772591d1..6cba764f24e1 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_checksum.h +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zio_checksum.h @@ -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; diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_checksum.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_checksum.c index dac118af67e1..997e3133f3d8 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_checksum.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio_checksum.c @@ -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); } diff --git a/sys/conf/files b/sys/conf/files index 364dc5455a85..a0c1ba317e4e 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -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 diff --git a/sys/crypto/skein/skein_port.h b/sys/crypto/skein/skein_port.h index 65f3405eecbe..7025a51673ff 100644 --- a/sys/crypto/skein/skein_port.h +++ b/sys/crypto/skein/skein_port.h @@ -19,7 +19,9 @@ #include #include +#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 */ diff --git a/sys/modules/zfs/Makefile b/sys/modules/zfs/Makefile index a824422e69fc..eb33a5cc54f9 100644 --- a/sys/modules/zfs/Makefile +++ b/sys/modules/zfs/Makefile @@ -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