mirror of
https://github.com/BLAKE3-team/BLAKE3
synced 2024-05-07 01:26:14 +02:00
4d6dfc4eed
Changes since 1.0.0: - The NEON implementation is now enabled by default on AArch64 targets. Previously it was disabled without the "neon" Cargo feature in Rust or the "BLAKE3_USE_NEON=1" preprocessor flag in C. This is still the case on ARM targets other than AArch64, because of the lack of dynamic CPU feature detection on ARM. Contributed by @rsdy. - The previous change leads to some build incompatibilities, particularly in C. If you build the C implementation for AArch64 targets, you now need to include blake3_neon.c, or else you'll get a linker error like "undefined reference to `blake3_hash_many_neon'". If you don't want the NEON implementation, you need to explicitly set "BLAKE3_USE_NEON=0". On the Rust side, AArch64 targets now require the C toolchain by default. build.rs includes workarounds for missing or very old C compilers for x86, but it doesn't currently include such workarounds for AArch64. If we hear about build breaks related to this, we can add more workarounds as appropriate. - C-specific Git tags ("c-0.3.7" etc.) have been removed, and all the projects in this repo (Rust "blake3", Rust "b3sum", and the C implementation) will continue to be versioned in lockstep for the foreseeable future.
60 lines
1.9 KiB
C
60 lines
1.9 KiB
C
#ifndef BLAKE3_H
|
|
#define BLAKE3_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#define BLAKE3_VERSION_STRING "1.1.0"
|
|
#define BLAKE3_KEY_LEN 32
|
|
#define BLAKE3_OUT_LEN 32
|
|
#define BLAKE3_BLOCK_LEN 64
|
|
#define BLAKE3_CHUNK_LEN 1024
|
|
#define BLAKE3_MAX_DEPTH 54
|
|
|
|
// This struct is a private implementation detail. It has to be here because
|
|
// it's part of blake3_hasher below.
|
|
typedef struct {
|
|
uint32_t cv[8];
|
|
uint64_t chunk_counter;
|
|
uint8_t buf[BLAKE3_BLOCK_LEN];
|
|
uint8_t buf_len;
|
|
uint8_t blocks_compressed;
|
|
uint8_t flags;
|
|
} blake3_chunk_state;
|
|
|
|
typedef struct {
|
|
uint32_t key[8];
|
|
blake3_chunk_state chunk;
|
|
uint8_t cv_stack_len;
|
|
// The stack size is MAX_DEPTH + 1 because we do lazy merging. For example,
|
|
// with 7 chunks, we have 3 entries in the stack. Adding an 8th chunk
|
|
// requires a 4th entry, rather than merging everything down to 1, because we
|
|
// don't know whether more input is coming. This is different from how the
|
|
// reference implementation does things.
|
|
uint8_t cv_stack[(BLAKE3_MAX_DEPTH + 1) * BLAKE3_OUT_LEN];
|
|
} blake3_hasher;
|
|
|
|
const char *blake3_version(void);
|
|
void blake3_hasher_init(blake3_hasher *self);
|
|
void blake3_hasher_init_keyed(blake3_hasher *self,
|
|
const uint8_t key[BLAKE3_KEY_LEN]);
|
|
void blake3_hasher_init_derive_key(blake3_hasher *self, const char *context);
|
|
void blake3_hasher_init_derive_key_raw(blake3_hasher *self, const void *context,
|
|
size_t context_len);
|
|
void blake3_hasher_update(blake3_hasher *self, const void *input,
|
|
size_t input_len);
|
|
void blake3_hasher_finalize(const blake3_hasher *self, uint8_t *out,
|
|
size_t out_len);
|
|
void blake3_hasher_finalize_seek(const blake3_hasher *self, uint64_t seek,
|
|
uint8_t *out, size_t out_len);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* BLAKE3_H */
|