Skip to content

Commit 62c3dd4

Browse files
committed
Update BLAKE3 for using the new impl handling
This commit changes the BLAKE3 implementation handling and also the calls to it from the ztest command. Signed-off-by: Tino Reichardt <[email protected]>
1 parent c002dc8 commit 62c3dd4

File tree

7 files changed

+327
-497
lines changed

7 files changed

+327
-497
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/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 <[email protected]>
25+
* Copyright (c) 2021-2022 Tino Reichardt <[email protected]>
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 */

module/icp/algs/blake3/blake3.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ static output_t make_output(const uint32_t input_cv[8],
129129
* bytes. For that reason, chaining values in the CV stack are represented as
130130
* bytes.
131131
*/
132-
static void output_chaining_value(const blake3_impl_ops_t *ops,
132+
static void output_chaining_value(const blake3_ops_t *ops,
133133
const output_t *ctx, uint8_t cv[32])
134134
{
135135
uint32_t cv_words[8];
@@ -139,7 +139,7 @@ static void output_chaining_value(const blake3_impl_ops_t *ops,
139139
store_cv_words(cv, cv_words);
140140
}
141141

142-
static void output_root_bytes(const blake3_impl_ops_t *ops, const output_t *ctx,
142+
static void output_root_bytes(const blake3_ops_t *ops, const output_t *ctx,
143143
uint64_t seek, uint8_t *out, size_t out_len)
144144
{
145145
uint64_t output_block_counter = seek / 64;
@@ -163,7 +163,7 @@ static void output_root_bytes(const blake3_impl_ops_t *ops, const output_t *ctx,
163163
}
164164
}
165165

166-
static void chunk_state_update(const blake3_impl_ops_t *ops,
166+
static void chunk_state_update(const blake3_ops_t *ops,
167167
blake3_chunk_state_t *ctx, const uint8_t *input, size_t input_len)
168168
{
169169
if (ctx->buf_len > 0) {
@@ -230,7 +230,7 @@ static size_t left_len(size_t content_len)
230230
* number of chunks hashed. These chunks are never the root and never empty;
231231
* those cases use a different codepath.
232232
*/
233-
static size_t compress_chunks_parallel(const blake3_impl_ops_t *ops,
233+
static size_t compress_chunks_parallel(const blake3_ops_t *ops,
234234
const uint8_t *input, size_t input_len, const uint32_t key[8],
235235
uint64_t chunk_counter, uint8_t flags, uint8_t *out)
236236
{
@@ -274,7 +274,7 @@ static size_t compress_chunks_parallel(const blake3_impl_ops_t *ops,
274274
* return it as an additional output.) These parents are never the root and
275275
* never empty; those cases use a different codepath.
276276
*/
277-
static size_t compress_parents_parallel(const blake3_impl_ops_t *ops,
277+
static size_t compress_parents_parallel(const blake3_ops_t *ops,
278278
const uint8_t *child_chaining_values, size_t num_chaining_values,
279279
const uint32_t key[8], uint8_t flags, uint8_t *out)
280280
{
@@ -320,7 +320,7 @@ static size_t compress_parents_parallel(const blake3_impl_ops_t *ops,
320320
* of implementing this special rule? Because we don't want to limit SIMD or
321321
* multi-threading parallelism for that update().
322322
*/
323-
static size_t blake3_compress_subtree_wide(const blake3_impl_ops_t *ops,
323+
static size_t blake3_compress_subtree_wide(const blake3_ops_t *ops,
324324
const uint8_t *input, size_t input_len, const uint32_t key[8],
325325
uint64_t chunk_counter, uint8_t flags, uint8_t *out)
326326
{
@@ -406,7 +406,7 @@ static size_t blake3_compress_subtree_wide(const blake3_impl_ops_t *ops,
406406
* As with compress_subtree_wide(), this function is not used on inputs of 1
407407
* chunk or less. That's a different codepath.
408408
*/
409-
static void compress_subtree_to_parent_node(const blake3_impl_ops_t *ops,
409+
static void compress_subtree_to_parent_node(const blake3_ops_t *ops,
410410
const uint8_t *input, size_t input_len, const uint32_t key[8],
411411
uint64_t chunk_counter, uint8_t flags, uint8_t out[2 * BLAKE3_OUT_LEN])
412412
{
@@ -434,7 +434,7 @@ static void hasher_init_base(BLAKE3_CTX *ctx, const uint32_t key[8],
434434
memcpy(ctx->key, key, BLAKE3_KEY_LEN);
435435
chunk_state_init(&ctx->chunk, key, flags);
436436
ctx->cv_stack_len = 0;
437-
ctx->ops = blake3_impl_get_ops();
437+
ctx->ops = blake3_get_ops();
438438
}
439439

440440
/*

module/icp/algs/blake3/blake3_generic.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,17 @@ static inline void blake3_hash_many_generic(const uint8_t * const *inputs,
187187
}
188188
}
189189

190-
static inline boolean_t blake3_is_generic_supported(void)
190+
/* the generic implementation is always okay */
191+
static boolean_t blake3_is_supported(void)
191192
{
192193
return (B_TRUE);
193194
}
194195

195-
const blake3_impl_ops_t blake3_generic_impl = {
196+
const blake3_ops_t blake3_generic_impl = {
196197
.compress_in_place = blake3_compress_in_place_generic,
197198
.compress_xof = blake3_compress_xof_generic,
198199
.hash_many = blake3_hash_many_generic,
199-
.is_supported = blake3_is_generic_supported,
200+
.is_supported = blake3_is_supported,
200201
.degree = 4,
201202
.name = "generic"
202203
};

0 commit comments

Comments
 (0)