diff options
Diffstat (limited to 'node_modules/des.js/test')
-rw-r--r-- | node_modules/des.js/test/cbc-test.js | 73 | ||||
-rw-r--r-- | node_modules/des.js/test/des-test.js | 139 | ||||
-rw-r--r-- | node_modules/des.js/test/ede-test.js | 73 | ||||
-rw-r--r-- | node_modules/des.js/test/fixtures.js | 5 | ||||
-rw-r--r-- | node_modules/des.js/test/utils-test.js | 169 |
5 files changed, 0 insertions, 459 deletions
diff --git a/node_modules/des.js/test/cbc-test.js b/node_modules/des.js/test/cbc-test.js deleted file mode 100644 index d07881c..0000000 --- a/node_modules/des.js/test/cbc-test.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var crypto = require('crypto'); -var Buffer = require('buffer').Buffer; - -var des = require('../'); - -var fixtures = require('./fixtures'); -var bin = fixtures.bin; - -describe('DES-CBC', function() { - var CBC = des.CBC.instantiate(des.DES); - - describe('encryption/decryption', function() { - var vectors = [ - { - key: '133457799bbcdff1', - iv: '0102030405060708', - input: '0123456789abcdef' - }, - { - key: '0000000000000000', - iv: 'ffffffffffffffff', - input: '0000000000000000' - }, - { - key: 'a3a3a3a3b3b3b3b3', - iv: 'cdcdcdcdcdcdcdcd', - input: 'cccccccccccccccc' - }, - { - key: 'deadbeefabbadead', - iv: 'a0da0da0da0da0da', - input: '0102030405060708090a' - }, - { - key: 'aabbccddeeff0011', - iv: 'fefefefefefefefe', - input: '0102030405060708090a0102030405060708090a0102030405060708090a' + - '0102030405060708090a0102030405060607080a0102030405060708090a' - } - ]; - - vectors.forEach(function(vec, i) { - it('should encrypt vector ' + i, function() { - var key = new Buffer(vec.key, 'hex'); - var iv = new Buffer(vec.iv, 'hex'); - var input = new Buffer(vec.input, 'hex'); - - var enc = CBC.create({ - type: 'encrypt', - key: key, - iv: iv - }); - var out = new Buffer(enc.update(input).concat(enc.final())); - - var cipher = crypto.createCipheriv('des-cbc', key, iv); - var expected = Buffer.concat([ cipher.update(input), cipher.final() ]); - - assert.deepEqual(out, expected); - - var dec = CBC.create({ - type: 'decrypt', - key: key, - iv: iv - }); - assert.deepEqual(new Buffer(dec.update(out).concat(dec.final())), - input); - }); - }); - }); -}); diff --git a/node_modules/des.js/test/des-test.js b/node_modules/des.js/test/des-test.js deleted file mode 100644 index b6a5ee8..0000000 --- a/node_modules/des.js/test/des-test.js +++ /dev/null @@ -1,139 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var crypto = require('crypto'); -var Buffer = require('buffer').Buffer; - -var des = require('../'); - -var fixtures = require('./fixtures'); -var bin = fixtures.bin; - -describe('DES', function() { - describe('Key Derivation', function() { - it('should derive proper keys', function() { - var d = des.DES.create({ - type: 'encrypt', - key: [ 0x13, 0x34, 0x57, 0x79, 0x9B, 0xBC, 0xDF, 0xF1 ] - }); - - var expected = [ - '000110 110000 001011 101111', - '111111 000111 000001 110010', - '011110 011010 111011 011001', - '110110 111100 100111 100101', - '010101 011111 110010 001010', - '010000 101100 111110 011001', - '011100 101010 110111 010110', - '110110 110011 010100 011101', - '011111 001110 110000 000111', - '111010 110101 001110 101000', - '011000 111010 010100 111110', - '010100 000111 101100 101111', - '111011 001000 010010 110111', - '111101 100001 100010 111100', - '111101 111000 101000 111010', - '110000 010011 101111 111011', - '111000 001101 101111 101011', - '111011 011110 011110 000001', - '101100 011111 001101 000111', - '101110 100100 011001 001111', - '001000 010101 111111 010011', - '110111 101101 001110 000110', - '011101 010111 000111 110101', - '100101 000110 011111 101001', - '100101 111100 010111 010001', - '111110 101011 101001 000001', - '010111 110100 001110 110111', - '111100 101110 011100 111010', - '101111 111001 000110 001101', - '001111 010011 111100 001010', - '110010 110011 110110 001011', - '000011 100001 011111 110101' - ]; - - expected = expected.map(fixtures.bin); - assert.deepEqual(d._desState.keys, expected); - }); - }); - - describe('encryption/decryption', function() { - var vectors = [ - { - key: '133457799bbcdff1', - input: '0123456789abcdef' - }, - { - key: '0000000000000000', - input: '0000000000000000' - }, - { - key: 'a3a3a3a3b3b3b3b3', - input: 'cccccccccccccccc' - }, - { - key: 'deadbeefabbadead', - input: '0102030405060708090a' - }, - { - key: 'aabbccddeeff0011', - input: '0102030405060708090a0102030405060708090a0102030405060708090a' + - '0102030405060708090a0102030405060607080a0102030405060708090a' - } - ]; - - vectors.forEach(function(vec, i) { - it('should encrypt vector ' + i, function() { - var key = new Buffer(vec.key, 'hex'); - var input = new Buffer(vec.input, 'hex'); - - var enc = des.DES.create({ - type: 'encrypt', - key: key - }); - var dec = des.DES.create({ - type: 'decrypt', - key: key - }); - var out = new Buffer(enc.update(input).concat(enc.final())); - - var cipher = crypto.createCipheriv('des-ecb', key, new Buffer(0)); - var expected = Buffer.concat([ cipher.update(input), cipher.final() ]); - - assert.deepEqual(out, expected); - - assert.deepEqual(new Buffer(dec.update(out).concat(dec.final())), - input); - }); - }); - - it('should buffer during encryption/decryption', function() { - var key = new Buffer('0102030405060708', 'hex'); - var chunk = new Buffer('01020304050607', 'hex'); - var count = 257; - var expected = new Buffer( - new Array(count + 1).join('01020304050607'), 'hex'); - - var enc = des.DES.create({ - type: 'encrypt', - key: key - }); - var cipher = []; - for (var i = 0; i < count; i++) - cipher = cipher.concat(enc.update(chunk)); - cipher = cipher.concat(enc.final()); - - var dec = des.DES.create({ - type: 'decrypt', - key: key - }); - var out = []; - for (var i = 0; i < count; i++) - out = out.concat(dec.update(cipher.slice(i * 7, (i + 1) * 7))); - out = out.concat(dec.final(cipher.slice(i * 7))); - - out = new Buffer(out); - assert.deepEqual(out, expected); - }); - }); -}); diff --git a/node_modules/des.js/test/ede-test.js b/node_modules/des.js/test/ede-test.js deleted file mode 100644 index 116a76a..0000000 --- a/node_modules/des.js/test/ede-test.js +++ /dev/null @@ -1,73 +0,0 @@ -'use strict'; - -var assert = require('assert'); -var crypto = require('crypto'); -var Buffer = require('buffer').Buffer; - -var des = require('../'); - -var fixtures = require('./fixtures'); -var bin = fixtures.bin; - -describe('DES-EDE-CBC', function() { - var CBC = des.CBC.instantiate(des.EDE); - - describe('encryption/decryption', function() { - var vectors = [ - { - key: new Array(4).join('133457799bbcdff1'), - iv: '0102030405060708', - input: '0123456789abcdef' - }, - { - key: new Array(4).join('0000000000000000'), - iv: 'ffffffffffffffff', - input: '0000000000000000' - }, - { - key: new Array(4).join('a3a3a3a3b3b3b3b3'), - iv: 'cdcdcdcdcdcdcdcd', - input: 'cccccccccccccccc' - }, - { - key: new Array(4).join('deadbeefabbadead'), - iv: 'a0da0da0da0da0da', - input: '0102030405060708090a' - }, - { - key: 'aabbccddeeff0011' + '1111222233334444' + 'ffffeeeeddddcccc', - iv: 'fefefefefefefefe', - input: '0102030405060708090a0102030405060708090a0102030405060708090a' + - '0102030405060708090a0102030405060607080a0102030405060708090a' - } - ]; - - vectors.forEach(function(vec, i) { - it('should encrypt vector ' + i, function() { - var key = new Buffer(vec.key, 'hex'); - var iv = new Buffer(vec.iv, 'hex'); - var input = new Buffer(vec.input, 'hex'); - - var enc = CBC.create({ - type: 'encrypt', - key: key, - iv: iv - }); - var out = new Buffer(enc.update(input).concat(enc.final())); - - var cipher = crypto.createCipheriv('des-ede3-cbc', key, iv); - var expected = Buffer.concat([ cipher.update(input), cipher.final() ]); - - assert.deepEqual(out, expected); - - var dec = CBC.create({ - type: 'decrypt', - key: key, - iv: iv - }); - assert.deepEqual(new Buffer(dec.update(out).concat(dec.final())), - input); - }); - }); - }); -}); diff --git a/node_modules/des.js/test/fixtures.js b/node_modules/des.js/test/fixtures.js deleted file mode 100644 index fe8ccd8..0000000 --- a/node_modules/des.js/test/fixtures.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -exports.bin = function bin(str) { - return parseInt(str.replace(/[^01]/g, ''), 2); -} diff --git a/node_modules/des.js/test/utils-test.js b/node_modules/des.js/test/utils-test.js deleted file mode 100644 index 4c576de..0000000 --- a/node_modules/des.js/test/utils-test.js +++ /dev/null @@ -1,169 +0,0 @@ -'use strict'; - -var assert = require('assert'); - -var des = require('../'); -var utils = des.utils; - -var fixtures = require('./fixtures'); -var bin = fixtures.bin; - -describe('utils', function() { - describe('IP', function() { - it('should permute properly', function() { - var out = new Array(2); - var inp = [ - bin('00000001 00100011 01000101 01100111'), - bin('10001001 10101011 11001101 11101111') - ]; - - utils.ip(inp[0], inp[1], out, 0); - - var expected = [ - bin('11001100 00000000 11001100 11111111'), - bin('11110000 10101010 11110000 10101010') - ]; - - assert.deepEqual(out, expected); - }); - - it('should rev-permute properly', function() { - var out = new Array(2); - var inp = [ - bin('11001100 00000000 11001100 11111111'), - bin('11110000 10101010 11110000 10101010') - ]; - - utils.rip(inp[0], inp[1], out, 0); - - var expected = [ - bin('00000001 00100011 01000101 01100111'), - bin('10001001 10101011 11001101 11101111') - ]; - - assert.deepEqual(out, expected); - }); - }); - - describe('PC1', function() { - it('should permute properly', function() { - var out = new Array(2); - var inp = [ - bin('00010011 00110100 01010111 01111001'), - bin('10011011 10111100 11011111 11110001') - ]; - - utils.pc1(inp[0], inp[1], out, 0); - - var expected = [ - bin('1111000 0110011 0010101 0101111'), - bin('0101010 1011001 1001111 0001111') - ]; - - assert.deepEqual(out, expected); - }); - }); - - describe('r28shl', function() { - it('should shl properly', function() { - assert.equal(utils.r28shl(bin('1111000011001100101010101111'), 1), - bin('1110000110011001010101011111')); - - assert.equal(utils.r28shl(bin('0101010101100110011110001111'), 1), - bin('1010101011001100111100011110')); - - assert.equal(utils.r28shl(bin('1111000011001100101010101111'), 4), - bin('0000110011001010101011111111')); - - assert.equal(utils.r28shl(bin('0101010101100110011110001111'), 4), - bin('0101011001100111100011110101')); - }); - }); - - describe('PC2', function() { - it('should permute properly', function() { - var out = new Array(2); - var inp = [ - bin('1110000 1100110 0101010 1011111'), - bin('1010101 0110011 0011110 0011110') - ]; - - utils.pc2(inp[0], inp[1], out, 0); - - var expected = [ - bin('000110 110000 001011 101111'), - bin('111111 000111 000001 110010') - ]; - - assert.deepEqual(out, expected); - }); - }); - - describe('readUInt32BE', function() { - it('should read number properly', function() { - var a = [ 0xde, 0xad, 0xbe, 0xef ]; - var o = utils.readUInt32BE(a, 0); - assert.equal(o, 0xdeadbeef); - }); - }); - - describe('writeUInt32BE', function() { - it('should read number properly', function() { - var a = [ 0, 0, 0, 0 ]; - utils.writeUInt32BE(a, 0xdeadbeef, 0); - var expected = [ 0xde, 0xad, 0xbe, 0xef ]; - assert.deepEqual(a, expected); - }); - }); - - describe('expand', function() { - it('should expand', function() { - var out = [ 0, 0 ]; - utils.expand(bin('1111 0000 1010 1010 1111 0000 1010 1010'), out, 0); - var expected = [ - bin('011110 100001 010101 010101'), - bin('011110 100001 010101 010101') - ]; - assert.deepEqual(out, expected); - }); - - it('should expand with low 1', function() { - var out = [ 0, 0 ]; - utils.expand(bin('1111 0000 1010 1010 1111 0000 1010 1011'), out, 0); - var expected = [ - bin('111110 100001 010101 010101'), - bin('011110 100001 010101 010111') - ]; - assert.deepEqual(out, expected); - }); - - it('should expand with low 1', function() { - var out = [ 0, 0 ]; - utils.expand(bin('10100010 01011100 00001011 11110100'), out, 0); - var expected = [ - bin('010100 000100 001011 111000'), - bin('000001 010111 111110 101001') - ]; - assert.deepEqual(out, expected); - }); - }); - - describe('substitute', function() { - it('should substitute', function() { - var input = [ - bin('011000 010001 011110 111010'), - bin('100001 100110 010100 100111') - ]; - var output = utils.substitute(input[0], input[1]); - assert.equal(output, bin('0101 1100 1000 0010 1011 0101 1001 0111')); - }); - }); - - describe('permute', function() { - it('should permute', function() { - var output = utils.permute( - bin('0101 1100 1000 0010 1011 0101 1001 0111')); - assert.equal(output, bin('0010 0011 0100 1010 1010 1001 1011 1011')); - }); - }); -}); |