SipHash24 implemented in WebAssembly.
Tailored to
Deno
All credit to the original authors Jean-Philippe Aumasson and Daniel J. Bernstein, as well as open-source contributors jedisct1 (Frank Denis), mafintosh and emilbayes for porting the reference implementation to JavaScript and WebAssembly.
import { siphash24 } from "https://denopkg.com/chiefbiiko/siphash24/mod.ts";
import {
BYTES,
siphash24
} from "https://denopkg.com/chiefbiiko/siphash24/mod.ts";
import {
encode,
decode
} from "https://denopkg.com/chiefbiiko/std-encoding/mod.ts";
const msg: Uint8Array = encode("msg from a MIB"); // x-byte msg
const key: Uint8Array = encode("sixteen_byte_key"); // 16-byte key
const mac: Uint8Array = new Uint8Array(BYTES); // 8-byte mac
siphash24(msg, key, mac);
console.log(
"msg: ",
decode(msg),
"\nkey: ",
decode(key),
"\nmac: ",
decode(mac, "hex")
);
Mac a variable-length message with a 16-byte key while providing a 8-byte output buffer.
Jean-Philippe Aumasson & Daniel J. Bernstein (2012-09-18). "SipHash: a fast short-input PRF".
SipHash (2-4) implemented in pure Javascript and WebAssembly