Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for constant-time decryption of PKCS#1 v1.5-encoded session keys #1445

Merged
merged 8 commits into from Jan 19, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/packet/public_key_encrypted_session_key.js
Expand Up @@ -129,10 +129,11 @@ class PublicKeyEncryptedSessionKeyPacket {
util.writeChecksum(randomSessionKey.sessionKey)
]) : null;
const decoded = await crypto.publicKeyDecrypt(this.publicKeyAlgorithm, key.publicParams, key.privateParams, this.encrypted, key.getFingerprintBytes(), randomPayload);
const checksum = decoded.subarray(decoded.length - 2);
const sessionKey = decoded.subarray(1, decoded.length - 2);
const symmetricAlgoByte = decoded[0];
const isValidChecksum = util.equalsUint8Array(checksum, util.writeChecksum(sessionKey));
const sessionKey = decoded.subarray(1, decoded.length - 2);
const expectedChecksum = decoded.subarray(decoded.length - 2);
const actualChecksum = util.writeChecksum(sessionKey);
larabr marked this conversation as resolved.
Show resolved Hide resolved
const isValidChecksum = actualChecksum[0] === expectedChecksum[0] & actualChecksum[1] === expectedChecksum[1];

if (randomSessionKey) {
// We must not leak info about the validity of the decrypted checksum or cipher algo.
Expand Down