UltrafastSecp256k1
3.50.0
Ultra high-performance secp256k1 elliptic curve cryptography library
Loading...
Searching...
No Matches
keccak256.hpp
Go to the documentation of this file.
1
#ifndef SECP256K1_COINS_KECCAK256_HPP
2
#define SECP256K1_COINS_KECCAK256_HPP
3
#pragma once
4
5
// ============================================================================
6
// Keccak-256 Hash Function
7
// ============================================================================
8
// Standard Keccak-256 (NOT SHA3-256; Ethereum uses raw Keccak before NIST
9
// finalization, i.e., without the 0x06 domain separator).
10
//
11
// Used by:
12
// - Ethereum address derivation (Keccak-256 of uncompressed pubkey)
13
// - EVM-compatible chains (BSC, Polygon, Avalanche, etc.)
14
// - Solidity keccak256()
15
//
16
// Implementation:
17
// - No heap allocation
18
// - Fixed 32-byte output
19
// - Incremental (absorb/squeeze) API available
20
// ============================================================================
21
22
#include <array>
23
#include <cstdint>
24
#include <cstddef>
25
26
namespace
secp256k1::coins
{
27
28
// -- Keccak-256 State ---------------------------------------------------------
29
30
struct
Keccak256State
{
31
std::uint64_t
state
[25];
// 1600-bit Keccak state (5x5 lanes)
32
std::uint8_t
buf
[136];
// Rate buffer (r = 1088 bits = 136 bytes)
33
std::size_t
buf_pos
;
// Current position in buffer
34
35
Keccak256State
();
36
~Keccak256State
();
37
38
// Absorb data
39
void
update
(
const
std::uint8_t* data, std::size_t len);
40
41
// Finalize and produce 32-byte hash
42
// Uses Keccak padding (0x01), NOT SHA3 padding (0x06)
43
std::array<std::uint8_t, 32>
finalize
();
44
};
45
46
// -- One-Shot API -------------------------------------------------------------
47
48
// Compute Keccak-256 hash of data
49
std::array<std::uint8_t, 32>
keccak256
(
const
std::uint8_t* data, std::size_t len);
50
51
}
// namespace secp256k1::coins
52
53
#endif
// SECP256K1_COINS_KECCAK256_HPP
secp256k1::coins
Definition
coin_address.hpp:32
secp256k1::coins::keccak256
std::array< std::uint8_t, 32 > keccak256(const std::uint8_t *data, std::size_t len)
secp256k1::coins::Keccak256State
Definition
keccak256.hpp:30
secp256k1::coins::Keccak256State::Keccak256State
Keccak256State()
secp256k1::coins::Keccak256State::buf_pos
std::size_t buf_pos
Definition
keccak256.hpp:33
secp256k1::coins::Keccak256State::~Keccak256State
~Keccak256State()
secp256k1::coins::Keccak256State::state
std::uint64_t state[25]
Definition
keccak256.hpp:31
secp256k1::coins::Keccak256State::finalize
std::array< std::uint8_t, 32 > finalize()
secp256k1::coins::Keccak256State::buf
std::uint8_t buf[136]
Definition
keccak256.hpp:32
secp256k1::coins::Keccak256State::update
void update(const std::uint8_t *data, std::size_t len)
cpu
include
secp256k1
coins
keccak256.hpp
Generated by
1.9.8