3 #ifndef CX_BLAKE3_REF_H
4 #define CX_BLAKE3_REF_H
11 #define INLINE static inline __attribute__((always_inline))
13 INLINE uint32_t load32(
const void *src)
15 #if defined(NATIVE_LITTLE_ENDIAN)
17 memcpy(&w, src,
sizeof w);
21 return ((uint32_t) (p[0]) << 0) | ((uint32_t) (p[1]) << 8) | ((uint32_t) (p[2]) << 16)
22 | ((uint32_t) (p[3]) << 24);
26 INLINE uint32_t rotr32(uint32_t w, uint32_t c)
28 return (w >> c) | (w << (32 - c));
31 INLINE
void load_key_words(
const uint8_t key[BLAKE3_KEY_LEN], uint32_t key_words[8])
33 key_words[0] = load32(&key[0 * 4]);
34 key_words[1] = load32(&key[1 * 4]);
35 key_words[2] = load32(&key[2 * 4]);
36 key_words[3] = load32(&key[3 * 4]);
37 key_words[4] = load32(&key[4 * 4]);
38 key_words[5] = load32(&key[5 * 4]);
39 key_words[6] = load32(&key[6 * 4]);
40 key_words[7] = load32(&key[7 * 4]);
43 INLINE
void store32(
void *dst, uint32_t w)
45 #if defined(NATIVE_LITTLE_ENDIAN)
46 memcpy(dst, &w,
sizeof w);
56 INLINE
void store_cv_words(
uint8_t bytes_out[32], uint32_t cv_words[8])
58 store32(&bytes_out[0 * 4], cv_words[0]);
59 store32(&bytes_out[1 * 4], cv_words[1]);
60 store32(&bytes_out[2 * 4], cv_words[2]);
61 store32(&bytes_out[3 * 4], cv_words[3]);
62 store32(&bytes_out[4 * 4], cv_words[4]);
63 store32(&bytes_out[5 * 4], cv_words[5]);
64 store32(&bytes_out[6 * 4], cv_words[6]);
65 store32(&bytes_out[7 * 4], cv_words[7]);
68 static unsigned int highest_one(uint64_t x)
71 if (x & 0xffffffff00000000ULL) {
75 if (x & 0x00000000ffff0000ULL) {
79 if (x & 0x000000000000ff00ULL) {
83 if (x & 0x00000000000000f0ULL) {
87 if (x & 0x000000000000000cULL) {
91 if (x & 0x0000000000000002ULL) {
99 INLINE
unsigned int hw(uint64_t x)
101 unsigned int count = 0;
120 void blake3_state_init(cx_blake3_state_t *chunk_state,
const uint32_t *key,
uint8_t flags);
131 void blake3_state_update(cx_blake3_state_t *chunk_state,
const uint8_t *input,
size_t input_len);
143 void blake3_state_reset(cx_blake3_state_t *chunk_state,
145 uint64_t chunk_counter);
161 cx_blake3_state_out_t blake3_state_output(
const cx_blake3_state_t *chunk_state);
174 void blake3_output_chain(
const cx_blake3_state_out_t *out,
uint8_t *cv);
193 void blake3_compress_subtree_to_parent(
const uint8_t *input,
196 uint64_t chunk_counter,
207 void blake3_hasher_merge_cv(cx_blake3_t *hash, uint64_t total_len);
218 void blake3_hasher_push_cv(cx_blake3_t *hash,
uint8_t *new_cv, uint64_t chunk_counter);
230 void blake3_output_root_bytes(
const cx_blake3_state_out_t *chunk_out,
uint8_t *out,
size_t out_len);
244 void blake3_init_ctx(cx_blake3_t *hash,
const uint32_t *key,
uint8_t mode);