update CFB tests

This commit is contained in:
Sanjana Rajan 2018-12-23 19:24:02 +01:00 committed by Daniel Huigens
parent 31931c9b0d
commit 4ce2dd28e1

View File

@ -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() {