diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f027d9395d..85176ef0f7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,8 @@ jobs: with: persist-credentials: false - - run: cargo fmt --all -- --check + - run: rustup toolchain install nightly --profile minimal --component rustfmt + - run: cargo +nightly fmt --all -- --check clippy: runs-on: ${{ matrix.host_os }} diff --git a/bench/aead.rs b/bench/aead.rs index b5df6f7a09..3bc39c1e23 100644 --- a/bench/aead.rs +++ b/bench/aead.rs @@ -13,11 +13,13 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #![allow(missing_docs)] -use criterion::{BatchSize, BenchmarkId, Criterion, black_box, criterion_group, criterion_main}; -use ring::{ - aead::{self, BoundKey}, - error, - rand::{SecureRandom, SystemRandom}, +use { + criterion::{BatchSize, BenchmarkId, Criterion, black_box, criterion_group, criterion_main}, + ring::{ + aead::{self, BoundKey}, + error, + rand::{SecureRandom, SystemRandom}, + }, }; static ALGORITHMS: &[(&str, &aead::Algorithm)] = &[ diff --git a/bench/agreement.rs b/bench/agreement.rs index 5262c79bce..7ca4584617 100644 --- a/bench/agreement.rs +++ b/bench/agreement.rs @@ -13,10 +13,12 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #![allow(missing_docs)] -use criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main}; -use ring::{ - agreement::{self, EphemeralPrivateKey, UnparsedPublicKey}, - rand, +use { + criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main}, + ring::{ + agreement::{self, EphemeralPrivateKey, UnparsedPublicKey}, + rand, + }, }; static ALGORITHMS: &[(&str, &agreement::Algorithm)] = &[ diff --git a/bench/digest.rs b/bench/digest.rs index 6e6b4ac685..03e3a0aff3 100644 --- a/bench/digest.rs +++ b/bench/digest.rs @@ -13,8 +13,10 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #![allow(missing_docs)] -use criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main}; -use ring::digest; +use { + criterion::{BenchmarkId, Criterion, black_box, criterion_group, criterion_main}, + ring::digest, +}; static ALGORITHMS: &[(&str, &digest::Algorithm)] = &[ ("sha256", &digest::SHA256), diff --git a/bench/ecdsa.rs b/bench/ecdsa.rs index 32ede9d13f..b2963ceedb 100644 --- a/bench/ecdsa.rs +++ b/bench/ecdsa.rs @@ -13,10 +13,14 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #![allow(missing_docs)] -use criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main}; -use ring::{ - rand, - signature::{self, EcdsaKeyPair, EcdsaSigningAlgorithm, EcdsaVerificationAlgorithm, KeyPair}, +use { + criterion::{BatchSize, Criterion, black_box, criterion_group, criterion_main}, + ring::{ + rand, + signature::{ + self, EcdsaKeyPair, EcdsaSigningAlgorithm, EcdsaVerificationAlgorithm, KeyPair, + }, + }, }; static ALGORITHMS: &[(&str, &EcdsaSigningAlgorithm, &EcdsaVerificationAlgorithm)] = &[ diff --git a/bench/rsa.rs b/bench/rsa.rs index e8caddb2b6..9cc1cfe41f 100644 --- a/bench/rsa.rs +++ b/bench/rsa.rs @@ -13,8 +13,10 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #![allow(missing_docs)] -use criterion::{Criterion, criterion_group, criterion_main}; -use ring::signature::{RSA_PKCS1_2048_8192_SHA256, UnparsedPublicKey}; +use { + criterion::{Criterion, criterion_group, criterion_main}, + ring::signature::{RSA_PKCS1_2048_8192_SHA256, UnparsedPublicKey}, +}; macro_rules! verify_case { ( $modulus_bits:expr, $exponent_value:expr ) => { diff --git a/build/build.rs b/build/build.rs index fa6cdacdea..06e2babcb0 100644 --- a/build/build.rs +++ b/build/build.rs @@ -19,13 +19,15 @@ // Avoid `std::env` here. All configuration should be done through `Target`, // `Profile`, and `Tools`. -use self::path::{join_components_with_forward_slashes_if_windows, walk_dir}; -use std::{ - ffi::{OsStr, OsString}, - fs, - io::Write, - path::{Path, PathBuf}, - process::{Command, Stdio}, +use { + self::path::{join_components_with_forward_slashes_if_windows, walk_dir}, + std::{ + ffi::{OsStr, OsString}, + fs, + io::Write, + path::{Path, PathBuf}, + process::{Command, Stdio}, + }, }; mod path; diff --git a/cavp/tests/shavs.rs b/cavp/tests/shavs.rs index f5654b195e..e926514052 100644 --- a/cavp/tests/shavs.rs +++ b/cavp/tests/shavs.rs @@ -52,13 +52,11 @@ mod digest_shavs { ( $file_name:ident, $algorithm_name:ident ) => { #[allow(non_snake_case)] mod $algorithm_name { - use super::run_known_answer_test; - use ring::digest; #[allow(deprecated)] use ring::test_file; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::wasm_bindgen_test as test; + use {super::run_known_answer_test, ring::digest}; #[test] fn short_msg_known_answer_test() { diff --git a/rustfmt.toml b/rustfmt.toml index fa1a3dbd13..670532086f 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,5 +1,7 @@ edition = "2024" style_edition = "2024" +group_imports = "One" +imports_granularity = "One" max_width = 100 newline_style = "Unix" reorder_imports = true diff --git a/src/aead/aes/bs.rs b/src/aead/aes/bs.rs index dfeb47bff2..dd649247d2 100644 --- a/src/aead/aes/bs.rs +++ b/src/aead/aes/bs.rs @@ -14,8 +14,10 @@ #![cfg(all(target_arch = "arm", target_endian = "little"))] -use super::{Counter, Overlapping, ffi::AES_KEY, vp}; -use core::mem::MaybeUninit; +use { + super::{Counter, Overlapping, ffi::AES_KEY, vp}, + core::mem::MaybeUninit, +}; #[repr(transparent)] struct Key(AES_KEY); diff --git a/src/aead/aes/fallback.rs b/src/aead/aes/fallback.rs index b31ff87a00..dc0d0451bf 100644 --- a/src/aead/aes/fallback.rs +++ b/src/aead/aes/fallback.rs @@ -15,13 +15,14 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - super::overlapping::IndexError, BLOCK_LEN, Block, Counter, EncryptBlock, EncryptCtr32, Iv, - KeyBytes, Overlapping, ffi, +use { + super::{ + super::overlapping::IndexError, BLOCK_LEN, Block, Counter, EncryptBlock, EncryptCtr32, Iv, + KeyBytes, Overlapping, ffi, + }, + crate::{bb, polyfill::usize_from_u32}, + core::{array, mem::size_of, num::NonZero}, }; -use crate::{bb, polyfill::usize_from_u32}; -use core::{array, mem::size_of, num::NonZero}; #[derive(Clone)] pub enum Key { diff --git a/src/aead/aes/ffi.rs b/src/aead/aes/ffi.rs index 8964a12294..d7bc92add7 100644 --- a/src/aead/aes/ffi.rs +++ b/src/aead/aes/ffi.rs @@ -14,13 +14,14 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{AES_128_KEY_LEN, AES_256_KEY_LEN, BLOCK_LEN, KeyBytes, Overlapping}; -use crate::{bits::BitLength, c}; -use core::{ - ffi::{c_int, c_uint}, - mem::MaybeUninit, - num::NonZero, +use { + super::{AES_128_KEY_LEN, AES_256_KEY_LEN, BLOCK_LEN, KeyBytes, Overlapping}, + crate::{bits::BitLength, c}, + core::{ + ffi::{c_int, c_uint}, + mem::MaybeUninit, + num::NonZero, + }, }; /// nonce || big-endian counter. diff --git a/src/aead/aes/mod.rs b/src/aead/aes/mod.rs index 2f73b9f7a8..dbd7a3760b 100644 --- a/src/aead/aes/mod.rs +++ b/src/aead/aes/mod.rs @@ -12,14 +12,14 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{NONCE_LEN, Overlapping, nonce::Nonce, overlapping, quic::Sample}; -use crate::cpu::{self, GetFeature as _}; -use core::num::NonZero; - #[cfg(all(target_arch = "aarch64", target_endian = "little"))] pub(super) use self::ffi::{RdKey, Rounds}; - pub(super) use ffi::Counter; +use { + super::{NONCE_LEN, Overlapping, nonce::Nonce, overlapping, quic::Sample}, + crate::cpu::{self, GetFeature as _}, + core::num::NonZero, +}; #[macro_use] mod ffi; diff --git a/src/aead/aes/tests/aes_gcm_tests.rs b/src/aead/aes/tests/aes_gcm_tests.rs index 4d436a306d..e45e6e9556 100644 --- a/src/aead/aes/tests/aes_gcm_tests.rs +++ b/src/aead/aes/tests/aes_gcm_tests.rs @@ -15,8 +15,10 @@ // These AES-GCM-specific tests are here instead of in `aead/tess/` because // `Counter`'s API isn't visible at that level. -use super::super::{super::aes_gcm::MAX_IN_OUT_LEN, *}; -use core::num::NonZero; +use { + super::super::{super::aes_gcm::MAX_IN_OUT_LEN, *}, + core::num::NonZero, +}; #[test] fn test_aes_gcm_counter_blocks_max() { diff --git a/src/aead/aes/tests/aes_tests.rs b/src/aead/aes/tests/aes_tests.rs index 8e3ddef8f1..08569b4e96 100644 --- a/src/aead/aes/tests/aes_tests.rs +++ b/src/aead/aes/tests/aes_tests.rs @@ -12,9 +12,10 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::super::*; -use crate::cpu; -use crate::testutil as test; +use { + super::super::*, + crate::{cpu, testutil as test}, +}; #[test] pub fn test_aes() { diff --git a/src/aead/aes/vp.rs b/src/aead/aes/vp.rs index 7ef61e1464..0d7d2498de 100644 --- a/src/aead/aes/vp.rs +++ b/src/aead/aes/vp.rs @@ -19,19 +19,20 @@ target_arch = "x86_64" ))] -#[allow(unused_imports)] -use crate::polyfill::prelude::*; - -use super::{Block, Counter, EncryptBlock, EncryptCtr32, Iv, KeyBytes, Overlapping, ffi}; -use crate::cpu; #[cfg(all(target_arch = "aarch64", target_endian = "little"))] use crate::polyfill::StartMutPtr; +#[allow(unused_imports)] +use crate::polyfill::prelude::*; #[cfg(any( all(target_arch = "arm", target_endian = "little"), target_arch = "x86", target_arch = "x86_64" ))] use ffi::AES_KEY; +use { + super::{Block, Counter, EncryptBlock, EncryptCtr32, Iv, KeyBytes, Overlapping, ffi}, + crate::cpu, +}; #[cfg(all(target_arch = "aarch64", target_endian = "little"))] #[derive(Clone)] @@ -227,8 +228,10 @@ impl EncryptBlock for Key { #[cfg(target_arch = "x86")] impl EncryptCtr32 for Key { fn ctr32_encrypt_within(&self, mut in_out: Overlapping<'_>, ctr: &mut Counter) { - use super::{BLOCK_LEN, overlapping::IndexError}; - use crate::polyfill::sliceutil; + use { + super::{BLOCK_LEN, overlapping::IndexError}, + crate::polyfill::sliceutil, + }; assert_eq!(in_out.len() % BLOCK_LEN, 0); let blocks = in_out.len() / BLOCK_LEN; diff --git a/src/aead/aes_gcm/aarch64.rs b/src/aead/aes_gcm/aarch64.rs index 9b8330c234..931e688b9f 100644 --- a/src/aead/aes_gcm/aarch64.rs +++ b/src/aead/aes_gcm/aarch64.rs @@ -16,10 +16,11 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{BLOCK_LEN, Counter, Overlapping, aes, gcm}; -use crate::{bits::BitLength, polyfill::u64_from_usize}; -use core::num::NonZero; +use { + super::{BLOCK_LEN, Counter, Overlapping, aes, gcm}, + crate::{bits::BitLength, polyfill::u64_from_usize}, + core::num::NonZero, +}; pub(super) fn seal_whole( aes_key: &aes::hw::Key, diff --git a/src/aead/aes_gcm/aeshwclmulmovbe.rs b/src/aead/aes_gcm/aeshwclmulmovbe.rs index ccdad98178..0f0782e56f 100644 --- a/src/aead/aes_gcm/aeshwclmulmovbe.rs +++ b/src/aead/aes_gcm/aeshwclmulmovbe.rs @@ -16,14 +16,15 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - super::overlapping::IndexError, - Aad, BLOCK_LEN, Overlapping, Tag, - aes::{self, Counter, EncryptCtr32, OverlappingPartialBlock}, - gcm, open_whole_partial_tail, +use { + super::{ + super::overlapping::IndexError, + Aad, BLOCK_LEN, Overlapping, Tag, + aes::{self, Counter, EncryptCtr32, OverlappingPartialBlock}, + gcm, open_whole_partial_tail, + }, + crate::{c, error::InputTooLongError}, }; -use crate::{c, error::InputTooLongError}; const STRIDE_LEN: usize = 6 * BLOCK_LEN; diff --git a/src/aead/aes_gcm/mod.rs b/src/aead/aes_gcm/mod.rs index 4517b82e38..78ebd2f9b0 100644 --- a/src/aead/aes_gcm/mod.rs +++ b/src/aead/aes_gcm/mod.rs @@ -14,19 +14,6 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - Aad, AuthError, ForgedPlaintext, Nonce, Overlapping, Tag, - aes::{self, BLOCK_LEN, Counter, OverlappingPartialBlock, ZERO_BLOCK}, - gcm, - overlapping::IndexError, -}; -use crate::{ - cpu, - error::InputTooLongError, - polyfill::{sliceutil::overwrite_at_start, usize_from_u64_saturated}, -}; - #[cfg(any( all(target_arch = "aarch64", target_endian = "little"), all(target_arch = "arm", target_endian = "little"), @@ -34,6 +21,19 @@ use crate::{ target_arch = "x86_64" ))] use cpu::GetFeature as _; +use { + super::{ + Aad, AuthError, ForgedPlaintext, Nonce, Overlapping, Tag, + aes::{self, BLOCK_LEN, Counter, OverlappingPartialBlock, ZERO_BLOCK}, + gcm, + overlapping::IndexError, + }, + crate::{ + cpu, + error::InputTooLongError, + polyfill::{sliceutil::overwrite_at_start, usize_from_u64_saturated}, + }, +}; mod aarch64; mod aeshwclmulmovbe; diff --git a/src/aead/aes_gcm/vaesclmulavx2.rs b/src/aead/aes_gcm/vaesclmulavx2.rs index fc8694b0e7..b43eea30f0 100644 --- a/src/aead/aes_gcm/vaesclmulavx2.rs +++ b/src/aead/aes_gcm/vaesclmulavx2.rs @@ -16,10 +16,11 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{BLOCK_LEN, Counter, Overlapping, aes, gcm}; -use crate::c; -use core::num::NonZero; +use { + super::{BLOCK_LEN, Counter, Overlapping, aes, gcm}, + crate::c, + core::num::NonZero, +}; pub(super) fn seal_whole_vaes_clmul_avx2( aes_key: &aes::hw::Key, diff --git a/src/aead/algorithm.rs b/src/aead/algorithm.rs index 6c4f7bbc7a..535a72a891 100644 --- a/src/aead/algorithm.rs +++ b/src/aead/algorithm.rs @@ -12,17 +12,19 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{ - Aad, AuthError, ForgedPlaintext, KeyInner, TAG_LEN, Tag, aes, aes_gcm, chacha20_poly1305, - nonce::{NONCE_LEN, Nonce}, - overlapping::{IndexError, Overlapping}, +use { + super::{ + Aad, AuthError, ForgedPlaintext, KeyInner, TAG_LEN, Tag, aes, aes_gcm, chacha20_poly1305, + nonce::{NONCE_LEN, Nonce}, + overlapping::{IndexError, Overlapping}, + }, + crate::{ + cpu, + error::{self, InputTooLongError}, + hkdf, + }, + core::ops::RangeFrom, }; -use crate::{ - cpu, - error::{self, InputTooLongError}, - hkdf, -}; -use core::ops::RangeFrom; impl hkdf::KeyType for &'static Algorithm { #[inline] diff --git a/src/aead/chacha/fallback.rs b/src/aead/chacha/fallback.rs index 596bc77122..e0877e6672 100644 --- a/src/aead/chacha/fallback.rs +++ b/src/aead/chacha/fallback.rs @@ -15,9 +15,11 @@ // Adapted from the public domain, estream code by D. Bernstein. // Adapted from the BoringSSL crypto/chacha/chacha.c. -use super::{super::overlapping::IndexError, BLOCK_LEN, Counter, Key, Overlapping}; -use crate::{bb, polyfill::sliceutil}; -use core::mem::size_of; +use { + super::{super::overlapping::IndexError, BLOCK_LEN, Counter, Key, Overlapping}, + crate::{bb, polyfill::sliceutil}, + core::mem::size_of, +}; pub(super) fn ChaCha20_ctr32(key: &Key, counter: Counter, mut in_out: Overlapping<'_>) { const SIGMA: [u32; 4] = [ diff --git a/src/aead/chacha/mod.rs b/src/aead/chacha/mod.rs index 9aad422823..e5e801b9b7 100644 --- a/src/aead/chacha/mod.rs +++ b/src/aead/chacha/mod.rs @@ -13,9 +13,11 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{Nonce, overlapping, quic::Sample}; -use crate::cpu; -use cfg_if::cfg_if; +use { + super::{Nonce, overlapping, quic::Sample}, + crate::cpu, + cfg_if::cfg_if, +}; cfg_if! { if #[cfg(any( diff --git a/src/aead/chacha/tests.rs b/src/aead/chacha/tests.rs index d3fa6e3014..a1b40a74ca 100644 --- a/src/aead/chacha/tests.rs +++ b/src/aead/chacha/tests.rs @@ -15,10 +15,11 @@ extern crate alloc; -use super::super::{chacha::*, overlapping::IndexError}; -use crate::error; -use crate::testutil as test; -use alloc::vec; +use { + super::super::{chacha::*, overlapping::IndexError}, + crate::{error, testutil as test}, + alloc::vec, +}; const MAX_ALIGNMENT_AND_OFFSET: (usize, usize) = (15, 259); const MAX_ALIGNMENT_AND_OFFSET_SUBSET: (usize, usize) = diff --git a/src/aead/chacha20_poly1305/integrated.rs b/src/aead/chacha20_poly1305/integrated.rs index 526cf5ad40..0233a77dda 100644 --- a/src/aead/chacha20_poly1305/integrated.rs +++ b/src/aead/chacha20_poly1305/integrated.rs @@ -12,13 +12,15 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{ - super::{NONCE_LEN, TAG_LEN}, - Aad, InputTooLongError, KEY_LEN, Key, Nonce, Tag, - chacha::Overlapping, - check_input_lengths, +use { + super::{ + super::{NONCE_LEN, TAG_LEN}, + Aad, InputTooLongError, KEY_LEN, Key, Nonce, Tag, + chacha::Overlapping, + check_input_lengths, + }, + cfg_if::cfg_if, }; -use cfg_if::cfg_if; macro_rules! declare_open { ( unsafe fn $name:ident ) => { diff --git a/src/aead/chacha20_poly1305/mod.rs b/src/aead/chacha20_poly1305/mod.rs index efee4da79f..37484c7326 100644 --- a/src/aead/chacha20_poly1305/mod.rs +++ b/src/aead/chacha20_poly1305/mod.rs @@ -14,18 +14,19 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - Aad, AuthError, ForgedPlaintext, Nonce, Tag, - chacha::{self, Counter, Overlapping}, - poly1305, -}; -use crate::{ - cpu, - error::InputTooLongError, - polyfill::{sliceutil, u64_from_usize, usize_from_u64_saturated}, +use { + super::{ + Aad, AuthError, ForgedPlaintext, Nonce, Tag, + chacha::{self, Counter, Overlapping}, + poly1305, + }, + crate::{ + cpu, + error::InputTooLongError, + polyfill::{sliceutil, u64_from_usize, usize_from_u64_saturated}, + }, + cfg_if::cfg_if, }; -use cfg_if::cfg_if; cfg_if! { if #[cfg(any( diff --git a/src/aead/chacha20_poly1305_openssh.rs b/src/aead/chacha20_poly1305_openssh.rs index 206a4f3f79..523781cc96 100644 --- a/src/aead/chacha20_poly1305_openssh.rs +++ b/src/aead/chacha20_poly1305_openssh.rs @@ -31,15 +31,16 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - Aad, Nonce, Tag, - chacha::{self, *}, - chacha20_poly1305, cpu, poly1305, -}; -use crate::{ - bb, - error::{self, InputTooLongError}, +use { + super::{ + Aad, Nonce, Tag, + chacha::{self, *}, + chacha20_poly1305, cpu, poly1305, + }, + crate::{ + bb, + error::{self, InputTooLongError}, + }, }; /// A key for sealing packets. diff --git a/src/aead/gcm/clmul_aarch64.rs b/src/aead/gcm/clmul_aarch64.rs index c37178a4ef..f839725ab9 100644 --- a/src/aead/gcm/clmul_aarch64.rs +++ b/src/aead/gcm/clmul_aarch64.rs @@ -14,12 +14,14 @@ #![cfg(all(target_arch = "aarch64", target_endian = "little"))] -use super::{ - UpdateBlock, Xi, - ffi::{self, BLOCK_LEN, KeyValue}, +use { + super::{ + UpdateBlock, Xi, + ffi::{self, BLOCK_LEN, KeyValue}, + }, + crate::cpu, + core::mem::MaybeUninit, }; -use crate::cpu; -use core::mem::MaybeUninit; #[derive(Clone)] #[repr(transparent)] // Used in FFI diff --git a/src/aead/gcm/clmul_x86.rs b/src/aead/gcm/clmul_x86.rs index 8111938c67..910ccddf21 100644 --- a/src/aead/gcm/clmul_x86.rs +++ b/src/aead/gcm/clmul_x86.rs @@ -14,12 +14,14 @@ #![cfg(target_arch = "x86")] -use super::{ - UpdateBlock, UpdateBlocks, Xi, - ffi::{self, BLOCK_LEN, KeyValue}, +use { + super::{ + UpdateBlock, UpdateBlocks, Xi, + ffi::{self, BLOCK_LEN, KeyValue}, + }, + crate::{c, cpu}, + core::{mem::MaybeUninit, num::NonZero, slice}, }; -use crate::{c, cpu}; -use core::{mem::MaybeUninit, num::NonZero, slice}; #[derive(Clone)] #[repr(transparent)] diff --git a/src/aead/gcm/clmul_x86_64.rs b/src/aead/gcm/clmul_x86_64.rs index 7dbea224fb..9d92f75118 100644 --- a/src/aead/gcm/clmul_x86_64.rs +++ b/src/aead/gcm/clmul_x86_64.rs @@ -14,12 +14,14 @@ #![cfg(target_arch = "x86_64")] -use super::{ - UpdateBlock, UpdateBlocks, Xi, - ffi::{self, BLOCK_LEN, KeyValue}, +use { + super::{ + UpdateBlock, UpdateBlocks, Xi, + ffi::{self, BLOCK_LEN, KeyValue}, + }, + crate::{c, cpu}, + core::{mem::MaybeUninit, num::NonZero, slice}, }; -use crate::{c, cpu}; -use core::{mem::MaybeUninit, num::NonZero, slice}; #[derive(Clone)] #[repr(transparent)] diff --git a/src/aead/gcm/clmulavxmovbe.rs b/src/aead/gcm/clmulavxmovbe.rs index 20c2c2421b..6733aef68a 100644 --- a/src/aead/gcm/clmulavxmovbe.rs +++ b/src/aead/gcm/clmulavxmovbe.rs @@ -14,9 +14,11 @@ #![cfg(target_arch = "x86_64")] -use super::{BLOCK_LEN, KeyValue, UpdateBlock, UpdateBlocks, Xi, ffi}; -use crate::{c, cpu::intel}; -use core::{mem::MaybeUninit, num::NonZero, slice}; +use { + super::{BLOCK_LEN, KeyValue, UpdateBlock, UpdateBlocks, Xi, ffi}, + crate::{c, cpu::intel}, + core::{mem::MaybeUninit, num::NonZero, slice}, +}; #[derive(Clone)] #[repr(transparent)] diff --git a/src/aead/gcm/fallback/mod.rs b/src/aead/gcm/fallback/mod.rs index 34201624cb..f4d9e88ed0 100644 --- a/src/aead/gcm/fallback/mod.rs +++ b/src/aead/gcm/fallback/mod.rs @@ -24,9 +24,10 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{BLOCK_LEN, KeyValue, UpdateBlock, UpdateBlocks, Xi, ffi::U128}; -use crate::polyfill::ArraySplitMap as _; +use { + super::{BLOCK_LEN, KeyValue, UpdateBlock, UpdateBlocks, Xi, ffi::U128}, + crate::polyfill::ArraySplitMap as _, +}; #[derive(Clone)] pub struct Key { diff --git a/src/aead/gcm/ffi.rs b/src/aead/gcm/ffi.rs index acf0182cbf..ba8b6a56be 100644 --- a/src/aead/gcm/ffi.rs +++ b/src/aead/gcm/ffi.rs @@ -14,9 +14,10 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use crate::{bb, c, polyfill::ArraySplitMap}; -use core::num::NonZero; +use { + crate::{bb, c, polyfill::ArraySplitMap}, + core::num::NonZero, +}; pub(in super::super) const BLOCK_LEN: usize = 16; pub(in super::super) type Block = [u8; BLOCK_LEN]; diff --git a/src/aead/gcm/mod.rs b/src/aead/gcm/mod.rs index 1e4d20c5a2..814a75bdf7 100644 --- a/src/aead/gcm/mod.rs +++ b/src/aead/gcm/mod.rs @@ -14,17 +14,17 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use self::ffi::{BLOCK_LEN, Block, ZERO_BLOCK}; -use super::{Aad, aes_gcm}; -use crate::{ - bits::{BitLength, FromByteLen as _}, - error::InputTooLongError, - polyfill::{NotSend, sliceutil::overwrite_at_start}, -}; -use cfg_if::cfg_if; - pub(super) use ffi::KeyValue; +use { + self::ffi::{BLOCK_LEN, Block, ZERO_BLOCK}, + super::{Aad, aes_gcm}, + crate::{ + bits::{BitLength, FromByteLen as _}, + error::InputTooLongError, + polyfill::{NotSend, sliceutil::overwrite_at_start}, + }, + cfg_if::cfg_if, +}; cfg_if! { if #[cfg(any(all(target_arch = "aarch64", target_endian = "little"), diff --git a/src/aead/gcm/neon.rs b/src/aead/gcm/neon.rs index 0b2740b414..5c0c78d450 100644 --- a/src/aead/gcm/neon.rs +++ b/src/aead/gcm/neon.rs @@ -19,10 +19,11 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{BLOCK_LEN, KeyValue, UpdateBlock, UpdateBlocks, Xi, ffi}; -use crate::{c, cpu}; -use core::{mem::MaybeUninit, num::NonZero}; +use { + super::{BLOCK_LEN, KeyValue, UpdateBlock, UpdateBlocks, Xi, ffi}, + crate::{c, cpu}, + core::{mem::MaybeUninit, num::NonZero}, +}; #[derive(Clone)] #[repr(transparent)] diff --git a/src/aead/gcm/vclmulavx2.rs b/src/aead/gcm/vclmulavx2.rs index 6c078bc07c..315e3db9bb 100644 --- a/src/aead/gcm/vclmulavx2.rs +++ b/src/aead/gcm/vclmulavx2.rs @@ -14,15 +14,17 @@ #![cfg(target_arch = "x86_64")] -use super::{ - UpdateBlock, Xi, - ffi::{self, BLOCK_LEN, KeyValue}, +use { + super::{ + UpdateBlock, Xi, + ffi::{self, BLOCK_LEN, KeyValue}, + }, + crate::{ + c, + cpu::intel::{Avx2, VAesClmul}, + }, + core::{mem::MaybeUninit, num::NonZero, slice}, }; -use crate::{ - c, - cpu::intel::{Avx2, VAesClmul}, -}; -use core::{mem::MaybeUninit, num::NonZero, slice}; #[derive(Clone)] #[repr(transparent)] diff --git a/src/aead/less_safe_key.rs b/src/aead/less_safe_key.rs index b51702a1e9..b62c194d8c 100644 --- a/src/aead/less_safe_key.rs +++ b/src/aead/less_safe_key.rs @@ -12,12 +12,14 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{Aad, Algorithm, KeyInner, Nonce, TAG_LEN, Tag, UnboundKey}; -use crate::{ - cpu, - error::{self, InputTooLongError}, +use { + super::{Aad, Algorithm, KeyInner, Nonce, TAG_LEN, Tag, UnboundKey}, + crate::{ + cpu, + error::{self, InputTooLongError}, + }, + core::ops::RangeFrom, }; -use core::ops::RangeFrom; /// Immutable keys for use in situations where `OpeningKey`/`SealingKey` and /// `NonceSequence` cannot reasonably be used. diff --git a/src/aead/mod.rs b/src/aead/mod.rs index 67d5581917..59bc0483b6 100644 --- a/src/aead/mod.rs +++ b/src/aead/mod.rs @@ -21,13 +21,6 @@ //! [AEAD]: https://eprint.iacr.org/2000/025.pdf //! [`crypto.cipher.AEAD`]: https://golang.org/pkg/crypto/cipher/#AEAD -use self::auth_error::AuthError; -use crate::{ - bb, cpu, - error::{self, InputTooLongError}, - polyfill::{u64_from_usize, usize_from_u64_saturated}, -}; - pub use self::{ algorithm::{AES_128_GCM, AES_256_GCM, Algorithm, CHACHA20_POLY1305}, less_safe_key::LessSafeKey, @@ -36,6 +29,14 @@ pub use self::{ sealing_key::SealingKey, unbound_key::UnboundKey, }; +use { + self::auth_error::AuthError, + crate::{ + bb, cpu, + error::{self, InputTooLongError}, + polyfill::{u64_from_usize, usize_from_u64_saturated}, + }, +}; /// A sequences of unique nonces. /// diff --git a/src/aead/opening_key.rs b/src/aead/opening_key.rs index 3e11527987..7fc15ae571 100644 --- a/src/aead/opening_key.rs +++ b/src/aead/opening_key.rs @@ -21,9 +21,11 @@ //! [AEAD]: https://eprint.iacr.org/2000/025.pdf //! [`crypto.cipher.AEAD`]: https://golang.org/pkg/crypto/cipher/#AEAD -use super::{Aad, Algorithm, BoundKey, LessSafeKey, NonceSequence, Tag, UnboundKey}; -use crate::error; -use core::ops::RangeFrom; +use { + super::{Aad, Algorithm, BoundKey, LessSafeKey, NonceSequence, Tag, UnboundKey}, + crate::error, + core::ops::RangeFrom, +}; /// An AEAD key for authenticating and decrypting ("opening"), bound to a nonce /// sequence. diff --git a/src/aead/overlapping/array.rs b/src/aead/overlapping/array.rs index 9c797da187..3e1ca99dd0 100644 --- a/src/aead/overlapping/array.rs +++ b/src/aead/overlapping/array.rs @@ -14,9 +14,7 @@ #![cfg_attr(not(test), allow(dead_code))] -use super::Overlapping; -use crate::error::LenMismatchError; -use core::array::TryFromSliceError; +use {super::Overlapping, crate::error::LenMismatchError, core::array::TryFromSliceError}; pub struct Array<'o, T, const N: usize> { // Invariant: N != 0. diff --git a/src/aead/overlapping/base.rs b/src/aead/overlapping/base.rs index a71c038f16..de4c5f9b77 100644 --- a/src/aead/overlapping/base.rs +++ b/src/aead/overlapping/base.rs @@ -13,9 +13,11 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. pub use self::index_error::IndexError; -use super::Array; -use crate::error::LenMismatchError; -use core::{mem, ops::RangeFrom}; +use { + super::Array, + crate::error::LenMismatchError, + core::{mem, ops::RangeFrom}, +}; pub struct Overlapping<'o, T> { // Invariant: self.src.start <= in_out.len(). diff --git a/src/aead/overlapping/partial_block.rs b/src/aead/overlapping/partial_block.rs index 9b7864a1e1..ee7a94c171 100644 --- a/src/aead/overlapping/partial_block.rs +++ b/src/aead/overlapping/partial_block.rs @@ -12,8 +12,7 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::Overlapping; -use crate::error::InputTooLongError; +use {super::Overlapping, crate::error::InputTooLongError}; pub struct PartialBlock<'i, T, const BLOCK_LEN: usize> { // invariant: `self.in_out.len() < BLOCK_LEN`. diff --git a/src/aead/poly1305/arm_neon.rs b/src/aead/poly1305/arm_neon.rs index e9d500018f..2b5e7593ff 100644 --- a/src/aead/poly1305/arm_neon.rs +++ b/src/aead/poly1305/arm_neon.rs @@ -18,9 +18,11 @@ #![cfg(all(target_arch = "arm", target_endian = "little"))] -use super::{BLOCK_LEN, Key, Tag}; -use crate::{c, cpu::arm::Neon, polyfill::sliceutil}; -use core::{ffi::c_int, num::Wrapping}; +use { + super::{BLOCK_LEN, Key, Tag}, + crate::{c, cpu::arm::Neon, polyfill::sliceutil}, + core::{ffi::c_int, num::Wrapping}, +}; type W32 = Wrapping; const ZERO: W32 = Wrapping(0); diff --git a/src/aead/poly1305/fallback.rs b/src/aead/poly1305/fallback.rs index 26e5a21ab3..83a9e0c3c3 100644 --- a/src/aead/poly1305/fallback.rs +++ b/src/aead/poly1305/fallback.rs @@ -15,10 +15,11 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{BLOCK_LEN, Key, TAG_LEN, Tag}; -use crate::polyfill::sliceutil; -use core::num::Wrapping; +use { + super::{BLOCK_LEN, Key, TAG_LEN, Tag}, + crate::polyfill::sliceutil, + core::num::Wrapping, +}; type W32 = Wrapping; type W64 = Wrapping; diff --git a/src/aead/poly1305/mod.rs b/src/aead/poly1305/mod.rs index 8b91379949..e7d0d30340 100644 --- a/src/aead/poly1305/mod.rs +++ b/src/aead/poly1305/mod.rs @@ -19,14 +19,15 @@ // TODO: enforce maximum input length. -#[allow(unused_imports)] -use crate::polyfill::prelude::*; - -use super::{TAG_LEN, Tag}; -use crate::cpu; #[cfg(all(target_arch = "arm", target_endian = "little"))] use crate::cpu::GetFeature as _; -use core::slice; +#[allow(unused_imports)] +use crate::polyfill::prelude::*; +use { + super::{TAG_LEN, Tag}, + crate::cpu, + core::slice, +}; mod arm_neon; mod fallback; diff --git a/src/aead/sealing_key.rs b/src/aead/sealing_key.rs index 5b8607b465..693d40f7a1 100644 --- a/src/aead/sealing_key.rs +++ b/src/aead/sealing_key.rs @@ -21,8 +21,10 @@ //! [AEAD]: https://eprint.iacr.org/2000/025.pdf //! [`crypto.cipher.AEAD`]: https://golang.org/pkg/crypto/cipher/#AEAD -use super::{Aad, Algorithm, BoundKey, LessSafeKey, NonceSequence, Tag, UnboundKey}; -use crate::error; +use { + super::{Aad, Algorithm, BoundKey, LessSafeKey, NonceSequence, Tag, UnboundKey}, + crate::error, +}; /// An AEAD key for encrypting and signing ("sealing"), bound to a nonce /// sequence. diff --git a/src/aead/tests/poly1305_tests.rs b/src/aead/tests/poly1305_tests.rs index fa768c50b3..79cd67fb5a 100644 --- a/src/aead/tests/poly1305_tests.rs +++ b/src/aead/tests/poly1305_tests.rs @@ -17,9 +17,10 @@ // (https://github.com/floodyberry/poly1305-donna) and released as public // domain. -use super::super::{Tag, poly1305::*}; -use crate::cpu; -use crate::testutil as test; +use { + super::super::{Tag, poly1305::*}, + crate::{cpu, testutil as test}, +}; // Adapted from BoringSSL's crypto/poly1305/poly1305_test.cc. #[test] diff --git a/src/aead/unbound_key.rs b/src/aead/unbound_key.rs index 23f9df9eb0..b05ff79892 100644 --- a/src/aead/unbound_key.rs +++ b/src/aead/unbound_key.rs @@ -21,8 +21,10 @@ //! [AEAD]: https://eprint.iacr.org/2000/025.pdf //! [`crypto.cipher.AEAD`]: https://golang.org/pkg/crypto/cipher/#AEAD -use super::{Algorithm, LessSafeKey, MAX_KEY_LEN}; -use crate::{cpu, error, hkdf}; +use { + super::{Algorithm, LessSafeKey, MAX_KEY_LEN}, + crate::{cpu, error, hkdf}, +}; /// An AEAD key without a designated role or nonce sequence. pub struct UnboundKey { diff --git a/src/agreement.rs b/src/agreement.rs index 641d6254a9..22a336db9a 100644 --- a/src/agreement.rs +++ b/src/agreement.rs @@ -60,12 +60,11 @@ // The "NSA Guide" steps here are from section 3.1, "Ephemeral Unified // Model." -use crate::{cpu, debug, ec, error, rand}; - pub use crate::ec::{ curve25519::x25519::X25519, suite_b::ecdh::{ECDH_P256, ECDH_P384}, }; +use crate::{cpu, debug, ec, error, rand}; /// A key agreement algorithm. pub struct Algorithm { diff --git a/src/arithmetic/bigint.rs b/src/arithmetic/bigint.rs index 8f6308abb3..616aad137e 100644 --- a/src/arithmetic/bigint.rs +++ b/src/arithmetic/bigint.rs @@ -38,12 +38,13 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use self::boxed_limbs::BoxedLimbs; -use super::{LimbSliceError, MAX_LIMBS, montgomery::*}; -use crate::{ - error::{self, LenMismatchError}, - limb::{self, Limb}, +use { + self::boxed_limbs::BoxedLimbs, + super::{LimbSliceError, MAX_LIMBS, montgomery::*}, + crate::{ + error::{self, LenMismatchError}, + limb::{self, Limb}, + }, }; pub(crate) use { self::{ @@ -106,10 +107,10 @@ fn unwrap_impossible_limb_slice_error(err: LimbSliceError) -> T { #[cfg(test)] mod tests { - use super::*; - use super::{elem::testutil::*, modulus::testutil::*}; - use crate::cpu; - use crate::testutil as test; + use { + super::{elem::testutil::*, modulus::testutil::*, *}, + crate::{cpu, testutil as test}, + }; // Type-level representation of an arbitrary modulus. struct M {} diff --git a/src/arithmetic/bigint/boxed_limbs.rs b/src/arithmetic/bigint/boxed_limbs.rs index c1d0b398f9..cc35a6f622 100644 --- a/src/arithmetic/bigint/boxed_limbs.rs +++ b/src/arithmetic/bigint/boxed_limbs.rs @@ -14,14 +14,15 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use crate::{ - error::LenMismatchError, - limb::{self, Limb}, - polyfill, +use { + crate::{ + error::LenMismatchError, + limb::{self, Limb}, + polyfill, + }, + alloc::{boxed::Box, vec::Vec}, + core::{marker::PhantomData, ptr}, }; -use alloc::{boxed::Box, vec::Vec}; -use core::{marker::PhantomData, ptr}; /// All `BoxedLimbs` are stored in the same number of limbs. pub(super) struct BoxedLimbs { diff --git a/src/arithmetic/bigint/elem.rs b/src/arithmetic/bigint/elem.rs index 90e60a9df6..9e4bcc08e7 100644 --- a/src/arithmetic/bigint/elem.rs +++ b/src/arithmetic/bigint/elem.rs @@ -14,24 +14,25 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - super::{MAX_LIMBS, montgomery::*}, - IntoMont, Mont, Uninit, - boxed_limbs::BoxedLimbs, - unwrap_impossible_len_mismatch_error, unwrap_impossible_limb_slice_error, -}; -use crate::{ - bits::BitLength, - c, cpu, - error::{self, LenMismatchError}, - limb::{self, Limb}, - polyfill::{ - StartMutPtr, - slice::{AliasingSlices, InOut}, +use { + super::{ + super::{MAX_LIMBS, montgomery::*}, + IntoMont, Mont, Uninit, + boxed_limbs::BoxedLimbs, + unwrap_impossible_len_mismatch_error, unwrap_impossible_limb_slice_error, + }, + crate::{ + bits::BitLength, + c, cpu, + error::{self, LenMismatchError}, + limb::{self, Limb}, + polyfill::{ + StartMutPtr, + slice::{AliasingSlices, InOut}, + }, }, + core::{marker::PhantomData, num::NonZero}, }; -use core::{marker::PhantomData, num::NonZero}; /// Elements of ℤ/mℤ for some modulus *m*. // diff --git a/src/arithmetic/bigint/exp.rs b/src/arithmetic/bigint/exp.rs index d0ec40a352..78588627c7 100644 --- a/src/arithmetic/bigint/exp.rs +++ b/src/arithmetic/bigint/exp.rs @@ -38,22 +38,23 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ +use { super::{ - LimbSliceError, limbs512, - montgomery::{RInverse, RRR, Unencoded}, + super::{ + LimbSliceError, limbs512, + montgomery::{RInverse, RRR, Unencoded}, + }, + Elem, IntoMont, Mont, One, PrivateExponent, Uninit, }, - Elem, IntoMont, Mont, One, PrivateExponent, Uninit, -}; -use crate::{ - bits::BitLength, - cpu, - error::LenMismatchError, - limb::{self, LIMB_BITS, Limb}, - window5::Window5, + crate::{ + bits::BitLength, + cpu, + error::LenMismatchError, + limb::{self, LIMB_BITS, Limb}, + window5::Window5, + }, + core::mem::MaybeUninit, }; -use core::mem::MaybeUninit; pub(crate) fn elem_exp_consttime( base: &Elem, @@ -96,8 +97,10 @@ fn elem_exp_consttime_inner( m: &Mont, other_prime_len_bits: BitLength, ) -> Result, LimbSliceError> { - use super::super::montgomery::{R, limbs_mul_mont, limbs_square_mont}; - use crate::{bssl, c, error, polyfill::dynarray}; + use { + super::super::montgomery::{R, limbs_mul_mont, limbs_square_mont}, + crate::{bssl, c, error, polyfill::dynarray}, + }; let base_rinverse: Elem = out.elem_reduce_mont(base_mod_n, m, other_prime_len_bits); @@ -210,24 +213,26 @@ fn elem_exp_consttime_inner( m: &Mont, other_prime_len_bits: BitLength, ) -> Result, LimbSliceError> { - use super::{ + use { super::{ - limbs::x86_64::mont::{ - gather5, mul_mont_gather5_amm, mul_mont5, power5_amm, sqr_mont5, + super::{ + limbs::x86_64::mont::{ + gather5, mul_mont_gather5_amm, mul_mont5, power5_amm, sqr_mont5, + }, + limbs512::scatter::scatter5, + montgomery::N0, }, - limbs512::scatter::scatter5, - montgomery::N0, + elem::from_montgomery_amm, + unwrap_impossible_limb_slice_error, }, - elem::from_montgomery_amm, - unwrap_impossible_limb_slice_error, - }; - use crate::{ - cpu::{ - GetFeature as _, - intel::{Adx, Bmi2}, + crate::{ + cpu::{ + GetFeature as _, + intel::{Adx, Bmi2}, + }, + polyfill::{self, sliceutil::as_chunks_exact}, + window5::LeakyWindow5, }, - polyfill::{self, sliceutil::as_chunks_exact}, - window5::LeakyWindow5, }; let n0 = m.n0(); @@ -370,11 +375,15 @@ fn elem_exp_consttime_inner( #[cfg(test)] mod tests { - use super::super::elem::testutil::*; - use super::super::{PublicModulus, modulus, unwrap_impossible_len_mismatch_error}; - use super::*; - use crate::cpu; - use crate::testutil as test; + use { + super::{ + super::{ + PublicModulus, elem::testutil::*, modulus, unwrap_impossible_len_mismatch_error, + }, + *, + }, + crate::{cpu, testutil as test}, + }; // Type-level representation of an arbitrary modulus. struct M {} diff --git a/src/arithmetic/bigint/modulus/mont.rs b/src/arithmetic/bigint/modulus/mont.rs index c2984eef81..30035faaff 100644 --- a/src/arithmetic/bigint/modulus/mont.rs +++ b/src/arithmetic/bigint/modulus/mont.rs @@ -14,26 +14,26 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ +use { super::{ - super::montgomery::{RR, RRR, Unencoded, limbs_square_mont}, - Elem, N0, One, OversizedUninit, PublicModulus, Uninit, - modulus::value::Value, - unwrap_impossible_limb_slice_error, + super::{ + super::montgomery::{RR, RRR, Unencoded, limbs_square_mont}, + Elem, N0, One, OversizedUninit, PublicModulus, Uninit, + modulus::value::Value, + unwrap_impossible_limb_slice_error, + }, + ValidatedInput, }, - ValidatedInput, -}; -use crate::polyfill::slice::Cursor; -use crate::{ - bits::BitLength, - cpu, - error::{self, LenMismatchError}, - limb::{self, LIMB_BITS, Limb}, - polyfill::{self, LeadingZerosStripped}, + crate::{ + bits::BitLength, + cpu, + error::{self, LenMismatchError}, + limb::{self, LIMB_BITS, Limb}, + polyfill::{self, LeadingZerosStripped, slice::Cursor}, + }, + alloc::boxed::Box, + core::{marker::PhantomData, num::NonZero}, }; -use alloc::boxed::Box; -use core::{marker::PhantomData, num::NonZero}; /// The modulus *m* for a ring ℤ/mℤ, along with the precomputed values needed /// for efficient Montgomery multiplication modulo *m*. The value must be odd diff --git a/src/arithmetic/bigint/modulus/one.rs b/src/arithmetic/bigint/modulus/one.rs index 7af74e194e..cdd5e5b8d6 100644 --- a/src/arithmetic/bigint/modulus/one.rs +++ b/src/arithmetic/bigint/modulus/one.rs @@ -14,17 +14,18 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::super::{ - super::montgomery::{R, RR, limbs_square_mont}, - Limb, Mont, unwrap_impossible_len_mismatch_error, unwrap_impossible_limb_slice_error, -}; -use crate::{ - error::LenMismatchError, - limb::{self, LIMB_BITS}, - polyfill::slice::Cursor, +use { + super::super::{ + super::montgomery::{R, RR, limbs_square_mont}, + Limb, Mont, unwrap_impossible_len_mismatch_error, unwrap_impossible_limb_slice_error, + }, + crate::{ + error::LenMismatchError, + limb::{self, LIMB_BITS}, + polyfill::slice::Cursor, + }, + core::{marker::PhantomData, mem::size_of}, }; -use core::{marker::PhantomData, mem::size_of}; // The value 1, Montgomery-encoded some number of times. pub struct One<'a, M, E> { diff --git a/src/arithmetic/bigint/modulus/testutil.rs b/src/arithmetic/bigint/modulus/testutil.rs index 2b8367ad08..894989043c 100644 --- a/src/arithmetic/bigint/modulus/testutil.rs +++ b/src/arithmetic/bigint/modulus/testutil.rs @@ -1,7 +1,10 @@ -use super::super::super::montgomery::RR; -use super::*; -use crate::cpu; -use crate::error::{self, KeyRejected}; +use { + super::{super::super::montgomery::RR, *}, + crate::{ + cpu, + error::{self, KeyRejected}, + }, +}; pub fn consume_modulus( test_case: &mut crate::testutil::TestCase, diff --git a/src/arithmetic/bigint/modulus/value.rs b/src/arithmetic/bigint/modulus/value.rs index a33aae639b..57d7bc3af4 100644 --- a/src/arithmetic/bigint/modulus/value.rs +++ b/src/arithmetic/bigint/modulus/value.rs @@ -12,16 +12,17 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::super::super::{MAX_LIMBS, MIN_LIMBS}; -use crate::{ - bb, - bits::{BitLength, FromByteLen as _}, - error::{self, InputTooLongError, LenMismatchError}, - limb, - limb::{LIMB_BITS, LIMB_BYTES, Limb}, - polyfill::usize_from_u32, +use { + super::super::super::{MAX_LIMBS, MIN_LIMBS}, + crate::{ + bb, + bits::{BitLength, FromByteLen as _}, + error::{self, InputTooLongError, LenMismatchError}, + limb::{self, LIMB_BITS, LIMB_BYTES, Limb}, + polyfill::usize_from_u32, + }, + core::marker::PhantomData, }; -use core::marker::PhantomData; /// `OwnedModulus`, without the overhead of Montgomery multiplication support. pub(crate) struct Value<'a, M> { diff --git a/src/arithmetic/bigint/oversized_uninit.rs b/src/arithmetic/bigint/oversized_uninit.rs index b6baaa1d29..f779a98e9f 100644 --- a/src/arithmetic/bigint/oversized_uninit.rs +++ b/src/arithmetic/bigint/oversized_uninit.rs @@ -14,10 +14,11 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{Limb, MAX_LIMBS}; -use crate::polyfill; -use core::mem::MaybeUninit; +use { + super::{Limb, MAX_LIMBS}, + crate::polyfill, + core::mem::MaybeUninit, +}; /// A buffer that has enough space to hold `N` values of the maximum size, /// hiding the representation of values from the user. diff --git a/src/arithmetic/bigint/private_exponent.rs b/src/arithmetic/bigint/private_exponent.rs index 755acd1aa9..7c5dfe51b6 100644 --- a/src/arithmetic/bigint/private_exponent.rs +++ b/src/arithmetic/bigint/private_exponent.rs @@ -12,9 +12,11 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{Limb, Mont, limb}; -use crate::error; -use alloc::boxed::Box; +use { + super::{Limb, Mont, limb}, + crate::error, + alloc::boxed::Box, +}; pub struct PrivateExponent { // Unlike most `[Limb]` we deal with, these are stored most significant @@ -56,8 +58,10 @@ impl PrivateExponent { input: untrusted::Input, p: &Mont, ) -> Result { - use super::boxed_limbs::Uninit; - use crate::{error::LenMismatchError, limb::LIMB_BYTES}; + use { + super::boxed_limbs::Uninit, + crate::{error::LenMismatchError, limb::LIMB_BYTES}, + }; // Do exactly what `from_be_bytes_padded` does for any inputs it accepts. if let r @ Ok(_) = Self::from_be_bytes_padded(input, p) { diff --git a/src/arithmetic/constant.rs b/src/arithmetic/constant.rs index 81d61ea9a7..eb6d275c5a 100644 --- a/src/arithmetic/constant.rs +++ b/src/arithmetic/constant.rs @@ -1,5 +1,4 @@ -use crate::limb::LeakyLimb; -use core::mem::size_of; +use {crate::limb::LeakyLimb, core::mem::size_of}; const fn parse_digit(d: u8) -> u8 { match d.to_ascii_lowercase() { diff --git a/src/arithmetic/exp_vartime.rs b/src/arithmetic/exp_vartime.rs index a1327ed706..0d7cb4c577 100644 --- a/src/arithmetic/exp_vartime.rs +++ b/src/arithmetic/exp_vartime.rs @@ -12,11 +12,13 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{ - bigint::{Elem, Mont, Uninit}, - montgomery::R, +use { + super::{ + bigint::{Elem, Mont, Uninit}, + montgomery::R, + }, + core::num::NonZero, }; -use core::num::NonZero; /// Calculates base**exponent (mod m). /// diff --git a/src/arithmetic/ffi.rs b/src/arithmetic/ffi.rs index fc2de9a5fd..4cc3d39b50 100644 --- a/src/arithmetic/ffi.rs +++ b/src/arithmetic/ffi.rs @@ -12,13 +12,15 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{LimbSliceError, MAX_LIMBS, MIN_LIMBS, n0::N0}; -use crate::{ - c, - limb::{LIMB_BITS, Limb}, - polyfill::{StartMutPtr, slice::AliasingSlices, usize_from_u32}, +use { + super::{LimbSliceError, MAX_LIMBS, MIN_LIMBS, n0::N0}, + crate::{ + c, + limb::{LIMB_BITS, Limb}, + polyfill::{StartMutPtr, slice::AliasingSlices, usize_from_u32}, + }, + core::{mem::size_of, num::NonZero}, }; -use core::{mem::size_of, num::NonZero}; const _MIN_LIMBS_ADDRESSES_MEMORY_SAFETY_ISSUES: () = { // The x86 implementation of `bn_mul_mont_sse2` requires at least 4 @@ -47,8 +49,10 @@ const _MAX_LIMBS_ADDRESSES_MEMORY_SAFETY_ISSUES: () = { macro_rules! bn_mul_mont_ffi { ( $in_out:expr, $n:expr, $n0:expr, $cpu:expr, unsafe { ($MIN_LEN:expr, $MOD_LEN:expr, $Cpu:ty) => $f:ident }) => {{ - use crate::{c, limb::Limb}; - use core::num::NonZero; + use { + crate::{c, limb::Limb}, + core::num::NonZero, + }; prefixed_extern! { // `r` and/or 'a' and/or 'b' may alias. unsafe fn $f( diff --git a/src/arithmetic/limbs/aarch64/mont.rs b/src/arithmetic/limbs/aarch64/mont.rs index c43bc91df8..08ffbe2296 100644 --- a/src/arithmetic/limbs/aarch64/mont.rs +++ b/src/arithmetic/limbs/aarch64/mont.rs @@ -16,14 +16,15 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::super::super::{LimbSliceError, MAX_LIMBS, MIN_LIMBS, n0::N0}; -use crate::{ - c, - limb::{LIMB_BYTES, Limb}, - polyfill::{StartMutPtr, slice::AliasingSlices}, +use { + super::super::super::{LimbSliceError, MAX_LIMBS, MIN_LIMBS, n0::N0}, + crate::{ + c, + limb::{LIMB_BYTES, Limb}, + polyfill::{StartMutPtr, slice::AliasingSlices}, + }, + core::num::NonZero, }; -use core::num::NonZero; // On Windows, at least, if a function stack allocates 4KB then it // must call `__chkstk` or do equivalent work. We check 3KB instead so diff --git a/src/arithmetic/limbs/fallback/mont.rs b/src/arithmetic/limbs/fallback/mont.rs index eae2358470..7ce91345c7 100644 --- a/src/arithmetic/limbs/fallback/mont.rs +++ b/src/arithmetic/limbs/fallback/mont.rs @@ -14,20 +14,21 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::super::super::{ - LimbSliceError, MAX_LIMBS, MIN_LIMBS, - ffi::bn_mul_mont_ffi, - montgomery::{N0, limbs_from_mont_in_place}, -}; -use crate::{ - c, - error::LenMismatchError, - limb::Limb, - polyfill::slice::{AliasedUninit, AliasingSlices}, +use { + super::super::super::{ + LimbSliceError, MAX_LIMBS, MIN_LIMBS, + ffi::bn_mul_mont_ffi, + montgomery::{N0, limbs_from_mont_in_place}, + }, + crate::{ + c, + error::LenMismatchError, + limb::Limb, + polyfill::slice::{AliasedUninit, AliasingSlices}, + }, + cfg_if::cfg_if, + core::{hint::unreachable_unchecked, num::NonZero}, }; -use cfg_if::cfg_if; -use core::{hint::unreachable_unchecked, num::NonZero}; #[allow(dead_code)] #[inline] @@ -127,8 +128,7 @@ prefixed_extern! { #[cfg(test)] mod tests { - use super::super::super::super::MAX_LIMBS; - use super::*; + use super::{super::super::super::MAX_LIMBS, *}; #[test] // TODO: wasm diff --git a/src/arithmetic/limbs/x86_64/mont.rs b/src/arithmetic/limbs/x86_64/mont.rs index 63251c7925..701df2ce45 100644 --- a/src/arithmetic/limbs/x86_64/mont.rs +++ b/src/arithmetic/limbs/x86_64/mont.rs @@ -16,23 +16,25 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use crate::polyfill::{self, SmallerChunks, StartMutPtr, slice::Uninit}; - -use super::super::super::{ - LimbSliceError, MAX_LIMBS, - limbs512::storage::{check_common, check_common_with_n}, - n0::N0, -}; -use crate::{ - c, - cpu::intel::{Adx, Bmi1, Bmi2}, - error::LenMismatchError, - limb::Limb, - polyfill::slice::AliasingSlices, - window5::Window5, +use { + super::super::super::{ + LimbSliceError, MAX_LIMBS, + limbs512::storage::{check_common, check_common_with_n}, + n0::N0, + }, + crate::{ + c, + cpu::intel::{Adx, Bmi1, Bmi2}, + error::LenMismatchError, + limb::Limb, + polyfill::{ + self, SmallerChunks, StartMutPtr, + slice::{AliasingSlices, Uninit}, + }, + window5::Window5, + }, + core::{mem::MaybeUninit, num::NonZero}, }; -use core::{mem::MaybeUninit, num::NonZero}; const _512_IS_LIMB_BITS_TIMES_8: () = assert!(8 * Limb::BITS == 512); diff --git a/src/arithmetic/limbs512/mod.rs b/src/arithmetic/limbs512/mod.rs index d0000d08ec..8b4a53c42c 100644 --- a/src/arithmetic/limbs512/mod.rs +++ b/src/arithmetic/limbs512/mod.rs @@ -12,8 +12,7 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::limb::LIMB_BITS; -use cfg_if::cfg_if; +use {crate::limb::LIMB_BITS, cfg_if::cfg_if}; cfg_if! { if #[cfg(target_arch = "x86_64")] { diff --git a/src/arithmetic/limbs512/scatter.rs b/src/arithmetic/limbs512/scatter.rs index 362d593169..3ba3946e6f 100644 --- a/src/arithmetic/limbs512/scatter.rs +++ b/src/arithmetic/limbs512/scatter.rs @@ -1,9 +1,10 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{super::LimbSliceError, LIMBS_PER_CHUNK}; -use crate::{limb::Limb, polyfill, window5::LeakyWindow5}; -use core::mem::MaybeUninit; +use { + super::{super::LimbSliceError, LIMBS_PER_CHUNK}, + crate::{limb::Limb, polyfill, window5::LeakyWindow5}, + core::mem::MaybeUninit, +}; // `a` is the `i`th entry to store into `table`, where `i` is NOT secret. // `table` has space for 32 entries the same size as `a`. Instead of storing diff --git a/src/arithmetic/limbs512/storage.rs b/src/arithmetic/limbs512/storage.rs index cb34282eef..37d487aac5 100644 --- a/src/arithmetic/limbs512/storage.rs +++ b/src/arithmetic/limbs512/storage.rs @@ -14,17 +14,18 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::LIMBS_PER_CHUNK; -use crate::{ - arithmetic::{LimbSliceError, MAX_LIMBS}, - error::LenMismatchError, - limb::Limb, - polyfill::StartPtr, -}; -use core::{ - mem::{MaybeUninit, align_of, size_of}, - num::NonZero, +use { + super::LIMBS_PER_CHUNK, + crate::{ + arithmetic::{LimbSliceError, MAX_LIMBS}, + error::LenMismatchError, + limb::Limb, + polyfill::StartPtr, + }, + core::{ + mem::{MaybeUninit, align_of, size_of}, + num::NonZero, + }, }; // Some x86_64 assembly is written under the assumption that some of its // input data and/or temporary storage is aligned to `MOD_EXP_CTIME_ALIGN` diff --git a/src/arithmetic/montgomery.rs b/src/arithmetic/montgomery.rs index 0e79e3b13a..d92a4de3d0 100644 --- a/src/arithmetic/montgomery.rs +++ b/src/arithmetic/montgomery.rs @@ -12,18 +12,19 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -#[allow(unused_imports)] -use crate::polyfill::prelude::*; - -use super::LimbSliceError; #[allow(unused_imports)] use super::MIN_LIMBS; pub use super::n0::N0; -use crate::{ - cpu, - polyfill::slice::{AliasSrc, AliasingSlices}, +#[allow(unused_imports)] +use crate::polyfill::prelude::*; +use { + super::LimbSliceError, + crate::{ + cpu, + polyfill::slice::{AliasSrc, AliasingSlices}, + }, + cfg_if::cfg_if, }; -use cfg_if::cfg_if; // Indicates that the element is not encoded; there is no *R* factor // that needs to be canceled out. @@ -241,8 +242,7 @@ where #[cfg(target_arch = "x86_64")] { - use super::limbs::x86_64; - use crate::cpu::GetFeature as _; + use {super::limbs::x86_64, crate::cpu::GetFeature as _}; if let (n, []) = n.as_chunks() { return x86_64::mont::sqr_mont5(in_out, n, n0, cpu.get_feature()); } diff --git a/src/bb/boolmask.rs b/src/bb/boolmask.rs index 7018a4bc22..efec2e6cf3 100644 --- a/src/bb/boolmask.rs +++ b/src/bb/boolmask.rs @@ -12,8 +12,10 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::Word; -use core::{hint, ops}; +use { + super::Word, + core::{hint, ops}, +}; // BoolMask is either `BoolMask::TRUE` or `BoolMask::FALSE`. #[repr(transparent)] diff --git a/src/bb/bytes.rs b/src/bb/bytes.rs index 73564019d0..6d6b849511 100644 --- a/src/bb/bytes.rs +++ b/src/bb/bytes.rs @@ -16,9 +16,10 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{BoolMask, LeakyWord, Word, WordOps}; -use crate::{bits::BitLength, error, polyfill::usize_from_u32}; +use { + super::{BoolMask, LeakyWord, Word, WordOps}, + crate::{bits::BitLength, error, polyfill::usize_from_u32}, +}; pub fn byte_leading_zeros_vartime(a: &u8) -> BitLength { BitLength::from_bits(usize_from_u32(a.leading_zeros())) diff --git a/src/bssl.rs b/src/bssl.rs index 1b1c753784..485470e170 100644 --- a/src/bssl.rs +++ b/src/bssl.rs @@ -12,8 +12,7 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::error; -use core::ffi::c_int; +use {crate::error, core::ffi::c_int}; /// An `int` returned from a foreign function containing **1** if the function /// was successful or **0** if an error occurred. This is the convention used by @@ -37,10 +36,12 @@ impl From for core::result::Result<(), error::Unspecified> { #[cfg(test)] mod tests { mod result { - use crate::bssl; - use core::{ - ffi::c_int, - mem::{align_of, size_of}, + use { + crate::bssl, + core::{ + ffi::c_int, + mem::{align_of, size_of}, + }, }; #[test] diff --git a/src/cpu/aarch64/darwin.rs b/src/cpu/aarch64/darwin.rs index 5a34e26534..6cd55a0819 100644 --- a/src/cpu/aarch64/darwin.rs +++ b/src/cpu/aarch64/darwin.rs @@ -57,8 +57,10 @@ const _AARCH64_APPLE_DARWIN_TARGETS_EXPECTED_FEATURES: () = pub fn detect_features() -> u32 { #[cfg(all(target_pointer_width = "64", not(target_os = "watchos")))] fn detect_feature(name: &CStr) -> bool { - use core::{mem::size_of_val, ptr}; - use libc::{c_int, c_void}; + use { + core::{mem::size_of_val, ptr}, + libc::{c_int, c_void}, + }; let mut value: c_int = 0; let mut len = size_of_val(&value); @@ -98,9 +100,10 @@ pub fn detect_features() -> u32 { #[cfg(test)] mod tests { - use super::super::Sha512; - use super::*; - use crate::cpu::{self, GetFeature}; + use { + super::{super::Sha512, *}, + crate::cpu::{self, GetFeature}, + }; #[test] fn sha512_detection() { diff --git a/src/cpu/aarch64/linux.rs b/src/cpu/aarch64/linux.rs index e8b37daf88..7cf58a4be9 100644 --- a/src/cpu/aarch64/linux.rs +++ b/src/cpu/aarch64/linux.rs @@ -36,8 +36,10 @@ use super::Neon; pub const FORCE_DYNAMIC_DETECTION: u32 = !Neon::mask(); pub fn detect_features() -> u32 { - use super::{Aes, CAPS_STATIC, PMull, Sha256, Sha512}; - use libc::{AT_HWCAP, HWCAP_AES, HWCAP_PMULL, HWCAP_SHA2, HWCAP_SHA512, getauxval}; + use { + super::{Aes, CAPS_STATIC, PMull, Sha256, Sha512}, + libc::{AT_HWCAP, HWCAP_AES, HWCAP_PMULL, HWCAP_SHA2, HWCAP_SHA512, getauxval}, + }; let mut features = 0; diff --git a/src/cpu/aarch64/mod.rs b/src/cpu/aarch64/mod.rs index 167667453b..5ae8cc49f5 100644 --- a/src/cpu/aarch64/mod.rs +++ b/src/cpu/aarch64/mod.rs @@ -92,9 +92,11 @@ impl_get_feature! { pub(super) mod featureflags { pub(in super::super) use super::detect::FORCE_DYNAMIC_DETECTION; - use super::*; - use crate::{cpu, polyfill::once_cell::race}; - use core::num::NonZero; + use { + super::*, + crate::{cpu, polyfill::once_cell::race}, + core::num::NonZero, + }; pub(in super::super) fn get_or_init() -> cpu::Features { fn init() -> NonZero { diff --git a/src/cpu/aarch64/windows.rs b/src/cpu/aarch64/windows.rs index bce30f136c..eb6195cb99 100644 --- a/src/cpu/aarch64/windows.rs +++ b/src/cpu/aarch64/windows.rs @@ -12,9 +12,11 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{Aes, CAPS_STATIC, Neon, PMull, Sha256}; -use windows_sys::Win32::System::Threading::{ - IsProcessorFeaturePresent, PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE, +use { + super::{Aes, CAPS_STATIC, Neon, PMull, Sha256}, + windows_sys::Win32::System::Threading::{ + IsProcessorFeaturePresent, PF_ARM_V8_CRYPTO_INSTRUCTIONS_AVAILABLE, + }, }; pub const FORCE_DYNAMIC_DETECTION: u32 = 0; diff --git a/src/cpu/arm/linux.rs b/src/cpu/arm/linux.rs index deda9cc9f8..92f46c44f6 100644 --- a/src/cpu/arm/linux.rs +++ b/src/cpu/arm/linux.rs @@ -46,8 +46,10 @@ pub fn detect_features() -> u32 { // rely only on static feature detection. #[cfg(not(target_env = "uclibc"))] { - use super::CAPS_STATIC; - use libc::{AT_HWCAP, c_ulong, getauxval}; + use { + super::CAPS_STATIC, + libc::{AT_HWCAP, c_ulong, getauxval}, + }; const HWCAP_NEON: c_ulong = 1 << 12; diff --git a/src/cpu/arm/mod.rs b/src/cpu/arm/mod.rs index 6f65454668..663d17212c 100644 --- a/src/cpu/arm/mod.rs +++ b/src/cpu/arm/mod.rs @@ -47,9 +47,11 @@ impl_get_feature! { pub(super) mod featureflags { pub(in super::super) use super::detect::FORCE_DYNAMIC_DETECTION; - use super::*; - use crate::{cpu, polyfill::once_cell::race}; - use core::num::NonZero; + use { + super::*, + crate::{cpu, polyfill::once_cell::race}, + core::num::NonZero, + }; pub(in super::super) fn get_or_init() -> cpu::Features { fn init() -> NonZero { diff --git a/src/cpu/x86.rs b/src/cpu/x86.rs index 37b789c7c0..626e099a17 100644 --- a/src/cpu/x86.rs +++ b/src/cpu/x86.rs @@ -38,9 +38,11 @@ mod abi_assumptions { } pub(super) mod featureflags { - use super::{super::CAPS_STATIC, *}; - use crate::{cpu, polyfill::once_cell::race}; - use core::num::NonZero; + use { + super::{super::CAPS_STATIC, *}, + crate::{cpu, polyfill::once_cell::race}, + core::num::NonZero, + }; pub(in super::super) fn get_or_init() -> cpu::Features { let _: NonZero = FEATURES.get_or_init(|| { @@ -222,8 +224,10 @@ mod tests { // This should always pass on any x86 system except very, very, old ones. #[test] fn x86_has_sse2() { - use super::*; - use crate::cpu::{self, GetFeature as _}; + use { + super::*, + crate::cpu::{self, GetFeature as _}, + }; assert!(matches!(cpu::features().get_feature(), Some(Sse2 { .. }))) } } diff --git a/src/cpu/x86_64.rs b/src/cpu/x86_64.rs index b25d0867ab..e13d5baa20 100644 --- a/src/cpu/x86_64.rs +++ b/src/cpu/x86_64.rs @@ -38,9 +38,11 @@ mod abi_assumptions { } pub(super) mod featureflags { - use super::{super::CAPS_STATIC, *}; - use crate::{cpu, polyfill::once_cell::race}; - use core::num::NonZero; + use { + super::{super::CAPS_STATIC, *}, + crate::{cpu, polyfill::once_cell::race}, + core::num::NonZero, + }; pub(in super::super) fn get_or_init() -> cpu::Features { let _: NonZero = FEATURES.get_or_init(|| { diff --git a/src/deprecated_test.rs b/src/deprecated_test.rs index 026e9fcbbf..4b9a1464c2 100644 --- a/src/deprecated_test.rs +++ b/src/deprecated_test.rs @@ -25,14 +25,13 @@ macro_rules! test_file { }; } +#[cfg(feature = "std")] +pub use crate::testutil::compile_time_assert_std_error_error; pub use crate::testutil::{ File, TestCase, compile_time_assert_clone, compile_time_assert_copy, compile_time_assert_eq, compile_time_assert_send, compile_time_assert_sync, from_hex, run, }; -#[cfg(feature = "std")] -pub use crate::testutil::compile_time_assert_std_error_error; - #[deprecated(note = "internal API that will be removed")] #[doc(hidden)] pub mod rand { diff --git a/src/digest/dynstate.rs b/src/digest/dynstate.rs index 95fc083636..3f48ce9ca7 100644 --- a/src/digest/dynstate.rs +++ b/src/digest/dynstate.rs @@ -14,10 +14,11 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{Algorithm, Output, format_output, sha1, sha2}; -use crate::cpu; -use core::mem::size_of; +use { + super::{Algorithm, Output, format_output, sha1, sha2}, + crate::cpu, + core::mem::size_of, +}; pub(super) enum DynInitialState { As64(sha2::State64), diff --git a/src/digest/mod.rs b/src/digest/mod.rs index f5c4c1e111..5496fc5d26 100644 --- a/src/digest/mod.rs +++ b/src/digest/mod.rs @@ -18,25 +18,25 @@ //! function should be used. Otherwise, the digest can be calculated in //! multiple steps using `Context`. +pub(crate) use self::finish_error::FinishError; #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use self::{ - dynstate::{DynInitialState, DynState}, - sha2::{SHA256_BLOCK_LEN, SHA512_BLOCK_LEN}, -}; -use crate::{ - bits::{BitLength, FromByteLen as _}, - cpu, debug, error, - polyfill::{ - self, - partial_buffer::{PartialBuffer, PurportedLen}, - sliceutil, +use { + self::{ + dynstate::{DynInitialState, DynState}, + sha2::{SHA256_BLOCK_LEN, SHA512_BLOCK_LEN}, }, + crate::{ + bits::{BitLength, FromByteLen as _}, + cpu, debug, error, + polyfill::{ + self, + partial_buffer::{PartialBuffer, PurportedLen}, + sliceutil, + }, + }, + core::num::Wrapping, }; -use core::num::Wrapping; - -pub(crate) use self::finish_error::FinishError; mod dynstate; mod sha1; @@ -620,9 +620,7 @@ impl OutputLen { mod tests { mod max_input { extern crate alloc; - use super::super::super::digest; - use crate::polyfill::u64_from_usize; - use alloc::vec; + use {super::super::super::digest, crate::polyfill::u64_from_usize, alloc::vec}; macro_rules! max_input_tests { ( $algorithm_name:ident ) => { diff --git a/src/digest/sha1.rs b/src/digest/sha1.rs index 67fcfca4f7..83702b295f 100644 --- a/src/digest/sha1.rs +++ b/src/digest/sha1.rs @@ -15,15 +15,16 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - BlockLen, OutputLen, - sha2::{ - State32, - fallback::{Word, ch, maj}, +use { + super::{ + BlockLen, OutputLen, + sha2::{ + State32, + fallback::{Word, ch, maj}, + }, }, + core::{mem::size_of, num::Wrapping}, }; -use core::{mem::size_of, num::Wrapping}; pub(super) const BLOCK_LEN: BlockLen = BlockLen::_512; pub const CHAINING_LEN: usize = 160 / 8; diff --git a/src/digest/sha2/fallback.rs b/src/digest/sha2/fallback.rs index 83629a84f9..82d218eee9 100644 --- a/src/digest/sha2/fallback.rs +++ b/src/digest/sha2/fallback.rs @@ -14,11 +14,12 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::CHAINING_WORDS; -use core::{ - num::Wrapping, - ops::{Add, AddAssign, BitAnd, BitOr, BitXor, Not, Shr}, +use { + super::CHAINING_WORDS, + core::{ + num::Wrapping, + ops::{Add, AddAssign, BitAnd, BitOr, BitXor, Not, Shr}, + }, }; #[cfg_attr( diff --git a/src/digest/sha2/ffi.rs b/src/digest/sha2/ffi.rs index 4d7cd36b14..4ff9629215 100644 --- a/src/digest/sha2/ffi.rs +++ b/src/digest/sha2/ffi.rs @@ -12,9 +12,11 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::CHAINING_WORDS; -use crate::c; -use core::num::{NonZero, Wrapping}; +use { + super::CHAINING_WORDS, + crate::c, + core::num::{NonZero, Wrapping}, +}; /// `unsafe { T => f }` means it is safe to call `f` iff we can construct /// a value of type `T`. diff --git a/src/digest/sha2/mod.rs b/src/digest/sha2/mod.rs index 3f78dac1a1..090a3ec4b1 100644 --- a/src/digest/sha2/mod.rs +++ b/src/digest/sha2/mod.rs @@ -12,12 +12,11 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::BlockLen; - pub(super) use self::{ sha2_32::{SHA256_BLOCK_LEN, State32, block_data_order_32}, sha2_64::{SHA512_BLOCK_LEN, State64, block_data_order_64}, }; +use super::BlockLen; pub(super) const CHAINING_WORDS: usize = 8; diff --git a/src/digest/sha2/sha2_32.rs b/src/digest/sha2/sha2_32.rs index 394d0387af..af76de80b4 100644 --- a/src/digest/sha2/sha2_32.rs +++ b/src/digest/sha2/sha2_32.rs @@ -12,10 +12,12 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{BlockLen, CHAINING_WORDS}; -use crate::cpu; -use cfg_if::cfg_if; -use core::num::Wrapping; +use { + super::{BlockLen, CHAINING_WORDS}, + crate::cpu, + cfg_if::cfg_if, + core::num::Wrapping, +}; pub(in super::super) const SHA256_BLOCK_LEN: BlockLen = BlockLen::_512; diff --git a/src/digest/sha2/sha2_64.rs b/src/digest/sha2/sha2_64.rs index a150741668..cc01b43b65 100644 --- a/src/digest/sha2/sha2_64.rs +++ b/src/digest/sha2/sha2_64.rs @@ -12,10 +12,12 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{BlockLen, CHAINING_WORDS}; -use crate::cpu; -use cfg_if::cfg_if; -use core::num::Wrapping; +use { + super::{BlockLen, CHAINING_WORDS}, + crate::cpu, + cfg_if::cfg_if, + core::num::Wrapping, +}; pub(in super::super) const SHA512_BLOCK_LEN: BlockLen = BlockLen::_1024; diff --git a/src/ec/curve25519/adx.rs b/src/ec/curve25519/adx.rs index 5f49d6c2d6..01c2d81176 100644 --- a/src/ec/curve25519/adx.rs +++ b/src/ec/curve25519/adx.rs @@ -12,12 +12,14 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::ops::{P3, Scalar}; -use crate::cpu::{ - self, GetFeature as _, - intel::{Adx, Bmi1, Bmi2}, +use { + super::ops::{P3, Scalar}, + crate::cpu::{ + self, GetFeature as _, + intel::{Adx, Bmi1, Bmi2}, + }, + core::mem::MaybeUninit, }; -use core::mem::MaybeUninit; pub type RequiredFeatures = (Adx, Bmi1, Bmi2); diff --git a/src/ec/curve25519/ed25519/mod.rs b/src/ec/curve25519/ed25519/mod.rs index fe1a9ff607..39e62df5e2 100644 --- a/src/ec/curve25519/ed25519/mod.rs +++ b/src/ec/curve25519/ed25519/mod.rs @@ -14,8 +14,7 @@ //! EdDSA Signatures. -use super::ops::ELEM_LEN; -use crate::digest; +use {super::ops::ELEM_LEN, crate::digest}; pub mod signing; pub mod verification; diff --git a/src/ec/curve25519/ed25519/signing.rs b/src/ec/curve25519/ed25519/signing.rs index 0ae8297cc5..b99be2bf09 100644 --- a/src/ec/curve25519/ed25519/signing.rs +++ b/src/ec/curve25519/ed25519/signing.rs @@ -14,12 +14,14 @@ //! EdDSA Signatures. -use super::{super::ops::*, eddsa_digest}; -use crate::{ - cpu, digest, error, - io::der, - pkcs8, rand, - signature::{self, KeyPair as SigningKeyPair}, +use { + super::{super::ops::*, eddsa_digest}, + crate::{ + cpu, digest, error, + io::der, + pkcs8, rand, + signature::{self, KeyPair as SigningKeyPair}, + }, }; /// An Ed25519 key pair, for signing. diff --git a/src/ec/curve25519/ed25519/verification.rs b/src/ec/curve25519/ed25519/verification.rs index 9fc814a820..e74fc07037 100644 --- a/src/ec/curve25519/ed25519/verification.rs +++ b/src/ec/curve25519/ed25519/verification.rs @@ -14,9 +14,11 @@ //! EdDSA Signatures. -use super::{super::ops::*, eddsa_digest}; -use crate::{bssl, cpu, error, sealed, signature}; -use core::mem::MaybeUninit; +use { + super::{super::ops::*, eddsa_digest}, + crate::{bssl, cpu, error, sealed, signature}, + core::mem::MaybeUninit, +}; /// Parameters for EdDSA signing and verification. pub struct EdDSAParameters; diff --git a/src/ec/curve25519/ops.rs b/src/ec/curve25519/ops.rs index f6dc98fdec..fc2fb39e4f 100644 --- a/src/ec/curve25519/ops.rs +++ b/src/ec/curve25519/ops.rs @@ -16,11 +16,13 @@ //! and Edwards25519. pub use super::scalar::{MaskedScalar, SCALAR_LEN, Scalar}; -use crate::{ - cpu, - limb::{LIMB_BITS, Limb}, +use { + crate::{ + cpu, + limb::{LIMB_BITS, Limb}, + }, + core::{marker::PhantomData, mem::MaybeUninit}, }; -use core::{marker::PhantomData, mem::MaybeUninit}; // Elem` is `fe` in curve25519/internal.h. // Elem is `fe_loose` in curve25519/internal.h. diff --git a/src/ec/curve25519/scalar.rs b/src/ec/curve25519/scalar.rs index 5045a9109c..895d340180 100644 --- a/src/ec/curve25519/scalar.rs +++ b/src/ec/curve25519/scalar.rs @@ -14,9 +14,10 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use crate::{arithmetic::limbs_from_hex, digest, error, limb}; -use core::array; +use { + crate::{arithmetic::limbs_from_hex, digest, error, limb}, + core::array, +}; #[repr(transparent)] pub struct Scalar([u8; SCALAR_LEN]); diff --git a/src/ec/curve25519/x25519.rs b/src/ec/curve25519/x25519.rs index ee82d86de6..66adf48df2 100644 --- a/src/ec/curve25519/x25519.rs +++ b/src/ec/curve25519/x25519.rs @@ -14,11 +14,13 @@ //! X25519 Key agreement. -use super::{ - ops::{ELEM_LEN, MaskedScalar, P3}, - scalar::SCALAR_LEN, +use { + super::{ + ops::{ELEM_LEN, MaskedScalar, P3}, + scalar::SCALAR_LEN, + }, + crate::{agreement, bb, cpu, ec, error, rand}, }; -use crate::{agreement, bb, cpu, ec, error, rand}; static CURVE25519: ec::Curve = ec::Curve { public_key_len: PUBLIC_KEY_LEN, @@ -192,9 +194,7 @@ const SHARED_SECRET_LEN: usize = ELEM_AND_SCALAR_LEN; #[cfg(test)] mod tests { - use super::*; - use crate::ec; - use untrusted::Input; + use {super::*, crate::ec, untrusted::Input}; #[test] fn test_x25519_public_from_private() { diff --git a/src/ec/keys.rs b/src/ec/keys.rs index 6cf925035b..ba719df8f2 100644 --- a/src/ec/keys.rs +++ b/src/ec/keys.rs @@ -1,5 +1,7 @@ -use super::{Curve, ELEM_MAX_BYTES, SEED_MAX_BYTES}; -use crate::{cpu, error, rand}; +use { + super::{Curve, ELEM_MAX_BYTES, SEED_MAX_BYTES}, + crate::{cpu, error, rand}, +}; pub struct KeyPair { seed: Seed, diff --git a/src/ec/mod.rs b/src/ec/mod.rs index 455144a94d..0d62e2087b 100644 --- a/src/ec/mod.rs +++ b/src/ec/mod.rs @@ -12,9 +12,8 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::{cpu, error, rand}; - pub use self::keys::{KeyPair, PublicKey, Seed}; +use crate::{cpu, error, rand}; pub struct Curve { pub public_key_len: usize, diff --git a/src/ec/suite_b/ecdh.rs b/src/ec/suite_b/ecdh.rs index 59b4374b8f..849628f748 100644 --- a/src/ec/suite_b/ecdh.rs +++ b/src/ec/suite_b/ecdh.rs @@ -14,8 +14,10 @@ //! ECDH key agreement using the P-256 and P-384 curves. -use super::{ops::*, private_key::*, public_key::*}; -use crate::{agreement, cpu, ec, error}; +use { + super::{ops::*, private_key::*, public_key::*}, + crate::{agreement, cpu, ec, error}, +}; /// A key agreement algorithm. macro_rules! ecdh { @@ -146,9 +148,10 @@ fn ecdh( #[cfg(test)] mod tests { - use super::super::ops; - use crate::testutil as test; - use crate::{agreement, ec, limb}; + use { + super::super::ops, + crate::{agreement, ec, limb, testutil as test}, + }; static SUPPORTED_SUITE_B_ALGS: [(&str, &agreement::Algorithm, &ec::Curve, &ops::CommonOps); 2] = [ ( diff --git a/src/ec/suite_b/ecdsa/digest_scalar.rs b/src/ec/suite_b/ecdsa/digest_scalar.rs index f35dc66ce4..ae00ddffac 100644 --- a/src/ec/suite_b/ecdsa/digest_scalar.rs +++ b/src/ec/suite_b/ecdsa/digest_scalar.rs @@ -67,9 +67,10 @@ fn digest_scalar_(n: &Modulus, digest: &[u8]) -> Scalar { #[cfg(test)] mod tests { - use super::digest_bytes_scalar; - use crate::testutil as test; - use crate::{cpu, digest, ec::suite_b::ops::*, limb}; + use { + super::digest_bytes_scalar, + crate::{cpu, digest, ec::suite_b::ops::*, limb, testutil as test}, + }; #[test] fn test() { diff --git a/src/ec/suite_b/ecdsa/signing.rs b/src/ec/suite_b/ecdsa/signing.rs index 3a492c4459..37fcfc2ed1 100644 --- a/src/ec/suite_b/ecdsa/signing.rs +++ b/src/ec/suite_b/ecdsa/signing.rs @@ -14,17 +14,19 @@ //! ECDSA Signatures using the P-256 and P-384 curves. -use super::digest_scalar::digest_scalar; -use crate::{ - arithmetic::montgomery::*, - cpu, digest, - ec::{ - self, - suite_b::{ops::*, private_key}, +use { + super::digest_scalar::digest_scalar, + crate::{ + arithmetic::montgomery::*, + cpu, digest, + ec::{ + self, + suite_b::{ops::*, private_key}, + }, + error, + io::der, + limb, pkcs8, rand, signature, }, - error, - io::der, - limb, pkcs8, rand, signature, }; /// An ECDSA signing algorithm. pub struct EcdsaSigningAlgorithm { @@ -522,8 +524,7 @@ static EC_PUBLIC_KEY_P384_PKCS8_V1_TEMPLATE: pkcs8::Template = pkcs8::Template { #[cfg(test)] mod tests { - use crate::testutil as test; - use crate::{rand, signature}; + use crate::{rand, signature, testutil as test}; #[test] fn signature_ecdsa_sign_fixed_test() { diff --git a/src/ec/suite_b/ecdsa/verification.rs b/src/ec/suite_b/ecdsa/verification.rs index 16b65df8dc..1d18c5ae37 100644 --- a/src/ec/suite_b/ecdsa/verification.rs +++ b/src/ec/suite_b/ecdsa/verification.rs @@ -14,14 +14,16 @@ //! ECDSA Signatures using the P-256 and P-384 curves. -use super::digest_scalar::digest_scalar; -use crate::{ - arithmetic::montgomery::*, - cpu, digest, - ec::suite_b::{ops::*, public_key::*, verify_jacobian_point_is_on_the_curve}, - error, - io::der, - limb, sealed, signature, +use { + super::digest_scalar::digest_scalar, + crate::{ + arithmetic::montgomery::*, + cpu, digest, + ec::suite_b::{ops::*, public_key::*, verify_jacobian_point_is_on_the_curve}, + error, + io::der, + limb, sealed, signature, + }, }; /// An ECDSA verification algorithm. @@ -274,9 +276,11 @@ pub static ECDSA_P384_SHA384_ASN1: EcdsaVerificationAlgorithm = EcdsaVerificatio #[cfg(test)] mod tests { extern crate alloc; - use super::*; - use crate::testutil as test; - use alloc::{vec, vec::Vec}; + use { + super::*, + crate::testutil as test, + alloc::{vec, vec::Vec}, + }; #[test] fn test_digest_based_test_vectors() { diff --git a/src/ec/suite_b/mod.rs b/src/ec/suite_b/mod.rs index 41adcfdf0b..6bcc433489 100644 --- a/src/ec/suite_b/mod.rs +++ b/src/ec/suite_b/mod.rs @@ -14,8 +14,10 @@ //! Elliptic curve operations on P-256 & P-384. -use self::ops::*; -use crate::{arithmetic::montgomery::*, cpu, ec, error, io::der, pkcs8}; +use { + self::ops::*, + crate::{arithmetic::montgomery::*, cpu, ec, error, io::der, pkcs8}, +}; // NIST SP 800-56A Step 3: "If q is an odd prime p, verify that // yQ**2 = xQ**3 + axQ + b in GF(p), where the arithmetic is performed modulo diff --git a/src/ec/suite_b/ops/elem.rs b/src/ec/suite_b/ops/elem.rs index 22c60161ea..77cab7d9d9 100644 --- a/src/ec/suite_b/ops/elem.rs +++ b/src/ec/suite_b/ops/elem.rs @@ -12,17 +12,17 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::ec::suite_b::ops::{ - p256::NUM_LIMBS as P256_NUM_LIMBS, p384::NUM_LIMBS as P384_NUM_LIMBS, -}; -use crate::{ - arithmetic::{ - limbs_from_hex, - montgomery::{Encoding, ProductEncoding, Unencoded}, +use { + crate::{ + arithmetic::{ + limbs_from_hex, + montgomery::{Encoding, ProductEncoding, Unencoded}, + }, + ec::suite_b::ops::{p256::NUM_LIMBS as P256_NUM_LIMBS, p384::NUM_LIMBS as P384_NUM_LIMBS}, + limb::{LeakyLimb, Limb}, }, - limb::{LeakyLimb, Limb}, + core::marker::PhantomData, }; -use core::marker::PhantomData; #[derive(Clone, Copy)] pub(super) enum NumLimbs { diff --git a/src/ec/suite_b/ops/mod.rs b/src/ec/suite_b/ops/mod.rs index 67c22c8f58..d9558dc765 100644 --- a/src/ec/suite_b/ops/mod.rs +++ b/src/ec/suite_b/ops/mod.rs @@ -12,17 +12,17 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::{ - arithmetic::limbs_from_hex, - arithmetic::montgomery::*, - bb::LeakyWord, - cpu, - error::{self, LenMismatchError}, - limb::*, +use { + crate::{ + arithmetic::{limbs_from_hex, montgomery::*}, + bb::LeakyWord, + cpu, + error::{self, LenMismatchError}, + limb::*, + }, + core::marker::PhantomData, + elem::{mul_mont, unary_op, unary_op_assign, unary_op_from_binary_op_assign}, }; -use core::marker::PhantomData; - -use elem::{mul_mont, unary_op, unary_op_assign, unary_op_from_binary_op_assign}; /// A field element, i.e. an element of ℤ/qℤ for the curve's field modulus /// *q*. @@ -611,9 +611,11 @@ fn unwrap_impossible_len_mismatch_error(LenMismatchError { .. }: LenMismatchE #[cfg(test)] mod tests { extern crate alloc; - use super::*; - use crate::testutil as test; - use alloc::{format, vec, vec::Vec}; + use { + super::*, + crate::testutil as test, + alloc::{format, vec::Vec}, + }; const ZERO_SCALAR: Scalar = Scalar { limbs: [0; elem::NumLimbs::MAX], @@ -1146,6 +1148,7 @@ mod tests { pub_ops: &PublicKeyOps, test_file: test::File, ) { + use alloc::vec; let cpu = cpu::features(); let cops = pub_ops.common; let q = &cops.elem_modulus(cpu); @@ -1366,6 +1369,7 @@ mod tests { } fn consume_elem(q: &Modulus, test_case: &mut test::TestCase, name: &str) -> Elem { + use alloc::vec; let unpadded_bytes = test_case.consume_bytes(name); let mut bytes = vec![0; q.bytes_len() - unpadded_bytes.len()]; bytes.extend(&unpadded_bytes); diff --git a/src/ec/suite_b/ops/p256.rs b/src/ec/suite_b/ops/p256.rs index edd3548309..9f20096924 100644 --- a/src/ec/suite_b/ops/p256.rs +++ b/src/ec/suite_b/ops/p256.rs @@ -12,12 +12,14 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{ - PublicModulus, - elem::{binary_op, binary_op_assign}, - elem_sqr_mul, elem_sqr_mul_acc, *, +use { + super::{ + PublicModulus, + elem::{binary_op, binary_op_assign}, + elem_sqr_mul, elem_sqr_mul_acc, *, + }, + cfg_if::cfg_if, }; -use cfg_if::cfg_if; pub(super) const NUM_LIMBS: usize = 256 / LIMB_BITS; diff --git a/src/ec/suite_b/private_key.rs b/src/ec/suite_b/private_key.rs index 19129296c3..19af74f403 100644 --- a/src/ec/suite_b/private_key.rs +++ b/src/ec/suite_b/private_key.rs @@ -15,8 +15,10 @@ //! Functionality shared by operations on private keys (ECC keygen and //! ECDSA signing). -use super::{ops::*, verify_affine_point_is_on_the_curve}; -use crate::{arithmetic::montgomery::R, cpu, ec, error, limb, rand}; +use { + super::{ops::*, verify_affine_point_is_on_the_curve}, + crate::{arithmetic::montgomery::R, cpu, ec, error, limb, rand}, +}; /// Generates a random scalar in the range [1, n). pub(super) fn random_scalar( diff --git a/src/ec/suite_b/public_key.rs b/src/ec/suite_b/public_key.rs index 328bb371a4..38d2e6c979 100644 --- a/src/ec/suite_b/public_key.rs +++ b/src/ec/suite_b/public_key.rs @@ -15,8 +15,10 @@ //! Functionality shared by operations on public keys (ECDSA verification and //! ECDH agreement). -use super::{ops::*, verify_affine_point_is_on_the_curve}; -use crate::{arithmetic::montgomery::*, error}; +use { + super::{ops::*, verify_affine_point_is_on_the_curve}, + crate::{arithmetic::montgomery::*, error}, +}; /// Parses a public key encoded in uncompressed form. The key is validated /// using the ECC Partial Public-Key Validation Routine from @@ -67,9 +69,10 @@ pub(super) fn parse_uncompressed_point( #[cfg(test)] mod tests { - use super::*; - use crate::cpu; - use crate::testutil as test; + use { + super::*, + crate::{cpu, testutil as test}, + }; #[test] fn parse_uncompressed_point_test() { diff --git a/src/error/mod.rs b/src/error/mod.rs index ead174fd45..55ee3cee70 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -14,12 +14,11 @@ //! Error reporting. -pub use self::{key_rejected::KeyRejected, unspecified::Unspecified}; - pub(crate) use self::{ input_too_long::InputTooLongError, len_mismatch_error::LenMismatchError, too_much_output_requested::TooMuchOutputRequestedError, }; +pub use self::{key_rejected::KeyRejected, unspecified::Unspecified}; mod input_too_long; mod into_unspecified; diff --git a/src/hmac.rs b/src/hmac.rs index 37c0e2991c..3c6629be2b 100644 --- a/src/hmac.rs +++ b/src/hmac.rs @@ -105,6 +105,7 @@ //! //! [RFC 2104]: https://tools.ietf.org/html/rfc2104 +pub(crate) use crate::digest::InputTooLongError; use crate::{ bb, cpu, digest::{self, Digest, FinishError}, @@ -113,8 +114,6 @@ use crate::{ rand, }; -pub(crate) use crate::digest::InputTooLongError; - /// An HMAC algorithm. #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Algorithm(&'static digest::Algorithm); diff --git a/src/io/der.rs b/src/io/der.rs index 52aed92b9b..9ddec211e9 100644 --- a/src/io/der.rs +++ b/src/io/der.rs @@ -16,8 +16,7 @@ //! //! This module contains the foundational parts of an ASN.1 DER parser. -use super::Positive; -use crate::error; +use {super::Positive, crate::error}; pub const CONSTRUCTED: u8 = 1 << 5; pub const CONTEXT_SPECIFIC: u8 = 2 << 6; @@ -194,8 +193,7 @@ pub fn positive_integer<'a>( #[cfg(test)] mod tests { - use super::*; - use crate::error; + use {super::*, crate::error}; fn with_i<'a, F, R>(value: &'a [u8], f: F) -> Result where diff --git a/src/io/der_writer.rs b/src/io/der_writer.rs index d6f9717d6c..5af00bd668 100644 --- a/src/io/der_writer.rs +++ b/src/io/der_writer.rs @@ -12,8 +12,10 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{der::*, writer::*, *}; -use alloc::boxed::Box; +use { + super::{der::*, writer::*, *}, + alloc::boxed::Box, +}; pub(crate) fn write_positive_integer( output: &mut dyn Accumulator, diff --git a/src/io/mod.rs b/src/io/mod.rs index 232d5ff39a..1f84072052 100644 --- a/src/io/mod.rs +++ b/src/io/mod.rs @@ -26,6 +26,5 @@ pub(crate) mod der_writer; pub(crate) mod positive; pub use self::positive::Positive; - #[cfg(feature = "alloc")] pub(crate) use self::writer::TooLongError; diff --git a/src/limb.rs b/src/limb.rs index 2468812447..f84db5140f 100644 --- a/src/limb.rs +++ b/src/limb.rs @@ -18,21 +18,21 @@ //! Limbs ordered least-significant-limb to most-significant-limb. The bits //! limbs use the native endianness. -use crate::{ - bb, c, - error::{self, LenMismatchError}, - polyfill::{ - ArrayFlatMap, StartMutPtr, - slice::{AliasingSlices, Cursor, InOut}, - sliceutil, usize_from_u32, - }, - window5::Window5, -}; -use core::{iter, num::NonZero}; - #[cfg(feature = "alloc")] use core::num::Wrapping; -use core::ops::RangeInclusive; +use { + crate::{ + bb, c, + error::{self, LenMismatchError}, + polyfill::{ + ArrayFlatMap, StartMutPtr, + slice::{AliasingSlices, Cursor, InOut}, + sliceutil, usize_from_u32, + }, + window5::Window5, + }, + core::{iter, num::NonZero, ops::RangeInclusive}, +}; // XXX: Not correct for x32 ABIs. pub type Limb = bb::Word; @@ -356,8 +356,7 @@ pub(crate) fn write_negative_assume_odd<'r>( #[allow(clippy::useless_conversion)] #[cfg(test)] mod tests { - use super::*; - use alloc::vec::Vec; + use {super::*, alloc::vec::Vec}; const MAX: LeakyLimb = LeakyLimb::MAX; diff --git a/src/pbkdf2.rs b/src/pbkdf2.rs index 13ba44b3f7..ddbf27f0ae 100644 --- a/src/pbkdf2.rs +++ b/src/pbkdf2.rs @@ -112,13 +112,15 @@ //! assert!(db.verify_password("alice", "@74d7]404j|W}6u").is_ok()); //! } -use self::{derive_error::DeriveError, verify_error::VerifyError}; -use crate::{ - bb, cpu, digest, - error::{self, TooMuchOutputRequestedError}, - hmac::{self, InputTooLongError}, +use { + self::{derive_error::DeriveError, verify_error::VerifyError}, + crate::{ + bb, cpu, digest, + error::{self, TooMuchOutputRequestedError}, + hmac::{self, InputTooLongError}, + }, + core::num::NonZero, }; -use core::num::NonZero; /// A PBKDF2 algorithm. #[derive(Clone, Copy, PartialEq, Eq)] diff --git a/src/polyfill/aliasing_slices.rs b/src/polyfill/aliasing_slices.rs index 1d0f3e85ec..ae36bc08b9 100644 --- a/src/polyfill/aliasing_slices.rs +++ b/src/polyfill/aliasing_slices.rs @@ -13,12 +13,13 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. pub(crate) use crate::error::LenMismatchError; -use crate::polyfill::{ - StartPtr, - slice::{AliasedUninit, Uninit}, +use { + crate::polyfill::{ + StartPtr, + slice::{AliasedUninit, Uninit}, + }, + core::{array, num::NonZero}, }; -use core::array; -use core::num::NonZero; pub(crate) trait AliasingSlices<'o, T, const INPUTS: usize> { /// The pointers passed to `f` will be valid and non-null, and will not diff --git a/src/polyfill/array_flat_map.rs b/src/polyfill/array_flat_map.rs index 8b3abbefe1..416ae5780f 100644 --- a/src/polyfill/array_flat_map.rs +++ b/src/polyfill/array_flat_map.rs @@ -58,8 +58,7 @@ where #[cfg(test)] mod tests { - use super::*; - use core::mem::size_of; + use {super::*, core::mem::size_of}; #[test] fn test_array_flat_map() { diff --git a/src/polyfill/array_split_map.rs b/src/polyfill/array_split_map.rs index ccacb385ee..e8c55fb3a8 100644 --- a/src/polyfill/array_split_map.rs +++ b/src/polyfill/array_split_map.rs @@ -14,7 +14,6 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - use core::array; pub trait ArraySplitMap { diff --git a/src/polyfill/dynarray.rs b/src/polyfill/dynarray.rs index 5c4f4a718f..35f0c93e1b 100644 --- a/src/polyfill/dynarray.rs +++ b/src/polyfill/dynarray.rs @@ -19,9 +19,10 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use crate::error::LenMismatchError; -use core::{mem::MaybeUninit, num::NonZero}; +use { + crate::error::LenMismatchError, + core::{mem::MaybeUninit, num::NonZero}, +}; /// An uninitialized array of slices. /// diff --git a/src/polyfill/mod.rs b/src/polyfill/mod.rs index 7108963492..5bf3f404ad 100644 --- a/src/polyfill/mod.rs +++ b/src/polyfill/mod.rs @@ -94,13 +94,11 @@ mod uninit_slice; mod uninit_slice_cursor; pub use self::{array_flat_map::ArrayFlatMap, array_split_map::ArraySplitMap, notsend::NotSend}; - #[allow(unused_imports)] pub use self::{ smaller_chunks::SmallerChunks, start_ptr::{StartMutPtr, StartPtr}, }; - #[cfg(feature = "alloc")] pub use leading_zeros_skipped::LeadingZerosStripped; diff --git a/src/polyfill/notsend.rs b/src/polyfill/notsend.rs index 9c14006f57..47159a34f1 100644 --- a/src/polyfill/notsend.rs +++ b/src/polyfill/notsend.rs @@ -12,8 +12,10 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::testutil; -use core::{marker::PhantomData, mem::size_of}; +use { + crate::testutil, + core::{marker::PhantomData, mem::size_of}, +}; /// A ZST that can be added to any type to make the type `!Send`. #[derive(Clone, Copy)] diff --git a/src/polyfill/once_cell/race.rs b/src/polyfill/once_cell/race.rs index 71cb0210b9..273dd46023 100644 --- a/src/polyfill/once_cell/race.rs +++ b/src/polyfill/once_cell/race.rs @@ -34,12 +34,13 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use cfg_if::cfg_if; -use core::{ - marker::PhantomData, - num::NonZero, - sync::atomic::{self, AtomicU32}, +use { + cfg_if::cfg_if, + core::{ + marker::PhantomData, + num::NonZero, + sync::atomic::{self, AtomicU32}, + }, }; pub trait Ordering { diff --git a/src/polyfill/uninit_slice.rs b/src/polyfill/uninit_slice.rs index acd0de49c8..d2c1c77b59 100644 --- a/src/polyfill/uninit_slice.rs +++ b/src/polyfill/uninit_slice.rs @@ -14,17 +14,18 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::{ - start_ptr::{StartMutPtr, StartPtr}, - uninit_slice_cursor::Cursor, -}; -use crate::error::LenMismatchError; -use core::{ - marker::PhantomData, - mem::{self, MaybeUninit}, - ops::RangeTo, - ptr, +use { + super::{ + start_ptr::{StartMutPtr, StartPtr}, + uninit_slice_cursor::Cursor, + }, + crate::error::LenMismatchError, + core::{ + marker::PhantomData, + mem::{self, MaybeUninit}, + ops::RangeTo, + ptr, + }, }; pub struct Uninit<'target, E> { diff --git a/src/polyfill/uninit_slice_cursor.rs b/src/polyfill/uninit_slice_cursor.rs index 1945beeee0..395832b29e 100644 --- a/src/polyfill/uninit_slice_cursor.rs +++ b/src/polyfill/uninit_slice_cursor.rs @@ -14,10 +14,11 @@ #[allow(unused_imports)] use crate::polyfill::prelude::*; - -use super::uninit_slice::{Uninit, WriteResult}; -use crate::error::LenMismatchError; -use core::mem; +use { + super::uninit_slice::{Uninit, WriteResult}, + crate::error::LenMismatchError, + core::mem, +}; pub struct Cursor<'buf, E> { uninit: Uninit<'buf, E>, diff --git a/src/rsa/base/public_exponent.rs b/src/rsa/base/public_exponent.rs index ff5ef2ae42..daba802985 100644 --- a/src/rsa/base/public_exponent.rs +++ b/src/rsa/base/public_exponent.rs @@ -1,6 +1,10 @@ -use crate::error; -use crate::polyfill::{ArrayFlatMap, LeadingZerosStripped}; -use core::num::NonZero; +use { + crate::{ + error, + polyfill::{ArrayFlatMap, LeadingZerosStripped}, + }, + core::num::NonZero, +}; /// The exponent `e` of an RSA public key. #[derive(Clone, Copy)] diff --git a/src/rsa/base/public_key.rs b/src/rsa/base/public_key.rs index 5d8090df30..9bee132189 100644 --- a/src/rsa/base/public_key.rs +++ b/src/rsa/base/public_key.rs @@ -12,16 +12,18 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{ - super::{N, PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, PublicKeyComponents}, - PublicExponent, PublicModulus, public_modulus, +use { + super::{ + super::{N, PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, PublicKeyComponents}, + PublicExponent, PublicModulus, public_modulus, + }, + crate::{ + arithmetic::{bigint, montgomery::RR}, + bits, cpu, error, + limb::LIMB_BYTES, + }, + core::num::NonZero, }; -use crate::{ - arithmetic::{bigint, montgomery::RR}, - bits, cpu, error, - limb::LIMB_BYTES, -}; -use core::num::NonZero; /// An RSA Public Key. #[derive(Clone)] diff --git a/src/rsa/base/public_modulus.rs b/src/rsa/base/public_modulus.rs index e50ee47317..6a139b4db0 100644 --- a/src/rsa/base/public_modulus.rs +++ b/src/rsa/base/public_modulus.rs @@ -1,11 +1,13 @@ -use crate::{ - arithmetic::{bigint, montgomery::RR}, - bits::{self, FromByteLen as _}, - cpu, - error::{self, InputTooLongError}, - rsa::N, +use { + crate::{ + arithmetic::{bigint, montgomery::RR}, + bits::{self, FromByteLen as _}, + cpu, + error::{self, InputTooLongError}, + rsa::N, + }, + core::ops::RangeInclusive, }; -use core::ops::RangeInclusive; /// The modulus (n) of an RSA public key. #[derive(Clone)] diff --git a/src/rsa/keypair.rs b/src/rsa/keypair.rs index 9813ba1920..8fa3f18cdd 100644 --- a/src/rsa/keypair.rs +++ b/src/rsa/keypair.rs @@ -18,7 +18,6 @@ use super::{ padding::{self, RsaEncoding}, public_key, }; - /// RSA PKCS#1 1.5 signatures. use crate::{ arithmetic::{ @@ -672,9 +671,7 @@ impl KeyPair { #[cfg(test)] mod tests { - use super::*; - use crate::testutil as test; - use alloc::vec; + use {super::*, crate::testutil as test, alloc::vec}; #[test] fn test_rsakeypair_private_exponentiate() { diff --git a/src/rsa/padding/pkcs1.rs b/src/rsa/padding/pkcs1.rs index eec5e2dc9a..0f872165c7 100644 --- a/src/rsa/padding/pkcs1.rs +++ b/src/rsa/padding/pkcs1.rs @@ -12,8 +12,10 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{super::PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, Padding, RsaEncoding, Verification}; -use crate::{bits, digest, error, io::der, rand, sealed}; +use { + super::{super::PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, Padding, RsaEncoding, Verification}, + crate::{bits, digest, error, io::der, rand, sealed}, +}; /// PKCS#1 1.5 padding as described in [RFC 3447 Section 8.2]. /// diff --git a/src/rsa/padding/pss.rs b/src/rsa/padding/pss.rs index 9137a3d7ed..f3b30df05f 100644 --- a/src/rsa/padding/pss.rs +++ b/src/rsa/padding/pss.rs @@ -12,8 +12,10 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{super::PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, Padding, RsaEncoding, Verification, mgf1}; -use crate::{bb, bits, digest, error, rand, sealed}; +use { + super::{super::PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, Padding, RsaEncoding, Verification, mgf1}, + crate::{bb, bits, digest, error, rand, sealed}, +}; /// RSA PSS padding as described in [RFC 3447 Section 8.1]. /// diff --git a/src/rsa/public_key.rs b/src/rsa/public_key.rs index 1ede8c834c..820daec518 100644 --- a/src/rsa/public_key.rs +++ b/src/rsa/public_key.rs @@ -12,15 +12,16 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::{N, base}; -use crate::{ - arithmetic::{bigint, montgomery::RR}, - cpu, error, - io::{self, der, der_writer}, -}; -use alloc::boxed::Box; - pub(super) use base::public_key::ValidatedInput; +use { + super::{N, base}, + crate::{ + arithmetic::{bigint, montgomery::RR}, + cpu, error, + io::{self, der, der_writer}, + }, + alloc::boxed::Box, +}; /// An RSA Public Key. #[derive(Clone)] diff --git a/src/rsa/public_key_components.rs b/src/rsa/public_key_components.rs index 3220d75175..362447aa90 100644 --- a/src/rsa/public_key_components.rs +++ b/src/rsa/public_key_components.rs @@ -12,8 +12,7 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::PublicKey; -use core::iter::FromIterator; +use {super::PublicKey, core::iter::FromIterator}; /// RSA public key components. /// diff --git a/src/rsa/tests/padding_tests.rs b/src/rsa/tests/padding_tests.rs index 51b9e8f262..ada3392ac0 100644 --- a/src/rsa/tests/padding_tests.rs +++ b/src/rsa/tests/padding_tests.rs @@ -12,10 +12,11 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use super::super::padding::*; -use crate::testutil as test; -use crate::{digest, error, sealed}; -use alloc::vec; +use { + super::super::padding::*, + crate::{digest, error, sealed, testutil as test}, + alloc::vec, +}; #[test] fn test_pss_padding_verify() { diff --git a/src/rsa/verification.rs b/src/rsa/verification.rs index 2218772484..8c78032366 100644 --- a/src/rsa/verification.rs +++ b/src/rsa/verification.rs @@ -14,17 +14,19 @@ //! Verification of RSA signatures. -use super::{ - PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, PublicKeyComponents, RsaParameters, - base::{PublicExponent, public_key}, - parse_public_key, -}; -use crate::{ - arithmetic::bigint, - bits::{self, FromByteLen as _}, - cpu, digest, - error::{self, InputTooLongError}, - sealed, signature, +use { + super::{ + PUBLIC_KEY_PUBLIC_MODULUS_MAX_LEN, PublicKeyComponents, RsaParameters, + base::{PublicExponent, public_key}, + parse_public_key, + }, + crate::{ + arithmetic::bigint, + bits::{self, FromByteLen as _}, + cpu, digest, + error::{self, InputTooLongError}, + sealed, signature, + }, }; impl signature::VerificationAlgorithm for RsaParameters { diff --git a/src/signature.rs b/src/signature.rs index dd37058b4c..347c16e760 100644 --- a/src/signature.rs +++ b/src/signature.rs @@ -255,8 +255,6 @@ //! # } //! ``` -use crate::{cpu, debug, ec, error, sealed}; - pub use crate::ec::{ curve25519::ed25519::{ ED25519_PUBLIC_KEY_LEN, @@ -276,7 +274,6 @@ pub use crate::ec::{ }, }, }; - #[cfg(feature = "alloc")] pub use crate::rsa::{ RsaParameters, @@ -294,6 +291,7 @@ pub use crate::rsa::{ RsaPublicKeyComponents, }, }; +use crate::{cpu, debug, ec, error, sealed}; /// An RSA key pair, used for signing. #[cfg(feature = "alloc")] diff --git a/src/tests/ownedmodulusvalue_tests.rs b/src/tests/ownedmodulusvalue_tests.rs index c8621836fc..d6898d4ffc 100644 --- a/src/tests/ownedmodulusvalue_tests.rs +++ b/src/tests/ownedmodulusvalue_tests.rs @@ -1,9 +1,11 @@ -use crate::{ - arithmetic::{MIN_LIMBS, bigint::modulus::ValidatedInput}, - error::KeyRejected, - limb::{LIMB_BITS, LIMB_BYTES}, +use { + crate::{ + arithmetic::{MIN_LIMBS, bigint::modulus::ValidatedInput}, + error::KeyRejected, + limb::{LIMB_BITS, LIMB_BYTES}, + }, + alloc::vec::Vec, }; -use alloc::vec::Vec; // XXX: This only tests the bit length calculation and error handling; it // doesn't verify that the resultant modulus has the expected value. diff --git a/src/tests/polyfill_tests/uninit_slice_tests.rs b/src/tests/polyfill_tests/uninit_slice_tests.rs index 350fabcdb7..9b0829b608 100644 --- a/src/tests/polyfill_tests/uninit_slice_tests.rs +++ b/src/tests/polyfill_tests/uninit_slice_tests.rs @@ -12,11 +12,13 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::{ - error::LenMismatchError, - polyfill::{StartPtr, slice::Uninit}, +use { + crate::{ + error::LenMismatchError, + polyfill::{StartPtr, slice::Uninit}, + }, + core::{mem::MaybeUninit, ptr, slice}, }; -use core::{mem::MaybeUninit, ptr, slice}; #[test] fn test_write_fully_with_empty() { diff --git a/src/testutil.rs b/src/testutil.rs index dd28ac1f94..b9c13f8d46 100644 --- a/src/testutil.rs +++ b/src/testutil.rs @@ -119,9 +119,10 @@ extern crate alloc; -use alloc::{format, string::String, vec::Vec}; - -use crate::{bits, digest, error}; +use { + crate::{bits, digest, error}, + alloc::{format, string::String, vec::Vec}, +}; #[cfg(any(feature = "std", feature = "test_logging"))] extern crate std; @@ -550,8 +551,7 @@ pub mod rand { #[cfg(test)] mod tests { - use crate::error; - use crate::testutil as test; + use crate::{error, testutil as test}; #[test] fn one_ok() { diff --git a/tests/aead_tests.rs b/tests/aead_tests.rs index 8e1e4e81a1..ffd2ceedff 100644 --- a/tests/aead_tests.rs +++ b/tests/aead_tests.rs @@ -20,10 +20,12 @@ use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] wasm_bindgen_test_configure!(run_in_browser); -use core::{array, ops::RangeFrom}; -use ring::{aead, error}; #[allow(deprecated)] use ring::{test, test_file}; +use { + core::{array, ops::RangeFrom}, + ring::{aead, error}, +}; /// Generate the known answer test functions for the given algorithm and test /// case input file, where each test is implemented by a test in `$test`. diff --git a/tests/build_path_tests.rs b/tests/build_path_tests.rs index 541ba92654..6cb3df1ab6 100644 --- a/tests/build_path_tests.rs +++ b/tests/build_path_tests.rs @@ -14,8 +14,10 @@ #![allow(missing_docs)] -use self::path::join_components_with_forward_slashes_if_windows; -use std::{ffi::OsStr, path::Path}; +use { + self::path::join_components_with_forward_slashes_if_windows, + std::{ffi::OsStr, path::Path}, +}; #[allow(dead_code)] #[path = "../build/build/path.rs"] diff --git a/tests/constant_time_tests.rs b/tests/constant_time_tests.rs index b8d9ac38ff..0b7915cb28 100644 --- a/tests/constant_time_tests.rs +++ b/tests/constant_time_tests.rs @@ -19,7 +19,6 @@ use constant_time::verify_slices_are_equal; #[allow(deprecated)] use ring::constant_time; use ring::{error, rand}; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/digest_tests.rs b/tests/digest_tests.rs index 0a3a824826..44b1b7eb95 100644 --- a/tests/digest_tests.rs +++ b/tests/digest_tests.rs @@ -17,7 +17,6 @@ use ring::digest; #[allow(deprecated)] use ring::{test, test_file}; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/ed25519_tests.rs b/tests/ed25519_tests.rs index c318bdb394..02d0081031 100644 --- a/tests/ed25519_tests.rs +++ b/tests/ed25519_tests.rs @@ -20,7 +20,6 @@ use ring::{ }; #[allow(deprecated)] use ring::{test, test_file}; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/hkdf_tests.rs b/tests/hkdf_tests.rs index a1de1c0929..37fdebd002 100644 --- a/tests/hkdf_tests.rs +++ b/tests/hkdf_tests.rs @@ -17,7 +17,6 @@ use ring::{digest, error, hkdf}; #[allow(deprecated)] use ring::{test, test_file}; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/hmac_tests.rs b/tests/hmac_tests.rs index f009309178..efd217348a 100644 --- a/tests/hmac_tests.rs +++ b/tests/hmac_tests.rs @@ -17,7 +17,6 @@ use ring::{digest, hmac}; #[allow(deprecated)] use ring::{test, test_file}; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/pbkdf2_tests.rs b/tests/pbkdf2_tests.rs index 5c7dec0c47..513df6c47d 100644 --- a/tests/pbkdf2_tests.rs +++ b/tests/pbkdf2_tests.rs @@ -14,13 +14,14 @@ #![allow(missing_docs)] -use core::num::NonZero; -use ring::{digest, error, pbkdf2}; #[allow(deprecated)] use ring::{test, test_file}; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; +use { + core::num::NonZero, + ring::{digest, error, pbkdf2}, +}; #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] wasm_bindgen_test_configure!(run_in_browser); diff --git a/tests/rand_tests.rs b/tests/rand_tests.rs index 91965362d9..2170254ddd 100644 --- a/tests/rand_tests.rs +++ b/tests/rand_tests.rs @@ -17,7 +17,6 @@ use ring::rand::{self, SecureRandom as _}; #[allow(deprecated)] use ring::test; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/rsa_tests.rs b/tests/rsa_tests.rs index d67844869d..b1b16fa490 100644 --- a/tests/rsa_tests.rs +++ b/tests/rsa_tests.rs @@ -23,7 +23,6 @@ use ring::{ }; #[allow(deprecated)] use ring::{test, test_file}; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure}; diff --git a/tests/signature_tests.rs b/tests/signature_tests.rs index 9a6d902eca..5098a39bba 100644 --- a/tests/signature_tests.rs +++ b/tests/signature_tests.rs @@ -3,7 +3,6 @@ use ring::signature; #[allow(deprecated)] use ring::test; - #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] use wasm_bindgen_test::{wasm_bindgen_test as test, wasm_bindgen_test_configure};