update CFB tests
This commit is contained in:
parent
31931c9b0d
commit
4ce2dd28e1
|
@ -277,31 +277,14 @@ describe('API functional testing', function() {
|
||||||
return algo !== 'idea' && algo !== 'plaintext';
|
return algo !== 'idea' && algo !== 'plaintext';
|
||||||
});
|
});
|
||||||
|
|
||||||
function testCFB(plaintext, resync) {
|
async function testCFB(plaintext) {
|
||||||
symmAlgos.forEach(async function(algo) {
|
await Promise.all(symmAlgos.map(async function(algo) {
|
||||||
const symmKey = await crypto.generateSessionKey(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 IV = new Uint8Array(crypto.cipher[algo].blockSize);
|
||||||
const text = util.Uint8Array_to_str(crypto.cfb.decrypt(algo, symmKey, symmencData, resync));
|
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);
|
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) {
|
function testAESGCM(plaintext, nativeDecrypt) {
|
||||||
|
@ -325,25 +308,11 @@ describe('API functional testing', function() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
it("Symmetric with OpenPGP CFB resync", function () {
|
it("Symmetric with OpenPGP CFB", async function () {
|
||||||
testCFB("hello", true);
|
await testCFB("hello");
|
||||||
testCFB("1234567", true);
|
await testCFB("1234567");
|
||||||
testCFB("foobarfoobar1234567890", true);
|
await testCFB("foobarfoobar1234567890");
|
||||||
testCFB("12345678901234567890123456789012345678901234567890", true);
|
await testCFB("12345678901234567890123456789012345678901234567890");
|
||||||
});
|
|
||||||
|
|
||||||
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");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Symmetric AES-GCM (native)', function() {
|
describe('Symmetric AES-GCM (native)', function() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user