pub struct PublicKey<S: Suite> {
pub point: NonZero<Point<S::E>>,
}
Expand description
Public key is a point on the elliptic curve of the chosen suite.
You can obtain a public key from a newly generated private key by
PrivateKey::public_key
, or by reading it from bytes with
PublicKey::from_bytes
Fields§
§point: NonZero<Point<S::E>>
Q
in the standard
Implementations§
Source§impl PublicKey<Curve25519Aes128cbcHmacsha256>
impl PublicKey<Curve25519Aes128cbcHmacsha256>
Sourcepub fn encrypt_in_place<'m>(
&self,
message: &'m mut [u8],
data_len: usize,
rng: &mut (impl RngCore + CryptoRng),
) -> Result<EncryptedMessage<'m>, EncError>
pub fn encrypt_in_place<'m>( &self, message: &'m mut [u8], data_len: usize, rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m>, EncError>
Encrypt the message bytes in place; specialization for
curve25519aes128_cbchmac
. Uses PKCS7 padding.
message
- the buffer containing the message to encrypt, plus enough space for paddingdata_len
- length of the message in the buffer
Given a message m
, the size of the buffer should be at least m.len() + pad_size(m.len())
. If the buffer size is too small, the function will
return crate::EncError::PadError
You can interact with the encrypted bytes through the returned
EncryptedMessage
, but be careful that changing them will invalidate
the mac.
Convenient alias for PublicKey::block_encrypt_in_place
Sourcepub fn encrypt(
&self,
message: &[u8],
rng: &mut (impl RngCore + CryptoRng),
) -> Result<Vec<u8>, EncError>
pub fn encrypt( &self, message: &[u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<Vec<u8>, EncError>
Encrypt the message bytes into a new buffer. Uses PKCS7 padding.
Returnes the encoded bytes of EncryptedMessage
. Specialization for
curve25519aes128_cbchmac
Convenient alias for PublicKey::block_encrypt
Source§impl PublicKey<Curve25519Xsalsa20Hmacsha256>
impl PublicKey<Curve25519Xsalsa20Hmacsha256>
Sourcepub fn encrypt_in_place<'m>(
&self,
message: &'m mut [u8],
rng: &mut (impl RngCore + CryptoRng),
) -> Result<EncryptedMessage<'m>, EncError>
pub fn encrypt_in_place<'m>( &self, message: &'m mut [u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m>, EncError>
Encrypt the message bytes in place; specialization for
curve25519xsalsa20hmac
You can interact with the encrypted bytes through the returned
EncryptedMessage
, but be careful that changing them will invalidate
the mac.
Convenient alias for PublicKey::stream_encrypt_in_place
Source§impl<S: Suite> PublicKey<S>
impl<S: Suite> PublicKey<S>
Sourcepub fn from_bytes(bytes: impl AsRef<[u8]>) -> Option<Self>
pub fn from_bytes(bytes: impl AsRef<[u8]>) -> Option<Self>
Read the encoded scalar. Should be compatible with most other software for working with elliptic curves.
Sourcepub fn to_bytes(&self) -> Vec<u8> ⓘ
pub fn to_bytes(&self) -> Vec<u8> ⓘ
Write the encoded scalar. Should be compatible with most other software for working with elliptic curves.
Sourcepub fn stream_encrypt_in_place<'m>(
&self,
message: &'m mut [u8],
rng: &mut (impl RngCore + CryptoRng),
) -> Result<EncryptedMessage<'m, S>, EncError>
pub fn stream_encrypt_in_place<'m>( &self, message: &'m mut [u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m, S>, EncError>
Encrypt the message bytes in place. Variant for suites with stream ciphers.
You can interact with the encrypted bytes through the returned
EncryptedMessage
, but be careful that changing them will invalidate
the mac.
Sourcepub fn block_encrypt_in_place<'m>(
&self,
message: &'m mut [u8],
data_len: usize,
rng: &mut (impl RngCore + CryptoRng),
) -> Result<EncryptedMessage<'m, S>, EncError>
pub fn block_encrypt_in_place<'m>( &self, message: &'m mut [u8], data_len: usize, rng: &mut (impl RngCore + CryptoRng), ) -> Result<EncryptedMessage<'m, S>, EncError>
Encrypt the message bytes in place. Variant for suites with block ciphers. Uses PKCS7 padding.
message
- the buffer containing the message to encrypt, plus enough space for paddingdata_len
- length of the message in the buffer
Given a message m
, the size of the buffer should be at least m.len() + pad_size(m.len())
. If the buffer size is too small, the function will
return EncError::PadError
You can interact with the encrypted bytes through the returned
EncryptedMessage
, but be careful that changing them will invalidate
the mac.
Sourcepub fn stream_encrypt(
&self,
message: &[u8],
rng: &mut (impl RngCore + CryptoRng),
) -> Result<Vec<u8>, EncError>
pub fn stream_encrypt( &self, message: &[u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<Vec<u8>, EncError>
Encrypt the message bytes into a new buffer. Variant for suites with stream ciphers.
Returnes the encoded bytes of EncryptedMessage
Sourcepub fn block_encrypt(
&self,
message: &[u8],
rng: &mut (impl RngCore + CryptoRng),
) -> Result<Vec<u8>, EncError>
pub fn block_encrypt( &self, message: &[u8], rng: &mut (impl RngCore + CryptoRng), ) -> Result<Vec<u8>, EncError>
Encrypt the message bytes into a new buffer. Variant for suites with block ciphers. Uses PKCS7 padding.
Returnes the encoded bytes of EncryptedMessage