Skip to content
Merged
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
14 changes: 14 additions & 0 deletions elliptic-curve/src/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ use zeroize::{Zeroize, ZeroizeOnDrop, Zeroizing};
#[cfg(feature = "arithmetic")]
use crate::{CurveArithmetic, NonZeroScalar, PublicKey};

#[cfg(feature = "ecdh")]
use crate::ecdh;

#[cfg(feature = "pem")]
use pem_rfc7468::{self as pem, PemLabel};

Expand Down Expand Up @@ -172,6 +175,17 @@ where
self.inner.to_bytes()
}

/// Perform Elliptic Curve Diffie-Hellman with the given public key, returning a shared secret.
///
/// See the documentation in the [`ecdh`] module for more information.
#[cfg(feature = "ecdh")]
pub fn diffie_hellman(self, public_key: &PublicKey<C>) -> ecdh::SharedSecret<C>
where
C: CurveArithmetic,
{
ecdh::diffie_hellman(self.to_nonzero_scalar(), public_key.as_affine())
}

/// Deserialize secret key encoded in the SEC1 ASN.1 DER `ECPrivateKey` format.
#[cfg(feature = "sec1")]
pub fn from_sec1_der(der_bytes: &[u8]) -> Result<Self>
Expand Down