Skip to content

Commit 49fa765

Browse files
committed
[WIP] Add legacy feature with ECDSA-related traits
ECDSA signing computes the `r` component of a signature by reducing the affine x-coordinate of an ephemeral point mod n. This adds a `ReduceAffineX` trait for performing this reduction, with the goal of facilitating an ECDSA implementation which is generic over (prime order) elliptic curves. Additionally, it adds an `IsAffineYOdd` trait which is useful for computing the "recovery ID" used to recover the public key which created a signature (ala point compression).
1 parent fd3516f commit 49fa765

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

elliptic-curve-crate/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ default-features = false
3737
hex = "0.4"
3838

3939
[features]
40-
default = []
40+
legacy = []
4141
weierstrass = []
4242
std = []
4343

4444
[package.metadata.docs.rs]
45-
all-features = true
45+
features = ["weierstrass", "std"]
4646
rustdoc-args = ["--cfg", "docsrs"]

elliptic-curve-crate/src/legacy.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//! Traits for implementing legacy protocols.
2+
//!
3+
//! These APIs could be potentially misused when designing new protocols.
4+
//! For that reason, we strongly suggest they aren't used in new protocols, but
5+
//! only as needed when implementing legacy protocols which require them.
6+
7+
/// Reduce the field element representing the x-coordinate of an affine point
8+
/// into the associated scalar type
9+
pub trait ReduceAffineX {
10+
/// Scalar type
11+
type Scalar; // TODO: bounds (should we add a `ScalarArith` marker trait?)
12+
13+
/// Convert the element in the base field representing the x-coordinate
14+
/// to the associated scalar type by lifting it into an integer and then
15+
/// reducing it to an element of the scalar field
16+
fn reduce_x_to_scalar(&self) -> Self::Scalar;
17+
}
18+
19+
/// Determines if the y-coordinate of an affine point is odd
20+
pub trait IsAffineYOdd {
21+
/// Is the y-coordinate odd?
22+
fn is_y_odd(&self) -> bool;
23+
}

elliptic-curve-crate/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ pub use rand_core;
2727
pub mod error;
2828
pub mod secret_key;
2929

30-
pub use generic_array::{self, typenum::consts};
31-
pub use subtle;
30+
#[cfg(feature = "legacy")]
31+
#[cfg_attr(docsrs, doc(cfg(feature = "legacy")))]
32+
pub mod legacy;
3233

3334
// TODO(tarcieri): other curve forms
3435
#[cfg(feature = "weierstrass")]
3536
#[cfg_attr(docsrs, doc(cfg(feature = "weierstrass")))]
3637
pub mod weierstrass;
3738

3839
pub use self::{error::Error, secret_key::SecretKey};
40+
pub use generic_array::{self, typenum::consts};
41+
pub use subtle;
3942

4043
/// Byte array containing a serialized scalar value (i.e. an integer)
4144
pub type ScalarBytes<Size> = generic_array::GenericArray<u8, Size>;

0 commit comments

Comments
 (0)