Skip to content

Fix RSA verification panic for modulus with length not evenly divisible by LIMB_BYTES - #937

Merged
briansmith merged 1 commit into
masterfrom
b/fix-panic-rsa-3
Jan 30, 2020
Merged

briansmith merged 1 commit into
masterfrom
b/fix-panic-rsa-3

Conversation

@briansmith

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/rsa/verification.rs Outdated
let (padding, decoded) = decoded.split_at(n_bytes_padded - n_bytes);
assert!(padding.iter().all(|&b| b == 0));
decoded
};

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not particularly happy with how ugly this is or how leaky the abstractions are. For example, this code is only correct assuming we've done various bounds checks that indicate the RSA modulus length is reasonable.

OTOH, for validation reasons it is important to avoid making the code in arithmetic and limbs more complicated than it is.

In the future, after the release that contains this fix, we should clean this up.

@briansmith

Copy link
Copy Markdown
Owner Author

I posted this to get early feedback. Tests should arrive soon, followed by the release.

This was referenced Jan 24, 2020
@briansmith
briansmith force-pushed the b/fix-panic-rsa-3 branch 2 times, most recently from 2c5666a to f5e3c3a Compare January 24, 2020 00:38
@andrewtj

Copy link
Copy Markdown
Contributor

I've tried this out with some samples generated using Go's crypto package and have had no issues.

@briansmith
briansmith marked this pull request as ready for review January 30, 2020 21:03
@briansmith
briansmith merged commit 6740200 into master Jan 30, 2020
@briansmith
briansmith deleted the b/fix-panic-rsa-3 branch January 30, 2020 21:04
@briansmith

Copy link
Copy Markdown
Owner Author

I posted this to get early feedback. Tests should arrive soon, followed by the release.

I did test this but I decided not to include the tests in the PR because there is a refactoring of the tests in progress and I don't want to interfere with that refactoring. The tests should appear later in a separate PR. Thanks @andrewtj for reporting this and for testing it.

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