Skip to content

Instantly share code, notes, and snippets.

@ian
ian / variableHash.js
Last active August 29, 2015 14:25 — forked from bminer/variableHash.js
Generate a variable-length hash of `data` in Node.js
var crypto = require("crypto");
/* variableHash - Generate a variable-length hash of `data`.
Similar to the answer here: http://crypto.stackexchange.com/a/3559/4829
If you want a b-bit hash of the message m, then use the first b bits of AES-CTR(SHA256(m)).
Rather than using the suggested algorithm in the stackexchange answer above, I developed
my own.
I decided to derive AES256 initialization vector and key from the output of SHA256(data).