diff --git a/Cargo.lock b/Cargo.lock index 2e68cd8f5..1dbf49c14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,11 +2,59 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +dependencies = [ + "gimli", +] + +[[package]] +name = "adler" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" + +[[package]] +name = "autocfg" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" + +[[package]] +name = "backtrace" +version = "0.3.67" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide", + "object", + "rustc-demangle", +] + +[[package]] +name = "bitvec" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + [[package]] name = "blake2" version = "0.10.6" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -25,6 +73,22 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block-buffer" +version = "0.11.0-pre" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b6a33d658e9ef24ba0c4566d3d023d7978ca2ea3efb65e4eacd4586695892b" +dependencies = [ + "crypto-common 0.2.0-pre", + "generic-array", +] + +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "cc" version = "1.0.79" @@ -62,6 +126,16 @@ dependencies = [ "typenum", ] +[[package]] +name = "crypto-common" +version = "0.2.0-pre" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6faaa83e7700e0832cbbf84854d4c356270526907d9b14fab927fc7a9b5befb8" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "digest" version = "0.10.6" @@ -69,36 +143,67 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" dependencies = [ "blobby", - "block-buffer", + "block-buffer 0.10.4", "const-oid", - "crypto-common", + "crypto-common 0.1.6", "subtle", ] +[[package]] +name = "digest" +version = "0.11.0-pre" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f2e47350a84ef81587a050177f84af69defbf2bee70bdfb92b500dbbd247e97" +dependencies = [ + "block-buffer 0.11.0-pre", + "crypto-common 0.2.0-pre", +] + +[[package]] +name = "error-chain" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9435d864e017c3c6afeac1654189b06cdb491cf2ff73dbf0d73b0f292f42ff8" +dependencies = [ + "backtrace", +] + [[package]] name = "fsb" version = "0.1.3" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", "whirlpool", ] +[[package]] +name = "funty" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6d5a32815ae3f33302d95fdcb2ce17862f8c65363dcfd29360480ba1001fc9c" + [[package]] name = "generic-array" -version = "0.14.6" +version = "0.14.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", ] +[[package]] +name = "gimli" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" + [[package]] name = "gost94" version = "0.10.4" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -106,7 +211,7 @@ dependencies = [ name = "groestl" version = "0.10.1" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -133,7 +238,7 @@ dependencies = [ name = "k12" version = "0.2.1" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -148,15 +253,15 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.140" +version = "0.2.141" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" +checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" [[package]] name = "md-5" version = "0.10.5" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", "md5-asm", ] @@ -165,7 +270,7 @@ dependencies = [ name = "md2" version = "0.10.2" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -173,7 +278,7 @@ dependencies = [ name = "md4" version = "0.10.2" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -186,27 +291,149 @@ dependencies = [ "cc", ] +[[package]] +name = "mem" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b50b6159a8e0e40eac611e28eb8055844fd0756c35764adaa159c9ba2a21ad61" +dependencies = [ + "byteorder", + "error-chain", +] + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "miniz_oxide" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +dependencies = [ + "adler", +] + +[[package]] +name = "num" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +dependencies = [ + "num-bigint", + "num-complex", + "num-integer", + "num-iter", + "num-rational", + "num-traits", +] + +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-complex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" +dependencies = [ + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-iter" +version = "0.1.43" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + +[[package]] +name = "object" +version = "0.30.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" +dependencies = [ + "memchr", +] + [[package]] name = "proc-macro-hack" version = "0.5.20+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" +[[package]] +name = "radium" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" + [[package]] name = "ripemd" version = "0.1.3" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] +[[package]] +name = "rustc-demangle" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" + [[package]] name = "sha1" version = "0.10.5" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.6", "hex-literal", "sha1-asm", ] @@ -226,7 +453,7 @@ version = "0.10.6" dependencies = [ "cfg-if", "cpufeatures", - "digest", + "digest 0.10.6", "hex-literal", "sha2-asm", ] @@ -244,7 +471,7 @@ dependencies = [ name = "sha3" version = "0.10.6" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", "keccak", ] @@ -253,7 +480,7 @@ dependencies = [ name = "shabal" version = "0.4.1" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -261,7 +488,7 @@ dependencies = [ name = "sm3" version = "0.4.1" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -269,7 +496,7 @@ dependencies = [ name = "streebog" version = "0.10.2" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -279,11 +506,17 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + [[package]] name = "tiger" version = "0.2.1" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", ] @@ -299,11 +532,21 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "vsh" +version = "0.1.0" +dependencies = [ + "bitvec", + "digest 0.11.0-pre", + "mem", + "num", +] + [[package]] name = "whirlpool" version = "0.10.4" dependencies = [ - "digest", + "digest 0.10.6", "hex-literal", "whirlpool-asm", ] @@ -316,3 +559,12 @@ checksum = "4b0930846e800a97c78fd09a494b25d1f0780be9face03b7a05151e3104a8284" dependencies = [ "cc", ] + +[[package]] +name = "wyz" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05f360fc0b24296329c78fda852a1e9ae82de9cf7b27dae4b7f62f118f77b9ed" +dependencies = [ + "tap", +] diff --git a/Cargo.toml b/Cargo.toml index 7f544e284..62152aaef 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ members = [ "sm3", "streebog", "tiger", + "vsh", "whirlpool", ] exclude = [ diff --git a/README.md b/README.md index 17283a668..22102f6a7 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Additionally all crates do not require the standard library (i.e. `no_std` capab | [Streebog] (GOST R 34.11-2012) | [`streebog`] | [![crates.io](https://img.shields.io/crates/v/streebog.svg)](https://crates.io/crates/streebog) | [![Documentation](https://docs.rs/streebog/badge.svg)](https://docs.rs/streebog) | ![MSRV 1.41][msrv-1.41] | :yellow_heart: | | [Tiger] | [`tiger`] | [![crates.io](https://img.shields.io/crates/v/tiger.svg)](https://crates.io/crates/tiger) | [![Documentation](https://docs.rs/tiger/badge.svg)](https://docs.rs/tiger) | ![MSRV 1.41][msrv-1.41] | :green_heart: | | [Whirlpool] | [`whirlpool`] | [![crates.io](https://img.shields.io/crates/v/whirlpool.svg)](https://crates.io/crates/whirlpool) | [![Documentation](https://docs.rs/whirlpool/badge.svg)](https://docs.rs/whirlpool) | ![MSRV 1.41][msrv-1.41] | :green_heart: | +| [Simple VSH] | [`Simple VSH`] | [![crates.io](https://img.shields.io/crates/v/vsh.svg)](https://crates.io/crates/vsh) | [![Documentation](https://docs.rs/vsh/badge.svg)](https://docs.rs/vsh) | ![MSRV 1.41][msrv-1.41] | :green_heart: | NOTE: the [`blake3`] crate implements the `digest` traits used by the rest of the hashes in this repository, but is maintained by the BLAKE3 team. @@ -255,6 +256,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted [`streebog`]: ./streebog [`tiger`]: ./tiger [`whirlpool`]: ./whirlpool +[`Simple Vsh`]: ./vsh [//]: # (footnotes) @@ -294,3 +296,4 @@ Unless you explicitly state otherwise, any contribution intentionally submitted [Streebog]: https://en.wikipedia.org/wiki/Streebog [Whirlpool]: https://en.wikipedia.org/wiki/Whirlpool_(cryptography) [Tiger]: http://www.cs.technion.ac.il/~biham/Reports/Tiger/tiger/tiger.html +[Simple Vsh]: https://en.wikipedia.org/wiki/Very_smooth_hash \ No newline at end of file diff --git a/vsh/CHANGELOG.md b/vsh/CHANGELOG.md new file mode 100644 index 000000000..5e3c3bf15 --- /dev/null +++ b/vsh/CHANGELOG.md @@ -0,0 +1,9 @@ +# 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.1.0 (2023-06-07) +- Initial release diff --git a/vsh/Cargo.toml b/vsh/Cargo.toml new file mode 100644 index 000000000..a763e87f5 --- /dev/null +++ b/vsh/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "vsh" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +bitvec = "1.0.1" +mem = "0.5.0" +num = "0.4.0" +digest = "0.11.0-pre" diff --git a/vsh/LICENSE-APACHE b/vsh/LICENSE-APACHE new file mode 100644 index 000000000..de60474be --- /dev/null +++ b/vsh/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 2020 Ulrik Mikaelsson + +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/vsh/LICENSE-MIT b/vsh/LICENSE-MIT new file mode 100644 index 000000000..ad4eda899 --- /dev/null +++ b/vsh/LICENSE-MIT @@ -0,0 +1,26 @@ +Copyright (c) 2021 RustCrypto Developers +Copyright (c) 2020 Shivendra Mishra + +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/vsh/README.md b/vsh/README.md new file mode 100644 index 000000000..1b6ff6139 --- /dev/null +++ b/vsh/README.md @@ -0,0 +1,55 @@ +# RustCrypto: Vsh + +[![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 [Vsh] hash function. + +[Documentation][docs-link] + +## 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, without any additional terms or conditions. + +[//]: # (badges) + +[crate-image]: https://img.shields.io/crates/v/vsh.svg +[crate-link]: https://crates.io/crates/vsh +[docs-image]: https://docs.rs/vsh/badge.svg +[docs-link]: https://docs.rs/vsh/ +[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/vsh/badge.svg?branch=master +[build-link]: https://github.com/RustCrypto/hashes/actions?query=workflow%3Avsh + +[//]: # (general links) + +[Vsh]: https://en.wikipedia.org/wiki/Very_smooth_hash \ No newline at end of file diff --git a/vsh/src/lib.rs b/vsh/src/lib.rs new file mode 100644 index 000000000..61937c6ae --- /dev/null +++ b/vsh/src/lib.rs @@ -0,0 +1,86 @@ +//! An implementation of the [Vsh][1] cryptographic hash algorithms. +//! +//! This is basic VSH implementation. +//! +//! # Usage +//! +//! ```rust +//! use hex_literal::hex; +//! use vsh::{Vsh, Digest}; +//! +//! // Create a Vsh object +//! let mut hasher = Vsh::new(); +//! +//! // process input message +//! hasher.update(b"hello world"); +//! +//! // Acquire hash digest which in this case is BigUint. +//! let result = hasher.finalize(); +//! ``` +//! +//! Also see [RustCrypto/hashes][2] readme. +//! +//! [1]: https://en.wikipedia.org/wiki/Very_smooth_hash +//! [2]: https://github.com/RustCrypto/hashes + +use digest::{ + core_api::{ + AlgorithmName + }, + HashMarker, +}; +use core::fmt; +use std::vec::Vec; +use num::bigint::BigUint; +mod vsh; + +/// Core Vsh hasher state. +#[derive(Clone)] +pub struct VshCore { + bytes: Vec +} + +impl HashMarker for VshCore {} + + + +impl AlgorithmName for VshCore { + fn write_alg_name(f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("Vsh") + } +} + +impl fmt::Debug for VshCore { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("VshCore { ... }") + } +} + + + +impl VshCore { + pub fn new() -> Self { + let bytes: Vec = Vec::new(); + VshCore { bytes: bytes } + } + + pub fn update(&mut self, data: &Vec) { + self.bytes = data.to_vec(); + } + + pub fn finalize(&mut self) -> Result { + let vhs_x:Vec; + match vsh::validate_and_pad_input(self.bytes.clone()) { + Ok(result) => { + vhs_x = vsh::calculate_vhs_of_x(result); + }, + Err(error) => { + return Err(error); + } + } + let primes = vsh::get_prime_list(vhs_x); + + let hash_of_data: BigUint = vsh::do_mod_with_products(primes); + Ok(hash_of_data) + } +} \ No newline at end of file diff --git a/vsh/src/vsh.rs b/vsh/src/vsh.rs new file mode 100644 index 000000000..240762962 --- /dev/null +++ b/vsh/src/vsh.rs @@ -0,0 +1,172 @@ + +use bitvec::prelude::*; +use num::bigint::BigUint; + +const PRIME_NUMBERS: &[u16] = &[ + 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, + 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, + 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, + 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, + 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, + 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, + 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, + 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, + 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, + 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, + 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, + 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, + 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, + 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, + 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, + 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, + 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, + 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, + 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, + 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, + 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, + 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, + 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, + 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, + 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, + 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, + 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, + 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, + 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, + 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, + 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, + 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, +]; + +const RSA_TEN_TWENTY_FOUR: &str = "135066410865995223349603216278805969938881475605667027524485143851526510604859533833940287150571909441798207282164471551373680419703964191743046496589274256239341020864383202110372958725762358509643110564073501508187510676594629205563685529475213500852879416377328533906109750544334999811150056977236890927563"; +const BLOCK_SIZE: u8 = 64; + +pub fn validate_and_pad_input(input: Vec) -> Result, String> { + let input_length = input.len() as u8; + + if input_length == 0 { + return Err(String::from("Failed to hash, can't hash without data.")); + } + + let padded_data = if input_length % BLOCK_SIZE == 0 { + input + } else { + let zeros_to_pad = BLOCK_SIZE - (input_length % BLOCK_SIZE); + let zeros = vec![0; zeros_to_pad as usize]; + [input.as_slice(), &zeros].concat() + }; + + Ok(padded_data) +} + + +pub fn get_prime_numbers() -> Vec { + PRIME_NUMBERS.to_vec() +} + +fn reverse_chunks_by_block_size(data: &[u8]) -> Vec> { + let mut chunks = Vec::new(); + + + for i in (0..data.len()).rev().step_by(BLOCK_SIZE as usize) { + let start_idx = if i < BLOCK_SIZE as usize - 1 { + 0 + } else { + i - (BLOCK_SIZE as usize - 1) + }; + + let end_idx = i + 1; + let chunk = &data[start_idx..end_idx]; + chunks.push(chunk.to_vec()); + } + chunks +} + +pub fn calculate_vhs_of_x(input: Vec) -> Vec { + let chunks = reverse_chunks_by_block_size(&input); + let mut set_bits: Vec = vec![]; + for chunk in chunks { + let bits = chunk.view_bits::(); + set_bits = bits + .iter() + .enumerate() + .filter(|(_, b)| **b) + .map(|(i, _)| (8 * BLOCK_SIZE as usize) - i) + .collect(); + } + set_bits +} + +pub fn get_prime_list(index:Vec) -> Vec { + let primes = get_prime_numbers(); + let mut prime_list: Vec = vec![]; + + for a_index in index { + prime_list.push(primes[a_index-1]); + } + + let mut prime_products = vec![1]; + for a_prime in prime_list { + let second_prime: Vec = vec![a_prime as u128]; + prime_products = get_prime_products(&prime_products, &second_prime); + } + prime_products +} + +pub fn do_mod_with_products(product: Vec) -> BigUint{ + + let modulus_str = RSA_TEN_TWENTY_FOUR; + let modulus: BigUint = BigUint::parse_bytes(modulus_str.as_bytes(), 10).unwrap(); + + let bytes: Vec = product.iter() + .flat_map(|&x| x.to_le_bytes().to_vec()) + .collect(); + let num = BigUint::from_bytes_le(&bytes); + let remainder = num % modulus; + remainder +} + + + +pub fn get_prime_products(x: &Vec, y: &Vec) -> Vec { + let n = x.len(); + let mut result = vec![0; n * 2]; + + if n <= 4 { + for i in 0..n { + for j in 0..n { + result[i + j] += x[i] * y[j]; + } + } + } else { + let mid = n / 2; + + let xl = x[0..mid].to_vec(); + let xr = x[mid..].to_vec(); + let yl = y[0..mid].to_vec(); + let yr = y[mid..].to_vec(); + + let p1 = get_prime_products(&xl, &yl); + let p2 = get_prime_products(&xr, &yr); + let mut xl_xr = xl.clone(); + for i in 0..mid { + xl_xr[i] += xr[i]; + } + let mut yl_yr = yl.clone(); + for i in 0..mid { + yl_yr[i] += yr[i]; + } + let p3 = get_prime_products(&xl_xr, &yl_yr); + + for i in 0..n { + result[i] += p1[i]; + result[i + n] += p2[i]; + result[i + mid] += p3[i] - p1[i] - p2[i]; + } + } + + while result.len() > 1 && result.last() == Some(&0) { + result.pop(); + } + + result +} \ No newline at end of file