pub enum HashAlgorithm {
Sha256,
Sha384,
Sha512,
}
Expand description
Hash algorithm enumeration for cryptographic operations.
用于密码操作的哈希算法枚举。
§Overview | 概述
This enum represents the supported hash algorithms used in various cryptographic constructions such as HMAC, digital signatures, and key derivation functions.
此枚举表示在各种密码构造中使用的支持的哈希算法, 如 HMAC、数字签名和密钥派生函数。
§Security Properties | 安全属性
All included hash functions are cryptographically secure and provide:
- Collision resistance: Computationally infeasible to find two inputs with same hash
- Preimage resistance: Given a hash, infeasible to find the original input
- Second preimage resistance: Given an input, infeasible to find another with same hash
所有包含的哈希函数都是密码学安全的,并提供:
- 抗碰撞性: 计算上不可行找到具有相同哈希的两个输入
- 原像抗性: 给定哈希值,不可行找到原始输入
- 第二原像抗性: 给定输入,不可行找到另一个具有相同哈希的输入
§Algorithm Details | 算法详情
Algorithm | Output Size | Security Level | Performance | Use Cases |
---|---|---|---|---|
SHA-256 | 256 bits | 128-bit | High | General purpose, Bitcoin |
SHA-384 | 384 bits | 192-bit | Medium | High security applications |
SHA-512 | 512 bits | 256-bit | Medium | Maximum security, long-term |
§Usage Guidelines | 使用指南
-
SHA-256: Recommended for most applications, widely supported
-
SHA-384: Use when 192-bit security level is required
-
SHA-512: Use for maximum security or when working with 64-bit architectures
-
SHA-256: 推荐用于大多数应用,广泛支持
-
SHA-384: 需要 192 位安全级别时使用
-
SHA-512: 用于最大安全性或在 64 位架构上工作时使用
Variants§
Sha256
SHA-256 hash algorithm (256-bit output, 128-bit security).
SHA-256 哈希算法(256 位输出,128 位安全性)。
Most widely used and supported hash function. Suitable for general-purpose cryptographic applications including digital signatures, HMAC, and key derivation.
最广泛使用和支持的哈希函数。适用于通用密码应用, 包括数字签名、HMAC 和密钥派生。
Sha384
SHA-384 hash algorithm (384-bit output, 192-bit security).
SHA-384 哈希算法(384 位输出,192 位安全性)。
Provides higher security level than SHA-256. Recommended for applications requiring 192-bit security strength.
提供比 SHA-256 更高的安全级别。推荐用于需要 192 位安全强度的应用。
Sha512
SHA-512 hash algorithm (512-bit output, 256-bit security).
SHA-512 哈希算法(512 位输出,256 位安全性)。
Provides maximum security level. Recommended for long-term security requirements and high-value applications.
提供最大安全级别。推荐用于长期安全要求和高价值应用。
Implementations§
Source§impl HashAlgorithm
impl HashAlgorithm
Sourcepub fn build() -> HashAlgorithmBuilder
pub fn build() -> HashAlgorithmBuilder
Creates a new hash algorithm builder.
创建新的哈希算法构建器。
§Examples | 示例
use seal_crypto_wrapper::algorithms::hash::HashAlgorithm;
let algorithm = HashAlgorithm::build().sha256();
Source§impl HashAlgorithm
impl HashAlgorithm
Sourcepub fn into_wrapper(self) -> HashAlgorithmWrapper
pub fn into_wrapper(self) -> HashAlgorithmWrapper
Converts the algorithm enum into a concrete wrapper implementation.
将算法枚举转换为具体的包装器实现。
§Purpose | 目的
This method bridges the gap between algorithm selection and actual cryptographic operations. It returns a wrapper that implements the hash algorithm trait.
此方法在算法选择和实际密码操作之间架起桥梁。 它返回一个实现哈希算法 trait 的包装器。
§Returns | 返回值
A HashAlgorithmWrapper
that can perform:
- Hashing
- HMAC computation
可以执行以下操作的 HashAlgorithmWrapper
:
- 哈希计算
- HMAC 计算
§Examples | 示例
use seal_crypto_wrapper::algorithms::hash::HashAlgorithm;
let algorithm = HashAlgorithm::build().sha256();
let hasher = algorithm.into_wrapper();
// Now you can use the hasher
let digest = hasher.hash(b"hello world");
Trait Implementations§
Source§impl<'__de, __Context> BorrowDecode<'__de, __Context> for HashAlgorithm
impl<'__de, __Context> BorrowDecode<'__de, __Context> for HashAlgorithm
Source§fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>(
decoder: &mut __D,
) -> Result<Self, DecodeError>
fn borrow_decode<__D: BorrowDecoder<'__de, Context = __Context>>( decoder: &mut __D, ) -> Result<Self, DecodeError>
Source§impl Clone for HashAlgorithm
impl Clone for HashAlgorithm
Source§fn clone(&self) -> HashAlgorithm
fn clone(&self) -> HashAlgorithm
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more