1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
//! 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-bit `Sha256` algorithm with the result truncated //! to 224 bits. //! * `Sha256`, which is the 32-bit `Sha256` algorithm. //! * `Sha384`, which is the 64-bit `Sha512` algorithm with the result truncated //! to 384 bits. //! * `Sha512`, which is the 64-bit `Sha512` algorithm. //! * `Sha512Trunc224`, which is the 64-bit `Sha512` algorithm with the result //! truncated to 224 bits. //! * `Sha512Trunc256`, which is the 64-bit `Sha512` 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: //! //! ```rust //! use sha2::{Sha256, Digest}; //! //! // create a Sha256 object //! let mut hasher = Sha256::new(); //! //! // write input message //! hasher.input(b"hello world"); //! //! // read hash digest and consume hasher //! let output = hasher.result(); //! //! assert_eq!(output[..], [0xb9, 0x4d, 0x27, 0xb9, 0x93, 0x4d, 0x3e, 0x08, //! 0xa5, 0x2e, 0x52, 0xd7, 0xda, 0x7d, 0xab, 0xfa, //! 0xc4, 0x84, 0xef, 0xe3, 0x7a, 0x53, 0x80, 0xee, //! 0x90, 0x88, 0xf7, 0xac, 0xe2, 0xef, 0xcd, 0xe9]); //! ``` //! //! An example of using `Sha512` is: //! //! ```rust //! use sha2::{Sha512, Digest}; //! //! // create a Sha512 object //! let mut hasher = Sha512::new(); //! //! // write input message //! hasher.input(b"hello world"); //! //! // read hash digest and consume hasher //! let output = hasher.result(); //! //! assert_eq!(output[..], [0x30, 0x9e, 0xcc, 0x48, 0x9c, 0x12, 0xd6, 0xeb, //! 0x4c, 0xc4, 0x0f, 0x50, 0xc9, 0x02, 0xf2, 0xb4, //! 0xd0, 0xed, 0x77, 0xee, 0x51, 0x1a, 0x7c, 0x7a, //! 0x9b, 0xcd, 0x3c, 0xa8, 0x6d, 0x4c, 0xd8, 0x6f, //! 0x98, 0x9d, 0xd3, 0x5b, 0xc5, 0xff, 0x49, 0x96, //! 0x70, 0xda, 0x34, 0x25, 0x5b, 0x45, 0xb0, 0xcf, //! 0xd8, 0x30, 0xe8, 0x1f, 0x60, 0x5d, 0xcf, 0x7d, //! 0xc5, 0x54, 0x2e, 0x93, 0xae, 0x9c, 0xd7, 0x6f][..]); //! ``` #![no_std] extern crate generic_array; extern crate byte_tools; extern crate digest; extern crate digest_buffer; extern crate fake_simd as simd; mod consts; mod sha256_utils; mod sha512_utils; mod sha256; mod sha512; pub use digest::Digest; pub use sha256::{Sha256, Sha224}; pub use sha512::{Sha512, Sha384, Sha512Trunc224, Sha512Trunc256};