Keccak-256 hash function implementation for hashsigs-cpp
| 20 | |
| 21 | // Keccak-256 hash function implementation for hashsigs-cpp |
| 22 | static std::array<uint8_t, 32> keccak256(const std::vector<uint8_t> &data) { |
| 23 | Keccak keccak(Keccak::Keccak256); |
| 24 | std::string hash = keccak(data.data(), data.size()); |
| 25 | |
| 26 | std::array<uint8_t, 32> result; |
| 27 | for (size_t i = 0; i < 32; ++i) { |
| 28 | std::string byte_str = hash.substr(i * 2, 2); |
| 29 | result[i] = static_cast<uint8_t>(std::stoi(byte_str, nullptr, 16)); |
| 30 | } |
| 31 | return result; |
| 32 | } |
| 33 | |
| 34 | // Helper: parse a hex string into a PublicKey (array<uint8_t, 32>) |
| 35 | static PublicKey parsePublicKeyFromHex(const std::string &hex) { |
no outgoing calls
no test coverage detected