Enum HashAlgorithm

Source
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 | 算法详情

AlgorithmOutput SizeSecurity LevelPerformanceUse Cases
SHA-256256 bits128-bitHighGeneral purpose, Bitcoin
SHA-384384 bits192-bitMediumHigh security applications
SHA-512512 bits256-bitMediumMaximum 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

Source

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

Source

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

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 HashAlgorithm

Source§

fn clone(&self) -> HashAlgorithm

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 HashAlgorithm

Source§

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

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

impl<__Context> Decode<__Context> for HashAlgorithm

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 HashAlgorithm

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 HashAlgorithm

Source§

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

Encode a given type.
Source§

impl From<HashAlgorithm> for HashAlgorithmWrapper

Source§

fn from(algorithm: HashAlgorithm) -> Self

Converts to this type from the input type.
Source§

impl Hash for HashAlgorithm

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 HashAlgorithm

Source§

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

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 HashAlgorithm

Source§

impl Eq for HashAlgorithm

Source§

impl StructuralPartialEq for HashAlgorithm

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