pub trait Pke {
type PublicKey: AsRef<[u8]> + Clone;
type SecretKey: Zeroize + AsRef<[u8]> + Clone;
type Ciphertext: AsRef<[u8]> + Clone;
// Required methods
fn name() -> &'static str;
fn keypair<R>(
rng: &mut R,
) -> Result<(Self::PublicKey, Self::SecretKey), Error>
where R: CryptoRng + RngCore;
fn encrypt<R>(
pk_recipient: &Self::PublicKey,
plaintext: &[u8],
aad: Option<&[u8]>,
rng: &mut R,
) -> Result<Self::Ciphertext, Error>
where R: RngCore + CryptoRng;
fn decrypt(
sk_recipient: &Self::SecretKey,
ciphertext: &Self::Ciphertext,
aad: Option<&[u8]>,
) -> Result<Vec<u8>, Error>;
}Expand description
Trait for Public Key Encryption schemes.
Required Associated Types§
Sourcetype PublicKey: AsRef<[u8]> + Clone
type PublicKey: AsRef<[u8]> + Clone
Public key type for the PKE scheme. Expected to be a byte representation that can be deserialized.
Sourcetype SecretKey: Zeroize + AsRef<[u8]> + Clone
type SecretKey: Zeroize + AsRef<[u8]> + Clone
Secret key type for the PKE scheme. Expected to be a byte representation that can be deserialized.
Sourcetype Ciphertext: AsRef<[u8]> + Clone
type Ciphertext: AsRef<[u8]> + Clone
Ciphertext type produced by the PKE scheme.
This is typically a Vec<u8> containing the serialized ciphertext components.
Required Methods§
Sourcefn keypair<R>(rng: &mut R) -> Result<(Self::PublicKey, Self::SecretKey), Error>
fn keypair<R>(rng: &mut R) -> Result<(Self::PublicKey, Self::SecretKey), Error>
Generates a new key pair for the PKE scheme.
Sourcefn encrypt<R>(
pk_recipient: &Self::PublicKey,
plaintext: &[u8],
aad: Option<&[u8]>,
rng: &mut R,
) -> Result<Self::Ciphertext, Error>
fn encrypt<R>( pk_recipient: &Self::PublicKey, plaintext: &[u8], aad: Option<&[u8]>, rng: &mut R, ) -> Result<Self::Ciphertext, Error>
Encrypts a plaintext message using the recipient’s public key.
§Arguments
pk_recipient- The recipient’s public key.plaintext- The message to encrypt.aad- Optional Associated Additional Data to be authenticated.rng- A cryptographically secure random number generator.
§Returns
The resulting ciphertext as a Vec<u8>.
Sourcefn decrypt(
sk_recipient: &Self::SecretKey,
ciphertext: &Self::Ciphertext,
aad: Option<&[u8]>,
) -> Result<Vec<u8>, Error>
fn decrypt( sk_recipient: &Self::SecretKey, ciphertext: &Self::Ciphertext, aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>
Decrypts a ciphertext using the recipient’s secret key.
§Arguments
sk_recipient- The recipient’s secret key.ciphertext- The ciphertext to decrypt.aad- Optional Associated Additional Data that was authenticated.
§Returns
The original plaintext as a Vec<u8> if decryption and authentication (if applicable) succeed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".