mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2024-12-27 19:39:35 +03:00
3c67d83a8a
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Prakash Surya <prakash.surya@delphix.com>
Reviewed by: Saso Kiselkov <saso.kiselkov@nexenta.com>
Reviewed by: Richard Lowe <richlowe@richlowe.net>
Approved by: Garrett D'Amore <garrett@damore.org>
Ported by: Tony Hutter <hutter2@llnl.gov>
OpenZFS-issue: https://www.illumos.org/issues/4185
OpenZFS-commit: https://github.com/openzfs/openzfs/commit/45818ee
Porting Notes:
This code is ported on top of the Illumos Crypto Framework code:
b5e030c8db
The list of porting changes includes:
- Copied module/icp/include/sha2/sha2.h directly from illumos
- Removed from module/icp/algs/sha2/sha2.c:
#pragma inline(SHA256Init, SHA384Init, SHA512Init)
- Added 'ctx' to lib/libzfs/libzfs_sendrecv.c:zio_checksum_SHA256() since
it now takes in an extra parameter.
- Added CTASSERT() to assert.h from for module/zfs/edonr_zfs.c
- Added skein & edonr to libicp/Makefile.am
- Added sha512.S. It was generated from sha512-x86_64.pl in Illumos.
- Updated ztest.c with new fletcher_4_*() args; used NULL for new CTX argument.
- In icp/algs/edonr/edonr_byteorder.h, Removed the #if defined(__linux) section
to not #include the non-existant endian.h.
- In skein_test.c, renane NULL to 0 in "no test vector" array entries to get
around a compiler warning.
- Fixup test files:
- Rename <sys/varargs.h> -> <varargs.h>, <strings.h> -> <string.h>,
- Remove <note.h> and define NOTE() as NOP.
- Define u_longlong_t
- Rename "#!/usr/bin/ksh" -> "#!/bin/ksh -p"
- Rename NULL to 0 in "no test vector" array entries to get around a
compiler warning.
- Remove "for isa in $($ISAINFO); do" stuff
- Add/update Makefiles
- Add some userspace headers like stdio.h/stdlib.h in places of
sys/types.h.
- EXPORT_SYMBOL *_Init/*_Update/*_Final... routines in ICP modules.
- Update scripts/zfs2zol-patch.sed
- include <sys/sha2.h> in sha2_impl.h
- Add sha2.h to include/sys/Makefile.am
- Add skein and edonr dirs to icp Makefile
- Add new checksums to zpool_get.cfg
- Move checksum switch block from zfs_secpolicy_setprop() to
zfs_check_settable()
- Fix -Wuninitialized error in edonr_byteorder.h on PPC
- Fix stack frame size errors on ARM32
- Don't unroll loops in Skein on 32-bit to save stack space
- Add memory barriers in sha2.c on 32-bit to save stack space
- Add filetest_001_pos.ksh checksum sanity test
- Add option to write psudorandom data in file_write utility
129 lines
3.7 KiB
C
129 lines
3.7 KiB
C
/*
|
|
* Platform-specific definitions for Skein hash function.
|
|
*
|
|
* Source code author: Doug Whiting, 2008.
|
|
*
|
|
* This algorithm and source code is released to the public domain.
|
|
*
|
|
* Many thanks to Brian Gladman for his portable header files.
|
|
*
|
|
* To port Skein to an "unsupported" platform, change the definitions
|
|
* in this file appropriately.
|
|
*/
|
|
/* Copyright 2013 Doug Whiting. This code is released to the public domain. */
|
|
|
|
#ifndef _SKEIN_PORT_H_
|
|
#define _SKEIN_PORT_H_
|
|
|
|
#include <sys/types.h> /* get integer type definitions */
|
|
#include <sys/systm.h> /* for bcopy() */
|
|
|
|
#ifndef RotL_64
|
|
#define RotL_64(x, N) (((x) << (N)) | ((x) >> (64 - (N))))
|
|
#endif
|
|
|
|
/*
|
|
* Skein is "natively" little-endian (unlike SHA-xxx), for optimal
|
|
* performance on x86 CPUs. The Skein code requires the following
|
|
* definitions for dealing with endianness:
|
|
*
|
|
* SKEIN_NEED_SWAP: 0 for little-endian, 1 for big-endian
|
|
* Skein_Put64_LSB_First
|
|
* Skein_Get64_LSB_First
|
|
* Skein_Swap64
|
|
*
|
|
* If SKEIN_NEED_SWAP is defined at compile time, it is used here
|
|
* along with the portable versions of Put64/Get64/Swap64, which
|
|
* are slow in general.
|
|
*
|
|
* Otherwise, an "auto-detect" of endianness is attempted below.
|
|
* If the default handling doesn't work well, the user may insert
|
|
* platform-specific code instead (e.g., for big-endian CPUs).
|
|
*
|
|
*/
|
|
#ifndef SKEIN_NEED_SWAP /* compile-time "override" for endianness? */
|
|
|
|
#include <sys/isa_defs.h> /* get endianness selection */
|
|
|
|
#define PLATFORM_MUST_ALIGN _ALIGNMENT_REQUIRED
|
|
#if defined(_BIG_ENDIAN)
|
|
/* here for big-endian CPUs */
|
|
#define SKEIN_NEED_SWAP (1)
|
|
#else
|
|
/* here for x86 and x86-64 CPUs (and other detected little-endian CPUs) */
|
|
#define SKEIN_NEED_SWAP (0)
|
|
#if PLATFORM_MUST_ALIGN == 0 /* ok to use "fast" versions? */
|
|
#define Skein_Put64_LSB_First(dst08, src64, bCnt) bcopy(src64, dst08, bCnt)
|
|
#define Skein_Get64_LSB_First(dst64, src08, wCnt) \
|
|
bcopy(src08, dst64, 8 * (wCnt))
|
|
#endif
|
|
#endif
|
|
|
|
#endif /* ifndef SKEIN_NEED_SWAP */
|
|
|
|
/*
|
|
* Provide any definitions still needed.
|
|
*/
|
|
#ifndef Skein_Swap64 /* swap for big-endian, nop for little-endian */
|
|
#if SKEIN_NEED_SWAP
|
|
#define Skein_Swap64(w64) \
|
|
(((((uint64_t)(w64)) & 0xFF) << 56) | \
|
|
(((((uint64_t)(w64)) >> 8) & 0xFF) << 48) | \
|
|
(((((uint64_t)(w64)) >> 16) & 0xFF) << 40) | \
|
|
(((((uint64_t)(w64)) >> 24) & 0xFF) << 32) | \
|
|
(((((uint64_t)(w64)) >> 32) & 0xFF) << 24) | \
|
|
(((((uint64_t)(w64)) >> 40) & 0xFF) << 16) | \
|
|
(((((uint64_t)(w64)) >> 48) & 0xFF) << 8) | \
|
|
(((((uint64_t)(w64)) >> 56) & 0xFF)))
|
|
#else
|
|
#define Skein_Swap64(w64) (w64)
|
|
#endif
|
|
#endif /* ifndef Skein_Swap64 */
|
|
|
|
#ifndef Skein_Put64_LSB_First
|
|
void
|
|
Skein_Put64_LSB_First(uint8_t *dst, const uint64_t *src, size_t bCnt)
|
|
#ifdef SKEIN_PORT_CODE /* instantiate the function code here? */
|
|
{
|
|
/*
|
|
* this version is fully portable (big-endian or little-endian),
|
|
* but slow
|
|
*/
|
|
size_t n;
|
|
|
|
for (n = 0; n < bCnt; n++)
|
|
dst[n] = (uint8_t)(src[n >> 3] >> (8 * (n & 7)));
|
|
}
|
|
#else
|
|
; /* output only the function prototype */
|
|
#endif
|
|
#endif /* ifndef Skein_Put64_LSB_First */
|
|
|
|
#ifndef Skein_Get64_LSB_First
|
|
void
|
|
Skein_Get64_LSB_First(uint64_t *dst, const uint8_t *src, size_t wCnt)
|
|
#ifdef SKEIN_PORT_CODE /* instantiate the function code here? */
|
|
{
|
|
/*
|
|
* this version is fully portable (big-endian or little-endian),
|
|
* but slow
|
|
*/
|
|
size_t n;
|
|
|
|
for (n = 0; n < 8 * wCnt; n += 8)
|
|
dst[n / 8] = (((uint64_t)src[n])) +
|
|
(((uint64_t)src[n + 1]) << 8) +
|
|
(((uint64_t)src[n + 2]) << 16) +
|
|
(((uint64_t)src[n + 3]) << 24) +
|
|
(((uint64_t)src[n + 4]) << 32) +
|
|
(((uint64_t)src[n + 5]) << 40) +
|
|
(((uint64_t)src[n + 6]) << 48) +
|
|
(((uint64_t)src[n + 7]) << 56);
|
|
}
|
|
#else
|
|
; /* output only the function prototype */
|
|
#endif
|
|
#endif /* ifndef Skein_Get64_LSB_First */
|
|
|
|
#endif /* _SKEIN_PORT_H_ */
|