Add generic implementation handling and SHA2 impl

The skeleton file module/icp/include/generic_impl.c can be used for
iterating over different implementations of algorithms.

It is used by SHA256, SHA512 and BLAKE3 currently.

The Solaris SHA2 implementation got replaced with a version which is
based on public domain code of cppcrypto v0.10.

These assembly files are taken from current openssl master:
- sha256-x86_64.S: x64, SSSE3, AVX, AVX2, SHA-NI (x86_64)
- sha512-x86_64.S: x64, AVX, AVX2 (x86_64)
- sha256-armv7.S: ARMv7, NEON, ARMv8-CE (arm)
- sha512-armv7.S: ARMv7, NEON (arm)
- sha256-armv8.S: ARMv7, NEON, ARMv8-CE (aarch64)
- sha512-armv8.S: ARMv7, ARMv8-CE (aarch64)
- sha256-ppc.S: Generic PPC64 LE/BE (ppc64)
- sha512-ppc.S: Generic PPC64 LE/BE (ppc64)
- sha256-p8.S: Power8 ISA Version 2.07 LE/BE (ppc64)
- sha512-p8.S: Power8 ISA Version 2.07 LE/BE (ppc64)

Tested-by: Rich Ercolani <rincebrain@gmail.com>
Tested-by: Sebastian Gottschall <s.gottschall@dd-wrt.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de>
Closes #13741
This commit is contained in:
Tino Reichardt
2023-03-01 09:40:28 +01:00
committed by Brian Behlendorf
parent ac678c8eee
commit 4c5fec01a4
30 changed files with 27986 additions and 96 deletions
+27 -7
View File
@@ -33,11 +33,11 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/time.h>
#define _SHA2_IMPL
#include <sys/sha2.h>
#include <sys/stdtypes.h>
#include <sys/zfs_impl.h>
/*
* Test messages from:
@@ -174,9 +174,19 @@ main(int argc, char *argv[])
boolean_t failed = B_FALSE;
uint64_t cpu_mhz = 0;
const zfs_impl_t *sha256 = zfs_impl_get_ops("sha256");
const zfs_impl_t *sha512 = zfs_impl_get_ops("sha512");
uint32_t id;
if (argc == 2)
cpu_mhz = atoi(argv[1]);
if (!sha256)
return (1);
if (!sha512)
return (1);
#define SHA2_ALGO_TEST(_m, mode, diglen, testdigest) \
do { \
SHA2_CTX ctx; \
@@ -194,7 +204,7 @@ main(int argc, char *argv[])
} \
} while (0)
#define SHA2_PERF_TEST(mode, diglen) \
#define SHA2_PERF_TEST(mode, diglen, name) \
do { \
SHA2_CTX ctx; \
uint8_t digest[diglen / 8]; \
@@ -216,8 +226,8 @@ main(int argc, char *argv[])
cpb = (cpu_mhz * 1e6 * ((double)delta / \
1000000)) / (8192 * 128 * 1024); \
} \
(void) printf("SHA%-9s%llu us (%.02f CPB)\n", #mode, \
(u_longlong_t)delta, cpb); \
(void) printf("sha%s-%-9s%7llu us (%.02f CPB)\n", #mode,\
name, (u_longlong_t)delta, cpb); \
} while (0)
(void) printf("Running algorithm correctness tests:\n");
@@ -237,8 +247,18 @@ main(int argc, char *argv[])
(void) printf("Running performance tests (hashing 1024 MiB of "
"data):\n");
SHA2_PERF_TEST(256, 256);
SHA2_PERF_TEST(512, 512);
for (id = 0; id < sha256->getcnt(); id++) {
sha256->setid(id);
const char *name = sha256->getname();
SHA2_PERF_TEST(256, 256, name);
}
for (id = 0; id < sha512->getcnt(); id++) {
sha512->setid(id);
const char *name = sha512->getname();
SHA2_PERF_TEST(512, 512, name);
}
return (0);
}