Skip to content

Add PrimeField::to_le_repr#10

Merged
tarcieri merged 1 commit intomainfrom
primefield-to-le-repr
Mar 31, 2026
Merged

Add PrimeField::to_le_repr#10
tarcieri merged 1 commit intomainfrom
primefield-to-le-repr

Conversation

@tarcieri
Copy link
Copy Markdown
Member

The current group::Wnaf implementation assumes PrimeField::to_repr returns a little endian encoding, so it doesn't work with our implementations of the NIST P-curves, which return a big endian SEC1 encoding.

Following the general idea from RustCrypto/group#10, this adds an API which is guaranteed to return a little endian encoding which will always work with the current implementation of group::Wnaf.

This is largely a stopgap solution which allows us to begin using group::Wnaf at all, though ideally we can find a more elegant upstream solution.

cc @str4d @tob-scott-a

The current `group::Wnaf` implementation assumes `PrimeField::to_repr`
returns a little endian encoding, so it doesn't work with our
implementations of the NIST P-curves, which return a big endian SEC1
encoding.

Following the general idea from RustCrypto/group#10, this adds an API
which is guaranteed to return a little endian encoding which will always
work with the current implementation of `group::Wnaf`.

This is largely a stopgap solution which allows us to begin using
`group::Wnaf` at all, though ideally we can find a more elegant upstream
solution.
@tarcieri
Copy link
Copy Markdown
Member Author

tarcieri commented Mar 31, 2026

@str4d curious what you had in mind here. I was wondering if PrimeField could support something like an IntoIterator implementation for an Iterator over bool that follows a little endian bit ordering or something like that which could be used instead of PrimeField::to_repr so that could be truly opaque, but that would require more invasive changes to group::Wnaf which I'm trying to avoid here for now

@tarcieri tarcieri merged commit 6d694c9 into main Mar 31, 2026
8 checks passed
@tarcieri tarcieri deleted the primefield-to-le-repr branch March 31, 2026 14:21
tarcieri added a commit to RustCrypto/group that referenced this pull request Mar 31, 2026
The wNAF implementation assumes a little endian representation for
scalars, but `PrimeField::to_repr` returns an opaque representation
which may be big endian and is in the case of our implementations of the
NIST P-curves.

RustCrypto/ff#10 added a stopgap API: `PrimeField::to_le_repr`, which is
guaranteed to return a little endian representation. This commit
switches `(rustcrypto-)group` to use it, which should make it compatible
with our curves which otherwise use a big endian SEC1 representation.
tarcieri added a commit to RustCrypto/group that referenced this pull request Mar 31, 2026
The wNAF implementation assumes a little endian representation for
scalars, but `PrimeField::to_repr` returns an opaque representation
which may be big endian and is in the case of our implementations of the
NIST P-curves.

RustCrypto/ff#10 added a stopgap API: `PrimeField::to_le_repr`, which is
guaranteed to return a little endian representation. This commit
switches `(rustcrypto-)group` to use it, which should make it compatible
with our curves which otherwise use a big endian SEC1 representation.
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