fixed bugs, added more tests
This commit is contained in:
1 parent
5a8274a7ef
commit
a1ff5b27bb
3 files changed
+32
-2
No files matched your search
Vendored
+1
-1
@@ -84,7 +84,7 @@ spritz._absorbByte = function _absorbByte(b, state) {
|
|||||||
|
|
||||||
spritz._absorbNibble = function _absorbNibble(x, state) {
|
spritz._absorbNibble = function _absorbNibble(x, state) {
|
||||||
if (state.a === N_OVER_TWO_FLOOR){
|
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));
|
util.swap(state.S, state.a, util.madd(N_OVER_TWO_FLOOR, x));
|
||||||
|
|||||||
+4
-1
@@ -46,7 +46,7 @@ spritz._absorbByte = function _absorbByte(b, state) {
|
|||||||
|
|
||||||
spritz._absorbNibble = function _absorbNibble(x, state) {
|
spritz._absorbNibble = function _absorbNibble(x, state) {
|
||||||
if (state.a === N_OVER_TWO_FLOOR){
|
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));
|
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){
|
spritz.hash = function hash(M, r){
|
||||||
|
if(r > 255){
|
||||||
|
throw "cannot hash into more than 255 bytes";
|
||||||
|
}
|
||||||
if(typeof M == 'string'){
|
if(typeof M == 'string'){
|
||||||
return spritz.hash(spritz.stringToUtf8ByteArray(M), r);
|
return spritz.hash(spritz.stringToUtf8ByteArray(M), r);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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];
|
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);
|
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(){
|
describe('the encrypt/decrypt function', function(){
|
||||||
|
|||||||
Reference in new issue
Block a user