Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new Error("SSL: SetupCipher: unkown encryption algorithm");
}
switch (cipher.encryptionMode) {
case CBC:
case NONE:
switch (cipher.hashAlgorithm) {
case MD5: h = "MD5"; break;
case SHA1: h = "SHA1"; break;
case SHA256: h = "SHA256"; break;
case SHA384: h = "SHA384"; break;
default:
throw new Error("SSL: SetupCipher: unknown hash algorithm");
}
o.hmac = new HMAC(new Digest(h), o.macSecret);
if (cipher.encryptionMode == CBC)
o.enc = new Mode("CBC", enc, o.iv); // no padding -- SSL 3.2 requires padding process beyond RFC2630
else
o.enc = enc;
break;
case GCM:
o.enc = new Gcm(enc);
o.nonce = BigInt(1);
break;
default:
o.enc = enc;
break;
}
}
function testCipherMode(name, direction, cipher, iv, padding, data, expected)
{
let mode, result;
if (name == "GCM") {
mode = new GCM(cipher);
result = mode.process(data, undefined, iv, padding /* AAD */, direction == "encrypt");
}
else {
mode = new Mode(name, cipher, iv, padding);
result = mode[direction](data);
}
if (Bin.comp(result, expected) != 0) {
trace(`${name}.${direction} FAIL\n`);
trace("result = " + Hex.toString(result) + "\n");
trace("expected = " + Hex.toString(expected) + "\n");
}
else
trace(`${name}.${direction} pass\n`);
}
constructor(cipher, tagLength = 16) {
this.block = cipher;
this.ctr = new Mode("CTR", this.block);
this.tagLength = tagLength;
};
init(iv, aad) {