Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenZFS 4185 - add new cryptographic checksums to ZFS: SHA-512, Skein, Edon-R #4760

Merged
merged 4 commits into from
Oct 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include config/tgz.am

SUBDIRS = include rpm
if CONFIG_USER
SUBDIRS += udev etc man scripts tests lib cmd contrib
SUBDIRS += udev etc man scripts lib tests cmd contrib
endif
if CONFIG_KERNEL
SUBDIRS += module
Expand Down
8 changes: 4 additions & 4 deletions cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -5654,16 +5654,16 @@ ztest_fletcher(ztest_ds_t *zd, uint64_t id)
*ptr = ztest_random(UINT_MAX);

VERIFY0(fletcher_4_impl_set("scalar"));
fletcher_4_native(buf, size, &zc_ref);
fletcher_4_byteswap(buf, size, &zc_ref_byteswap);
fletcher_4_native(buf, size, NULL, &zc_ref);
fletcher_4_byteswap(buf, size, NULL, &zc_ref_byteswap);

VERIFY0(fletcher_4_impl_set("cycle"));
while (run_count-- > 0) {
zio_cksum_t zc;
zio_cksum_t zc_byteswap;

fletcher_4_byteswap(buf, size, &zc_byteswap);
fletcher_4_native(buf, size, &zc);
fletcher_4_byteswap(buf, size, NULL, &zc_byteswap);
fletcher_4_native(buf, size, NULL, &zc);

VERIFY0(bcmp(&zc, &zc_ref, sizeof (zc)));
VERIFY0(bcmp(&zc_byteswap, &zc_ref_byteswap,
Expand Down
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ AC_PROG_INSTALL
AC_PROG_CC
AC_PROG_LIBTOOL
AM_PROG_AS
AM_PROG_CC_C_O

ZFS_AC_LICENSE
ZFS_AC_PACKAGE
Expand Down Expand Up @@ -178,6 +179,7 @@ AC_CONFIG_FILES([
tests/zfs-tests/tests/functional/cache/Makefile
tests/zfs-tests/tests/functional/cachefile/Makefile
tests/zfs-tests/tests/functional/casenorm/Makefile
tests/zfs-tests/tests/functional/checksum/Makefile
tests/zfs-tests/tests/functional/clean_mirror/Makefile
tests/zfs-tests/tests/functional/cli_root/Makefile
tests/zfs-tests/tests/functional/cli_root/zdb/Makefile
Expand Down
3 changes: 3 additions & 0 deletions include/sys/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ COMMON_H = \
$(top_srcdir)/include/sys/dsl_scan.h \
$(top_srcdir)/include/sys/dsl_synctask.h \
$(top_srcdir)/include/sys/dsl_userhold.h \
$(top_srcdir)/include/sys/edonr.h \
$(top_srcdir)/include/sys/efi_partition.h \
$(top_srcdir)/include/sys/metaslab.h \
$(top_srcdir)/include/sys/metaslab_impl.h \
Expand All @@ -46,6 +47,8 @@ COMMON_H = \
$(top_srcdir)/include/sys/sa.h \
$(top_srcdir)/include/sys/sa_impl.h \
$(top_srcdir)/include/sys/sdt.h \
$(top_srcdir)/include/sys/sha2.h \
$(top_srcdir)/include/sys/skein.h \
$(top_srcdir)/include/sys/spa_boot.h \
$(top_srcdir)/include/sys/space_map.h \
$(top_srcdir)/include/sys/space_reftree.h \
Expand Down
6 changes: 6 additions & 0 deletions include/sys/crypto/icp.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@
int aes_mod_init(void);
int aes_mod_fini(void);

int edonr_mod_init(void);
int edonr_mod_fini(void);

int sha1_mod_init(void);
int sha1_mod_fini(void);

int sha2_mod_init(void);
int sha2_mod_fini(void);

int skein_mod_init(void);
int skein_mod_fini(void);

int icp_init(void);
void icp_fini(void);

Expand Down
2 changes: 2 additions & 0 deletions include/sys/dmu.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
* Copyright 2014 HybridCluster. All rights reserved.
* Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
* Copyright 2013 Saso Kiselkov. All rights reserved.
*/

/* Portions Copyright 2010 Robert Milkowski */
Expand Down Expand Up @@ -317,6 +318,7 @@ typedef struct dmu_buf {
#define DMU_POOL_FREE_BPOBJ "free_bpobj"
#define DMU_POOL_BPTREE_OBJ "bptree_obj"
#define DMU_POOL_EMPTY_BPOBJ "empty_bpobj"
#define DMU_POOL_CHECKSUM_SALT "org.illumos:checksum_salt"
#define DMU_POOL_VDEV_ZAP_MAP "com.delphix:vdev_zap_map"

/*
Expand Down
98 changes: 98 additions & 0 deletions include/sys/edonr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* IDI,NTNU
*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://opensource.org/licenses/CDDL-1.0.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright (C) 2009, 2010, Jorn Amundsen <[email protected]>
*
* Tweaked Edon-R implementation for SUPERCOP, based on NIST API.
*
* $Id: edonr.h 517 2013-02-17 20:34:39Z joern $
*/
/*
* Portions copyright (c) 2013, Saso Kiselkov, All rights reserved
*/

#ifndef _SYS_EDONR_H_
#define _SYS_EDONR_H_

#ifdef __cplusplus
extern "C" {
#endif

#ifdef _KERNEL
#include <sys/types.h>
#else
#include <stdint.h> /* uint32_t... */
#include <stdlib.h> /* size_t ... */
#endif

/*
* EdonR allows to call EdonRUpdate() consecutively only if the total length
* of stored unprocessed data and the new supplied data is less than or equal
* to the BLOCK_SIZE on which the compression functions operates.
* Otherwise an assertion failure is invoked.
*/

/* Specific algorithm definitions */
#define EdonR224_DIGEST_SIZE 28
#define EdonR224_BLOCK_SIZE 64
#define EdonR256_DIGEST_SIZE 32
#define EdonR256_BLOCK_SIZE 64
#define EdonR384_DIGEST_SIZE 48
#define EdonR384_BLOCK_SIZE 128
#define EdonR512_DIGEST_SIZE 64
#define EdonR512_BLOCK_SIZE 128

#define EdonR256_BLOCK_BITSIZE 512
#define EdonR512_BLOCK_BITSIZE 1024

typedef struct {
uint32_t DoublePipe[16];
uint8_t LastPart[EdonR256_BLOCK_SIZE * 2];
} EdonRData256;
typedef struct {
uint64_t DoublePipe[16];
uint8_t LastPart[EdonR512_BLOCK_SIZE * 2];
} EdonRData512;

typedef struct {
size_t hashbitlen;

/* + algorithm specific parameters */
int unprocessed_bits;
uint64_t bits_processed;
union {
EdonRData256 p256[1];
EdonRData512 p512[1];
} pipe[1];
} EdonRState;

void EdonRInit(EdonRState *state, size_t hashbitlen);
void EdonRUpdate(EdonRState *state, const uint8_t *data, size_t databitlen);
void EdonRFinal(EdonRState *state, uint8_t *hashval);
void EdonRHash(size_t hashbitlen, const uint8_t *data, size_t databitlen,
uint8_t *hashval);

#ifdef __cplusplus
}
#endif

#endif /* _SYS_EDONR_H_ */
39 changes: 39 additions & 0 deletions module/icp/include/sha2/sha2.h → include/sys/sha2.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
#ifndef _SYS_SHA2_H
#define _SYS_SHA2_H

#ifdef _KERNEL
#include <sys/types.h> /* for uint_* */
#else
#include <stdint.h>
#endif

#ifdef __cplusplus
extern "C" {
Expand All @@ -37,12 +41,27 @@ extern "C" {
#define SHA2_HMAC_MAX_KEY_LEN INT_MAX /* SHA2-HMAC max key length in bytes */

#define SHA256_DIGEST_LENGTH 32 /* SHA256 digest length in bytes */
#define SHA384_DIGEST_LENGTH 48 /* SHA384 digest length in bytes */
#define SHA512_DIGEST_LENGTH 64 /* SHA512 digest length in bytes */

/* Truncated versions of SHA-512 according to FIPS-180-4, section 5.3.6 */
#define SHA512_224_DIGEST_LENGTH 28 /* SHA512/224 digest length */
#define SHA512_256_DIGEST_LENGTH 32 /* SHA512/256 digest length */

#define SHA256_HMAC_BLOCK_SIZE 64 /* SHA256-HMAC block size */
#define SHA512_HMAC_BLOCK_SIZE 128 /* SHA512-HMAC block size */

#define SHA256 0
#define SHA256_HMAC 1
#define SHA256_HMAC_GEN 2
#define SHA384 3
#define SHA384_HMAC 4
#define SHA384_HMAC_GEN 5
#define SHA512 6
#define SHA512_HMAC 7
#define SHA512_HMAC_GEN 8
#define SHA512_224 9
#define SHA512_256 10

/*
* SHA2 context.
Expand Down Expand Up @@ -87,6 +106,18 @@ extern void SHA256Update(SHA256_CTX *, const void *, size_t);

extern void SHA256Final(void *, SHA256_CTX *);

extern void SHA384Init(SHA384_CTX *);

extern void SHA384Update(SHA384_CTX *, const void *, size_t);

extern void SHA384Final(void *, SHA384_CTX *);

extern void SHA512Init(SHA512_CTX *);

extern void SHA512Update(SHA512_CTX *, const void *, size_t);

extern void SHA512Final(void *, SHA512_CTX *);

#ifdef _SHA2_IMPL
/*
* The following types/functions are all private to the implementation
Expand All @@ -105,6 +136,14 @@ typedef enum sha2_mech_type {
SHA256_MECH_INFO_TYPE, /* SUN_CKM_SHA256 */
SHA256_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC */
SHA256_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA256_HMAC_GENERAL */
SHA384_MECH_INFO_TYPE, /* SUN_CKM_SHA384 */
SHA384_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC */
SHA384_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA384_HMAC_GENERAL */
SHA512_MECH_INFO_TYPE, /* SUN_CKM_SHA512 */
SHA512_HMAC_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC */
SHA512_HMAC_GEN_MECH_INFO_TYPE, /* SUN_CKM_SHA512_HMAC_GENERAL */
SHA512_224_MECH_INFO_TYPE, /* SUN_CKM_SHA512_224 */
SHA512_256_MECH_INFO_TYPE /* SUN_CKM_SHA512_256 */
} sha2_mech_type_t;

#endif /* _SHA2_IMPL */
Expand Down
Loading