pub struct X25519PrivateKey(/* private fields */);
Expand description
A private key for X25519 key agreement operations.
X25519 is an elliptic-curve Diffie-Hellman key exchange protocol based on Curve25519 as defined in RFC 7748. It allows two parties to establish a shared secret key over an insecure channel.
Key features of X25519:
- High security (128-bit security level)
- High performance
- Small key sizes (32 bytes)
- Protection against various side-channel attacks
- Relatively simple implementation compared to other elliptic curve systems
This implementation provides:
- Generation of random X25519 private keys
- Derivation of the corresponding public key
- Shared key generation with another party’s public key
- CBOR serialization and deserialization
- Various utility and conversion methods
Implementations§
Source§impl X25519PrivateKey
impl X25519PrivateKey
pub const KEY_SIZE: usize = 32usize
Sourcepub fn keypair() -> (X25519PrivateKey, X25519PublicKey)
pub fn keypair() -> (X25519PrivateKey, X25519PublicKey)
Generate a new random X25519PrivateKey
and corresponding
X25519PublicKey
.
Sourcepub fn keypair_using(
rng: &mut impl RandomNumberGenerator,
) -> (X25519PrivateKey, X25519PublicKey)
pub fn keypair_using( rng: &mut impl RandomNumberGenerator, ) -> (X25519PrivateKey, X25519PublicKey)
Generate a new random X25519PrivateKey
and corresponding
X25519PublicKey
using the given random number generator.
Sourcepub fn new_using(rng: &mut impl RandomNumberGenerator) -> Self
pub fn new_using(rng: &mut impl RandomNumberGenerator) -> Self
Generate a new random X25519PrivateKey
using the given random number
generator.
Sourcepub const fn from_data(data: [u8; 32]) -> Self
pub const fn from_data(data: [u8; 32]) -> Self
Restore an X25519PrivateKey
from a fixed-size array of bytes.
Sourcepub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
pub fn from_data_ref(data: impl AsRef<[u8]>) -> Result<Self>
Restore an X25519PrivateKey
from a reference to an array of bytes.
Sourcepub fn from_hex(hex: impl AsRef<str>) -> Self
pub fn from_hex(hex: impl AsRef<str>) -> Self
Restore an X25519PrivateKey
from a hex string.
§Panics
Panics if the hex string is invalid or the length is not
X25519PrivateKey::KEY_SIZE * 2
.
Sourcepub fn public_key(&self) -> X25519PublicKey
pub fn public_key(&self) -> X25519PublicKey
Get the X25519PublicKey
corresponding to this X25519PrivateKey
.
Sourcepub fn derive_from_key_material(key_material: impl AsRef<[u8]>) -> Self
pub fn derive_from_key_material(key_material: impl AsRef<[u8]>) -> Self
Derive an X25519PrivateKey
from the given key material.
Derive a shared symmetric key from this X25519PrivateKey
and the given
X25519PublicKey
.
Trait Implementations§
Source§impl AsRef<[u8]> for X25519PrivateKey
impl AsRef<[u8]> for X25519PrivateKey
Source§impl AsRef<X25519PrivateKey> for X25519PrivateKey
Implements AsRef<X25519PrivateKey>
to allow self-reference.
impl AsRef<X25519PrivateKey> for X25519PrivateKey
Implements AsRef<X25519PrivateKey>
to allow self-reference.
Source§impl CBORTagged for X25519PrivateKey
Implements the CBORTagged trait to provide CBOR tag information.
impl CBORTagged for X25519PrivateKey
Implements the CBORTagged trait to provide CBOR tag information.
Source§impl CBORTaggedDecodable for X25519PrivateKey
Implements CBORTaggedDecodable to provide CBOR decoding functionality.
impl CBORTaggedDecodable for X25519PrivateKey
Implements CBORTaggedDecodable to provide CBOR decoding functionality.
Source§fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
fn from_untagged_cbor(untagged_cbor: CBOR) -> Result<Self>
Source§fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
fn from_tagged_cbor(cbor: CBOR) -> Result<Self, Error>where
Self: Sized,
Source§impl CBORTaggedEncodable for X25519PrivateKey
Implements CBORTaggedEncodable to provide CBOR encoding functionality.
impl CBORTaggedEncodable for X25519PrivateKey
Implements CBORTaggedEncodable to provide CBOR encoding functionality.
Source§fn untagged_cbor(&self) -> CBOR
fn untagged_cbor(&self) -> CBOR
Source§fn tagged_cbor(&self) -> CBOR
fn tagged_cbor(&self) -> CBOR
Source§impl Clone for X25519PrivateKey
impl Clone for X25519PrivateKey
Source§fn clone(&self) -> X25519PrivateKey
fn clone(&self) -> X25519PrivateKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for X25519PrivateKey
Implements Debug to output the key with a type label.
impl Debug for X25519PrivateKey
Implements Debug to output the key with a type label.
Source§impl Decrypter for X25519PrivateKey
Implements the Decrypter trait to support key encapsulation mechanisms.
impl Decrypter for X25519PrivateKey
Implements the Decrypter trait to support key encapsulation mechanisms.
Source§fn encapsulation_private_key(&self) -> EncapsulationPrivateKey
fn encapsulation_private_key(&self) -> EncapsulationPrivateKey
Source§impl Default for X25519PrivateKey
Implements Default to create a new random X25519PrivateKey.
impl Default for X25519PrivateKey
Implements Default to create a new random X25519PrivateKey.
Source§impl<'a> From<&'a X25519PrivateKey> for &'a [u8; 32]
Implements conversion from an X25519PrivateKey reference to a byte array
reference.
impl<'a> From<&'a X25519PrivateKey> for &'a [u8; 32]
Implements conversion from an X25519PrivateKey reference to a byte array reference.
Source§fn from(value: &'a X25519PrivateKey) -> Self
fn from(value: &'a X25519PrivateKey) -> Self
Source§impl From<&X25519PrivateKey> for Vec<u8>
Implements conversion from an X25519PrivateKey reference to a byte vector.
impl From<&X25519PrivateKey> for Vec<u8>
Implements conversion from an X25519PrivateKey reference to a byte vector.
Source§fn from(key: &X25519PrivateKey) -> Self
fn from(key: &X25519PrivateKey) -> Self
Source§impl From<&X25519PrivateKey> for X25519PrivateKey
Implements conversion from an X25519PrivateKey reference to an owned
X25519PrivateKey.
impl From<&X25519PrivateKey> for X25519PrivateKey
Implements conversion from an X25519PrivateKey reference to an owned X25519PrivateKey.
Source§fn from(key: &X25519PrivateKey) -> Self
fn from(key: &X25519PrivateKey) -> Self
Source§impl From<Rc<X25519PrivateKey>> for X25519PrivateKey
Implements conversion from a reference-counted X25519PrivateKey to an owned
X25519PrivateKey.
impl From<Rc<X25519PrivateKey>> for X25519PrivateKey
Implements conversion from a reference-counted X25519PrivateKey to an owned X25519PrivateKey.
Source§fn from(value: Rc<X25519PrivateKey>) -> Self
fn from(value: Rc<X25519PrivateKey>) -> Self
Source§impl From<X25519PrivateKey> for CBOR
Implements conversion from X25519PrivateKey to CBOR for serialization.
impl From<X25519PrivateKey> for CBOR
Implements conversion from X25519PrivateKey to CBOR for serialization.
Source§fn from(value: X25519PrivateKey) -> Self
fn from(value: X25519PrivateKey) -> Self
Source§impl From<X25519PrivateKey> for Vec<u8>
Implements conversion from an X25519PrivateKey to a byte vector.
impl From<X25519PrivateKey> for Vec<u8>
Implements conversion from an X25519PrivateKey to a byte vector.
Source§fn from(key: X25519PrivateKey) -> Self
fn from(key: X25519PrivateKey) -> Self
Source§impl Hash for X25519PrivateKey
impl Hash for X25519PrivateKey
Source§impl PartialEq for X25519PrivateKey
impl PartialEq for X25519PrivateKey
Source§impl TryFrom<CBOR> for X25519PrivateKey
Implements TryFrom<CBOR>
for X25519PrivateKey to support conversion from
CBOR data.
impl TryFrom<CBOR> for X25519PrivateKey
Implements TryFrom<CBOR>
for X25519PrivateKey to support conversion from
CBOR data.
impl Eq for X25519PrivateKey
impl StructuralPartialEq for X25519PrivateKey
Auto Trait Implementations§
impl Freeze for X25519PrivateKey
impl RefUnwindSafe for X25519PrivateKey
impl Send for X25519PrivateKey
impl Sync for X25519PrivateKey
impl Unpin for X25519PrivateKey
impl UnwindSafe for X25519PrivateKey
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> CBORDecodable for T
impl<T> CBORDecodable for T
Source§impl<T> CBOREncodable for T
impl<T> CBOREncodable for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)