From f6a72b26c2b2d0d300b10d1c8192ca90a724a615 Mon Sep 17 00:00:00 2001 From: Zachary Carter Date: Wed, 19 Jun 2013 20:23:52 -0700 Subject: [PATCH 1/3] fix implementation, with additional tests --- lib/hkdf.js | 21 ++++++++++++++------- test/all-test.js | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 9 deletions(-) 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 Date: Sun, 23 Jun 2013 16:22:31 -0700 Subject: [PATCH 2/3] remove private flag --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 9d60b39..43d33db 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,6 @@ { "name" : "node-hkdf", "version" : "0.0.1", - "private" : true, "description" : "HKDF key derivation function", "main" : "index", "repository" : { From 1bbdf710f56a2f9af7e0a8d9af32db572b4a1354 Mon Sep 17 00:00:00 2001 From: Zach Carter Date: Sun, 23 Jun 2013 17:49:58 -0600 Subject: [PATCH 3/3] Update README.md --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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