Skip to content

p521: fix ReduceNonZero<U576>#1345

Merged
tarcieri merged 1 commit into
RustCrypto:masterfrom
khonsulabs:reduce-non-zero-fix
Aug 3, 2025
Merged

p521: fix ReduceNonZero<U576>#1345
tarcieri merged 1 commit into
RustCrypto:masterfrom
khonsulabs:reduce-non-zero-fix

Conversation

@daxpedda

@daxpedda daxpedda commented Aug 2, 2025

Copy link
Copy Markdown
Contributor

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

tarcieri commented Aug 3, 2025

Copy link
Copy Markdown
Member

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