kryptos/hash
Types
Supported cryptographic hash algorithms.
pub type HashAlgorithm {
Blake2b
Blake2s
Md5
Sha1
Sha256
Sha384
Sha512
Sha512x224
Sha512x256
Sha3x224
Sha3x256
Sha3x384
Sha3x512
}
Constructors
-
Blake2bBLAKE2b (512-bit output)
-
Blake2sBLAKE2s (256-bit output)
-
Md5MD5 (128-bit output), cryptographically broken - use only for legacy compatibility.
-
Sha1SHA-1 (160-bit output)
-
Sha256SHA-256 (256-bit output)
-
Sha384SHA-384 (384-bit output)
-
Sha512SHA-512 (512-bit output)
-
Sha512x224SHA-512/224 (224-bit output), truncated SHA-512.
-
Sha512x256SHA-512/256 (256-bit output), truncated SHA-512.
-
Sha3x224SHA3-224 (224-bit output)
-
Sha3x256SHA3-256 (256-bit output)
-
Sha3x384SHA3-384 (384-bit output)
-
Sha3x512SHA3-512 (512-bit output)
Values
pub fn byte_size(algorithm: HashAlgorithm) -> Int
Returns the output size in bytes for a hash algorithm.
Parameters
algorithm: The hash algorithm to get the size for
Returns
The digest size in bytes.
pub fn final(hasher: Hasher) -> BitArray
Finalizes the hash computation and returns the digest.
After calling this function, the hasher should not be reused.
Parameters
hasher: The hasher to finalize
Returns
A BitArray containing the computed hash digest.
pub fn new(algorithm: HashAlgorithm) -> Result(Hasher, Nil)
Creates a new hasher for incremental hashing.
Use this when you need to hash data in chunks, such as when streaming or when the full input isn’t available at once.
Parameters
algorithm: The hash algorithm to use
Returns
Ok(Hasher)- A new hasher ready to accept input dataError(Nil)- If the hash algorithm is not supported by the runtime