Path: blob/main/contrib/llvm-project/llvm/include/llvm-c/blake3.h
35233 views
/*===-- llvm-c/blake3.h - BLAKE3 C Interface ----------------------*- C -*-===*\1|* *|2|* Released into the public domain with CC0 1.0 *|3|* See 'llvm/lib/Support/BLAKE3/LICENSE' for info. *|4|* SPDX-License-Identifier: CC0-1.0 *|5|* *|6|*===----------------------------------------------------------------------===*|7|* *|8|* This header declares the C interface to LLVM's BLAKE3 implementation. *|9|* Original BLAKE3 C API: https://github.com/BLAKE3-team/BLAKE3/tree/1.3.1/c *|10|* *|11|* Symbols are prefixed with 'llvm' to avoid a potential conflict with *|12|* another BLAKE3 version within the same program. *|13|* *|14\*===----------------------------------------------------------------------===*/1516#ifndef LLVM_C_BLAKE3_H17#define LLVM_C_BLAKE3_H1819#include <stddef.h>20#include <stdint.h>2122#ifdef __cplusplus23extern "C" {24#endif2526#define LLVM_BLAKE3_VERSION_STRING "1.3.1"27#define LLVM_BLAKE3_KEY_LEN 3228#define LLVM_BLAKE3_OUT_LEN 3229#define LLVM_BLAKE3_BLOCK_LEN 6430#define LLVM_BLAKE3_CHUNK_LEN 102431#define LLVM_BLAKE3_MAX_DEPTH 543233// This struct is a private implementation detail. It has to be here because34// it's part of llvm_blake3_hasher below.35typedef struct {36uint32_t cv[8];37uint64_t chunk_counter;38uint8_t buf[LLVM_BLAKE3_BLOCK_LEN];39uint8_t buf_len;40uint8_t blocks_compressed;41uint8_t flags;42} llvm_blake3_chunk_state;4344typedef struct {45uint32_t key[8];46llvm_blake3_chunk_state chunk;47uint8_t cv_stack_len;48// The stack size is MAX_DEPTH + 1 because we do lazy merging. For example,49// with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk50// requires a 4th entry, rather than merging everything down to 1, because we51// don't know whether more input is coming. This is different from how the52// reference implementation does things.53uint8_t cv_stack[(LLVM_BLAKE3_MAX_DEPTH + 1) * LLVM_BLAKE3_OUT_LEN];54} llvm_blake3_hasher;5556const char *llvm_blake3_version(void);57void llvm_blake3_hasher_init(llvm_blake3_hasher *self);58void llvm_blake3_hasher_init_keyed(llvm_blake3_hasher *self,59const uint8_t key[LLVM_BLAKE3_KEY_LEN]);60void llvm_blake3_hasher_init_derive_key(llvm_blake3_hasher *self,61const char *context);62void llvm_blake3_hasher_init_derive_key_raw(llvm_blake3_hasher *self,63const void *context,64size_t context_len);65void llvm_blake3_hasher_update(llvm_blake3_hasher *self, const void *input,66size_t input_len);67void llvm_blake3_hasher_finalize(const llvm_blake3_hasher *self, uint8_t *out,68size_t out_len);69void llvm_blake3_hasher_finalize_seek(const llvm_blake3_hasher *self,70uint64_t seek, uint8_t *out,71size_t out_len);72void llvm_blake3_hasher_reset(llvm_blake3_hasher *self);7374#ifdef __cplusplus75}76#endif7778#endif /* LLVM_C_BLAKE3_H */798081