Skip to content

Commit

Permalink
k256/p256/p384: Elliptic Curve Diffie-Hellman
Browse files Browse the repository at this point in the history
Adds type aliases for the high-level generic Elliptic Curve
Diffie-Hellman (Ephemeral) implementation introduced in
RustCrypto/traits#251.
  • Loading branch information
tarcieri committed Aug 6, 2020
1 parent 93f7ff9 commit b06fcf0
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion k256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ criterion = "0.3"
default = ["arithmetic", "oid", "std"]
arithmetic = []
digest = ["ecdsa-core/digest"]
ecdh = ["elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signer", "ecdsa-core/verifier", "rand", "sha256", "zeroize"]
endomorphism-mul = []
field-montgomery = []
force-32-bit = []
oid = ["elliptic-curve/oid"]
rand = ["elliptic-curve/rand_core"]
rand = ["elliptic-curve/rand"]
sha256 = ["digest", "sha2"]
test-vectors = []
std = ["elliptic-curve/std"]
Expand Down
9 changes: 9 additions & 0 deletions k256/src/ecdh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Elliptic Curve Diffie-Hellman (Ephemeral) Support.
use crate::Secp256k1;

/// NIST P-256 Ephemeral Diffie-Hellman Secret.
pub type EphemeralSecret = elliptic_curve::ecdh::EphemeralSecret<Secp256k1>;

/// Shared secret value computed via ECDH key agreement.
pub type SharedSecret = elliptic_curve::ecdh::SharedSecret<Secp256k1>;
13 changes: 10 additions & 3 deletions k256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ mod arithmetic;
#[cfg(feature = "arithmetic")]
mod mul;

#[cfg(feature = "ecdh")]
#[cfg_attr(docsrs, doc(cfg(feature = "ecdh")))]
pub mod ecdh;

#[cfg(feature = "ecdsa-core")]
#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa-core")))]
pub mod ecdsa;
Expand Down Expand Up @@ -59,7 +63,10 @@ impl elliptic_curve::Curve for Secp256k1 {
type ElementSize = U32;
}

impl elliptic_curve::weierstrass::Curve for Secp256k1 {}
impl elliptic_curve::weierstrass::Curve for Secp256k1 {
/// secp256k1 points are typically compressed.
const COMPRESS_POINTS: bool = true;
}

#[cfg(feature = "oid")]
impl elliptic_curve::Identifier for Secp256k1 {
Expand All @@ -72,9 +79,9 @@ pub type SecretKey = elliptic_curve::SecretKey<Secp256k1>;
/// K-256 (secp256k1) Public Key.
pub type PublicKey = elliptic_curve::weierstrass::PublicKey<Secp256k1>;

/// K-256 Scalar Bytes.
/// K-256 Serialized Field Element.
///
/// Byte array containing a serialized scalar value (i.e. an integer)
/// Byte array containing a serialized field element value (base field or scalar).
pub type ElementBytes = elliptic_curve::ElementBytes<Secp256k1>;

/// K-256 Compressed Curve Point.
Expand Down
3 changes: 2 additions & 1 deletion p256/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ proptest = "0.10"
[features]
default = ["arithmetic", "std"]
arithmetic = []
ecdh = ["elliptic-curve/ecdh"]
ecdsa = ["arithmetic", "ecdsa-core/signer", "ecdsa-core/verifier", "rand", "sha256", "zeroize"]
oid = ["elliptic-curve/oid"]
rand = ["elliptic-curve/rand_core"]
rand = ["elliptic-curve/rand"]
sha256 = ["ecdsa-core/digest", "ecdsa-core/hazmat", "sha2"]
test-vectors = []
std = ["elliptic-curve/std"]
Expand Down
9 changes: 9 additions & 0 deletions p256/src/ecdh.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//! Elliptic Curve Diffie-Hellman (Ephemeral) Support.
use crate::NistP256;

/// NIST P-256 Ephemeral Diffie-Hellman Secret.
pub type EphemeralSecret = elliptic_curve::ecdh::EphemeralSecret<NistP256>;

/// Shared secret value computed via ECDH key agreement.
pub type SharedSecret = elliptic_curve::ecdh::SharedSecret<NistP256>;
13 changes: 10 additions & 3 deletions p256/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#[cfg(feature = "arithmetic")]
mod arithmetic;

#[cfg(feature = "ecdh")]
#[cfg_attr(docsrs, doc(cfg(feature = "ecdh")))]
pub mod ecdh;

#[cfg(feature = "ecdsa-core")]
#[cfg_attr(docsrs, doc(cfg(feature = "ecdsa-core")))]
pub mod ecdsa;
Expand Down Expand Up @@ -67,7 +71,10 @@ impl elliptic_curve::Curve for NistP256 {
type ElementSize = U32;
}

impl elliptic_curve::weierstrass::Curve for NistP256 {}
impl elliptic_curve::weierstrass::Curve for NistP256 {
/// NIST P-256 points are typically uncompressed.
const COMPRESS_POINTS: bool = false;
}

#[cfg(feature = "oid")]
impl elliptic_curve::Identifier for NistP256 {
Expand All @@ -80,9 +87,9 @@ pub type SecretKey = elliptic_curve::SecretKey<NistP256>;
/// NIST P-256 Public Key
pub type PublicKey = elliptic_curve::weierstrass::PublicKey<NistP256>;

/// NIST P-256 Scalar Bytes.
/// NIST P-256 Serialized Field Element.
///
/// Byte array containing a serialized scalar value (i.e. an integer)
/// Byte array containing a serialized field element value (base field or scalar).
pub type ElementBytes = elliptic_curve::ElementBytes<NistP256>;

/// NIST P-256 Compressed Curve Point
Expand Down
4 changes: 3 additions & 1 deletion p384/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ impl elliptic_curve::Identifier for NistP384 {
const OID: ObjectIdentifier = ObjectIdentifier::new(&[1, 3, 132, 0, 34]);
}

impl elliptic_curve::weierstrass::Curve for NistP384 {}
impl elliptic_curve::weierstrass::Curve for NistP384 {
const COMPRESS_POINTS: bool = false;
}

/// NIST P-384 Secret Key
pub type SecretKey = elliptic_curve::SecretKey<NistP384>;
Expand Down

0 comments on commit b06fcf0

Please sign in to comment.