Skip to content

Commit 10c2baa

Browse files
committed
Add new SHA2 files
The C files are generic public domain files which are mostly faster the the BSD ones - this depends on compiler and it's flags of cause ;) The assembly files are taken from current openssl master, and are licensed under the Apache License Version 2.0: - sha256-x86_64.S: SSSE3, AVX, AVX2, SHA-NI - sha512-x86_64.S: AVX, AVX2 - sha256-armv8.S: NEON, ARMv8 Cryptography Extension - sha512-armv8.S: ARMv8 Cryptography Extension - sha256-ppc.S: generic PPC64 LE/BE - sha512-ppc.S: generic PPC64 LE/BE - sha256-p8.S: Power ISA Version 2.07 LE/BE - sha512-p8.S: Power ISA Version 2.07 LE/BE Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de>
1 parent 3886f99 commit 10c2baa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+18933
-1899
lines changed

cmd/ztest.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
#include <libnvpair.h>
136136
#include <libzutil.h>
137137
#include <sys/crypto/icp.h>
138+
#include <sys/zfs_impl.h>
138139
#if (__GLIBC__ && !__UCLIBC__)
139140
#include <execinfo.h> /* for backtrace() */
140141
#endif
@@ -6389,6 +6390,7 @@ ztest_blake3(ztest_ds_t *zd, uint64_t id)
63896390
int i, *ptr;
63906391
uint32_t size;
63916392
BLAKE3_CTX ctx;
6393+
const zfs_impl_t *blake3 = zfs_impl_get_ops("blake3");
63926394

63936395
size = ztest_random_blocksize();
63946396
buf = umem_alloc(size, UMEM_NOFAIL);
@@ -6413,7 +6415,7 @@ ztest_blake3(ztest_ds_t *zd, uint64_t id)
64136415
void *res2 = &zc_res2;
64146416

64156417
/* BLAKE3_KEY_LEN = 32 */
6416-
VERIFY0(blake3_set_impl_name("generic"));
6418+
VERIFY0(blake3->setname("generic"));
64176419
templ = abd_checksum_blake3_tmpl_init(&salt);
64186420
Blake3_InitKeyed(&ctx, salt_ptr);
64196421
Blake3_Update(&ctx, buf, size);
@@ -6422,7 +6424,7 @@ ztest_blake3(ztest_ds_t *zd, uint64_t id)
64226424
ZIO_CHECKSUM_BSWAP(&zc_ref2);
64236425
abd_checksum_blake3_tmpl_free(templ);
64246426

