Struct hpke_rs::Hpke

source ·
pub struct Hpke<Crypto: 'static + HpkeCrypto> { /* private fields */ }
Expand description

The HPKE configuration struct. This holds the configuration for HPKE but no state. To use HPKE first instantiate the configuration with let hpke = Hpke::new(mode, kem_mode, kdf_mode, aead_mode). Now one can use the hpke configuration.

Note that cloning does NOT clone the PRNG state.

Implementations§

source§

impl<Crypto: HpkeCrypto> Hpke<Crypto>

source

pub fn new( mode: Mode, kem_id: KemAlgorithm, kdf_id: KdfAlgorithm, aead_id: AeadAlgorithm ) -> Self

Set up the configuration for HPKE.

source

pub fn setup_sender( &mut self, pk_r: &HpkePublicKey, info: &[u8], psk: Option<&[u8]>, psk_id: Option<&[u8]>, sk_s: Option<&HpkePrivateKey> ) -> Result<(Vec<u8>, Context<Crypto>), HpkeError>

Set up an HPKE sender.

For the base and PSK modes this encapsulates the public key pk_r of the receiver. For the Auth and AuthPSK modes this encapsulates and authenticates the public key pk_r of the receiver with the senders secret key sk_s.

Note that this API expects the public key to be encoded. This differs from the RFC. But the public keys will be present in encoded form rather than raw form such that it doesn’t make sense to deserialize before passing it in.

The encapsulated secret is returned together with the context. If the secret key is missing in an authenticated mode, an error is returned.

source

pub fn setup_receiver( &self, enc: &[u8], sk_r: &HpkePrivateKey, info: &[u8], psk: Option<&[u8]>, psk_id: Option<&[u8]>, pk_s: Option<&HpkePublicKey> ) -> Result<Context<Crypto>, HpkeError>

Set up an HPKE receiver.

For the base and PSK modes this decapsulates enc with the secret key sk_r of the receiver. For the Auth and AuthPSK modes this decapsulates and authenticates enc with the secret key sk_r of the receiver and the senders public key pk_s.

Note that this API expects the public key to be encoded. This differs from the RFC. But the public keys will be present in encoded form rather than raw form such that it doesn’t make sense to deserialize before passing it in.

The context based on the decapsulated values and, if present, the PSK is returned. If the secret key is missing in an authenticated mode, an error is returned.

source

pub fn seal( &mut self, pk_r: &HpkePublicKey, info: &[u8], aad: &[u8], plain_txt: &[u8], psk: Option<&[u8]>, psk_id: Option<&[u8]>, sk_s: Option<&HpkePrivateKey> ) -> Result<(Vec<u8>, Vec<u8>), HpkeError>

  1. Single-Shot APIs 6.1. Encryption and Decryption

Single shot API to encrypt the bytes in plain_text to the public key pk_r.

Note that this API expects the public key to be encoded. This differs from the RFC. But the public keys will be present in encoded form rather than raw form such that it doesn’t make sense to deserialize before passing it in.

Returns the encapsulated secret and the ciphertext, or an error.

source

pub fn open( &self, enc: &[u8], sk_r: &HpkePrivateKey, info: &[u8], aad: &[u8], ct: &[u8], psk: Option<&[u8]>, psk_id: Option<&[u8]>, pk_s: Option<&HpkePublicKey> ) -> Result<Vec<u8>, HpkeError>

  1. Single-Shot APIs 6.1. Encryption and Decryption

Single shot API to decrypt the bytes in ct with the private key sk_r.

Note that this API expects the public key to be encoded. This differs from the RFC. But the public keys will be present in encoded form rather than raw form such that it doesn’t make sense to deserialize before passing it in.

Returns the decrypted plain text, or an error.

source

pub fn send_export( &mut self, pk_r: &HpkePublicKey, info: &[u8], psk: Option<&[u8]>, psk_id: Option<&[u8]>, sk_s: Option<&HpkePrivateKey>, exporter_context: &[u8], length: usize ) -> Result<(Vec<u8>, Vec<u8>), HpkeError>

  1. Single-Shot APIs 6.2. Secret Export

Single shot API to derive an exporter secret for receiver with public key pk_r.

Note that this API expects the public key to be encoded. This differs from the RFC. But the public keys will be present in encoded form rather than raw form such that it doesn’t make sense to deserialize before passing it in.

Returns the encapsulated secret and the exporter secret for the given exporter context and length.

source

pub fn receiver_export( &self, enc: &[u8], sk_r: &HpkePrivateKey, info: &[u8], psk: Option<&[u8]>, psk_id: Option<&[u8]>, pk_s: Option<&HpkePublicKey>, exporter_context: &[u8], length: usize ) -> Result<Vec<u8>, HpkeError>

  1. Single-Shot APIs 6.2. Secret Export

Single shot API to derive an exporter secret for receiver with private key sk_r.

Note that this API expects the public key to be encoded. This differs from the RFC. But the public keys will be present in encoded form rather than raw form such that it doesn’t make sense to deserialize before passing it in.

Returns the exporter secret for the given exporter context and length.

source

pub fn key_schedule( &self, shared_secret: &[u8], info: &[u8], psk: &[u8], psk_id: &[u8] ) -> Result<Context<Crypto>, HpkeError>

Creating the Encryption Context Generate the HPKE context from the given input.

source

pub fn generate_key_pair(&mut self) -> Result<HpkeKeyPair, HpkeError>

  1. Cryptographic Dependencies Randomized algorithm to generate a key pair (skX, pkX) for the KEM. This is equivalent to derive_key_pair(random_vector(sk.len()))

Returns an HpkeKeyPair.

source

pub fn derive_key_pair(&self, ikm: &[u8]) -> Result<HpkeKeyPair, HpkeError>

7.1.2. DeriveKeyPair Derive a key pair for the used KEM with the given input key material.

Returns an HpkeKeyPair result or an HpkeError if key derivation fails.

Trait Implementations§

source§

impl<Crypto: 'static + HpkeCrypto> Clone for Hpke<Crypto>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<Crypto: Debug + 'static + HpkeCrypto> Debug for Hpke<Crypto>
where Crypto::HpkePrng: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<Crypto: HpkeCrypto> Display for Hpke<Crypto>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Crypto> RefUnwindSafe for Hpke<Crypto>
where <Crypto as HpkeCrypto>::HpkePrng: RefUnwindSafe,

§

impl<Crypto> Send for Hpke<Crypto>
where <Crypto as HpkeCrypto>::HpkePrng: Send,

§

impl<Crypto> Sync for Hpke<Crypto>
where <Crypto as HpkeCrypto>::HpkePrng: Sync,

§

impl<Crypto> Unpin for Hpke<Crypto>
where <Crypto as HpkeCrypto>::HpkePrng: Unpin,

§

impl<Crypto> UnwindSafe for Hpke<Crypto>
where <Crypto as HpkeCrypto>::HpkePrng: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.