Enum KemAlgorithm

Source
pub enum KemAlgorithm {
    Rsa(RsaBits, HashAlgorithm),
    Kyber(KyberSecurityLevel),
}
Expand description

Key Encapsulation Mechanism algorithm enumeration.

密钥封装机制算法枚举。

§Algorithm Types | 算法类型

This enum supports both traditional and post-quantum KEM algorithms, allowing applications to choose based on their security and compatibility requirements.

此枚举支持传统和后量子 KEM 算法, 允许应用程序根据其安全性和兼容性要求进行选择。

Variants§

§

Rsa(RsaBits, HashAlgorithm)

RSA-based Key Encapsulation Mechanism.

基于 RSA 的密钥封装机制。

Traditional public-key cryptosystem with configurable key size and hash function. Widely supported but vulnerable to quantum attacks.

具有可配置密钥大小和哈希函数的传统公钥密码系统。 广泛支持但易受量子攻击。

§

Kyber(KyberSecurityLevel)

Kyber post-quantum Key Encapsulation Mechanism.

Kyber 后量子密钥封装机制。

NIST-standardized lattice-based KEM providing security against quantum computers. Offers excellent performance and smaller ciphertext sizes compared to RSA.

NIST 标准化的基于格的 KEM,提供对量子计算机的安全性。 与 RSA 相比提供出色的性能和更小的密文大小。

Implementations§

Source§

impl KemAlgorithm

Source

pub fn build() -> KemAlgorithmBuilder

Creates a new KEM algorithm builder.

创建新的 KEM 算法构建器。

§Examples | 示例
use seal_crypto_wrapper::algorithms::asymmetric::kem::KemAlgorithm;

// Post-quantum KEM
let kyber = KemAlgorithm::build().kyber512();

// Traditional KEM
let rsa = KemAlgorithm::build().rsa2048().sha256();
Source§

impl KemAlgorithm

Source

pub fn into_wrapper(self) -> KemAlgorithmWrapper

Converts the algorithm enum into a concrete wrapper implementation.

将算法枚举转换为具体的包装器实现。

§Purpose | 目的

This method creates a wrapper that implements the KEM algorithm trait, enabling actual cryptographic operations like key encapsulation and decapsulation with type safety guarantees.

此方法创建一个实现 KEM 算法 trait 的包装器, 启用实际的密码操作,如密钥封装和解封装,并提供类型安全保证。

§Returns | 返回值

A KemAlgorithmWrapper that can perform:

  • Key pair generation
  • Key encapsulation (encryption)
  • Key decapsulation (decryption)
  • Algorithm introspection

可以执行以下操作的 KemAlgorithmWrapper

  • 密钥对生成
  • 密钥封装(加密)
  • 密钥解封装(解密)
  • 算法内省
§Examples | 示例
use seal_crypto_wrapper::algorithms::asymmetric::kem::KemAlgorithm;

let algorithm = KemAlgorithm::build().kyber512();
let kem = algorithm.into_wrapper();

// Generate key pair
let keypair = kem.generate_keypair()?;
let (public_key, private_key) = keypair.into_keypair();

// Encapsulate a shared secret
let (shared_secret, ciphertext) = kem.encapsulate_key(&public_key)?;

// Decapsulate to recover the shared secret
let recovered_secret = kem.decapsulate_key(&private_key, &ciphertext)?;
assert_eq!(shared_secret, recovered_secret);

Trait Implementations§

Source§

impl<'__de, __Context> BorrowDecode<'__de, __Context> for KemAlgorithm

Source§

fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given BorrowDecode.
Source§

impl Clone for KemAlgorithm

Source§

fn clone(&self) -> KemAlgorithm

Returns a duplicate 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 Debug for KemAlgorithm

Source§

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

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

impl<__Context> Decode<__Context> for KemAlgorithm

Source§

fn decode<__D: Decoder<Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>

Attempt to decode this type with the given Decode.
Source§

impl<'de> Deserialize<'de> for KemAlgorithm

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Encode for KemAlgorithm

Source§

fn encode<__E: Encoder>(&self, encoder: &mut __E) -> Result<(), EncodeError>

Encode a given type.
Source§

impl From<KemAlgorithm> for KemAlgorithmWrapper

Source§

fn from(algorithm: KemAlgorithm) -> Self

Converts to this type from the input type.
Source§

impl Hash for KemAlgorithm

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for KemAlgorithm

Source§

fn eq(&self, other: &KemAlgorithm) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for KemAlgorithm

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for KemAlgorithm

Source§

impl Eq for KemAlgorithm

Source§

impl StructuralPartialEq for KemAlgorithm

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ConditionallySerde for T
where T: Serialize + for<'de> Deserialize<'de>,

Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,