diff --git a/README.md b/README.md index cc6ef1d..1f40082 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,23 @@ -The HKDF Key Derivation Function +# node-hkdf + +The HMAC-based Key Derivation Function for node.js. spec: https://tools.ietf.org/html/rfc5869 + +## install + + npm install hkdf + +## use + + const HKDF = require('hkdf'); + + var hkdf = new HKDF('sha256', 'salt123', 'initialKeyingMaterial'); + hkdf.derive('info', 42, function(key) { + // key is a Buffer, that can be serialized however one desires + console.log(key.toString('hex')); + }); + +## license + +Apache License 2.0 diff --git a/lib/hkdf.js b/lib/hkdf.js index 6314d0c..ec97161 100644 --- a/lib/hkdf.js +++ b/lib/hkdf.js @@ -9,8 +9,7 @@ var crypto = require("crypto"); function zeros(length) { var buf = new Buffer(length); - // XXX is this the character zero, or the byte 0. - buf.fill("0"); + buf.fill(0); return buf.toString(); } @@ -33,20 +32,28 @@ function HKDF(hashAlg, salt, ikm) { HKDF.prototype = { derive: function(info, size, cb) { - var prev = ""; - var output = new Buffer(size); + var prev = new Buffer(0); + var output; + var buffers = []; var num_blocks = Math.ceil(size / this.hashLength); + info = new Buffer(info); for (var i=0; i