6425-
VERIFY0(blake3_set_impl_name("cycle"));
6427+
VERIFY0(blake3->setname("cycle"));
64266428
while (run_count-- > 0) {
64276429

64286430
/* Test current implementation */

include/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ COMMON_H = \
7474
sys/rrwlock.h \
7575
sys/sa.h \
7676
sys/sa_impl.h \
77+
sys/sha2.h \
7778
sys/skein.h \
7879
sys/spa.h \
7980
sys/spa_boot.h \
@@ -124,6 +125,7 @@ COMMON_H = \
124125
sys/zfs_delay.h \
125126
sys/zfs_file.h \
126127
sys/zfs_fuid.h \
128+
sys/zfs_impl.h \
127129
sys/zfs_project.h \
128130
sys/zfs_quota.h \
129131
sys/zfs_racct.h \

include/os/freebsd/spl/sys/mod_os.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@
9292
#define fletcher_4_param_set_args(var) \
9393
CTLTYPE_STRING, NULL, 0, fletcher_4_param, "A"
9494

95+
#define blake3_param_set_args(var) \
96+
CTLTYPE_STRING, NULL, 0, blake3_param, "A"
97+
98+
#define sha256_param_set_args(var) \
99+
CTLTYPE_STRING, NULL, 0, sha256_param, "A"
100+
101+
#define sha512_param_set_args(var) \
102+
CTLTYPE_STRING, NULL, 0, sha512_param, "A"
103+
95104
#include <sys/kernel.h>
96105
#define module_init(fn) \
97106
static void \

include/sys/blake3.h

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
/*
2323
* Based on BLAKE3 v1.3.1, https://github.com/BLAKE3-team/BLAKE3
2424
* Copyright (c) 2019-2020 Samuel Neves and Jack O'Connor
25-
* Copyright (c) 2021 Tino Reichardt <milky-zfs@mcmilk.de>
25+
* Copyright (c) 2021-2022 Tino Reichardt <milky-zfs@mcmilk.de>
2626
*/
2727

28-
#ifndef BLAKE3_H
29-
#define BLAKE3_H
28+
#ifndef _SYS_BLAKE3_H
29+
#define _SYS_BLAKE3_H
3030

3131
#ifdef _KERNEL
3232
#include <sys/types.h>
@@ -72,7 +72,7 @@ typedef struct {
7272
*/
7373
uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
7474

75-
/* const blake3_impl_ops_t *ops */
75+
/* const blake3_ops_t *ops */
7676
const void *ops;
7777
} BLAKE3_CTX;
7878

@@ -97,29 +97,8 @@ extern void **blake3_per_cpu_ctx;
9797
extern void blake3_per_cpu_ctx_init(void);
9898
extern void blake3_per_cpu_ctx_fini(void);
9999

100-
/* return number of supported implementations */
101-
extern int blake3_get_impl_count(void);
102-
103-
/* return id of selected implementation */
104-
extern int blake3_get_impl_id(void);
105-
106-
/* return name of selected implementation */
107-
extern const char *blake3_get_impl_name(void);
108-
109-
/* setup id as fastest implementation */
110-
extern void blake3_set_impl_fastest(uint32_t id);
111-
112-
/* set implementation by id */
113-
extern void blake3_set_impl_id(uint32_t id);
114-
115-
/* set implementation by name */
116-
extern int blake3_set_impl_name(const char *name);
117-
118-
/* set startup implementation */
119-
extern void blake3_setup_impl(void);
120-
121100
#ifdef __cplusplus
122101
}
123102
#endif
124103

125-
#endif /* BLAKE3_H */
104+
#endif /* _SYS_BLAKE3_H */

include/sys/sha2.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or https://opensource.org/licenses/CDDL-1.0.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
22+
/*
23+
* Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
24+
*/
25+
26+
#ifndef _SYS_SHA2_H
27+
#define _SYS_SHA2_H
28+
29+
#ifdef _KERNEL
30+
#include <sys/types.h>
31+
#else
32+
#include <stdint.h>
33+
#include <stdlib.h>
34+
#endif
35+
36+
#ifdef __cplusplus
37+
extern "C" {
38+
#endif
39+
40+
#define SHA224_BLOCK_LENGTH 64
41+
#define SHA256_BLOCK_LENGTH 64
42+
#define SHA384_BLOCK_LENGTH 128
43+
#define SHA512_BLOCK_LENGTH 128
44+
45+
#define SHA224_DIGEST_LENGTH 28
46+
#define SHA256_DIGEST_LENGTH 32
47+
#define SHA384_DIGEST_LENGTH 48
48+
#define SHA512_DIGEST_LENGTH 64
49+
50+
#define SHA512_224_DIGEST_LENGTH 28
51+
#define SHA512_256_DIGEST_LENGTH 32
52+
53+
/* sha256 context */
54+
typedef struct {
55+
uint32_t state[8];
56+
uint64_t count[2];
57+
uint8_t wbuf[64];
58+
59+
/* const sha256_ops_t *ops */
60+
const void *ops;
61+
} sha256_ctx;
62+
63+
/* sha512 context */
64+
typedef struct {
65+
uint64_t state[8];
66+
uint64_t count[2];
67+
uint8_t wbuf[128];
68+
69+
/* const sha256_ops_t *ops */
70+
const void *ops;
71+
} sha512_ctx;
72+
73+
/* SHA2 context */
74+
typedef struct {
75+
union {
76+
sha256_ctx sha256;
77+
sha512_ctx sha512;
78+
};
79+
80+
/* algorithm type */
81+
int algotype;
82+
} SHA2_CTX;
83+
84+
/* SHA2 algorithm types */
85+
enum sha2_algotype {
86+
SHA224 = 0,
87+
SHA256,
88+
SHA384,
89+
SHA512,
90+
SHA512_224,
91+
SHA512_256
92+
};
93+
94+
/* SHA2 Init function */
95+
extern void SHA2Init(SHA2_CTX *ctx, int algotype);
96+
97+
/* SHA2 Update function */
98+
extern void SHA2Update(SHA2_CTX *ctx, const void *data, size_t len);
99+
100+
/* SHA2 Final function */
101+
extern void SHA2Final(SHA2_CTX *ctx, void *digest);
102+
103+
#ifdef __cplusplus
104+
}
105+
#endif
106+
107+
#endif /* SYS_SHA2_H */

