Function elliptic_curve::ecdh::diffie_hellman[][src]

pub fn diffie_hellman<C>(
    secret_key: impl Borrow<NonZeroScalar<C>>,
    public_key: impl Borrow<AffinePoint<C>>
) -> SharedSecret<C> where
    C: Curve + ProjectiveArithmetic,
    AffinePoint<C>: Copy + Clone + Debug + Zeroize,
    ProjectivePoint<C>: From<AffinePoint<C>>,
    Scalar<C>: PrimeField<Repr = FieldBytes<C>> + Clone + Zeroize,
    SharedSecret<C>: for<'a> From<&'a AffinePoint<C>>, 
This is supported on crate feature ecdh only.

Low-level Elliptic Curve Diffie-Hellman (ECDH) function.

Whenever possible, we recommend using the high-level ECDH ephemeral API provided by EphemeralSecret.

However, if you are implementing a protocol which requires a static scalar value as part of an ECDH exchange, this API can be used to compute a SharedSecret from that value.

Note that this API operates on the low-level NonZeroScalar and AffinePoint types. If you are attempting to use the higher-level SecretKey and PublicKey types, you will need to use the following conversions:

let shared_secret = elliptic_curve::ecdh::diffie_hellman(
    secret_key.secret_scalar(),
    public_key.as_affine()
);