pub fn verifySignature(sig: []const u8, msg: []const u8, pubkey: []const u8) !bool { // Validate lengths if (sig.len != 64) return error.InvalidSignatureLength; if (pubkey.len != 33 and pubkey.len != 65) return error.InvalidPublicKeyLength; // Validate signature components (r, s in valid range) const r = sig[0..32]; const s = sig[32..64]; if (!isValidScalar(r) or !isValidScalar(s)) return error.InvalidSignature; // ... verification logic ...}
Test Vectors
Every crypto function needs test vectors from official sources:
test "Whirlpool official test vectors" { // From ISO/IEC 10118-3:2004 const vectors = .{ .{ .input = "", .expected = "19FA61D75522A466..." }, .{ .input = "a", .expected = "8ACA2602792AEC6F..." }, .{ .input = "abc", .expected = "..." }, // ... more vectors }; for (vectors) |v| { const result = Whirlpool.hash(v.input); const expected = try hexToBytes(v.expected); try std.testing.expectEqualSlices(u8, &expected, &result); }}
Cross-Validation
Test against reference implementations:
// Whirlpool.test.tsimport { whirlpool as nobleWhirlpool } from "@noble/hashes/whirlpool";describe("cross-validation", () => { it("matches noble implementation", () => { const data = "test data"; const ours = Whirlpool.hash(data); const noble = nobleWhirlpool(data); expect(ours).toEqual(noble); }); // Fuzz test it("matches noble for random inputs", () => { for (let i = 0; i < 1000; i++) { const data = crypto.getRandomValues(new Uint8Array(Math.random() * 1000)); const ours = Whirlpool.hash(data); const noble = nobleWhirlpool(data); expect(ours).toEqual(noble); } });});
Documentation
// docs/crypto/whirlpool/index.mdx---title: Whirlpooldescription: Whirlpool cryptographic hash function---# WhirlpoolWhirlpool is a cryptographic hash function that produces a 512-bit digest.<Warning>Whirlpool is not commonly used in Ethereum. Consider using [Keccak256](/crypto/keccak256) for Ethereum operations.</Warning>## Usage```typescriptimport * as Whirlpool from "@tevm/voltaire/Whirlpool";// Hash a stringconst hash = Whirlpool.hash("hello world");// Hash as hexconst hex = Whirlpool.hashHex("hello world");```text## Security- 512-bit output- Designed by Vincent Rijmen and Paulo Barreto- Standardized in ISO/IEC 10118-3:2004## Test Vectors| Input | Output (truncated) ||-------|-------------------|| `""` | `0x19FA61D75522A466...` || `"abc"` | `0x...` |