Skip to content

Conversation

daxpedda
Copy link
Contributor

@daxpedda daxpedda commented Aug 2, 2025

I just realized from #1341 that P-521 ReduceNonZero<U576> wasn't implemented correctly.

Because U576 can fit way more then 2 * ORDER, doing input - ORDER_MINUS_ONE doesn't actually bring it below the modulus. We then use Scalar::from_uint_unchecked(), which does require input below the modulus.

I couldn't trigger a bug in practice however, not sure exactly how fiat_p521_scalar_non_montgomery_domain_field_element() fails when its requirements aren't fulfilled.

@daxpedda daxpedda changed the title p521: use reduction in ReduceNonZero<U576> p521: fix ReduceNonZero<U576> Aug 2, 2025
@tarcieri
Copy link
Member

tarcieri commented Aug 3, 2025

I couldn't trigger a bug in practice however, not sure exactly how fiat_p521_scalar_non_montgomery_domain_field_element() fails when its requirements aren't fulfilled.

It's the mathematical equivalent of UB

@tarcieri tarcieri merged commit 30da3cc into RustCrypto:master Aug 3, 2025
13 checks passed
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