Skip to content

Implicit rejection api for PKCS#1 v1.5 decryption - #680

Closed
lubux wants to merge 1 commit into
RustCrypto:masterfrom
lubux:feat/implicit-rejection
Closed

lubux wants to merge 1 commit into
RustCrypto:masterfrom
lubux:feat/implicit-rejection

Conversation

@lubux

@lubux lubux commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

This draft PR replaces the PKCS#1 v1.5 unpad function with an implicit rejection API based on:

Issue #626

The new PKCS#1 v1.5 unpad function does not return an error if the padding is invalid.
Instead, it deterministically generates and returns a replacement random message derived from the secret key and the ciphertext.
As a result, callers cannot distinguish between valid and invalid padding based on the output, thus reducing the risk side-channel attacks.

Breaking changes:

  • Removes the sha2 feature flag because SHA-2 is required for the implicit rejection algorithm.

  • PKCS#1 v1.5 decryption no longer returns an error if the padding is invalid.

WARNING: This PR requires careful review before progressing beyond the draft stage.

TODO: The existing 0 padding function does not seem to be constant time: uint_to_zeroizing_be_pad

@tarcieri

tarcieri commented Apr 7, 2026

Copy link
Copy Markdown
Member

To reiterate my comment from #626:

Instead of adding new APIs, features, etc, I would like to see implicit rejection added by removing the existing fallible handling of padding. If there are APIs that only handle padding errors the Result can be changed to return a value, but APIs that are part of existing traits, or APIs that handle errors other than padding should continue to return a Result.

Ideally it should be a change that's largely invisible, but we should copiously document that PKCS#1 v1.5 padding errors no longer return an error but instead the pseudorandom rejection symbol.

@lubux
lubux force-pushed the feat/implicit-rejection branch 2 times, most recently from b69ef83 to ab6455e Compare April 7, 2026 15:05
@lubux

lubux commented Apr 9, 2026

Copy link
Copy Markdown
Contributor Author

To reiterate my comment from #626:

Instead of adding new APIs, features, etc, I would like to see implicit rejection added by removing the existing fallible handling of padding. If there are APIs that only handle padding errors the Result can be changed to return a value, but APIs that are part of existing traits, or APIs that handle errors other than padding should continue to return a Result.

Ideally it should be a change that's largely invisible, but we should copiously document that PKCS#1 v1.5 padding errors no longer return an error but instead the pseudorandom rejection symbol.

Removed the feature flag and made it the default behavior without introducing new APIs.

@lubux
lubux marked this pull request as ready for review June 12, 2026 07:16
@tarcieri

tarcieri commented Nov 1, 2026

Copy link
Copy Markdown
Member

Closing in favor of #749, which incorporates some of the code from this PR, thanks!

@tarcieri tarcieri closed this Nov 1, 2026
tarcieri added a commit that referenced this pull request Nov 1, 2026
Avoid a padding oracle by returning a deterministic rejection symbol
rather than an error on padding failures. See sections 7.1/7.2 of:

https://www.ietf.org/archive/id/draft-irtf-cfrg-rsa-guidance-10.html

Incorporates some of the code from #680 / #702, where some of the code
from the latter was merged in #739 (blinding support).

Uses `cargo checkct` / BINSEC to verify constant-time operation.

Closes #626
tarcieri added a commit that referenced this pull request Nov 1, 2026
Avoid a padding oracle by returning a deterministic rejection symbol
rather than an error on padding failures. See sections 7.1/7.2 of:

https://www.ietf.org/archive/id/draft-irtf-cfrg-rsa-guidance-10.html

Incorporates some of the code from #680 / #702, where some of the code
from the latter was merged in #739 (blinding support).

Uses `cargo checkct` / BINSEC to verify constant-time operation.

Closes #626
tarcieri added a commit that referenced this pull request Nov 1, 2026
Avoid a padding oracle by returning a deterministic rejection symbol
rather than an error on padding failures. See sections 7.1/7.2 of:

https://www.ietf.org/archive/id/draft-irtf-cfrg-rsa-guidance-10.html

Incorporates some of the code from #680 / #702, where some of the code
from the latter was merged in #739 (blinding support).

Uses `cargo checkct` / BINSEC to verify constant-time operation.

Closes #626
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.

2 participants