Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions curve25519-dalek/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ serde = { version = "1.0", default-features = false, optional = true, features =
"derive",
] }
zeroize = { version = "1", default-features = false, optional = true }
typenum = { version = "1", default-features = false, optional = true }

[target.'cfg(target_arch = "x86_64")'.dependencies]
cpufeatures = "0.2.17"
Expand All @@ -80,6 +81,7 @@ default = ["alloc", "precomputed-tables", "zeroize"]
alloc = ["zeroize?/alloc"]
precomputed-tables = []
legacy_compatibility = []
hazmat = ["rand_core", "ff", "typenum"]
group = ["dep:group", "rand_core"]
group-bits = ["group", "ff/bits"]
digest = ["dep:digest"]
Expand Down
3 changes: 2 additions & 1 deletion curve25519-dalek/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ curve25519-dalek = ">= 5.0, < 5.2"
| `digest` | | Enables `RistrettoPoint::{from_hash, hash_from_bytes}` and `Scalar::{from_hash, hash_from_bytes}`. This is an optional dependency whose version is not subject to SemVer. See [below](#public-api-semver-exemptions) for more details. |
| `serde` | | Enables `serde` serialization/deserialization for all the point and scalar types. |
| `legacy_compatibility`| | Enables `Scalar::from_bits`, which allows the user to build unreduced scalars whose arithmetic is broken. Do not use this unless you know what you're doing. |
| `hazmat` | | Enables `FieldElement` satisfying `ff` traits and bespoke traits for lazy reduction |
| `group` | | Enables external `group` and `ff` crate traits. |
| `group-bits` | | Enables `group` and impls `ff::PrimeFieldBits` for `Scalar`. |
| `group-bits` | | Enables `group` and impls `ff::PrimeFieldBits` for `Scalar`, and `FieldElement` if `hazmat`. |

To disable the default features when using `curve25519-dalek` as a dependency,
add `default-features = false` to the dependency in your `Cargo.toml`. To
Expand Down
7 changes: 6 additions & 1 deletion curve25519-dalek/src/backend/serial/fiat_u32/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl FieldElement2625 {

/// Serialize this `FieldElement51` to a 32-byte array. The
/// encoding is canonical.
pub fn to_bytes(self) -> [u8; 32] {
pub const fn to_bytes(self) -> [u8; 32] {
let mut bytes = [0u8; 32];
fiat_25519_to_bytes(&mut bytes, &self.0);
bytes
Expand Down Expand Up @@ -269,3 +269,8 @@ impl FieldElement2625 {
output
}
}

#[cfg(feature = "hazmat")]
impl crate::hazmat::UnderlyingCapacity for FieldElement2625 {
type Capacity = typenum::U3;
}
7 changes: 6 additions & 1 deletion curve25519-dalek/src/backend/serial/fiat_u64/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl FieldElement51 {

/// Serialize this `FieldElement51` to a 32-byte array. The
/// encoding is canonical.
pub fn to_bytes(self) -> [u8; 32] {
pub const fn to_bytes(self) -> [u8; 32] {
let mut bytes = [0u8; 32];
fiat_25519_to_bytes(&mut bytes, &self.0);
bytes
Expand Down Expand Up @@ -260,3 +260,8 @@ impl FieldElement51 {
output
}
}

#[cfg(feature = "hazmat")]
impl crate::hazmat::UnderlyingCapacity for FieldElement51 {
type Capacity = typenum::U8;
}
7 changes: 6 additions & 1 deletion curve25519-dalek/src/backend/serial/u32/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl FieldElement2625 {
/// Serialize this `FieldElement51` to a 32-byte array. The
/// encoding is canonical.
#[allow(clippy::identity_op)]
pub fn to_bytes(self) -> [u8; 32] {
pub const fn to_bytes(self) -> [u8; 32] {
let inp = &self.0;
// Reduce the value represented by `in` to the range [0,2*p)
let mut h: [u32; 10] = FieldElement2625::reduce([
Expand Down Expand Up @@ -605,3 +605,8 @@ impl FieldElement2625 {
FieldElement2625::reduce(coeffs)
}
}

#[cfg(feature = "hazmat")]
impl crate::hazmat::UnderlyingCapacity for FieldElement2625 {
type Capacity = typenum::U3;
}
9 changes: 7 additions & 2 deletions curve25519-dalek/src/backend/serial/u64/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl FieldElement51 {

/// Given 64-bit input limbs, reduce to enforce the bound 2^(51 + epsilon).
#[inline(always)]
fn reduce(mut limbs: [u64; 5]) -> FieldElement51 {
const fn reduce(mut limbs: [u64; 5]) -> FieldElement51 {
const LOW_51_BIT_MASK: u64 = (1u64 << 51) - 1;

// Since the input limbs are bounded by 2^64, the biggest
Expand Down Expand Up @@ -365,7 +365,7 @@ impl FieldElement51 {
/// Serialize this `FieldElement51` to a 32-byte array. The
/// encoding is canonical.
#[rustfmt::skip] // keep alignment of s[*] calculations
pub fn to_bytes(self) -> [u8; 32] {
pub const fn to_bytes(self) -> [u8; 32] {
// Let h = limbs[0] + limbs[1]*2^51 + ... + limbs[4]*2^204.
//
// Write h = pq + r with 0 <= r < p.
Expand Down Expand Up @@ -573,3 +573,8 @@ impl FieldElement51 {
square
}
}

#[cfg(feature = "hazmat")]
impl crate::hazmat::UnderlyingCapacity for FieldElement51 {
type Capacity = typenum::U8;
}
2 changes: 1 addition & 1 deletion curve25519-dalek/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl ConstantTimeEq for FieldElement {

impl FieldElement {
/// Load a `FieldElement` from 64 bytes, by reducing modulo q.
#[cfg(feature = "digest")]
#[cfg(any(feature = "digest", feature = "hazmat"))]
pub(crate) fn from_bytes_wide(bytes: &[u8; 64]) -> Self {
let mut fl = [0u8; 32];
let mut gl = [0u8; 32];
Expand Down
Loading
Loading