You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
wNAF uses PrimeField::to_repr on scalars assuming little endian #78
Several places in wnaf.rs, PrimeField::to_repr is called on scalars assuming this outputs a little endian serialization. That method is documented as follows:
/// The endianness of the byte representation is implementation-specific. Generic/// encodings of field elements should be treated as opaque.
We are using the big endian SEC1 serialization of scalars for our implementations of the NIST P-curves as well as secp256k1.
It would be nice to eliminate the endianness assumptions in the implementation. As a hack we added a secondary method which always provides a little endian serialization to PrimeField in rustcrypto-ff, but whatever can eliminate the endianness assumptions here would be nice. Perhaps something that constructs an Iterator over the bits of the scalar in little endian order would be generally useful?
Possibly allow the implementor to choose the "native" endianness for their PrimeField type, specified in an associated const, and force the callers to deal with it by forcing the endianness to appear in the result of the representation type (as a wrapper). Callers can grab the underlying bytes and work with the type's specified endianness, or utility functions (iterators) that are agnostic to the endianness. We can provide these.
I think we wanted to be opinionated about the endianness initially to avoid this conversation entirely, forcing consumers of the API to put their own encoding/serialization facade over the concrete PrimeField types (which we didn't expect to be exposed directly in those code paths anyway).
@ebfull would you be okay with an additive change to ff for that perhaps, e.g. pub trait FieldEndianness with an associated pub enum ByteOrder constant?
I ask because I already have an enum like that in the primefield crate (which only depends on ff, not group) and it would be nice to be able to source that enum from ff if it's defining one, and also there may be other field element applications that could use that information (we use it in primefield, for example).
@tarcieri Sure, though PrimeField should probably just require the ByteOrder associated constant right? (If it has endian-sensitive APIs in it, then it seems like it shouldn't be another trait.)
I've opened an RFC which proposes to add a pub enum ReprEndianness to ff, and an associated constant thereof on PrimeField, all of which can be done in a purely additive manner: zkcrypto/rfcs#4
Activity
ebfull commentedon Jun 1, 2026
Possibly allow the implementor to choose the "native" endianness for their
PrimeFieldtype, specified in an associatedconst, and force the callers to deal with it by forcing the endianness to appear in the result of the representation type (as a wrapper). Callers can grab the underlying bytes and work with the type's specified endianness, or utility functions (iterators) that are agnostic to the endianness. We can provide these.I think we wanted to be opinionated about the endianness initially to avoid this conversation entirely, forcing consumers of the API to put their own encoding/serialization facade over the concrete PrimeField types (which we didn't expect to be exposed directly in those code paths anyway).
tarcieri commentedon Jun 1, 2026
@ebfull would you be okay with an additive change to
fffor that perhaps, e.g.pub trait FieldEndiannesswith an associatedpub enum ByteOrderconstant?I ask because I already have an enum like that in the
primefieldcrate (which only depends onff, notgroup) and it would be nice to be able to source thatenumfromffif it's defining one, and also there may be other field element applications that could use that information (we use it inprimefield, for example).If that sounds good I can write an RFC for it.
ebfull commentedon Jun 1, 2026
@tarcieri Sure, though
PrimeFieldshould probably just require theByteOrderassociated constant right? (If it has endian-sensitive APIs in it, then it seems like it shouldn't be another trait.)tarcieri commentedon Jun 1, 2026
Yes, though that'd be a breaking change, right? I'd be fine with that if you want to make a last minute one and yank
ffv0.14.0tarcieri commentedon Jun 2, 2026
Never mind, it can be done purely additively using an associated constant default: https://github.com/RustCrypto/ff/pull/14
I'll go ahead and write up an RFC for this.
tarcieri commentedon Jun 4, 2026
I've opened an RFC which proposes to add a
pub enum ReprEndiannesstoff, and an associated constant thereof onPrimeField, all of which can be done in a purely additive manner: zkcrypto/rfcs#4