// Keccak-256 (Ethereum's pre-standard SHA-3) via BouncyCastle, plus hex helpers. using System; using Org.BouncyCastle.Crypto.Digests; namespace Nethermind.AerePqc.Qbft; public static class Keccak256 { public static byte[] Hash(byte[] data) { var d = new KeccakDigest(256); d.BlockUpdate(data, 0, data.Length); var outp = new byte[32]; d.DoFinal(outp, 0); return outp; } } public static class Hex { public static byte[] Decode(string s) { if (s.StartsWith("0x") || s.StartsWith("0X")) s = s.Substring(2); if (s.Length == 0) return Array.Empty(); if ((s.Length & 1) != 0) s = "0" + s; var b = new byte[s.Length / 2]; for (int i = 0; i < b.Length; i++) b[i] = Convert.ToByte(s.Substring(i * 2, 2), 16); return b; } public static string Encode(byte[] b) => "0x" + Convert.ToHexString(b).ToLowerInvariant(); }