Add PrimeFieldBits support to Scalar (#579)
Co-authored-by: Michael Rosenberg <micro@fastmail.com> Co-authored-by: pinkforest(she/her) <36498018+pinkforest@users.noreply.github.com>
This commit is contained in:
parent
533b53a0ec
commit
76a8b2a081
curve25519-dalek
@ -5,6 +5,10 @@ major series.
|
||||
|
||||
## 4.x series
|
||||
|
||||
### Unreleased
|
||||
|
||||
* Add implementation for `PrimeFieldBits`, behind the `group-bits` feature flag.
|
||||
|
||||
### 4.1.1
|
||||
|
||||
* Mark `constants::BASEPOINT_ORDER` deprecated from pub API
|
||||
|
@ -27,7 +27,7 @@ rustdoc-args = [
|
||||
"--html-in-header", "docs/assets/rustdoc-include-katex-header.html",
|
||||
"--cfg", "docsrs",
|
||||
]
|
||||
features = ["serde", "rand_core", "digest", "legacy_compatibility", "group"]
|
||||
features = ["serde", "rand_core", "digest", "legacy_compatibility", "group-bits"]
|
||||
|
||||
[dev-dependencies]
|
||||
sha2 = { version = "0.10", default-features = false }
|
||||
@ -48,6 +48,7 @@ required-features = ["alloc", "rand_core"]
|
||||
|
||||
[dependencies]
|
||||
cfg-if = "1"
|
||||
ff = { version = "0.13", default-features = false, optional = true }
|
||||
group = { version = "0.13", default-features = false, optional = true }
|
||||
rand_core = { version = "0.6.4", default-features = false, optional = true }
|
||||
digest = { version = "0.10", default-features = false, optional = true }
|
||||
@ -67,6 +68,7 @@ alloc = ["zeroize?/alloc"]
|
||||
precomputed-tables = []
|
||||
legacy_compatibility = []
|
||||
group = ["dep:group", "rand_core"]
|
||||
group-bits = ["group", "ff/bits"]
|
||||
|
||||
[target.'cfg(all(not(curve25519_dalek_backend = "fiat"), not(curve25519_dalek_backend = "serial"), target_arch = "x86_64"))'.dependencies]
|
||||
curve25519-dalek-derive = { version = "0.1", path = "../curve25519-dalek-derive" }
|
||||
|
@ -124,6 +124,8 @@ use core::ops::{Sub, SubAssign};
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
#[cfg(feature = "group-bits")]
|
||||
use group::ff::{FieldBits, PrimeFieldBits};
|
||||
#[cfg(feature = "group")]
|
||||
use {
|
||||
group::ff::{Field, FromUniformBytes, PrimeField},
|
||||
@ -1321,6 +1323,19 @@ impl PrimeField for Scalar {
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(feature = "group-bits")]
|
||||
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> {
|
||||
constants::BASEPOINT_ORDER_PRIVATE.to_bytes().into()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "group")]
|
||||
impl FromUniformBytes<64> for Scalar {
|
||||
fn from_uniform_bytes(bytes: &[u8; 64]) -> Self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user