From effb1f04d79e6fdda386dc6ef5a2ea71f8a9617e Mon Sep 17 00:00:00 2001 From: Shunsuke Shimizu Date: Sat, 4 May 2019 16:13:18 +0900 Subject: [PATCH 01/84] tweak Chacha and Blake diagonalization to hide latency on b --- hashes/blake/src/lib.rs | 10 ++++++---- stream-ciphers/chacha/src/guts.rs | 14 ++++++++------ 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/hashes/blake/src/lib.rs b/hashes/blake/src/lib.rs index 3ddf349c..69cd9a72 100644 --- a/hashes/blake/src/lib.rs +++ b/hashes/blake/src/lib.rs @@ -71,14 +71,16 @@ fn round64( (a, b, c, d) } + #[inline(always)] fn diagonalize((a, b, c, d): (X4, X4, X4, X4)) -> (X4, X4, X4, X4) { - (a, b.shuffle3012(), c.shuffle2301(), d.shuffle1230()) + // Since b has the critical data dependency, avoid rotating b to hide latency. + (a.shuffle1230(), b, c.shuffle3012(), d.shuffle2301()) } #[inline(always)] fn undiagonalize((a, b, c, d): (X4, X4, X4, X4)) -> (X4, X4, X4, X4) { - (a, b.shuffle1230(), c.shuffle2301(), d.shuffle3012()) + (a.shuffle3012(), b, c.shuffle1230(), d.shuffle2301()) } macro_rules! define_compressor { @@ -114,8 +116,8 @@ macro_rules! define_compressor { let m1 = mach.vec([m1!(0), m1!(2), m1!(4), m1!(6)]); xs = $round::(xs, m0, m1); // diagonal step - let m0 = mach.vec([m0!(8), m0!(10), m0!(12), m0!(14)]); - let m1 = mach.vec([m1!(8), m1!(10), m1!(12), m1!(14)]); + let m0 = mach.vec([m0!(14), m0!(8), m0!(10), m0!(12)]); + let m1 = mach.vec([m1!(14), m1!(8), m1!(10), m1!(12)]); xs = undiagonalize($round::(diagonalize(xs), m0, m1)); } let h: (M::$X4, M::$X4) = (mach.unpack(state.h[0]), mach.unpack(state.h[1])); diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 394aab48..c4434b64 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -41,16 +41,18 @@ pub(crate) fn round(mut x: State) -> State { #[inline(always)] pub(crate) fn diagonalize(mut x: State) -> State { - x.b = x.b.shuffle_lane_words3012(); - x.c = x.c.shuffle_lane_words2301(); - x.d = x.d.shuffle_lane_words1230(); + // Since b has the critical data dependency, avoid rotating b to hide latency. + x.c = x.c.shuffle_lane_words3012(); + x.d = x.d.shuffle_lane_words2301(); + x.a = x.a.shuffle_lane_words1230(); x } + #[inline(always)] pub(crate) fn undiagonalize(mut x: State) -> State { - x.b = x.b.shuffle_lane_words1230(); - x.c = x.c.shuffle_lane_words2301(); - x.d = x.d.shuffle_lane_words3012(); + x.c = x.c.shuffle_lane_words1230(); + x.d = x.d.shuffle_lane_words2301(); + x.a = x.a.shuffle_lane_words3012(); x } From 8608f02b1fd8847cdaeb09c965f7ea26faa2039c Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 22 Jan 2020 11:15:23 -0800 Subject: [PATCH 02/84] tune diagonalization-tweak so it's fast on SSE2 too Without this change the pivot-around-b tweak would cause a performance regression on pre-AVX2 Intel archs. With this adjustment, the new diagonalization is faster across the board. --- stream-ciphers/chacha/src/guts.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index c4434b64..ee73d976 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -42,14 +42,19 @@ pub(crate) fn round(mut x: State) -> State { #[inline(always)] pub(crate) fn diagonalize(mut x: State) -> State { // Since b has the critical data dependency, avoid rotating b to hide latency. + // + // The order of these statements is important for performance on pre-AVX2 Intel machines, which + // are throughput-bound and operating near their superscalar limits during refill_wide. The + // permutations here and in undiagonalize have been found in testing on Nehalem to be optimal. + x.a = x.a.shuffle_lane_words1230(); x.c = x.c.shuffle_lane_words3012(); x.d = x.d.shuffle_lane_words2301(); - x.a = x.a.shuffle_lane_words1230(); x } #[inline(always)] pub(crate) fn undiagonalize(mut x: State) -> State { + // The order of these statements is magic. See comment in diagonalize. x.c = x.c.shuffle_lane_words1230(); x.d = x.d.shuffle_lane_words2301(); x.a = x.a.shuffle_lane_words3012(); From bc2dc2e8f6b7d4e720dbd864e2e6807b1b2e9841 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 16 Jan 2020 12:35:20 -0800 Subject: [PATCH 03/84] forgo simd for non-performance-sensitive functions Simpler. --- stream-ciphers/chacha/src/guts.rs | 85 +++++++++++++++---------------- 1 file changed, 40 insertions(+), 45 deletions(-) diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index ee73d976..304b2ae0 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -62,9 +62,35 @@ pub(crate) fn undiagonalize(mut x: State) -> State { } impl ChaCha { - #[inline(always)] pub fn new(key: &[u8; 32], nonce: &[u8]) -> Self { - init_chacha(key, nonce) + let ctr_nonce = [ + 0, + if nonce.len() == 12 { + read_u32le(&nonce[0..4]) + } else { + 0 + }, + read_u32le(&nonce[nonce.len() - 8..nonce.len() - 4]), + read_u32le(&nonce[nonce.len() - 4..]), + ]; + let key0 = [ + read_u32le(&key[0..4]), + read_u32le(&key[4..8]), + read_u32le(&key[8..12]), + read_u32le(&key[12..16]), + ]; + let key1 = [ + read_u32le(&key[16..20]), + read_u32le(&key[20..24]), + read_u32le(&key[24..28]), + read_u32le(&key[28..32]), + ]; + + ChaCha { + b: key0.into(), + c: key1.into(), + d: ctr_nonce.into(), + } } #[inline(always)] @@ -127,14 +153,22 @@ impl ChaCha { refill_narrow_rounds(self, drounds) } - #[inline(always)] + #[inline] pub fn set_stream_param(&mut self, param: u32, value: u64) { - set_stream_param(self, param, value) + let mut d: [u32; 4] = self.d.into(); + let p0 = ((param << 1) | 1) as usize; + let p1 = (param << 1) as usize; + d[p0] = (value >> 32) as u32; + d[p1] = value as u32; + self.d = d.into(); } - #[inline(always)] + #[inline] pub fn get_stream_param(&self, param: u32) -> u64 { - get_stream_param(self, param) + let d: [u32; 4] = self.d.into(); + let p0 = ((param << 1) | 1) as usize; + let p1 = (param << 1) as usize; + ((d[p0] as u64) << 32) | d[p1] as u64 } } @@ -242,50 +276,11 @@ dispatch!(m, Mach, { } }); -dispatch_light128!(m, Mach, { - fn set_stream_param(state: &mut ChaCha, param: u32, value: u64) { - let d: Mach::u32x4 = m.unpack(state.d); - state.d = d - .insert((value >> 32) as u32, (param << 1) | 1) - .insert(value as u32, param << 1) - .into(); - } -}); - -dispatch_light128!(m, Mach, { - fn get_stream_param(state: &ChaCha, param: u32) -> u64 { - let d: Mach::u32x4 = m.unpack(state.d); - ((d.extract((param << 1) | 1) as u64) << 32) | d.extract(param << 1) as u64 - } -}); - fn read_u32le(xs: &[u8]) -> u32 { assert_eq!(xs.len(), 4); u32::from(xs[0]) | (u32::from(xs[1]) << 8) | (u32::from(xs[2]) << 16) | (u32::from(xs[3]) << 24) } -dispatch_light128!(m, Mach, { - fn init_chacha(key: &[u8; 32], nonce: &[u8]) -> ChaCha { - let ctr_nonce = [ - 0, - if nonce.len() == 12 { - read_u32le(&nonce[0..4]) - } else { - 0 - }, - read_u32le(&nonce[nonce.len() - 8..nonce.len() - 4]), - read_u32le(&nonce[nonce.len() - 4..]), - ]; - let key0: Mach::u32x4 = m.read_le(&key[..16]); - let key1: Mach::u32x4 = m.read_le(&key[16..]); - ChaCha { - b: key0.into(), - c: key1.into(), - d: ctr_nonce.into(), - } - } -}); - dispatch_light128!(m, Mach, { fn init_chacha_x(key: &[u8; 32], nonce: &[u8; 24], rounds: u32) -> ChaCha { let key0: Mach::u32x4 = m.read_le(&key[..16]); From f06ce94f54a26f59980db5599796130c8d71ff8d Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 22 Jan 2020 11:28:14 -0800 Subject: [PATCH 04/84] add license files in workspace root resolves #27 --- LICENSE-APACHE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE-MIT | 25 ++++++ 2 files changed, 226 insertions(+) create mode 100644 LICENSE-APACHE create mode 100644 LICENSE-MIT diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 00000000..1eb32153 --- /dev/null +++ b/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 2019 The CryptoCorrosion Contributors + +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/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 00000000..d78c961b --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2019 The CryptoCorrosion Contributors + +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. From 80655df86e7c76aa775a55680f4978ee5a29cf82 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 22 Jan 2020 11:29:33 -0800 Subject: [PATCH 05/84] add narrow benchmark New benchmark tests performance when user requests data a little bit at a time so we never get a chance to use the wide impl. --- stream-ciphers/chacha/benches/chacha20.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/stream-ciphers/chacha/benches/chacha20.rs b/stream-ciphers/chacha/benches/chacha20.rs index b8d7c228..df70c1db 100644 --- a/stream-ciphers/chacha/benches/chacha20.rs +++ b/stream-ciphers/chacha/benches/chacha20.rs @@ -18,3 +18,15 @@ pub fn stream_10k(b: &mut Bencher) { }); b.bytes = 10240; } + +#[bench] +pub fn stream_narrow_10k(b: &mut Bencher) { + let mut state = ChaCha20::new_var(&[0; 32], &[0; 8]).unwrap(); + let mut result = [0; 192]; + b.iter(|| { + for _ in 0..10 { + state.apply_keystream(&mut result) + } + }); + b.bytes = 1920; +} From 5e04d6f65a4633374daac5b9e13d467e0281d650 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 22 Jan 2020 13:16:17 -0800 Subject: [PATCH 06/84] fix simplified ChaCha impl for non-amd64 --- utils-simd/ppv-lite86/src/generic.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 2d0a74cf..8cc357cd 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -16,6 +16,12 @@ impl From<[u32; 4]> for vec128_storage { Self { d } } } +impl From for [u32; 4] { + #[inline] + fn from(d: vec128_storage) -> Self { + unsafe { d.d } + } +} #[derive(Clone, Copy)] pub struct vec256_storage { v128: [vec128_storage; 2], From 3a2e74fec7ff1316167f8d73b86718b9eb6d364e Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 09:39:32 -0700 Subject: [PATCH 07/84] impl PartialEq, Eq for vecXXX_storage --- utils-simd/ppv-lite86/Cargo.toml | 2 +- utils-simd/ppv-lite86/src/generic.rs | 11 +++++++++-- utils-simd/ppv-lite86/src/x86_64/mod.rs | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index b1c0c0f5..7063090f 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.6" +version = "0.2.7" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 8cc357cd..7d8a779e 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -22,7 +22,14 @@ impl From for [u32; 4] { unsafe { d.d } } } -#[derive(Clone, Copy)] +impl Eq for vec128_storage {} +impl PartialEq for vec128_storage { + #[inline] + fn eq(&self, rhs: &Self) -> bool { + unsafe { self.o == rhs.o } + } +} +#[derive(Clone, Copy, PartialEq, Eq)] pub struct vec256_storage { v128: [vec128_storage; 2], } @@ -36,7 +43,7 @@ impl vec256_storage { self.v128 } } -#[derive(Clone, Copy)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct vec512_storage { v128: [vec128_storage; 4], } diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index 39d3b900..ecf184f3 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -137,6 +137,13 @@ impl Default for vec128_storage { vec128_storage { u128x1: [0] } } } +impl Eq for vec128_storage {} +impl PartialEq for vec128_storage { + #[inline(always)] + fn eq(&self, rhs: &Self) -> bool { + unsafe { self.u128x1 == rhs.u128x1 } + } +} #[allow(non_camel_case_types)] #[derive(Copy, Clone)] @@ -167,6 +174,13 @@ impl vec256_storage { unsafe { self.sse2 } } } +impl Eq for vec256_storage {} +impl PartialEq for vec256_storage { + #[inline(always)] + fn eq(&self, rhs: &Self) -> bool { + unsafe { self.sse2 == rhs.sse2 } + } +} #[allow(non_camel_case_types)] #[derive(Copy, Clone)] @@ -193,6 +207,13 @@ impl vec512_storage { unsafe { self.sse2 } } } +impl Eq for vec512_storage {} +impl PartialEq for vec512_storage { + #[inline(always)] + fn eq(&self, rhs: &Self) -> bool { + unsafe { self.avx == rhs.avx } + } +} macro_rules! impl_into { ($storage:ident, $array:ty, $name:ident) => { From 3eaf0fab80622d71a2119d22d19d2402fd1d60f1 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 11:21:08 -0700 Subject: [PATCH 08/84] ChaCha: derive PartialEq, Eq --- stream-ciphers/chacha/src/guts.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 304b2ae0..55e30a0f 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -11,14 +11,16 @@ const BUFBLOCKS: u64 = 1 << LOG2_BUFBLOCKS; pub(crate) const BUFSZ64: u64 = BLOCK64 * BUFBLOCKS; pub(crate) const BUFSZ: usize = BUFSZ64 as usize; -#[derive(Clone)] +/// Parameters of a ChaCha stream, including fixed parameters and current position. +#[derive(Clone, PartialEq, Eq)] pub struct ChaCha { pub(crate) b: vec128_storage, pub(crate) c: vec128_storage, pub(crate) d: vec128_storage, } -#[derive(Clone)] +/// Working state of a ChaCha stream. +#[derive(Clone, PartialEq, Eq)] pub struct State { pub(crate) a: V, pub(crate) b: V, From ceb077511dcb72697141615f5fa377f708285097 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 12:06:20 -0700 Subject: [PATCH 09/84] ChaCha: position-independent stream comparison Provide stream_eq to compare streams, irrespective of their current position. --- stream-ciphers/chacha/src/guts.rs | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 55e30a0f..94a2697a 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -172,6 +172,22 @@ impl ChaCha { let p1 = (param << 1) as usize; ((d[p0] as u64) << 32) | d[p1] as u64 } + + /// Return whether rhs represents the same stream, irrespective of current 32-bit position. + #[inline] + pub fn stream32_eq(&self, rhs: &Self) -> bool { + let self_d: [u32; 4] = self.d.into(); + let rhs_d: [u32; 4] = rhs.d.into(); + self.b == rhs.b && self.c == rhs.c && self_d[3] == rhs_d[3] && self_d[2] == rhs_d[2] && self_d[1] == rhs_d[1] + } + + /// Return whether rhs represents the same stream, irrespective of current 64-bit position. + #[inline] + pub fn stream64_eq(&self, rhs: &Self) -> bool { + let self_d: [u32; 4] = self.d.into(); + let rhs_d: [u32; 4] = rhs.d.into(); + self.b == rhs.b && self.c == rhs.c && self_d[3] == rhs_d[3] && self_d[2] == rhs_d[2] + } } #[inline(always)] @@ -301,3 +317,25 @@ dispatch_light128!(m, Mach, { state } }); + +#[cfg(test)] +mod tests { + use super::*; + + /// Basic check that streamXX_eq is block-count invariant + #[test] + fn test_stream_eq() { + let key = hex!("fa44478c59ca70538e3549096ce8b523232c50d9e8e8d10c203ef6c8d07098a5"); + let nonce = hex!("8d3a0d6d7827c00701020304"); + let mut a = ChaCha::new(&key, &nonce); + let b = a.clone(); + let mut out = [0u8; BLOCK]; + assert!(a == b); + assert!(a.stream32_eq(&b)); + assert!(a.stream64_eq(&b)); + a.refill(0, &mut out); + assert!(a != b); + assert!(a.stream32_eq(&b)); + assert!(a.stream64_eq(&b)); + } +} From 9be43f5eb62dd77885fcdf28ac77a1b97fe88279 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 13:18:45 -0700 Subject: [PATCH 10/84] ppv-lite86: target_feature-gate tests For the machine-specific tests in ppv-lite86, use compile-time feature detection to #[ignore] unavailable tests. Must compile with RUSTFLAGS="-C target-cpu=native" to run all supported low-level tests (added to Travis config). --- .travis.yml | 3 +++ utils-simd/ppv-lite86/src/x86_64/sse2.rs | 19 +++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 9752ea52..6e997576 100644 --- a/.travis.yml +++ b/.travis.yml @@ -78,6 +78,9 @@ matrix: - env: TARGET=x86_64-unknown-linux-gnu rust: 1.31.1 + # machine-specific tests are skipped based on static feature detection + - env: TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-cpu=native" + before_install: - set -e - rustup self update diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 81021a99..60e7681c 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -1136,13 +1136,14 @@ where } #[cfg(test)] +#[cfg(target_arch = "x86_64")] mod test { use super::*; use crate::x86_64::{SSE2, SSE41, SSSE3}; use crate::Machine; #[test] - #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(target_feature = "ssse3"), ignore)] fn test_bswap32_s2_vs_s3() { let xs = [0x0f0e_0d0c, 0x0b0a_0908, 0x0706_0504, 0x0302_0100]; let ys = [0x0c0d_0e0f, 0x0809_0a0b, 0x0405_0607, 0x0001_0203]; @@ -1165,7 +1166,7 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(target_feature = "ssse3"), ignore)] fn test_bswap64_s2_vs_s3() { let xs = [0x0f0e_0d0c_0b0a_0908, 0x0706_0504_0302_0100]; let ys = [0x0809_0a0b_0c0d_0e0f, 0x0001_0203_0405_0607]; @@ -1188,7 +1189,7 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(target_feature = "ssse3"), ignore)] fn test_shuffle32_s2_vs_s3() { let xs = [0x0, 0x1, 0x2, 0x3]; let ys = [0x2, 0x3, 0x0, 0x1]; @@ -1226,7 +1227,7 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(target_feature = "ssse3"), ignore)] fn test_shuffle64_s2_vs_s3() { let xs = [0x0, 0x1, 0x2, 0x3]; let ys = [0x2, 0x3, 0x0, 0x1]; @@ -1263,8 +1264,8 @@ mod test { assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); } + #[cfg_attr(not(all(target_feature = "ssse3", target_feature = "sse4.1")), ignore)] #[test] - #[cfg(target_arch = "x86_64")] fn test_lanes_u32x4() { let xs = [0x1, 0x2, 0x3, 0x4]; @@ -1295,7 +1296,7 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(all(target_feature = "ssse3", target_feature = "sse4.1")), ignore)] fn test_lanes_u64x2() { let xs = [0x1, 0x2]; @@ -1326,7 +1327,6 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] fn test_vec4_u32x4_s2() { let xs = [1, 2, 3, 4]; let s2 = unsafe { SSE2::instance() }; @@ -1342,7 +1342,7 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(all(target_feature = "ssse3", target_feature = "sse4.1")), ignore)] fn test_vec4_u32x4_s4() { let xs = [1, 2, 3, 4]; let s4 = unsafe { SSE41::instance() }; @@ -1358,7 +1358,6 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] fn test_vec2_u64x2_s2() { let xs = [0x1, 0x2]; let s2 = unsafe { SSE2::instance() }; @@ -1370,7 +1369,7 @@ mod test { } #[test] - #[cfg(target_arch = "x86_64")] + #[cfg_attr(not(all(target_feature = "ssse3", target_feature = "sse4.1")), ignore)] fn test_vec4_u64x2_s4() { let xs = [0x1, 0x2]; let s4 = unsafe { SSE41::instance() }; From 785bfbe9b89344de9978cb80758c07e2ca3cbde3 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 14:04:48 -0700 Subject: [PATCH 11/84] replace `simd` feature with `no_simd` `simd` does not make a useful feature, because there is no way for a user to be dependent on it being enabled (I don't expose any SIMD-only interfaces). Rather, `no_simd` is a feature, because some users can't compile SIMD intrinsics for various reasons. Fixes #25. This has the additional benefit of eliminating a default-feature, a facility I have found to be a Cargo misfeature. --- stream-ciphers/chacha/Cargo.toml | 7 ++++--- utils-simd/ppv-lite86/Cargo.toml | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index 0fccf0d4..ce954647 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c2-chacha" -version = "0.2.3" +version = "0.2.4" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" edition = "2018" @@ -20,10 +20,11 @@ stream-cipher = { version = "0.3", optional = true } hex-literal = "0.2" [features] -default = ["std", "simd", "rustcrypto_api"] +default = ["std", "rustcrypto_api"] std = ["ppv-lite86/std"] rustcrypto_api = ["stream-cipher", "byteorder"] -simd = ["ppv-lite86/simd"] +no_simd = ["ppv-lite86/no_simd"] +simd = [] # deprecated [badges] travis-ci = { repository = "cryptocorrosion/cryptocorrosion" } diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 7063090f..008543e0 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.7" +version = "0.2.8" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" @@ -15,6 +15,7 @@ categories = ["cryptography", "no-std"] travis-ci = { repository = "cryptocorrosion/cryptocorrosion" } [features] -default = ["std", "simd"] +default = ["std"] std = [] -simd = [] +simd = [] # deprecated +no_simd = [] # for weird platforms like "x86_64 without SSE2" From 3ee5be0bfe904a467b74367219ad26946cbe1d07 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 15:06:58 -0700 Subject: [PATCH 12/84] working toward 64-bit Blake support (And disable 64-bit blake tests until fixed) --- hashes/blake/tests/lib.rs | 4 ++-- utils-simd/ppv-lite86/src/generic.rs | 36 ++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/hashes/blake/tests/lib.rs b/hashes/blake/tests/lib.rs index 856a1861..a52edbf9 100644 --- a/hashes/blake/tests/lib.rs +++ b/hashes/blake/tests/lib.rs @@ -6,5 +6,5 @@ use digest::dev::digest_test; new_test!(blake224, "blake224", blake_hash::Blake224, digest_test); new_test!(blake256, "blake256", blake_hash::Blake256, digest_test); -new_test!(blake384, "blake384", blake_hash::Blake384, digest_test); -new_test!(blake512, "blake512", blake_hash::Blake512, digest_test); +//new_test!(blake384, "blake384", blake_hash::Blake384, digest_test); +//new_test!(blake512, "blake512", blake_hash::Blake512, digest_test); diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 7d8a779e..4f4113fc 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -22,6 +22,24 @@ impl From for [u32; 4] { unsafe { d.d } } } +impl From<[u64; 2]> for vec128_storage { + #[inline] + fn from(q: [u64; 2]) -> Self { + Self { q } + } +} +impl From for [u64; 2] { + #[inline] + fn from(q: vec128_storage) -> Self { + unsafe { q.q } + } +} +impl Default for vec128_storage { + #[inline] + fn default() -> Self { + Self { o: [0] } + } +} impl Eq for vec128_storage {} impl PartialEq for vec128_storage { #[inline] @@ -29,7 +47,7 @@ impl PartialEq for vec128_storage { unsafe { self.o == rhs.o } } } -#[derive(Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, PartialEq, Eq, Default)] pub struct vec256_storage { v128: [vec128_storage; 2], } @@ -43,7 +61,21 @@ impl vec256_storage { self.v128 } } -#[derive(Clone, Copy, PartialEq, Eq)] +impl From<[u64; 4]> for vec256_storage { + #[inline] + fn from(q: [u64; 4]) -> Self { + Self { v128: [[0, 1].into(), [2, 3].into()] } + } +} +impl From for [u64; 4] { + #[inline] + fn from(q: vec256_storage) -> Self { + let [a, b]: [u64; 2] = q.v128[0].into(); + let [c, d]: [u64; 2] = q.v128[1].into(); + [a, b, c, d] + } +} +#[derive(Clone, Copy, PartialEq, Eq, Default)] pub struct vec512_storage { v128: [vec128_storage; 4], } From 8bd2124d05c774febb90a6f0cc1b6bb875668037 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 15:20:00 -0700 Subject: [PATCH 13/84] officially increase MSRV to 1.32.0 Not sure how long build has been broken on 1.31.1, Travis was off. --- .travis.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6e997576..94fde947 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,7 +76,7 @@ matrix: - env: TARGET=x86_64-unknown-linux-gnu rust: stable - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.31.1 + rust: 1.32.0 # machine-specific tests are skipped based on static feature detection - env: TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-cpu=native" diff --git a/README.md b/README.md index 65ab2511..39fc22ab 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The main interface to these crates is the RustCrypto traits. All crates are no-std compatible. -Minimum Rust version: 1.31. +Minimum Rust version: 1.32.0 [![Build Status](https://travis-ci.org/cryptocorrosion/cryptocorrosion.svg?branch=master)](https://travis-ci.org/cryptocorrosion/cryptocorrosion) From 5f35a9f923de2beb56ea3d376bd47e095fad277c Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 16 May 2020 15:28:25 -0700 Subject: [PATCH 14/84] new c2-chacha and ppv-lite86 releases --- stream-ciphers/chacha/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index ce954647..cf6a1e86 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/c2-chacha" [dependencies] byteorder = { version = "1.3", optional = true } -ppv-lite86 = { package = "ppv-lite86", version = "0.2.6", default-features = false } +ppv-lite86 = { package = "ppv-lite86", version = "0.2.8", default-features = false } stream-cipher = { version = "0.3", optional = true } [dev-dependencies] From 88cad1dcb9e7da12b64fa762c74a128abb43bc7d Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 19 Aug 2020 14:27:32 -0700 Subject: [PATCH 15/84] use repr(C) for union; its correctness is clearer --- utils-simd/ppv-lite86/src/generic.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 4f4113fc..b663a169 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -4,6 +4,7 @@ use core::ops::*; use crate::soft::{x2, x4}; use crate::types::*; +#[repr(C)] #[derive(Clone, Copy)] pub union vec128_storage { d: [u32; 4], From 99df5dba5fa2471d51f58e3691621e5cd22d464d Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 19 Aug 2020 14:57:30 -0700 Subject: [PATCH 16/84] avoid u128 union members in portable code For wasm32 compatibility. Implements #33. --- utils-simd/ppv-lite86/Cargo.toml | 2 +- utils-simd/ppv-lite86/src/generic.rs | 27 +++++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 008543e0..84a59adc 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.8" +version = "0.2.9" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index b663a169..d26266c2 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -9,7 +9,6 @@ use crate::types::*; pub union vec128_storage { d: [u32; 4], q: [u64; 2], - o: [u128; 1], } impl From<[u32; 4]> for vec128_storage { #[inline] @@ -38,14 +37,14 @@ impl From for [u64; 2] { impl Default for vec128_storage { #[inline] fn default() -> Self { - Self { o: [0] } + Self { q: [0, 0] } } } impl Eq for vec128_storage {} impl PartialEq for vec128_storage { #[inline] fn eq(&self, rhs: &Self) -> bool { - unsafe { self.o == rhs.o } + unsafe { self.q == rhs.q } } } #[derive(Clone, Copy, PartialEq, Eq, Default)] @@ -152,14 +151,22 @@ where unsafe { T::unpack(q) } } +fn o_of_q(q: [u64; 2]) -> u128 { + u128::from(q[0]) | (u128::from(q[1]) << 64) +} + +fn q_of_o(o: u128) -> [u64; 2] { + [o as u64, (o >> 64) as u64] +} + fn omap(a: T, f: F) -> T where T: Store + Into, F: Fn(u128) -> u128, { let a: vec128_storage = a.into(); - let ao = unsafe { a.o }; - let o = vec128_storage { o: [f(ao[0])] }; + let ao = o_of_q(unsafe { a.q }); + let o = vec128_storage { q: q_of_o(f(ao)) }; unsafe { T::unpack(o) } } @@ -170,10 +177,10 @@ where { let a: vec128_storage = a.into(); let b: vec128_storage = b.into(); - let ao = unsafe { a.o }; - let bo = unsafe { b.o }; + let ao = o_of_q(unsafe { a.q }); + let bo = o_of_q(unsafe { b.q }); let o = vec128_storage { - o: [f(ao[0], bo[0])], + q: q_of_o(f(ao, bo)), }; unsafe { T::unpack(o) } } @@ -457,7 +464,7 @@ impl From for vec128_storage { impl From for vec128_storage { #[inline(always)] fn from(o: u128x1_generic) -> Self { - Self { o: o.0 } + Self { q: q_of_o(o.0[0]) } } } @@ -476,7 +483,7 @@ impl Store for u64x2_generic { impl Store for u128x1_generic { #[inline(always)] unsafe fn unpack(s: vec128_storage) -> Self { - Self(s.o) + Self([o_of_q(s.q); 1]) } } From 8169f9f17ee98c9ac01794df5a3ed089905c6c8a Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Fri, 18 Sep 2020 14:53:03 -0700 Subject: [PATCH 17/84] enable simd by default Correct features tests to fit the feature changes from 785bfbe fixes #35 --- test_alt_simd.sh | 14 ++++++-------- utils-simd/ppv-lite86/src/lib.rs | 8 ++++---- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/test_alt_simd.sh b/test_alt_simd.sh index 52c05d81..3886fd58 100755 --- a/test_alt_simd.sh +++ b/test_alt_simd.sh @@ -9,12 +9,10 @@ if [ -n "$FAILFAST" ]; then set -e; fi # not ported to crypto-simd API yet: # - hashes/groestl -echo BACKEND ppv-null -cd hashes/blake; cargo test --no-default-features; cd ../.. -cd hashes/jh; cargo test --no-default-features; cd ../.. -cd stream-ciphers/chacha; cargo test --no-default-features; cd ../.. +echo GENERIC +pushd stream-ciphers/chacha; cargo test --features no_simd; popd -echo BACKEND packed_simd -cd hashes/blake; cargo test --no-default-features --features packed_simd,std; cd ../.. -cd hashes/jh; cargo test -p jh-x86_64 --no-default-features --features packed_simd,std; cd ../.. -cd stream-ciphers/chacha; cargo test --no-default-features --features packed_simd,std; cd ../.. +#echo BACKEND packed_simd +#cd hashes/blake; cargo test --no-default-features --features packed_simd,std; cd ../.. +#cd hashes/jh; cargo test -p jh-x86_64 --no-default-features --features packed_simd,std; cd ../.. +#cd stream-ciphers/chacha; cargo test --no-default-features --features packed_simd,std; cd ../.. diff --git a/utils-simd/ppv-lite86/src/lib.rs b/utils-simd/ppv-lite86/src/lib.rs index 43dc5d86..ea89c512 100644 --- a/utils-simd/ppv-lite86/src/lib.rs +++ b/utils-simd/ppv-lite86/src/lib.rs @@ -9,14 +9,14 @@ mod soft; mod types; pub use self::types::*; -#[cfg(all(feature = "simd", target_arch = "x86_64", not(miri)))] +#[cfg(all(target_arch = "x86_64", not(feature = "no_simd"), not(miri)))] pub mod x86_64; -#[cfg(all(feature = "simd", target_arch = "x86_64", not(miri)))] +#[cfg(all(target_arch = "x86_64", not(feature = "no_simd"), not(miri)))] use self::x86_64 as arch; -#[cfg(any(miri, not(all(feature = "simd", any(target_arch = "x86_64")))))] +#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64")))] pub mod generic; -#[cfg(any(miri, not(all(feature = "simd", any(target_arch = "x86_64")))))] +#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64")))] use self::generic as arch; pub use self::arch::{vec128_storage, vec256_storage, vec512_storage}; From fae19dcd6fbde4ebe481111a6be16af167fae329 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 12 Jun 2020 16:49:46 +1200 Subject: [PATCH 18/84] Increase MSRV to 1.41.0 The new versions of the RustCrypto crates all have MSRV 1.41.0. --- .travis.yml | 2 +- README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 94fde947..7263cc74 100644 --- a/.travis.yml +++ b/.travis.yml @@ -76,7 +76,7 @@ matrix: - env: TARGET=x86_64-unknown-linux-gnu rust: stable - env: TARGET=x86_64-unknown-linux-gnu - rust: 1.32.0 + rust: 1.41.0 # machine-specific tests are skipped based on static feature detection - env: TARGET=x86_64-unknown-linux-gnu RUSTFLAGS="-C target-cpu=native" diff --git a/README.md b/README.md index 39fc22ab..37bc0e32 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ The main interface to these crates is the RustCrypto traits. All crates are no-std compatible. -Minimum Rust version: 1.32.0 +Minimum Rust version: 1.41.0 [![Build Status](https://travis-ci.org/cryptocorrosion/cryptocorrosion.svg?branch=master)](https://travis-ci.org/cryptocorrosion/cryptocorrosion) From aad6294f88f6bfba14f30f8fb713a2dc494a7b47 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 12 Jun 2020 16:55:09 +1200 Subject: [PATCH 19/84] c2-chacha: Migrate to stream-cipher 0.4 --- stream-ciphers/chacha/Cargo.toml | 5 ++--- stream-ciphers/chacha/src/rustcrypto_impl.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index cf6a1e86..17efe3a1 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -12,9 +12,8 @@ readme = "README.md" documentation = "https://docs.rs/c2-chacha" [dependencies] -byteorder = { version = "1.3", optional = true } ppv-lite86 = { package = "ppv-lite86", version = "0.2.8", default-features = false } -stream-cipher = { version = "0.3", optional = true } +stream-cipher = { version = "0.4", optional = true } [dev-dependencies] hex-literal = "0.2" @@ -22,7 +21,7 @@ hex-literal = "0.2" [features] default = ["std", "rustcrypto_api"] std = ["ppv-lite86/std"] -rustcrypto_api = ["stream-cipher", "byteorder"] +rustcrypto_api = ["stream-cipher"] no_simd = ["ppv-lite86/no_simd"] simd = [] # deprecated diff --git a/stream-ciphers/chacha/src/rustcrypto_impl.rs b/stream-ciphers/chacha/src/rustcrypto_impl.rs index ce74a63f..b63106ad 100644 --- a/stream-ciphers/chacha/src/rustcrypto_impl.rs +++ b/stream-ciphers/chacha/src/rustcrypto_impl.rs @@ -1,8 +1,8 @@ -use byteorder::{ByteOrder, LE}; -use core::cmp; use crate::guts::generic_array::typenum::{Unsigned, U10, U12, U24, U32, U4, U6, U8}; use crate::guts::generic_array::{ArrayLength, GenericArray}; use crate::guts::{ChaCha, Machine, BLOCK, BLOCK64, BUFSZ}; +use core::cmp; +use core::convert::TryInto; pub use stream_cipher; use stream_cipher::{LoopError, NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek}; @@ -241,12 +241,12 @@ dispatch_light128!(m, Mach, { let ctr_nonce = [ 0, if nonce.len() == 12 { - LE::read_u32(&nonce[0..4]) + u32::from_le_bytes(nonce[0..4].try_into().unwrap()) } else { 0 }, - LE::read_u32(&nonce[nonce.len() - 8..nonce.len() - 4]), - LE::read_u32(&nonce[nonce.len() - 4..]), + u32::from_le_bytes(nonce[nonce.len() - 8..nonce.len() - 4].try_into().unwrap()), + u32::from_le_bytes(nonce[nonce.len() - 4..].try_into().unwrap()), ]; let key0: Mach::u32x4 = m.read_le(&key[..16]); let key1: Mach::u32x4 = m.read_le(&key[16..]); @@ -276,8 +276,8 @@ dispatch_light128!(m, Mach, { let ctr_nonce1 = [ 0, 0, - LE::read_u32(&nonce[16..20]), - LE::read_u32(&nonce[20..24]), + u32::from_le_bytes(nonce[16..20].try_into().unwrap()), + u32::from_le_bytes(nonce[20..24].try_into().unwrap()), ]; state.b = x.a; state.c = x.d; From d00e80bc011eeb57d3cdf98b9c1cb5cf62337f84 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 12 Jun 2020 17:21:00 +1200 Subject: [PATCH 20/84] skein: Migrate to digest 0.9 Requires migrating threefish-cipher to block-cipher 0.7. --- block-ciphers/threefish/Cargo.toml | 4 +--- block-ciphers/threefish/src/lib.rs | 29 +++++++++++++++-------------- hashes/skein/Cargo.toml | 7 +++---- hashes/skein/src/lib.rs | 22 +++++++++------------- 4 files changed, 28 insertions(+), 34 deletions(-) diff --git a/block-ciphers/threefish/Cargo.toml b/block-ciphers/threefish/Cargo.toml index 122e0b04..40c48322 100644 --- a/block-ciphers/threefish/Cargo.toml +++ b/block-ciphers/threefish/Cargo.toml @@ -9,9 +9,7 @@ repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "threefish", "gost", "block-cipher"] [dependencies] -generic-array = "0.12" -byteorder = { version = "1", default-features = false } -block-cipher-trait = "0.6" +block-cipher = "0.7" [dev-dependencies] hex-literal = "0.2" diff --git a/block-ciphers/threefish/src/lib.rs b/block-ciphers/threefish/src/lib.rs index e5c46d59..4418ad26 100644 --- a/block-ciphers/threefish/src/lib.rs +++ b/block-ciphers/threefish/src/lib.rs @@ -1,20 +1,18 @@ #![no_std] #![allow(non_upper_case_globals)] -extern crate block_cipher_trait; -extern crate byteorder; -extern crate generic_array; +extern crate block_cipher; #[cfg(test)] #[macro_use] extern crate hex_literal; +use core::convert::TryInto; use core::ops::BitXor; mod consts; use consts::{C240, P_1024, P_256, P_512, R_1024, R_256, R_512}; -use block_cipher_trait::generic_array::typenum::{U1, U128, U32, U64}; -use block_cipher_trait::generic_array::GenericArray; -pub use block_cipher_trait::BlockCipher; -use byteorder::{ByteOrder, LE}; +use block_cipher::generic_array::typenum::{U1, U128, U32, U64}; +use block_cipher::generic_array::GenericArray; +pub use block_cipher::{BlockCipher, NewBlockCipher}; fn mix(r: u32, x: (u64, u64)) -> (u64, u64) { let y0 = x.0.wrapping_add(x.1); @@ -30,13 +28,13 @@ fn inv_mix(r: u32, y: (u64, u64)) -> (u64, u64) { fn read_u64v_le(ns: &mut [u64], buf: &[u8]) { for (c, n) in buf.chunks_exact(8).zip(ns) { - *n = LE::read_u64(c); + *n = u64::from_le_bytes(c.try_into().unwrap()); } } fn write_u64v_le(buf: &mut [u8], ns: &[u64]) { for (c, n) in buf.chunks_exact_mut(8).zip(ns) { - LE::write_u64(c, *n); + c.copy_from_slice(&n.to_le_bytes()); } } @@ -120,14 +118,17 @@ macro_rules! impl_threefish( } } - impl BlockCipher for $name { - type BlockSize = $block_size; + impl NewBlockCipher for $name { type KeySize = $block_size; - type ParBlocks = U1; fn new(key: &GenericArray) -> $name { Self::with_tweak(key, 0, 0) } + } + + impl BlockCipher for $name { + type BlockSize = $block_size; + type ParBlocks = U1; fn encrypt_block(&self, block: &mut GenericArray) { @@ -208,8 +209,8 @@ mod test { //! tests from NIST submission use super::{Threefish1024, Threefish256, Threefish512}; - use block_cipher_trait::generic_array::GenericArray; - use block_cipher_trait::BlockCipher; + use block_cipher::generic_array::GenericArray; + use block_cipher::{BlockCipher, NewBlockCipher}; #[test] fn test_256() { diff --git a/hashes/skein/Cargo.toml b/hashes/skein/Cargo.toml index e5a85ea8..d7754fa6 100644 --- a/hashes/skein/Cargo.toml +++ b/hashes/skein/Cargo.toml @@ -9,10 +9,9 @@ keywords = ["crypto", "skein", "hash", "digest"] categories = ["cryptography", "no-std"] [dependencies] -block-buffer = "0.7" -block-padding = "0.1.0" -digest = "0.8" +block-buffer = { version = "0.9", features = ["block-padding"] } +digest = "0.9" threefish-cipher = "0.3" [dev-dependencies] -digest = { version = "0.8", features = ["dev"] } +digest = { version = "0.9", features = ["dev"] } diff --git a/hashes/skein/src/lib.rs b/hashes/skein/src/lib.rs index edf82eef..52391449 100644 --- a/hashes/skein/src/lib.rs +++ b/hashes/skein/src/lib.rs @@ -3,16 +3,14 @@ #![no_std] extern crate block_buffer; -extern crate block_padding; pub extern crate digest; extern crate threefish_cipher; pub use digest::generic_array::GenericArray; pub use digest::Digest; -use block_buffer::byteorder::{ByteOrder, LE}; use block_buffer::BlockBuffer; -use block_padding::ZeroPadding; +use block_buffer::block_padding::ZeroPadding; use digest::generic_array::typenum::{NonZero, PartialDiv, Unsigned, U128, U32, U64, U8}; use digest::generic_array::ArrayLength; use threefish_cipher::{BlockCipher, Threefish1024, Threefish256, Threefish512}; @@ -176,9 +174,9 @@ macro_rules! define_hasher { Block::default(), ); let mut cfg = GenericArray::::default(); - LE::write_u64(&mut cfg[..8], SCHEMA_VER); - LE::write_u64(&mut cfg[8..16], N::to_u64() * 8); - LE::write_u64(&mut cfg[16..24], CFG_TREE_INFO_SEQUENTIAL); + cfg[..8].copy_from_slice(&SCHEMA_VER.to_le_bytes()); + cfg[8..16].copy_from_slice(&(N::to_u64() * 8).to_le_bytes()); + cfg[16..24].copy_from_slice(&CFG_TREE_INFO_SEQUENTIAL.to_le_bytes()); Self::process_block(&mut state, &cfg, CFG_STR_LEN); // The chaining vars ctx->X are now initialized for the given hashBitLen. @@ -200,11 +198,11 @@ macro_rules! define_hasher { type BlockSize = <$threefish as BlockCipher>::BlockSize; } - impl digest::Input for $name + impl digest::Update for $name where N: Unsigned + ArrayLength + NonZero + Default, { - fn input>(&mut self, data: T) { + fn update(&mut self, data: impl AsRef<[u8]>) { let buffer = &mut self.buffer; let state = &mut self.state; buffer.input_lazy(data.as_ref(), |block| { @@ -213,32 +211,30 @@ macro_rules! define_hasher { } } - impl digest::FixedOutput for $name + impl digest::FixedOutputDirty for $name where N: Unsigned + ArrayLength + NonZero + Default, { type OutputSize = N; - fn fixed_result(mut self) -> GenericArray { + fn finalize_into_dirty(&mut self, output: &mut GenericArray) { self.state.t.1 |= T1_FLAG_FINAL; let pos = self.buffer.position(); let final_block = self.buffer.pad_with::().unwrap(); Self::process_block(&mut self.state, final_block, pos); // run Threefish in "counter mode" to generate output - let mut output = GenericArray::default(); for (i, chunk) in output.chunks_mut($state_bits / 8).enumerate() { let mut ctr = State::new( T1_FLAG_FIRST | T1_BLK_TYPE_OUT | T1_FLAG_FINAL, self.state.x, ); let mut b = GenericArray::::default(); - LE::write_u64(&mut b[..8], i as u64); + b[..8].copy_from_slice(&(i as u64).to_le_bytes()); Self::process_block(&mut ctr, &b, 8); let n = chunk.len(); chunk.copy_from_slice(&ctr.x.bytes()[..n]); } - output } } From 35c26e20aa2ed998b556a25aaeb650dee85eef72 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 12 Jun 2020 17:38:26 +1200 Subject: [PATCH 21/84] blake-hash: Migrate to digest 0.9 --- hashes/blake/Cargo.toml | 6 +++--- hashes/blake/src/lib.rs | 46 ++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/hashes/blake/Cargo.toml b/hashes/blake/Cargo.toml index d38346b0..92a98d14 100644 --- a/hashes/blake/Cargo.toml +++ b/hashes/blake/Cargo.toml @@ -9,8 +9,8 @@ keywords = ["crypto", "blake", "hash", "digest"] categories = ["cryptography", "no-std"] [dependencies] -block-buffer = "0.7" -digest = "0.8" +block-buffer = "0.9" +digest = "0.9" simd = { package = "ppv-lite86", version = "0.2.6", optional = true } [features] @@ -18,7 +18,7 @@ default = ["simd", "std"] std = [] [dev-dependencies] -digest = { version = "0.8", features = ["dev"] } +digest = { version = "0.9", features = ["dev"] } [badges] travis-ci = { repository = "cryptocorrosion/cryptocorrosion" } diff --git a/hashes/blake/src/lib.rs b/hashes/blake/src/lib.rs index 69cd9a72..08a2cad0 100644 --- a/hashes/blake/src/lib.rs +++ b/hashes/blake/src/lib.rs @@ -13,8 +13,8 @@ pub extern crate simd; mod consts; -use block_buffer::byteorder::{ByteOrder, BE}; use block_buffer::BlockBuffer; +use core::convert::TryInto; use core::mem; use digest::generic_array::typenum::{PartialDiv, Unsigned, U2}; use digest::generic_array::GenericArray; @@ -84,7 +84,7 @@ fn undiagonalize((a, b, c, d): (X4, X4, X4, X4)) -> (X4, X4, X4, X4) } macro_rules! define_compressor { - ($compressor:ident, $storage:ident, $word:ident, $Bufsz:ty, $deserializer:path, $uval:expr, $rounds:expr, $round:ident, $X4:ident) => { + ($compressor:ident, $storage:ident, $word:ident, $Bufsz:ty, $uval:expr, $rounds:expr, $round:ident, $X4:ident) => { #[derive(Clone, Copy, Default)] pub struct $compressor { h: [$storage; 2], @@ -102,7 +102,7 @@ macro_rules! define_compressor { .iter_mut() .zip(block.chunks_exact(mem::size_of::<$word>())) { - *mx = $deserializer(b); + *mx = $word::from_be_bytes(b.try_into().unwrap()); } let u = (mach.vec([U[0], U[1], U[2], U[3]]), mach.vec([U[4], U[5], U[6], U[7]])); @@ -158,7 +158,7 @@ macro_rules! define_compressor { macro_rules! define_hasher { ($name:ident, $word:ident, $buf:expr, $Bufsz:ty, $bits:expr, $Bytes:ident, - $serializer:path, $compressor:ident, $iv:expr) => { + $compressor:ident, $iv:expr) => { #[derive(Clone)] pub struct $name { compressor: $compressor, @@ -198,30 +198,30 @@ macro_rules! define_hasher { type BlockSize = $Bytes; } - impl digest::Input for $name { - fn input>(&mut self, data: T) { + impl digest::Update for $name { + fn update(&mut self, data: impl AsRef<[u8]>) { let compressor = &mut self.compressor; let t = &mut self.t; - self.buffer.input(data.as_ref(), |block| { + self.buffer.input_block(data.as_ref(), |block| { Self::increase_count(t, (mem::size_of::<$word>() * 16) as $word); compressor.put_block(block, *t); }); } } - impl digest::FixedOutput for $name { + impl digest::FixedOutputDirty for $name { type OutputSize = $Bytes; - fn fixed_result(self) -> GenericArray { + fn finalize_into_dirty(&mut self, out: &mut GenericArray) { let mut compressor = self.compressor; - let mut buffer = self.buffer; + let buffer = &mut self.buffer; let mut t = self.t; Self::increase_count(&mut t, buffer.position() as $word); let mut msglen = [0u8; $buf / 8]; - $serializer(&mut msglen[..$buf / 16], t.1); - $serializer(&mut msglen[$buf / 16..], t.0); + msglen[..$buf / 16].copy_from_slice(&t.1.to_be_bytes()); + msglen[$buf / 16..].copy_from_slice(&t.0.to_be_bytes()); let footerlen = 1 + 2 * mem::size_of::<$word>(); @@ -239,7 +239,7 @@ macro_rules! define_hasher { let extra_block = buffer.position() + footerlen > $buf; if extra_block { let pad = $buf - buffer.position(); - buffer.input(&PADDING[..pad], |block| compressor.put_block(block, t)); + buffer.input_block(&PADDING[..pad], |block| compressor.put_block(block, t)); debug_assert_eq!(buffer.position(), 0); } @@ -251,12 +251,12 @@ macro_rules! define_hasher { // skip begin-padding byte if continuing padding let x = extra_block as usize; let (start, end) = (x, x + ($buf - footerlen - buffer.position())); - buffer.input(&PADDING[start..end], |_| unreachable!()); - buffer.input(&[magic], |_| unreachable!()); - buffer.input(&msglen, |block| compressor.put_block(block, t)); + buffer.input_block(&PADDING[start..end], |_| unreachable!()); + buffer.input_block(&[magic], |_| unreachable!()); + buffer.input_block(&msglen, |block| compressor.put_block(block, t)); debug_assert_eq!(buffer.position(), 0); - GenericArray::clone_from_slice(&compressor.finalize()[..$Bytes::to_usize()]) + out.as_mut_slice().copy_from_slice(&compressor.finalize()[..$Bytes::to_usize()]); } } @@ -274,19 +274,19 @@ use consts::{ use digest::generic_array::typenum::{U128, U28, U32, U48, U64}; #[rustfmt::skip] -define_compressor!(Compressor256, vec128_storage, u32, U64, BE::read_u32, BLAKE256_U, 14, round32, u32x4); +define_compressor!(Compressor256, vec128_storage, u32, U64, BLAKE256_U, 14, round32, u32x4); #[rustfmt::skip] -define_hasher!(Blake224, u32, 64, U64, 224, U28, BE::write_u32, Compressor256, BLAKE224_IV); +define_hasher!(Blake224, u32, 64, U64, 224, U28, Compressor256, BLAKE224_IV); #[rustfmt::skip] -define_hasher!(Blake256, u32, 64, U64, 256, U32, BE::write_u32, Compressor256, BLAKE256_IV); +define_hasher!(Blake256, u32, 64, U64, 256, U32, Compressor256, BLAKE256_IV); #[rustfmt::skip] -define_compressor!(Compressor512, vec256_storage, u64, U128, BE::read_u64, BLAKE512_U, 16, round64, u64x4); +define_compressor!(Compressor512, vec256_storage, u64, U128, BLAKE512_U, 16, round64, u64x4); #[rustfmt::skip] -define_hasher!(Blake384, u64, 128, U128, 384, U48, BE::write_u64, Compressor512, BLAKE384_IV); +define_hasher!(Blake384, u64, 128, U128, 384, U48, Compressor512, BLAKE384_IV); #[rustfmt::skip] -define_hasher!(Blake512, u64, 128, U128, 512, U64, BE::write_u64, Compressor512, BLAKE512_IV); +define_hasher!(Blake512, u64, 128, U128, 512, U64, Compressor512, BLAKE512_IV); From 15e5c9ba8454431803e8feb7fb7341441b8825a2 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 12 Jun 2020 18:49:40 +1200 Subject: [PATCH 22/84] groestl: Migrate to digest 0.9 --- hashes/groestl/Cargo.toml | 6 ++-- hashes/groestl/src/lib.rs | 65 +++++++++++++++++---------------------- 2 files changed, 32 insertions(+), 39 deletions(-) diff --git a/hashes/groestl/Cargo.toml b/hashes/groestl/Cargo.toml index dc0b8469..c5bd86ee 100644 --- a/hashes/groestl/Cargo.toml +++ b/hashes/groestl/Cargo.toml @@ -11,12 +11,12 @@ repository = "https://github.com/cryptocorrosion/hashes" edition = "2018" [dependencies] -block-buffer = "0.7" -digest = "0.8" +block-buffer = "0.9" +digest = "0.9" lazy_static = { version = "1.2", optional = true } [dev-dependencies] -digest = { version = "0.8", features = ["dev"] } +digest = { version = "0.9", features = ["dev"] } [features] std = ["lazy_static"] diff --git a/hashes/groestl/src/lib.rs b/hashes/groestl/src/lib.rs index 212a464f..0b893ba6 100644 --- a/hashes/groestl/src/lib.rs +++ b/hashes/groestl/src/lib.rs @@ -10,7 +10,6 @@ pub extern crate digest; #[macro_use] extern crate lazy_static; -use block_buffer::byteorder::{BigEndian, ByteOrder, LE}; use block_buffer::generic_array::typenum::{ PartialDiv, Unsigned, U1024, U128, U16, U28, U48, U512, U64, U8, }; @@ -43,7 +42,7 @@ impl Compressor512 { fn input(&mut self, data: &BBGenericArray) { tf512(&mut self.cv, data); } - fn finalize(mut self) -> Block512 { + fn finalize_dirty(&mut self) -> Block512 { of512(&mut self.cv); unsafe { CvBytes512 { cv: self.cv }.block } } @@ -66,7 +65,7 @@ impl Compressor1024 { fn input(&mut self, data: &BBGenericArray) { tf1024(&mut self.cv, data); } - fn finalize(mut self) -> Block1024 { + fn finalize_dirty(&mut self) -> Block1024 { of1024(&mut self.cv); unsafe { CvBytes1024 { cv: self.cv }.block } } @@ -91,12 +90,12 @@ macro_rules! impl_digest { block_counter: 0, } } - fn finalize(self) -> [u64; $bits::USIZE / 64] { - let mut buffer = self.buffer; - let mut compressor = self.compressor; + fn finalize_dirty(&mut self) -> [u64; $bits::USIZE / 64] { + let buffer = &mut self.buffer; + let compressor = &mut self.compressor; let count = self.block_counter + 1 + (buffer.remaining() <= 8) as u64; - buffer.len64_padding::(count, |b| compressor.input(b)); - compressor.finalize() + buffer.len64_padding_be(count, |b| compressor.input(b)); + compressor.finalize_dirty() } } impl Default for $groestl { @@ -112,25 +111,23 @@ macro_rules! impl_digest { impl digest::BlockInput for $groestl { type BlockSize = <$bits as PartialDiv>::Output; } - impl digest::Input for $groestl { - fn input>(&mut self, data: T) { + impl digest::Update for $groestl { + fn update(&mut self, data: impl AsRef<[u8]>) { let block_counter = &mut self.block_counter; let compressor = &mut self.compressor; - self.buffer.input(data.as_ref(), |b| { + self.buffer.input_block(data.as_ref(), |b| { *block_counter += 1; compressor.input(b) }); } } - impl digest::FixedOutput for $groestl { + impl digest::FixedOutputDirty for $groestl { type OutputSize = <$bits as PartialDiv>::Output; - fn fixed_result(self) -> DGenericArray { - let result = self.finalize(); - let mut out: DGenericArray = DGenericArray::default(); + fn finalize_into_dirty(&mut self, out: &mut DGenericArray) { + let result = self.finalize_dirty(); for (out, &input) in out.chunks_exact_mut(8).zip(&result[$bits::USIZE / 128..]) { - LE::write_u64(out, input); + out.copy_from_slice(&input.to_le_bytes()); } - out } } impl digest::Reset for $groestl { @@ -154,21 +151,19 @@ impl Default for Groestl224 { impl digest::BlockInput for Groestl224 { type BlockSize = U64; } -impl digest::Input for Groestl224 { - fn input>(&mut self, data: T) { - digest::Input::input(&mut self.0, data.as_ref()); +impl digest::Update for Groestl224 { + fn update(&mut self, data: impl AsRef<[u8]>) { + digest::Update::update(&mut self.0, data.as_ref()); } } -impl digest::FixedOutput for Groestl224 { +impl digest::FixedOutputDirty for Groestl224 { type OutputSize = U28; - fn fixed_result(self) -> DGenericArray { - let result = self.0.finalize(); - let mut out: DGenericArray = DGenericArray::default(); - LE::write_u32(&mut out[..4], (result[4] >> 32) as u32); + fn finalize_into_dirty(&mut self, out: &mut DGenericArray) { + let result = self.0.finalize_dirty(); + out[..4].copy_from_slice(&((result[4] >> 32) as u32).to_le_bytes()); for (out, &input) in out[4..].chunks_exact_mut(8).zip(&result[5..8]) { - LE::write_u64(out, input); + out.copy_from_slice(&input.to_le_bytes()); } - out } } impl digest::Reset for Groestl224 { @@ -187,20 +182,18 @@ impl Default for Groestl384 { impl digest::BlockInput for Groestl384 { type BlockSize = ::BlockSize; } -impl digest::Input for Groestl384 { - fn input>(&mut self, data: T) { - digest::Input::input(&mut self.0, data.as_ref()); +impl digest::Update for Groestl384 { + fn update(&mut self, data: impl AsRef<[u8]>) { + digest::Update::update(&mut self.0, data.as_ref()); } } -impl digest::FixedOutput for Groestl384 { +impl digest::FixedOutputDirty for Groestl384 { type OutputSize = U48; - fn fixed_result(self) -> DGenericArray { - let result = self.0.finalize(); - let mut out: DGenericArray = DGenericArray::default(); + fn finalize_into_dirty(&mut self, out: &mut DGenericArray) { + let result = self.0.finalize_dirty(); for (out, &input) in out.chunks_exact_mut(8).zip(&result[10..]) { - LE::write_u64(out, input); + out.copy_from_slice(&input.to_le_bytes()); } - out } } impl digest::Reset for Groestl384 { From ec0bc35a1189276e52a1870b332b2eb041743e82 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Fri, 12 Jun 2020 18:55:16 +1200 Subject: [PATCH 23/84] jh: Migrate to digest 0.9 --- hashes/jh/Cargo.toml | 6 +++--- hashes/jh/src/lib.rs | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index e8bb569f..d73262f7 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -11,13 +11,13 @@ repository = "https://github.com/cryptocorrosion/cryptocorrosion" edition = "2018" [dependencies] -block-buffer = "0.7" -digest = "0.8" +block-buffer = "0.9" +digest = "0.9" hex-literal = "0.2" simd = { package = "ppv-lite86", version = "0.2.6" } [dev-dependencies] -digest = { version = "0.8", features = ["dev"] } +digest = { version = "0.9", features = ["dev"] } [build-dependencies] cc = "1.0.3" diff --git a/hashes/jh/src/lib.rs b/hashes/jh/src/lib.rs index 1cded6db..0d0bbf3a 100644 --- a/hashes/jh/src/lib.rs +++ b/hashes/jh/src/lib.rs @@ -15,7 +15,6 @@ mod consts; pub use digest::Digest; -use block_buffer::byteorder::{BigEndian, ByteOrder}; use block_buffer::generic_array::GenericArray as BBGenericArray; use block_buffer::BlockBuffer; use core::fmt::{Debug, Formatter, Result}; @@ -56,33 +55,33 @@ macro_rules! define_hasher { type BlockSize = U64; } - impl digest::Input for $name { - fn input>(&mut self, data: T) { + impl digest::Update for $name { + fn update(&mut self, data: impl AsRef<[u8]>) { let data = data.as_ref(); self.datalen += data.len(); let state = &mut self.state; - self.buffer.input(data, |b| state.input(b)) + self.buffer.input_block(data, |b| state.input(b)) } } - impl digest::FixedOutput for $name { + impl digest::FixedOutputDirty for $name { type OutputSize = $OutputBytes; - fn fixed_result(mut self) -> DGenericArray { + fn finalize_into_dirty(&mut self, out: &mut DGenericArray) { let state = &mut self.state; let buffer = &mut self.buffer; let len = self.datalen as u64 * 8; if buffer.position() == 0 { - buffer.len64_padding::(len, |b| state.input(b)); + buffer.len64_padding_be(len, |b| state.input(b)); } else { use block_buffer::block_padding::Iso7816; state.input(buffer.pad_with::().unwrap()); let mut last = BBGenericArray::default(); - BigEndian::write_u64(&mut last[56..], len); + last[56..].copy_from_slice(&len.to_be_bytes()); state.input(&last); } let finalized = self.state.finalize(); - DGenericArray::clone_from_slice(&finalized[(128 - $OutputBytes::to_usize())..]) + out.as_mut_slice().copy_from_slice(&finalized[(128 - $OutputBytes::to_usize())..]); } } From 7be1e5369b9a58dfb0b68d80f0464aa5b605998c Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 15 Jun 2020 17:42:16 +0000 Subject: [PATCH 24/84] docs: MSRV bump does not apply to support crates --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 37bc0e32..63dfb239 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,9 @@ The main interface to these crates is the RustCrypto traits. All crates are no-std compatible. -Minimum Rust version: 1.41.0 +Minimum Rust version: +- algorithm crates (with RustCrypto API): 1.41.0 +- support crates: 1.32.0 [![Build Status](https://travis-ci.org/cryptocorrosion/cryptocorrosion.svg?branch=master)](https://travis-ci.org/cryptocorrosion/cryptocorrosion) From affccb0519774ef527d7f1af28d751602205816b Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 15 Jun 2020 17:52:03 +0000 Subject: [PATCH 25/84] test different MSRVs by crate --- ci/script.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/ci/script.sh b/ci/script.sh index 6bf55341..c20b5d3e 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -27,10 +27,24 @@ portable_only() { cross test --target $TARGET --release -p c2-chacha -p ppv-lite86 } +older_msrv_crates() { + cross build --target $TARGET -p ppv-lite86 + cross build --target $TARGET --release -p ppv-lite86 + + if [ ! -z $DISABLE_TESTS ]; then + return + fi + + cross test --target $TARGET -p ppv-lite86 + cross test --target $TARGET --release -p ppv-lite86 +} + # we don't run the "test phase" when doing deploys if [ -z $TRAVIS_TAG ]; then if [ -z $PORTABLE_ONLY ]; then main + elif [ -z $OLDER_MSRV_CRATES ]; then + older_msrv_crates else portable_only fi From e79eb66e381b0f29eff29172482d41d7d80bda3b Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 15 Jun 2020 17:53:25 +0000 Subject: [PATCH 26/84] maintain older MSRV for some crates --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 7263cc74..4b54219e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -75,6 +75,8 @@ matrix: rust: nightly - env: TARGET=x86_64-unknown-linux-gnu rust: stable + - env: TARGET=x86_64-unknown-linux-gnu OLDER_MSRV_CRATES=1 DISABLE_TESTS=1 + rust: 1.32.0 - env: TARGET=x86_64-unknown-linux-gnu rust: 1.41.0 From 1e468bc1b5570e784ee131605e65171b5a9c1021 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 15 Jun 2020 18:24:36 +0000 Subject: [PATCH 27/84] fix travis script --- ci/script.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/script.sh b/ci/script.sh index c20b5d3e..1662a2a7 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -41,11 +41,11 @@ older_msrv_crates() { # we don't run the "test phase" when doing deploys if [ -z $TRAVIS_TAG ]; then - if [ -z $PORTABLE_ONLY ]; then - main - elif [ -z $OLDER_MSRV_CRATES ]; then + if [ -n $PORTABLE_ONLY ]; then + portable_only + elif [ -n $OLDER_MSRV_CRATES ]; then older_msrv_crates else - portable_only + main fi fi From 97a78c9dbdb1b36afa9948c342dca2e60829730d Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 15 Jun 2020 18:36:22 +0000 Subject: [PATCH 28/84] shell is hard --- ci/script.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/script.sh b/ci/script.sh index 1662a2a7..268c5483 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -41,9 +41,9 @@ older_msrv_crates() { # we don't run the "test phase" when doing deploys if [ -z $TRAVIS_TAG ]; then - if [ -n $PORTABLE_ONLY ]; then + if [ -n "$PORTABLE_ONLY" ]; then portable_only - elif [ -n $OLDER_MSRV_CRATES ]; then + elif [ -n "$OLDER_MSRV_CRATES" ]; then older_msrv_crates else main From d84373e79306aedfe5813eb76d6fc9b17cee10e7 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Mon, 22 Jun 2020 13:06:04 +1200 Subject: [PATCH 29/84] Remove unnecessary GenericArray::as_mut_slice calls --- hashes/blake/src/lib.rs | 2 +- hashes/jh/src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hashes/blake/src/lib.rs b/hashes/blake/src/lib.rs index 08a2cad0..1cbc67d9 100644 --- a/hashes/blake/src/lib.rs +++ b/hashes/blake/src/lib.rs @@ -256,7 +256,7 @@ macro_rules! define_hasher { buffer.input_block(&msglen, |block| compressor.put_block(block, t)); debug_assert_eq!(buffer.position(), 0); - out.as_mut_slice().copy_from_slice(&compressor.finalize()[..$Bytes::to_usize()]); + out.copy_from_slice(&compressor.finalize()[..$Bytes::to_usize()]); } } diff --git a/hashes/jh/src/lib.rs b/hashes/jh/src/lib.rs index 0d0bbf3a..b94520f7 100644 --- a/hashes/jh/src/lib.rs +++ b/hashes/jh/src/lib.rs @@ -81,7 +81,7 @@ macro_rules! define_hasher { state.input(&last); } let finalized = self.state.finalize(); - out.as_mut_slice().copy_from_slice(&finalized[(128 - $OutputBytes::to_usize())..]); + out.copy_from_slice(&finalized[(128 - $OutputBytes::to_usize())..]); } } From ede56cee70e5731c3e87e41aafdb3cc171cbe5b4 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 14 Jul 2020 11:39:00 +1200 Subject: [PATCH 30/84] c2-chacha: Migrate to stream-cipher 0.6 --- stream-ciphers/chacha/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index 17efe3a1..098042f3 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/c2-chacha" [dependencies] ppv-lite86 = { package = "ppv-lite86", version = "0.2.8", default-features = false } -stream-cipher = { version = "0.4", optional = true } +stream-cipher = { version = "0.6", optional = true } [dev-dependencies] hex-literal = "0.2" From c622fec5ab4ff2ea93954ffa992b318c82095466 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Tue, 14 Jul 2020 11:39:42 +1200 Subject: [PATCH 31/84] threefish-cipher: Migrate to block-cipher 0.8 --- block-ciphers/threefish/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block-ciphers/threefish/Cargo.toml b/block-ciphers/threefish/Cargo.toml index 40c48322..17eb1899 100644 --- a/block-ciphers/threefish/Cargo.toml +++ b/block-ciphers/threefish/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "threefish", "gost", "block-cipher"] [dependencies] -block-cipher = "0.7" +block-cipher = "0.8" [dev-dependencies] hex-literal = "0.2" From e42d7188d5a40cf3d1cdd09a26799d73dde6bf1c Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Sun, 30 Aug 2020 18:52:20 +0100 Subject: [PATCH 32/84] c2-chacha: Migrate to stream-cipher 0.7 --- stream-ciphers/chacha/Cargo.toml | 2 +- stream-ciphers/chacha/src/rustcrypto_impl.rs | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index 098042f3..e7b9ecd4 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/c2-chacha" [dependencies] ppv-lite86 = { package = "ppv-lite86", version = "0.2.8", default-features = false } -stream-cipher = { version = "0.6", optional = true } +stream-cipher = { version = "0.7", optional = true } [dev-dependencies] hex-literal = "0.2" diff --git a/stream-ciphers/chacha/src/rustcrypto_impl.rs b/stream-ciphers/chacha/src/rustcrypto_impl.rs index b63106ad..f28a5ad0 100644 --- a/stream-ciphers/chacha/src/rustcrypto_impl.rs +++ b/stream-ciphers/chacha/src/rustcrypto_impl.rs @@ -4,7 +4,9 @@ use crate::guts::{ChaCha, Machine, BLOCK, BLOCK64, BUFSZ}; use core::cmp; use core::convert::TryInto; pub use stream_cipher; -use stream_cipher::{LoopError, NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek}; +use stream_cipher::{ + LoopError, NewStreamCipher, OverflowError, SeekNum, SyncStreamCipher, SyncStreamCipherSeek, +}; const BIG_LEN: u64 = 0; const SMALL_LEN: u64 = 1 << 32; @@ -206,12 +208,14 @@ impl NewStreamCipher for ChaChaAny { impl SyncStreamCipherSeek for ChaChaAny { #[inline] - fn current_pos(&self) -> u64 { + fn try_current_pos(&self) -> Result { unimplemented!() } #[inline(always)] - fn seek(&mut self, ct: u64) { - Self::seek(self, ct) + fn try_seek(&mut self, pos: T) -> Result<(), LoopError> { + pos.try_into() + .map_err(|_| LoopError) + .map(|ct| Self::seek(self, ct)) } } From 96bb212bd1819e4105b61c5c8a297206f38bfda9 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Fri, 18 Sep 2020 15:08:13 -0700 Subject: [PATCH 33/84] remove broken function fixes #32 --- utils-simd/ppv-lite86/src/generic.rs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index d26266c2..0da6a133 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -61,12 +61,6 @@ impl vec256_storage { self.v128 } } -impl From<[u64; 4]> for vec256_storage { - #[inline] - fn from(q: [u64; 4]) -> Self { - Self { v128: [[0, 1].into(), [2, 3].into()] } - } -} impl From for [u64; 4] { #[inline] fn from(q: vec256_storage) -> Self { From 0dec28b9d04c96cbff95c8b894f90067dbff30ae Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Fri, 18 Sep 2020 15:19:47 -0700 Subject: [PATCH 34/84] eliminate build warnings cf. #37 --- hashes/blake/src/lib.rs | 1 - stream-ciphers/chacha/src/guts.rs | 6 +++--- utils-simd/ppv-lite86/src/types.rs | 1 + utils-simd/ppv-lite86/src/x86_64/sse2.rs | 5 +++-- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/hashes/blake/src/lib.rs b/hashes/blake/src/lib.rs index 1cbc67d9..b8ab5221 100644 --- a/hashes/blake/src/lib.rs +++ b/hashes/blake/src/lib.rs @@ -8,7 +8,6 @@ use std as core; extern crate block_buffer; pub extern crate digest; -#[macro_use] pub extern crate simd; mod consts; diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 94a2697a..4649bcc7 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -255,7 +255,7 @@ dispatch!(m, Mach, { } }); -/// Refill the buffer from a single-block round, updating the block count. +// Refill the buffer from a single-block round, updating the block count. dispatch_light128!(m, Mach, { fn refill_narrow(state: &mut ChaCha, drounds: u32, out: &mut [u8; BLOCK]) { let x = refill_narrow_rounds(state, drounds); @@ -270,8 +270,8 @@ dispatch_light128!(m, Mach, { } }); -/// Single-block, rounds-only; shared by try_apply_keystream for tails shorter than BUFSZ -/// and XChaCha's setup step. +// Single-block, rounds-only; shared by try_apply_keystream for tails shorter than BUFSZ +// and XChaCha's setup step. dispatch!(m, Mach, { fn refill_narrow_rounds(state: &mut ChaCha, drounds: u32) -> State { let k: Mach::u32x4 = m.vec([0x6170_7865, 0x3320_646e, 0x7962_2d32, 0x6b20_6574]); diff --git a/utils-simd/ppv-lite86/src/types.rs b/utils-simd/ppv-lite86/src/types.rs index 119b6bb8..f9b2caa5 100644 --- a/utils-simd/ppv-lite86/src/types.rs +++ b/utils-simd/ppv-lite86/src/types.rs @@ -221,6 +221,7 @@ mod types { } pub use self::types::*; +#[allow(non_camel_case_types)] pub trait Machine: Sized + Copy { type u32x4: u32x4; type u64x2: u64x2; diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 60e7681c..7189bca5 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -411,7 +411,7 @@ impl MultiLane<[u128; 1]> for u128x1_sse2 { } #[inline(always)] fn from_lanes(xs: [u128; 1]) -> Self { - unimplemented!() + unimplemented!("{:?}", xs) } } @@ -780,7 +780,7 @@ impl BSwap for u128x1_sse2 { impl BSwap for u128x1_sse2 { #[inline(always)] fn bswap(self) -> Self { - Self::new(unsafe { unimplemented!() }) + unimplemented!() } } @@ -1078,6 +1078,7 @@ impl PartialEq for x2 { } } +#[allow(unused)] #[inline(always)] unsafe fn eq128_s4(x: __m128i, y: __m128i) -> bool { let q = _mm_shuffle_epi32(_mm_cmpeq_epi64(x, y), 0b1100_0110); From 9f2a3c9a4c03d80e8d5cab448654ec99dc727f57 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Fri, 9 Oct 2020 08:02:23 -0700 Subject: [PATCH 35/84] fmt --- hashes/blake/src/lib.rs | 1 - hashes/groestl/src/compressor.rs | 12 ++- hashes/jh/src/lib.rs | 2 +- hashes/skein/src/lib.rs | 2 +- stream-ciphers/chacha/src/guts.rs | 6 +- utils-simd/ppv-lite86/src/generic.rs | 2 +- utils-simd/ppv-lite86/src/soft.rs | 11 ++- utils-simd/ppv-lite86/src/types.rs | 20 ++--- utils-simd/ppv-lite86/src/x86_64/mod.rs | 2 +- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 98 ++++++++++-------------- 10 files changed, 76 insertions(+), 80 deletions(-) diff --git a/hashes/blake/src/lib.rs b/hashes/blake/src/lib.rs index b8ab5221..098d088f 100644 --- a/hashes/blake/src/lib.rs +++ b/hashes/blake/src/lib.rs @@ -70,7 +70,6 @@ fn round64( (a, b, c, d) } - #[inline(always)] fn diagonalize((a, b, c, d): (X4, X4, X4, X4)) -> (X4, X4, X4, X4) { // Since b has the critical data dependency, avoid rotating b to hide latency. diff --git a/hashes/groestl/src/compressor.rs b/hashes/groestl/src/compressor.rs index d20da74d..fb02b381 100644 --- a/hashes/groestl/src/compressor.rs +++ b/hashes/groestl/src/compressor.rs @@ -175,7 +175,8 @@ unsafe fn transpose_a(i: X4) -> X4 { _mm_unpackhi_epi16(i.0, i.1), _mm_unpacklo_epi16(i.2, i.3), _mm_unpackhi_epi16(i.2, i.3), - ).map(|x| _mm_shuffle_epi32(x, 0b1101_1000)); + ) + .map(|x| _mm_shuffle_epi32(x, 0b1101_1000)); X4( _mm_unpacklo_epi32(z.0, z.2), _mm_unpacklo_epi32(z.1, z.3), @@ -367,7 +368,8 @@ unsafe fn transpose_inv(i: X8) -> X8 { _mm_unpackhi_epi64(i.4, i.5), _mm_unpacklo_epi64(i.6, i.7), _mm_unpackhi_epi64(i.6, i.7), - ).map(|x| { + ) + .map(|x| { _mm_shuffle_epi8( x, _mm_set_epi64x(0x0f07_0b03_0e06_0a02, 0x0d05_0901_0c04_0800), @@ -382,7 +384,8 @@ unsafe fn transpose_inv(i: X8) -> X8 { _mm_unpacklo_epi16(i.5, i.7), _mm_unpackhi_epi16(i.4, i.6), _mm_unpackhi_epi16(i.5, i.7), - ).map(|x| _mm_shuffle_epi32(x, 0b1101_1000)); + ) + .map(|x| _mm_shuffle_epi32(x, 0b1101_1000)); X8( _mm_unpacklo_epi32(i.0, i.4), _mm_unpacklo_epi32(i.2, i.6), @@ -446,7 +449,8 @@ unsafe fn rounds_q(mut x: X8) -> X8 { _mm_set_epi64x(0x080b_0e01_0407_0a0d, 0x0003_0609_0c0f_0205), _mm_set_epi64x(0x090c_0f02_0508_0b0e, 0x0104_070a_0d00_0306), _mm_set_epi64x(0x0e01_0407_0a0d_0003, 0x0609_0c0f_0205_080b), - ).shuffle((1, 3, 5, 7, 0, 2, 4, 6)); + ) + .shuffle((1, 3, 5, 7, 0, 2, 4, 6)); let f = _mm_set1_epi64x(0xffff_ffff_ffff_ffffu64 as i64); for q in const_q.chunks_exact(2) { // 2 rounds at a time so we can flip-flop between register sets diff --git a/hashes/jh/src/lib.rs b/hashes/jh/src/lib.rs index b94520f7..a04049d5 100644 --- a/hashes/jh/src/lib.rs +++ b/hashes/jh/src/lib.rs @@ -15,10 +15,10 @@ mod consts; pub use digest::Digest; +use crate::compressor::Compressor; use block_buffer::generic_array::GenericArray as BBGenericArray; use block_buffer::BlockBuffer; use core::fmt::{Debug, Formatter, Result}; -use crate::compressor::Compressor; use digest::generic_array::typenum::{Unsigned, U28, U32, U48, U64}; use digest::generic_array::GenericArray as DGenericArray; diff --git a/hashes/skein/src/lib.rs b/hashes/skein/src/lib.rs index 52391449..f7685858 100644 --- a/hashes/skein/src/lib.rs +++ b/hashes/skein/src/lib.rs @@ -9,8 +9,8 @@ extern crate threefish_cipher; pub use digest::generic_array::GenericArray; pub use digest::Digest; -use block_buffer::BlockBuffer; use block_buffer::block_padding::ZeroPadding; +use block_buffer::BlockBuffer; use digest::generic_array::typenum::{NonZero, PartialDiv, Unsigned, U128, U32, U64, U8}; use digest::generic_array::ArrayLength; use threefish_cipher::{BlockCipher, Threefish1024, Threefish256, Threefish512}; diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 4649bcc7..309b6c2b 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -178,7 +178,11 @@ impl ChaCha { pub fn stream32_eq(&self, rhs: &Self) -> bool { let self_d: [u32; 4] = self.d.into(); let rhs_d: [u32; 4] = rhs.d.into(); - self.b == rhs.b && self.c == rhs.c && self_d[3] == rhs_d[3] && self_d[2] == rhs_d[2] && self_d[1] == rhs_d[1] + self.b == rhs.b + && self.c == rhs.c + && self_d[3] == rhs_d[3] + && self_d[2] == rhs_d[2] + && self_d[1] == rhs_d[1] } /// Return whether rhs represents the same stream, irrespective of current 64-bit position. diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 0da6a133..f0e83d96 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -1,8 +1,8 @@ #![allow(non_camel_case_types)] -use core::ops::*; use crate::soft::{x2, x4}; use crate::types::*; +use core::ops::*; #[repr(C)] #[derive(Clone, Copy)] diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index d12dac52..8976c484 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -1,9 +1,9 @@ //! Implement 256- and 512- bit in terms of 128-bit, for machines without native wide SIMD. -use core::marker::PhantomData; -use core::ops::*; use crate::types::*; use crate::{vec128_storage, vec256_storage, vec512_storage}; +use core::marker::PhantomData; +use core::ops::*; #[derive(Copy, Clone, Default)] #[allow(non_camel_case_types)] @@ -238,7 +238,12 @@ macro_rules! fwd_unop_x4 { ($fn:ident) => { #[inline(always)] fn $fn(self) -> Self { - x4([self.0[0].$fn(), self.0[1].$fn(), self.0[2].$fn(), self.0[3].$fn()]) + x4([ + self.0[0].$fn(), + self.0[1].$fn(), + self.0[2].$fn(), + self.0[3].$fn(), + ]) } }; } diff --git a/utils-simd/ppv-lite86/src/types.rs b/utils-simd/ppv-lite86/src/types.rs index f9b2caa5..4fb6fe6b 100644 --- a/utils-simd/ppv-lite86/src/types.rs +++ b/utils-simd/ppv-lite86/src/types.rs @@ -111,7 +111,7 @@ mod types { + MultiLane<[u32; 4]> + Into { -} + } pub trait u64x2: BitOps64 + Store @@ -120,11 +120,11 @@ mod types { + MultiLane<[u64; 2]> + Into { -} + } pub trait u128x1: BitOps128 + Store + Swap64 + MultiLane<[u128; 1]> + Into { -} + } pub trait u32x4x2: BitOps32 @@ -134,7 +134,7 @@ mod types { + ArithOps + Into { -} + } pub trait u64x2x2: BitOps64 + Store @@ -144,7 +144,7 @@ mod types { + StoreBytes + Into { -} + } pub trait u64x4: BitOps64 + Store @@ -155,7 +155,7 @@ mod types { + StoreBytes + Into { -} + } pub trait u128x2: BitOps128 + Store @@ -164,7 +164,7 @@ mod types { + Swap64 + Into { -} + } pub trait u32x4x4: BitOps32 @@ -175,7 +175,7 @@ mod types { + LaneWords4 + Into { -} + } pub trait u64x2x4: BitOps64 + Store @@ -184,7 +184,7 @@ mod types { + ArithOps + Into { -} + } // TODO: Words4 pub trait u128x4: BitOps128 @@ -194,7 +194,7 @@ mod types { + Swap64 + Into { -} + } /// A vector composed of multiple 128-bit lanes. pub trait MultiLane { diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index ecf184f3..d7455d0c 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -1,7 +1,7 @@ // crate minimums: sse2, x86_64 -use core::arch::x86_64::{__m128i, __m256i}; use crate::types::*; +use core::arch::x86_64::{__m128i, __m256i}; mod sse2; diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 7189bca5..bf0063fb 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -166,28 +166,23 @@ macro_rules! impl_bitops128 { macro_rules! rotr_32_s3 { ($name:ident, $k0:expr, $k1:expr) => { - #[inline(always)] - fn $name(self) -> Self { - Self::new(unsafe { - _mm_shuffle_epi8( - self.x, - _mm_set_epi64x($k0, $k1), - ) - }) + #[inline(always)] + fn $name(self) -> Self { + Self::new(unsafe { _mm_shuffle_epi8(self.x, _mm_set_epi64x($k0, $k1)) }) } }; } macro_rules! rotr_32 { ($name:ident, $i:expr) => { - #[inline(always)] - fn $name(self) -> Self { - Self::new(unsafe { - _mm_or_si128( - _mm_srli_epi32(self.x, $i as i32), - _mm_slli_epi32(self.x, 32 - $i as i32), - ) - }) - } + #[inline(always)] + fn $name(self) -> Self { + Self::new(unsafe { + _mm_or_si128( + _mm_srli_epi32(self.x, $i as i32), + _mm_slli_epi32(self.x, 32 - $i as i32), + ) + }) + } }; } impl RotateEachWord32 for u32x4_sse2 { @@ -228,28 +223,23 @@ impl RotateEachWord32 for u32x4_sse2 { macro_rules! rotr_64_s3 { ($name:ident, $k0:expr, $k1:expr) => { - #[inline(always)] - fn $name(self) -> Self { - Self::new(unsafe { - _mm_shuffle_epi8( - self.x, - _mm_set_epi64x($k0, $k1), - ) - }) + #[inline(always)] + fn $name(self) -> Self { + Self::new(unsafe { _mm_shuffle_epi8(self.x, _mm_set_epi64x($k0, $k1)) }) } }; } macro_rules! rotr_64 { ($name:ident, $i:expr) => { - #[inline(always)] - fn $name(self) -> Self { - Self::new(unsafe { - _mm_or_si128( - _mm_srli_epi64(self.x, $i as i32), - _mm_slli_epi64(self.x, 64 - $i as i32), - ) - }) - } + #[inline(always)] + fn $name(self) -> Self { + Self::new(unsafe { + _mm_or_si128( + _mm_srli_epi64(self.x, $i as i32), + _mm_slli_epi64(self.x, 64 - $i as i32), + ) + }) + } }; } impl RotateEachWord32 for u64x2_sse2 { @@ -296,15 +286,15 @@ impl RotateEachWord64 for u64x2_sse2 { macro_rules! rotr_128 { ($name:ident, $i:expr) => { - #[inline(always)] - fn $name(self) -> Self { - Self::new(unsafe { - _mm_or_si128( - _mm_srli_si128(self.x, $i as i32), - _mm_slli_si128(self.x, 128 - $i as i32), - ) - }) - } + #[inline(always)] + fn $name(self) -> Self { + Self::new(unsafe { + _mm_or_si128( + _mm_srli_si128(self.x, $i as i32), + _mm_slli_si128(self.x, 128 - $i as i32), + ) + }) + } }; } // TODO: completely unoptimized @@ -1493,19 +1483,13 @@ pub mod avx2 { impl ArithOps for u32x4x4_avx2 where NI: Copy {} macro_rules! shuf_lane_bytes { ($name:ident, $k0:expr, $k1:expr) => { - #[inline(always)] - fn $name(self) -> Self { - Self::new(unsafe { - [ - _mm256_shuffle_epi8( - self.x[0], - _mm256_set_epi64x($k0, $k1, $k0, $k1), - ), - _mm256_shuffle_epi8( - self.x[1], - _mm256_set_epi64x($k0, $k1, $k0, $k1), - ) - ] + #[inline(always)] + fn $name(self) -> Self { + Self::new(unsafe { + [ + _mm256_shuffle_epi8(self.x[0], _mm256_set_epi64x($k0, $k1, $k0, $k1)), + _mm256_shuffle_epi8(self.x[1], _mm256_set_epi64x($k0, $k1, $k0, $k1)), + ] }) } }; @@ -1523,7 +1507,7 @@ pub mod avx2 { _mm256_or_si256( _mm256_srli_epi32(self.x[1], $i as i32), _mm256_slli_epi32(self.x[1], 32 - $i as i32), - ) + ), ] }) } From 1eb8f4b6879cc41b130f1afe62c648b4ac1f3328 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Fri, 9 Oct 2020 08:11:49 -0700 Subject: [PATCH 36/84] eliminate clippy warnings --- block-ciphers/threefish/src/lib.rs | 2 +- hashes/groestl/src/compressor.rs | 4 +- stream-ciphers/chacha/src/guts.rs | 1 + utils-simd/ppv-lite86/src/types.rs | 332 +++++++++++++++-------------- 4 files changed, 174 insertions(+), 165 deletions(-) diff --git a/block-ciphers/threefish/src/lib.rs b/block-ciphers/threefish/src/lib.rs index 4418ad26..56df1082 100644 --- a/block-ciphers/threefish/src/lib.rs +++ b/block-ciphers/threefish/src/lib.rs @@ -114,7 +114,7 @@ macro_rules! impl_threefish( } } - $name { sk: sk } + $name { sk } } } diff --git a/hashes/groestl/src/compressor.rs b/hashes/groestl/src/compressor.rs index fb02b381..72b12d5a 100644 --- a/hashes/groestl/src/compressor.rs +++ b/hashes/groestl/src/compressor.rs @@ -47,7 +47,7 @@ impl BitXor for X4 { impl Map2 for (X4, X4) { type Output = X4; #[inline(always)] - fn map(self: Self, mut f: F) -> Self::Output + fn map(self, mut f: F) -> Self::Output where F: FnMut(__m128i, __m128i) -> __m128i, { @@ -115,7 +115,7 @@ impl BitXor for X8 { impl Map2 for (X8, X8) { type Output = X8; #[inline(always)] - fn map(self: Self, mut f: F) -> Self::Output + fn map(self, mut f: F) -> Self::Output where F: FnMut(__m128i, __m128i) -> __m128i, { diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 309b6c2b..814d4a77 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -195,6 +195,7 @@ impl ChaCha { } #[inline(always)] +#[allow(clippy::many_single_char_names)] fn refill_wide_impl( m: Mach, state: &mut ChaCha, diff --git a/utils-simd/ppv-lite86/src/types.rs b/utils-simd/ppv-lite86/src/types.rs index 4fb6fe6b..a2826707 100644 --- a/utils-simd/ppv-lite86/src/types.rs +++ b/utils-simd/ppv-lite86/src/types.rs @@ -1,3 +1,4 @@ +#![allow(non_camel_case_types)] use core::ops::{Add, AddAssign, BitAnd, BitOr, BitXor, BitXorAssign, Not}; pub trait AndNot { @@ -44,184 +45,179 @@ pub trait RotateEachWord64 { pub trait RotateEachWord128 {} -#[allow(non_camel_case_types)] -mod types { - //! Vector type naming scheme: - //! uN[xP]xL - //! Unsigned; N-bit words * P bits per lane * L lanes - //! - //! A lane is always 128-bits, chosen because common SIMD architectures treat 128-bit units of - //! wide vectors specially (supporting e.g. intra-lane shuffles), and tend to have limited and - //! slow inter-lane operations. +// Vector type naming scheme: +// uN[xP]xL +// Unsigned; N-bit words * P bits per lane * L lanes +// +// A lane is always 128-bits, chosen because common SIMD architectures treat 128-bit units of +// wide vectors specially (supporting e.g. intra-lane shuffles), and tend to have limited and +// slow inter-lane operations. - use crate::arch::{vec128_storage, vec256_storage, vec512_storage}; - use crate::{ArithOps, BitOps128, BitOps32, BitOps64, Machine, Store, StoreBytes}; +use crate::arch::{vec128_storage, vec256_storage, vec512_storage}; - pub trait UnsafeFrom { - unsafe fn unsafe_from(t: T) -> Self; - } +#[allow(clippy::missing_safety_doc)] +pub trait UnsafeFrom { + unsafe fn unsafe_from(t: T) -> Self; +} - /// A vector composed of two elements, which may be words or themselves vectors. - pub trait Vec2 { - fn extract(self, i: u32) -> W; - fn insert(self, w: W, i: u32) -> Self; - } +/// A vector composed of two elements, which may be words or themselves vectors. +pub trait Vec2 { + fn extract(self, i: u32) -> W; + fn insert(self, w: W, i: u32) -> Self; +} - /// A vector composed of four elements, which may be words or themselves vectors. - pub trait Vec4 { - fn extract(self, i: u32) -> W; - fn insert(self, w: W, i: u32) -> Self; - } +/// A vector composed of four elements, which may be words or themselves vectors. +pub trait Vec4 { + fn extract(self, i: u32) -> W; + fn insert(self, w: W, i: u32) -> Self; +} - // TODO: multiples of 4 should inherit this - /// A vector composed of four words; depending on their size, operations may cross lanes. - pub trait Words4 { - fn shuffle1230(self) -> Self; - fn shuffle2301(self) -> Self; - fn shuffle3012(self) -> Self; - } +// TODO: multiples of 4 should inherit this +/// A vector composed of four words; depending on their size, operations may cross lanes. +pub trait Words4 { + fn shuffle1230(self) -> Self; + fn shuffle2301(self) -> Self; + fn shuffle3012(self) -> Self; +} - /// A vector composed one or more lanes each composed of four words. - pub trait LaneWords4 { - fn shuffle_lane_words1230(self) -> Self; - fn shuffle_lane_words2301(self) -> Self; - fn shuffle_lane_words3012(self) -> Self; - } +/// A vector composed one or more lanes each composed of four words. +pub trait LaneWords4 { + fn shuffle_lane_words1230(self) -> Self; + fn shuffle_lane_words2301(self) -> Self; + fn shuffle_lane_words3012(self) -> Self; +} - // TODO: make this a part of BitOps - /// Exchange neigboring ranges of bits of the specified size - pub trait Swap64 { - fn swap1(self) -> Self; - fn swap2(self) -> Self; - fn swap4(self) -> Self; - fn swap8(self) -> Self; - fn swap16(self) -> Self; - fn swap32(self) -> Self; - fn swap64(self) -> Self; - } +// TODO: make this a part of BitOps +/// Exchange neigboring ranges of bits of the specified size +pub trait Swap64 { + fn swap1(self) -> Self; + fn swap2(self) -> Self; + fn swap4(self) -> Self; + fn swap8(self) -> Self; + fn swap16(self) -> Self; + fn swap32(self) -> Self; + fn swap64(self) -> Self; +} - pub trait u32x4: - BitOps32 - + Store - + ArithOps - + Vec4 - + Words4 - + LaneWords4 - + StoreBytes - + MultiLane<[u32; 4]> - + Into - { - } - pub trait u64x2: - BitOps64 - + Store - + ArithOps - + Vec2 - + MultiLane<[u64; 2]> - + Into - { - } - pub trait u128x1: - BitOps128 + Store + Swap64 + MultiLane<[u128; 1]> + Into - { - } +pub trait u32x4: + BitOps32 + + Store + + ArithOps + + Vec4 + + Words4 + + LaneWords4 + + StoreBytes + + MultiLane<[u32; 4]> + + Into +{ +} +pub trait u64x2: + BitOps64 + + Store + + ArithOps + + Vec2 + + MultiLane<[u64; 2]> + + Into +{ +} +pub trait u128x1: + BitOps128 + Store + Swap64 + MultiLane<[u128; 1]> + Into +{ +} - pub trait u32x4x2: - BitOps32 - + Store - + Vec2 - + MultiLane<[M::u32x4; 2]> - + ArithOps - + Into - { - } - pub trait u64x2x2: - BitOps64 - + Store - + Vec2 - + MultiLane<[M::u64x2; 2]> - + ArithOps - + StoreBytes - + Into - { - } - pub trait u64x4: - BitOps64 - + Store - + Vec4 - + MultiLane<[u64; 4]> - + ArithOps - + Words4 - + StoreBytes - + Into - { - } - pub trait u128x2: - BitOps128 - + Store - + Vec2 - + MultiLane<[M::u128x1; 2]> - + Swap64 - + Into - { - } +pub trait u32x4x2: + BitOps32 + + Store + + Vec2 + + MultiLane<[M::u32x4; 2]> + + ArithOps + + Into +{ +} +pub trait u64x2x2: + BitOps64 + + Store + + Vec2 + + MultiLane<[M::u64x2; 2]> + + ArithOps + + StoreBytes + + Into +{ +} +pub trait u64x4: + BitOps64 + + Store + + Vec4 + + MultiLane<[u64; 4]> + + ArithOps + + Words4 + + StoreBytes + + Into +{ +} +pub trait u128x2: + BitOps128 + + Store + + Vec2 + + MultiLane<[M::u128x1; 2]> + + Swap64 + + Into +{ +} - pub trait u32x4x4: - BitOps32 - + Store - + Vec4 - + MultiLane<[M::u32x4; 4]> - + ArithOps - + LaneWords4 - + Into - { - } - pub trait u64x2x4: - BitOps64 - + Store - + Vec4 - + MultiLane<[M::u64x2; 4]> - + ArithOps - + Into - { - } - // TODO: Words4 - pub trait u128x4: - BitOps128 - + Store - + Vec4 - + MultiLane<[M::u128x1; 4]> - + Swap64 - + Into - { - } +pub trait u32x4x4: + BitOps32 + + Store + + Vec4 + + MultiLane<[M::u32x4; 4]> + + ArithOps + + LaneWords4 + + Into +{ +} +pub trait u64x2x4: + BitOps64 + + Store + + Vec4 + + MultiLane<[M::u64x2; 4]> + + ArithOps + + Into +{ +} +// TODO: Words4 +pub trait u128x4: + BitOps128 + + Store + + Vec4 + + MultiLane<[M::u128x1; 4]> + + Swap64 + + Into +{ +} - /// A vector composed of multiple 128-bit lanes. - pub trait MultiLane { - /// Split a multi-lane vector into single-lane vectors. - fn to_lanes(self) -> Lanes; - /// Build a multi-lane vector from individual lanes. - fn from_lanes(lanes: Lanes) -> Self; - } +/// A vector composed of multiple 128-bit lanes. +pub trait MultiLane { + /// Split a multi-lane vector into single-lane vectors. + fn to_lanes(self) -> Lanes; + /// Build a multi-lane vector from individual lanes. + fn from_lanes(lanes: Lanes) -> Self; +} - /// Combine single vectors into a multi-lane vector. - pub trait VZip { - fn vzip(self) -> V; - } +/// Combine single vectors into a multi-lane vector. +pub trait VZip { + fn vzip(self) -> V; +} - impl VZip for T - where - V: MultiLane, - { - #[inline(always)] - fn vzip(self) -> V { - V::from_lanes(self) - } +impl VZip for T +where + V: MultiLane, +{ + #[inline(always)] + fn vzip(self) -> V { + V::from_lanes(self) } } -pub use self::types::*; -#[allow(non_camel_case_types)] pub trait Machine: Sized + Copy { type u32x4: u32x4; type u64x2: u64x2; @@ -265,15 +261,27 @@ pub trait Machine: Sized + Copy { unsafe { V::unsafe_read_be(input) } } + /// # Safety + /// Caller must ensure the type of Self is appropriate for the hardware of the execution + /// environment. unsafe fn instance() -> Self; } pub trait Store { + /// # Safety + /// Caller must ensure the type of Self is appropriate for the hardware of the execution + /// environment. unsafe fn unpack(p: S) -> Self; } pub trait StoreBytes { + /// # Safety + /// Caller must ensure the type of Self is appropriate for the hardware of the execution + /// environment. unsafe fn unsafe_read_le(input: &[u8]) -> Self; + /// # Safety + /// Caller must ensure the type of Self is appropriate for the hardware of the execution + /// environment. unsafe fn unsafe_read_be(input: &[u8]) -> Self; fn write_le(self, out: &mut [u8]); fn write_be(self, out: &mut [u8]); From 9213f7eb1fd70618cacce1141d660b0cb6fcef1f Mon Sep 17 00:00:00 2001 From: roblabla Date: Mon, 26 Oct 2020 11:27:08 +0000 Subject: [PATCH 37/84] Migrate to new cipher crate stream_cipher is deprecated, cipher replaces it. --- block-ciphers/threefish/Cargo.toml | 2 +- block-ciphers/threefish/src/lib.rs | 12 ++++++------ stream-ciphers/chacha/Cargo.toml | 4 ++-- stream-ciphers/chacha/src/guts.rs | 2 +- stream-ciphers/chacha/src/rustcrypto_impl.rs | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/block-ciphers/threefish/Cargo.toml b/block-ciphers/threefish/Cargo.toml index 17eb1899..0f56240a 100644 --- a/block-ciphers/threefish/Cargo.toml +++ b/block-ciphers/threefish/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "threefish", "gost", "block-cipher"] [dependencies] -block-cipher = "0.8" +cipher = "0.2" [dev-dependencies] hex-literal = "0.2" diff --git a/block-ciphers/threefish/src/lib.rs b/block-ciphers/threefish/src/lib.rs index 56df1082..ba511388 100644 --- a/block-ciphers/threefish/src/lib.rs +++ b/block-ciphers/threefish/src/lib.rs @@ -1,6 +1,6 @@ #![no_std] #![allow(non_upper_case_globals)] -extern crate block_cipher; +extern crate cipher; #[cfg(test)] #[macro_use] extern crate hex_literal; @@ -10,9 +10,9 @@ use core::ops::BitXor; mod consts; use consts::{C240, P_1024, P_256, P_512, R_1024, R_256, R_512}; -use block_cipher::generic_array::typenum::{U1, U128, U32, U64}; -use block_cipher::generic_array::GenericArray; -pub use block_cipher::{BlockCipher, NewBlockCipher}; +use cipher::generic_array::typenum::{U1, U128, U32, U64}; +use cipher::generic_array::GenericArray; +pub use cipher::{BlockCipher, NewBlockCipher}; fn mix(r: u32, x: (u64, u64)) -> (u64, u64) { let y0 = x.0.wrapping_add(x.1); @@ -209,8 +209,8 @@ mod test { //! tests from NIST submission use super::{Threefish1024, Threefish256, Threefish512}; - use block_cipher::generic_array::GenericArray; - use block_cipher::{BlockCipher, NewBlockCipher}; + use cipher::generic_array::GenericArray; + use cipher::{BlockCipher, NewBlockCipher}; #[test] fn test_256() { diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index e7b9ecd4..d1ed5b3b 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/c2-chacha" [dependencies] ppv-lite86 = { package = "ppv-lite86", version = "0.2.8", default-features = false } -stream-cipher = { version = "0.7", optional = true } +cipher = { version = "0.2", optional = true } [dev-dependencies] hex-literal = "0.2" @@ -21,7 +21,7 @@ hex-literal = "0.2" [features] default = ["std", "rustcrypto_api"] std = ["ppv-lite86/std"] -rustcrypto_api = ["stream-cipher"] +rustcrypto_api = ["cipher"] no_simd = ["ppv-lite86/no_simd"] simd = [] # deprecated diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 814d4a77..8fcce7b1 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -1,5 +1,5 @@ #[cfg(feature = "rustcrypto_api")] -pub use stream_cipher::generic_array; +pub use cipher::generic_array; pub use ppv_lite86::Machine; use ppv_lite86::{vec128_storage, ArithOps, BitOps32, LaneWords4, MultiLane, StoreBytes, Vec4}; diff --git a/stream-ciphers/chacha/src/rustcrypto_impl.rs b/stream-ciphers/chacha/src/rustcrypto_impl.rs index f28a5ad0..011aa12d 100644 --- a/stream-ciphers/chacha/src/rustcrypto_impl.rs +++ b/stream-ciphers/chacha/src/rustcrypto_impl.rs @@ -3,8 +3,8 @@ use crate::guts::generic_array::{ArrayLength, GenericArray}; use crate::guts::{ChaCha, Machine, BLOCK, BLOCK64, BUFSZ}; use core::cmp; use core::convert::TryInto; -pub use stream_cipher; -use stream_cipher::{ +pub use cipher::stream as stream_cipher; +use cipher::stream::{ LoopError, NewStreamCipher, OverflowError, SeekNum, SyncStreamCipher, SyncStreamCipherSeek, }; From 3012849c2d9c50228a780031e7c200b193a6b4fa Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 2 Nov 2020 08:57:19 -0800 Subject: [PATCH 38/84] release new versions --- block-ciphers/threefish/Cargo.toml | 2 +- hashes/blake/Cargo.toml | 2 +- hashes/groestl/Cargo.toml | 2 +- hashes/jh/Cargo.toml | 2 +- stream-ciphers/chacha/Cargo.toml | 2 +- unreleased-changes.sh | 23 +++++++++++++++++++++++ utils-simd/ppv-lite86/Cargo.toml | 2 +- 7 files changed, 29 insertions(+), 6 deletions(-) create mode 100755 unreleased-changes.sh diff --git a/block-ciphers/threefish/Cargo.toml b/block-ciphers/threefish/Cargo.toml index 0f56240a..69f2b687 100644 --- a/block-ciphers/threefish/Cargo.toml +++ b/block-ciphers/threefish/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "threefish-cipher" -version = "0.3.1" +version = "0.4.0" authors = ["The Rust-Crypto Project Developers", "The Cryptocorrosion Contributors"] license = "MIT/Apache-2.0" description = "Threefish block cipher" diff --git a/hashes/blake/Cargo.toml b/hashes/blake/Cargo.toml index 92a98d14..d57552fc 100644 --- a/hashes/blake/Cargo.toml +++ b/hashes/blake/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blake-hash" -version = "0.3.2" +version = "0.4.0" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "BLAKE hash functions" diff --git a/hashes/groestl/Cargo.toml b/hashes/groestl/Cargo.toml index c5bd86ee..72f07207 100644 --- a/hashes/groestl/Cargo.toml +++ b/hashes/groestl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "groestl-aesni" -version = "0.2.2" +version = "0.3.0" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "Hardware-accelerated Groestl hash for x86-64 systems with AES extensions" diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index d73262f7..11bd91e6 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jh-x86_64" -version = "0.2.2" +version = "0.3.0" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "Portable JH with optimizations for x86-64 cpus" diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index d1ed5b3b..74d5ab77 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c2-chacha" -version = "0.2.4" +version = "0.3.0" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" edition = "2018" diff --git a/unreleased-changes.sh b/unreleased-changes.sh new file mode 100755 index 00000000..532e545d --- /dev/null +++ b/unreleased-changes.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +CRATE_TAGS=$(git tag | sed 's/-[^-]*$//' | uniq) +CARGOS=$(echo */*/Cargo.toml) + +for TAG in $CRATE_TAGS; do + LATEST_TAG=$(git tag | grep $TAG | tail -n1) + FOUND_CARGO= + for CARGO in $CARGOS; do + # fixups for tag names that don't match crate names + CRATE=$(echo $TAG | sed -e 's/^jh$/jh-x86_64/' -e 's/^blake$/blake-hash/' -e 's/^groestl$/groestl-aesni/') + if grep -q "name = \"$CRATE\"" $CARGO; then + FOUND_CARGO=1 + DIR=$(dirname $CARGO) + git log --color=always --stat $LATEST_TAG..HEAD -- $DIR | less -R + break + fi + done + if [ -z "$FOUND_CARGO" ]; then + echo "Couldn't find a Cargo.toml for $TAG!" + fi +done + diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 84a59adc..8f3fb522 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.9" +version = "0.2.10" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" From 39493bd4fe895789b1286e113891b67b631c51c2 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Mon, 2 Nov 2020 09:05:08 -0800 Subject: [PATCH 39/84] fix unreleased-changes.sh for multi-digit version components --- unreleased-changes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unreleased-changes.sh b/unreleased-changes.sh index 532e545d..e7d82105 100755 --- a/unreleased-changes.sh +++ b/unreleased-changes.sh @@ -4,7 +4,7 @@ CRATE_TAGS=$(git tag | sed 's/-[^-]*$//' | uniq) CARGOS=$(echo */*/Cargo.toml) for TAG in $CRATE_TAGS; do - LATEST_TAG=$(git tag | grep $TAG | tail -n1) + LATEST_TAG=$(git tag | grep $TAG | sort -V | tail -n1) FOUND_CARGO= for CARGO in $CARGOS; do # fixups for tag names that don't match crate names From ffbe05ce35c0d75d8baa82c6359cc9bc7fa99903 Mon Sep 17 00:00:00 2001 From: Paul Grandperrin Date: Tue, 5 Jan 2021 11:53:29 -0300 Subject: [PATCH 40/84] c2-chacha: add XChaCha8 and XChaCha12 Rational: https://eprint.iacr.org/2019/1492.pdf --- stream-ciphers/chacha/src/lib.rs | 2 +- stream-ciphers/chacha/src/rustcrypto_impl.rs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/stream-ciphers/chacha/src/lib.rs b/stream-ciphers/chacha/src/lib.rs index 363a1a7b..17fe3588 100644 --- a/stream-ciphers/chacha/src/lib.rs +++ b/stream-ciphers/chacha/src/lib.rs @@ -42,4 +42,4 @@ pub mod guts; #[cfg(feature = "rustcrypto_api")] mod rustcrypto_impl; #[cfg(feature = "rustcrypto_api")] -pub use self::rustcrypto_impl::{stream_cipher, ChaCha12, ChaCha20, ChaCha8, Ietf, XChaCha20}; +pub use self::rustcrypto_impl::{stream_cipher, Ietf, ChaCha8, ChaCha12, ChaCha20, XChaCha8, XChaCha12, XChaCha20}; diff --git a/stream-ciphers/chacha/src/rustcrypto_impl.rs b/stream-ciphers/chacha/src/rustcrypto_impl.rs index 011aa12d..130bb5f9 100644 --- a/stream-ciphers/chacha/src/rustcrypto_impl.rs +++ b/stream-ciphers/chacha/src/rustcrypto_impl.rs @@ -292,12 +292,18 @@ dispatch_light128!(m, Mach, { /// IETF RFC 7539 ChaCha. Unsuitable for messages longer than 256 GiB. pub type Ietf = ChaChaAny; -/// ChaCha20, as used in several standards; from Bernstein's original publication. -pub type ChaCha20 = ChaChaAny; -/// Similar to ChaCha20, but with fewer rounds for higher performance. -pub type ChaCha12 = ChaChaAny; /// Similar to ChaCha20, but with fewer rounds for higher performance. pub type ChaCha8 = ChaChaAny; +/// Similar to ChaCha20, but with fewer rounds for higher performance. +pub type ChaCha12 = ChaChaAny; +/// ChaCha20, as used in several standards; from Bernstein's original publication. +pub type ChaCha20 = ChaChaAny; +/// Constructed analogously to XChaCha20, but with fewer rounds for higher performance; +/// mixes during initialization to support both a long nonce and a full-length (64-bit) block counter. +pub type XChaCha8 = ChaChaAny; +/// Constructed analogously to XChaCha20, but with fewer rounds for higher performance; +/// mixes during initialization to support both a long nonce and a full-length (64-bit) block counter. +pub type XChaCha12 = ChaChaAny; /// Constructed analogously to XSalsa20; mixes during initialization to support both a long nonce /// and a full-length (64-bit) block counter. pub type XChaCha20 = ChaChaAny; From 99d97056c87dc825830f83bb832c5eec3e3fb261 Mon Sep 17 00:00:00 2001 From: Jin Eguchi Date: Sun, 24 Jan 2021 02:26:18 +0900 Subject: [PATCH 41/84] skein: fix build(mismatched types) --- hashes/skein/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashes/skein/Cargo.toml b/hashes/skein/Cargo.toml index d7754fa6..ec9fcfc5 100644 --- a/hashes/skein/Cargo.toml +++ b/hashes/skein/Cargo.toml @@ -11,7 +11,7 @@ categories = ["cryptography", "no-std"] [dependencies] block-buffer = { version = "0.9", features = ["block-padding"] } digest = "0.9" -threefish-cipher = "0.3" +threefish-cipher = "0.4" [dev-dependencies] digest = { version = "0.9", features = ["dev"] } From 8e31b3c65fd979181f563feac90ac11c900b350d Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 12 May 2021 08:41:11 -0700 Subject: [PATCH 42/84] release chacha 0.3.1 --- stream-ciphers/chacha/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index 74d5ab77..d8012d5e 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c2-chacha" -version = "0.3.0" +version = "0.3.1" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" edition = "2018" From 74ceab51ab24a77d199f37792bdf63b47ab88a39 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 12 May 2021 08:47:17 -0700 Subject: [PATCH 43/84] release skein-hash 0.3.1 --- hashes/skein/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hashes/skein/Cargo.toml b/hashes/skein/Cargo.toml index ec9fcfc5..0864fd6e 100644 --- a/hashes/skein/Cargo.toml +++ b/hashes/skein/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "skein-hash" -version = "0.3.0" +version = "0.3.1" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "Skein hash functions" From 92d4041181fa2358b291cc652083a7ac329fe1a3 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 12:16:23 -0700 Subject: [PATCH 44/84] ppv-lite86: fix missed #inlines --- utils-simd/ppv-lite86/Cargo.toml | 2 +- utils-simd/ppv-lite86/src/generic.rs | 98 +++++++++++++------------ utils-simd/ppv-lite86/src/x86_64/mod.rs | 4 + 3 files changed, 58 insertions(+), 46 deletions(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 8f3fb522..2d257de6 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.10" +version = "0.2.11" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index f0e83d96..0731875c 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -11,38 +11,38 @@ pub union vec128_storage { q: [u64; 2], } impl From<[u32; 4]> for vec128_storage { - #[inline] + #[inline(always)] fn from(d: [u32; 4]) -> Self { Self { d } } } impl From for [u32; 4] { - #[inline] + #[inline(always)] fn from(d: vec128_storage) -> Self { unsafe { d.d } } } impl From<[u64; 2]> for vec128_storage { - #[inline] + #[inline(always)] fn from(q: [u64; 2]) -> Self { Self { q } } } impl From for [u64; 2] { - #[inline] + #[inline(always)] fn from(q: vec128_storage) -> Self { unsafe { q.q } } } impl Default for vec128_storage { - #[inline] + #[inline(always)] fn default() -> Self { Self { q: [0, 0] } } } impl Eq for vec128_storage {} impl PartialEq for vec128_storage { - #[inline] + #[inline(always)] fn eq(&self, rhs: &Self) -> bool { unsafe { self.q == rhs.q } } @@ -62,7 +62,7 @@ impl vec256_storage { } } impl From for [u64; 4] { - #[inline] + #[inline(always)] fn from(q: vec256_storage) -> Self { let [a, b]: [u64; 2] = q.v128[0].into(); let [c, d]: [u64; 2] = q.v128[1].into(); @@ -84,6 +84,7 @@ impl vec512_storage { } } +#[inline(always)] fn dmap(t: T, f: F) -> T where T: Store + Into, @@ -117,6 +118,7 @@ where unsafe { T::unpack(d) } } +#[inline(always)] fn qmap(t: T, f: F) -> T where T: Store + Into, @@ -130,6 +132,7 @@ where unsafe { T::unpack(q) } } +#[inline(always)] fn qmap2(a: T, b: T, f: F) -> T where T: Store + Into, @@ -145,14 +148,17 @@ where unsafe { T::unpack(q) } } +#[inline(always)] fn o_of_q(q: [u64; 2]) -> u128 { u128::from(q[0]) | (u128::from(q[1]) << 64) } +#[inline(always)] fn q_of_o(o: u128) -> [u64; 2] { [o as u64, (o >> 64) as u64] } +#[inline(always)] fn omap(a: T, f: F) -> T where T: Store + Into, @@ -164,6 +170,7 @@ where unsafe { T::unpack(o) } } +#[inline(always)] fn omap2(a: T, b: T, f: F) -> T where T: Store + Into, @@ -247,39 +254,39 @@ macro_rules! impl_bitops { } impl Swap64 for $vec { - #[inline] + #[inline(always)] fn swap1(self) -> Self { qmap(self, |x| { ((x & 0x5555555555555555) << 1) | ((x & 0xaaaaaaaaaaaaaaaa) >> 1) }) } - #[inline] + #[inline(always)] fn swap2(self) -> Self { qmap(self, |x| { ((x & 0x3333333333333333) << 2) | ((x & 0xcccccccccccccccc) >> 2) }) } - #[inline] + #[inline(always)] fn swap4(self) -> Self { qmap(self, |x| { ((x & 0x0f0f0f0f0f0f0f0f) << 4) | ((x & 0xf0f0f0f0f0f0f0f0) >> 4) }) } - #[inline] + #[inline(always)] fn swap8(self) -> Self { qmap(self, |x| { ((x & 0x00ff00ff00ff00ff) << 8) | ((x & 0xff00ff00ff00ff00) >> 8) }) } - #[inline] + #[inline(always)] fn swap16(self) -> Self { dmap(self, |x| x.rotate_left(16)) } - #[inline] + #[inline(always)] fn swap32(self) -> Self { qmap(self, |x| x.rotate_left(32)) } - #[inline] + #[inline(always)] fn swap64(self) -> Self { omap(self, |x| (x << 64) | (x >> 64)) } @@ -291,82 +298,83 @@ impl_bitops!(u64x2_generic); impl_bitops!(u128x1_generic); impl RotateEachWord32 for u32x4_generic { - #[inline] + #[inline(always)] fn rotate_each_word_right7(self) -> Self { dmap(self, |x| x.rotate_right(7)) } - #[inline] + #[inline(always)] fn rotate_each_word_right8(self) -> Self { dmap(self, |x| x.rotate_right(8)) } - #[inline] + #[inline(always)] fn rotate_each_word_right11(self) -> Self { dmap(self, |x| x.rotate_right(11)) } - #[inline] + #[inline(always)] fn rotate_each_word_right12(self) -> Self { dmap(self, |x| x.rotate_right(12)) } - #[inline] + #[inline(always)] fn rotate_each_word_right16(self) -> Self { dmap(self, |x| x.rotate_right(16)) } - #[inline] + #[inline(always)] fn rotate_each_word_right20(self) -> Self { dmap(self, |x| x.rotate_right(20)) } - #[inline] + #[inline(always)] fn rotate_each_word_right24(self) -> Self { dmap(self, |x| x.rotate_right(24)) } - #[inline] + #[inline(always)] fn rotate_each_word_right25(self) -> Self { dmap(self, |x| x.rotate_right(25)) } } impl RotateEachWord32 for u64x2_generic { - #[inline] + #[inline(always)] fn rotate_each_word_right7(self) -> Self { qmap(self, |x| x.rotate_right(7)) } - #[inline] + #[inline(always)] fn rotate_each_word_right8(self) -> Self { qmap(self, |x| x.rotate_right(8)) } - #[inline] + #[inline(always)] fn rotate_each_word_right11(self) -> Self { qmap(self, |x| x.rotate_right(11)) } - #[inline] + #[inline(always)] fn rotate_each_word_right12(self) -> Self { qmap(self, |x| x.rotate_right(12)) } - #[inline] + #[inline(always)] fn rotate_each_word_right16(self) -> Self { qmap(self, |x| x.rotate_right(16)) } - #[inline] + #[inline(always)] fn rotate_each_word_right20(self) -> Self { qmap(self, |x| x.rotate_right(20)) } - #[inline] + #[inline(always)] fn rotate_each_word_right24(self) -> Self { qmap(self, |x| x.rotate_right(24)) } - #[inline] + #[inline(always)] fn rotate_each_word_right25(self) -> Self { qmap(self, |x| x.rotate_right(25)) } } impl RotateEachWord64 for u64x2_generic { - #[inline] + #[inline(always)] fn rotate_each_word_right32(self) -> Self { qmap(self, |x| x.rotate_right(32)) } } // workaround for koute/cargo-web#52 (u128::rotate_* broken with cargo web) +#[inline(always)] fn rotate_u128_right(x: u128, i: u32) -> u128 { (x >> i) | (x << (128 - i)) } @@ -377,41 +385,41 @@ fn test_rotate_u128() { } impl RotateEachWord32 for u128x1_generic { - #[inline] + #[inline(always)] fn rotate_each_word_right7(self) -> Self { Self([rotate_u128_right(self.0[0], 7)]) } - #[inline] + #[inline(always)] fn rotate_each_word_right8(self) -> Self { Self([rotate_u128_right(self.0[0], 8)]) } - #[inline] + #[inline(always)] fn rotate_each_word_right11(self) -> Self { Self([rotate_u128_right(self.0[0], 11)]) } - #[inline] + #[inline(always)] fn rotate_each_word_right12(self) -> Self { Self([rotate_u128_right(self.0[0], 12)]) } - #[inline] + #[inline(always)] fn rotate_each_word_right16(self) -> Self { Self([rotate_u128_right(self.0[0], 16)]) } - #[inline] + #[inline(always)] fn rotate_each_word_right20(self) -> Self { Self([rotate_u128_right(self.0[0], 20)]) } - #[inline] + #[inline(always)] fn rotate_each_word_right24(self) -> Self { Self([rotate_u128_right(self.0[0], 24)]) } - #[inline] + #[inline(always)] fn rotate_each_word_right25(self) -> Self { Self([rotate_u128_right(self.0[0], 25)]) } } impl RotateEachWord64 for u128x1_generic { - #[inline] + #[inline(always)] fn rotate_each_word_right32(self) -> Self { Self([rotate_u128_right(self.0[0], 32)]) } @@ -430,7 +438,7 @@ impl Machine for GenericMachine { type u32x4x4 = u32x4x4_generic; type u64x2x4 = u64x2x4_generic; type u128x4 = u128x4_generic; - #[inline] + #[inline(always)] unsafe fn instance() -> Self { Self } @@ -747,7 +755,7 @@ impl u128x4 for u128x4_generic {} #[macro_export] macro_rules! dispatch { ($mach:ident, $MTy:ident, { $([$pub:tt$(($krate:tt))*])* fn $name:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty $body:block }) => { - #[inline] + #[inline(always)] $($pub$(($krate))*)* fn $name($($arg: $argty),*) -> $ret { let $mach = unsafe { $crate::generic::GenericMachine::instance() }; #[inline(always)] @@ -764,7 +772,7 @@ macro_rules! dispatch { #[macro_export] macro_rules! dispatch_light128 { ($mach:ident, $MTy:ident, { $([$pub:tt$(($krate:tt))*])* fn $name:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty $body:block }) => { - #[inline] + #[inline(always)] $($pub$(($krate))*)* fn $name($($arg: $argty),*) -> $ret { let $mach = unsafe { $crate::generic::GenericMachine::instance() }; #[inline(always)] @@ -781,7 +789,7 @@ macro_rules! dispatch_light128 { #[macro_export] macro_rules! dispatch_light256 { ($mach:ident, $MTy:ident, { $([$pub:tt$(($krate:tt))*])* fn $name:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty $body:block }) => { - #[inline] + #[inline(always)] $($pub$(($krate))*)* fn $name($($arg: $argty),*) -> $ret { let $mach = unsafe { $crate::generic::GenericMachine::instance() }; #[inline(always)] @@ -798,7 +806,7 @@ macro_rules! dispatch_light256 { #[macro_export] macro_rules! dispatch_light512 { ($mach:ident, $MTy:ident, { $([$pub:tt$(($krate:tt))*])* fn $name:ident($($arg:ident: $argty:ty),* $(,)*) -> $ret:ty $body:block }) => { - #[inline] + #[inline(always)] $($pub$(($krate))*)* fn $name($($arg: $argty),*) -> $ret { let $mach = unsafe { $crate::generic::GenericMachine::instance() }; #[inline(always)] diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index d7455d0c..bda6bb5e 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -167,9 +167,11 @@ impl Default for vec256_storage { } } impl vec256_storage { + #[inline(always)] pub fn new128(xs: [vec128_storage; 2]) -> Self { Self { sse2: xs } } + #[inline(always)] pub fn split128(self) -> [vec128_storage; 2] { unsafe { self.sse2 } } @@ -200,9 +202,11 @@ impl Default for vec512_storage { } } impl vec512_storage { + #[inline(always)] pub fn new128(xs: [vec128_storage; 4]) -> Self { Self { sse2: xs } } + #[inline(always)] pub fn split128(self) -> [vec128_storage; 4] { unsafe { self.sse2 } } From cd329d1a3ae5547c066e0901e9b76b3f4b258e3f Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 13:35:20 -0700 Subject: [PATCH 45/84] ppv-lite86: impl transpose4 and to_scalars Only for u32x4x4 types for now, in principle the transpose family and to_scalars could be implemented for almost everything. --- utils-simd/ppv-lite86/src/soft.rs | 11 +++++ utils-simd/ppv-lite86/src/types.rs | 11 +++++ utils-simd/ppv-lite86/src/x86_64/sse2.rs | 53 ++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index 8976c484..b66eaf90 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -310,6 +310,17 @@ impl Vec4 for x4 { self } } +impl Vec4Ext for x4 { + #[inline(always)] + fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) where Self: Sized { + ( + x4([a.0[0], b.0[0], c.0[0], d.0[0]]), + x4([a.0[1], b.0[1], c.0[1], d.0[1]]), + x4([a.0[2], b.0[2], c.0[2], d.0[2]]), + x4([a.0[3], b.0[3], c.0[3], d.0[3]]) + ) + } +} impl> Store for x4 { #[inline(always)] unsafe fn unpack(p: vec512_storage) -> Self { diff --git a/utils-simd/ppv-lite86/src/types.rs b/utils-simd/ppv-lite86/src/types.rs index a2826707..2aa796ec 100644 --- a/utils-simd/ppv-lite86/src/types.rs +++ b/utils-simd/ppv-lite86/src/types.rs @@ -71,6 +71,15 @@ pub trait Vec4 { fn extract(self, i: u32) -> W; fn insert(self, w: W, i: u32) -> Self; } +/// Vec4 functions which may not be implemented yet for all Vec4 types. +/// NOTE: functions in this trait may be moved to Vec4 in any patch release. To avoid breakage, +/// import Vec4Ext only together with Vec4, and don't qualify its methods. +pub trait Vec4Ext { + fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) where Self: Sized; +} +pub trait Vector { + fn to_scalars(self) -> T; +} // TODO: multiples of 4 should inherit this /// A vector composed of four words; depending on their size, operations may cross lanes. @@ -169,6 +178,8 @@ pub trait u32x4x4: BitOps32 + Store + Vec4 + + Vec4Ext + + Vector<[u32; 16]> + MultiLane<[M::u32x4; 4]> + ArithOps + LaneWords4 diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index bf0063fb..b0e33056 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -880,6 +880,15 @@ pub type u64x2x4_sse2 = x4>; #[allow(non_camel_case_types)] pub type u128x4_sse2 = x4>; +impl Vector<[u32; 16]> for u32x4x4_sse2 { + #[inline(always)] + fn to_scalars(self) -> [u32; 16] { + unsafe { + core::mem::transmute(self) + } + } +} + impl u32x4x2> for u32x4x2_sse2 where u32x4_sse2: RotateEachWord32 + BSwap, @@ -983,6 +992,8 @@ where Machine86: Machine, u32x4x4_sse2: MultiLane<[ as Machine>::u32x4; 4]>, u32x4x4_sse2: Vec4< as Machine>::u32x4>, + u32x4x4_sse2: Vec4Ext< as Machine>::u32x4>, + u32x4x4_sse2: Vector<[u32; 16]>, { } impl u64x2x4> for u64x2x4_sse2 @@ -1010,6 +1021,8 @@ where Avx2Machine: Machine, u32x4x4_sse2: MultiLane<[ as Machine>::u32x4; 4]>, u32x4x4_sse2: Vec4< as Machine>::u32x4>, + u32x4x4_sse2: Vec4Ext< as Machine>::u32x4>, + u32x4x4_sse2: Vector<[u32; 16]>, { } impl u64x2x4> for u64x2x4_sse2 @@ -1450,6 +1463,46 @@ pub mod avx2 { }) } } + impl Vec4Ext> for u32x4x4_avx2 { + #[inline(always)] + fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) { + /* + * a00:a01 a10:a11 + * b00:b01 b10:b11 + * c00:c01 c10:c11 + * d00:d01 d10:d11 + * => + * a00:b00 c00:d00 + * a01:b01 c01:d01 + * a10:b10 c10:d10 + * a11:b11 c11:d11 + */ + unsafe { + let ab00 = _mm256_permute2x128_si256::<0x20>(a.x[0], b.x[0]); + let ab01 = _mm256_permute2x128_si256::<0x31>(a.x[0], b.x[0]); + let ab10 = _mm256_permute2x128_si256::<0x20>(a.x[1], b.x[1]); + let ab11 = _mm256_permute2x128_si256::<0x31>(a.x[1], b.x[1]); + let cd00 = _mm256_permute2x128_si256::<0x20>(c.x[0], d.x[0]); + let cd01 = _mm256_permute2x128_si256::<0x31>(c.x[0], d.x[0]); + let cd10 = _mm256_permute2x128_si256::<0x20>(c.x[1], d.x[1]); + let cd11 = _mm256_permute2x128_si256::<0x31>(c.x[1], d.x[1]); + ( + Self { x: [ab00, cd00], ni: a.ni }, + Self { x: [ab01, cd01], ni: a.ni }, + Self { x: [ab10, cd10], ni: a.ni }, + Self { x: [ab11, cd11], ni: a.ni }, + ) + } + } + } + impl Vector<[u32; 16]> for u32x4x4_avx2 { + #[inline(always)] + fn to_scalars(self) -> [u32; 16] { + unsafe { + core::mem::transmute(self) + } + } + } impl LaneWords4 for u32x4x4_avx2 { #[inline(always)] fn shuffle_lane_words1230(self) -> Self { From f491a3a171eb06991026319f53cd0b566a9b89b1 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 21:48:28 -0700 Subject: [PATCH 46/84] Creating FUNDING.yml --- .github/FUNDING.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .github/FUNDING.yml diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 00000000..6b83dc1f --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1,3 @@ +# These are supported funding model platforms + +github: kazcw From 26f6b9171f2e61ead18c32bf00d780adb1bc8f66 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 21:41:39 -0700 Subject: [PATCH 47/84] README: remove obsolete section --- README.md | 20 -------------------- 1 file changed, 20 deletions(-) diff --git a/README.md b/README.md index 63dfb239..269177e3 100644 --- a/README.md +++ b/README.md @@ -38,26 +38,6 @@ runtime CPU detection is not yet supported. | ---------- | ---------- | ------------------ | | ChaCha | c2-chacha | :heavy_check_mark: | -## SIMD - -Many of the crates in this project include optimized SIMD implementations, -enabled by default on x86-64 by the "simd" feature. The fastest implementation -available for your hardware will be automatically selected at runtime, except -in no-std builds. - -For other hardware platforms, e.g. ARM: an alternative, portable SIMD backend -based on the packed\_simd crate is available for recent nightly Rust; you can -enable it as "packed\_simd". - -If you'd prefer to minimize usage of `unsafe` code: disable the "simd" feature -to switch to a generic implementation. - -| feature | crate | no `unsafe` | rust version | build time? | performance | -| -------------- | ------------ | ------------------ | -------------- | ----------- | ------------- | -| simd (default) | ppv\_lite86 | :x: | 1.27 | fast | fast | -| (no simd) | ppv\_null | :heavy_check_mark: | | fast | slow | -| packed\_simd | packed\_simd | | recent nightly | slow | fast | - ## License All crates licensed under either of From a9d2b13d971d023328db6fab1c85cbd2ac69aa0e Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 22:06:44 -0700 Subject: [PATCH 48/84] build scripts: bring up to date --- test_alt_simd.sh | 18 ------------------ test_stable.sh | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) delete mode 100755 test_alt_simd.sh diff --git a/test_alt_simd.sh b/test_alt_simd.sh deleted file mode 100755 index 3886fd58..00000000 --- a/test_alt_simd.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/sh - -if [ -n "$FAILFAST" ]; then set -e; fi - -# no SIMD yet: -# - hashes/threefish -# - block-ciphers/skein - -# not ported to crypto-simd API yet: -# - hashes/groestl - -echo GENERIC -pushd stream-ciphers/chacha; cargo test --features no_simd; popd - -#echo BACKEND packed_simd -#cd hashes/blake; cargo test --no-default-features --features packed_simd,std; cd ../.. -#cd hashes/jh; cargo test -p jh-x86_64 --no-default-features --features packed_simd,std; cd ../.. -#cd stream-ciphers/chacha; cargo test --no-default-features --features packed_simd,std; cd ../.. diff --git a/test_stable.sh b/test_stable.sh index b0048dc9..fda2e9d7 100755 --- a/test_stable.sh +++ b/test_stable.sh @@ -1,4 +1,4 @@ #!/bin/sh +cargo +1.32.0-x86_64-unknown-linux-gnu test cargo +stable test -cargo +1.31.1-x86_64-unknown-linux-gnu test From 1ba3096db5f60262917acb2725bb649a34afe3ae Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 22:26:30 -0700 Subject: [PATCH 49/84] use stable syntax for const intrinsic args Fixes #48. --- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index b0e33056..7ce291b1 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -1478,14 +1478,14 @@ pub mod avx2 { * a11:b11 c11:d11 */ unsafe { - let ab00 = _mm256_permute2x128_si256::<0x20>(a.x[0], b.x[0]); - let ab01 = _mm256_permute2x128_si256::<0x31>(a.x[0], b.x[0]); - let ab10 = _mm256_permute2x128_si256::<0x20>(a.x[1], b.x[1]); - let ab11 = _mm256_permute2x128_si256::<0x31>(a.x[1], b.x[1]); - let cd00 = _mm256_permute2x128_si256::<0x20>(c.x[0], d.x[0]); - let cd01 = _mm256_permute2x128_si256::<0x31>(c.x[0], d.x[0]); - let cd10 = _mm256_permute2x128_si256::<0x20>(c.x[1], d.x[1]); - let cd11 = _mm256_permute2x128_si256::<0x31>(c.x[1], d.x[1]); + let ab00 = _mm256_permute2x128_si256(a.x[0], b.x[0], 0x20); + let ab01 = _mm256_permute2x128_si256(a.x[0], b.x[0], 0x31); + let ab10 = _mm256_permute2x128_si256(a.x[1], b.x[1], 0x20); + let ab11 = _mm256_permute2x128_si256(a.x[1], b.x[1], 0x31); + let cd00 = _mm256_permute2x128_si256(c.x[0], d.x[0], 0x20); + let cd01 = _mm256_permute2x128_si256(c.x[0], d.x[0], 0x31); + let cd10 = _mm256_permute2x128_si256(c.x[1], d.x[1], 0x20); + let cd11 = _mm256_permute2x128_si256(c.x[1], d.x[1], 0x31); ( Self { x: [ab00, cd00], ni: a.ni }, Self { x: [ab01, cd01], ni: a.ni }, From b18a9e996144d7d54ea9a4a940343f90b7a2a10f Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 22:29:49 -0700 Subject: [PATCH 50/84] ppv-lite86: release 0.2.12 --- utils-simd/ppv-lite86/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 2d257de6..e1dd427d 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.11" +version = "0.2.12" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" From ea81be19e2dc4bfcc0c3f774e7e5d286558a18d4 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 22:55:56 -0700 Subject: [PATCH 51/84] ppv-lite86: soft impl for to_scalars --- utils-simd/ppv-lite86/src/generic.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 0731875c..483890eb 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -615,6 +615,22 @@ pub type u32x4x4_generic = x4; pub type u64x2x4_generic = x4; pub type u128x4_generic = x4; +impl Vector<[u32; 16]> for u32x4x4_generic { + fn to_scalars(self) -> [u32; 16] { + let [a, b, c, d] = self.0; + let a = a.0; + let b = b.0; + let c = c.0; + let d = d.0; + [ + a[0], b[0], c[0], d[0], + a[1], b[1], c[1], d[1], + a[2], b[2], c[2], d[2], + a[3], b[3], c[3], d[3], + ] + } +} + impl MultiLane<[u32; 4]> for u32x4_generic { #[inline(always)] fn to_lanes(self) -> [u32; 4] { From 1f2656db4427424cf69e01ad1663740adcb05f98 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 23:01:24 -0700 Subject: [PATCH 52/84] ppv-lite86: release 0.2.13 --- utils-simd/ppv-lite86/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index e1dd427d..947b7ffc 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.12" +version = "0.2.13" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" From df1d97c0bb9e2fcee26f5b5557d17e8494a3722f Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 23:15:48 -0700 Subject: [PATCH 53/84] ppv-lite86: fix soft impl of to_scalars --- utils-simd/ppv-lite86/src/generic.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 483890eb..473dab42 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -623,10 +623,10 @@ impl Vector<[u32; 16]> for u32x4x4_generic { let c = c.0; let d = d.0; [ - a[0], b[0], c[0], d[0], - a[1], b[1], c[1], d[1], - a[2], b[2], c[2], d[2], - a[3], b[3], c[3], d[3], + a[0], a[1], a[2], a[3], + b[0], b[1], b[2], b[3], + c[0], c[1], c[2], c[3], + d[0], d[1], d[2], d[3], ] } } From 317588170054f6a9434daca1d4d74532bb03abc1 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Wed, 13 Oct 2021 23:17:47 -0700 Subject: [PATCH 54/84] ppv-lite86: release 0.2.14 --- utils-simd/ppv-lite86/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 947b7ffc..4903a5e5 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.13" +version = "0.2.14" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" From e1059dc3bb1be6f08a9736f831e2de3b1f3e8701 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 14 Oct 2021 06:21:51 -0700 Subject: [PATCH 55/84] c2-chacha: improve AVX2 performance 16-48% --- stream-ciphers/chacha/Cargo.toml | 2 +- stream-ciphers/chacha/src/guts.rs | 99 ++++++++++++++++++------------- 2 files changed, 59 insertions(+), 42 deletions(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index d8012d5e..565533b5 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -12,7 +12,7 @@ readme = "README.md" documentation = "https://docs.rs/c2-chacha" [dependencies] -ppv-lite86 = { package = "ppv-lite86", version = "0.2.8", default-features = false } +ppv-lite86 = { package = "ppv-lite86", version = "0.2.14", default-features = false } cipher = { version = "0.2", optional = true } [dev-dependencies] diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 8fcce7b1..110ad927 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -2,7 +2,7 @@ pub use cipher::generic_array; pub use ppv_lite86::Machine; -use ppv_lite86::{vec128_storage, ArithOps, BitOps32, LaneWords4, MultiLane, StoreBytes, Vec4}; +use ppv_lite86::{vec128_storage, ArithOps, BitOps32, LaneWords4, MultiLane, StoreBytes, Vec4, Vec4Ext, Vector}; pub(crate) const BLOCK: usize = 64; pub(crate) const BLOCK64: u64 = BLOCK as u64; @@ -194,64 +194,81 @@ impl ChaCha { } } +// This implementation is platform-independent. #[inline(always)] -#[allow(clippy::many_single_char_names)] -fn refill_wide_impl( - m: Mach, - state: &mut ChaCha, - drounds: u32, - out: &mut [u8; BUFSZ], -) { - let k = m.vec([0x6170_7865, 0x3320_646e, 0x7962_2d32, 0x6b20_6574]); - let mut pos = state.pos64(m); - let d0: Mach::u32x4 = m.unpack(state.d); - pos += 1; +#[cfg(target_endian = "big")] +fn add_pos(_m: Mach, d0: Mach::u32x4, i: u64) -> Mach::u32x4 { + let pos0 = ((d0.extract(1) as u64) << 32) | d0.extract(0) as u64; + let pos = pos0.wrapping_add(i); + d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0) +} +#[inline(always)] +#[cfg(target_endian = "big")] +fn d0123(m: Mach, d: vec128_storage) -> Mach::u32x4x4 { + let d0: Mach::u32x4 = m.unpack(d); + let mut pos = ((d0.extract(1) as u64) << 32) | d0.extract(0) as u64; + pos = pos.wrapping_add(1); let d1 = d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0); - pos += 1; + pos = pos.wrapping_add(1); let d2 = d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0); - pos += 1; + pos = pos.wrapping_add(1); let d3 = d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0); + Mach::u32x4x4::from_lanes([d0, d1, d2, d3]) +} + +// Pos is packed into the state vectors as a little-endian u64, +// so on LE platforms we can use native vector ops to increment it. +#[inline(always)] +#[cfg(target_endian = "little")] +fn add_pos(m: Mach, d: Mach::u32x4, i: u64) -> Mach::u32x4 { + let d0: Mach::u64x2 = m.unpack(d.into()); + let incr = m.vec([i, 0]); + m.unpack((d0 + incr).into()) +} +#[inline(always)] +#[cfg(target_endian = "little")] +fn d0123(m: Mach, d: vec128_storage) -> Mach::u32x4x4 { + let d0: Mach::u64x2 = m.unpack(d); + let incr = Mach::u64x2x4::from_lanes([m.vec([0, 0]), m.vec([1, 0]), m.vec([2, 0]), m.vec([3, 0])]); + m.unpack((Mach::u64x2x4::from_lanes([d0, d0, d0, d0]) + incr).into()) +} +fn to_bytes(xs: [u32; 16]) -> [u8; 64] { + unsafe { + core::mem::transmute(xs) + } +} + +#[allow(clippy::many_single_char_names)] +#[inline(always)] +fn refill_wide_impl( + m: Mach, state: &mut ChaCha, drounds: u32, out: &mut [u8; BUFSZ], +) { + let k = m.vec([0x6170_7865, 0x3320_646e, 0x7962_2d32, 0x6b20_6574]); let b = m.unpack(state.b); let c = m.unpack(state.c); let mut x = State { a: Mach::u32x4x4::from_lanes([k, k, k, k]), b: Mach::u32x4x4::from_lanes([b, b, b, b]), c: Mach::u32x4x4::from_lanes([c, c, c, c]), - d: m.unpack(Mach::u32x4x4::from_lanes([d0, d1, d2, d3]).into()), + d: d0123(m, state.d), }; for _ in 0..drounds { x = round(x); x = undiagonalize(round(diagonalize(x))); } - let mut pos = state.pos64(m); - let d0: Mach::u32x4 = m.unpack(state.d); - pos += 1; - let d1 = d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0); - pos += 1; - let d2 = d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0); - pos += 1; - let d3 = d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0); - pos += 1; - let d4 = d0.insert((pos >> 32) as u32, 1).insert(pos as u32, 0); - - let (a, b, c, d) = ( - x.a.to_lanes(), - x.b.to_lanes(), - x.c.to_lanes(), - x.d.to_lanes(), - ); + let kk = Mach::u32x4x4::from_lanes([k, k, k, k]); let sb = m.unpack(state.b); + let sb = Mach::u32x4x4::from_lanes([sb, sb, sb, sb]); let sc = m.unpack(state.c); - let sd = [m.unpack(state.d), d1, d2, d3]; - state.d = d4.into(); - let mut words = out.chunks_exact_mut(16); - for ((((&a, &b), &c), &d), &sd) in a.iter().zip(&b).zip(&c).zip(&d).zip(&sd) { - (a + k).write_le(words.next().unwrap()); - (b + sb).write_le(words.next().unwrap()); - (c + sc).write_le(words.next().unwrap()); - (d + sd).write_le(words.next().unwrap()); - } + let sc = Mach::u32x4x4::from_lanes([sc, sc, sc, sc]); + let sd = d0123(m, state.d); + let results = Mach::u32x4x4::transpose4(x.a + kk, x.b + sb, x.c + sc, x.d + sd); + out[0..64].copy_from_slice(&to_bytes(results.0.to_scalars())); + out[64..128].copy_from_slice(&to_bytes(results.1.to_scalars())); + out[128..192].copy_from_slice(&to_bytes(results.2.to_scalars())); + out[192..256].copy_from_slice(&to_bytes(results.3.to_scalars())); + state.d = add_pos(m, sd.to_lanes()[0], 4).into(); } dispatch!(m, Mach, { From 0929e74bc55d8555c296b1e262a5f228e6c59ca0 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 14 Oct 2021 06:27:43 -0700 Subject: [PATCH 56/84] c2-chacha: release 0.3.2 --- stream-ciphers/chacha/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index 565533b5..c907b061 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c2-chacha" -version = "0.3.1" +version = "0.3.2" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" edition = "2018" From 766ae7d1c464dbefda4afaba7df9885ceb40066b Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 14 Oct 2021 06:36:37 -0700 Subject: [PATCH 57/84] c2-chacha: fix no-std build --- stream-ciphers/chacha/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/stream-ciphers/chacha/src/lib.rs b/stream-ciphers/chacha/src/lib.rs index 17fe3588..6131682f 100644 --- a/stream-ciphers/chacha/src/lib.rs +++ b/stream-ciphers/chacha/src/lib.rs @@ -4,6 +4,8 @@ //! //! Stream-cipher usage: //! ``` +//! #[cfg(features = "std")] +//! fn demo() { //! extern crate c2_chacha; //! //! use c2_chacha::stream_cipher::{NewStreamCipher, SyncStreamCipher, SyncStreamCipherSeek}; @@ -26,6 +28,7 @@ //! for chunk in buffer.chunks_mut(3) { //! cipher.apply_keystream(chunk); //! } +//! } //! ``` #![cfg_attr(not(feature = "std"), no_std)] From 3a0503b5b48cc53f894c17b98416cfc675564f72 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 09:20:06 -0700 Subject: [PATCH 58/84] ppv-lite86: remove an obsolete impl --- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 7ce291b1..8cbebf5e 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -1015,16 +1015,6 @@ where { } -impl u32x4x4> for u32x4x4_sse2 -where - u32x4_sse2: RotateEachWord32 + BSwap, - Avx2Machine: Machine, - u32x4x4_sse2: MultiLane<[ as Machine>::u32x4; 4]>, - u32x4x4_sse2: Vec4< as Machine>::u32x4>, - u32x4x4_sse2: Vec4Ext< as Machine>::u32x4>, - u32x4x4_sse2: Vector<[u32; 16]>, -{ -} impl u64x2x4> for u64x2x4_sse2 where u64x2_sse2: RotateEachWord64 + RotateEachWord32 + BSwap, From c9aa3995a58ebcaa42ded7ede3e0682e0aa9bfde Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 10:33:06 -0700 Subject: [PATCH 59/84] ppv-lite86: x2/x4 had some assumptions that were only valid for the types it was in use for --- utils-simd/ppv-lite86/src/soft.rs | 44 +++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index b66eaf90..1d18f79d 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -175,22 +175,23 @@ impl BSwap for x2 { impl StoreBytes for x2 { #[inline(always)] unsafe fn unsafe_read_le(input: &[u8]) -> Self { - let input = input.split_at(16); + let input = input.split_at(input.len() / 2); x2::new([W::unsafe_read_le(input.0), W::unsafe_read_le(input.1)]) } #[inline(always)] unsafe fn unsafe_read_be(input: &[u8]) -> Self { - x2::unsafe_read_le(input).bswap() + let input = input.split_at(input.len() / 2); + x2::new([W::unsafe_read_be(input.0), W::unsafe_read_be(input.1)]) } #[inline(always)] fn write_le(self, out: &mut [u8]) { - let out = out.split_at_mut(16); + let out = out.split_at_mut(out.len() / 2); self.0[0].write_le(out.0); self.0[1].write_le(out.1); } #[inline(always)] fn write_be(self, out: &mut [u8]) { - let out = out.split_at_mut(16); + let out = out.split_at_mut(out.len() / 2); self.0[0].write_be(out.0); self.0[1].write_be(out.1); } @@ -379,30 +380,39 @@ impl BSwap for x4 { impl StoreBytes for x4 { #[inline(always)] unsafe fn unsafe_read_le(input: &[u8]) -> Self { + let n = input.len() / 4; x4([ - W::unsafe_read_le(&input[0..16]), - W::unsafe_read_le(&input[16..32]), - W::unsafe_read_le(&input[32..48]), - W::unsafe_read_le(&input[48..64]), + W::unsafe_read_le(&input[..n]), + W::unsafe_read_le(&input[n..n * 2]), + W::unsafe_read_le(&input[n * 2..n * 3]), + W::unsafe_read_le(&input[n * 3..]), ]) } #[inline(always)] unsafe fn unsafe_read_be(input: &[u8]) -> Self { - x4::unsafe_read_le(input).bswap() + let n = input.len() / 4; + x4([ + W::unsafe_read_be(&input[..n]), + W::unsafe_read_be(&input[n..n * 2]), + W::unsafe_read_be(&input[n * 2..n * 3]), + W::unsafe_read_be(&input[n * 3..]), + ]) } #[inline(always)] fn write_le(self, out: &mut [u8]) { - self.0[0].write_le(&mut out[0..16]); - self.0[1].write_le(&mut out[16..32]); - self.0[2].write_le(&mut out[32..48]); - self.0[3].write_le(&mut out[48..64]); + let n = out.len() / 4; + self.0[0].write_le(&mut out[..n]); + self.0[1].write_le(&mut out[n..n * 2]); + self.0[2].write_le(&mut out[n * 2..n * 3]); + self.0[3].write_le(&mut out[n * 3..]); } #[inline(always)] fn write_be(self, out: &mut [u8]) { - self.0[0].write_be(&mut out[0..16]); - self.0[1].write_be(&mut out[16..32]); - self.0[2].write_be(&mut out[32..48]); - self.0[3].write_be(&mut out[48..64]); + let n = out.len() / 4; + self.0[0].write_be(&mut out[..n]); + self.0[1].write_be(&mut out[n..n * 2]); + self.0[2].write_be(&mut out[n * 2..n * 3]); + self.0[3].write_be(&mut out[n * 3..]); } } impl LaneWords4 for x4 { From 511ac7ed35a95a01f52c1dc6fe16b582fe1173fd Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 09:50:39 -0700 Subject: [PATCH 60/84] ppv-lite86: new u32x4x2_avx2; use to impl u32x4x4_avx2 --- utils-simd/ppv-lite86/src/soft.rs | 23 ++ utils-simd/ppv-lite86/src/x86_64/mod.rs | 2 +- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 319 +++++++++++++---------- 3 files changed, 203 insertions(+), 141 deletions(-) diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index 1d18f79d..4a88fccf 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -196,6 +196,29 @@ impl StoreBytes for x2 { self.0[1].write_be(out.1); } } +impl LaneWords4 for x2 { + #[inline(always)] + fn shuffle_lane_words2301(self) -> Self { + Self::new([ + self.0[0].shuffle_lane_words2301(), + self.0[1].shuffle_lane_words2301(), + ]) + } + #[inline(always)] + fn shuffle_lane_words1230(self) -> Self { + Self::new([ + self.0[0].shuffle_lane_words1230(), + self.0[1].shuffle_lane_words1230(), + ]) + } + #[inline(always)] + fn shuffle_lane_words3012(self) -> Self { + Self::new([ + self.0[0].shuffle_lane_words3012(), + self.0[1].shuffle_lane_words3012(), + ]) + } +} #[derive(Copy, Clone, Default)] #[allow(non_camel_case_types)] diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index bda6bb5e..0538e3f7 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -79,7 +79,7 @@ where type u64x2 = sse2::u64x2_sse2; type u128x1 = sse2::u128x1_sse2; - type u32x4x2 = sse2::u32x4x2_sse2; + type u32x4x2 = sse2::avx2::u32x4x2_avx2; type u64x2x2 = sse2::u64x2x2_sse2; type u64x4 = sse2::u64x4_sse2; type u128x2 = sse2::u128x2_sse2; diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 8cbebf5e..965319d0 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -1377,65 +1377,58 @@ mod test { pub mod avx2 { #![allow(non_camel_case_types)] - use crate::soft::x4; + use crate::soft::{x2, x4}; use crate::types::*; - use crate::x86_64::sse2::{u128x1_sse2, u32x4_sse2}; + use crate::x86_64::sse2::{u128x1_sse2, u32x4_sse2, G0}; use crate::x86_64::{vec256_storage, vec512_storage, Avx2Machine, YesS3, YesS4}; use core::arch::x86_64::*; use core::marker::PhantomData; use core::ops::*; #[derive(Copy, Clone)] - pub struct u32x4x4_avx2 { - x: [__m256i; 2], + pub struct u32x4x2_avx2 { + x: __m256i, ni: PhantomData, } - impl u32x4x4_avx2 { + impl u32x4x2_avx2 { #[inline(always)] - fn new(x: [__m256i; 2]) -> Self { + fn new(x: __m256i) -> Self { Self { x, ni: PhantomData } } } - impl u32x4x4> for u32x4x4_avx2 where NI: Copy {} - impl Store for u32x4x4_avx2 { + impl u32x4x2> for u32x4x2_avx2 where NI: Copy {} + impl Store for u32x4x2_avx2 { #[inline(always)] - unsafe fn unpack(p: vec512_storage) -> Self { - Self::new([p.avx[0].avx, p.avx[1].avx]) + unsafe fn unpack(p: vec256_storage) -> Self { + Self::new(p.avx) } } - impl MultiLane<[u32x4_sse2; 4]> for u32x4x4_avx2 { + impl MultiLane<[u32x4_sse2; 2]> for u32x4x2_avx2 { #[inline(always)] - fn to_lanes(self) -> [u32x4_sse2; 4] { + fn to_lanes(self) -> [u32x4_sse2; 2] { unsafe { [ - u32x4_sse2::new(_mm256_extracti128_si256(self.x[0], 0)), - u32x4_sse2::new(_mm256_extracti128_si256(self.x[0], 1)), - u32x4_sse2::new(_mm256_extracti128_si256(self.x[1], 0)), - u32x4_sse2::new(_mm256_extracti128_si256(self.x[1], 1)), + u32x4_sse2::new(_mm256_extracti128_si256(self.x, 0)), + u32x4_sse2::new(_mm256_extracti128_si256(self.x, 1)), ] } } #[inline(always)] - fn from_lanes(x: [u32x4_sse2; 4]) -> Self { + fn from_lanes(x: [u32x4_sse2; 2]) -> Self { Self::new(unsafe { - [ - _mm256_setr_m128i(x[0].x, x[1].x), - _mm256_setr_m128i(x[2].x, x[3].x), - ] + _mm256_setr_m128i(x[0].x, x[1].x) }) } } - impl Vec4> for u32x4x4_avx2 { + impl Vec2> for u32x4x2_avx2 { #[inline(always)] fn extract(self, i: u32) -> u32x4_sse2 { unsafe { match i { - 0 => u32x4_sse2::new(_mm256_extracti128_si256(self.x[0], 0)), - 1 => u32x4_sse2::new(_mm256_extracti128_si256(self.x[0], 1)), - 2 => u32x4_sse2::new(_mm256_extracti128_si256(self.x[1], 0)), - 3 => u32x4_sse2::new(_mm256_extracti128_si256(self.x[1], 1)), + 0 => u32x4_sse2::new(_mm256_extracti128_si256(self.x, 0)), + 1 => u32x4_sse2::new(_mm256_extracti128_si256(self.x, 1)), _ => panic!(), } } @@ -1444,95 +1437,21 @@ pub mod avx2 { fn insert(self, w: u32x4_sse2, i: u32) -> Self { Self::new(unsafe { match i { - 0 => [_mm256_inserti128_si256(self.x[0], w.x, 0), self.x[1]], - 1 => [_mm256_inserti128_si256(self.x[0], w.x, 1), self.x[1]], - 2 => [self.x[0], _mm256_inserti128_si256(self.x[1], w.x, 0)], - 3 => [self.x[0], _mm256_inserti128_si256(self.x[1], w.x, 1)], + 0 => _mm256_inserti128_si256(self.x, w.x, 0), + 1 => _mm256_inserti128_si256(self.x, w.x, 1), _ => panic!(), } }) } } - impl Vec4Ext> for u32x4x4_avx2 { - #[inline(always)] - fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) { - /* - * a00:a01 a10:a11 - * b00:b01 b10:b11 - * c00:c01 c10:c11 - * d00:d01 d10:d11 - * => - * a00:b00 c00:d00 - * a01:b01 c01:d01 - * a10:b10 c10:d10 - * a11:b11 c11:d11 - */ - unsafe { - let ab00 = _mm256_permute2x128_si256(a.x[0], b.x[0], 0x20); - let ab01 = _mm256_permute2x128_si256(a.x[0], b.x[0], 0x31); - let ab10 = _mm256_permute2x128_si256(a.x[1], b.x[1], 0x20); - let ab11 = _mm256_permute2x128_si256(a.x[1], b.x[1], 0x31); - let cd00 = _mm256_permute2x128_si256(c.x[0], d.x[0], 0x20); - let cd01 = _mm256_permute2x128_si256(c.x[0], d.x[0], 0x31); - let cd10 = _mm256_permute2x128_si256(c.x[1], d.x[1], 0x20); - let cd11 = _mm256_permute2x128_si256(c.x[1], d.x[1], 0x31); - ( - Self { x: [ab00, cd00], ni: a.ni }, - Self { x: [ab01, cd01], ni: a.ni }, - Self { x: [ab10, cd10], ni: a.ni }, - Self { x: [ab11, cd11], ni: a.ni }, - ) - } - } - } - impl Vector<[u32; 16]> for u32x4x4_avx2 { - #[inline(always)] - fn to_scalars(self) -> [u32; 16] { - unsafe { - core::mem::transmute(self) - } - } - } - impl LaneWords4 for u32x4x4_avx2 { - #[inline(always)] - fn shuffle_lane_words1230(self) -> Self { - Self::new(unsafe { - [ - _mm256_shuffle_epi32(self.x[0], 0b1001_0011), - _mm256_shuffle_epi32(self.x[1], 0b1001_0011), - ] - }) - } - #[inline(always)] - fn shuffle_lane_words2301(self) -> Self { - Self::new(unsafe { - [ - _mm256_shuffle_epi32(self.x[0], 0b0100_1110), - _mm256_shuffle_epi32(self.x[1], 0b0100_1110), - ] - }) - } - #[inline(always)] - fn shuffle_lane_words3012(self) -> Self { - Self::new(unsafe { - [ - _mm256_shuffle_epi32(self.x[0], 0b0011_1001), - _mm256_shuffle_epi32(self.x[1], 0b0011_1001), - ] - }) - } - } - impl BitOps32 for u32x4x4_avx2 where NI: Copy {} - impl ArithOps for u32x4x4_avx2 where NI: Copy {} + impl BitOps32 for u32x4x2_avx2 where NI: Copy {} + impl ArithOps for u32x4x2_avx2 where NI: Copy {} macro_rules! shuf_lane_bytes { ($name:ident, $k0:expr, $k1:expr) => { #[inline(always)] fn $name(self) -> Self { Self::new(unsafe { - [ - _mm256_shuffle_epi8(self.x[0], _mm256_set_epi64x($k0, $k1, $k0, $k1)), - _mm256_shuffle_epi8(self.x[1], _mm256_set_epi64x($k0, $k1, $k0, $k1)), - ] + _mm256_shuffle_epi8(self.x, _mm256_set_epi64x($k0, $k1, $k0, $k1)) }) } }; @@ -1542,21 +1461,15 @@ pub mod avx2 { #[inline(always)] fn $name(self) -> Self { Self::new(unsafe { - [ - _mm256_or_si256( - _mm256_srli_epi32(self.x[0], $i as i32), - _mm256_slli_epi32(self.x[0], 32 - $i as i32), - ), - _mm256_or_si256( - _mm256_srli_epi32(self.x[1], $i as i32), - _mm256_slli_epi32(self.x[1], 32 - $i as i32), - ), - ] + _mm256_or_si256( + _mm256_srli_epi32(self.x, $i as i32), + _mm256_slli_epi32(self.x, 32 - $i as i32), + ) }) } }; } - impl RotateEachWord32 for u32x4x4_avx2 { + impl RotateEachWord32 for u32x4x2_avx2 { rotr_32!(rotate_each_word_right7, 7); shuf_lane_bytes!( rotate_each_word_right8, @@ -1578,15 +1491,12 @@ pub mod avx2 { ); rotr_32!(rotate_each_word_right25, 25); } - impl BitOps0 for u32x4x4_avx2 where NI: Copy {} - impl From> for vec512_storage { + impl BitOps0 for u32x4x2_avx2 where NI: Copy {} + impl From> for vec256_storage { #[inline(always)] - fn from(x: u32x4x4_avx2) -> Self { + fn from(x: u32x4x2_avx2) -> Self { Self { - avx: [ - vec256_storage { avx: x.x[0] }, - vec256_storage { avx: x.x[1] }, - ], + avx: x.x, } } } @@ -1604,55 +1514,184 @@ pub mod avx2 { } }; } - impl_assign!(u32x4x4_avx2, BitXorAssign, bitxor_assign, bitxor); - impl_assign!(u32x4x4_avx2, BitOrAssign, bitor_assign, bitor); - impl_assign!(u32x4x4_avx2, BitAndAssign, bitand_assign, bitand); - impl_assign!(u32x4x4_avx2, AddAssign, add_assign, add); + impl_assign!(u32x4x2_avx2, BitXorAssign, bitxor_assign, bitxor); + impl_assign!(u32x4x2_avx2, BitOrAssign, bitor_assign, bitor); + impl_assign!(u32x4x2_avx2, BitAndAssign, bitand_assign, bitand); + impl_assign!(u32x4x2_avx2, AddAssign, add_assign, add); - macro_rules! impl_bitop_x2 { + macro_rules! impl_bitop { ($vec:ident, $Op:ident, $op_fn:ident, $impl_fn:ident) => { impl $Op for $vec { type Output = Self; #[inline(always)] fn $op_fn(self, rhs: Self) -> Self::Output { Self::new(unsafe { - [$impl_fn(self.x[0], rhs.x[0]), $impl_fn(self.x[1], rhs.x[1])] + $impl_fn(self.x, rhs.x) }) } } }; } - impl_bitop_x2!(u32x4x4_avx2, BitXor, bitxor, _mm256_xor_si256); - impl_bitop_x2!(u32x4x4_avx2, BitOr, bitor, _mm256_or_si256); - impl_bitop_x2!(u32x4x4_avx2, BitAnd, bitand, _mm256_and_si256); - impl_bitop_x2!(u32x4x4_avx2, AndNot, andnot, _mm256_andnot_si256); - impl_bitop_x2!(u32x4x4_avx2, Add, add, _mm256_add_epi32); + impl_bitop!(u32x4x2_avx2, BitXor, bitxor, _mm256_xor_si256); + impl_bitop!(u32x4x2_avx2, BitOr, bitor, _mm256_or_si256); + impl_bitop!(u32x4x2_avx2, BitAnd, bitand, _mm256_and_si256); + impl_bitop!(u32x4x2_avx2, AndNot, andnot, _mm256_andnot_si256); + impl_bitop!(u32x4x2_avx2, Add, add, _mm256_add_epi32); - impl Not for u32x4x4_avx2 { + impl Not for u32x4x2_avx2 { type Output = Self; #[inline(always)] fn not(self) -> Self::Output { unsafe { let f = _mm256_set1_epi8(-0x7f); - Self::new([f, f]) ^ self + Self::new(f) ^ self } } } - impl BSwap for u32x4x4_avx2 { + impl BSwap for u32x4x2_avx2 { shuf_lane_bytes!(bswap, 0x0c0d_0e0f_0809_0a0b, 0x0405_0607_0001_0203); } - impl From>> for u32x4x4_avx2 + impl From, G0>> for u32x4x2_avx2 where NI: Copy, + { + #[inline(always)] + fn from(x: x2, G0>) -> Self { + Self::new(unsafe { + _mm256_setr_m128i(x.0[0].x, x.0[1].x) + }) + } + } + + impl LaneWords4 for u32x4x2_avx2 { + #[inline(always)] + fn shuffle_lane_words1230(self) -> Self { + Self::new(unsafe { + _mm256_shuffle_epi32(self.x, 0b1001_0011) + }) + } + #[inline(always)] + fn shuffle_lane_words2301(self) -> Self { + Self::new(unsafe { + _mm256_shuffle_epi32(self.x, 0b0100_1110) + }) + } + #[inline(always)] + fn shuffle_lane_words3012(self) -> Self { + Self::new(unsafe { + _mm256_shuffle_epi32(self.x, 0b0011_1001) + }) + } + } + + /////////////////////////////////////////////////////////////////////////////////////////// + + pub type u32x4x4_avx2 = x2, G0>; + impl u32x4x4> for u32x4x4_avx2 {} + + impl Store for u32x4x4_avx2 { + #[inline(always)] + unsafe fn unpack(p: vec512_storage) -> Self { + Self::new([u32x4x2_avx2::unpack(p.avx[0]), u32x4x2_avx2::unpack(p.avx[1])]) + } + } + impl MultiLane<[u32x4_sse2; 4]> for u32x4x4_avx2 { + #[inline(always)] + fn to_lanes(self) -> [u32x4_sse2; 4] { + let [a, b] = self.0[0].to_lanes(); + let [c, d] = self.0[1].to_lanes(); + [a, b, c, d] + } + #[inline(always)] + fn from_lanes(x: [u32x4_sse2; 4]) -> Self { + let ab = u32x4x2_avx2::from_lanes([x[0], x[1]]); + let cd = u32x4x2_avx2::from_lanes([x[2], x[3]]); + Self::new([ab, cd]) + } + } + impl Vec4> for u32x4x4_avx2 { + #[inline(always)] + fn extract(self, i: u32) -> u32x4_sse2 { + match i { + 0 => self.0[0].extract(0), + 1 => self.0[0].extract(1), + 2 => self.0[1].extract(0), + 3 => self.0[1].extract(1), + _ => panic!(), + } + } + #[inline(always)] + fn insert(self, w: u32x4_sse2, i: u32) -> Self { + Self::new(match i { + 0 => [self.0[0].insert(w, 0), self.0[1]], + 1 => [self.0[0].insert(w, 1), self.0[1]], + 2 => [self.0[0], self.0[1].insert(w, 0)], + 3 => [self.0[0], self.0[1].insert(w, 1)], + _ => panic!(), + }) + } + } + impl Vec4Ext> for u32x4x4_avx2 { + #[inline(always)] + fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) { + /* + * a00:a01 a10:a11 + * b00:b01 b10:b11 + * c00:c01 c10:c11 + * d00:d01 d10:d11 + * => + * a00:b00 c00:d00 + * a01:b01 c01:d01 + * a10:b10 c10:d10 + * a11:b11 c11:d11 + */ + unsafe { + let ab00 = u32x4x2_avx2::new(_mm256_permute2x128_si256(a.0[0].x, b.0[0].x, 0x20)); + let ab01 = u32x4x2_avx2::new(_mm256_permute2x128_si256(a.0[0].x, b.0[0].x, 0x31)); + let ab10 = u32x4x2_avx2::new(_mm256_permute2x128_si256(a.0[1].x, b.0[1].x, 0x20)); + let ab11 = u32x4x2_avx2::new(_mm256_permute2x128_si256(a.0[1].x, b.0[1].x, 0x31)); + let cd00 = u32x4x2_avx2::new(_mm256_permute2x128_si256(c.0[0].x, d.0[0].x, 0x20)); + let cd01 = u32x4x2_avx2::new(_mm256_permute2x128_si256(c.0[0].x, d.0[0].x, 0x31)); + let cd10 = u32x4x2_avx2::new(_mm256_permute2x128_si256(c.0[1].x, d.0[1].x, 0x20)); + let cd11 = u32x4x2_avx2::new(_mm256_permute2x128_si256(c.0[1].x, d.0[1].x, 0x31)); + ( + Self::new([ab00, cd00]), + Self::new([ab01, cd01]), + Self::new([ab10, cd10]), + Self::new([ab11, cd11]), + ) + } + } + } + impl Vector<[u32; 16]> for u32x4x4_avx2 { + #[inline(always)] + fn to_scalars(self) -> [u32; 16] { + unsafe { + core::mem::transmute(self) + } + } + } + impl From> for vec512_storage { + #[inline(always)] + fn from(x: u32x4x4_avx2) -> Self { + Self { + avx: [ + vec256_storage { avx: x.0[0].x }, + vec256_storage { avx: x.0[1].x }, + ], + } + } + } + impl From>> for u32x4x4_avx2 { #[inline(always)] fn from(x: x4>) -> Self { Self::new(unsafe { [ - _mm256_setr_m128i(x.0[0].x, x.0[1].x), - _mm256_setr_m128i(x.0[2].x, x.0[3].x), + u32x4x2_avx2::new(_mm256_setr_m128i(x.0[0].x, x.0[1].x)), + u32x4x2_avx2::new(_mm256_setr_m128i(x.0[2].x, x.0[3].x)), ] }) } From 66ee9720b2089d3bdc4b0f829b3e0f7d3a031b5c Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 10:24:58 -0700 Subject: [PATCH 61/84] ppv-lite86: impl StoreBytes for u32x4x2, u32x4x4 --- utils-simd/ppv-lite86/src/types.rs | 2 ++ utils-simd/ppv-lite86/src/x86_64/sse2.rs | 28 ++++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/utils-simd/ppv-lite86/src/types.rs b/utils-simd/ppv-lite86/src/types.rs index 2aa796ec..8a2acfcf 100644 --- a/utils-simd/ppv-lite86/src/types.rs +++ b/utils-simd/ppv-lite86/src/types.rs @@ -141,6 +141,7 @@ pub trait u32x4x2: + MultiLane<[M::u32x4; 2]> + ArithOps + Into + + StoreBytes { } pub trait u64x2x2: @@ -184,6 +185,7 @@ pub trait u32x4x4: + ArithOps + LaneWords4 + Into + + StoreBytes { } pub trait u64x2x4: diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 965319d0..85307901 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -1405,6 +1405,28 @@ pub mod avx2 { Self::new(p.avx) } } + impl StoreBytes for u32x4x2_avx2 { + #[inline(always)] + unsafe fn unsafe_read_le(input: &[u8]) -> Self { + assert_eq!(input.len(), 32); + Self::new(_mm256_loadu_si256(input.as_ptr() as *const _)) + } + #[inline(always)] + unsafe fn unsafe_read_be(input: &[u8]) -> Self { + Self::unsafe_read_le(input).bswap() + } + #[inline(always)] + fn write_le(self, out: &mut [u8]) { + unsafe { + assert_eq!(out.len(), 32); + _mm256_storeu_si256(out.as_mut_ptr() as *mut _, self.x) + } + } + #[inline(always)] + fn write_be(self, out: &mut [u8]) { + self.bswap().write_le(out) + } + } impl MultiLane<[u32x4_sse2; 2]> for u32x4x2_avx2 { #[inline(always)] fn to_lanes(self) -> [u32x4_sse2; 2] { @@ -1625,10 +1647,8 @@ pub mod avx2 { #[inline(always)] fn insert(self, w: u32x4_sse2, i: u32) -> Self { Self::new(match i { - 0 => [self.0[0].insert(w, 0), self.0[1]], - 1 => [self.0[0].insert(w, 1), self.0[1]], - 2 => [self.0[0], self.0[1].insert(w, 0)], - 3 => [self.0[0], self.0[1].insert(w, 1)], + 0 | 1 => [self.0[0].insert(w, i), self.0[1]], + 2 | 3 => [self.0[0], self.0[1].insert(w, i - 2)], _ => panic!(), }) } From 6c540f95285047c9ba86fb6bdfcd8ae3cb32a91a Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 10:48:38 -0700 Subject: [PATCH 62/84] ppv-lite86: release 0.2.15 --- utils-simd/ppv-lite86/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 4903a5e5..17ee4b99 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.14" +version = "0.2.15" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" From cadd431b300d802a42ac440ce69d77b8721cadf7 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 09:49:49 -0700 Subject: [PATCH 63/84] c2-chacha: fix for big-endian --- stream-ciphers/chacha/src/guts.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 110ad927..8ace65ef 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -2,7 +2,7 @@ pub use cipher::generic_array; pub use ppv_lite86::Machine; -use ppv_lite86::{vec128_storage, ArithOps, BitOps32, LaneWords4, MultiLane, StoreBytes, Vec4, Vec4Ext, Vector}; +use ppv_lite86::{vec128_storage, ArithOps, BitOps32, LaneWords4, MultiLane, StoreBytes, Vec4, Vec4Ext}; pub(crate) const BLOCK: usize = 64; pub(crate) const BLOCK64: u64 = BLOCK as u64; @@ -233,12 +233,6 @@ fn d0123(m: Mach, d: vec128_storage) -> Mach::u32x4x4 { m.unpack((Mach::u64x2x4::from_lanes([d0, d0, d0, d0]) + incr).into()) } -fn to_bytes(xs: [u32; 16]) -> [u8; 64] { - unsafe { - core::mem::transmute(xs) - } -} - #[allow(clippy::many_single_char_names)] #[inline(always)] fn refill_wide_impl( @@ -264,10 +258,10 @@ fn refill_wide_impl( let sc = Mach::u32x4x4::from_lanes([sc, sc, sc, sc]); let sd = d0123(m, state.d); let results = Mach::u32x4x4::transpose4(x.a + kk, x.b + sb, x.c + sc, x.d + sd); - out[0..64].copy_from_slice(&to_bytes(results.0.to_scalars())); - out[64..128].copy_from_slice(&to_bytes(results.1.to_scalars())); - out[128..192].copy_from_slice(&to_bytes(results.2.to_scalars())); - out[192..256].copy_from_slice(&to_bytes(results.3.to_scalars())); + results.0.write_le(&mut out[0..64]); + results.1.write_le(&mut out[64..128]); + results.2.write_le(&mut out[128..192]); + results.3.write_le(&mut out[192..256]); state.d = add_pos(m, sd.to_lanes()[0], 4).into(); } From dce9577eab0cd8d6b0de9d966b35171684d14ab2 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 10:56:54 -0700 Subject: [PATCH 64/84] c2-chacha: release 0.3.3 --- stream-ciphers/chacha/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index c907b061..f458be08 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "c2-chacha" -version = "0.3.2" +version = "0.3.3" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" edition = "2018" From e9c9cebaa1defc2d19ae093317afc018b705d833 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 11:08:15 -0700 Subject: [PATCH 65/84] cargo fmt --- stream-ciphers/chacha/src/guts.rs | 12 ++++-- stream-ciphers/chacha/src/lib.rs | 4 +- stream-ciphers/chacha/src/rustcrypto_impl.rs | 4 +- utils-simd/ppv-lite86/src/generic.rs | 8 ++-- utils-simd/ppv-lite86/src/soft.rs | 7 +++- utils-simd/ppv-lite86/src/types.rs | 11 ++--- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 44 +++++++------------- 7 files changed, 41 insertions(+), 49 deletions(-) diff --git a/stream-ciphers/chacha/src/guts.rs b/stream-ciphers/chacha/src/guts.rs index 8ace65ef..cf0dd000 100644 --- a/stream-ciphers/chacha/src/guts.rs +++ b/stream-ciphers/chacha/src/guts.rs @@ -2,7 +2,9 @@ pub use cipher::generic_array; pub use ppv_lite86::Machine; -use ppv_lite86::{vec128_storage, ArithOps, BitOps32, LaneWords4, MultiLane, StoreBytes, Vec4, Vec4Ext}; +use ppv_lite86::{ + vec128_storage, ArithOps, BitOps32, LaneWords4, MultiLane, StoreBytes, Vec4, Vec4Ext, +}; pub(crate) const BLOCK: usize = 64; pub(crate) const BLOCK64: u64 = BLOCK as u64; @@ -229,14 +231,18 @@ fn add_pos(m: Mach, d: Mach::u32x4, i: u64) -> Mach::u32x4 { #[cfg(target_endian = "little")] fn d0123(m: Mach, d: vec128_storage) -> Mach::u32x4x4 { let d0: Mach::u64x2 = m.unpack(d); - let incr = Mach::u64x2x4::from_lanes([m.vec([0, 0]), m.vec([1, 0]), m.vec([2, 0]), m.vec([3, 0])]); + let incr = + Mach::u64x2x4::from_lanes([m.vec([0, 0]), m.vec([1, 0]), m.vec([2, 0]), m.vec([3, 0])]); m.unpack((Mach::u64x2x4::from_lanes([d0, d0, d0, d0]) + incr).into()) } #[allow(clippy::many_single_char_names)] #[inline(always)] fn refill_wide_impl( - m: Mach, state: &mut ChaCha, drounds: u32, out: &mut [u8; BUFSZ], + m: Mach, + state: &mut ChaCha, + drounds: u32, + out: &mut [u8; BUFSZ], ) { let k = m.vec([0x6170_7865, 0x3320_646e, 0x7962_2d32, 0x6b20_6574]); let b = m.unpack(state.b); diff --git a/stream-ciphers/chacha/src/lib.rs b/stream-ciphers/chacha/src/lib.rs index 6131682f..68a22bcd 100644 --- a/stream-ciphers/chacha/src/lib.rs +++ b/stream-ciphers/chacha/src/lib.rs @@ -45,4 +45,6 @@ pub mod guts; #[cfg(feature = "rustcrypto_api")] mod rustcrypto_impl; #[cfg(feature = "rustcrypto_api")] -pub use self::rustcrypto_impl::{stream_cipher, Ietf, ChaCha8, ChaCha12, ChaCha20, XChaCha8, XChaCha12, XChaCha20}; +pub use self::rustcrypto_impl::{ + stream_cipher, ChaCha12, ChaCha20, ChaCha8, Ietf, XChaCha12, XChaCha20, XChaCha8, +}; diff --git a/stream-ciphers/chacha/src/rustcrypto_impl.rs b/stream-ciphers/chacha/src/rustcrypto_impl.rs index 130bb5f9..3e2faaad 100644 --- a/stream-ciphers/chacha/src/rustcrypto_impl.rs +++ b/stream-ciphers/chacha/src/rustcrypto_impl.rs @@ -1,12 +1,12 @@ use crate::guts::generic_array::typenum::{Unsigned, U10, U12, U24, U32, U4, U6, U8}; use crate::guts::generic_array::{ArrayLength, GenericArray}; use crate::guts::{ChaCha, Machine, BLOCK, BLOCK64, BUFSZ}; -use core::cmp; -use core::convert::TryInto; pub use cipher::stream as stream_cipher; use cipher::stream::{ LoopError, NewStreamCipher, OverflowError, SeekNum, SyncStreamCipher, SyncStreamCipherSeek, }; +use core::cmp; +use core::convert::TryInto; const BIG_LEN: u64 = 0; const SMALL_LEN: u64 = 1 << 32; diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 473dab42..c8fa3a57 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -623,10 +623,10 @@ impl Vector<[u32; 16]> for u32x4x4_generic { let c = c.0; let d = d.0; [ - a[0], a[1], a[2], a[3], - b[0], b[1], b[2], b[3], - c[0], c[1], c[2], c[3], - d[0], d[1], d[2], d[3], + a[0], a[1], a[2], a[3], // + b[0], b[1], b[2], b[3], // + c[0], c[1], c[2], c[3], // + d[0], d[1], d[2], d[3], // ] } } diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index 4a88fccf..0ae390c4 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -336,12 +336,15 @@ impl Vec4 for x4 { } impl Vec4Ext for x4 { #[inline(always)] - fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) where Self: Sized { + fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) + where + Self: Sized, + { ( x4([a.0[0], b.0[0], c.0[0], d.0[0]]), x4([a.0[1], b.0[1], c.0[1], d.0[1]]), x4([a.0[2], b.0[2], c.0[2], d.0[2]]), - x4([a.0[3], b.0[3], c.0[3], d.0[3]]) + x4([a.0[3], b.0[3], c.0[3], d.0[3]]), ) } } diff --git a/utils-simd/ppv-lite86/src/types.rs b/utils-simd/ppv-lite86/src/types.rs index 8a2acfcf..f9f3bf1c 100644 --- a/utils-simd/ppv-lite86/src/types.rs +++ b/utils-simd/ppv-lite86/src/types.rs @@ -75,7 +75,9 @@ pub trait Vec4 { /// NOTE: functions in this trait may be moved to Vec4 in any patch release. To avoid breakage, /// import Vec4Ext only together with Vec4, and don't qualify its methods. pub trait Vec4Ext { - fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) where Self: Sized; + fn transpose4(a: Self, b: Self, c: Self, d: Self) -> (Self, Self, Self, Self) + where + Self: Sized; } pub trait Vector { fn to_scalars(self) -> T; @@ -121,12 +123,7 @@ pub trait u32x4: { } pub trait u64x2: - BitOps64 - + Store - + ArithOps - + Vec2 - + MultiLane<[u64; 2]> - + Into + BitOps64 + Store + ArithOps + Vec2 + MultiLane<[u64; 2]> + Into { } pub trait u128x1: diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 85307901..515cabbb 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -883,9 +883,7 @@ pub type u128x4_sse2 = x4>; impl Vector<[u32; 16]> for u32x4x4_sse2 { #[inline(always)] fn to_scalars(self) -> [u32; 16] { - unsafe { - core::mem::transmute(self) - } + unsafe { core::mem::transmute(self) } } } @@ -1439,9 +1437,7 @@ pub mod avx2 { } #[inline(always)] fn from_lanes(x: [u32x4_sse2; 2]) -> Self { - Self::new(unsafe { - _mm256_setr_m128i(x[0].x, x[1].x) - }) + Self::new(unsafe { _mm256_setr_m128i(x[0].x, x[1].x) }) } } impl Vec2> for u32x4x2_avx2 { @@ -1517,9 +1513,7 @@ pub mod avx2 { impl From> for vec256_storage { #[inline(always)] fn from(x: u32x4x2_avx2) -> Self { - Self { - avx: x.x, - } + Self { avx: x.x } } } @@ -1547,9 +1541,7 @@ pub mod avx2 { type Output = Self; #[inline(always)] fn $op_fn(self, rhs: Self) -> Self::Output { - Self::new(unsafe { - $impl_fn(self.x, rhs.x) - }) + Self::new(unsafe { $impl_fn(self.x, rhs.x) }) } } }; @@ -1581,30 +1573,22 @@ pub mod avx2 { { #[inline(always)] fn from(x: x2, G0>) -> Self { - Self::new(unsafe { - _mm256_setr_m128i(x.0[0].x, x.0[1].x) - }) + Self::new(unsafe { _mm256_setr_m128i(x.0[0].x, x.0[1].x) }) } } impl LaneWords4 for u32x4x2_avx2 { #[inline(always)] fn shuffle_lane_words1230(self) -> Self { - Self::new(unsafe { - _mm256_shuffle_epi32(self.x, 0b1001_0011) - }) + Self::new(unsafe { _mm256_shuffle_epi32(self.x, 0b1001_0011) }) } #[inline(always)] fn shuffle_lane_words2301(self) -> Self { - Self::new(unsafe { - _mm256_shuffle_epi32(self.x, 0b0100_1110) - }) + Self::new(unsafe { _mm256_shuffle_epi32(self.x, 0b0100_1110) }) } #[inline(always)] fn shuffle_lane_words3012(self) -> Self { - Self::new(unsafe { - _mm256_shuffle_epi32(self.x, 0b0011_1001) - }) + Self::new(unsafe { _mm256_shuffle_epi32(self.x, 0b0011_1001) }) } } @@ -1616,7 +1600,10 @@ pub mod avx2 { impl Store for u32x4x4_avx2 { #[inline(always)] unsafe fn unpack(p: vec512_storage) -> Self { - Self::new([u32x4x2_avx2::unpack(p.avx[0]), u32x4x2_avx2::unpack(p.avx[1])]) + Self::new([ + u32x4x2_avx2::unpack(p.avx[0]), + u32x4x2_avx2::unpack(p.avx[1]), + ]) } } impl MultiLane<[u32x4_sse2; 4]> for u32x4x4_avx2 { @@ -1688,9 +1675,7 @@ pub mod avx2 { impl Vector<[u32; 16]> for u32x4x4_avx2 { #[inline(always)] fn to_scalars(self) -> [u32; 16] { - unsafe { - core::mem::transmute(self) - } + unsafe { core::mem::transmute(self) } } } impl From> for vec512_storage { @@ -1704,8 +1689,7 @@ pub mod avx2 { } } } - impl From>> for u32x4x4_avx2 - { + impl From>> for u32x4x4_avx2 { #[inline(always)] fn from(x: x4>) -> Self { Self::new(unsafe { From f8d79d80007b13743e5d1ca661537e498403cba7 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 11:39:10 -0700 Subject: [PATCH 66/84] GitHub Action for rustfmt check --- .github/workflows/check-rustfmt.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/workflows/check-rustfmt.yaml diff --git a/.github/workflows/check-rustfmt.yaml b/.github/workflows/check-rustfmt.yaml new file mode 100644 index 00000000..705c3fba --- /dev/null +++ b/.github/workflows/check-rustfmt.yaml @@ -0,0 +1,9 @@ +name: check-rustfmt +on: pull_request +jobs: + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: cargo-fmt + run: cargo fmt -- --check From a2e9baf66a827cfe0c1998d75d5ab6c992c09428 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 14:06:16 -0700 Subject: [PATCH 67/84] clippy --- hashes/groestl/src/lib.rs | 2 +- utils-simd/ppv-lite86/CHANGELOG.md | 9 +++++++++ utils-simd/ppv-lite86/src/x86_64/mod.rs | 24 ++++++++++++------------ utils-simd/ppv-lite86/src/x86_64/sse2.rs | 24 ++++++++++++------------ 4 files changed, 34 insertions(+), 25 deletions(-) create mode 100644 utils-simd/ppv-lite86/CHANGELOG.md diff --git a/hashes/groestl/src/lib.rs b/hashes/groestl/src/lib.rs index 0b893ba6..2dad9db2 100644 --- a/hashes/groestl/src/lib.rs +++ b/hashes/groestl/src/lib.rs @@ -86,7 +86,7 @@ macro_rules! impl_digest { let compressor = $compressor::new(iv.0); Self { buffer: BlockBuffer::default(), - compressor: compressor, + compressor, block_counter: 0, } } diff --git a/utils-simd/ppv-lite86/CHANGELOG.md b/utils-simd/ppv-lite86/CHANGELOG.md new file mode 100644 index 00000000..7f539a36 --- /dev/null +++ b/utils-simd/ppv-lite86/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). + +## [Unreleased] +### Added +- impl `From` (rather than just `Into`) for conversions between `*_storage` types and arrays. diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index 0538e3f7..937732da 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -119,16 +119,16 @@ impl Store for vec128_storage { p } } -impl<'a> Into<&'a [u32; 4]> for &'a vec128_storage { +impl<'a> From<&'a vec128_storage> for &'a [u32; 4] { #[inline(always)] - fn into(self) -> &'a [u32; 4] { - unsafe { &self.u32x4 } + fn from(x: &'a vec128_storage) -> Self { + unsafe { &x.u32x4 } } } -impl Into for [u32; 4] { +impl From<[u32; 4]> for vec128_storage { #[inline(always)] - fn into(self) -> vec128_storage { - vec128_storage { u32x4: self } + fn from(u32x4: [u32; 4]) -> Self { + vec128_storage { u32x4 } } } impl Default for vec128_storage { @@ -154,10 +154,10 @@ pub union vec256_storage { sse2: [vec128_storage; 2], avx: __m256i, } -impl Into for [u64; 4] { +impl From<[u64; 4]> for vec256_storage { #[inline(always)] - fn into(self) -> vec256_storage { - vec256_storage { u64x4: self } + fn from(u64x4: [u64; 4]) -> Self { + vec256_storage { u64x4 } } } impl Default for vec256_storage { @@ -221,10 +221,10 @@ impl PartialEq for vec512_storage { macro_rules! impl_into { ($storage:ident, $array:ty, $name:ident) => { - impl Into<$array> for $storage { + impl From<$storage> for $array { #[inline(always)] - fn into(self) -> $array { - unsafe { self.$name } + fn from(vec: $storage) -> Self { + unsafe { vec.$name } } } }; diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 515cabbb..97197a43 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -189,21 +189,21 @@ impl RotateEachWord32 for u32x4_sse2 { rotr_32!(rotate_each_word_right7, 7); rotr_32_s3!( rotate_each_word_right8, - 0x0c0f0e0d_080b0a09, - 0x04070605_00030201 + 0x0c0f_0e0d_080b_0a09, + 0x0407_0605_0003_0201 ); rotr_32!(rotate_each_word_right11, 11); rotr_32!(rotate_each_word_right12, 12); rotr_32_s3!( rotate_each_word_right16, - 0x0d0c0f0e_09080b0a, - 0x05040706_01000302 + 0x0d0c_0f0e_0908_0b0a, + 0x0504_0706_0100_0302 ); rotr_32!(rotate_each_word_right20, 20); rotr_32_s3!( rotate_each_word_right24, - 0x0e0d0c0f_0a09080b, - 0x06050407_02010003 + 0x0e0d_0c0f_0a09_080b, + 0x0605_0407_0201_0003 ); rotr_32!(rotate_each_word_right25, 25); } @@ -1491,21 +1491,21 @@ pub mod avx2 { rotr_32!(rotate_each_word_right7, 7); shuf_lane_bytes!( rotate_each_word_right8, - 0x0c0f0e0d_080b0a09, - 0x04070605_00030201 + 0x0c0f_0e0d_080b_0a09, + 0x0407_0605_0003_0201 ); rotr_32!(rotate_each_word_right11, 11); rotr_32!(rotate_each_word_right12, 12); shuf_lane_bytes!( rotate_each_word_right16, - 0x0d0c0f0e_09080b0a, - 0x05040706_01000302 + 0x0d0c_0f0e_0908_0b0a, + 0x0504_0706_0100_0302 ); rotr_32!(rotate_each_word_right20, 20); shuf_lane_bytes!( rotate_each_word_right24, - 0x0e0d0c0f_0a09080b, - 0x06050407_02010003 + 0x0e0d_0c0f_0a09_080b, + 0x0605_0407_0201_0003 ); rotr_32!(rotate_each_word_right25, 25); } From 4cf46f5e1bbbc4c56001f7c62b223f0547271d4b Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 14:06:29 -0700 Subject: [PATCH 68/84] Github Action for clippy check --- .github/workflows/check-clippy.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .github/workflows/check-clippy.yaml diff --git a/.github/workflows/check-clippy.yaml b/.github/workflows/check-clippy.yaml new file mode 100644 index 00000000..a8a16e15 --- /dev/null +++ b/.github/workflows/check-clippy.yaml @@ -0,0 +1,9 @@ +name: check-clippy +on: pull_request +jobs: + clippy: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: cargo-clippy + run: cargo clippy From 67225b9e5a111d2a996765f0b7d6eb0a43d6023b Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 13:31:59 -0700 Subject: [PATCH 69/84] c2-chacha: cipher 0.2 -> 0.3 (breaking) --- stream-ciphers/chacha/CHANGELOG.md | 9 +++++++++ stream-ciphers/chacha/Cargo.toml | 2 +- stream-ciphers/chacha/src/lib.rs | 2 +- stream-ciphers/chacha/src/rustcrypto_impl.rs | 14 ++++++-------- 4 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 stream-ciphers/chacha/CHANGELOG.md diff --git a/stream-ciphers/chacha/CHANGELOG.md b/stream-ciphers/chacha/CHANGELOG.md new file mode 100644 index 00000000..44b58459 --- /dev/null +++ b/stream-ciphers/chacha/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). + +## [Unreleased] +### Changed +- Update `cipher` dependency: 0.2 -> 0.3. diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index f458be08..a474100d 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/c2-chacha" [dependencies] ppv-lite86 = { package = "ppv-lite86", version = "0.2.14", default-features = false } -cipher = { version = "0.2", optional = true } +cipher = { version = "0.3", optional = true } [dev-dependencies] hex-literal = "0.2" diff --git a/stream-ciphers/chacha/src/lib.rs b/stream-ciphers/chacha/src/lib.rs index 68a22bcd..f064a271 100644 --- a/stream-ciphers/chacha/src/lib.rs +++ b/stream-ciphers/chacha/src/lib.rs @@ -46,5 +46,5 @@ pub mod guts; mod rustcrypto_impl; #[cfg(feature = "rustcrypto_api")] pub use self::rustcrypto_impl::{ - stream_cipher, ChaCha12, ChaCha20, ChaCha8, Ietf, XChaCha12, XChaCha20, XChaCha8, + ChaCha12, ChaCha20, ChaCha8, Ietf, XChaCha12, XChaCha20, XChaCha8, }; diff --git a/stream-ciphers/chacha/src/rustcrypto_impl.rs b/stream-ciphers/chacha/src/rustcrypto_impl.rs index 3e2faaad..2e4e2188 100644 --- a/stream-ciphers/chacha/src/rustcrypto_impl.rs +++ b/stream-ciphers/chacha/src/rustcrypto_impl.rs @@ -1,10 +1,8 @@ use crate::guts::generic_array::typenum::{Unsigned, U10, U12, U24, U32, U4, U6, U8}; use crate::guts::generic_array::{ArrayLength, GenericArray}; use crate::guts::{ChaCha, Machine, BLOCK, BLOCK64, BUFSZ}; -pub use cipher::stream as stream_cipher; -use cipher::stream::{ - LoopError, NewStreamCipher, OverflowError, SeekNum, SyncStreamCipher, SyncStreamCipherSeek, -}; +use cipher::errors::{LoopError, OverflowError}; +use cipher::{NewCipher, SeekNum, StreamCipher, StreamCipherSeek}; use core::cmp; use core::convert::TryInto; @@ -178,7 +176,7 @@ impl ChaChaAny { } } -impl NewStreamCipher for ChaChaAny +impl NewCipher for ChaChaAny where NonceSize: Unsigned + ArrayLength + Default, Rounds: Default, @@ -194,7 +192,7 @@ where } } -impl NewStreamCipher for ChaChaAny { +impl NewCipher for ChaChaAny { type KeySize = U32; type NonceSize = U24; #[inline] @@ -206,7 +204,7 @@ impl NewStreamCipher for ChaChaAny { } } -impl SyncStreamCipherSeek for ChaChaAny { +impl StreamCipherSeek for ChaChaAny { #[inline] fn try_current_pos(&self) -> Result { unimplemented!() @@ -219,7 +217,7 @@ impl SyncStreamCipherSeek for ChaChaAny SyncStreamCipher for ChaChaAny { +impl StreamCipher for ChaChaAny { #[inline] fn try_apply_keystream(&mut self, data: &mut [u8]) -> Result<(), LoopError> { Self::try_apply_keystream(self, data).map_err(|_| LoopError) From a60ca142a17ea5e9b6a425a172c5f665f1cc3dba Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 14:18:32 -0700 Subject: [PATCH 70/84] threefish: cipher 0.2 -> 0.3 (breaking) --- block-ciphers/threefish/CHANGELOG.md | 9 +++++++++ block-ciphers/threefish/Cargo.toml | 3 ++- block-ciphers/threefish/src/lib.rs | 14 ++++++++------ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 block-ciphers/threefish/CHANGELOG.md diff --git a/block-ciphers/threefish/CHANGELOG.md b/block-ciphers/threefish/CHANGELOG.md new file mode 100644 index 00000000..44b58459 --- /dev/null +++ b/block-ciphers/threefish/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). + +## [Unreleased] +### Changed +- Update `cipher` dependency: 0.2 -> 0.3. diff --git a/block-ciphers/threefish/Cargo.toml b/block-ciphers/threefish/Cargo.toml index 69f2b687..fb30fb46 100644 --- a/block-ciphers/threefish/Cargo.toml +++ b/block-ciphers/threefish/Cargo.toml @@ -7,9 +7,10 @@ description = "Threefish block cipher" documentation = "https://docs.rs/threefish" repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "threefish", "gost", "block-cipher"] +edition = "2018" [dependencies] -cipher = "0.2" +cipher = "0.3" [dev-dependencies] hex-literal = "0.2" diff --git a/block-ciphers/threefish/src/lib.rs b/block-ciphers/threefish/src/lib.rs index ba511388..19d911ed 100644 --- a/block-ciphers/threefish/src/lib.rs +++ b/block-ciphers/threefish/src/lib.rs @@ -1,9 +1,6 @@ #![no_std] #![allow(non_upper_case_globals)] -extern crate cipher; -#[cfg(test)] -#[macro_use] -extern crate hex_literal; + use core::convert::TryInto; use core::ops::BitXor; @@ -12,7 +9,7 @@ use consts::{C240, P_1024, P_256, P_512, R_1024, R_256, R_512}; use cipher::generic_array::typenum::{U1, U128, U32, U64}; use cipher::generic_array::GenericArray; -pub use cipher::{BlockCipher, NewBlockCipher}; +use cipher::{BlockCipher, BlockDecrypt, BlockEncrypt, NewBlockCipher}; fn mix(r: u32, x: (u64, u64)) -> (u64, u64) { let y0 = x.0.wrapping_add(x.1); @@ -129,7 +126,9 @@ macro_rules! impl_threefish( impl BlockCipher for $name { type BlockSize = $block_size; type ParBlocks = U1; + } + impl BlockEncrypt for $name { fn encrypt_block(&self, block: &mut GenericArray) { let mut v = [0u64; $n_w]; @@ -163,7 +162,9 @@ macro_rules! impl_threefish( write_u64v_le(block, &v[..]); } + } + impl BlockDecrypt for $name { fn decrypt_block(&self, block: &mut GenericArray) { let mut v = [0u64; $n_w]; @@ -210,7 +211,8 @@ mod test { use super::{Threefish1024, Threefish256, Threefish512}; use cipher::generic_array::GenericArray; - use cipher::{BlockCipher, NewBlockCipher}; + use cipher::{BlockDecrypt, BlockEncrypt, NewBlockCipher}; + use hex_literal::hex; #[test] fn test_256() { From 209a9fda9171d0fc8d7da7ab77229cbea4739619 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sun, 24 Oct 2021 14:31:59 -0700 Subject: [PATCH 71/84] skein: cipher 0.2 -> 0.3 (breaking) --- hashes/skein/CHANGELOG.md | 9 +++++++++ hashes/skein/Cargo.toml | 2 ++ hashes/skein/src/lib.rs | 3 ++- 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 hashes/skein/CHANGELOG.md diff --git a/hashes/skein/CHANGELOG.md b/hashes/skein/CHANGELOG.md new file mode 100644 index 00000000..44b58459 --- /dev/null +++ b/hashes/skein/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). + +## [Unreleased] +### Changed +- Update `cipher` dependency: 0.2 -> 0.3. diff --git a/hashes/skein/Cargo.toml b/hashes/skein/Cargo.toml index 0864fd6e..995cca96 100644 --- a/hashes/skein/Cargo.toml +++ b/hashes/skein/Cargo.toml @@ -7,11 +7,13 @@ description = "Skein hash functions" repository = "https://github.com/cryptocorrosion/hashes" keywords = ["crypto", "skein", "hash", "digest"] categories = ["cryptography", "no-std"] +edition = "2018" [dependencies] block-buffer = { version = "0.9", features = ["block-padding"] } digest = "0.9" threefish-cipher = "0.4" +cipher = "0.3" [dev-dependencies] digest = { version = "0.9", features = ["dev"] } diff --git a/hashes/skein/src/lib.rs b/hashes/skein/src/lib.rs index f7685858..b6cf5c38 100644 --- a/hashes/skein/src/lib.rs +++ b/hashes/skein/src/lib.rs @@ -11,9 +11,10 @@ pub use digest::Digest; use block_buffer::block_padding::ZeroPadding; use block_buffer::BlockBuffer; +use cipher::{BlockCipher, BlockEncrypt}; use digest::generic_array::typenum::{NonZero, PartialDiv, Unsigned, U128, U32, U64, U8}; use digest::generic_array::ArrayLength; -use threefish_cipher::{BlockCipher, Threefish1024, Threefish256, Threefish512}; +use threefish_cipher::{Threefish1024, Threefish256, Threefish512}; /// N word buffer. #[derive(Copy, Clone)] From 8e7c84e0027b011aa10da70386ff5acf88fd684e Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 30 Dec 2021 10:15:00 -0800 Subject: [PATCH 72/84] ppv-lite86: add interface needed for BLAKE Fixes #67 --- utils-simd/ppv-lite86/src/generic.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index c8fa3a57..add6c485 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -69,6 +69,14 @@ impl From for [u64; 4] { [a, b, c, d] } } +impl From<[u64; 4]> for vec256_storage { + #[inline(always)] + fn from([a, b, c, d]: [u64; 4]) -> Self { + Self { + v128: [[a, b].into(), [c, d].into()], + } + } +} #[derive(Clone, Copy, PartialEq, Eq, Default)] pub struct vec512_storage { v128: [vec128_storage; 4], From 4b1e1d655d05c9da29aa833ce705feedb3da760b Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 30 Dec 2021 10:15:05 -0800 Subject: [PATCH 73/84] release ppv-lite86 0.2.16, BLAKE 0.4.1 --- hashes/blake/Cargo.toml | 4 ++-- utils-simd/ppv-lite86/CHANGELOG.md | 3 ++- utils-simd/ppv-lite86/Cargo.toml | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hashes/blake/Cargo.toml b/hashes/blake/Cargo.toml index d57552fc..bd41c48c 100644 --- a/hashes/blake/Cargo.toml +++ b/hashes/blake/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "blake-hash" -version = "0.4.0" +version = "0.4.1" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "BLAKE hash functions" @@ -11,7 +11,7 @@ categories = ["cryptography", "no-std"] [dependencies] block-buffer = "0.9" digest = "0.9" -simd = { package = "ppv-lite86", version = "0.2.6", optional = true } +simd = { package = "ppv-lite86", version = "0.2.16", optional = true } [features] default = ["simd", "std"] diff --git a/utils-simd/ppv-lite86/CHANGELOG.md b/utils-simd/ppv-lite86/CHANGELOG.md index 7f539a36..6e34be39 100644 --- a/utils-simd/ppv-lite86/CHANGELOG.md +++ b/utils-simd/ppv-lite86/CHANGELOG.md @@ -4,6 +4,7 @@ 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). -## [Unreleased] +## [0.2.16] ### Added +- add [u64; 4] conversion for generic vec256, to support BLAKE on non-x86. - impl `From` (rather than just `Into`) for conversions between `*_storage` types and arrays. diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 17ee4b99..b457f540 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.15" +version = "0.2.16" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" From 33ec0f37114a8f2f65874dcee31eb579ae640e20 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Thu, 30 Dec 2021 10:23:50 -0800 Subject: [PATCH 74/84] BLAKE: init changelog --- hashes/blake/CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 hashes/blake/CHANGELOG.md diff --git a/hashes/blake/CHANGELOG.md b/hashes/blake/CHANGELOG.md new file mode 100644 index 00000000..adb13026 --- /dev/null +++ b/hashes/blake/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.4.1] +### Changed +- Update `ppv-lite86` dependency to fix support for non-x86 platforms. From 9f59773f6e8f337ac4bb6625ab8312310427943f Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Fri, 4 Nov 2022 23:03:05 +0000 Subject: [PATCH 75/84] use generic implementation on x86-without-simd --- utils-simd/ppv-lite86/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/utils-simd/ppv-lite86/src/lib.rs b/utils-simd/ppv-lite86/src/lib.rs index ea89c512..638552fc 100644 --- a/utils-simd/ppv-lite86/src/lib.rs +++ b/utils-simd/ppv-lite86/src/lib.rs @@ -9,14 +9,14 @@ mod soft; mod types; pub use self::types::*; -#[cfg(all(target_arch = "x86_64", not(feature = "no_simd"), not(miri)))] +#[cfg(all(target_arch = "x86_64", target_feature = "sse2", not(feature = "no_simd"), not(miri)))] pub mod x86_64; -#[cfg(all(target_arch = "x86_64", not(feature = "no_simd"), not(miri)))] +#[cfg(all(target_arch = "x86_64", target_feature = "sse2", not(feature = "no_simd"), not(miri)))] use self::x86_64 as arch; -#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64")))] +#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64"), all(target_arch = "x86_64", not(target_feature = "sse2"))))] pub mod generic; -#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64")))] +#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64"), all(target_arch = "x86_64", not(target_feature = "sse2"))))] use self::generic as arch; pub use self::arch::{vec128_storage, vec256_storage, vec512_storage}; From 325fd94cf15c0abfcc5b4631993b48abcf0f1cf1 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Fri, 4 Nov 2022 23:14:22 +0000 Subject: [PATCH 76/84] version bump --- utils-simd/ppv-lite86/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index b457f540..a4497f83 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.16" +version = "0.2.17" authors = ["The CryptoCorrosion Contributors"] edition = "2018" license = "MIT/Apache-2.0" @@ -18,4 +18,4 @@ travis-ci = { repository = "cryptocorrosion/cryptocorrosion" } default = ["std"] std = [] simd = [] # deprecated -no_simd = [] # for weird platforms like "x86_64 without SSE2" +no_simd = [] From 216afcf1e1ffae5b8b7c76963466f5bb05f93c6c Mon Sep 17 00:00:00 2001 From: Joshua Liebow-Feeser Date: Thu, 24 Aug 2023 23:33:27 -0700 Subject: [PATCH 77/84] Fix some unsoundness and remove some unsafe Some code relied on the layout of types with no `#[repr(...)]` attribute, which is unsound since the layout of these types is not guaranteed by rustc. This change adds the appropriate `repr` attributes and replaces unsafe code with safe code where possible. --- hashes/groestl/Cargo.toml | 1 + hashes/groestl/src/compressor.rs | 4 ++- hashes/groestl/src/lib.rs | 9 ++---- hashes/jh/Cargo.toml | 1 + hashes/jh/src/compressor.rs | 13 ++++---- hashes/skein/src/lib.rs | 38 +++++++++++++++++++++--- utils-simd/ppv-lite86/Cargo.toml | 1 + utils-simd/ppv-lite86/src/generic.rs | 36 ++++++++++------------ utils-simd/ppv-lite86/src/soft.rs | 7 +++-- utils-simd/ppv-lite86/src/x86_64/mod.rs | 4 ++- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 28 +++++++++-------- 11 files changed, 91 insertions(+), 51 deletions(-) diff --git a/hashes/groestl/Cargo.toml b/hashes/groestl/Cargo.toml index 72f07207..4d637dd0 100644 --- a/hashes/groestl/Cargo.toml +++ b/hashes/groestl/Cargo.toml @@ -14,6 +14,7 @@ edition = "2018" block-buffer = "0.9" digest = "0.9" lazy_static = { version = "1.2", optional = true } +zerocopy = { version = "0.6.3", features = ["simd"] } [dev-dependencies] digest = { version = "0.9", features = ["dev"] } diff --git a/hashes/groestl/src/compressor.rs b/hashes/groestl/src/compressor.rs index 72b12d5a..2727243d 100644 --- a/hashes/groestl/src/compressor.rs +++ b/hashes/groestl/src/compressor.rs @@ -2,6 +2,7 @@ use block_buffer::generic_array::typenum::{U128, U64}; use block_buffer::generic_array::GenericArray; use core::arch::x86_64::*; use core::ops::BitXor; +use zerocopy::{AsBytes, FromBytes}; trait Map2 { type Output; @@ -11,7 +12,8 @@ trait Map2 { Self: Sized; } -#[derive(Copy, Clone)] +#[derive(Copy, Clone, FromBytes, AsBytes)] +#[repr(C)] pub struct X4(__m128i, __m128i, __m128i, __m128i); #[derive(Copy, Clone)] diff --git a/hashes/groestl/src/lib.rs b/hashes/groestl/src/lib.rs index 2dad9db2..535ccc2c 100644 --- a/hashes/groestl/src/lib.rs +++ b/hashes/groestl/src/lib.rs @@ -18,6 +18,7 @@ use block_buffer::BlockBuffer; use core::fmt::{Debug, Formatter, Result}; use digest::generic_array::GenericArray as DGenericArray; pub use digest::Digest; +use zerocopy::transmute; mod compressor; use crate::compressor::{init1024, init512, of1024, of512, tf1024, tf512}; @@ -26,17 +27,13 @@ use crate::compressor::{init1024, init512, of1024, of512, tf1024, tf512}; struct Align16(T); type Block512 = [u64; 512 / 64]; -union CvBytes512 { - block: Block512, - cv: compressor::X4, -} #[derive(Clone)] struct Compressor512 { cv: compressor::X4, } impl Compressor512 { fn new(block: Block512) -> Self { - let cv = init512(unsafe { CvBytes512 { block }.cv }); + let cv = init512(transmute!(block)); Compressor512 { cv } } fn input(&mut self, data: &BBGenericArray) { @@ -44,7 +41,7 @@ impl Compressor512 { } fn finalize_dirty(&mut self) -> Block512 { of512(&mut self.cv); - unsafe { CvBytes512 { cv: self.cv }.block } + transmute!(self.cv) } } diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index 11bd91e6..da06b4df 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -15,6 +15,7 @@ block-buffer = "0.9" digest = "0.9" hex-literal = "0.2" simd = { package = "ppv-lite86", version = "0.2.6" } +zerocopy = "0.6.3" [dev-dependencies] digest = { version = "0.9", features = ["dev"] } diff --git a/hashes/jh/src/compressor.rs b/hashes/jh/src/compressor.rs index 57b02cd7..eaf885d7 100644 --- a/hashes/jh/src/compressor.rs +++ b/hashes/jh/src/compressor.rs @@ -4,6 +4,7 @@ use core::ptr; use digest::generic_array::typenum::U64; use digest::generic_array::GenericArray; use simd::{vec128_storage, AndNot, Machine, Swap64, VZip, Vec2}; +use zerocopy::transmute; const E8_BITSLICE_ROUNDCONSTANT: [[u8; 32]; 42] = [ hex!("72d5dea2df15f8677b84150ab723155781abd6904d5a87f64e9f4fc5c3d12b40"), @@ -199,21 +200,23 @@ dispatch!(mach, M, { }); #[derive(Clone, Copy)] -pub union Compressor { +pub struct Compressor { cv: [vec128_storage; 8], - bytes: [u8; 128], } + impl Compressor { #[inline] pub fn new(bytes: [u8; 128]) -> Self { - Compressor { bytes } + Compressor { + cv: transmute!(bytes), + } } #[inline] pub fn input(&mut self, data: &GenericArray) { - f8(unsafe { &mut self.cv }, data.as_ptr()); + f8(&mut self.cv, data.as_ptr()) } #[inline] pub fn finalize(self) -> [u8; 128] { - unsafe { self.bytes } + transmute!(self.cv) } } diff --git a/hashes/skein/src/lib.rs b/hashes/skein/src/lib.rs index b6cf5c38..0252aac0 100644 --- a/hashes/skein/src/lib.rs +++ b/hashes/skein/src/lib.rs @@ -18,6 +18,7 @@ use threefish_cipher::{Threefish1024, Threefish256, Threefish512}; /// N word buffer. #[derive(Copy, Clone)] +#[repr(C)] union Block where N: ArrayLength, @@ -43,13 +44,45 @@ where } fn as_byte_array(&self) -> &GenericArray { + // SAFETY: Both fields of this union have the same layout and bit + // validity, so it's okay to treat either field as the other field's + // type. Since the union is `repr(C)`, they both live in the same byte + // range. (One exception: They don't have the same alignment, but the + // alignment of the entire union is the greater of their alignments, so + // this isn't an issue.) unsafe { &self.bytes } } fn as_byte_array_mut(&mut self) -> &mut GenericArray { + // SAFETY: Both fields of this union have the same layout and bit + // validity, so it's okay to treat either field as the other field's + // type. Since the union is `repr(C)`, they both live in the same byte + // range. (One exception: They don't have the same alignment, but the + // alignment of the entire union is the greater of their alignments, so + // this isn't an issue.) unsafe { &mut self.bytes } } + fn as_word_array(&self) -> &GenericArray>::Output> { + // SAFETY: Both fields of this union have the same layout and bit + // validity, so it's okay to treat either field as the other field's + // type. Since the union is `repr(C)`, they both live in the same byte + // range. (One exception: They don't have the same alignment, but the + // alignment of the entire union is the greater of their alignments, so + // this isn't an issue.) + unsafe { &self.words } + } + + fn as_word_array_mut(&mut self) -> &mut GenericArray>::Output> { + // SAFETY: Both fields of this union have the same layout and bit + // validity, so it's okay to treat either field as the other field's + // type. Since the union is `repr(C)`, they both live in the same byte + // range. (One exception: They don't have the same alignment, but the + // alignment of the entire union is the greater of their alignments, so + // this isn't an issue.) + unsafe { &mut self.words } + } + fn from_byte_array(block: &GenericArray) -> Self { Block { bytes: *block } } @@ -81,10 +114,7 @@ where type Output = Block; fn bitxor(mut self, rhs: Block) -> Self::Output { // XOR is endian-agnostic - for (s, r) in unsafe { &mut self.words } - .iter_mut() - .zip(unsafe { &rhs.words }) - { + for (s, r) in self.as_word_array_mut().iter_mut().zip(rhs.as_word_array()) { *s ^= *r; } self diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index a4497f83..a52b5df0 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -10,6 +10,7 @@ keywords = ["crypto", "simd", "x86"] categories = ["cryptography", "no-std"] [dependencies] +zerocopy = { version = "0.6.3", features = ["simd"] } [badges] travis-ci = { repository = "cryptocorrosion/cryptocorrosion" } diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index add6c485..a405994a 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -3,9 +3,10 @@ use crate::soft::{x2, x4}; use crate::types::*; use core::ops::*; +use zerocopy::{AsBytes, FromBytes}; #[repr(C)] -#[derive(Clone, Copy)] +#[derive(Clone, Copy, FromBytes, AsBytes)] pub union vec128_storage { d: [u32; 4], q: [u64; 2], @@ -452,11 +453,14 @@ impl Machine for GenericMachine { } } -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes)] +#[repr(transparent)] pub struct u32x4_generic([u32; 4]); -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes)] +#[repr(transparent)] pub struct u64x2_generic([u64; 2]); -#[derive(Copy, Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes)] +#[repr(transparent)] pub struct u128x1_generic([u128; 1]); impl From for vec128_storage { @@ -561,53 +565,45 @@ impl BSwap for u128x1_generic { impl StoreBytes for u32x4_generic { #[inline(always)] unsafe fn unsafe_read_le(input: &[u8]) -> Self { - assert_eq!(input.len(), 16); - let x = core::mem::transmute(core::ptr::read(input as *const _ as *const [u8; 16])); + let x = u32x4_generic::read_from(input).unwrap(); dmap(x, |x| x.to_le()) } #[inline(always)] unsafe fn unsafe_read_be(input: &[u8]) -> Self { - assert_eq!(input.len(), 16); - let x = core::mem::transmute(core::ptr::read(input as *const _ as *const [u8; 16])); + let x = u32x4_generic::read_from(input).unwrap(); dmap(x, |x| x.to_be()) } #[inline(always)] fn write_le(self, out: &mut [u8]) { - assert_eq!(out.len(), 16); let x = dmap(self, |x| x.to_le()); - unsafe { core::ptr::write(out as *mut _ as *mut [u8; 16], core::mem::transmute(x)) } + x.write_to(out).unwrap(); } #[inline(always)] fn write_be(self, out: &mut [u8]) { - assert_eq!(out.len(), 16); let x = dmap(self, |x| x.to_be()); - unsafe { core::ptr::write(out as *mut _ as *mut [u8; 16], core::mem::transmute(x)) } + x.write_to(out).unwrap(); } } impl StoreBytes for u64x2_generic { #[inline(always)] unsafe fn unsafe_read_le(input: &[u8]) -> Self { - assert_eq!(input.len(), 16); - let x = core::mem::transmute(core::ptr::read(input as *const _ as *const [u8; 16])); + let x = u64x2_generic::read_from(input).unwrap(); qmap(x, |x| x.to_le()) } #[inline(always)] unsafe fn unsafe_read_be(input: &[u8]) -> Self { - assert_eq!(input.len(), 16); - let x = core::mem::transmute(core::ptr::read(input as *const _ as *const [u8; 16])); + let x = u64x2_generic::read_from(input).unwrap(); qmap(x, |x| x.to_be()) } #[inline(always)] fn write_le(self, out: &mut [u8]) { - assert_eq!(out.len(), 16); let x = qmap(self, |x| x.to_le()); - unsafe { core::ptr::write(out as *mut _ as *mut [u8; 16], core::mem::transmute(x)) } + x.write_to(out).unwrap(); } #[inline(always)] fn write_be(self, out: &mut [u8]) { - assert_eq!(out.len(), 16); let x = qmap(self, |x| x.to_be()); - unsafe { core::ptr::write(out as *mut _ as *mut [u8; 16], core::mem::transmute(x)) } + x.write_to(out).unwrap(); } } diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index 0ae390c4..1ac76ebf 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -4,8 +4,10 @@ use crate::types::*; use crate::{vec128_storage, vec256_storage, vec512_storage}; use core::marker::PhantomData; use core::ops::*; +use zerocopy::{AsBytes, FromBytes}; -#[derive(Copy, Clone, Default)] +#[derive(Copy, Clone, Default, FromBytes, AsBytes)] +#[repr(transparent)] #[allow(non_camel_case_types)] pub struct x2(pub [W; 2], PhantomData); impl x2 { @@ -220,7 +222,8 @@ impl LaneWords4 for x2 { } } -#[derive(Copy, Clone, Default)] +#[derive(Copy, Clone, Default, FromBytes, AsBytes)] +#[repr(transparent)] #[allow(non_camel_case_types)] pub struct x4(pub [W; 4]); impl x4 { diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index 937732da..b41a0f47 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -2,6 +2,7 @@ use crate::types::*; use core::arch::x86_64::{__m128i, __m256i}; +use zerocopy::{AsBytes, FromBytes}; mod sse2; @@ -106,7 +107,8 @@ pub type AVX2 = Avx2Machine; /// Converting into and out of this type should be essentially free, although it may be more /// aligned than a particular impl requires. #[allow(non_camel_case_types)] -#[derive(Copy, Clone)] +#[derive(Copy, Clone, FromBytes, AsBytes)] +#[repr(C)] pub union vec128_storage { u32x4: [u32; 4], u64x2: [u64; 2], diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 97197a43..4f9cae57 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -9,6 +9,7 @@ use core::marker::PhantomData; use core::ops::{ Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, }; +use zerocopy::{transmute, AsBytes, FromBytes}; macro_rules! impl_binop { ($vec:ident, $trait:ident, $fn:ident, $impl_fn:ident) => { @@ -39,7 +40,8 @@ macro_rules! impl_binop_assign { macro_rules! def_vec { ($vec:ident, $word:ident) => { #[allow(non_camel_case_types)] - #[derive(Copy, Clone)] + #[derive(Copy, Clone, FromBytes, AsBytes)] + #[repr(transparent)] pub struct $vec { x: __m128i, s3: PhantomData, @@ -883,7 +885,7 @@ pub type u128x4_sse2 = x4>; impl Vector<[u32; 16]> for u32x4x4_sse2 { #[inline(always)] fn to_scalars(self) -> [u32; 16] { - unsafe { core::mem::transmute(self) } + transmute!(self) } } @@ -1153,7 +1155,7 @@ mod test { x_s3.bswap() }; - assert_eq!(x_s2, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s2, transmute!(x_s3)); assert_eq!(x_s2, s2.vec(ys)); } @@ -1177,7 +1179,7 @@ mod test { }; assert_eq!(x_s2, s2.vec(ys)); - assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s3, transmute!(x_s3)); } #[test] @@ -1199,7 +1201,7 @@ mod test { x_s3.shuffle2301() }; assert_eq!(x_s2, s2.vec(ys)); - assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s3, transmute!(x_s3)); let x_s2 = { let x_s2: ::u32x4 = s2.vec(xs); @@ -1210,12 +1212,12 @@ mod test { x_s3.shuffle3012() }; assert_eq!(x_s2, s2.vec(zs)); - assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s3, transmute!(x_s3)); let x_s2 = x_s2.shuffle1230(); let x_s3 = x_s3.shuffle1230(); assert_eq!(x_s2, s2.vec(xs)); - assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s3, transmute!(x_s3)); } #[test] @@ -1237,7 +1239,7 @@ mod test { x_s3.shuffle2301() }; assert_eq!(x_s2, s2.vec(ys)); - assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s3, transmute!(x_s3)); let x_s2 = { let x_s2: ::u64x4 = s2.vec(xs); @@ -1248,12 +1250,12 @@ mod test { x_s3.shuffle3012() }; assert_eq!(x_s2, s2.vec(zs)); - assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s3, transmute!(x_s3)); let x_s2 = x_s2.shuffle1230(); let x_s3 = x_s3.shuffle1230(); assert_eq!(x_s2, s2.vec(xs)); - assert_eq!(x_s3, unsafe { core::mem::transmute(x_s3) }); + assert_eq!(x_s3, transmute!(x_s3)); } #[cfg_attr(not(all(target_feature = "ssse3", target_feature = "sse4.1")), ignore)] @@ -1382,8 +1384,10 @@ pub mod avx2 { use core::arch::x86_64::*; use core::marker::PhantomData; use core::ops::*; + use zerocopy::{transmute, AsBytes, FromBytes}; - #[derive(Copy, Clone)] + #[derive(Copy, Clone, FromBytes, AsBytes)] + #[repr(transparent)] pub struct u32x4x2_avx2 { x: __m256i, ni: PhantomData, @@ -1675,7 +1679,7 @@ pub mod avx2 { impl Vector<[u32; 16]> for u32x4x4_avx2 { #[inline(always)] fn to_scalars(self) -> [u32; 16] { - unsafe { core::mem::transmute(self) } + transmute!(self) } } impl From> for vec512_storage { From 0effdfc787c23e72a313d635cdc26acfac835ee1 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Tue, 30 Jul 2024 02:13:27 +0000 Subject: [PATCH 78/84] Update Rust version --- Cargo.toml | 1 + README.md | 6 +----- block-ciphers/threefish/Cargo.toml | 3 ++- hashes/blake/Cargo.toml | 1 + hashes/groestl/Cargo.toml | 3 ++- hashes/jh/Cargo.toml | 3 ++- hashes/skein/Cargo.toml | 3 ++- stream-ciphers/chacha/Cargo.toml | 3 ++- utils-simd/crypto-simd/Cargo.toml | 3 ++- utils-simd/ppv-lite86/Cargo.toml | 3 ++- utils-simd/ppv-null/Cargo.toml | 3 ++- 11 files changed, 19 insertions(+), 13 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fb9780d0..174e5c36 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "utils-simd/ppv-lite86", "utils-simd/ppv-null", ] +resolver = "2" [patch.crates-io] c2-chacha = { path = "stream-ciphers/chacha" } diff --git a/README.md b/README.md index 269177e3..9f2d6e89 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,7 @@ The main interface to these crates is the RustCrypto traits. All crates are no-std compatible. -Minimum Rust version: -- algorithm crates (with RustCrypto API): 1.41.0 -- support crates: 1.32.0 - -[![Build Status](https://travis-ci.org/cryptocorrosion/cryptocorrosion.svg?branch=master)](https://travis-ci.org/cryptocorrosion/cryptocorrosion) +Minimum Rust version: 1.61.0 ## Supported algorithms diff --git a/block-ciphers/threefish/Cargo.toml b/block-ciphers/threefish/Cargo.toml index fb30fb46..64ffce39 100644 --- a/block-ciphers/threefish/Cargo.toml +++ b/block-ciphers/threefish/Cargo.toml @@ -7,7 +7,8 @@ description = "Threefish block cipher" documentation = "https://docs.rs/threefish" repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "threefish", "gost", "block-cipher"] -edition = "2018" +edition = "2021" +rust-version = "1.61" [dependencies] cipher = "0.3" diff --git a/hashes/blake/Cargo.toml b/hashes/blake/Cargo.toml index bd41c48c..c0f37d5b 100644 --- a/hashes/blake/Cargo.toml +++ b/hashes/blake/Cargo.toml @@ -7,6 +7,7 @@ description = "BLAKE hash functions" repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "blake", "hash", "digest"] categories = ["cryptography", "no-std"] +rust-version = "1.61" [dependencies] block-buffer = "0.9" diff --git a/hashes/groestl/Cargo.toml b/hashes/groestl/Cargo.toml index 72f07207..e100c25e 100644 --- a/hashes/groestl/Cargo.toml +++ b/hashes/groestl/Cargo.toml @@ -8,7 +8,8 @@ documentation = "https://docs.rs/groestl-aesni" keywords = ["crypto", "groestl", "hash", "digest"] categories = ["cryptography", "no-std"] repository = "https://github.com/cryptocorrosion/hashes" -edition = "2018" +edition = "2021" +rust-version = "1.61" [dependencies] block-buffer = "0.9" diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index 11bd91e6..d1ba4a43 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -8,7 +8,8 @@ documentation = "https://docs.rs/jh-x86_64" keywords = ["crypto", "jh", "hash", "digest"] categories = ["cryptography", "no-std"] repository = "https://github.com/cryptocorrosion/cryptocorrosion" -edition = "2018" +edition = "2021" +rust-version = "1.61" [dependencies] block-buffer = "0.9" diff --git a/hashes/skein/Cargo.toml b/hashes/skein/Cargo.toml index 995cca96..7eb48154 100644 --- a/hashes/skein/Cargo.toml +++ b/hashes/skein/Cargo.toml @@ -7,7 +7,8 @@ description = "Skein hash functions" repository = "https://github.com/cryptocorrosion/hashes" keywords = ["crypto", "skein", "hash", "digest"] categories = ["cryptography", "no-std"] -edition = "2018" +edition = "2021" +rust-version = "1.61" [dependencies] block-buffer = { version = "0.9", features = ["block-padding"] } diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index a474100d..42a4b469 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -3,13 +3,14 @@ name = "c2-chacha" version = "0.3.3" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" -edition = "2018" +edition = "2021" description = "The ChaCha family of stream ciphers" repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["chacha", "chacha20", "xchacha20", "cipher", "crypto"] categories = ["cryptography", "no-std"] readme = "README.md" documentation = "https://docs.rs/c2-chacha" +rust-version = "1.61" [dependencies] ppv-lite86 = { package = "ppv-lite86", version = "0.2.14", default-features = false } diff --git a/utils-simd/crypto-simd/Cargo.toml b/utils-simd/crypto-simd/Cargo.toml index 9b3858ef..b07c3e7c 100644 --- a/utils-simd/crypto-simd/Cargo.toml +++ b/utils-simd/crypto-simd/Cargo.toml @@ -2,12 +2,13 @@ name = "crypto-simd" version = "0.2.0" authors = ["The CryptoCorrosion Contributors"] -edition = "2018" +edition = "2021" license = "MIT/Apache-2.0" description = "Crypto-oriented SIMD wrapper abstracting over multiple backends" repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "simd"] categories = ["cryptography", "no-std"] +rust-version = "1.61" [dependencies] packed_simd_crate = { package = "packed_simd", version = "0.3", optional = true } diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index a4497f83..aa8428b0 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -2,12 +2,13 @@ name = "ppv-lite86" version = "0.2.17" authors = ["The CryptoCorrosion Contributors"] -edition = "2018" +edition = "2021" license = "MIT/Apache-2.0" description = "Implementation of the crypto-simd API for x86" repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "simd", "x86"] categories = ["cryptography", "no-std"] +rust-version = "1.61" [dependencies] diff --git a/utils-simd/ppv-null/Cargo.toml b/utils-simd/ppv-null/Cargo.toml index ce778a74..d18b096e 100644 --- a/utils-simd/ppv-null/Cargo.toml +++ b/utils-simd/ppv-null/Cargo.toml @@ -2,12 +2,13 @@ name = "ppv-null" version = "0.2.0" authors = ["The CryptoCorrosion Contributors"] -edition = "2018" +edition = "2021" license = "MIT/Apache-2.0" description = "Safe, portable, non-SIMD implementation of the crypto-simd API" repository = "https://github.com/cryptocorrosion/cryptocorrosion" keywords = ["crypto", "simd"] categories = ["cryptography", "no-std"] +rust-version = "1.61" [dependencies] crypto-simd = "0.1" From 6cf6260414546c0eacd7236b931bdc095e5a2e41 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Tue, 30 Jul 2024 02:46:06 +0000 Subject: [PATCH 79/84] Updates and GH test workflow --- .github/workflows/check-clippy.yaml | 15 ++- .github/workflows/check-rustfmt.yaml | 12 ++- .github/workflows/tests.yaml | 156 +++++++++++++++++++++++++++ hashes/jh/Cargo.toml | 2 +- 4 files changed, 178 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/check-clippy.yaml b/.github/workflows/check-clippy.yaml index a8a16e15..bdc77a89 100644 --- a/.github/workflows/check-clippy.yaml +++ b/.github/workflows/check-clippy.yaml @@ -1,9 +1,18 @@ -name: check-clippy -on: pull_request +name: Clippy + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +env: + CARGO_TERM_COLOR: always + jobs: clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: cargo-clippy run: cargo clippy diff --git a/.github/workflows/check-rustfmt.yaml b/.github/workflows/check-rustfmt.yaml index 705c3fba..fb582971 100644 --- a/.github/workflows/check-rustfmt.yaml +++ b/.github/workflows/check-rustfmt.yaml @@ -1,9 +1,15 @@ -name: check-rustfmt -on: pull_request +name: Rustfmt + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + jobs: format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: cargo-fmt run: cargo fmt -- --check diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..84efd0b5 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,156 @@ +name: Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +permissions: + contents: read + +jobs: + check-doc: + name: Check doc + runs-on: ubuntu-latest + env: + RUSTDOCFLAGS: "-Dwarnings --cfg docsrs -Zunstable-options --generate-link-to-definition" + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + - name: Workspace docs + run: cargo doc --all-features --no-deps + + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + toolchain: stable + - os: macos-latest + target: x86_64-apple-darwin + toolchain: stable + # TODO: also aarch64 / M1 + - os: windows-latest + target: x86_64-pc-windows-gnu + toolchain: stable + - os: windows-latest + target: x86_64-pc-windows-msvc + toolchain: beta + # Test both windows-gnu and windows-msvc; use beta rust on one + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + variant: MSRV + toolchain: 1.61.0 + - os: ubuntu-latest + deps: sudo apt-get update ; sudo apt install gcc-multilib + target: i686-unknown-linux-gnu + toolchain: nightly + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + toolchain: nightly + variant: minimal_versions + + steps: + - uses: actions/checkout@v4 + - name: MSRV + if: ${{ matrix.variant == 'MSRV' }} + run: cp Cargo.lock.msrv Cargo.lock + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + target: ${{ matrix.target }} + toolchain: ${{ matrix.toolchain }} + - run: ${{ matrix.deps }} + - name: Maybe minimal versions + if: ${{ matrix.variant == 'minimal_versions' }} + run: | + cargo generate-lockfile -Z minimal-versions + - name: Test + run: | + cargo test --target ${{ matrix.target }} + + test-cross: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: powerpc-unknown-linux-gnu + toolchain: stable + + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + target: ${{ matrix.target }} + toolchain: ${{ matrix.toolchain }} + - name: Cache cargo plugins + uses: actions/cache@v4 + with: + path: ~/.cargo/bin/ + key: ${{ runner.os }}-cargo-plugins + - name: Install cross + run: cargo install cross || true + - name: Test + run: | + cross test --no-fail-fast --target ${{ matrix.target }} -p c2-chacha + cross test --no-fail-fast --target ${{ matrix.target }} -p ppv-lite86 + cross test --no-fail-fast --target ${{ matrix.target }} -p ppv-null + cross test --no-fail-fast --target ${{ matrix.target }} -p crypto-simd + cross test --no-fail-fast --target ${{ matrix.target }} -p threefish-cipher + cross test --no-fail-fast --target ${{ matrix.target }} -p blake-hash + cross test --no-fail-fast --target ${{ matrix.target }} -p skein-hash + cross test --no-fail-fast --target ${{ matrix.target }} -p jh-x86_64 + # groestl-aesni: not cross-tested as it only supports specific hardware. + + test-miri: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + run: | + rustup toolchain install nightly --component miri + rustup override set nightly + cargo miri setup + - name: Test + run: | + cargo miri test -p c2-chacha + cargo miri test -p ppv-lite86 + cargo miri test -p ppv-null + cargo miri test -p crypto-simd + cargo miri test -p threefish-cipher + cargo miri test -p blake-hash + cargo miri test -p skein-hash + # groestl-aesni: not tested as it only supports specific hardware. + # jh-x86_64: should work under miri but runs too slowly. + + test-no-std: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + with: + target: thumbv6m-none-eabi + - name: Chacha, build only + run: cargo build -p c2-chacha --target=thumbv6m-none-eabi --no-default-features + + test-ios: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + with: + target: aarch64-apple-ios + - name: Chacha, build only + run: cargo build -p c2-chacha --target=aarch64-apple-ios diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index d1ba4a43..51629694 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" rust-version = "1.61" [dependencies] -block-buffer = "0.9" +block-buffer = { version = "0.9", features = ["block-padding"] } digest = "0.9" hex-literal = "0.2" simd = { package = "ppv-lite86", version = "0.2.6" } From 5e71465deb7d53a7a09b89981ccf1a27bb129bcf Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Tue, 30 Jul 2024 02:46:06 +0000 Subject: [PATCH 80/84] Updates and GH test workflow --- .github/workflows/check-clippy.yaml | 15 +- .github/workflows/check-rustfmt.yaml | 12 +- .github/workflows/tests.yaml | 168 +++++++++++++++++++ Cargo.lock.msrv | 230 +++++++++++++++++++++++++++ hashes/jh/Cargo.toml | 2 +- utils-simd/ppv-lite86/src/lib.rs | 28 +++- 6 files changed, 444 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/tests.yaml create mode 100644 Cargo.lock.msrv diff --git a/.github/workflows/check-clippy.yaml b/.github/workflows/check-clippy.yaml index a8a16e15..bdc77a89 100644 --- a/.github/workflows/check-clippy.yaml +++ b/.github/workflows/check-clippy.yaml @@ -1,9 +1,18 @@ -name: check-clippy -on: pull_request +name: Clippy + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +env: + CARGO_TERM_COLOR: always + jobs: clippy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: cargo-clippy run: cargo clippy diff --git a/.github/workflows/check-rustfmt.yaml b/.github/workflows/check-rustfmt.yaml index 705c3fba..fb582971 100644 --- a/.github/workflows/check-rustfmt.yaml +++ b/.github/workflows/check-rustfmt.yaml @@ -1,9 +1,15 @@ -name: check-rustfmt -on: pull_request +name: Rustfmt + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + jobs: format: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: cargo-fmt run: cargo fmt -- --check diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 00000000..3cb563a0 --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,168 @@ +name: Tests + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +permissions: + contents: read + +jobs: + #check-doc: + # name: Check doc + # runs-on: ubuntu-latest + # env: + # RUSTDOCFLAGS: "-Dwarnings --cfg docsrs -Zunstable-options --generate-link-to-definition" + # steps: + # - uses: actions/checkout@v4 + # - name: Install toolchain + # uses: dtolnay/rust-toolchain@master + # with: + # toolchain: nightly + # - name: Workspace docs + # run: cargo doc --all-features --no-deps + + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + toolchain: stable + - os: macos-latest + target: x86_64-apple-darwin + toolchain: stable + # TODO: also aarch64 / M1 + - os: windows-latest + target: x86_64-pc-windows-gnu + toolchain: stable + - os: windows-latest + target: x86_64-pc-windows-msvc + toolchain: beta + # Test both windows-gnu and windows-msvc; use beta rust on one + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + variant: MSRV + toolchain: 1.61.0 + # FIXME: some failures down the dependency tree + #- os: ubuntu-latest + # target: x86_64-unknown-linux-gnu + # toolchain: nightly + # variant: minimal_versions + + steps: + - uses: actions/checkout@v4 + - name: MSRV + if: ${{ matrix.variant == 'MSRV' }} + run: cp Cargo.lock.msrv Cargo.lock + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + target: ${{ matrix.target }} + toolchain: ${{ matrix.toolchain }} + - run: ${{ matrix.deps }} + - name: Maybe minimal versions + if: ${{ matrix.variant == 'minimal_versions' }} + run: | + cargo generate-lockfile -Z minimal-versions + - name: Test + run: | + cargo test --target ${{ matrix.target }} + + test-cross: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + include: + - os: ubuntu-latest + target: powerpc-unknown-linux-gnu + toolchain: stable + + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@master + with: + target: ${{ matrix.target }} + toolchain: ${{ matrix.toolchain }} + - name: Cache cargo plugins + uses: actions/cache@v4 + with: + path: ~/.cargo/bin/ + key: ${{ runner.os }}-cargo-plugins + - name: Install cross + run: cargo install cross || true + - name: Test + run: | + cross test --no-fail-fast --target ${{ matrix.target }} -p c2-chacha + cross test --no-fail-fast --target ${{ matrix.target }} -p ppv-lite86 + cross test --no-fail-fast --target ${{ matrix.target }} -p ppv-null + cross test --no-fail-fast --target ${{ matrix.target }} -p crypto-simd + cross test --no-fail-fast --target ${{ matrix.target }} -p threefish-cipher + cross test --no-fail-fast --target ${{ matrix.target }} -p blake-hash + cross test --no-fail-fast --target ${{ matrix.target }} -p skein-hash + # Failing on PPC + # cross test --no-fail-fast --target ${{ matrix.target }} -p jh-x86_64 + # groestl-aesni: not cross-tested as it only supports specific hardware. + + test-miri: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + run: | + rustup toolchain install nightly --component miri + rustup override set nightly + cargo miri setup + - name: Test + run: | + cargo miri test -p c2-chacha + cargo miri test -p ppv-lite86 + cargo miri test -p ppv-null + cargo miri test -p crypto-simd + cargo miri test -p threefish-cipher + cargo miri test -p blake-hash + cargo miri test -p skein-hash + # groestl-aesni: not tested as it only supports specific hardware. + # jh-x86_64: should work under miri but runs too slowly. + + test-no-std: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + with: + target: thumbv6m-none-eabi + - name: Chacha, build only + run: cargo build -p c2-chacha --target=thumbv6m-none-eabi --no-default-features + + test-ios: + runs-on: macos-latest + steps: + - uses: actions/checkout@v4 + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + with: + target: aarch64-apple-ios + - name: Chacha, build only + run: cargo build -p c2-chacha --target=aarch64-apple-ios + + test-686: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Deps + run: sudo apt-get update ; sudo apt install gcc-multilib + - name: Install toolchain + uses: dtolnay/rust-toolchain@nightly + with: + target: i686-unknown-linux-gnu + toolchain: nightly + - name: Chacha + run: cargo test -p c2-chacha --target=i686-unknown-linux-gnu diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv new file mode 100644 index 00000000..b0aaa00a --- /dev/null +++ b/Cargo.lock.msrv @@ -0,0 +1,230 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" + +[[package]] +name = "blake-hash" +version = "0.4.1" +dependencies = [ + "block-buffer", + "digest", + "ppv-lite86", +] + +[[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.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "block-padding", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "c2-chacha" +version = "0.3.3" +dependencies = [ + "cipher", + "hex-literal", + "ppv-lite86", +] + +[[package]] +name = "cc" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26a5c3fd7bfa1ce3897a3a3501d362b2d87b7f2583ebcb4a949ec25911025cbc" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "cipher" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ee52072ec15386f770805afd189a01c8841be8696bed250fa2f13c4c0d6dfb7" +dependencies = [ + "generic-array", +] + +[[package]] +name = "crypto-simd" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28a0eee94b5af99ac4441823c99f59b1ef92a6a4b9723b4c6ad95e8cd4c994b2" + +[[package]] +name = "crypto-simd" +version = "0.2.0" +dependencies = [ + "packed_simd", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "blobby", + "generic-array", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "groestl-aesni" +version = "0.3.0" +dependencies = [ + "block-buffer", + "digest", + "lazy_static", +] + +[[package]] +name = "hex-literal" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d70693199b3cf4552f3fa720b54163927a3ebed2aef240efaf556033ab336a11" +dependencies = [ + "hex-literal-impl", + "proc-macro-hack", +] + +[[package]] +name = "hex-literal-impl" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59448fc2f82a5fb6907f78c3d69d843e82ff5b051923313cc4438cb0c7b745a8" +dependencies = [ + "proc-macro-hack", +] + +[[package]] +name = "jh-x86_64" +version = "0.3.0" +dependencies = [ + "block-buffer", + "cc", + "digest", + "hex-literal", + "ppv-lite86", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libm" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", + "libm", +] + +[[package]] +name = "packed_simd" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f9f08af0c877571712e2e3e686ad79efad9657dbf0f7c3c8ba943ff6c38932d" +dependencies = [ + "cfg-if", + "num-traits", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" + +[[package]] +name = "ppv-null" +version = "0.2.0" +dependencies = [ + "crypto-simd 0.1.1", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + +[[package]] +name = "skein-hash" +version = "0.3.1" +dependencies = [ + "block-buffer", + "cipher", + "digest", + "threefish-cipher", +] + +[[package]] +name = "threefish-cipher" +version = "0.4.0" +dependencies = [ + "cipher", + "hex-literal", +] + +[[package]] +name = "typenum" +version = "1.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index d1ba4a43..51629694 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -12,7 +12,7 @@ edition = "2021" rust-version = "1.61" [dependencies] -block-buffer = "0.9" +block-buffer = { version = "0.9", features = ["block-padding"] } digest = "0.9" hex-literal = "0.2" simd = { package = "ppv-lite86", version = "0.2.6" } diff --git a/utils-simd/ppv-lite86/src/lib.rs b/utils-simd/ppv-lite86/src/lib.rs index 638552fc..311df97b 100644 --- a/utils-simd/ppv-lite86/src/lib.rs +++ b/utils-simd/ppv-lite86/src/lib.rs @@ -9,14 +9,34 @@ mod soft; mod types; pub use self::types::*; -#[cfg(all(target_arch = "x86_64", target_feature = "sse2", not(feature = "no_simd"), not(miri)))] +#[cfg(all( + target_arch = "x86_64", + target_feature = "sse2", + not(feature = "no_simd"), + not(miri) +))] pub mod x86_64; -#[cfg(all(target_arch = "x86_64", target_feature = "sse2", not(feature = "no_simd"), not(miri)))] +#[cfg(all( + target_arch = "x86_64", + target_feature = "sse2", + not(feature = "no_simd"), + not(miri) +))] use self::x86_64 as arch; -#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64"), all(target_arch = "x86_64", not(target_feature = "sse2"))))] +#[cfg(any( + feature = "no_simd", + miri, + not(target_arch = "x86_64"), + all(target_arch = "x86_64", not(target_feature = "sse2")) +))] pub mod generic; -#[cfg(any(feature = "no_simd", miri, not(target_arch = "x86_64"), all(target_arch = "x86_64", not(target_feature = "sse2"))))] +#[cfg(any( + feature = "no_simd", + miri, + not(target_arch = "x86_64"), + all(target_arch = "x86_64", not(target_feature = "sse2")) +))] use self::generic as arch; pub use self::arch::{vec128_storage, vec256_storage, vec512_storage}; From 6802e23b395bbe8933e69bdbe5d42dbeb86786d1 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Tue, 30 Jul 2024 03:27:58 +0000 Subject: [PATCH 81/84] Version bump --- hashes/groestl/Cargo.toml | 2 +- hashes/jh/Cargo.toml | 2 +- hashes/skein/Cargo.toml | 2 +- utils-simd/ppv-lite86/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/hashes/groestl/Cargo.toml b/hashes/groestl/Cargo.toml index e2ffeb84..6f5db0b2 100644 --- a/hashes/groestl/Cargo.toml +++ b/hashes/groestl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "groestl-aesni" -version = "0.3.0" +version = "0.3.1" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "Hardware-accelerated Groestl hash for x86-64 systems with AES extensions" diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index c4009b0b..93b52542 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "jh-x86_64" -version = "0.3.0" +version = "0.3.1" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "Portable JH with optimizations for x86-64 cpus" diff --git a/hashes/skein/Cargo.toml b/hashes/skein/Cargo.toml index 7eb48154..cb4ec249 100644 --- a/hashes/skein/Cargo.toml +++ b/hashes/skein/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "skein-hash" -version = "0.3.1" +version = "0.3.2" authors = ["The CryptoCorrosion Contributors"] license = "MIT/Apache-2.0" description = "Skein hash functions" diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index f9c89b18..4ac78e14 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.17" +version = "0.2.18" authors = ["The CryptoCorrosion Contributors"] edition = "2021" license = "MIT/Apache-2.0" From ee6c7d4056780ee58593597b739bb501be567e03 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Tue, 30 Jul 2024 12:23:05 +0000 Subject: [PATCH 82/84] Update dependencies --- block-ciphers/threefish/Cargo.toml | 2 +- hashes/groestl/Cargo.toml | 3 ++- hashes/groestl/src/compressor.rs | 4 ++-- hashes/jh/Cargo.toml | 4 ++-- stream-ciphers/chacha/Cargo.toml | 2 +- utils-simd/ppv-lite86/Cargo.toml | 5 +++-- utils-simd/ppv-lite86/src/generic.rs | 9 +++++---- utils-simd/ppv-lite86/src/soft.rs | 6 +++--- utils-simd/ppv-lite86/src/x86_64/mod.rs | 4 ++-- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 10 ++++++---- 10 files changed, 27 insertions(+), 22 deletions(-) diff --git a/block-ciphers/threefish/Cargo.toml b/block-ciphers/threefish/Cargo.toml index 64ffce39..192cd77c 100644 --- a/block-ciphers/threefish/Cargo.toml +++ b/block-ciphers/threefish/Cargo.toml @@ -14,7 +14,7 @@ rust-version = "1.61" cipher = "0.3" [dev-dependencies] -hex-literal = "0.2" +hex-literal = "0.3" [features] no_unroll = [] diff --git a/hashes/groestl/Cargo.toml b/hashes/groestl/Cargo.toml index 6f5db0b2..1ab180c9 100644 --- a/hashes/groestl/Cargo.toml +++ b/hashes/groestl/Cargo.toml @@ -15,7 +15,8 @@ rust-version = "1.61" block-buffer = "0.9" digest = "0.9" lazy_static = { version = "1.2", optional = true } -zerocopy = { version = "0.6.3", features = ["simd"] } +zerocopy = { version = "0.7", features = ["simd"] } +zerocopy-derive = "0.7" [dev-dependencies] digest = { version = "0.9", features = ["dev"] } diff --git a/hashes/groestl/src/compressor.rs b/hashes/groestl/src/compressor.rs index 2727243d..52d45550 100644 --- a/hashes/groestl/src/compressor.rs +++ b/hashes/groestl/src/compressor.rs @@ -2,7 +2,7 @@ use block_buffer::generic_array::typenum::{U128, U64}; use block_buffer::generic_array::GenericArray; use core::arch::x86_64::*; use core::ops::BitXor; -use zerocopy::{AsBytes, FromBytes}; +use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; trait Map2 { type Output; @@ -12,7 +12,7 @@ trait Map2 { Self: Sized; } -#[derive(Copy, Clone, FromBytes, AsBytes)] +#[derive(Copy, Clone, FromBytes, AsBytes, FromZeroes)] #[repr(C)] pub struct X4(__m128i, __m128i, __m128i, __m128i); diff --git a/hashes/jh/Cargo.toml b/hashes/jh/Cargo.toml index 93b52542..42d02b6a 100644 --- a/hashes/jh/Cargo.toml +++ b/hashes/jh/Cargo.toml @@ -14,9 +14,9 @@ rust-version = "1.61" [dependencies] block-buffer = { version = "0.9", features = ["block-padding"] } digest = "0.9" -hex-literal = "0.2" +hex-literal = "0.3" simd = { package = "ppv-lite86", version = "0.2.6" } -zerocopy = "0.6.3" +zerocopy = "0.7" [dev-dependencies] digest = { version = "0.9", features = ["dev"] } diff --git a/stream-ciphers/chacha/Cargo.toml b/stream-ciphers/chacha/Cargo.toml index 42a4b469..591c1733 100644 --- a/stream-ciphers/chacha/Cargo.toml +++ b/stream-ciphers/chacha/Cargo.toml @@ -17,7 +17,7 @@ ppv-lite86 = { package = "ppv-lite86", version = "0.2.14", default-features = fa cipher = { version = "0.3", optional = true } [dev-dependencies] -hex-literal = "0.2" +hex-literal = "0.3" [features] default = ["std", "rustcrypto_api"] diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 4ac78e14..b10d5f94 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.18" +version = "0.2.19" authors = ["The CryptoCorrosion Contributors"] edition = "2021" license = "MIT/Apache-2.0" @@ -11,7 +11,8 @@ categories = ["cryptography", "no-std"] rust-version = "1.61" [dependencies] -zerocopy = { version = "0.6.3", features = ["simd"] } +zerocopy = { version = "0.7", features = ["simd"] } +zerocopy-derive = "0.7" [badges] travis-ci = { repository = "cryptocorrosion/cryptocorrosion" } diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index a405994a..325877ef 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -4,9 +4,10 @@ use crate::soft::{x2, x4}; use crate::types::*; use core::ops::*; use zerocopy::{AsBytes, FromBytes}; +use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; #[repr(C)] -#[derive(Clone, Copy, FromBytes, AsBytes)] +#[derive(Clone, Copy, FromBytes, AsBytes, FromZeroes)] pub union vec128_storage { d: [u32; 4], q: [u64; 2], @@ -453,13 +454,13 @@ impl Machine for GenericMachine { } } -#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes)] +#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] pub struct u32x4_generic([u32; 4]); -#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes)] +#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] pub struct u64x2_generic([u64; 2]); -#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes)] +#[derive(Copy, Clone, Debug, PartialEq, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] pub struct u128x1_generic([u128; 1]); diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index 1ac76ebf..038f3972 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -4,9 +4,9 @@ use crate::types::*; use crate::{vec128_storage, vec256_storage, vec512_storage}; use core::marker::PhantomData; use core::ops::*; -use zerocopy::{AsBytes, FromBytes}; +use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; -#[derive(Copy, Clone, Default, FromBytes, AsBytes)] +#[derive(Copy, Clone, Default, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] #[allow(non_camel_case_types)] pub struct x2(pub [W; 2], PhantomData); @@ -222,7 +222,7 @@ impl LaneWords4 for x2 { } } -#[derive(Copy, Clone, Default, FromBytes, AsBytes)] +#[derive(Copy, Clone, Default, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] #[allow(non_camel_case_types)] pub struct x4(pub [W; 4]); diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index b41a0f47..cb4c298e 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -2,7 +2,7 @@ use crate::types::*; use core::arch::x86_64::{__m128i, __m256i}; -use zerocopy::{AsBytes, FromBytes}; +use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; mod sse2; @@ -107,7 +107,7 @@ pub type AVX2 = Avx2Machine; /// Converting into and out of this type should be essentially free, although it may be more /// aligned than a particular impl requires. #[allow(non_camel_case_types)] -#[derive(Copy, Clone, FromBytes, AsBytes)] +#[derive(Copy, Clone, FromBytes, AsBytes, FromZeroes)] #[repr(C)] pub union vec128_storage { u32x4: [u32; 4], diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index 4f9cae57..fba0c949 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -9,7 +9,8 @@ use core::marker::PhantomData; use core::ops::{ Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, }; -use zerocopy::{transmute, AsBytes, FromBytes}; +use zerocopy::transmute; +use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; macro_rules! impl_binop { ($vec:ident, $trait:ident, $fn:ident, $impl_fn:ident) => { @@ -40,7 +41,7 @@ macro_rules! impl_binop_assign { macro_rules! def_vec { ($vec:ident, $word:ident) => { #[allow(non_camel_case_types)] - #[derive(Copy, Clone, FromBytes, AsBytes)] + #[derive(Copy, Clone, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] pub struct $vec { x: __m128i, @@ -1384,9 +1385,10 @@ pub mod avx2 { use core::arch::x86_64::*; use core::marker::PhantomData; use core::ops::*; - use zerocopy::{transmute, AsBytes, FromBytes}; + use zerocopy::transmute; + use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; - #[derive(Copy, Clone, FromBytes, AsBytes)] + #[derive(Copy, Clone, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] pub struct u32x4x2_avx2 { x: __m256i, From c10d89901f85cf3891cb594a55c7f6d88865c723 Mon Sep 17 00:00:00 2001 From: Sebastian Scholz Date: Fri, 2 Aug 2024 15:41:07 +0200 Subject: [PATCH 83/84] Use zerocopies derive feature rather than depending on zerocopy_derive --- hashes/groestl/Cargo.toml | 3 +-- hashes/groestl/src/compressor.rs | 2 +- utils-simd/ppv-lite86/Cargo.toml | 3 +-- utils-simd/ppv-lite86/src/generic.rs | 3 +-- utils-simd/ppv-lite86/src/soft.rs | 2 +- utils-simd/ppv-lite86/src/x86_64/mod.rs | 2 +- utils-simd/ppv-lite86/src/x86_64/sse2.rs | 6 ++---- 7 files changed, 8 insertions(+), 13 deletions(-) diff --git a/hashes/groestl/Cargo.toml b/hashes/groestl/Cargo.toml index 1ab180c9..41b0edbb 100644 --- a/hashes/groestl/Cargo.toml +++ b/hashes/groestl/Cargo.toml @@ -15,8 +15,7 @@ rust-version = "1.61" block-buffer = "0.9" digest = "0.9" lazy_static = { version = "1.2", optional = true } -zerocopy = { version = "0.7", features = ["simd"] } -zerocopy-derive = "0.7" +zerocopy = { version = "0.7", features = ["simd", "derive"] } [dev-dependencies] digest = { version = "0.9", features = ["dev"] } diff --git a/hashes/groestl/src/compressor.rs b/hashes/groestl/src/compressor.rs index 52d45550..fc6b5fd4 100644 --- a/hashes/groestl/src/compressor.rs +++ b/hashes/groestl/src/compressor.rs @@ -2,7 +2,7 @@ use block_buffer::generic_array::typenum::{U128, U64}; use block_buffer::generic_array::GenericArray; use core::arch::x86_64::*; use core::ops::BitXor; -use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes, FromZeroes}; trait Map2 { type Output; diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index b10d5f94..6b8fbd6f 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -11,8 +11,7 @@ categories = ["cryptography", "no-std"] rust-version = "1.61" [dependencies] -zerocopy = { version = "0.7", features = ["simd"] } -zerocopy-derive = "0.7" +zerocopy = { version = "0.7", features = ["simd", "derive"] } [badges] travis-ci = { repository = "cryptocorrosion/cryptocorrosion" } diff --git a/utils-simd/ppv-lite86/src/generic.rs b/utils-simd/ppv-lite86/src/generic.rs index 325877ef..8989482a 100644 --- a/utils-simd/ppv-lite86/src/generic.rs +++ b/utils-simd/ppv-lite86/src/generic.rs @@ -3,8 +3,7 @@ use crate::soft::{x2, x4}; use crate::types::*; use core::ops::*; -use zerocopy::{AsBytes, FromBytes}; -use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes, FromZeroes}; #[repr(C)] #[derive(Clone, Copy, FromBytes, AsBytes, FromZeroes)] diff --git a/utils-simd/ppv-lite86/src/soft.rs b/utils-simd/ppv-lite86/src/soft.rs index 038f3972..b2cf0e19 100644 --- a/utils-simd/ppv-lite86/src/soft.rs +++ b/utils-simd/ppv-lite86/src/soft.rs @@ -4,7 +4,7 @@ use crate::types::*; use crate::{vec128_storage, vec256_storage, vec512_storage}; use core::marker::PhantomData; use core::ops::*; -use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes, FromZeroes}; #[derive(Copy, Clone, Default, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] diff --git a/utils-simd/ppv-lite86/src/x86_64/mod.rs b/utils-simd/ppv-lite86/src/x86_64/mod.rs index cb4c298e..9d22c0d6 100644 --- a/utils-simd/ppv-lite86/src/x86_64/mod.rs +++ b/utils-simd/ppv-lite86/src/x86_64/mod.rs @@ -2,7 +2,7 @@ use crate::types::*; use core::arch::x86_64::{__m128i, __m256i}; -use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{AsBytes, FromBytes, FromZeroes}; mod sse2; diff --git a/utils-simd/ppv-lite86/src/x86_64/sse2.rs b/utils-simd/ppv-lite86/src/x86_64/sse2.rs index fba0c949..4b95911d 100644 --- a/utils-simd/ppv-lite86/src/x86_64/sse2.rs +++ b/utils-simd/ppv-lite86/src/x86_64/sse2.rs @@ -9,8 +9,7 @@ use core::marker::PhantomData; use core::ops::{ Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not, }; -use zerocopy::transmute; -use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; +use zerocopy::{transmute, AsBytes, FromBytes, FromZeroes}; macro_rules! impl_binop { ($vec:ident, $trait:ident, $fn:ident, $impl_fn:ident) => { @@ -1385,8 +1384,7 @@ pub mod avx2 { use core::arch::x86_64::*; use core::marker::PhantomData; use core::ops::*; - use zerocopy::transmute; - use zerocopy_derive::{AsBytes, FromBytes, FromZeroes}; + use zerocopy::{transmute, AsBytes, FromBytes, FromZeroes}; #[derive(Copy, Clone, FromBytes, AsBytes, FromZeroes)] #[repr(transparent)] From 16e2fe894fc39944c2625d735fff3d697d052e42 Mon Sep 17 00:00:00 2001 From: Kaz Wesley Date: Sat, 3 Aug 2024 03:06:54 +0000 Subject: [PATCH 84/84] Version bump --- utils-simd/ppv-lite86/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils-simd/ppv-lite86/Cargo.toml b/utils-simd/ppv-lite86/Cargo.toml index 6b8fbd6f..feb8cc2c 100644 --- a/utils-simd/ppv-lite86/Cargo.toml +++ b/utils-simd/ppv-lite86/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ppv-lite86" -version = "0.2.19" +version = "0.2.20" authors = ["The CryptoCorrosion Contributors"] edition = "2021" license = "MIT/Apache-2.0"