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.

Tested-by: Rich Ercolani <[email protected]>
Tested-by: Sebastian Gottschall <[email protected]>
Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Tino Reichardt <[email protected]>
Closes openzfs#13741
  • Loading branch information
mcmilk authored and sdimitro committed Mar 8, 2023
1 parent 3d6f779 commit 38c0b4f
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 498 deletions.
6 changes: 4 additions & 2 deletions cmd/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
#include <sys/crypto/icp.h>
#include <sys/un.h>
#include <sys/socket.h>
#include <sys/zfs_impl.h>
#include <libzoa_util.h>
#if (__GLIBC__ && !__UCLIBC__)
#include <execinfo.h> /* for backtrace() */
Expand Down Expand Up @@ -6574,6 +6575,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 @@ -6598,7 +6600,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 @@ -6607,7 +6609,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 <[email protected]>
* Copyright (c) 2021-2022 Tino Reichardt <[email protected]>
*/

#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 @@ -432,7 +432,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 38c0b4f

Please sign in to comment.