From a1ff5b27bb059571aa06f4adb41a2f895220c5e7 Mon Sep 17 00:00:00 2001 From: didier amyot Date: Sun, 27 Mar 2016 11:34:05 -0400 Subject: [PATCH] fixed bugs, added more tests --- dist/spritz.js | 2 +- src/spritz.js | 5 ++++- test/utilSpec.js | 27 +++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/dist/spritz.js b/dist/spritz.js index 22b8afd..2efc18e 100644 --- a/dist/spritz.js +++ b/dist/spritz.js @@ -84,7 +84,7 @@ spritz._absorbByte = function _absorbByte(b, state) { spritz._absorbNibble = function _absorbNibble(x, state) { if (state.a === N_OVER_TWO_FLOOR){ - spritz.shuffle(state); + spritz._shuffle(state); } util.swap(state.S, state.a, util.madd(N_OVER_TWO_FLOOR, x)); diff --git a/src/spritz.js b/src/spritz.js index cc2dc4a..23f1f5b 100644 --- a/src/spritz.js +++ b/src/spritz.js @@ -46,7 +46,7 @@ spritz._absorbByte = function _absorbByte(b, state) { spritz._absorbNibble = function _absorbNibble(x, state) { if (state.a === N_OVER_TWO_FLOOR){ - spritz.shuffle(state); + spritz._shuffle(state); } util.swap(state.S, state.a, util.madd(N_OVER_TWO_FLOOR, x)); @@ -150,6 +150,9 @@ spritz.utf8ByteArrayToString = function utf8ByteArrayToString(utf8Array){ }; spritz.hash = function hash(M, r){ + if(r > 255){ + throw "cannot hash into more than 255 bytes"; + } if(typeof M == 'string'){ return spritz.hash(spritz.stringToUtf8ByteArray(M), r); } diff --git a/test/utilSpec.js b/test/utilSpec.js index e7ab311..93f4d6d 100644 --- a/test/utilSpec.js +++ b/test/utilSpec.js @@ -43,6 +43,33 @@ describe('the hash function', function(){ var expt = [2,143,162,180,139,147,74,24,98,184,105,16,81,58,71,103,124,28,45,149,236,62,117,112,120,111,28,50,139,189,74,71]; assert.deepEqual(spritz.hash(M, r), expt); }); + + it('should be able to hash into big outputs', function(){ + var M = 'key'; + var r = 128; + var expt = [161,146,113,209,92,234,84,76,1,178]; + assert.deepEqual(spritz.hash(M, r).splice(0, 10), expt); + + r = 196; + expt = [70,186,211,241,183,79,116,6,36,178,244,78,18,13,72,203,248,160,165,201,59]; + assert.deepEqual(spritz.hash(M, r).splice(0, expt.length), expt); + + + }); + + it('should be able to hash a big chunck of text', function(){ + var message = ""; + for(var i = 0; i < 1000; i++){ + message += "key"; + } + r = 196; + expt = [53,4,194,202,251,2,132,3,208,1,176,128,17,208,30,26,47,86,68,211,170]; + assert.deepEqual(spritz.hash(message, r).splice(0, expt.length), expt); + + r = 255; + expt = [148,179,139,174,155,47,98,51,153,231,105,247,132,230,146]; + assert.deepEqual(spritz.hash(message, r).splice(0, expt.length), expt); + }); }); describe('the encrypt/decrypt function', function(){