[Pkg-javascript-commits] [node-hmac-drbg] 03/12: lib: do not overwrite `.reseed()`

Bastien Roucariès rouca at moszumanska.debian.org
Thu May 4 10:20:13 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-hmac-drbg.

commit 1addd5085ed33c6e50a73f88ea8f134f0314914f
Author: Fedor Indutny <fedor at indutny.com>
Date:   Sun Apr 9 18:32:59 2017 -0400

    lib: do not overwrite `.reseed()`
    
    Fix: #1
---
 lib/hmac-drbg.js  | 10 +++++-----
 test/drbg-test.js | 30 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/lib/hmac-drbg.js b/lib/hmac-drbg.js
index ca735cc..9051a52 100644
--- a/lib/hmac-drbg.js
+++ b/lib/hmac-drbg.js
@@ -13,7 +13,7 @@ function HmacDRBG(options) {
   this.outLen = this.hash.outSize;
   this.minEntropy = options.minEntropy || this.hash.hmacStrength;
 
-  this.reseed = null;
+  this._reseed = null;
   this.reseedInterval = null;
   this.K = null;
   this.V = null;
@@ -38,7 +38,7 @@ HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
   }
 
   this._update(seed);
-  this.reseed = 1;
+  this._reseed = 1;
   this.reseedInterval = 0x1000000000000;  // 2^48
 };
 
@@ -80,11 +80,11 @@ HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
          'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
 
   this._update(entropy.concat(add || []));
-  this.reseed = 1;
+  this._reseed = 1;
 };
 
 HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
-  if (this.reseed > this.reseedInterval)
+  if (this._reseed > this.reseedInterval)
     throw new Error('Reseed is required');
 
   // Optional encoding
@@ -108,6 +108,6 @@ HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
 
   var res = temp.slice(0, len);
   this._update(add);
-  this.reseed++;
+  this._reseed++;
   return utils.encode(res, enc);
 };
diff --git a/test/drbg-test.js b/test/drbg-test.js
index 55446cc..14fd28a 100644
--- a/test/drbg-test.js
+++ b/test/drbg-test.js
@@ -58,4 +58,34 @@ describe('Hmac_DRBG', () => {
       });
     });
   });
+
+  describe('reseeding', function() {
+    it('should reseed', function() {
+      const entropy = 'totally random string with many chars that I typed ' +
+                      'in agony';
+      const nonce = 'nonce';
+      const pers = 'pers';
+
+      const original = HmacDRBG({
+        hash: hash.sha256,
+        entropy,
+        nonce,
+        pers
+      });
+      const reseeded = HmacDRBG({
+        hash: hash.sha256,
+        entropy,
+        nonce,
+        pers
+      });
+
+      assert.strictEqual(original.generate(32, 'hex'),
+                         reseeded.generate(32, 'hex'));
+
+      reseeded.reseed('another absolutely random string');
+
+      assert.notEqual(original.generate(32, 'hex'),
+                      reseeded.generate(32, 'hex'));
+    });
+  });
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-hmac-drbg.git



More information about the Pkg-javascript-commits mailing list