diff options
Diffstat (limited to 'rust/vendor/md-5')
-rw-r--r-- | rust/vendor/md-5/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | rust/vendor/md-5/CHANGELOG.md | 90 | ||||
-rw-r--r-- | rust/vendor/md-5/Cargo.toml | 59 | ||||
-rw-r--r-- | rust/vendor/md-5/LICENSE-APACHE | 201 | ||||
-rw-r--r-- | rust/vendor/md-5/LICENSE-MIT | 27 | ||||
-rw-r--r-- | rust/vendor/md-5/README.md | 72 | ||||
-rw-r--r-- | rust/vendor/md-5/benches/mod.rs | 14 | ||||
-rw-r--r-- | rust/vendor/md-5/src/compress.rs | 14 | ||||
-rw-r--r-- | rust/vendor/md-5/src/compress/loongarch64_asm.rs | 178 | ||||
-rw-r--r-- | rust/vendor/md-5/src/compress/soft.rs | 151 | ||||
-rw-r--r-- | rust/vendor/md-5/src/consts.rs | 18 | ||||
-rw-r--r-- | rust/vendor/md-5/src/lib.rs | 144 | ||||
-rw-r--r-- | rust/vendor/md-5/tests/data/md5.blb | bin | 0 -> 3271 bytes | |||
-rw-r--r-- | rust/vendor/md-5/tests/mod.rs | 15 |
14 files changed, 984 insertions, 0 deletions
diff --git a/rust/vendor/md-5/.cargo-checksum.json b/rust/vendor/md-5/.cargo-checksum.json new file mode 100644 index 0000000..748ff9e --- /dev/null +++ b/rust/vendor/md-5/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CHANGELOG.md":"11667f2f7ba0fca4a71350d13e2bf393c326cb0de87e723c8f10347cf2cb2052","Cargo.toml":"d6889f7a35144bad6b21ef85f3a6c19dc39a06dac08d0714a7465e0783e74fb7","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"b4eb00df6e2a4d22518fcaa6a2b4646f249b3a3c9814509b22bd2091f1392ff1","README.md":"23c2e70875a8ccdd29c0c7e929f1769dd8ae1f3e5be5dcd0a368f1d9fab1917b","benches/mod.rs":"10a5c151bf7b145838ab754013d49463e3123297778cfe275c95ebec28c4f7c9","src/compress.rs":"29475198d6212cbfa72a1c9c26f120f504fb2125ce1d452c1d1ff3436a6a825f","src/compress/loongarch64_asm.rs":"1369331db864c80dd03474fe2b3c48a791f515af27cf194292d183566bcf51a1","src/compress/soft.rs":"8ae6f2af517cb8d250b21f19edbc8c999dc3a34c0dfb42f16ad7c845a6111389","src/consts.rs":"d7fd1569a59b0cdde3aeef0fe2a2c0efc2bf11b2847d621d93e82b0396a06a3b","src/lib.rs":"8a717e53ad7840e4bd84bf67a658a5fe5a137f33a6240e8e5ff5e6f3deaf49b0","tests/data/md5.blb":"d32b41b81a906139c80f2bdf20920a547a5b5a6aaba2797fc2629665c42aaa47","tests/mod.rs":"b729eff5e20d0fee8da37aa101e6bc36919be11197350fffe2dc2b976f178f96"},"package":"d89e7ee0cfbedfc4da3340218492196241d89eefb6dab27de5df917a6d2e78cf"}
\ No newline at end of file diff --git a/rust/vendor/md-5/CHANGELOG.md b/rust/vendor/md-5/CHANGELOG.md new file mode 100644 index 0000000..65c30dd --- /dev/null +++ b/rust/vendor/md-5/CHANGELOG.md @@ -0,0 +1,90 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## 0.10.6 (2023-09-22) +### Added +- `asm!`-based backend for LoongArch64 targets gated behind `loongarch64_asm` feature [#505] + +[#505]: https://github.com/RustCrypto/hashes/pull/505 + +## 0.10.5 (2022-09-22) +### Added +- Feature-gated OID support ([#413]) + +[#413]: https://github.com/RustCrypto/hashes/pull/413 + +## 0.10.4 (2022-09-02) +### Fixed +- MSRV issue which was not resolved by v0.10.3 ([#401]) + +[#401]: https://github.com/RustCrypto/hashes/pull/401 + +## 0.10.3 (2022-09-02) +### Fixed +- MSRV issue caused by publishing v0.10.2 using a buggy Nightly toolchain ([#399]) + +[#399]: https://github.com/RustCrypto/hashes/pull/399 + +## 0.10.2 (2022-08-30) +### Changed +- Ignore `asm` feature on unsupported targets ([#388]) + +[#388]: https://github.com/RustCrypto/hashes/pull/388 + +## 0.10.1 (2022-02-17) +### Fixed +- Minimal versions build ([#363]) + +[#363]: https://github.com/RustCrypto/hashes/pull/363 + +## 0.10.0 (2021-12-07) +### Changed +- Update to `digest` v0.10 ([#217]) + +[#217]: https://github.com/RustCrypto/hashes/pull/217 + +## 0.9.1 (2020-06-28) +### Changed +- Update to `block-buffer` v0.9 ([#164]) +- Update to `opaque-debug` v0.3 ([#168]) + +[#164]: https://github.com/RustCrypto/hashes/pull/164 +[#168]: https://github.com/RustCrypto/hashes/pull/168 + +## 0.9.0 (2020-06-09) +### Changed +- Update to `digest` v0.9 release; MSRV 1.41+ ([#155]) +- Use new `*Dirty` traits from the `digest` crate ([#153]) +- Bump `block-buffer` to v0.8 release ([#151]) +- Rename `*result*` to `finalize` ([#148]) +- Update to Rust 2018 edition ([#128]) + +[#155]: https://github.com/RustCrypto/hashes/pull/155 +[#153]: https://github.com/RustCrypto/hashes/pull/153 +[#151]: https://github.com/RustCrypto/hashes/pull/151 +[#148]: https://github.com/RustCrypto/hashes/pull/148 +[#128]: https://github.com/RustCrypto/hashes/pull/128 + +## 0.8.0 (2018-10-02) + +## 0.7.0 (2017-11-15) + +## 0.5.2 (2017-06-13) + +## 0.5.1 (2017-06-13) + +## 0.5.0 (2017-06-12) + +## 0.4.4 (2017-06-02) + +## 0.4.3 (2017-05-09) + +## 0.4.2 (2017-05-02) + +## 0.4.1 (2017-04-18) + +## 0.4.0 (2017-04-06) diff --git a/rust/vendor/md-5/Cargo.toml b/rust/vendor/md-5/Cargo.toml new file mode 100644 index 0000000..40f618e --- /dev/null +++ b/rust/vendor/md-5/Cargo.toml @@ -0,0 +1,59 @@ +# 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 are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. + +[package] +edition = "2018" +name = "md-5" +version = "0.10.6" +authors = ["RustCrypto Developers"] +description = "MD5 hash function" +documentation = "https://docs.rs/md-5" +readme = "README.md" +keywords = [ + "crypto", + "md5", + "hash", + "digest", +] +categories = [ + "cryptography", + "no-std", +] +license = "MIT OR Apache-2.0" +repository = "https://github.com/RustCrypto/hashes" + +[lib] +name = "md5" + +[dependencies.cfg-if] +version = "1.0" + +[dependencies.digest] +version = "0.10.7" + +[dev-dependencies.digest] +version = "0.10.7" +features = ["dev"] + +[dev-dependencies.hex-literal] +version = "0.2.2" + +[features] +asm = ["md5-asm"] +default = ["std"] +force-soft = [] +loongarch64_asm = [] +oid = ["digest/oid"] +std = ["digest/std"] + +[target."cfg(any(target_arch = \"x86\", target_arch = \"x86_64\"))".dependencies.md5-asm] +version = "0.5" +optional = true diff --git a/rust/vendor/md-5/LICENSE-APACHE b/rust/vendor/md-5/LICENSE-APACHE new file mode 100644 index 0000000..78173fa --- /dev/null +++ b/rust/vendor/md-5/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/rust/vendor/md-5/LICENSE-MIT b/rust/vendor/md-5/LICENSE-MIT new file mode 100644 index 0000000..66cf755 --- /dev/null +++ b/rust/vendor/md-5/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/rust/vendor/md-5/README.md b/rust/vendor/md-5/README.md new file mode 100644 index 0000000..56af174 --- /dev/null +++ b/rust/vendor/md-5/README.md @@ -0,0 +1,72 @@ +# RustCrypto: MD5 + +[![crate][crate-image]][crate-link] +[![Docs][docs-image]][docs-link] +![Apache2/MIT licensed][license-image] +![Rust Version][rustc-image] +[![Project Chat][chat-image]][chat-link] +[![Build Status][build-image]][build-link] + +Pure Rust implementation of the [MD5 hash function][1]. + +[Documentation][docs-link] + +## ⚠️ Security Warning + +This crate is provided for the purposes of legacy interoperability with +protocols and systems which mandate the use of MD5. + +However, MD5 is [cryptographically broken and unsuitable for further use][2]. + +Collision attacks against MD5 are both practical and trivial, and +[theoretical attacks against MD5's preimage resistance have been found][3]. + +[RFC6151][4] advises no new IETF protocols can be designed MD5-based constructions, +including HMAC-MD5. + +## Minimum Supported Rust Version + +Rust **1.41** or higher. + +Minimum supported Rust version can be changed in the future, but it will be +done with a minor version bump. + +## SemVer Policy + +- All on-by-default features of this library are covered by SemVer +- MSRV is considered exempt from SemVer as noted above + +## License + +Licensed under either of: + + * [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) + * [MIT license](http://opensource.org/licenses/MIT) + +at your option. + +### Contribution + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall be +dual licensed as above, without any additional terms or conditions. + +[//]: # (badges) + +[crate-image]: https://img.shields.io/crates/v/md-5.svg +[crate-link]: https://crates.io/crates/md-5 +[docs-image]: https://docs.rs/md-5/badge.svg +[docs-link]: https://docs.rs/md-5/ +[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg +[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg +[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260041-hashes +[build-image]: https://github.com/RustCrypto/hashes/workflows/md5/badge.svg?branch=master +[build-link]: https://github.com/RustCrypto/hashes/actions?query=workflow%3Amd5 + +[//]: # (general links) + +[1]: https://en.wikipedia.org/wiki/MD5 +[2]: https://www.kb.cert.org/vuls/id/836068 +[3]: https://dl.acm.org/citation.cfm?id=1724151 +[4]: https://tools.ietf.org/html/rfc6151 diff --git a/rust/vendor/md-5/benches/mod.rs b/rust/vendor/md-5/benches/mod.rs new file mode 100644 index 0000000..7729eb7 --- /dev/null +++ b/rust/vendor/md-5/benches/mod.rs @@ -0,0 +1,14 @@ +#![feature(test)] +extern crate test; + +use digest::bench_update; +use md5::Md5; +use test::Bencher; + +bench_update!( + Md5::default(); + md5_10 10; + md5_100 100; + md5_1000 1000; + md5_10000 10000; +); diff --git a/rust/vendor/md-5/src/compress.rs b/rust/vendor/md-5/src/compress.rs new file mode 100644 index 0000000..c0bcd81 --- /dev/null +++ b/rust/vendor/md-5/src/compress.rs @@ -0,0 +1,14 @@ +cfg_if::cfg_if! { + if #[cfg(feature = "force-soft")] { + mod soft; + pub use soft::compress; + } else if #[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64")))] { + pub use md5_asm::compress; + } else if #[cfg(all(feature = "loongarch64_asm", target_arch = "loongarch64"))] { + mod loongarch64_asm; + pub use loongarch64_asm::compress; + } else { + mod soft; + pub use soft::compress; + } +} diff --git a/rust/vendor/md-5/src/compress/loongarch64_asm.rs b/rust/vendor/md-5/src/compress/loongarch64_asm.rs new file mode 100644 index 0000000..3bbd852 --- /dev/null +++ b/rust/vendor/md-5/src/compress/loongarch64_asm.rs @@ -0,0 +1,178 @@ +//! LoongArch64 assembly backend + +macro_rules! c { + ($($l:expr)*) => { + concat!($($l ,)*) + }; +} + +macro_rules! round0 { + ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => { + c!( + "xor $t4," $c "," $d ";" + "and $t4, $t4," $b ";" + "xor $t4, $t4," $d ";" + roundtail!($a, $b, $k, $s, $i) + ) + } +} + +macro_rules! round1 { + ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => { + c!( + "andn $t4," $c "," $d ";" + "and $t5," $d "," $b ";" + "or $t4, $t4, $t5;" + roundtail!($a, $b, $k, $s, $i) + ) + } +} + +macro_rules! round2 { + ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => { + c!( + "xor $t4," $c "," $d ";" + "xor $t4, $t4," $b ";" + roundtail!($a, $b, $k, $s, $i) + ) + } +} + +macro_rules! round3 { + ($a:literal, $b:literal, $c:literal, $d:literal, $k:literal, $s:literal, $i:literal) => { + c!( + "orn $t4," $b "," $d ";" + "xor $t4, $t4," $c ";" + roundtail!($a, $b, $k, $s, $i) + ) + } +} + +macro_rules! roundtail { + ($a:literal, $b:literal, $k:literal, $s:literal, $i:literal) => { + c!( + "ld.w $t5, $a3," $i " * 4;" + "ld.w $t6, $a1," $k " * 4;" + "add.w " $a "," $a ", $t5;" + "add.w " $a "," $a ", $t6;" + "add.w " $a "," $a ", $t4;" + "rotri.w " $a "," $a ", 32 -" $s ";" + "add.w " $a "," $a "," $b ";" + ) + } +} + +pub fn compress(state: &mut [u32; 4], blocks: &[[u8; 64]]) { + if blocks.is_empty() { + return; + } + + unsafe { + core::arch::asm!( + "42:", + + "move $t0, $a4", + "move $t1, $a5", + "move $t2, $a6", + "move $t3, $a7", + + /* 64 rounds of hashing */ + round0!("$t0", "$t1", "$t2", "$t3", 0, 7, 0), + round0!("$t3", "$t0", "$t1", "$t2", 1, 12, 1), + round0!("$t2", "$t3", "$t0", "$t1", 2, 17, 2), + round0!("$t1", "$t2", "$t3", "$t0", 3, 22, 3), + round0!("$t0", "$t1", "$t2", "$t3", 4, 7, 4), + round0!("$t3", "$t0", "$t1", "$t2", 5, 12, 5), + round0!("$t2", "$t3", "$t0", "$t1", 6, 17, 6), + round0!("$t1", "$t2", "$t3", "$t0", 7, 22, 7), + round0!("$t0", "$t1", "$t2", "$t3", 8, 7, 8), + round0!("$t3", "$t0", "$t1", "$t2", 9, 12, 9), + round0!("$t2", "$t3", "$t0", "$t1", 10, 17, 10), + round0!("$t1", "$t2", "$t3", "$t0", 11, 22, 11), + round0!("$t0", "$t1", "$t2", "$t3", 12, 7, 12), + round0!("$t3", "$t0", "$t1", "$t2", 13, 12, 13), + round0!("$t2", "$t3", "$t0", "$t1", 14, 17, 14), + round0!("$t1", "$t2", "$t3", "$t0", 15, 22, 15), + + round1!("$t0", "$t1", "$t2", "$t3", 1, 5, 16), + round1!("$t3", "$t0", "$t1", "$t2", 6, 9, 17), + round1!("$t2", "$t3", "$t0", "$t1", 11, 14, 18), + round1!("$t1", "$t2", "$t3", "$t0", 0, 20, 19), + round1!("$t0", "$t1", "$t2", "$t3", 5, 5, 20), + round1!("$t3", "$t0", "$t1", "$t2", 10, 9, 21), + round1!("$t2", "$t3", "$t0", "$t1", 15, 14, 22), + round1!("$t1", "$t2", "$t3", "$t0", 4, 20, 23), + round1!("$t0", "$t1", "$t2", "$t3", 9, 5, 24), + round1!("$t3", "$t0", "$t1", "$t2", 14, 9, 25), + round1!("$t2", "$t3", "$t0", "$t1", 3, 14, 26), + round1!("$t1", "$t2", "$t3", "$t0", 8, 20, 27), + round1!("$t0", "$t1", "$t2", "$t3", 13, 5, 28), + round1!("$t3", "$t0", "$t1", "$t2", 2, 9, 29), + round1!("$t2", "$t3", "$t0", "$t1", 7, 14, 30), + + round1!("$t1", "$t2", "$t3", "$t0", 12, 20, 31), + round2!("$t0", "$t1", "$t2", "$t3", 5, 4, 32), + round2!("$t3", "$t0", "$t1", "$t2", 8, 11, 33), + round2!("$t2", "$t3", "$t0", "$t1", 11, 16, 34), + round2!("$t1", "$t2", "$t3", "$t0", 14, 23, 35), + round2!("$t0", "$t1", "$t2", "$t3", 1, 4, 36), + round2!("$t3", "$t0", "$t1", "$t2", 4, 11, 37), + round2!("$t2", "$t3", "$t0", "$t1", 7, 16, 38), + round2!("$t1", "$t2", "$t3", "$t0", 10, 23, 39), + round2!("$t0", "$t1", "$t2", "$t3", 13, 4, 40), + round2!("$t3", "$t0", "$t1", "$t2", 0, 11, 41), + round2!("$t2", "$t3", "$t0", "$t1", 3, 16, 42), + round2!("$t1", "$t2", "$t3", "$t0", 6, 23, 43), + round2!("$t0", "$t1", "$t2", "$t3", 9, 4, 44), + round2!("$t3", "$t0", "$t1", "$t2", 12, 11, 45), + round2!("$t2", "$t3", "$t0", "$t1", 15, 16, 46), + round2!("$t1", "$t2", "$t3", "$t0", 2, 23, 47), + + round3!("$t0", "$t1", "$t2", "$t3", 0, 6, 48), + round3!("$t3", "$t0", "$t1", "$t2", 7, 10, 49), + round3!("$t2", "$t3", "$t0", "$t1", 14, 15, 50), + round3!("$t1", "$t2", "$t3", "$t0", 5, 21, 51), + round3!("$t0", "$t1", "$t2", "$t3", 12, 6, 52), + round3!("$t3", "$t0", "$t1", "$t2", 3, 10, 53), + round3!("$t2", "$t3", "$t0", "$t1", 10, 15, 54), + round3!("$t1", "$t2", "$t3", "$t0", 1, 21, 55), + round3!("$t0", "$t1", "$t2", "$t3", 8, 6, 56), + round3!("$t3", "$t0", "$t1", "$t2", 15, 10, 57), + round3!("$t2", "$t3", "$t0", "$t1", 6, 15, 58), + round3!("$t1", "$t2", "$t3", "$t0", 13, 21, 59), + round3!("$t0", "$t1", "$t2", "$t3", 4, 6, 60), + round3!("$t3", "$t0", "$t1", "$t2", 11, 10, 61), + round3!("$t2", "$t3", "$t0", "$t1", 2, 15, 62), + round3!("$t1", "$t2", "$t3", "$t0", 9, 21, 63), + + "add.w $a4, $a4, $t0", + "add.w $a5, $a5, $t1", + "add.w $a6, $a6, $t2", + "add.w $a7, $a7, $t3", + + // Looping over blocks + "addi.d $a1, $a1, 64", + "addi.d $a2, $a2, -1", + "bnez $a2, 42b", + + inout("$a1") blocks.as_ptr() => _, + inout("$a2") blocks.len() => _, + in("$a3") crate::consts::RC.as_ptr(), + inout("$a4") state[0], + inout("$a5") state[1], + inout("$a6") state[2], + inout("$a7") state[3], + + // Clobbers + out("$t0") _, + out("$t1") _, + out("$t2") _, + out("$t3") _, + out("$t4") _, + out("$t5") _, + out("$t6") _, + + options(preserves_flags, readonly, pure, nostack), + ); + } +} diff --git a/rust/vendor/md-5/src/compress/soft.rs b/rust/vendor/md-5/src/compress/soft.rs new file mode 100644 index 0000000..40630a1 --- /dev/null +++ b/rust/vendor/md-5/src/compress/soft.rs @@ -0,0 +1,151 @@ +#![allow(clippy::many_single_char_names, clippy::unreadable_literal)] +use crate::consts::RC; +use core::convert::TryInto; + +#[inline(always)] +fn op_f(w: u32, x: u32, y: u32, z: u32, m: u32, c: u32, s: u32) -> u32 { + ((x & y) | (!x & z)) + .wrapping_add(w) + .wrapping_add(m) + .wrapping_add(c) + .rotate_left(s) + .wrapping_add(x) +} +#[inline(always)] +fn op_g(w: u32, x: u32, y: u32, z: u32, m: u32, c: u32, s: u32) -> u32 { + ((x & z) | (y & !z)) + .wrapping_add(w) + .wrapping_add(m) + .wrapping_add(c) + .rotate_left(s) + .wrapping_add(x) +} + +#[inline(always)] +fn op_h(w: u32, x: u32, y: u32, z: u32, m: u32, c: u32, s: u32) -> u32 { + (x ^ y ^ z) + .wrapping_add(w) + .wrapping_add(m) + .wrapping_add(c) + .rotate_left(s) + .wrapping_add(x) +} + +#[inline(always)] +fn op_i(w: u32, x: u32, y: u32, z: u32, m: u32, c: u32, s: u32) -> u32 { + (y ^ (x | !z)) + .wrapping_add(w) + .wrapping_add(m) + .wrapping_add(c) + .rotate_left(s) + .wrapping_add(x) +} + +#[inline] +pub fn compress_block(state: &mut [u32; 4], input: &[u8; 64]) { + let mut a = state[0]; + let mut b = state[1]; + let mut c = state[2]; + let mut d = state[3]; + + let mut data = [0u32; 16]; + for (o, chunk) in data.iter_mut().zip(input.chunks_exact(4)) { + *o = u32::from_le_bytes(chunk.try_into().unwrap()); + } + + // round 1 + a = op_f(a, b, c, d, data[0], RC[0], 7); + d = op_f(d, a, b, c, data[1], RC[1], 12); + c = op_f(c, d, a, b, data[2], RC[2], 17); + b = op_f(b, c, d, a, data[3], RC[3], 22); + + a = op_f(a, b, c, d, data[4], RC[4], 7); + d = op_f(d, a, b, c, data[5], RC[5], 12); + c = op_f(c, d, a, b, data[6], RC[6], 17); + b = op_f(b, c, d, a, data[7], RC[7], 22); + + a = op_f(a, b, c, d, data[8], RC[8], 7); + d = op_f(d, a, b, c, data[9], RC[9], 12); + c = op_f(c, d, a, b, data[10], RC[10], 17); + b = op_f(b, c, d, a, data[11], RC[11], 22); + + a = op_f(a, b, c, d, data[12], RC[12], 7); + d = op_f(d, a, b, c, data[13], RC[13], 12); + c = op_f(c, d, a, b, data[14], RC[14], 17); + b = op_f(b, c, d, a, data[15], RC[15], 22); + + // round 2 + a = op_g(a, b, c, d, data[1], RC[16], 5); + d = op_g(d, a, b, c, data[6], RC[17], 9); + c = op_g(c, d, a, b, data[11], RC[18], 14); + b = op_g(b, c, d, a, data[0], RC[19], 20); + + a = op_g(a, b, c, d, data[5], RC[20], 5); + d = op_g(d, a, b, c, data[10], RC[21], 9); + c = op_g(c, d, a, b, data[15], RC[22], 14); + b = op_g(b, c, d, a, data[4], RC[23], 20); + + a = op_g(a, b, c, d, data[9], RC[24], 5); + d = op_g(d, a, b, c, data[14], RC[25], 9); + c = op_g(c, d, a, b, data[3], RC[26], 14); + b = op_g(b, c, d, a, data[8], RC[27], 20); + + a = op_g(a, b, c, d, data[13], RC[28], 5); + d = op_g(d, a, b, c, data[2], RC[29], 9); + c = op_g(c, d, a, b, data[7], RC[30], 14); + b = op_g(b, c, d, a, data[12], RC[31], 20); + + // round 3 + a = op_h(a, b, c, d, data[5], RC[32], 4); + d = op_h(d, a, b, c, data[8], RC[33], 11); + c = op_h(c, d, a, b, data[11], RC[34], 16); + b = op_h(b, c, d, a, data[14], RC[35], 23); + + a = op_h(a, b, c, d, data[1], RC[36], 4); + d = op_h(d, a, b, c, data[4], RC[37], 11); + c = op_h(c, d, a, b, data[7], RC[38], 16); + b = op_h(b, c, d, a, data[10], RC[39], 23); + + a = op_h(a, b, c, d, data[13], RC[40], 4); + d = op_h(d, a, b, c, data[0], RC[41], 11); + c = op_h(c, d, a, b, data[3], RC[42], 16); + b = op_h(b, c, d, a, data[6], RC[43], 23); + + a = op_h(a, b, c, d, data[9], RC[44], 4); + d = op_h(d, a, b, c, data[12], RC[45], 11); + c = op_h(c, d, a, b, data[15], RC[46], 16); + b = op_h(b, c, d, a, data[2], RC[47], 23); + + // round 4 + a = op_i(a, b, c, d, data[0], RC[48], 6); + d = op_i(d, a, b, c, data[7], RC[49], 10); + c = op_i(c, d, a, b, data[14], RC[50], 15); + b = op_i(b, c, d, a, data[5], RC[51], 21); + + a = op_i(a, b, c, d, data[12], RC[52], 6); + d = op_i(d, a, b, c, data[3], RC[53], 10); + c = op_i(c, d, a, b, data[10], RC[54], 15); + b = op_i(b, c, d, a, data[1], RC[55], 21); + + a = op_i(a, b, c, d, data[8], RC[56], 6); + d = op_i(d, a, b, c, data[15], RC[57], 10); + c = op_i(c, d, a, b, data[6], RC[58], 15); + b = op_i(b, c, d, a, data[13], RC[59], 21); + + a = op_i(a, b, c, d, data[4], RC[60], 6); + d = op_i(d, a, b, c, data[11], RC[61], 10); + c = op_i(c, d, a, b, data[2], RC[62], 15); + b = op_i(b, c, d, a, data[9], RC[63], 21); + + 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); +} + +#[inline] +pub fn compress(state: &mut [u32; 4], blocks: &[[u8; 64]]) { + for block in blocks { + compress_block(state, block) + } +} diff --git a/rust/vendor/md-5/src/consts.rs b/rust/vendor/md-5/src/consts.rs new file mode 100644 index 0000000..67ce879 --- /dev/null +++ b/rust/vendor/md-5/src/consts.rs @@ -0,0 +1,18 @@ +pub(crate) const STATE_INIT: [u32; 4] = [0x6745_2301, 0xEFCD_AB89, 0x98BA_DCFE, 0x1032_5476]; + +// TODO: remove `allow` on deprecation of `md5-asm` +#[allow(dead_code)] +pub(crate) static RC: [u32; 64] = [ + // round 1 + 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, + 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, + // round 2 + 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, + 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, + // round 3 + 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, + 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, + // round 4 + 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, + 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, +]; diff --git a/rust/vendor/md-5/src/lib.rs b/rust/vendor/md-5/src/lib.rs new file mode 100644 index 0000000..a45de2f --- /dev/null +++ b/rust/vendor/md-5/src/lib.rs @@ -0,0 +1,144 @@ +//! An implementation of the [MD5][1] cryptographic hash algorithm. +//! +//! # Usage +//! +//! ```rust +//! use md5::{Md5, Digest}; +//! use hex_literal::hex; +//! +//! // create a Md5 hasher instance +//! let mut hasher = Md5::new(); +//! +//! // process input message +//! hasher.update(b"hello world"); +//! +//! // acquire hash digest in the form of GenericArray, +//! // which in this case is equivalent to [u8; 16] +//! let result = hasher.finalize(); +//! assert_eq!(result[..], hex!("5eb63bbbe01eeed093cb22bb8f5acdc3")); +//! ``` +//! +//! Also see [RustCrypto/hashes][2] readme. +//! +//! [1]: https://en.wikipedia.org/wiki/MD5 +//! [2]: https://github.com/RustCrypto/hashes + +#![no_std] +#![doc( + html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg", + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg" +)] +#![warn(missing_docs, rust_2018_idioms)] + +pub use digest::{self, Digest}; + +mod compress; +pub(crate) mod consts; + +use core::{fmt, slice::from_ref}; +#[cfg(feature = "oid")] +use digest::const_oid::{AssociatedOid, ObjectIdentifier}; +use digest::{ + block_buffer::Eager, + core_api::{ + AlgorithmName, Block, BlockSizeUser, Buffer, BufferKindUser, CoreWrapper, FixedOutputCore, + OutputSizeUser, Reset, UpdateCore, + }, + typenum::{Unsigned, U16, U64}, + HashMarker, Output, +}; + +/// Core MD5 hasher state. +#[derive(Clone)] +pub struct Md5Core { + block_len: u64, + state: [u32; 4], +} + +impl HashMarker for Md5Core {} + +impl BlockSizeUser for Md5Core { + type BlockSize = U64; +} + +impl BufferKindUser for Md5Core { + type BufferKind = Eager; +} + +impl OutputSizeUser for Md5Core { + type OutputSize = U16; +} + +impl UpdateCore for Md5Core { + #[inline] + fn update_blocks(&mut self, blocks: &[Block<Self>]) { + self.block_len = self.block_len.wrapping_add(blocks.len() as u64); + compress::compress(&mut self.state, convert(blocks)) + } +} + +impl FixedOutputCore for Md5Core { + #[inline] + fn finalize_fixed_core(&mut self, buffer: &mut Buffer<Self>, out: &mut Output<Self>) { + let bit_len = self + .block_len + .wrapping_mul(Self::BlockSize::U64) + .wrapping_add(buffer.get_pos() as u64) + .wrapping_mul(8); + let mut s = self.state; + buffer.len64_padding_le(bit_len, |b| { + compress::compress(&mut s, convert(from_ref(b))) + }); + for (chunk, v) in out.chunks_exact_mut(4).zip(s.iter()) { + chunk.copy_from_slice(&v.to_le_bytes()); + } + } +} + +impl Default for Md5Core { + #[inline] + fn default() -> Self { + Self { + block_len: 0, + state: consts::STATE_INIT, + } + } +} + +impl Reset for Md5Core { + #[inline] + fn reset(&mut self) { + *self = Default::default(); + } +} + +impl AlgorithmName for Md5Core { + fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("Md5") + } +} + +impl fmt::Debug for Md5Core { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("Md5Core { ... }") + } +} + +#[cfg(feature = "oid")] +#[cfg_attr(docsrs, doc(cfg(feature = "oid")))] +impl AssociatedOid for Md5Core { + const OID: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.2.5"); +} + +/// MD5 hasher state. +pub type Md5 = CoreWrapper<Md5Core>; + +const BLOCK_SIZE: usize = <Md5Core as BlockSizeUser>::BlockSize::USIZE; + +#[inline(always)] +fn convert(blocks: &[Block<Md5Core>]) -> &[[u8; BLOCK_SIZE]] { + // SAFETY: GenericArray<u8, U64> and [u8; 64] have + // exactly the same memory layout + let p = blocks.as_ptr() as *const [u8; BLOCK_SIZE]; + unsafe { core::slice::from_raw_parts(p, blocks.len()) } +} diff --git a/rust/vendor/md-5/tests/data/md5.blb b/rust/vendor/md-5/tests/data/md5.blb Binary files differnew file mode 100644 index 0000000..3f6d643 --- /dev/null +++ b/rust/vendor/md-5/tests/data/md5.blb diff --git a/rust/vendor/md-5/tests/mod.rs b/rust/vendor/md-5/tests/mod.rs new file mode 100644 index 0000000..316cb8f --- /dev/null +++ b/rust/vendor/md-5/tests/mod.rs @@ -0,0 +1,15 @@ +use digest::dev::{feed_rand_16mib, fixed_reset_test}; +use hex_literal::hex; +use md5::{Digest, Md5}; + +digest::new_test!(md5_main, "md5", md5::Md5, fixed_reset_test); + +#[test] +fn md5_rand() { + let mut h = Md5::new(); + feed_rand_16mib(&mut h); + assert_eq!( + h.finalize()[..], + hex!("61aec26f1b909578ef638ae02dac0977")[..] + ); +} |