include/sys/zfs_impl.h

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or https://opensource.org/licenses/CDDL-1.0.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
22+
/*
23+
* Copyright (c) 2022 Tino Reichardt <milky-zfs@mcmilk.de>
24+
*/
25+
26+
#ifndef _SYS_ZFS_IMPL_H
27+
#define _SYS_ZFS_IMPL_H
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
/* generic implementation backends */
34+
typedef struct
35+
{
36+
/* algorithm name */
37+
const char *name;
38+
39+
/* get number of supported implementations */
40+
uint32_t (*getcnt)(void);
41+
42+
/* get id of selected implementation */
43+
uint32_t (*getid)(void);
44+
45+
/* get name of selected implementation */
46+
const char *(*getname)(void);
47+
48+
/* setup id as fastest implementation */
49+
void (*set_fastest)(uint32_t id);
50+
51+
/* set implementation by id */
52+
void (*setid)(uint32_t id);
53+
54+
/* set implementation by name */
55+
int (*setname)(const char *val);
56+
} zfs_impl_t;
57+
58+
/* return some set of function pointer */
59+
extern const zfs_impl_t *zfs_impl_get_ops(const char *algo);
60+
61+
extern const zfs_impl_t zfs_blake3_ops;
62+
extern const zfs_impl_t zfs_sha256_ops;
63+
extern const zfs_impl_t zfs_sha512_ops;
64+
65+
#ifdef __cplusplus
66+
}
67+
#endif
68+
69+
#endif /* _SYS_ZFS_IMPL_H */

include/sys/zio_checksum.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,9 @@ _SYS_ZIO_CHECKSUM_H const zio_checksum_info_t
110110
*/
111111

112112
/* SHA2 */
113-
extern zio_checksum_t abd_checksum_SHA256;
114-
extern zio_checksum_t abd_checksum_SHA512_native;
115-
extern zio_checksum_t abd_checksum_SHA512_byteswap;
113+
extern zio_checksum_t abd_checksum_sha256;
114+
extern zio_checksum_t abd_checksum_sha512_native;
115+
extern zio_checksum_t abd_checksum_sha512_byteswap;
116116

117117
/* Skein */
118118
extern zio_checksum_t abd_checksum_skein_native;

lib/libicp/Makefile.am

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ nodist_libicp_la_SOURCES = \
1616
module/icp/algs/blake3/blake3.c \
1717
module/icp/algs/blake3/blake3_generic.c \
1818
module/icp/algs/blake3/blake3_impl.c \
19-
module/icp/algs/blake3/blake3_x86-64.c \
2019
module/icp/algs/edonr/edonr.c \
2120
module/icp/algs/modes/modes.c \
2221
module/icp/algs/modes/cbc.c \
@@ -26,30 +25,38 @@ nodist_libicp_la_SOURCES = \
2625
module/icp/algs/modes/ctr.c \
2726
module/icp/algs/modes/ccm.c \
2827
module/icp/algs/modes/ecb.c \
29-
module/icp/algs/sha2/sha2.c \
28+
module/icp/algs/sha2/sha2_generic.c \
29+
module/icp/algs/sha2/sha256_impl.c \
30+
module/icp/algs/sha2/sha512_impl.c \
3031
module/icp/algs/skein/skein.c \
3132
module/icp/algs/skein/skein_block.c \
3233
module/icp/algs/skein/skein_iv.c \
3334
module/icp/illumos-crypto.c \
3435
module/icp/io/aes.c \
35-
module/icp/io/sha2_mod.c \
3636
module/icp/io/skein_mod.c \
3737
module/icp/core/kcf_sched.c \
3838
module/icp/core/kcf_prov_lib.c \
3939
module/icp/core/kcf_callprov.c \
4040
module/icp/core/kcf_mech_tabs.c \
41-
module/icp/core/kcf_prov_tabs.c
41+
module/icp/core/kcf_prov_tabs.c \
42+
module/zfs/zfs_impl.c
4243

