Skip to main content

Pke

Trait Pke 

Source
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§

Source

type PublicKey: AsRef<[u8]> + Clone

Public key type for the PKE scheme. Expected to be a byte representation that can be deserialized.

Source

type SecretKey: Zeroize + AsRef<[u8]> + Clone

Secret key type for the PKE scheme. Expected to be a byte representation that can be deserialized.

Source

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§

Source

fn name() -> &'static str

Returns the PKE algorithm name.

Source

fn keypair<R>(rng: &mut R) -> Result<(Self::PublicKey, Self::SecretKey), Error>
where R: CryptoRng + RngCore,

Generates a new key pair for the PKE scheme.

Source

fn encrypt<R>( pk_recipient: &Self::PublicKey, plaintext: &[u8], aad: Option<&[u8]>, rng: &mut R, ) -> Result<Self::Ciphertext, Error>
where R: RngCore + CryptoRng,

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>.

Source

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".

Implementations on Foreign Types§

Source§

impl Pke for EciesP224

Source§

type PublicKey = EciesP224PublicKey

Source§

type SecretKey = EciesP224SecretKey

Source§

type Ciphertext = Vec<u8>

Source§

fn name() -> &'static str

Source§

fn keypair<R>( rng: &mut R, ) -> Result<(<EciesP224 as Pke>::PublicKey, <EciesP224 as Pke>::SecretKey), Error>
where R: RngCore + CryptoRng,

Source§

fn encrypt<R>( pk_recipient: &<EciesP224 as Pke>::PublicKey, plaintext: &[u8], aad: Option<&[u8]>, rng: &mut R, ) -> Result<<EciesP224 as Pke>::Ciphertext, Error>
where R: RngCore + CryptoRng,

Source§

fn decrypt( sk_recipient: &<EciesP224 as Pke>::SecretKey, ciphertext_bytes: &<EciesP224 as Pke>::Ciphertext, aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>

Source§

impl Pke for EciesP256

Source§

type PublicKey = EciesP256PublicKey

Source§

type SecretKey = EciesP256SecretKey

Source§

type Ciphertext = Vec<u8>

Source§

fn name() -> &'static str

Source§

fn keypair<R>( rng: &mut R, ) -> Result<(<EciesP256 as Pke>::PublicKey, <EciesP256 as Pke>::SecretKey), Error>
where R: RngCore + CryptoRng,

Source§

fn encrypt<R>( pk_recipient: &<EciesP256 as Pke>::PublicKey, plaintext: &[u8], aad: Option<&[u8]>, rng: &mut R, ) -> Result<<EciesP256 as Pke>::Ciphertext, Error>
where R: RngCore + CryptoRng,

Source§

fn decrypt( sk_recipient: &<EciesP256 as Pke>::SecretKey, ciphertext_bytes: &<EciesP256 as Pke>::Ciphertext, aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>

Source§

impl Pke for EciesP384

Source§

type PublicKey = EciesP384PublicKey

Source§

type SecretKey = EciesP384SecretKey

Source§

type Ciphertext = Vec<u8>

Source§

fn name() -> &'static str

Source§

fn keypair<R>( rng: &mut R, ) -> Result<(<EciesP384 as Pke>::PublicKey, <EciesP384 as Pke>::SecretKey), Error>
where R: RngCore + CryptoRng,

Source§

fn encrypt<R>( pk_recipient: &<EciesP384 as Pke>::PublicKey, plaintext: &[u8], aad: Option<&[u8]>, rng: &mut R, ) -> Result<<EciesP384 as Pke>::Ciphertext, Error>
where R: RngCore + CryptoRng,

Source§

fn decrypt( sk_recipient: &<EciesP384 as Pke>::SecretKey, ciphertext_bytes: &<EciesP384 as Pke>::Ciphertext, aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>

Source§

impl Pke for EciesP521

Source§

type PublicKey = EciesP521PublicKey

Source§

type SecretKey = EciesP521SecretKey

Source§

type Ciphertext = Vec<u8>

Source§

fn name() -> &'static str

Source§

fn keypair<R>( rng: &mut R, ) -> Result<(<EciesP521 as Pke>::PublicKey, <EciesP521 as Pke>::SecretKey), Error>
where R: RngCore + CryptoRng,

Source§

fn encrypt<R>( pk_recipient: &<EciesP521 as Pke>::PublicKey, plaintext: &[u8], aad: Option<&[u8]>, rng: &mut R, ) -> Result<<EciesP521 as Pke>::Ciphertext, Error>
where R: RngCore + CryptoRng,

Source§

fn decrypt( sk_recipient: &<EciesP521 as Pke>::SecretKey, ciphertext_bytes: &<EciesP521 as Pke>::Ciphertext, aad: Option<&[u8]>, ) -> Result<Vec<u8>, Error>

Implementors§