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
26namespace secp256k1::coins {
27
28// -- Keccak-256 State ---------------------------------------------------------
29
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
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
49std::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
std::array< std::uint8_t, 32 > keccak256(const std::uint8_t *data, std::size_t len)
std::array< std::uint8_t, 32 > finalize()
void update(const std::uint8_t *data, std::size_t len)