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]
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>
32 #include <sys/types.h>
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.
54 uint64_t chunk_counter
;
55 uint8_t buf
[BLAKE3_BLOCK_LEN
];
57 uint8_t blocks_compressed
;
59 } blake3_chunk_state_t
;
63 blake3_chunk_state_t chunk
;
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 */
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
,
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);
104 #endif /* _SYS_BLAKE3_H */