Skip to content

Make RSA/ElGamal PKCS#1 v1.5 decryption constant time - #232

Open
michalz-zoom wants to merge 6 commits into
masterfrom
pkcs1-const-time
Open

Make RSA/ElGamal PKCS#1 v1.5 decryption constant time#232
michalz-zoom wants to merge 6 commits into
masterfrom
pkcs1-const-time

Conversation

@michalz-zoom

Copy link
Copy Markdown
Contributor

KBPGP RSA decryption code suffers from padding oracle attacks. There are two major issues:

  • Decrypting a message fails with distinct errors in the "unpadding" function: "Failed to find expected header", "didn't get 0x00 separator" etc.
  • Early exits in the unpadding code. This creates a timing side channel.

This PR hardens the OpenPGP message decryption path starting at Message::_decrypt in processor.iced. PCKS padding and session key recovery now avoids early exits, distinct errors or branching.

  • eme_pkcs1_decode scans the whole decrypted encoded message instead of stopping at the separator.
  • Padding failures are returned as a validity bit, not distinct public errors.
  • RSA/ElGamal callers (decrypt_and_unpad) do not abort on padding failure.
  • import_key_pgp_ct avoids branching on the session-key algorithm/checksum result by checking all supported ciphers and selecting a key.
  • The OpenPGP data packet is still decrypted with either the real session key or a random fallback key.
  • Final failure is collapsed to "Unable to decrypt".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant