Skip to content

Commit 70dccf5

Browse files
committed
Add PrimeField::to_le_repr
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.
1 parent e155572 commit 70dccf5

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,15 @@ pub trait PrimeField: Field + From<u64> {
304304
/// encodings of field elements should be treated as opaque.
305305
fn to_repr(&self) -> Self::Repr;
306306

307+
/// Convert an element of the prime field into a little endian byte representation.
308+
///
309+
/// The provided implementation assumes [`PrimeField::to_repr`] returns a little endian
310+
/// representation and needs to be overridden if it uses big endian.
311+
// TODO(tarcieri): this is largely a hack to make `group::Wnaf` work. Ideally it could go away.
312+
fn to_le_repr(&self) -> Self::Repr {
313+
self.to_repr()
314+
}
315+
307316
/// Returns true iff this element is odd.
308317
fn is_odd(&self) -> Choice;
309318

0 commit comments

Comments
 (0)