Implement PrimeFieldBits for dalek-ff-group

This commit is contained in:
Luke Parker 2022-06-30 03:17:15 -04:00
parent 0a690f5632
commit 2e168204f0
No known key found for this signature in database
GPG key ID: F9F1386DB1E119B6
2 changed files with 18 additions and 1 deletions

View file

@ -14,6 +14,7 @@ digest = "0.10"
subtle = "2.4"
ff = "0.12"
group = "0.12"
curve25519-dalek = "3.2"

View file

@ -29,7 +29,8 @@ use dalek::{
}
};
use group::{ff::{Field, PrimeField}, Group, GroupEncoding, prime::PrimeGroup};
use ff::{Field, PrimeField, FieldBits, PrimeFieldBits};
use group::{Group, GroupEncoding, prime::PrimeGroup};
macro_rules! deref_borrow {
($Source: ident, $Target: ident) => {
@ -190,6 +191,21 @@ impl PrimeField for Scalar {
fn root_of_unity() -> Self { unimplemented!() }
}
impl PrimeFieldBits for Scalar {
type ReprBits = [u8; 32];
fn to_le_bits(&self) -> FieldBits<Self::ReprBits> {
self.to_repr().into()
}
fn char_le_bits() -> FieldBits<Self::ReprBits> {
let mut bytes = (Scalar::zero() - Scalar::one()).to_repr();
bytes[0] += 1;
debug_assert_eq!(Scalar::from_bytes_mod_order(bytes), Scalar::zero());
bytes.into()
}
}
macro_rules! dalek_group {
(
$Point: ident,