|
1 |
| -#ifndef BLAKE3_H |
2 |
| -#define BLAKE3_H |
| 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 |
3 | 19 |
|
4 | 20 | #include <stddef.h>
|
5 | 21 | #include <stdint.h>
|
|
8 | 24 | extern "C" {
|
9 | 25 | #endif
|
10 | 26 |
|
11 |
| -#define BLAKE3_VERSION_STRING "1.3.1" |
12 |
| -#define BLAKE3_KEY_LEN 32 |
13 |
| -#define BLAKE3_OUT_LEN 32 |
14 |
| -#define BLAKE3_BLOCK_LEN 64 |
15 |
| -#define BLAKE3_CHUNK_LEN 1024 |
16 |
| -#define BLAKE3_MAX_DEPTH 54 |
| 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 |
17 | 33 |
|
18 | 34 | // This struct is a private implementation detail. It has to be here because
|
19 |
| -// it's part of blake3_hasher below. |
| 35 | +// it's part of llvm_blake3_hasher below. |
20 | 36 | typedef struct {
|
21 | 37 | uint32_t cv[8];
|
22 | 38 | uint64_t chunk_counter;
|
23 |
| - uint8_t buf[BLAKE3_BLOCK_LEN]; |
| 39 | + uint8_t buf[LLVM_BLAKE3_BLOCK_LEN]; |
24 | 40 | uint8_t buf_len;
|
25 | 41 | uint8_t blocks_compressed;
|
26 | 42 | uint8_t flags;
|
27 |
| -} blake3_chunk_state; |
| 43 | +} llvm_blake3_chunk_state; |
28 | 44 |
|
29 | 45 | typedef struct {
|
30 | 46 | uint32_t key[8];
|
31 |
| - blake3_chunk_state chunk; |
| 47 | + llvm_blake3_chunk_state chunk; |
32 | 48 | uint8_t cv_stack_len;
|
33 | 49 | // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example,
|
34 | 50 | // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk
|
35 | 51 | // requires a 4th entry, rather than merging everything down to 1, because we
|
36 | 52 | // don't know whether more input is coming. This is different from how the
|
37 | 53 | // reference implementation does things.
|
38 |
| - uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN]; |
39 |
| -} blake3_hasher; |
40 |
| - |
41 |
| -const char *blake3_version(void); |
42 |
| -void blake3_hasher_init(blake3_hasher *self); |
43 |
| -void blake3_hasher_init_keyed(blake3_hasher *self, |
44 |
| - const uint8_t key[BLAKE3_KEY_LEN]); |
45 |
| -void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context); |
46 |
| -void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context, |
47 |
| - size_t context_len); |
48 |
| -void blake3_hasher_update(blake3_hasher *self, const void *input, |
49 |
| - size_t input_len); |
50 |
| -void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out, |
51 |
| - size_t out_len); |
52 |
| -void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek, |
53 |
| - uint8_t *out, size_t out_len); |
54 |
| -void blake3_hasher_reset(blake3_hasher *self); |
| 54 | + uint8_t cv_stack[(LLVM_BLAKE3_MAX_DEPTH + 1) * LLVM_BLAKE3_OUT_LEN]; |
| 55 | +} llvm_blake3_hasher; |
| 56 | + |
| 57 | +const char *llvm_blake3_version(void); |
| 58 | +void llvm_blake3_hasher_init(llvm_blake3_hasher *self); |
| 59 | +void llvm_blake3_hasher_init_keyed(llvm_blake3_hasher *self, |
| 60 | + const uint8_t key[LLVM_BLAKE3_KEY_LEN]); |
| 61 | +void llvm_blake3_hasher_init_derive_key(llvm_blake3_hasher *self, |
| 62 | + const char *context); |
| 63 | +void llvm_blake3_hasher_init_derive_key_raw(llvm_blake3_hasher *self, |
| 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); |
| 70 | +void llvm_blake3_hasher_finalize_seek(const llvm_blake3_hasher *self, |
| 71 | + uint64_t seek, uint8_t *out, |
| 72 | + size_t out_len); |
| 73 | +void llvm_blake3_hasher_reset(llvm_blake3_hasher *self); |
55 | 74 |
|
56 | 75 | #ifdef __cplusplus
|
57 | 76 | }
|
58 | 77 | #endif
|
59 | 78 |
|
60 |
| -#endif /* BLAKE3_H */ |
| 79 | +#endif /* LLVM_C_BLAKE3_H */ |
0 commit comments