Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
blake3-impl.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
8/*
9 BLAKE3 reference source code package - C implementations
10
11 Intellectual property:
12
13 The Rust code is copyright Jack O'Connor, 2019-2020.
14 The C code is copyright Samuel Neves and Jack O'Connor, 2019-2020.
15 The assembly code is copyright Samuel Neves, 2019-2020.
16
17 This work is released into the public domain with CC0 1.0. Alternatively, it is licensed under the Apache
18 License 2.0.
19
20 - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
21 - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
22
23 More information about the BLAKE3 hash function can be found at
24 https://github.com/BLAKE3-team/BLAKE3.
25*/
26
27#ifndef BLAKE3_IMPL_H
28#define BLAKE3_IMPL_H
29
30#include <cstddef>
31#include <cstdint>
32#include <cstring>
33
34#include "blake3s.hpp"
35
36namespace blake3 {
37
38// Right rotates 32 bit inputs
39constexpr uint32_t rotr32(uint32_t w, uint32_t c)
40{
41 return (w >> c) | (w << (32 - c));
42}
43
44constexpr uint32_t load32(const uint8_t* src)
45{
46 return (static_cast<uint32_t>(src[0]) << 0) | (static_cast<uint32_t>(src[1]) << 8) |
47 (static_cast<uint32_t>(src[2]) << 16) | (static_cast<uint32_t>(src[3]) << 24);
48}
49
51{
52 key_words[0] = load32(&key[0]);
53 key_words[1] = load32(&key[4]);
54 key_words[2] = load32(&key[8]);
55 key_words[3] = load32(&key[12]);
56 key_words[4] = load32(&key[16]);
57 key_words[5] = load32(&key[20]);
58 key_words[6] = load32(&key[24]);
59 key_words[7] = load32(&key[28]);
60}
61
62constexpr void store32(uint8_t* dst, uint32_t w)
63{
64 dst[0] = static_cast<uint8_t>(w >> 0);
65 dst[1] = static_cast<uint8_t>(w >> 8);
66 dst[2] = static_cast<uint8_t>(w >> 16);
67 dst[3] = static_cast<uint8_t>(w >> 24);
68}
69
70constexpr void store_cv_words(out_array& bytes_out, key_array& cv_words)
71{
72 store32(&bytes_out[0], cv_words[0]);
73 store32(&bytes_out[4], cv_words[1]);
74 store32(&bytes_out[8], cv_words[2]);
75 store32(&bytes_out[12], cv_words[3]);
76 store32(&bytes_out[16], cv_words[4]);
77 store32(&bytes_out[20], cv_words[5]);
78 store32(&bytes_out[24], cv_words[6]);
79 store32(&bytes_out[28], cv_words[7]);
80}
81
82} // namespace blake3
83
84#include "blake3s.tcc"
85
86#endif
constexpr uint32_t load32(const uint8_t *src)
std::array< uint32_t, BLAKE3_KEY_LEN > key_array
Definition blake3s.hpp:65
constexpr void store_cv_words(out_array &bytes_out, key_array &cv_words)
constexpr void load_key_words(const std::array< uint8_t, BLAKE3_KEY_LEN > &key, key_array &key_words)
constexpr void store32(uint8_t *dst, uint32_t w)
std::array< uint8_t, BLAKE3_OUT_LEN > out_array
Definition blake3s.hpp:68
constexpr uint32_t rotr32(uint32_t w, uint32_t c)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13