Changeset - bcd08758ec7c
[Not reviewed]
default
0 3 1
Laman - 5 years ago 2019-06-29 18:09:21

testing blake
4 files changed with 47 insertions and 2 deletions:
0 comments (0 inline, 0 general)
spec/test/blakeSpec.js
Show inline comments
 
new file 100644
 
/* global expect */
 

	
 
describe("Blake2",function(){
 
	let cryptoJS=require("../../dist/main.js");
 
	let util=cryptoJS.util;
 
	let blake2s=cryptoJS.blake2s;
 
	let str2utf8=util.str2utf8;
 
	
 
	let msg=str2utf8("abc");
 
	let longMsg=str2utf8("0123456789.10.456789.20.456789.30.456789.40.456789.50.456789.60.456789.70.456789.80.456789.90.456789");
 
	let key=str2utf8("zoqpiz");
 
	let longKey=str2utf8("zoqpizjutyclcmkamzhhmhvchxjtefjy");
 
	
 
	describe("blake2s",function(){
 
		it("should return a correct variable size output",function(){
 
			expect(util.bytes2hex(blake2s(msg,16))).toEqual("aa4938119b1dc7b87cbad0ffd200d0ae");
 
		});
 
		it("should work with just a message",function(){
 
			expect(util.bytes2hex(blake2s(msg))).toEqual("508c5e8c327c14e2e1a72ba34eeb452f37458b209ed63a294d999b4c86675982");
 
		});
 
		it("should work for multi block messages",function(){
 
			expect(util.bytes2hex(blake2s(longMsg.slice(0,64)))).toEqual("70484f89974551454d596350dda8af2aa6f0811b527549b9ecfe7adede063753");
 
			expect(util.bytes2hex(blake2s(longMsg.slice(0,65)))).toEqual("af14d4f74947bbde734d0e3015c667cc80676efe4349be235be8046e9e45e0ae");
 
			expect(util.bytes2hex(blake2s(longMsg))).toEqual("59a44e5e417d07fb382505ee7e67c23e0d476d354abc81899960bcab677beee1");
 
		});
 
		it("should work for keyed messages",function(){
 
			expect(util.bytes2hex(blake2s(msg,32,key))).toEqual("0da0b6a54e8f294b60bb25c572700166ddb9d124257ff36f9f43f18b844adf9f");
 
		});
 
		it("should work with long keyes",function(){
 
			expect(util.bytes2hex(blake2s(msg,32,longKey))).toEqual("09ef85c9942bebdeb866c6ade769220fd9b851aead642017f6d59bf7e2a32037");
 
		});
 
		it("should work with an empty input",function(){
 
			expect(util.bytes2hex(blake2s([]))).toEqual("69217a3079908094e11121d042354a7c1f55b6482ca1a51e1b250dfd1ed0eef9");
 
		});
 
	});
 
	
 
});
spec/test/utilSpec.js
Show inline comments
 
/* global expect */
 

	
 
describe("Util",function(){
 
  let util=require("../../src/util.js");
 
  let cryptoJS=require("../../dist/main.js");
 
	let util=cryptoJS.util;
 
	let utf=[ // https://tools.ietf.org/html/rfc3629#page-8
 
		["",[]],
 
		["abc",[97,98,99]],
src/blake.js
Show inline comments
 
// https://tools.ietf.org/html/rfc7693
 
import {MASK,int32s2bytes,bytes2int32s} from "./util.js";
 

	
 
const BLOCK_LEN=64;
 

	
src/main.js
Show inline comments
 
@@ -3,4 +3,10 @@ import {blake2s} from "./blake.js";
 
import {Chacha20} from "./chacha.js";
 

	
 
export default {util,blake2s,Chacha20};
 
	
 
\ No newline at end of file
 

	
 
// export for tests running on Node
 
if(typeof module!=='undefined'&&module.hasOwnProperty('exports')){
 
	module.exports.util=util;
 
	module.exports.blake2s=blake2s;
 
	module.exports.Chacha20=Chacha20;
 
}
0 comments (0 inline, 0 general)