Skip to content

Commit

Permalink
Update BLAKE3 for using the new impl handling
Browse files Browse the repository at this point in the history
This commit changes the BLAKE3 implementation handling and
also the calls to it from the ztest command.

Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de>
  • Loading branch information
mcmilk committed Sep 17, 2022
1 parent c56f491 commit 1d40c3b
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 494 deletions.
6 changes: 4 additions & 2 deletions cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@
#include <libnvpair.h>
#include <libzutil.h>
#include <sys/crypto/icp.h>
#include <sys/zfs_impl.h>
#if (__GLIBC__ && !__UCLIBC__)
#include <execinfo.h> /* for backtrace() */
#endif
Expand Down Expand Up @@ -6389,6 +6390,7 @@ ztest_blake3(ztest_ds_t *zd, uint64_t id)
int i, *ptr;
uint32_t size;
BLAKE3_CTX ctx;
const zfs_impl_t *blake3 = zfs_impl_get_ops("blake3");

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

/* BLAKE3_KEY_LEN = 32 */
VERIFY0(blake3_impl_setname("generic"));
VERIFY0(blake3->setname("generic"));
templ = abd_checksum_blake3_tmpl_init(&salt);
Blake3_InitKeyed(&ctx, salt_ptr);
Blake3_Update(&ctx, buf, size);
Expand All @@ -6422,7 +6424,7 @@ ztest_blake3(ztest_ds_t *zd, uint64_t id)
ZIO_CHECKSUM_BSWAP(&zc_ref2);
abd_checksum_blake3_tmpl_free(templ);

VERIFY0(blake3_impl_setname("cycle"));
VERIFY0(blake3->setname("cycle"));
while (run_count-- > 0) {

/* Test current implementation */
Expand Down
26 changes: 4 additions & 22 deletions include/sys/blake3.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
/*
* Based on BLAKE3 v1.3.1, https://github.com/BLAKE3-team/BLAKE3
* Copyright (c) 2019-2020 Samuel Neves and Jack O'Connor
* Copyright (c) 2021 Tino Reichardt <milky-zfs@mcmilk.de>
* Copyright (c) 2021-2022 Tino Reichardt <milky-zfs@mcmilk.de>
*/

#ifndef BLAKE3_H
#define BLAKE3_H
#ifndef _SYS_BLAKE3_H
#define _SYS_BLAKE3_H

#ifdef _KERNEL
#include <sys/types.h>
Expand Down Expand Up @@ -97,26 +97,8 @@ extern void **blake3_per_cpu_ctx;
extern void blake3_per_cpu_ctx_init(void);
extern void blake3_per_cpu_ctx_fini(void);

/* get count of supported implementations */
extern uint32_t blake3_impl_getcnt(void);

/* get id of selected implementation */
extern uint32_t blake3_impl_getid(void);

/* get name of selected implementation */
extern const char *blake3_impl_getname(void);

/* setup id as fastest implementation */
extern void blake3_impl_set_fastest(uint32_t id);

/* set implementation by id */
extern void blake3_impl_setid(uint32_t id);

/* set implementation by name */
extern int blake3_impl_setname(const char *name);

#ifdef __cplusplus
}
#endif

#endif /* BLAKE3_H */
#endif /* _SYS_BLAKE3_H */
2 changes: 1 addition & 1 deletion module/icp/algs/blake3/blake3.c
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ static void hasher_init_base(BLAKE3_CTX *ctx, const uint32_t key[8],
memcpy(ctx->key, key, BLAKE3_KEY_LEN);
chunk_state_init(&ctx->chunk, key, flags);
ctx->cv_stack_len = 0;
ctx->ops = blake3_impl_get_ops();
ctx->ops = blake3_get_ops();
}

/*
Expand Down
5 changes: 3 additions & 2 deletions module/icp/algs/blake3/blake3_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ static inline void blake3_hash_many_generic(const uint8_t * const *inputs,
}
}

static inline boolean_t blake3_is_generic_supported(void)
/* the generic implementation is always okay */
static boolean_t blake3_is_supported(void)
{
return (B_TRUE);
}
Expand All @@ -196,7 +197,7 @@ const blake3_ops_t blake3_generic_impl = {
.compress_in_place = blake3_compress_in_place_generic,
.compress_xof = blake3_compress_xof_generic,
.hash_many = blake3_hash_many_generic,
.is_supported = blake3_is_generic_supported,
.is_supported = blake3_is_supported,
.degree = 4,
.name = "generic"
};
Loading

0 comments on commit 1d40c3b

Please sign in to comment.