Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aienux/blob/main/vendor/sha2/src/lib.rs # aienux Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aienux / vendor / sha2 / src / lib.rs` 110 lines ยท 3559 bytes Raw Blame History 1 //! An implementation of the [SHA-2][1] cryptographic hash algorithms. 2 //! 3 //! There are 6 standard algorithms specified in the SHA-2 standard: [`Sha224`], 4 //! [`Sha256`], [`Sha512_224`], [`Sha512_256`], [`Sha384`], and [`Sha512`]. 5 //! 6 //! Algorithmically, there are only 2 core algorithms: SHA-256 and SHA-512. 7 //! All other algorithms are just applications of these with different initial 8 //! hash values, and truncated to different digest bit lengths. The first two 9 //! algorithms in the list are based on SHA-256, while the last four are based 10 //! on SHA-512. 11 //! 12 //! # Usage 13 //! 14 //! ## One-shot API 15 //! 16 //! ```rust 17 //! use hex_literal::hex; 18 //! use sha2::{Sha256, Digest}; 19 //! 20 //! let result = Sha256::digest(b"hello world"); 21 //! assert_eq!(result[..], hex!(" 22 //! `b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9` 23 //! ")[..]); 24 //! ``` 25 //! 26 //! ## Incremental API 27 //! 28 //! ```rust 29 //! use hex_literal::hex; 30 //! use sha2::{Sha256, Sha512, Digest}; 31 //! 32 //! // create a Sha256 object 33 //! let mut hasher = Sha256::new(); 34 //! 35 //! // write input message 36 //! hasher.update(b"hello world"); 37 //! 38 //! // read hash digest and consume hasher 39 //! let result = hasher.finalize(); 40 //! 41 //! assert_eq!(result[..], hex!(" 42 //! `b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9` 43 //! ")[..]); 44 //! 45 //! // same for Sha512 46 //! let mut hasher = Sha512::new(); 47 //! hasher.update(b"hello world"); 48 //! let result = hasher.finalize(); 49 //! 50 //! assert_eq!(result[..], hex!(" 51 //! `309ecc489c12d6eb4cc40f50c902f2b4d0ed77ee511a7c7a9bcd3ca86d4cd86f` 52 //! `989dd35bc5ff499670da34255b45b0cfd830e81f605dcf7dc5542e93ae9cd76f` 53 //! ")[..]); 54 //! ``` 55 //! 56 //! Also see [RustCrypto/hashes][2] readme. 57 //! 58 //! [1]: https://en.wikipedia.org/wiki/SHA-2 59 //! [2]: https://github.com/RustCrypto/hashes 60 61 #![no_std] 62 #![cfg_attr(docsrs, feature(doc_cfg))] 63 #![doc( 64 html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/`6ee8e381`/logo.svg", 65 html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/`6ee8e381`/logo.svg" 66 )] 67 #![warn(missing_docs, rust_2018_idioms)] 68 69 pub use digest::{self, Digest}; 70 71 #[cfg(feature = "oid")] 72 use digest::const_oid::{AssociatedOid, ObjectIdentifier}; 73 use digest::{ 74 consts::{U28, U32, U48, U64}, 75 core_api::{CoreWrapper, CtVariableCoreWrapper}, 76 impl_oid_carrier, 77 }; 78 79 #[rustfmt::skip] 80 mod consts; 81 mod core_api; 82 mod sha256; 83 mod sha512; 84 85 #[cfg(feature = "compress")] 86 pub use sha256::compress256; 87 #[cfg(feature = "compress")] 88 pub use sha512::compress512; 89 90 pub use core_api::{Sha256VarCore, Sha512VarCore}; 91 92 impl_oid_carrier!(OidSha256, "2.16.840.1.101.3.4.2.1"); 93 impl_oid_carrier!(OidSha384, "2.16.840.1.101.3.4.2.2"); 94 impl_oid_carrier!(OidSha512, "2.16.840.1.101.3.4.2.3"); 95 impl_oid_carrier!(OidSha224, "2.16.840.1.101.3.4.2.4"); 96 impl_oid_carrier!(OidSha512_224, "2.16.840.1.101.3.4.2.5"); 97 impl_oid_carrier!(OidSha512_256, "2.16.840.1.101.3.4.2.6"); 98 99 /// SHA-224 hasher. 100 pub type Sha224 = CoreWrapper>; 101 /// SHA-256 hasher. 102 pub type Sha256 = CoreWrapper>; 103 /// SHA-512/224 hasher. 104 pub type Sha512_224 = CoreWrapper>; 105 /// SHA-512/256 hasher. 106 pub type Sha512_256 = CoreWrapper>; 107 /// SHA-384 hasher. 108 pub type Sha384 = CoreWrapper>; 109 /// SHA-512 hasher. 110 pub type Sha512 = CoreWrapper>;