kem/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3#![cfg_attr(docsrs, feature(doc_auto_cfg))]
4#![doc(
5    html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
6    html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg",
7    html_root_url = "https://docs.rs/kem"
8)]
9#![forbid(unsafe_code)]
10#![warn(missing_docs, unused_qualifications, missing_debug_implementations)]
11
12use core::fmt::Debug;
13use rand_core::CryptoRngCore;
14
15/// A value that can be encapsulated to. Often, this will just be a public key. However, it can
16/// also be a bundle of public keys, or it can include a sender's private key for authenticated
17/// encapsulation.
18pub trait Encapsulate<EK, SS> {
19    /// Encapsulation error
20    type Error: Debug;
21
22    /// Encapsulates a fresh shared secret
23    fn encapsulate(&self, rng: &mut impl CryptoRngCore) -> Result<(EK, SS), Self::Error>;
24}
25
26/// A value that can be used to decapsulate an encapsulated key. Often, this will just be a secret
27/// key. But, as with [`Encapsulate`], it can be a bundle of secret keys, or it can include a
28/// sender's private key for authenticated encapsulation.
29pub trait Decapsulate<EK, SS> {
30    /// Decapsulation error
31    type Error: Debug;
32
33    /// Decapsulates the given encapsulated key
34    fn decapsulate(&self, encapsulated_key: &EK) -> Result<SS, Self::Error>;
35}