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: Complete, auditors: [Nishat], commit: 5be53b6f75bac06d6d0132220044b28777021f0f }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
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
40
41struct keccak256 ethash_keccak256(const uint8_t* data, size_t size) NOEXCEPT;
42
43namespace bb::crypto {
48class Keccak {
49 public:
51 // Losing 2 bits of this is not an issue -> we can just reduce mod p
52 {
53 // cast into uint256_t
54 std::vector<uint8_t> buffer = to_buffer(data);
55
56 keccak256 hash_result = ethash_keccak256(&buffer[0], buffer.size());
57 for (auto& word : hash_result.word64s) {
58 if (is_little_endian()) {
59 word = __builtin_bswap64(word);
60 }
61 }
62 std::array<uint8_t, KECCAK256_OUTPUT_BYTES> result;
63
64 for (size_t i = 0; i < KECCAK256_OUTPUT_WORDS; ++i) {
65 for (size_t j = 0; j < 8; ++j) {
66 uint8_t byte = static_cast<uint8_t>(hash_result.word64s[i] >> (56 - (j * 8)));
67 result[i * 8 + j] = byte;
68 }
69 }
70
71 return from_buffer<bb::fr>(result);
72 }
73};
74} // namespace bb::crypto
75
76#ifdef __cplusplus
77}
78#endif
A wrapper class used to construct KeccakTranscript.
Definition keccak.hpp:48
static bb::fr hash(std::vector< uint256_t > const &data)
Definition keccak.hpp:50
const std::vector< MemoryValue > 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[KECCAKF1600_LANES]) NOEXCEPT
std::unique_ptr< uint8_t[]> buffer
Definition engine.cpp:60
@ KECCAK256_OUTPUT_WORDS
@ KECCAKF1600_LANES
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
bool is_little_endian()
Definition net.hpp:14
std::vector< uint8_t > to_buffer(T const &value)
uint64_t word64s[KECCAK256_OUTPUT_WORDS]