From 4ce2dd28e130ba0408d629ba59e370398f820a4c Mon Sep 17 00:00:00 2001 From: Sanjana Rajan Date: Sun, 23 Dec 2018 19:24:02 +0100 Subject: [PATCH] update CFB tests --- test/crypto/crypto.js | 53 +++++++++---------------------------------- 1 file changed, 11 insertions(+), 42 deletions(-) diff --git a/test/crypto/crypto.js b/test/crypto/crypto.js index 00d03e70..6459d346 100644 --- a/test/crypto/crypto.js +++ b/test/crypto/crypto.js @@ -277,31 +277,14 @@ describe('API functional testing', function() { return algo !== 'idea' && algo !== 'plaintext'; }); - function testCFB(plaintext, resync) { - symmAlgos.forEach(async function(algo) { + async function testCFB(plaintext) { + await Promise.all(symmAlgos.map(async function(algo) { const symmKey = await crypto.generateSessionKey(algo); - const symmencData = crypto.cfb.encrypt(await crypto.getPrefixRandom(algo), algo, util.str_to_Uint8Array(plaintext), symmKey, resync); - const text = util.Uint8Array_to_str(crypto.cfb.decrypt(algo, symmKey, symmencData, resync)); + const IV = new Uint8Array(crypto.cipher[algo].blockSize); + const symmencData = await crypto.cfb.encrypt(algo, symmKey, util.str_to_Uint8Array(plaintext), IV); + const text = util.Uint8Array_to_str(await crypto.cfb.decrypt(algo, symmKey, symmencData, new Uint8Array(crypto.cipher[algo].blockSize))); expect(text).to.equal(plaintext); - }); - } - - function testAESCFB(plaintext) { - symmAlgos.forEach(async function(algo) { - if(algo.substr(0,3) === 'aes') { - const symmKey = await crypto.generateSessionKey(algo); - const rndm = await crypto.getPrefixRandom(algo); - - const repeat = new Uint8Array([rndm[rndm.length - 2], rndm[rndm.length - 1]]); - const prefix = util.concatUint8Array([rndm, repeat]); - - const symmencData = crypto.cfb.encrypt(rndm, algo, util.str_to_Uint8Array(plaintext), symmKey, false); - const decrypted = crypto.cfb.decrypt(algo, symmKey, symmencData, false); - - const text = util.Uint8Array_to_str(decrypted); - expect(text).to.equal(plaintext); - } - }); + })); } function testAESGCM(plaintext, nativeDecrypt) { @@ -325,25 +308,11 @@ describe('API functional testing', function() { }); } - it("Symmetric with OpenPGP CFB resync", function () { - testCFB("hello", true); - testCFB("1234567", true); - testCFB("foobarfoobar1234567890", true); - testCFB("12345678901234567890123456789012345678901234567890", true); - }); - - it("Symmetric without OpenPGP CFB resync", function () { - testCFB("hello", false); - testCFB("1234567", false); - testCFB("foobarfoobar1234567890", false); - testCFB("12345678901234567890123456789012345678901234567890", false); - }); - - it("asmCrypto AES without OpenPGP CFB resync", function () { - testAESCFB("hello"); - testAESCFB("1234567"); - testAESCFB("foobarfoobar1234567890"); - testAESCFB("12345678901234567890123456789012345678901234567890"); + it("Symmetric with OpenPGP CFB", async function () { + await testCFB("hello"); + await testCFB("1234567"); + await testCFB("foobarfoobar1234567890"); + await testCFB("12345678901234567890123456789012345678901234567890"); }); describe('Symmetric AES-GCM (native)', function() {