Enum SignatureAlgorithm

Source
pub enum SignatureAlgorithm {
    Dilithium(DilithiumSecurityLevel),
    Ed25519,
    EcdsaP256,
}
Expand description

Digital signature algorithm enumeration.

数字签名算法枚举。

§Algorithm Selection Guide | 算法选择指南

Choose based on your requirements:

根据您的要求选择:

  • High Performance: Ed25519

  • Standards Compliance: ECDSA P-256

  • Post-Quantum Security: Dilithium variants

  • Long-term Security: Dilithium-5

  • Balanced Approach: Dilithium-2

  • 高性能: Ed25519

  • 标准合规性: ECDSA P-256

  • 后量子安全: Dilithium 变体

  • 长期安全: Dilithium-5

  • 平衡方法: Dilithium-2

Variants§

§

Dilithium(DilithiumSecurityLevel)

Dilithium post-quantum signature algorithm.

Dilithium 后量子签名算法。

Based on lattice cryptography, providing security against both classical and quantum computers. Standardized by NIST as FIPS 204.

基于格密码学,提供对经典和量子计算机的安全性。 由 NIST 标准化为 FIPS 204。

§

Ed25519

Ed25519 signature algorithm using Edwards curves.

使用 Edwards 曲线的 Ed25519 签名算法。

High-performance signature algorithm with deterministic signatures. Based on Curve25519 and provides 128-bit security level.

具有确定性签名的高性能签名算法。 基于 Curve25519 并提供 128 位安全级别。

§

EcdsaP256

ECDSA over NIST P-256 curve.

基于 NIST P-256 曲线的 ECDSA。

Widely standardized and supported signature algorithm. Provides 128-bit security level with good performance.

广泛标准化和支持的签名算法。 提供 128 位安全级别和良好性能。

Implementations§

Source§

impl SignatureAlgorithm

Source

pub fn build() -> SignatureAlgorithmBuilder

Creates a new signature algorithm builder.

创建新的签名算法构建器。

§Returns | 返回值

A builder that provides access to different signature algorithms. Use the builder methods to select the specific algorithm needed.

提供访问不同签名算法的构建器。 使用构建器方法选择所需的特定算法。

§Examples | 示例
use seal_crypto_wrapper::algorithms::asymmetric::signature::SignatureAlgorithm;

let ed25519 = SignatureAlgorithm::build().ed25519();
let dilithium = SignatureAlgorithm::build().dilithium2();
Source§

impl SignatureAlgorithm

Source

pub fn into_wrapper(self) -> SignatureAlgorithmWrapper

Converts the algorithm enum into a concrete wrapper implementation.

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

§Purpose | 目的

This method creates a wrapper that implements the signature algorithm trait, enabling actual cryptographic operations like key pair generation, message signing, and signature verification with type safety guarantees.

此方法创建一个实现签名算法 trait 的包装器, 启用实际的密码操作,如密钥对生成、消息签名和签名验证,并提供类型安全保证。

§Returns | 返回值

A SignatureAlgorithmWrapper that can perform:

  • Key pair generation
  • Message signing
  • Signature verification
  • Algorithm introspection

可以执行以下操作的 SignatureAlgorithmWrapper

  • 密钥对生成
  • 消息签名
  • 签名验证
  • 算法内省
§Examples | 示例
use seal_crypto_wrapper::algorithms::asymmetric::signature::SignatureAlgorithm;

let algorithm = SignatureAlgorithm::build().ed25519();
let signer = algorithm.into_wrapper();

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

// Sign a message
let message = b"Hello, World!";
let signature = signer.sign(message, &private_key)?;

// Verify the signature
signer.verify(message, &public_key, &signature)?;
§Security Best Practices | 安全最佳实践

When using the wrapper:

  1. Protect Private Keys: Keep private keys secure and confidential
  2. Verify Signatures: Always verify signatures before trusting data
  3. Use Fresh Keys: Generate new keys for different purposes
  4. Hash Messages: For large messages, hash before signing

使用包装器时:

  1. 保护私钥: 保持私钥安全和机密
  2. 验证签名: 在信任数据之前始终验证签名
  3. 使用新密钥: 为不同目的生成新密钥
  4. 哈希消息: 对于大消息,签名前先哈希
§Algorithm-Specific Notes | 算法特定注意事项
  • Ed25519: Deterministic signatures, no additional randomness needed

  • ECDSA P-256: Requires high-quality randomness for each signature

  • Dilithium: Post-quantum secure, larger keys and signatures

  • Ed25519: 确定性签名,不需要额外的随机性

  • ECDSA P-256: 每个签名都需要高质量的随机性

  • Dilithium: 后量子安全,更大的密钥和签名

Trait Implementations§

Source§

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

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 SignatureAlgorithm

Source§

fn clone(&self) -> SignatureAlgorithm

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 SignatureAlgorithm

Source§

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

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

impl<__Context> Decode<__Context> for SignatureAlgorithm

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 SignatureAlgorithm

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 SignatureAlgorithm

Source§

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

Encode a given type.
Source§

impl From<SignatureAlgorithm> for SignatureAlgorithmWrapper

Source§

fn from(value: SignatureAlgorithm) -> Self

Converts to this type from the input type.
Source§

impl Hash for SignatureAlgorithm

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 SignatureAlgorithm

Source§

fn eq(&self, other: &SignatureAlgorithm) -> 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 SignatureAlgorithm

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 SignatureAlgorithm

Source§

impl Eq for SignatureAlgorithm

Source§

impl StructuralPartialEq for SignatureAlgorithm

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