pub struct SharedSecret<C>where
C: Curve,{ /* private fields */ }Expand description
Shared secret value computed via ECDH key agreement.
Implementations§
Sourcepub fn extract<D>(&self, salt: Option<&[u8]>) -> Hkdf<D, SimpleHmac<D>>
pub fn extract<D>(&self, salt: Option<&[u8]>) -> Hkdf<D, SimpleHmac<D>>
Use HKDF (HMAC-based Extract-and-Expand Key Derivation Function) to extract entropy from this shared secret.
This method can be used to transform the shared secret into uniformly random values which are suitable as key material.
The D type parameter is a cryptographic digest function.
sha2::Sha256 is a common choice for use with HKDF.
The salt parameter can be used to supply additional randomness.
Some examples include:
- randomly generated (but authenticated) string
- fixed application-specific value
- previous shared secret used for rekeying (as in TLS 1.3 and Noise)
After initializing HKDF, use Hkdf::expand to obtain output key
material.
Sourcepub fn raw_secret_bytes(
&self,
) -> &GenericArray<u8, <C as Curve>::FieldBytesSize>
pub fn raw_secret_bytes( &self, ) -> &GenericArray<u8, <C as Curve>::FieldBytesSize>
This value contains the raw serialized x-coordinate of the elliptic curve point computed from a Diffie-Hellman exchange, serialized as bytes.
When in doubt, use SharedSecret::extract instead.
§⚠️ WARNING: NOT UNIFORMLY RANDOM! ⚠️
This value is not uniformly random and should not be used directly as a cryptographic key for anything which requires that property (e.g. symmetric ciphers).
Instead, the resulting value should be used as input to a Key Derivation
Function (KDF) or cryptographic hash function to produce a symmetric key.
The SharedSecret::extract function will do this for you.
Trait Implementations§
Source§fn from(affine: &AffinePoint<C>) -> SharedSecret<C>
fn from(affine: &AffinePoint<C>) -> SharedSecret<C>
Source§fn from(
secret_bytes: GenericArray<u8, <C as Curve>::FieldBytesSize>,
) -> SharedSecret<C>
fn from( secret_bytes: GenericArray<u8, <C as Curve>::FieldBytesSize>, ) -> SharedSecret<C>
NOTE: this impl is intended to be used by curve implementations to
instantiate a SharedSecret value from their respective
AffinePoint type.
Curve implementations should provide the field element representing
the affine x-coordinate as secret_bytes.
Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more