Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:00

0001 /*===-- llvm-c/blake3.h - BLAKE3 C Interface ----------------------*- C -*-===*\
0002 |*                                                                            *|
0003 |* Released into the public domain with CC0 1.0                               *|
0004 |* See 'llvm/lib/Support/BLAKE3/LICENSE' for info.                            *|
0005 |* SPDX-License-Identifier: CC0-1.0                                           *|
0006 |*                                                                            *|
0007 |*===----------------------------------------------------------------------===*|
0008 |*                                                                            *|
0009 |* This header declares the C interface to LLVM's BLAKE3 implementation.      *|
0010 |* Original BLAKE3 C API: https://github.com/BLAKE3-team/BLAKE3/tree/1.3.1/c  *|
0011 |*                                                                            *|
0012 |* Symbols are prefixed with 'llvm' to avoid a potential conflict with        *|
0013 |* another BLAKE3 version within the same program.                            *|
0014 |*                                                                            *|
0015 \*===----------------------------------------------------------------------===*/
0016 
0017 #ifndef LLVM_C_BLAKE3_H
0018 #define LLVM_C_BLAKE3_H
0019 
0020 #include <stddef.h>
0021 #include <stdint.h>
0022 
0023 #ifdef __cplusplus
0024 extern "C" {
0025 #endif
0026 
0027 #define LLVM_BLAKE3_VERSION_STRING "1.3.1"
0028 #define LLVM_BLAKE3_KEY_LEN 32
0029 #define LLVM_BLAKE3_OUT_LEN 32
0030 #define LLVM_BLAKE3_BLOCK_LEN 64
0031 #define LLVM_BLAKE3_CHUNK_LEN 1024
0032 #define LLVM_BLAKE3_MAX_DEPTH 54
0033 
0034 // This struct is a private implementation detail. It has to be here because
0035 // it's part of llvm_blake3_hasher below.
0036 typedef struct {
0037   uint32_t cv[8];
0038   uint64_t chunk_counter;
0039   uint8_t buf[LLVM_BLAKE3_BLOCK_LEN];
0040   uint8_t buf_len;
0041   uint8_t blocks_compressed;
0042   uint8_t flags;
0043 } llvm_blake3_chunk_state;
0044 
0045 typedef struct {
0046   uint32_t key[8];
0047   llvm_blake3_chunk_state chunk;
0048   uint8_t cv_stack_len;
0049   // The stack size is MAX_DEPTH + 1 because we do lazy merging. For example,
0050   // with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk
0051   // requires a 4th entry, rather than merging everything down to 1, because we
0052   // don't know whether more input is coming. This is different from how the
0053   // reference implementation does things.
0054   uint8_t cv_stack[(LLVM_BLAKE3_MAX_DEPTH + 1) * LLVM_BLAKE3_OUT_LEN];
0055 } llvm_blake3_hasher;
0056 
0057 const char *llvm_blake3_version(void);
0058 void llvm_blake3_hasher_init(llvm_blake3_hasher *self);
0059 void llvm_blake3_hasher_init_keyed(llvm_blake3_hasher *self,
0060                                    const uint8_t key[LLVM_BLAKE3_KEY_LEN]);
0061 void llvm_blake3_hasher_init_derive_key(llvm_blake3_hasher *self,
0062                                         const char *context);
0063 void llvm_blake3_hasher_init_derive_key_raw(llvm_blake3_hasher *self,
0064                                             const void *context,
0065                                             size_t context_len);
0066 void llvm_blake3_hasher_update(llvm_blake3_hasher *self, const void *input,
0067                                size_t input_len);
0068 void llvm_blake3_hasher_finalize(const llvm_blake3_hasher *self, uint8_t *out,
0069                                  size_t out_len);
0070 void llvm_blake3_hasher_finalize_seek(const llvm_blake3_hasher *self,
0071                                       uint64_t seek, uint8_t *out,
0072                                       size_t out_len);
0073 void llvm_blake3_hasher_reset(llvm_blake3_hasher *self);
0074 
0075 #ifdef __cplusplus
0076 }
0077 #endif
0078 
0079 #endif /* LLVM_C_BLAKE3_H */