- blowfish.js test file: rewording output message

- adding twofish.js test file with test vectors for 256 bit key length
This commit is contained in:
Carsten Wentzlow 2011-12-10 14:41:00 +01:00
parent 982e6992fc
commit 1aa1cb8d9a
3 changed files with 37 additions and 3 deletions

View File

@ -40,10 +40,10 @@ unittests.register("Blowfish cipher test with test vectors from http://www.schne
[[0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10],[0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF],[0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A]]];
for (var i = 0; i < testvectors.length; i++) {
result[i] = new test_result("Testing vectors block "+
result[i] = new test_result("Testing vector with block "+
util.hexidump(testvectors[i][0])+
" with key "+util.hexidump(testvectors[i][1])+
" should be "+util.hexidump(testvectors[i][0]),
" and key "+util.hexidump(testvectors[i][1])+
" should be "+util.hexidump(testvectors[i][2]),
test_bf(testvectors[i][1],testvectors[i][0],testvectors[i][2]));
}
return result;

View File

@ -0,0 +1,33 @@
unittests.register("Twofish test with test vectors from http://www.schneier.com/code/ecb_ival.txt", function() {
var result = new Array();
var start = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var start_short = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
var ct = [[0x57,0xFF,0x73,0x9D,0x4D,0xC9,0x2C,0x1B,0xD7,0xFC,0x01,0x70,0x0C,0xC8,0x21,0x6F],
[0xD4,0x3B,0xB7,0x55,0x6E,0xA3,0x2E,0x46,0xF2,0xA2,0x82,0xB7,0xD4,0x5B,0x4E,0x0D],
[0x90,0xAF,0xE9,0x1B,0xB2,0x88,0x54,0x4F,0x2C,0x32,0xDC,0x23,0x9B,0x26,0x35,0xE6],
[0x6C,0xB4,0x56,0x1C,0x40,0xBF,0x0A,0x97,0x05,0x93,0x1C,0xB6,0xD4,0x08,0xE7,0xFA],
[0x30,0x59,0xD6,0xD6,0x17,0x53,0xB9,0x58,0xD9,0x2F,0x47,0x81,0xC8,0x64,0x0E,0x58],
[0xE6,0x94,0x65,0x77,0x05,0x05,0xD7,0xF8,0x0E,0xF6,0x8C,0xA3,0x8A,0xB3,0xA3,0xD6],
[0x5A,0xB6,0x7A,0x5F,0x85,0x39,0xA4,0xA5,0xFD,0x9F,0x03,0x73,0xBA,0x46,0x34,0x66],
[0xDC,0x09,0x6B,0xCD,0x99,0xFC,0x72,0xF7,0x99,0x36,0xD4,0xC7,0x48,0xE7,0x5A,0xF7],
[0xC5,0xA3,0xE7,0xCE,0xE0,0xF1,0xB7,0x26,0x05,0x28,0xA6,0x8F,0xB4,0xEA,0x05,0xF2],
[0x43,0xD5,0xCE,0xC3,0x27,0xB2,0x4A,0xB9,0x0A,0xD3,0x4A,0x79,0xD0,0x46,0x91,0x51]];
ct[47] = [0x43,0x10,0x58,0xF4,0xDB,0xC7,0xF7,0x34,0xDA,0x4F,0x02,0xF0,0x4C,0xC4,0xF4,0x59];
ct[48] = [0x37,0xFE,0x26,0xFF,0x1C,0xF6,0x61,0x75,0xF5,0xDD,0xF4,0xC3,0x3B,0x97,0xA2,0x05];
for (var i = 0; i < 49; i++) {
if (i == 0)
result[i] = new test_result("Testing vector with block "+util.hexidump(start_short)+" with key "+ util.hexidump(start) +" should be "+util.hexidump(ct[0]),util.bin2str(TFencrypt(start_short,util.bin2str(start))) == util.bin2str(ct[0]));
else if (i == 1)
result[i] = new test_result("Testing vector with block "+util.hexidump(ct[0])+" with key "+ util.hexidump(start) +" should be "+util.hexidump(ct[1]),util.bin2str(TFencrypt(ct[0],util.bin2str(start))) == util.bin2str(ct[1]));
else if (i == 2)
result[i] = new test_result("Testing vector with block "+util.hexidump(ct[i-1])+" with key "+ util.hexidump(ct[i-2].concat(start_short)) +" should be "+util.hexidump(ct[i]),util.bin2str(TFencrypt(ct[i-1],util.bin2str(ct[i-2].concat(start_short)))) == util.bin2str(ct[i]));
else if (i < 10)
result[i] = new test_result("Testing vector with block "+util.hexidump(ct[i-1])+" with key "+ util.hexidump(ct[i-2].concat(ct[i-3])) +" should be "+util.hexidump(ct[i]),util.bin2str(TFencrypt(ct[i-1],util.bin2str(ct[i-2].concat(ct[i-3])))) == util.bin2str(ct[i]));
else if (i > 46)
result[i-37] = new test_result("Testing vector with block "+util.hexidump(ct[i-1])+" with key "+ util.hexidump(ct[i-2].concat(ct[i-3])) +" should be "+util.hexidump(ct[i]),util.bin2str(TFencrypt(ct[i-1],util.bin2str(ct[i-2].concat(ct[i-3])))) == util.bin2str(ct[i]));
else
ct[i] = TFencrypt(ct[i-1],util.bin2str(ct[i-2].concat(ct[i-3])));
}
return result;
});

View File

@ -67,6 +67,7 @@
<script type="text/javascript" src="ciphers/hash/sha.js"></script>
<script type="text/javascript" src="ciphers/hash/ripe-md.js"></script>
<script type="text/javascript" src="ciphers/symmetric/blowfish.js"></script>
<script type="text/javascript" src="ciphers/symmetric/twofish.js"></script>
<title>OpenPGP.js testpage</title>