Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
keccak.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/* ethash: C/C++ implementation of Ethash, the Ethereum Proof of Work algorithm.
8 * Copyright 2018-2019 Pawel Bylica.
9 * Licensed under the Apache License, Version 2.0.
10 */
11
12#pragma once
13
14#include "./hash_types.hpp"
17
18#include <stddef.h>
19#include <vector>
20
21#ifdef __cplusplus
22#define NOEXCEPT noexcept
23#else
24#define NOEXCEPT
25#endif
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
39void ethash_keccakf1600(uint64_t state[25]) NOEXCEPT;
40
41struct keccak256 ethash_keccak256(const uint8_t* data, size_t size) NOEXCEPT;
42
43struct keccak256 hash_field_elements(const uint64_t* limbs, size_t num_elements);
44
45struct keccak256 hash_field_element(const uint64_t* limb);
46
47namespace bb::crypto {
52class Keccak {
53 public:
55 // Losing 2 bits of this is not an issue -> we can just reduce mod p
56 {
57 // cast into uint256_t
58 std::vector<uint8_t> buffer = to_buffer(data);
59
60 keccak256 hash_result = ethash_keccak256(&buffer[0], buffer.size());
61 for (auto& word : hash_result.word64s) {
62 if (is_little_endian()) {
63 word = __builtin_bswap64(word);
64 }
65 }
66 std::array<uint8_t, 32> result;
67
68 for (size_t i = 0; i < 4; ++i) {
69 for (size_t j = 0; j < 8; ++j) {
70 uint8_t byte = static_cast<uint8_t>(hash_result.word64s[i] >> (56 - (j * 8)));
71 result[i * 8 + j] = byte;
72 }
73 }
74
75 return from_buffer<bb::fr>(result);
76 }
77};
78} // namespace bb::crypto
79
80#ifdef __cplusplus
81}
82#endif
A wrapper class used to construct KeccakTranscript.
Definition keccak.hpp:52
static bb::fr hash(std::vector< uint256_t > const &data)
Definition keccak.hpp:54
const std::vector< FF > data
struct keccak256 ethash_keccak256(const uint8_t *data, size_t size) NOEXCEPT
Definition keccak.cpp:107
#define NOEXCEPT
Definition keccak.hpp:24
struct keccak256 ethash_keccak256(const uint8_t *data, size_t size) NOEXCEPT
Definition keccak.cpp:107
void ethash_keccakf1600(uint64_t state[25]) NOEXCEPT
struct keccak256 hash_field_elements(const uint64_t *limbs, size_t num_elements)
Definition keccak.cpp:114
struct keccak256 hash_field_element(const uint64_t *limb)
Definition keccak.cpp:136
uint8_t buffer[RANDOM_BUFFER_SIZE]
Definition engine.cpp:34
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
bool is_little_endian()
Definition net.hpp:10
std::vector< uint8_t > to_buffer(T const &value)
uint64_t word64s[4]