mirror of
https://github.com/saymrwulf/curve25519-dalek-source.git
synced 2026-09-06 20:41:14 +00:00
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
3 changed files with 22 additions and 1 deletions
|
|
@ -5,6 +5,10 @@ major series.
|
||||||
|
|
||||||
## 4.x series
|
## 4.x series
|
||||||
|
|
||||||
|
### Unreleased
|
||||||
|
|
||||||
|
* Add implementation for `PrimeFieldBits`, behind the `group-bits` feature flag.
|
||||||
|
|
||||||
### 4.1.1
|
### 4.1.1
|
||||||
|
|
||||||
* Mark `constants::BASEPOINT_ORDER` deprecated from pub API
|
* Mark `constants::BASEPOINT_ORDER` deprecated from pub API
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ rustdoc-args = [
|
||||||
"--html-in-header", "docs/assets/rustdoc-include-katex-header.html",
|
"--html-in-header", "docs/assets/rustdoc-include-katex-header.html",
|
||||||
"--cfg", "docsrs",
|
"--cfg", "docsrs",
|
||||||
]
|
]
|
||||||
features = ["serde", "rand_core", "digest", "legacy_compatibility", "group"]
|
features = ["serde", "rand_core", "digest", "legacy_compatibility", "group-bits"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
sha2 = { version = "0.10", default-features = false }
|
sha2 = { version = "0.10", default-features = false }
|
||||||
|
|
@ -48,6 +48,7 @@ required-features = ["alloc", "rand_core"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cfg-if = "1"
|
cfg-if = "1"
|
||||||
|
ff = { version = "0.13", default-features = false, optional = true }
|
||||||
group = { 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 }
|
rand_core = { version = "0.6.4", default-features = false, optional = true }
|
||||||
digest = { version = "0.10", default-features = false, optional = true }
|
digest = { version = "0.10", default-features = false, optional = true }
|
||||||
|
|
@ -67,6 +68,7 @@ alloc = ["zeroize?/alloc"]
|
||||||
precomputed-tables = []
|
precomputed-tables = []
|
||||||
legacy_compatibility = []
|
legacy_compatibility = []
|
||||||
group = ["dep:group", "rand_core"]
|
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]
|
[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" }
|
curve25519-dalek-derive = { version = "0.1", path = "../curve25519-dalek-derive" }
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,8 @@ use core::ops::{Sub, SubAssign};
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
#[cfg(feature = "group-bits")]
|
||||||
|
use group::ff::{FieldBits, PrimeFieldBits};
|
||||||
#[cfg(feature = "group")]
|
#[cfg(feature = "group")]
|
||||||
use {
|
use {
|
||||||
group::ff::{Field, FromUniformBytes, PrimeField},
|
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")]
|
#[cfg(feature = "group")]
|
||||||
impl FromUniformBytes<64> for Scalar {
|
impl FromUniformBytes<64> for Scalar {
|
||||||
fn from_uniform_bytes(bytes: &[u8; 64]) -> Self {
|
fn from_uniform_bytes(bytes: &[u8; 64]) -> Self {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue