Started porting crypto tests

This commit is contained in:
Robert Nelson 2014-01-03 08:10:50 -08:00
parent e5e1675615
commit 3beb4ac0ad
9 changed files with 279 additions and 281 deletions

View File

@ -1,2 +1,3 @@
require('./ci-quick.js'); require('./ci-quick.js');
require('./general'); require('./general');
require('./crypto');

View File

@ -1,11 +1,12 @@
var unit = require('../../unit.js'); var openpgp = require('openpgp');
unit.register("AES Rijndael cipher test with test vectors from ecb_tbl.txt", function() { 'use strict';
var openpgp = require('openpgp');
var expect = chai.expect;
describe("AES Rijndael cipher test with test vectors from ecb_tbl.txt", function() {
var util = openpgp.util; var util = openpgp.util;
var result = new Array();
function test_aes(input, key, output) { function test_aes(input, key, output) {
var aes = new openpgp.crypto.cipher.aes128(util.bin2str(key)); var aes = new openpgp.crypto.cipher.aes128(util.bin2str(key));
@ -62,60 +63,33 @@ unit.register("AES Rijndael cipher test with test vectors from ecb_tbl.txt", fun
[[0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x10,0x12,0x13,0x14,0x15,0x17,0x18,0x19,0x1A,0x1C,0x1D,0x1E,0x1F,0x21,0x22,0x23,0x24,0x26,0x27,0x28,0x29,0x2B,0x2C,0x2D,0x2E],[0x06,0x9A,0x00,0x7F,0xC7,0x6A,0x45,0x9F,0x98,0xBA,0xF9,0x17,0xFE,0xDF,0x95,0x21],[0x08,0x0E,0x95,0x17,0xEB,0x16,0x77,0x71,0x9A,0xCF,0x72,0x80,0x86,0x04,0x0A,0xE3]], [[0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x10,0x12,0x13,0x14,0x15,0x17,0x18,0x19,0x1A,0x1C,0x1D,0x1E,0x1F,0x21,0x22,0x23,0x24,0x26,0x27,0x28,0x29,0x2B,0x2C,0x2D,0x2E],[0x06,0x9A,0x00,0x7F,0xC7,0x6A,0x45,0x9F,0x98,0xBA,0xF9,0x17,0xFE,0xDF,0x95,0x21],[0x08,0x0E,0x95,0x17,0xEB,0x16,0x77,0x71,0x9A,0xCF,0x72,0x80,0x86,0x04,0x0A,0xE3]],
[[0x30,0x31,0x32,0x33,0x35,0x36,0x37,0x38,0x3A,0x3B,0x3C,0x3D,0x3F,0x40,0x41,0x42,0x44,0x45,0x46,0x47,0x49,0x4A,0x4B,0x4C,0x4E,0x4F,0x50,0x51,0x53,0x54,0x55,0x56],[0x72,0x61,0x65,0xC1,0x72,0x3F,0xBC,0xF6,0xC0,0x26,0xD7,0xD0,0x0B,0x09,0x10,0x27],[0x7C,0x17,0x00,0x21,0x1A,0x39,0x91,0xFC,0x0E,0xCD,0xED,0x0A,0xB3,0xE5,0x76,0xB0]]]; [[0x30,0x31,0x32,0x33,0x35,0x36,0x37,0x38,0x3A,0x3B,0x3C,0x3D,0x3F,0x40,0x41,0x42,0x44,0x45,0x46,0x47,0x49,0x4A,0x4B,0x4C,0x4E,0x4F,0x50,0x51,0x53,0x54,0x55,0x56],[0x72,0x61,0x65,0xC1,0x72,0x3F,0xBC,0xF6,0xC0,0x26,0xD7,0xD0,0x0B,0x09,0x10,0x27],[0x7C,0x17,0x00,0x21,0x1A,0x39,0x91,0xFC,0x0E,0xCD,0xED,0x0A,0xB3,0xE5,0x76,0xB0]]];
var res = true; it('128 bit key', function (done) {
var j = 0;
for (var i = 0; i < testvectors128.length; i++) { for (var i = 0; i < testvectors128.length; i++) {
var res2 = test_aes(testvectors128[i][1],testvectors128[i][0],testvectors128[i][2]); var res = test_aes(testvectors128[i][1],testvectors128[i][0],testvectors128[i][2]);
res &= res2; expect(res, 'block ' + util.hexidump(testvectors128[i][1]) +
if (!res2) { ' and key '+util.hexidump(testvectors128[i][0]) +
result[j] = new unit.result("Testing 128 bit key vector with block "+ ' should be '+util.hexidump(testvectors128[i][2])).to.be.true;
util.hexidump(testvectors128[i][1])+
" and key "+util.hexidump(testvectors128[i][0])+
" should be "+util.hexidump(testvectors128[i][2]),
false);
j++;
}
}
if (res) {
result[j] = new unit.result("128 bit key test vectors completed.",true)
j++;
} }
done();
});
res = true; it('192 bit key', function (done) {
for (var i = 0; i < testvectors192.length; i++) { for (var i = 0; i < testvectors192.length; i++) {
var res2 = test_aes(testvectors192[i][1],testvectors192[i][0],testvectors192[i][2]); var res = test_aes(testvectors192[i][1],testvectors192[i][0],testvectors192[i][2]);
res &= res2; expect(res, 'block ' + util.hexidump(testvectors192[i][1]) +
if (!res2) { ' and key ' + util.hexidump(testvectors192[i][0])+
result[j] = new unit.result("Testing 192 bit key vector with block "+ ' should be ' + util.hexidump(testvectors192[i][2])).to.be.true;
util.hexidump(testvectors192[i][1])+
" and key "+util.hexidump(testvectors192[i][0])+
" should be "+util.hexidump(testvectors192[i][2]),
false);
j++;
}
}
if (res) {
result[j] = new unit.result("192 bit key test vectors completed.",true)
j++;
} }
done();
});
res = true; it('256 bit key', function (done) {
for (var i = 0; i < testvectors256.length; i++) { for (var i = 0; i < testvectors256.length; i++) {
var res2 = test_aes(testvectors256[i][1],testvectors256[i][0],testvectors256[i][2]); var res = test_aes(testvectors256[i][1],testvectors256[i][0],testvectors256[i][2]);
res &= res2; expect(res, 'block ' + util.hexidump(testvectors256[i][1]) +
if (!res2) { ' and key ' + util.hexidump(testvectors256[i][0]) +
result[j] = new unit.result("Testing 256 bit key vector with block "+ ' should be ' + util.hexidump(testvectors256[i][2]));
util.hexidump(testvectors256[i][1])+
" and key "+util.hexidump(testvectors256[i][0])+
" should be "+util.hexidump(testvectors256[i][2]),
false);
j++;
} }
} done();
if (res) { });
result[j] = new unit.result("256 bit key test vectors completed.", true)
j++;
}
return result;
}); });

View File

@ -1,9 +1,11 @@
var unit = require('../unit.js'); var openpgp = require('openpgp');
unit.register("Functional testing of openpgp.crypto.* methods", function() { 'use strict';
var openpgp = require('openpgp');
var expect = chai.expect;
describe('API functional testing', function() {
var util = openpgp.util; var util = openpgp.util;
var result = [];
var RSApubMPIstrs = [ var RSApubMPIstrs = [
util.bin2str([0x08,0x00,0xac,0x15,0xb3,0xd6,0xd2,0x0f,0xf0,0x7a,0xdd,0x21,0xb7, util.bin2str([0x08,0x00,0xac,0x15,0xb3,0xd6,0xd2,0x0f,0xf0,0x7a,0xdd,0x21,0xb7,
0xbf,0x61,0xfa,0xca,0x93,0x86,0xc8,0x55,0x5a,0x4b,0xa6,0xa4,0x1a, 0xbf,0x61,0xfa,0xca,0x93,0x86,0xc8,0x55,0x5a,0x4b,0xa6,0xa4,0x1a,
@ -136,56 +138,54 @@ unit.register("Functional testing of openpgp.crypto.* methods", function() {
0x67,0x8d,0x9d,0x14,0xb6,0x9d,0x32,0x82,0xd0,0xb5,0xc6,0x57,0xf0,0x91,0xd9, 0x67,0x8d,0x9d,0x14,0xb6,0x9d,0x32,0x82,0xd0,0xb5,0xc6,0x57,0xf0,0x91,0xd9,
0xc3,0x26,0xae,0x9f,0xa9,0x67,0x49,0x96,0x5c,0x07,0x3e,0x47,0x5c,0xed,0x60, 0xc3,0x26,0xae,0x9f,0xa9,0x67,0x49,0x96,0x5c,0x07,0x3e,0x47,0x5c,0xed,0x60,
0x07,0xac,0x6a])]; 0x07,0xac,0x6a])];
var DSAsecMPIstrs = [util.bin2str([0x01,0x00,0x9b,0x58,0xa8,0xf4,0x04,0xb1,0xd5,0x14,0x09,0xe1, var DSAsecMPIstrs = [
0xe1,0xa1,0x8a,0x0b,0xa3,0xc3,0xa3,0x66,0xaa,0x27,0x99,0x50, util.bin2str([0x01,0x00,0x9b,0x58,0xa8,0xf4,0x04,0xb1,0xd5,0x14,0x09,0xe1,0xe1,0xa1,0x8a,
0x1c,0x4d,0xba,0x24,0xee,0xdf,0xdf,0xb8,0x8e,0x8e])]; 0x0b,0xa3,0xc3,0xa3,0x66,0xaa,0x27,0x99,0x50,0x1c,0x4d,0xba,0x24,0xee,0xdf,
0xdf,0xb8,0x8e,0x8e])];
var ElgamalpubMPIstrs = var ElgamalpubMPIstrs = [
[util.bin2str([0x08,0x00,0xea,0xcc,0xbe,0xe2,0xe4,0x5a,0x51,0x18,0x93,0xa1,0x12,0x2f, util.bin2str([0x08,0x00,0xea,0xcc,0xb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69,0xe0,0x2b,0x05,0xee,0xb7, 0x69,0xe0,0x2b,0x05,0xee,0xb7,0xa7,0x7f,0xf3,0x21,0x48,0x85,0xc2,0x95,0x5f,
0xa7,0x7f,0xf3,0x21,0x48,0x85,0xc2,0x95,0x5f,0x6f,0x1e,0xb3,0x9b,0x97, 0x6f,0x1e,0xb3,0x9b,0x97,0xf8,0x14,0xc3,0xff,0x4d,0x97,0x25,0x29,0x94,0x41,
0xf8,0x14,0xc3,0xff,0x4d,0x97,0x25,0x29,0x94,0x41,0x4b,0x90,0xd8,0xba, 0x4b,0x90,0xd8,0xba,0x71,0x45,0x4b,0x1e,0x2f,0xca,0x82,0x5f,0x56,0x77,0xe9,
0x71,0x45,0x4b,0x1e,0x2f,0xca,0x82,0x5f,0x56,0x77,0xe9,0xd3,0x88,0x5d, 0xd3,0x88,0x5d,0x8b,0xec,0x92,0x8b,0x8a,0x23,0x88,0x05,0xf8,0x2c,0xa8,0xf1,
0x8b,0xec,0x92,0x8b,0x8a,0x23,0x88,0x05,0xf8,0x2c,0xa8,0xf1,0x70,0x76, 0x70,0x76,0xe7,0xbf,0x75,0xa8,0x31,0x14,0x8e,0x76,0xc8,0x01,0xa6,0x25,0x27,
0xe7,0xbf,0x75,0xa8,0x31,0x14,0x8e,0x76,0xc8,0x01,0xa6,0x25,0x27,0x49, 0x49,0xaf,0xdc,0xf4,0xf6,0xf4,0xce,0x90,0x84,0x15,0x2b,0x4d,0xb3,0xcc,0x77,
0xaf,0xdc,0xf4,0xf6,0xf4,0xce,0x90,0x84,0x15,0x2b,0x4d,0xb3,0xcc,0x77, 0xdb,0x65,0x71,0x75,0xd3,0x00,0x1d,0x22,0xc5,0x42,0x2f,0x51,0xfa,0x7b,0xeb,
0xdb,0x65,0x71,0x75,0xd3,0x00,0x1d,0x22,0xc5,0x42,0x2f,0x51,0xfa,0x7b, 0x6e,0x03,0xd9,0x41,0xdd,0x2d,0x1a,0xdd,0x07,0x74,0x8b,0xb7,0xa2,0xfa,0xb2,
0xeb,0x6e,0x03,0xd9,0x41,0xdd,0x2d,0x1a,0xdd,0x07,0x74,0x8b,0xb7,0xa2, 0x59,0x0e,0x0e,0x94,0x7c,0x00,0xad,0x95,0x23,0x42,0x91,0x18,0x4c,0x97,0xf1,
0xfa,0xb2,0x59,0x0e,0x0e,0x94,0x7c,0x00,0xad,0x95,0x23,0x42,0x91,0x18, 0x27,0x62,0x77]),
0x4c,0x97,0xf1,0x27,0x62,0x77]),
util.bin2str([0x00,0x03,0x05]), util.bin2str([0x00,0x03,0x05]),
util.bin2str([0x07,0xff,0x57,0x19,0x76,0xfc,0x09,0x6a,0x7a,0xf7,0xba,0xb2,0x42,0xbf, util.bin2str([0x07,0xff,0x57,0x19,0x76,0xfc,0x09,0x6a,0x7a,0xf7,0xba,0xb2,0x42,0xbf,0xcd,
0xcd,0x2b,0xc1,0x1a,0x79,0x25,0x8c,0xad,0xf4,0x3a,0x0a,0x7a,0x9b,0x4c, 0x2b,0xc1,0x1a,0x79,0x25,0x8c,0xad,0xf4,0x3a,0x0a,0x7a,0x9b,0x4c,0x46,0x3c,
0x46,0x3c,0xe0,0x4f,0xcc,0x6e,0xe5,0x7a,0x33,0x3a,0x4e,0x80,0xcb,0xd3, 0xe0,0x4f,0xcc,0x6e,0xe5,0x7a,0x33,0x3a,0x4e,0x80,0xcb,0xd3,0x62,0xd7,0x8f,
0x62,0xd7,0x8f,0xe2,0xc8,0xb0,0xd0,0xcb,0x49,0xc9,0x9e,0x2d,0x97,0x16, 0xe2,0xc8,0xb0,0xd0,0xcb,0x49,0xc9,0x9e,0x2d,0x97,0x16,0x3a,0x7d,0xb1,0xe1,
0x3a,0x7d,0xb1,0xe1,0xd3,0xd9,0xd7,0x3f,0x20,0x60,0xe3,0x3e,0x77,0xea, 0xd3,0xd9,0xd7,0x3f,0x20,0x60,0xe3,0x3e,0x77,0xea,0x0c,0xe4,0x7b,0xf0,0x39,
0x0c,0xe4,0x7b,0xf0,0x39,0x1a,0x0d,0xd9,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28,0x1d,0x4e,
0xd1,0x76,0xc2,0xbe,0x01,0x82,0x61,0x8d,0xe7,0x7e,0x28,0x1d,0x4e,0x8c, 0x8c,0xb9,0xe8,0x7e,0xa4,0x5f,0xa6,0x3a,0x9e,0x5d,0xac,0xf3,0x60,0x22,0x14,
0xb9,0xe8,0x7e,0xa4,0x5f,0xa6,0x3a,0x9e,0x5d,0xac,0xf3,0x60,0x22,0x14, 0xd5,0xd5,0xbe,0x1f,0xf0,0x19,0xe6,0x81,0xfd,0x5d,0xe1,0xf8,0x76,0x5f,0xe3,
0xd5,0xd5,0xbe,0x1f,0xf0,0x19,0xe6,0x81,0xfd,0x5d,0xe1,0xf8,0x76,0x5f, 0xda,0xba,0x19,0xf3,0xcb,0x10,0xa0,0x6b,0xd0,0x2d,0xbe,0x40,0x42,0x7b,0x9b,
0xe3,0xda,0xba,0x19,0xf3,0xcb,0x10,0xa0,0x6b,0xd0,0x2d,0xbe,0x40,0x42, 0x15,0xa4,0x2d,0xec,0xcf,0x09,0xd6,0xe3,0x92,0xc3,0x8d,0x65,0x6b,0x60,0x97,
0x7b,0x9b,0x15,0xa4,0x2d,0xec,0xcf,0x09,0xd6,0xe3,0x92,0xc3,0x8d,0x65, 0xda,0x6b,0xca])];
0x6b,0x60,0x97,0xda,0x6b,0xca])];
var ElgamalsecMPIstrs = [ var ElgamalsecMPIstrs = [
util.bin2str([0x01,0x52,0x02,0x80,0x87,0xf6,0xe4,0x49,0xd7,0x2e,0x3e,0xfe,0x60,0xb9, util.bin2str([0x01,0x52,0x02,0x80,0x87,0xf6,0xe4,0x49,0xd7,0x2e,0x3e,0xfe,0x60,0xb9,0xa3,
0xa3,0x2a,0xf0,0x67,0x58,0xe9,0xf6,0x47,0x83,0xde,0x7e,0xfb,0xbb,0xbd, 0x2a,0xf0,0x67,0x58,0xe9,0xf6,0x47,0x83,0xde,0x7e,0xfb,0xbb,0xbd,0xdf,0x48,
0xdf,0x48,0x12,0x1b,0x06,0x7d,0x13,0xbc,0x3b,0x49,0xf9,0x86,0xd4,0x53, 0x12,0x1b,0x06,0x7d,0x13,0xbc,0x3b,0x49,0xf9,0x86,0xd4,0x53,0xed,0x2d,0x68])];
0xed,0x2d,0x68])];
var RSApubMPIs = []; var RSApubMPIs = [];
var i; var i;
@ -223,14 +223,19 @@ unit.register("Functional testing of openpgp.crypto.* methods", function() {
ElgamalpubMPIs[i].read(ElgamalpubMPIstrs[i]); ElgamalpubMPIs[i].read(ElgamalpubMPIstrs[i]);
} }
describe('Sign and verify', function () {
it('RSA', function (done) {
//Originally we passed public and secret MPI separately, now they are joined. Is this what we want to do long term? //Originally we passed public and secret MPI separately, now they are joined. Is this what we want to do long term?
// RSA // RSA
var RSAsignedData = openpgp.crypto.signature.sign(2, 1, RSApubMPIs.concat(RSAsecMPIs), "foobar"); var RSAsignedData = openpgp.crypto.signature.sign(2, 1, RSApubMPIs.concat(RSAsecMPIs), "foobar");
var RSAsignedDataMPI = new openpgp.mpi(); var RSAsignedDataMPI = new openpgp.mpi();
RSAsignedDataMPI.read(RSAsignedData); RSAsignedDataMPI.read(RSAsignedData);
result[0] = new unit.result("Testing RSA Sign and Verify", var success = openpgp.crypto.signature.verify(1, 2, [RSAsignedDataMPI], RSApubMPIs, "foobar");
openpgp.crypto.signature.verify(1, 2, [RSAsignedDataMPI], RSApubMPIs, "foobar")); expect(success).to.be.true;
done();
});
it('DSA', function (done) {
// DSA // DSA
var DSAsignedData = openpgp.crypto.signature.sign(2, 17, DSApubMPIs.concat(DSAsecMPIs), "foobar"); var DSAsignedData = openpgp.crypto.signature.sign(2, 17, DSApubMPIs.concat(DSAsecMPIs), "foobar");
@ -239,32 +244,50 @@ unit.register("Functional testing of openpgp.crypto.* methods", function() {
DSAmsgMPIs[1] = new openpgp.mpi(); DSAmsgMPIs[1] = new openpgp.mpi();
DSAmsgMPIs[0].read(DSAsignedData.substring(0,34)); DSAmsgMPIs[0].read(DSAsignedData.substring(0,34));
DSAmsgMPIs[1].read(DSAsignedData.substring(34,68)); DSAmsgMPIs[1].read(DSAsignedData.substring(34,68));
result[1] = new unit.result("Testing DSA Sign and Verify", var success = openpgp.crypto.signature.verify(17, 2, DSAmsgMPIs, DSApubMPIs, "foobar");
openpgp.crypto.signature.verify(17, 2, DSAmsgMPIs, DSApubMPIs, "foobar")); expect(success).to.be.true;
done();
});
});
describe('Encrypt and decrypt', function () {
var symmAlgo = "aes256"; // AES256 var symmAlgo = "aes256"; // AES256
var symmKey = openpgp.crypto.generateSessionKey(symmAlgo); var symmKey = openpgp.crypto.generateSessionKey(symmAlgo);
var symmencDataOCFB = openpgp.crypto.cfb.encrypt(openpgp.crypto.getPrefixRandom(symmAlgo), symmAlgo, "foobarfoobar1234567890", symmKey, true); var symmencDataOCFB = openpgp.crypto.cfb.encrypt(openpgp.crypto.getPrefixRandom(symmAlgo), symmAlgo, "foobarfoobar1234567890", symmKey, true);
var symmencDataCFB = openpgp.crypto.cfb.encrypt(openpgp.crypto.getPrefixRandom(symmAlgo), symmAlgo, "foobarfoobar1234567890", symmKey, false); var symmencDataCFB = openpgp.crypto.cfb.encrypt(openpgp.crypto.getPrefixRandom(symmAlgo), symmAlgo, "foobarfoobar1234567890", symmKey, false);
result[2] = new unit.result("Testing symmetric encrypt and decrypt with OpenPGP CFB resync", it("Symmetric with OpenPGP CFB resync", function (done) {
openpgp.crypto.cfb.decrypt(symmAlgo,symmKey,symmencDataOCFB,true) == "foobarfoobar1234567890"); var text = openpgp.crypto.cfb.decrypt(symmAlgo,symmKey,symmencDataOCFB,true);
result[3] = new unit.result("Testing symmetric encrypt and decrypt without OpenPGP CFB resync (used in modification detection code \"MDC\" packets)",
openpgp.crypto.cfb.decrypt(symmAlgo,symmKey,symmencDataCFB,false) == "foobarfoobar1234567890");
expect(text).to.equal("foobarfoobar1234567890");
done();
});
it("Symmetric without OpenPGP CFB resync", function (done) {
var text = openpgp.crypto.cfb.decrypt(symmAlgo,symmKey,symmencDataCFB,false);
expect(text).to.equal("foobarfoobar1234567890");
done();
});
it('Asymmetric using RSA with eme_pkcs1 padding', function (done) {
var RSAUnencryptedData = new openpgp.mpi(); var RSAUnencryptedData = new openpgp.mpi();
RSAUnencryptedData.fromBytes(openpgp.crypto.pkcs1.eme.encode(symmKey, RSApubMPIs[0].byteLength())); RSAUnencryptedData.fromBytes(openpgp.crypto.pkcs1.eme.encode(symmKey, RSApubMPIs[0].byteLength()));
var RSAEncryptedData = openpgp.crypto.publicKeyEncrypt("rsa_encrypt_sign", RSApubMPIs, RSAUnencryptedData); var RSAEncryptedData = openpgp.crypto.publicKeyEncrypt("rsa_encrypt_sign", RSApubMPIs, RSAUnencryptedData);
result[4] = new unit.result("Testing asymmetric encrypt and decrypt using RSA with eme_pkcs1 padding", var result = openpgp.crypto.pkcs1.eme.decode(openpgp.crypto.publicKeyDecrypt("rsa_encrypt_sign", RSApubMPIs.concat(RSAsecMPIs), RSAEncryptedData).write().substring(2), RSApubMPIs[0].byteLength());
openpgp.crypto.pkcs1.eme.decode(openpgp.crypto.publicKeyDecrypt("rsa_encrypt_sign", RSApubMPIs.concat(RSAsecMPIs), RSAEncryptedData).write().substring(2), RSApubMPIs[0].byteLength()) == symmKey); expect(result).to.equal(symmKey);
done();
});
it('Asymmetric using Elgamal with eme_pkcs1 padding', function (done) {
var ElgamalUnencryptedData = new openpgp.mpi(); var ElgamalUnencryptedData = new openpgp.mpi();
ElgamalUnencryptedData.fromBytes(openpgp.crypto.pkcs1.eme.encode(symmKey, ElgamalpubMPIs[0].byteLength())); ElgamalUnencryptedData.fromBytes(openpgp.crypto.pkcs1.eme.encode(symmKey, ElgamalpubMPIs[0].byteLength()));
var ElgamalEncryptedData = openpgp.crypto.publicKeyEncrypt("elgamal", ElgamalpubMPIs, ElgamalUnencryptedData); var ElgamalEncryptedData = openpgp.crypto.publicKeyEncrypt("elgamal", ElgamalpubMPIs, ElgamalUnencryptedData);
result[5] = new unit.result("Testing asymmetric encrypt and decrypt using Elgamal with eme_pkcs1 padding", var result = openpgp.crypto.pkcs1.eme.decode(openpgp.crypto.publicKeyDecrypt("elgamal", ElgamalpubMPIs.concat(ElgamalsecMPIs), ElgamalEncryptedData).write().substring(2), ElgamalpubMPIs[0].byteLength());
openpgp.crypto.pkcs1.eme.decode(openpgp.crypto.publicKeyDecrypt("elgamal", ElgamalpubMPIs.concat(ElgamalsecMPIs), ElgamalEncryptedData).write().substring(2), ElgamalpubMPIs[0].byteLength()) == symmKey); expect(result).to.equal(symmKey);
done();
return result; });
});
}); });

View File

@ -4,7 +4,7 @@ var openpgp = require('openpgp');
var expect = chai.expect; var expect = chai.expect;
describe('Basic tests', function() { describe('Basic', function() {
describe("Key generation/encryption/decryption", function() { describe("Key generation/encryption/decryption", function() {
var testHelper = function(passphrase, userid, message) { var testHelper = function(passphrase, userid, message) {

View File

@ -1,4 +1,4 @@
describe('General tests', function () { describe('General', function () {
require('./basic.js'); require('./basic.js');
require('./key.js'); require('./key.js');
require('./keyring.js'); require('./keyring.js');

View File

@ -4,7 +4,7 @@ var openpgp = require('openpgp');
var expect = chai.expect; var expect = chai.expect;
describe('Key tests', function() { describe('Key', function() {
var twoKeys = var twoKeys =
['-----BEGIN PGP PUBLIC KEY BLOCK-----', ['-----BEGIN PGP PUBLIC KEY BLOCK-----',
'Version: GnuPG v2.0.19 (GNU/Linux)', 'Version: GnuPG v2.0.19 (GNU/Linux)',

View File

@ -4,7 +4,7 @@ var openpgp = require('openpgp');
var expect = chai.expect; var expect = chai.expect;
describe("Keyring testing", function() { describe("Keyring", function() {
var keyring = new (new require('keyring'))(); var keyring = new (new require('keyring'))();
keyring.init(); keyring.init();

View File

@ -4,7 +4,7 @@ var openpgp = require('openpgp');
var expect = chai.expect; var expect = chai.expect;
describe("Packet testing", function() { describe("Packet", function() {
var armored_key = var armored_key =
'-----BEGIN PGP PRIVATE KEY BLOCK-----\n' + '-----BEGIN PGP PRIVATE KEY BLOCK-----\n' +
'Version: GnuPG v2.0.19 (GNU/Linux)\n' + 'Version: GnuPG v2.0.19 (GNU/Linux)\n' +

View File

@ -4,7 +4,7 @@ var openpgp = require('openpgp');
var expect = chai.expect; var expect = chai.expect;
describe("Signature testing", function() { describe("Signature", function() {
var priv_key_arm1 = var priv_key_arm1 =
[ '-----BEGIN PGP PRIVATE KEY BLOCK-----', [ '-----BEGIN PGP PRIVATE KEY BLOCK-----',
'Version: GnuPG v1.4.11 (GNU/Linux)', 'Version: GnuPG v1.4.11 (GNU/Linux)',