Skip to content

Commit

Permalink
Separate out tests into separate files & move to test folder
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisveness committed Oct 15, 2016
1 parent 17e31f7 commit d69d567
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 46 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Chris Veness",
"version": "0.0.0",
"scripts": {
"test": "mocha test.js",
"test": "mocha test/*.js",
"lint": "eslint *.js"
},
"devDependencies": {
Expand Down
51 changes: 6 additions & 45 deletions test.js → test/aes.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
// Crypto Test Harness (c) Chris Veness 2014 */
// Crypto Test Harness - AES (c) Chris Veness 2014-2016 */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

'use strict';

var chai = require('chai'); // BDD/TDD assertion library

var Aes = require('../aes.js');
Aes.Ctr = require('../aes-ctr.js');

chai.should();
var test = it; // just an alias


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* AES - test vectors: csrc.nist.gov/publications/fips/fips197/fips-197.pdf C.1 */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('aes', function() {
var Aes = require('./aes.js');

var plaintext = vectorToBytes('00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff');

var key128 = vectorToBytes('00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f');
Expand Down Expand Up @@ -46,59 +48,18 @@ describe('aes', function() {
}
});


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Aes CTR: test Unicode text & password (ciphertext will be different on each invocation) */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('aes.ctr', function() {
var Aes = require('./aes.js');
Aes.Ctr = require('./aes-ctr.js');

var origtext = 'My big secret סוד קצת بت سرية ความลับบิต 位的秘密';
var ciphertext = Aes.Ctr.encrypt(origtext, 'pāšşŵōřđ', 256);
var decrtext = Aes.Ctr.decrypt(ciphertext, 'pāšşŵōřđ', 256);

test('decrypted ciphertext matches original text', function() { decrtext.should.equal(origtext); });
});

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Block TEA: test decrypted encrypted text matches original text (with Unicode text & password) */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('tea-block', function() {
var Tea = require('./tea-block.js');

var origtext = 'My big secret סוד קצת بت سرية ความลับบิต 位的秘密';
var ciphertext = Tea.encrypt(origtext, 'pāšşŵōřđ');
var decrtext = Tea.decrypt(ciphertext, 'pāšşŵōřđ');

test('decrypted ciphertext matches original text', function() { decrtext.should.equal(origtext); });
});

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-1: csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA1.pdf */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('sha1', function() {
var Sha1 = require('./sha1.js');

var msg1 = 'abc';
test('sha1 1 block msg', function() { Sha1.hash(msg1).should.equal('a9993e364706816aba3e25717850c26c9cd0d89d'); });
var msg2 = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq';
test('sha1 2 block msg', function() { Sha1.hash(msg2).should.equal('84983e441c3bd26ebaae4aa1f95129e5e54670f1'); });
});

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-256: csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA256.pdf */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('sha256', function() {
var Sha256 = require('./sha256.js');

var msg1 = 'abc';
test('sha256 1 block msg', function() { Sha256.hash(msg1).should.equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'); });
var msg2 = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq';
test('sha256 2 block msg', function() { Sha256.hash(msg2).should.equal('248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1'); });
});

/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
40 changes: 40 additions & 0 deletions test/sha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
// Crypto Test Harness - SHA (c) Chris Veness 2014-2016 */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

'use strict';

var chai = require('chai'); // BDD/TDD assertion library

var Sha1 = require('../sha1.js');
var Sha256 = require('../sha256.js');

chai.should();
var test = it; // just an alias


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-1: csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA1.pdf */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('sha1', function() {
var msg1 = 'abc';
test('sha1 1 block msg', function() { Sha1.hash(msg1).should.equal('a9993e364706816aba3e25717850c26c9cd0d89d'); });
var msg2 = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq';
test('sha1 2 block msg', function() { Sha1.hash(msg2).should.equal('84983e441c3bd26ebaae4aa1f95129e5e54670f1'); });
});


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* SHA-256: csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA256.pdf */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('sha256', function() {
var msg1 = 'abc';
test('sha256 1 block msg', function() { Sha256.hash(msg1).should.equal('ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'); });
var msg2 = 'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq';
test('sha256 2 block msg', function() { Sha256.hash(msg2).should.equal('248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1'); });
});


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28 changes: 28 additions & 0 deletions test/tea.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
// Crypto Test Harness - TEA (c) Chris Veness 2014-2016 */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

'use strict';

var chai = require('chai'); // BDD/TDD assertion library

var Tea = require('../tea-block.js');

chai.should();
var test = it; // just an alias


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Block TEA: test decrypted encrypted text matches original text (with Unicode text & password) */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

describe('tea-block', function() {
var origtext = 'My big secret סוד קצת بت سرية ความลับบิต 位的秘密';
var ciphertext = Tea.encrypt(origtext, 'pāšşŵōřđ');
var decrtext = Tea.decrypt(ciphertext, 'pāšşŵōřđ');

test('decrypted ciphertext matches original text', function() { decrtext.should.equal(origtext); });
});


/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

0 comments on commit d69d567

Please sign in to comment.