mirror of
https://github.com/serai-dex/serai.git
synced 2024-12-22 19:49:22 +00:00
Implement PrimeFieldBits for dalek-ff-group
This commit is contained in:
parent
0a690f5632
commit
2e168204f0
2 changed files with 18 additions and 1 deletions
|
@ -14,6 +14,7 @@ digest = "0.10"
|
|||
|
||||
subtle = "2.4"
|
||||
|
||||
ff = "0.12"
|
||||
group = "0.12"
|
||||
|
||||
curve25519-dalek = "3.2"
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue