Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : Trait Reduce implemented for U256 and U512 on struct Scalar #716

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions curve25519-dalek/src/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1362,7 +1362,17 @@ fn read_le_u64_into(src: &[u8], dst: &mut [u64]) {
);
}
}
// Implementing the Reduce trait for curve25519_dalek::Scalar
impl Reduce<U256> for Scalar {
fn reduce(value: U256) -> Self {
Self::from_bytes_mod_order(value.to_bytes())
}
}

impl Reduce<U512> for Scalar {
fn reduce(value: U512) -> Self {
Self::from_bytes_mod_order_wide(value.to_bytes())

/// _Clamps_ the given little-endian representation of a 32-byte integer. Clamping the value puts
/// it in the range:
///
Expand Down
6 changes: 6 additions & 0 deletions curve25519-dalek/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,3 +421,9 @@ pub(crate) trait ValidityCheck {
/// Checks whether the point is on the curve. Not CT.
fn is_valid(&self) -> bool;
}

// Reduce trait

pub trait Reduce<T>{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this re-defined here? Isn't the point of the referenced issue that we should be implementing the Reduce trait from elliptic_curve?

Copy link
Contributor

@tarcieri tarcieri Oct 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note we'll have another breaking release of elliptic-curve out soon, probably early 2025, so it would probably make sense to target these changes along with #676

fn reduce(value:T) -> Self
}