Module crypto::sha2 [−][src]
An implementation of the SHA-2 cryptographic hash algorithms.
There are 6 standard algorithms specified in the SHA-2 standard:
Sha224
, which is the 32-bitSha256
algorithm with the result truncated to 224 bits.Sha256
, which is the 32-bitSha256
algorithm.Sha384
, which is the 64-bitSha512
algorithm with the result truncated to 384 bits.Sha512
, which is the 64-bitSha512
algorithm.Sha512Trunc224
, which is the 64-bitSha512
algorithm with the result truncated to 224 bits.Sha512Trunc256
, which is the 64-bitSha512
algorithm with the result truncated to 256 bits.
Algorithmically, there are only 2 core algorithms: Sha256
and Sha512
.
All other algorithms are just applications of these with different initial hash
values, and truncated to different digest bit lengths.
Usage
An example of using Sha256
is:
use self::crypto::digest::Digest; use self::crypto::sha2::Sha256; // create a Sha256 object let mut hasher = Sha256::new(); // write input message hasher.input_str("hello world"); // read hash digest let hex = hasher.result_str(); assert_eq!(hex, concat!("b94d27b9934d3e08a52e52d7da7dabfa", "c484efe37a5380ee9088f7ace2efcde9"));
An example of using Sha512
is:
use self::crypto::digest::Digest; use self::crypto::sha2::Sha512; // create a Sha512 object let mut hasher = Sha512::new(); // write input message hasher.input_str("hello world"); // read hash digest let hex = hasher.result_str(); assert_eq!(hex, concat!("309ecc489c12d6eb4cc40f50c902f2b4", "d0ed77ee511a7c7a9bcd3ca86d4cd86f", "989dd35bc5ff499670da34255b45b0cf", "d830e81f605dcf7dc5542e93ae9cd76f"));
Structs
Sha224 |
The SHA-256 hash algorithm with the SHA-224 initial hash value. The result is truncated to 224 bits. |
Sha256 |
The SHA-256 hash algorithm with the SHA-256 initial hash value. |
Sha384 |
The SHA-512 hash algorithm with the SHA-384 initial hash value. The result is truncated to 384 bits. |
Sha512 |
The SHA-512 hash algorithm with the SHA-512 initial hash value. |
Sha512Trunc224 |
The SHA-512 hash algorithm with the SHA-512/224 initial hash value. The result is truncated to 224 bits. |
Sha512Trunc256 |
The SHA-512 hash algorithm with the SHA-512/256 initial hash value. The result is truncated to 256 bits. |
Constants
K32 |
Constants necessary for SHA-256 family of digests. |
K64 |
Constants necessary for SHA-512 family of digests. |
K32X4 |
Constants necessary for SHA-256 family of digests. |
K64X2 |
Constants necessary for SHA-512 family of digests. |
Functions
sha256_digest_block |
Process a block with the SHA-256 algorithm. (See more...) |
sha256_digest_block_u32 |
Process a block with the SHA-256 algorithm. |
sha256_digest_round_x2 |
Emulates |
sha256_schedule_x4 |
Performs 4 rounds of the SHA-256 message schedule update. |
sha512_digest_block |
Process a block with the SHA-512 algorithm. (See more...) |
sha512_digest_block_u64 |
Process a block with the SHA-512 algorithm. |
sha512_digest_round |
Performs one round of the SHA-512 message block digest. |
sha512_schedule_x2 |
Performs 2 rounds of the SHA-512 message schedule update. |