pub struct SharedSecret<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) -> &FieldBytes<C>
pub fn raw_secret_bytes(&self) -> &FieldBytes<C>
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(secret_bytes: FieldBytes<C>) -> Self
fn from(secret_bytes: FieldBytes<C>) -> Self
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
.