diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /vendor/sha-1-0.8.2 | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/sha-1-0.8.2')
-rw-r--r-- | vendor/sha-1-0.8.2/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/Cargo.lock | 148 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/Cargo.toml | 58 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/LICENSE-APACHE | 201 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/LICENSE-MIT | 27 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/benches/lib.rs | 7 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/examples/sha1sum.rs | 49 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/src/aarch64.rs | 9 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/src/consts.rs | 19 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/src/lib.rs | 141 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/src/utils.rs | 300 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/tests/data/one_million_a.bin | 1 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/tests/data/sha1.blb | 1 | ||||
-rw-r--r-- | vendor/sha-1-0.8.2/tests/lib.rs | 14 |
14 files changed, 976 insertions, 0 deletions
diff --git a/vendor/sha-1-0.8.2/.cargo-checksum.json b/vendor/sha-1-0.8.2/.cargo-checksum.json new file mode 100644 index 000000000..4c2a775dd --- /dev/null +++ b/vendor/sha-1-0.8.2/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"Cargo.lock":"cb91ffff371524a65d00a6d075e7d94d01f253393661058750217edc1005b76e","Cargo.toml":"80517f782161bae604f15650e2ef9ddbfd4c25c68a61d023e183483412bce8dd","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"b4eb00df6e2a4d22518fcaa6a2b4646f249b3a3c9814509b22bd2091f1392ff1","benches/lib.rs":"a37a0e99c673a3049d4ffa229eb1b3e1a3006f611a76b881f12440fcb075c361","examples/sha1sum.rs":"3b52d8ba4cc4271d3111b5cb578095761eab7ded2fede3c498d11eaf68a120b8","src/aarch64.rs":"150de941565333e50edb5b156e9448ce613621fac0660f6ed114d061ab97be6a","src/consts.rs":"b4346e3e6d28ad3f0a24cc199ebc73784466202a2cab09dfc938c14a41d5b4b2","src/lib.rs":"31e1c136ed0e41bf83fc5b32e8a456b89b556e541c3fe3fd78c9284a78bf7930","src/utils.rs":"a38e6d9df1994357f292c846e9fce3026bc02374fae8cbca18b9884e8a4759c6","tests/data/one_million_a.bin":"e53c99dcb3ee1436b1c01e53799a07891009be5cdb244133e5eda0ec56d7233a","tests/data/sha1.blb":"b620d6ab76fd26fea6b7be1be720652926b6cea9901a294ff8ba855666ddf19a","tests/lib.rs":"adce369751e6faab77582c03436abcd7dae816843501e1c63cbfd72942b76100"},"package":"f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df"}
\ No newline at end of file diff --git a/vendor/sha-1-0.8.2/Cargo.lock b/vendor/sha-1-0.8.2/Cargo.lock new file mode 100644 index 000000000..cef4543a0 --- /dev/null +++ b/vendor/sha-1-0.8.2/Cargo.lock @@ -0,0 +1,148 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "blobby" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fe5f8c2940b65859ece4b3b2ba02d2b12c87cab455fd42dee2556a187bb2cf6" +dependencies = [ + "byteorder", +] + +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + +[[package]] +name = "byteorder" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" + +[[package]] +name = "cc" +version = "1.0.48" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f52a465a666ca3d838ebbf08b241383421412fe7ebb463527bba275526d89f76" + +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "blobby", + "generic-array", +] + +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + +[[package]] +name = "hex-literal" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc2928beef125e519d69ae1baa8c37ea2e0d3848545217f6db0179c5eb1d639" +dependencies = [ + "hex-literal-impl", + "proc-macro-hack", +] + +[[package]] +name = "hex-literal-impl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "520870c3213943eb8d7803e80180d12a6c7ceb4ae74602544529d1643dc4ddda" +dependencies = [ + "proc-macro-hack", +] + +[[package]] +name = "libc" +version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" + +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + +[[package]] +name = "proc-macro-hack" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "463bf29e7f11344e58c9e01f171470ab15c925c6822ad75028cc1c0e1d1eb63b" +dependencies = [ + "proc-macro-hack-impl", +] + +[[package]] +name = "proc-macro-hack-impl" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c47dcb1594802de8c02f3b899e2018c78291168a22c281be21ea0fb4796842" + +[[package]] +name = "sha-1" +version = "0.8.2" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "hex-literal", + "libc", + "opaque-debug", + "sha1-asm", +] + +[[package]] +name = "sha1-asm" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9dae2289dd5f5dc67fb0f341a5676c5c197415c51ce7345ae1bd0d36a6cbbfc" +dependencies = [ + "cc", +] + +[[package]] +name = "typenum" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" diff --git a/vendor/sha-1-0.8.2/Cargo.toml b/vendor/sha-1-0.8.2/Cargo.toml new file mode 100644 index 000000000..a230700c7 --- /dev/null +++ b/vendor/sha-1-0.8.2/Cargo.toml @@ -0,0 +1,58 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +name = "sha-1" +version = "0.8.2" +authors = ["RustCrypto Developers"] +description = "SHA-1 hash function" +documentation = "https://docs.rs/sha-1" +keywords = ["crypto", "sha1", "hash", "digest"] +categories = ["cryptography", "no-std"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/RustCrypto/hashes" + +[lib] +name = "sha1" +[dependencies.block-buffer] +version = "0.7" + +[dependencies.digest] +version = "0.8" + +[dependencies.fake-simd] +version = "0.1" + +[dependencies.libc] +version = "0.2" +optional = true + +[dependencies.opaque-debug] +version = "0.2" + +[dependencies.sha1-asm] +version = "0.4" +optional = true +[dev-dependencies.digest] +version = "0.8" +features = ["dev"] + +[dev-dependencies.hex-literal] +version = "0.1" + +[features] +asm = ["sha1-asm"] +asm-aarch64 = ["asm", "libc"] +default = ["std"] +std = ["digest/std"] +[badges.travis-ci] +repository = "RustCrypto/hashes" diff --git a/vendor/sha-1-0.8.2/LICENSE-APACHE b/vendor/sha-1-0.8.2/LICENSE-APACHE new file mode 100644 index 000000000..78173fa2e --- /dev/null +++ b/vendor/sha-1-0.8.2/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/sha-1-0.8.2/LICENSE-MIT b/vendor/sha-1-0.8.2/LICENSE-MIT new file mode 100644 index 000000000..66cf75563 --- /dev/null +++ b/vendor/sha-1-0.8.2/LICENSE-MIT @@ -0,0 +1,27 @@ +Copyright (c) 2006-2009 Graydon Hoare +Copyright (c) 2009-2013 Mozilla Foundation +Copyright (c) 2016 Artyom Pavlov + +Permission is hereby granted, free of charge, to any +person obtaining a copy of this software and associated +documentation files (the "Software"), to deal in the +Software without restriction, including without +limitation the rights to use, copy, modify, merge, +publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software +is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice +shall be included in all copies or substantial portions +of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF +ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED +TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT +SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR +IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/vendor/sha-1-0.8.2/benches/lib.rs b/vendor/sha-1-0.8.2/benches/lib.rs new file mode 100644 index 000000000..e204e565a --- /dev/null +++ b/vendor/sha-1-0.8.2/benches/lib.rs @@ -0,0 +1,7 @@ +#![no_std] +#![feature(test)] +#[macro_use] +extern crate digest; +extern crate sha1; + +bench!(sha1::Sha1); diff --git a/vendor/sha-1-0.8.2/examples/sha1sum.rs b/vendor/sha-1-0.8.2/examples/sha1sum.rs new file mode 100644 index 000000000..bde1ab4f6 --- /dev/null +++ b/vendor/sha-1-0.8.2/examples/sha1sum.rs @@ -0,0 +1,49 @@ +extern crate sha1; + +use sha1::{Sha1, Digest}; +use std::env; +use std::fs; +use std::io::{self, Read}; + +const BUFFER_SIZE: usize = 1024; + +/// Print digest result as hex string and name pair +fn print_result(sum: &[u8], name: &str) { + for byte in sum { + print!("{:02x}", byte); + } + println!("\t{}", name); +} + +/// Compute digest value for given `Reader` and print it +/// On any error simply return without doing anything +fn process<D: Digest + Default, R: Read>(reader: &mut R, name: &str) { + let mut sh = D::default(); + let mut buffer = [0u8; BUFFER_SIZE]; + loop { + let n = match reader.read(&mut buffer) { + Ok(n) => n, + Err(_) => return, + }; + sh.input(&buffer[..n]); + if n == 0 || n < BUFFER_SIZE { + break; + } + } + print_result(&sh.result(), name); +} + +fn main() { + let args = env::args(); + // Process files listed in command line arguments one by one + // If no files provided process input from stdin + if args.len() > 1 { + for path in args.skip(1) { + if let Ok(mut file) = fs::File::open(&path) { + process::<Sha1, _>(&mut file, &path); + } + } + } else { + process::<Sha1, _>(&mut io::stdin(), "-"); + } +} diff --git a/vendor/sha-1-0.8.2/src/aarch64.rs b/vendor/sha-1-0.8.2/src/aarch64.rs new file mode 100644 index 000000000..d3cffecd7 --- /dev/null +++ b/vendor/sha-1-0.8.2/src/aarch64.rs @@ -0,0 +1,9 @@ +// TODO: Import those from libc, see https://github.com/rust-lang/libc/pull/1638 +const AT_HWCAP: u64 = 16; +const HWCAP_SHA1: u64 = 32; + +#[inline(always)] +pub fn sha1_supported() -> bool { + let hwcaps: u64 = unsafe { ::libc::getauxval(AT_HWCAP) }; + (hwcaps & HWCAP_SHA1) != 0 +} diff --git a/vendor/sha-1-0.8.2/src/consts.rs b/vendor/sha-1-0.8.2/src/consts.rs new file mode 100644 index 000000000..628d4d6e0 --- /dev/null +++ b/vendor/sha-1-0.8.2/src/consts.rs @@ -0,0 +1,19 @@ +#![cfg_attr(feature = "cargo-clippy", allow(unreadable_literal))] + +pub const STATE_LEN: usize = 5; + +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] +pub const BLOCK_LEN: usize = 16; + +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] +pub const K0: u32 = 0x5A827999u32; +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] +pub const K1: u32 = 0x6ED9EBA1u32; +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] +pub const K2: u32 = 0x8F1BBCDCu32; +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] +pub const K3: u32 = 0xCA62C1D6u32; + +pub const H: [u32; STATE_LEN] = [ + 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 +]; diff --git a/vendor/sha-1-0.8.2/src/lib.rs b/vendor/sha-1-0.8.2/src/lib.rs new file mode 100644 index 000000000..374c234c2 --- /dev/null +++ b/vendor/sha-1-0.8.2/src/lib.rs @@ -0,0 +1,141 @@ +//! An implementation of the [SHA-1][1] cryptographic hash algorithm. +//! +//! # Usage +//! +//! ```rust +//! # #[macro_use] extern crate hex_literal; +//! # extern crate sha1; +//! # fn main() { +//! use sha1::{Sha1, Digest}; +//! +//! // create a Sha1 object +//! let mut hasher = Sha1::new(); +//! +//! // process input message +//! hasher.input(b"hello world"); +//! +//! // acquire hash digest in the form of GenericArray, +//! // which in this case is equivalent to [u8; 20] +//! let result = hasher.result(); +//! assert_eq!(result[..], hex!("2aae6c35c94fcfb415dbe95f408b9ce91ee846ed")); +//! # } +//! ``` +//! +//! Also see [RustCrypto/hashes][2] readme. +//! +//! [1]: https://en.wikipedia.org/wiki/SHA-1 +//! [2]: https://github.com/RustCrypto/hashes +#![no_std] +#![doc(html_logo_url = + "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] + +// Give relevant error messages if the user tries to enable AArch64 asm on unsupported platforms. +#[cfg(all(feature = "asm-aarch64", target_arch = "aarch64", not(target_os = "linux")))] +compile_error!("Your OS isn’t yet supported for runtime-checking of AArch64 features."); +#[cfg(all(feature = "asm-aarch64", target_os = "linux", not(target_arch = "aarch64")))] +compile_error!("Enable the \"asm\" feature instead of \"asm-aarch64\" on non-AArch64 Linux systems."); +#[cfg(all(not(feature = "asm-aarch64"), feature = "asm", target_arch = "aarch64", target_os = "linux"))] +compile_error!("Enable the \"asm-aarch64\" feature on AArch64 if you want to use asm."); + +extern crate block_buffer; +#[macro_use] extern crate opaque_debug; +#[macro_use] pub extern crate digest; +#[cfg(feature = "std")] +extern crate std; +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] +extern crate fake_simd as simd; +#[cfg(feature = "asm-aarch64")] +extern crate libc; + +#[cfg(feature = "asm")] +extern crate sha1_asm; +#[cfg(all(feature = "asm", not(feature = "asm-aarch64")))] +#[inline(always)] +fn compress(state: &mut [u32; 5], block: &GenericArray<u8, U64>) { + let block: &[u8; 64] = unsafe { core::mem::transmute(block) }; + sha1_asm::compress(state, block); +} +#[cfg(feature = "asm-aarch64")] +mod aarch64; +#[cfg(feature = "asm-aarch64")] +#[inline(always)] +fn compress(state: &mut [u32; 5], block: &GenericArray<u8, U64>) { + // TODO: Replace this platform-specific call with is_aarch64_feature_detected!("sha1") once + // that macro is stabilised and https://github.com/rust-lang/rfcs/pull/2725 is implemented + // to let us use it on no_std. + if aarch64::sha1_supported() { + let block: &[u8; 64] = unsafe { core::mem::transmute(block) }; + sha1_asm::compress(state, block); + } else { + utils::compress(state, block); + } +} + +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] +mod utils; +#[cfg(not(feature = "asm"))] +use utils::compress; + +pub use digest::Digest; +use digest::{Input, BlockInput, FixedOutput, Reset}; +use digest::generic_array::GenericArray; +use digest::generic_array::typenum::{U20, U64}; +use block_buffer::BlockBuffer; +use block_buffer::byteorder::{BE, ByteOrder}; + +mod consts; +use consts::{STATE_LEN, H}; + +/// Structure representing the state of a SHA-1 computation +#[derive(Clone)] +pub struct Sha1 { + h: [u32; STATE_LEN], + len: u64, + buffer: BlockBuffer<U64>, +} + +impl Default for Sha1 { + fn default() -> Self { + Sha1{ h: H, len: 0u64, buffer: Default::default() } + } +} + +impl BlockInput for Sha1 { + type BlockSize = U64; +} + +impl Input for Sha1 { + fn input<B: AsRef<[u8]>>(&mut self, input: B) { + let input = input.as_ref(); + // Assumes that `length_bits<<3` will not overflow + self.len += input.len() as u64; + let state = &mut self.h; + self.buffer.input(input, |d| compress(state, d)); + } +} + +impl FixedOutput for Sha1 { + type OutputSize = U20; + + fn fixed_result(mut self) -> GenericArray<u8, Self::OutputSize> { + { + let state = &mut self.h; + let l = self.len << 3; + self.buffer.len64_padding::<BE, _>(l, |d| compress(state, d)); + } + let mut out = GenericArray::default(); + BE::write_u32_into(&self.h,&mut out); + out + } +} + +impl Reset for Sha1 { + fn reset(&mut self) { + self.h = H; + self.len = 0; + self.buffer.reset(); + } +} + +impl_opaque_debug!(Sha1); +impl_write!(Sha1); diff --git a/vendor/sha-1-0.8.2/src/utils.rs b/vendor/sha-1-0.8.2/src/utils.rs new file mode 100644 index 000000000..e8b941a6e --- /dev/null +++ b/vendor/sha-1-0.8.2/src/utils.rs @@ -0,0 +1,300 @@ +#![cfg_attr(feature = "cargo-clippy", allow(many_single_char_names))] + +use consts::{BLOCK_LEN, K0, K1, K2, K3}; +use block_buffer::byteorder::{BE, ByteOrder}; +use simd::u32x4; +use digest::generic_array::GenericArray; +use digest::generic_array::typenum::U64; + +type Block = GenericArray<u8, U64>; + +/// Not an intrinsic, but gets the first element of a vector. +#[inline] +pub fn sha1_first(w0: u32x4) -> u32 { + w0.0 +} + +/// Not an intrinsic, but adds a word to the first element of a vector. +#[inline] +pub fn sha1_first_add(e: u32, w0: u32x4) -> u32x4 { + let u32x4(a, b, c, d) = w0; + u32x4(e.wrapping_add(a), b, c, d) +} + +/// Emulates `llvm.x86.sha1msg1` intrinsic. +fn sha1msg1(a: u32x4, b: u32x4) -> u32x4 { + let u32x4(_, _, w2, w3) = a; + let u32x4(w4, w5, _, _) = b; + a ^ u32x4(w2, w3, w4, w5) +} + +/// Emulates `llvm.x86.sha1msg2` intrinsic. +fn sha1msg2(a: u32x4, b: u32x4) -> u32x4 { + let u32x4(x0, x1, x2, x3) = a; + let u32x4(_, w13, w14, w15) = b; + + let w16 = (x0 ^ w13).rotate_left(1); + let w17 = (x1 ^ w14).rotate_left(1); + let w18 = (x2 ^ w15).rotate_left(1); + let w19 = (x3 ^ w16).rotate_left(1); + + u32x4(w16, w17, w18, w19) +} + +/// Performs 4 rounds of the message schedule update. +/* +pub fn sha1_schedule_x4(v0: u32x4, v1: u32x4, v2: u32x4, v3: u32x4) -> u32x4 { + sha1msg2(sha1msg1(v0, v1) ^ v2, v3) +} +*/ + +/// Emulates `llvm.x86.sha1nexte` intrinsic. +#[inline] +fn sha1_first_half(abcd: u32x4, msg: u32x4) -> u32x4 { + sha1_first_add(sha1_first(abcd).rotate_left(30), msg) +} + +/// Emulates `llvm.x86.sha1rnds4` intrinsic. +/// Performs 4 rounds of the message block digest. +fn sha1_digest_round_x4(abcd: u32x4, work: u32x4, i: i8) -> u32x4 { + const K0V: u32x4 = u32x4(K0, K0, K0, K0); + const K1V: u32x4 = u32x4(K1, K1, K1, K1); + const K2V: u32x4 = u32x4(K2, K2, K2, K2); + const K3V: u32x4 = u32x4(K3, K3, K3, K3); + + match i { + 0 => sha1rnds4c(abcd, work + K0V), + 1 => sha1rnds4p(abcd, work + K1V), + 2 => sha1rnds4m(abcd, work + K2V), + 3 => sha1rnds4p(abcd, work + K3V), + _ => unreachable!("unknown icosaround index"), + } +} + +/// Not an intrinsic, but helps emulate `llvm.x86.sha1rnds4` intrinsic. +fn sha1rnds4c(abcd: u32x4, msg: u32x4) -> u32x4 { + let u32x4(mut a, mut b, mut c, mut d) = abcd; + let u32x4(t, u, v, w) = msg; + let mut e = 0u32; + + macro_rules! bool3ary_202 { + ($a:expr, $b:expr, $c:expr) => ($c ^ ($a & ($b ^ $c))) + } // Choose, MD5F, SHA1C + + e = e.wrapping_add(a.rotate_left(5)) + .wrapping_add(bool3ary_202!(b, c, d)) + .wrapping_add(t); + b = b.rotate_left(30); + + d = d.wrapping_add(e.rotate_left(5)) + .wrapping_add(bool3ary_202!(a, b, c)) + .wrapping_add(u); + a = a.rotate_left(30); + + c = c.wrapping_add(d.rotate_left(5)) + .wrapping_add(bool3ary_202!(e, a, b)) + .wrapping_add(v); + e = e.rotate_left(30); + + b = b.wrapping_add(c.rotate_left(5)) + .wrapping_add(bool3ary_202!(d, e, a)) + .wrapping_add(w); + d = d.rotate_left(30); + + u32x4(b, c, d, e) +} + +/// Not an intrinsic, but helps emulate `llvm.x86.sha1rnds4` intrinsic. +fn sha1rnds4p(abcd: u32x4, msg: u32x4) -> u32x4 { + let u32x4(mut a, mut b, mut c, mut d) = abcd; + let u32x4(t, u, v, w) = msg; + let mut e = 0u32; + + macro_rules! bool3ary_150 { + ($a:expr, $b:expr, $c:expr) => ($a ^ $b ^ $c) + } // Parity, XOR, MD5H, SHA1P + + e = e.wrapping_add(a.rotate_left(5)) + .wrapping_add(bool3ary_150!(b, c, d)) + .wrapping_add(t); + b = b.rotate_left(30); + + d = d.wrapping_add(e.rotate_left(5)) + .wrapping_add(bool3ary_150!(a, b, c)) + .wrapping_add(u); + a = a.rotate_left(30); + + c = c.wrapping_add(d.rotate_left(5)) + .wrapping_add(bool3ary_150!(e, a, b)) + .wrapping_add(v); + e = e.rotate_left(30); + + b = b.wrapping_add(c.rotate_left(5)) + .wrapping_add(bool3ary_150!(d, e, a)) + .wrapping_add(w); + d = d.rotate_left(30); + + u32x4(b, c, d, e) +} + +/// Not an intrinsic, but helps emulate `llvm.x86.sha1rnds4` intrinsic. +fn sha1rnds4m(abcd: u32x4, msg: u32x4) -> u32x4 { + let u32x4(mut a, mut b, mut c, mut d) = abcd; + let u32x4(t, u, v, w) = msg; + let mut e = 0u32; + + macro_rules! bool3ary_232 { + ($a:expr, $b:expr, $c:expr) => (($a & $b) ^ ($a & $c) ^ ($b & $c)) + } // Majority, SHA1M + + e = e.wrapping_add(a.rotate_left(5)) + .wrapping_add(bool3ary_232!(b, c, d)) + .wrapping_add(t); + b = b.rotate_left(30); + + d = d.wrapping_add(e.rotate_left(5)) + .wrapping_add(bool3ary_232!(a, b, c)) + .wrapping_add(u); + a = a.rotate_left(30); + + c = c.wrapping_add(d.rotate_left(5)) + .wrapping_add(bool3ary_232!(e, a, b)) + .wrapping_add(v); + e = e.rotate_left(30); + + b = b.wrapping_add(c.rotate_left(5)) + .wrapping_add(bool3ary_232!(d, e, a)) + .wrapping_add(w); + d = d.rotate_left(30); + + u32x4(b, c, d, e) +} + +/// Process a block with the SHA-1 algorithm. +fn sha1_digest_block_u32(state: &mut [u32; 5], block: &[u32; 16]) { + + macro_rules! schedule { + ($v0:expr, $v1:expr, $v2:expr, $v3:expr) => ( + sha1msg2(sha1msg1($v0, $v1) ^ $v2, $v3) + ) + } + + macro_rules! rounds4 { + ($h0:ident, $h1:ident, $wk:expr, $i:expr) => ( + sha1_digest_round_x4($h0, sha1_first_half($h1, $wk), $i) + ) + } + + // Rounds 0..20 + // TODO: replace with `u32x4::load` + let mut h0 = u32x4(state[0], state[1], state[2], state[3]); + let mut w0 = u32x4(block[0], block[1], block[2], block[3]); + let mut h1 = sha1_digest_round_x4(h0, sha1_first_add(state[4], w0), 0); + let mut w1 = u32x4(block[4], block[5], block[6], block[7]); + h0 = rounds4!(h1, h0, w1, 0); + let mut w2 = u32x4(block[8], block[9], block[10], block[11]); + h1 = rounds4!(h0, h1, w2, 0); + let mut w3 = u32x4(block[12], block[13], block[14], block[15]); + h0 = rounds4!(h1, h0, w3, 0); + let mut w4 = schedule!(w0, w1, w2, w3); + h1 = rounds4!(h0, h1, w4, 0); + + // Rounds 20..40 + w0 = schedule!(w1, w2, w3, w4); + h0 = rounds4!(h1, h0, w0, 1); + w1 = schedule!(w2, w3, w4, w0); + h1 = rounds4!(h0, h1, w1, 1); + w2 = schedule!(w3, w4, w0, w1); + h0 = rounds4!(h1, h0, w2, 1); + w3 = schedule!(w4, w0, w1, w2); + h1 = rounds4!(h0, h1, w3, 1); + w4 = schedule!(w0, w1, w2, w3); + h0 = rounds4!(h1, h0, w4, 1); + + // Rounds 40..60 + w0 = schedule!(w1, w2, w3, w4); + h1 = rounds4!(h0, h1, w0, 2); + w1 = schedule!(w2, w3, w4, w0); + h0 = rounds4!(h1, h0, w1, 2); + w2 = schedule!(w3, w4, w0, w1); + h1 = rounds4!(h0, h1, w2, 2); + w3 = schedule!(w4, w0, w1, w2); + h0 = rounds4!(h1, h0, w3, 2); + w4 = schedule!(w0, w1, w2, w3); + h1 = rounds4!(h0, h1, w4, 2); + + // Rounds 60..80 + w0 = schedule!(w1, w2, w3, w4); + h0 = rounds4!(h1, h0, w0, 3); + w1 = schedule!(w2, w3, w4, w0); + h1 = rounds4!(h0, h1, w1, 3); + w2 = schedule!(w3, w4, w0, w1); + h0 = rounds4!(h1, h0, w2, 3); + w3 = schedule!(w4, w0, w1, w2); + h1 = rounds4!(h0, h1, w3, 3); + w4 = schedule!(w0, w1, w2, w3); + h0 = rounds4!(h1, h0, w4, 3); + + let e = sha1_first(h1).rotate_left(30); + let u32x4(a, b, c, d) = h0; + + state[0] = state[0].wrapping_add(a); + state[1] = state[1].wrapping_add(b); + state[2] = state[2].wrapping_add(c); + state[3] = state[3].wrapping_add(d); + state[4] = state[4].wrapping_add(e); +} + +/// Process a block with the SHA-1 algorithm. (See more...) +/// +/// SHA-1 is a cryptographic hash function, and as such, it operates +/// on an arbitrary number of bytes. This function operates on a fixed +/// number of bytes. If you call this function with anything other than +/// 64 bytes, then it will panic! This function takes two arguments: +/// +/// * `state` is reference to an **array** of 5 words. +/// * `block` is reference to a **slice** of 64 bytes. +/// +/// If you want the function that performs a message digest on an arbitrary +/// number of bytes, then see also the `Sha1` struct above. +/// +/// # Implementation +/// +/// First, some background. Both ARM and Intel are releasing documentation +/// that they plan to include instruction set extensions for SHA1 and SHA256 +/// sometime in the near future. Second, LLVM won't lower these intrinsics yet, +/// so these functions were written emulate these instructions. Finally, +/// the block function implemented with these emulated intrinsics turned out +/// to be quite fast! What follows is a discussion of this CPU-level view +/// of the SHA-1 algorithm and how it relates to the mathematical definition. +/// +/// The SHA instruction set extensions can be divided up into two categories: +/// +/// * message work schedule update calculation ("schedule" v., "work" n.) +/// * message block 80-round digest calculation ("digest" v., "block" n.) +/// +/// The schedule-related functions can be used to easily perform 4 rounds +/// of the message work schedule update calculation, as shown below: +/// +/// ```ignore +/// macro_rules! schedule_x4 { +/// ($v0:expr, $v1:expr, $v2:expr, $v3:expr) => ( +/// sha1msg2(sha1msg1($v0, $v1) ^ $v2, $v3) +/// ) +/// } +/// +/// macro_rules! round_x4 { +/// ($h0:ident, $h1:ident, $wk:expr, $i:expr) => ( +/// sha1rnds4($h0, sha1_first_half($h1, $wk), $i) +/// ) +/// } +/// ``` +/// +/// and also shown above is how the digest-related functions can be used to +/// perform 4 rounds of the message block digest calculation. +/// +pub fn compress(state: &mut [u32; 5], block: &Block) { + let mut block_u32 = [0u32; BLOCK_LEN]; + BE::read_u32_into(block, &mut block_u32[..]); + sha1_digest_block_u32(state, &block_u32); +} diff --git a/vendor/sha-1-0.8.2/tests/data/one_million_a.bin b/vendor/sha-1-0.8.2/tests/data/one_million_a.bin new file mode 100644 index 000000000..0c759d80f --- /dev/null +++ b/vendor/sha-1-0.8.2/tests/data/one_million_a.bin @@ -0,0 +1 @@ +4<ڤ+ۭ'1e4o
\ No newline at end of file diff --git a/vendor/sha-1-0.8.2/tests/data/sha1.blb b/vendor/sha-1-0.8.2/tests/data/sha1.blb new file mode 100644 index 000000000..13ae2df26 --- /dev/null +++ b/vendor/sha-1-0.8.2/tests/data/sha1.blb @@ -0,0 +1 @@ +blobby1abc>6Gj>%qxPl؝8abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq>D;nJQ)Fp+The quick brown fox jumps over the lazy dog/z-(턞v9+The quick brown fox jumps over the lazy cogޟ,^:Z}
\ No newline at end of file diff --git a/vendor/sha-1-0.8.2/tests/lib.rs b/vendor/sha-1-0.8.2/tests/lib.rs new file mode 100644 index 000000000..348684b1f --- /dev/null +++ b/vendor/sha-1-0.8.2/tests/lib.rs @@ -0,0 +1,14 @@ +#![no_std] +#[macro_use] +extern crate digest; +extern crate sha1; + +use digest::dev::{one_million_a, digest_test}; + +new_test!(sha1_main, "sha1", sha1::Sha1, digest_test); + +#[test] +fn sha1_1million_a() { + let output = include_bytes!("data/one_million_a.bin"); + one_million_a::<sha1::Sha1>(output); +} |