diff --git a/test/crypto/cipher/aes.js b/test/crypto/cipher/aes.js index c04121e2..62166a7b 100644 --- a/test/crypto/cipher/aes.js +++ b/test/crypto/cipher/aes.js @@ -4,7 +4,7 @@ var openpgp = require('openpgp'), util = openpgp.util, expect = chai.expect; -describe("AES Rijndael cipher test with test vectors from ecb_tbl.txt", function() { +describe('AES Rijndael cipher test with test vectors from ecb_tbl.txt', function() { function test_aes(input, key, output) { var aes = new openpgp.crypto.cipher.aes128(util.bin2str(key)); diff --git a/test/crypto/cipher/cast5.js b/test/crypto/cipher/cast5.js index 949ca847..c1fc7344 100644 --- a/test/crypto/cipher/cast5.js +++ b/test/crypto/cipher/cast5.js @@ -16,7 +16,7 @@ it('CAST-128 cipher test with test vectors from RFC2144', function (done) { for (var i = 0; i < testvectors.length; i++) { var res = test_cast(testvectors[i][1],testvectors[i][0],testvectors[i][2]); - expect(res, 'Testing vector with block ' + util.hexidump(testvectors[i][0]) + + expect(res, 'vector with block ' + util.hexidump(testvectors[i][0]) + ' and key ' + util.hexidump(testvectors[i][1]) + ' should be ' + util.hexidump(testvectors[i][2])).to.be.true; } diff --git a/test/crypto/cipher/des.js b/test/crypto/cipher/des.js index 5afbe776..d002fe0b 100644 --- a/test/crypto/cipher/des.js +++ b/test/crypto/cipher/des.js @@ -4,7 +4,7 @@ var openpgp = require('openpgp'), util = openpgp.util, expect = chai.expect; -describe("TripleDES (EDE) cipher test with test vectors from http://csrc.nist.gov/publications/nistpubs/800-20/800-20.pdf", function() { +describe('TripleDES (EDE) cipher test with test vectors from http://csrc.nist.gov/publications/nistpubs/800-20/800-20.pdf', function() { var key = util.bin2str([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]); var testvectors = [[[0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00],[0x95,0xF8,0xA5,0xE5,0xDD,0x31,0xD9,0x00]], [[0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00],[0xDD,0x7F,0x12,0x1C,0xA5,0x01,0x56,0x19]], @@ -122,13 +122,13 @@ describe("TripleDES (EDE) cipher test with test vectors from http://csrc.nist.go var encrypted = des.encrypt(thisVectorSet[i][0], padding); var decrypted = des.decrypt(encrypted, padding); - expect(util.bin2str(encrypted), 'Testing vector with block [' + util.hexidump(thisVectorSet[i][0]) + + expect(util.bin2str(encrypted), 'vector with block [' + util.hexidump(thisVectorSet[i][0]) + '] and key [' + util.hexstrdump(key) + '] and padding [' + padding + '] should be ' + util.hexidump(thisVectorSet[i][1]) + ' - Actually [' + util.hexidump(encrypted) + ']').to.equal(util.bin2str(thisVectorSet[i][1])); - expect(util.bin2str(decrypted), 'Testing vector with block [' + util.hexidump(thisVectorSet[i][0]) + + expect(util.bin2str(decrypted), 'vector with block [' + util.hexidump(thisVectorSet[i][0]) + '] and key [' + util.hexstrdump(key) + '] and padding [' + padding + '] should be ' + util.hexidump(thisVectorSet[i][0]) + diff --git a/test/crypto/cipher/twofish.js b/test/crypto/cipher/twofish.js index 03c0d67f..3b1dfd8f 100644 --- a/test/crypto/cipher/twofish.js +++ b/test/crypto/cipher/twofish.js @@ -4,7 +4,7 @@ var openpgp = require('openpgp'), util = openpgp.util, expect = chai.expect; -it("Twofish test with test vectors from http://www.schneier.com/code/ecb_ival.txt", function(done) { +it('Twofish with test vectors from http://www.schneier.com/code/ecb_ival.txt', function(done) { function TFencrypt(block, key) { var tf = new openpgp.crypto.cipher.twofish(key); @@ -56,7 +56,7 @@ it("Twofish test with test vectors from http://www.schneier.com/code/ecb_ival.tx testvectors[i] = TFencrypt(testvectors[i-1],util.bin2str(testvectors[i-2].concat(testvectors[i-3]))); continue; } - expect(res, 'Testing vector with block ' + util.hexidump(blk) + + expect(res, 'vector with block ' + util.hexidump(blk) + ' with key ' + util.hexstrdump(key) + ' should be ' + util.hexidump(ct) + ' but is ' + util.hexidump(TFencrypt(blk,key))).to.equal(exp); diff --git a/test/crypto/hash/md5.js b/test/crypto/hash/md5.js index c5d2a318..39c46c83 100644 --- a/test/crypto/hash/md5.js +++ b/test/crypto/hash/md5.js @@ -1,22 +1,16 @@ -var unit = require('../../unit.js'); +'use strict'; -unit.register("MD5 test with test vectors from RFC 1321", function() { - var openpgp = require('openpgp'), - util = openpgp.util, - MD5 = openpgp.crypto.hash.md5; +var openpgp = require('openpgp'), + util = openpgp.util, + MD5 = openpgp.crypto.hash.md5, + expect = chai.expect; - var result = new Array(); - result[0] = new unit.result("MD5 (\"\") = d41d8cd98f00b204e9800998ecf8427e", - util.hexstrdump(MD5("")) == "d41d8cd98f00b204e9800998ecf8427e"); - result[1] = new unit.result("MD5 (\"a\") = 0cc175b9c0f1b6a831c399e269772661", - util.hexstrdump(MD5 ("abc")) == "900150983cd24fb0d6963f7d28e17f72"); - result[2] = new unit.result("MD5 (\"message digest\") = f96b697d7cb7938d525a2f31aaf161d0", - util.hexstrdump(MD5 ("message digest")) == "f96b697d7cb7938d525a2f31aaf161d0"); - result[3] = new unit.result("MD5 (\"abcdefghijklmnopqrstuvwxyz\") = c3fcd3d76192e4007dfb496cca67e13b", - util.hexstrdump(MD5 ("abcdefghijklmnopqrstuvwxyz")) == "c3fcd3d76192e4007dfb496cca67e13b"); - result[4] = new unit.result("MD5 (\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\") = d174ab98d277d9f5a5611c2c9f419d9f", - util.hexstrdump(MD5 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")) == "d174ab98d277d9f5a5611c2c9f419d9f"); - result[5] = new unit.result("MD5 (\"12345678901234567890123456789012345678901234567890123456789012345678901234567890\") = 57edf4a22be3c955ac49da2e2107b67a", - util.hexstrdump(MD5 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890")) == "57edf4a22be3c955ac49da2e2107b67a"); - return result; +it('MD5 with test vectors from RFC 1321', function(done) { + expect(util.hexstrdump(MD5('')), 'MD5("") = d41d8cd98f00b204e9800998ecf8427e').to.equal('d41d8cd98f00b204e9800998ecf8427e'); + expect(util.hexstrdump(MD5('abc')), 'MD5("a") = 0cc175b9c0f1b6a831c399e269772661').to.equal('900150983cd24fb0d6963f7d28e17f72'); + expect(util.hexstrdump(MD5('message digest')), 'MD5("message digest") = f96b697d7cb7938d525a2f31aaf161d0').to.equal('f96b697d7cb7938d525a2f31aaf161d0'); + expect(util.hexstrdump(MD5('abcdefghijklmnopqrstuvwxyz')), 'MD5("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b').to.equal('c3fcd3d76192e4007dfb496cca67e13b'); + expect(util.hexstrdump(MD5('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')), 'MD5("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = d174ab98d277d9f5a5611c2c9f419d9f').to.equal('d174ab98d277d9f5a5611c2c9f419d9f'); + expect(util.hexstrdump(MD5('12345678901234567890123456789012345678901234567890123456789012345678901234567890')), 'MD5("12345678901234567890123456789012345678901234567890123456789012345678901234567890") = 57edf4a22be3c955ac49da2e2107b67a').to.equal('57edf4a22be3c955ac49da2e2107b67a'); + done(); }); diff --git a/test/crypto/hash/ripemd.js b/test/crypto/hash/ripemd.js index 25c3970c..db947e3a 100644 --- a/test/crypto/hash/ripemd.js +++ b/test/crypto/hash/ripemd.js @@ -1,19 +1,14 @@ -var unit = require('../../unit.js'); +'use strict'; -unit.register("RIPE-MD 160 bits test with test vectors from http://homes.esat.kuleuven.be/~bosselae/ripemd160.html", function() { +var openpgp = require('openpgp'), + util = openpgp.util, + RMDstring = openpgp.crypto.hash.ripemd, + expect = chai.expect; - var openpgp = require('openpgp'), - util = openpgp.util, - RMDstring = openpgp.crypto.hash.ripemd; - - var result = new Array(); - result[0] = new unit.result("RMDstring (\"\") = 9c1185a5c5e9fc54612808977ee8f548b2258d31", - util.hexstrdump(RMDstring("")) == "9c1185a5c5e9fc54612808977ee8f548b2258d31"); - result[1] = new unit.result("RMDstring (\"a\") = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe", - util.hexstrdump(RMDstring("a")) == "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"); - result[2] = new unit.result("RMDstring (\"abc\") = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc", - util.hexstrdump(RMDstring("abc")) == "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"); - result[3] = new unit.result("RMDstring (\"message digest\") = 5d0689ef49d2fae572b881b123a85ffa21595f36", - util.hexstrdump(RMDstring("message digest")) == "5d0689ef49d2fae572b881b123a85ffa21595f36"); - return result; +it("RIPE-MD 160 bits with test vectors from http://homes.esat.kuleuven.be/~bosselae/ripemd160.html", function(done) { + expect(util.hexstrdump(RMDstring('')), 'RMDstring("") = 9c1185a5c5e9fc54612808977ee8f548b2258d31').to.equal('9c1185a5c5e9fc54612808977ee8f548b2258d31'); + expect(util.hexstrdump(RMDstring('a')), 'RMDstring("a") = 0bdc9d2d256b3ee9daae347be6f4dc835a467ffe').to.equal('0bdc9d2d256b3ee9daae347be6f4dc835a467ffe'); + expect(util.hexstrdump(RMDstring('abc')), 'RMDstring("abc") = 8eb208f7e05d987a9b044a8e98c6b087f15a0bfc').to.equal('8eb208f7e05d987a9b044a8e98c6b087f15a0bfc'); + expect(util.hexstrdump(RMDstring('message digest')), 'RMDstring("message digest") = 5d0689ef49d2fae572b881b123a85ffa21595f36').to.equal('5d0689ef49d2fae572b881b123a85ffa21595f36'); + done(); }); diff --git a/test/crypto/hash/sha.js b/test/crypto/hash/sha.js index 52f0d304..7bbdf4ea 100644 --- a/test/crypto/hash/sha.js +++ b/test/crypto/hash/sha.js @@ -1,32 +1,20 @@ -var unit = require('../../unit.js'); +'use strict'; +var openpgp = require('openpgp'), + util = openpgp.util, + hash = openpgp.crypto.hash, + expect = chai.expect; -unit.register("SHA* test with test vectors from NIST FIPS 180-2", function() { - var openpgp = require('openpgp'), - util = openpgp.util, - hash = openpgp.crypto.hash; - - var result = new Array(); - - result[0] = new unit.result("SHA1 - a9993e364706816aba3e25717850c26c9cd0d89d = hash.sha1(\"abc\") ", - "a9993e364706816aba3e25717850c26c9cd0d89d" == util.hexstrdump(hash.sha1("abc"))); - result[1] = new unit.result("SHA1 - 84983e441c3bd26ebaae4aa1f95129e5e54670f1 = hash.sha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ", - "84983e441c3bd26ebaae4aa1f95129e5e54670f1" == util.hexstrdump(hash.sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))); - result[2] = new unit.result("SHA224 - 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7 = hash.sha224(\"abc\") ", - "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" == util.hexstrdump(hash.sha224("abc"))); - result[3] = new unit.result("SHA224 - 75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525 = hash.sha224(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ", - "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" == util.hexstrdump(hash.sha224("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))); - result[4] = new unit.result("SHA256 - ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad = hash.sha256(\"abc\") ", - "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" == util.hexstrdump(hash.sha256("abc"))); - result[5] = new unit.result("SHA256 - 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1 = hash.sha256(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ", - "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" == util.hexstrdump(hash.sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))); - result[6] = new unit.result("SHA384 - cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7 = hash.sha384(\"abc\") ", - "cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" == util.hexstrdump(hash.sha384("abc"))); - result[7] = new unit.result("SHA384 - 3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b = str384(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ", - "3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b" == util.hexstrdump(hash.sha384("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))); - result[8] = new unit.result("SHA512 - ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f = hash.sha512(\"abc\") ", - "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" == util.hexstrdump(hash.sha512("abc"))); - result[9] = new unit.result("SHA512 - 204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445 = hash.sha512(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") ", - "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445" == util.hexstrdump(hash.sha512("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"))); - return result; +it('SHA* with test vectors from NIST FIPS 180-2', function(done) { + expect(util.hexstrdump(hash.sha1('abc')), 'hash.sha1("abc") = a9993e364706816aba3e25717850c26c9cd0d89d').to.equal('a9993e364706816aba3e25717850c26c9cd0d89d'); + expect(util.hexstrdump(hash.sha1('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')), 'hash.sha1("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 84983e441c3bd26ebaae4aa1f95129e5e54670f1').to.equal('84983e441c3bd26ebaae4aa1f95129e5e54670f1'); + expect(util.hexstrdump(hash.sha224('abc')), 'hash.sha224("abc") = 23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7').to.equal('23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7'); + expect(util.hexstrdump(hash.sha224('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')), 'hash.sha224("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525').to.equal('75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525'); + expect(util.hexstrdump(hash.sha256('abc')), 'hash.sha256("abc") = ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad').to.equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'); + expect(util.hexstrdump(hash.sha256('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')), 'hash.sha256("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1').to.equal('248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1'); + expect(util.hexstrdump(hash.sha384('abc')), 'hash.sha384("abc") = cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7').to.equal('cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7'); + expect(util.hexstrdump(hash.sha384('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')), 'hash.sha384("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b').to.equal('3391fdddfc8dc7393707a65b1b4709397cf8b1d162af05abfe8f450de5f36bc6b0455a8520bc4e6f5fe95b1fe3c8452b'); + expect(util.hexstrdump(hash.sha512('abc')), 'hash.sha512("abc") = ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f').to.equal('ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f'); + expect(util.hexstrdump(hash.sha512('abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq')), 'hash.sha512("abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq") = 204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445').to.equal('204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445'); + done(); });