Add warning for external consumers of dmu_tx_callback_register
[zfs.git] / include / sys / blake3.h
blobb981b18db94321aae43723f6c899fc79cf6bb509
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Based on BLAKE3 v1.3.1, https://github.com/BLAKE3-team/BLAKE3
24 * Copyright (c) 2019-2020 Samuel Neves and Jack O'Connor
25 * Copyright (c) 2021-2022 Tino Reichardt <milky-zfs@mcmilk.de>
28 #ifndef _SYS_BLAKE3_H
29 #define _SYS_BLAKE3_H
31 #ifdef _KERNEL
32 #include <sys/types.h>
33 #else
34 #include <stdint.h>
35 #include <stdlib.h>
36 #endif
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
42 #define BLAKE3_KEY_LEN 32
43 #define BLAKE3_OUT_LEN 32
44 #define BLAKE3_MAX_DEPTH 54
45 #define BLAKE3_BLOCK_LEN 64
46 #define BLAKE3_CHUNK_LEN 1024
49 * This struct is a private implementation detail.
50 * It has to be here because it's part of BLAKE3_CTX below.
52 typedef struct {
53 uint32_t cv[8];
54 uint64_t chunk_counter;
55 uint8_t buf[BLAKE3_BLOCK_LEN];
56 uint8_t buf_len;
57 uint8_t blocks_compressed;
58 uint8_t flags;
59 } blake3_chunk_state_t;
61 typedef struct {
62 uint32_t key[8];
63 blake3_chunk_state_t chunk;
64 uint8_t cv_stack_len;
67 * The stack size is MAX_DEPTH + 1 because we do lazy merging. For
68 * example, with 7 chunks, we have 3 entries in the stack. Adding an
69 * 8th chunk requires a 4th entry, rather than merging everything down
70 * to 1, because we don't know whether more input is coming. This is
71 * different from how the reference implementation does things.
73 uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
75 /* const blake3_ops_t *ops */
76 const void *ops;
77 } BLAKE3_CTX;
79 /* init the context for hash operation */
80 void Blake3_Init(BLAKE3_CTX *ctx);
82 /* init the context for a MAC and/or tree hash operation */
83 void Blake3_InitKeyed(BLAKE3_CTX *ctx, const uint8_t key[BLAKE3_KEY_LEN]);
85 /* process the input bytes */
86 void Blake3_Update(BLAKE3_CTX *ctx, const void *input, size_t input_len);
88 /* finalize the hash computation and output the result */
89 void Blake3_Final(const BLAKE3_CTX *ctx, uint8_t *out);
91 /* finalize the hash computation and output the result */
92 void Blake3_FinalSeek(const BLAKE3_CTX *ctx, uint64_t seek, uint8_t *out,
93 size_t out_len);
95 /* these are pre-allocated contexts */
96 extern void **blake3_per_cpu_ctx;
97 extern void blake3_per_cpu_ctx_init(void);
98 extern void blake3_per_cpu_ctx_fini(void);
100 #ifdef __cplusplus
102 #endif
104 #endif /* _SYS_BLAKE3_H */