Crate jisp_sha2

source ·
Expand description

§About

This crate contains my implementation of SHA256, SHA512 and their variants SHA224 and SHA384.

§Security

This implementation is just my personal project and has not been officially verified or audited. It should therefore not be used in any real-world applications, it is only meant for small personal projects such as mine.

§Usage

When using this crate it is important that you first preprocess your data which can be given in either string form or as a vector of u8 bytes. The algorithm will return a BigInt from the external crypto_bigint crate. If this is not your preferred data type there are functions in conversions to transform this output to a list of either u64 or u32 words.

§Example

use jisp_sha2::preprocessing::sha256_preprocessing;
use jisp_sha2::sha256::sha_256;
use crypto_bigint::U256;
 
let input_str = "abc";
 
let hex = sha256_preprocessing("abc");
let hash = sha_256(hex);
 
let expected = 
    U256::from_be_hex("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad");
assert_eq!(hash, expected);

Re-exports§

Modules§

  • A collection of constant words for each of the different SHA-2 variations To use the SHA-2 algorithm with different constants you can implement the Constants trait
  • Some functions to transform Uint integers into and from lists of u32 and u64 integers.
  • Functions for performing the standard preprocessing steps before applying the SHA-2 algorithm
  • simple functions for printing lists of bytes with spaces inbetween every 4 or 8 bytes
  • This is the SHA-256 Algorithm. You can use the standard implementations of sha_256 and sha_224 or you can use custom constants and initial hash values with sha256_internal
  • This is the SHA-512 Algorithm. You can use the standard implementations of sha_512 and sha_384 or you can use custom constants and initial hash values with sha512_internal