4344
if TARGET_CPU_AARCH64
4445
nodist_libicp_la_SOURCES += \
4546
module/icp/asm-aarch64/blake3/b3_aarch64_sse2.S \
46-
module/icp/asm-aarch64/blake3/b3_aarch64_sse41.S
47+
module/icp/asm-aarch64/blake3/b3_aarch64_sse41.S \
48+
module/icp/asm-aarch64/sha2/sha256-armv8.S \
49+
module/icp/asm-aarch64/sha2/sha512-armv8.S
4750
endif
4851

4952
if TARGET_CPU_POWERPC
5053
nodist_libicp_la_SOURCES += \
5154
module/icp/asm-ppc64/blake3/b3_ppc64le_sse2.S \
52-
module/icp/asm-ppc64/blake3/b3_ppc64le_sse41.S
55+
module/icp/asm-ppc64/blake3/b3_ppc64le_sse41.S \
56+
module/icp/asm-ppc64/sha2/sha256-ppc.S \
57+
module/icp/asm-ppc64/sha2/sha512-ppc.S \
58+
module/icp/asm-ppc64/sha2/sha256-p8.S \
59+
module/icp/asm-ppc64/sha2/sha512-p8.S
5360
endif
5461

5562
if TARGET_CPU_X86_64
@@ -60,8 +67,8 @@ nodist_libicp_la_SOURCES += \
6067
module/icp/asm-x86_64/modes/gcm_pclmulqdq.S \
6168
module/icp/asm-x86_64/modes/aesni-gcm-x86_64.S \
6269
module/icp/asm-x86_64/modes/ghash-x86_64.S \
63-
module/icp/asm-x86_64/sha2/sha256_impl.S \
64-
module/icp/asm-x86_64/sha2/sha512_impl.S \
70+
module/icp/asm-x86_64/sha2/sha256-x86_64.S \
71+
module/icp/asm-x86_64/sha2/sha512-x86_64.S \
6572
module/icp/asm-x86_64/blake3/blake3_avx2.S \
6673
module/icp/asm-x86_64/blake3/blake3_avx512.S \
6774
module/icp/asm-x86_64/blake3/blake3_sse2.S \

lib/libspl/include/Makefile.am

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ libspl_sys_HEADERS = \
4545
%D%/sys/poll.h \
4646
%D%/sys/priv.h \
4747
%D%/sys/processor.h \
48-
%D%/sys/sha2.h \
4948
%D%/sys/simd.h \
5049
%D%/sys/stack.h \
5150
%D%/sys/stdtypes.h \

lib/libzfs/Makefile.am

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ dist_libzfs_la_SOURCES += \
3434
endif
3535

3636
nodist_libzfs_la_SOURCES = \
37-
module/icp/algs/sha2/sha2.c \
38-
\
3937
module/zcommon/cityhash.c \
4038
module/zcommon/zfeature_common.c \
4139
module/zcommon/zfs_comutil.c \
@@ -52,7 +50,6 @@ nodist_libzfs_la_SOURCES = \
5250
module/zcommon/zpool_prop.c \
5351
module/zcommon/zprop_common.c
5452

55-
5653
libzfs_la_LIBADD = \
5754
libshare.la \
5855
libzfs_core.la \

0 commit comments

Comments
 (0)