LLVM  16.0.0git
blake3.h
Go to the documentation of this file.
1 /*===-- llvm-c/blake3.h - BLAKE3 C Interface ----------------------*- C -*-===*\
2 |* *|
3 |* Released into the public domain with CC0 1.0 *|
4 |* See 'llvm/lib/Support/BLAKE3/LICENSE' for info. *|
5 |* SPDX-License-Identifier: CC0-1.0 *|
6 |* *|
7 |*===----------------------------------------------------------------------===*|
8 |* *|
9 |* This header declares the C interface to LLVM's BLAKE3 implementation. *|
10 |* Original BLAKE3 C API: https://github.com/BLAKE3-team/BLAKE3/tree/1.3.1/c *|
11 |* *|
12 |* Symbols are prefixed with 'llvm' to avoid a potential conflict with *|
13 |* another BLAKE3 version within the same program. *|
14 |* *|
15 \*===----------------------------------------------------------------------===*/
16 
17 #ifndef LLVM_C_BLAKE3_H
18 #define LLVM_C_BLAKE3_H
19 
20 #include <stddef.h>
21 #include <stdint.h>
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define LLVM_BLAKE3_VERSION_STRING "1.3.1"
28 #define LLVM_BLAKE3_KEY_LEN 32
29 #define LLVM_BLAKE3_OUT_LEN 32
30 #define LLVM_BLAKE3_BLOCK_LEN 64
31 #define LLVM_BLAKE3_CHUNK_LEN 1024
32 #define LLVM_BLAKE3_MAX_DEPTH 54
33 
34 // This struct is a private implementation detail. It has to be here because
35 // it's part of llvm_blake3_hasher below.
36 typedef struct {
37  uint32_t cv[8];
39  uint8_t buf[LLVM_BLAKE3_BLOCK_LEN];
40  uint8_t buf_len;
42  uint8_t flags;
44 
45 typedef struct {
46  uint32_t key[8];
48  uint8_t cv_stack_len;
49  // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example,
50  // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk
51  // requires a 4th entry, rather than merging everything down to 1, because we
52  // don't know whether more input is coming. This is different from how the
53  // reference implementation does things.
54  uint8_t cv_stack[(LLVM_BLAKE3_MAX_DEPTH + 1) * LLVM_BLAKE3_OUT_LEN];
56 
57 const char *llvm_blake3_version(void);
60  const uint8_t key[LLVM_BLAKE3_KEY_LEN]);
62  const char *context);
64  const void *context,
65  size_t context_len);
66 void llvm_blake3_hasher_update(llvm_blake3_hasher *self, const void *input,
67  size_t input_len);
68 void llvm_blake3_hasher_finalize(const llvm_blake3_hasher *self, uint8_t *out,
69  size_t out_len);
71  uint64_t seek, uint8_t *out,
72  size_t out_len);
74 
75 #ifdef __cplusplus
76 }
77 #endif
78 
79 #endif /* LLVM_C_BLAKE3_H */
llvm_blake3_hasher
Definition: blake3.h:45
llvm_blake3_hasher_init_keyed
void llvm_blake3_hasher_init_keyed(llvm_blake3_hasher *self, const uint8_t key[LLVM_BLAKE3_KEY_LEN])
LLVM_BLAKE3_BLOCK_LEN
#define LLVM_BLAKE3_BLOCK_LEN
Definition: blake3.h:30
LLVM_BLAKE3_MAX_DEPTH
#define LLVM_BLAKE3_MAX_DEPTH
Definition: blake3.h:32
llvm_blake3_hasher_finalize_seek
void llvm_blake3_hasher_finalize_seek(const llvm_blake3_hasher *self, uint64_t seek, uint8_t *out, size_t out_len)
llvm_blake3_hasher_init_derive_key
void llvm_blake3_hasher_init_derive_key(llvm_blake3_hasher *self, const char *context)
llvm_blake3_hasher_finalize
void llvm_blake3_hasher_finalize(const llvm_blake3_hasher *self, uint8_t *out, size_t out_len)
llvm_blake3_chunk_state::blocks_compressed
uint8_t blocks_compressed
Definition: blake3.h:41
llvm_blake3_chunk_state::chunk_counter
uint64_t chunk_counter
Definition: blake3.h:38
input
The initial backend is deliberately restricted to z10 We should add support for later architectures at some point If an asm ties an i32 r result to an i64 input
Definition: README.txt:10
llvm_blake3_chunk_state::buf_len
uint8_t buf_len
Definition: blake3.h:40
llvm_blake3_hasher_init_derive_key_raw
void llvm_blake3_hasher_init_derive_key_raw(llvm_blake3_hasher *self, const void *context, size_t context_len)
uint64_t
LLVM_BLAKE3_KEY_LEN
#define LLVM_BLAKE3_KEY_LEN
Definition: blake3.h:28
llvm_blake3_hasher::cv_stack_len
uint8_t cv_stack_len
Definition: blake3.h:48
llvm_blake3_hasher_update
void llvm_blake3_hasher_update(llvm_blake3_hasher *self, const void *input, size_t input_len)
uint32_t
llvm_blake3_version
const char * llvm_blake3_version(void)
Definition: blake3.c:15
llvm_blake3_chunk_state
Definition: blake3.h:36
llvm_blake3_hasher_reset
void llvm_blake3_hasher_reset(llvm_blake3_hasher *self)
LLVM_BLAKE3_OUT_LEN
#define LLVM_BLAKE3_OUT_LEN
Definition: blake3.h:29
llvm_blake3_hasher_init
void llvm_blake3_hasher_init(llvm_blake3_hasher *self)
llvm_blake3_hasher::chunk
llvm_blake3_chunk_state chunk
Definition: blake3.h:47
llvm_blake3_chunk_state::flags
uint8_t flags
Definition: blake3.h:42