From f9b35c0d0152c9afea728903e847a3c6275a39e9 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Wed, 18 Mar 2020 18:56:11 -0400 Subject: [PATCH 1/4] Expose sha256_utils with the utils feature flag --- sha2/Cargo.toml | 1 + sha2/src/lib.rs | 47 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 15 deletions(-) diff --git a/sha2/Cargo.toml b/sha2/Cargo.toml index e8694817..d3271d19 100644 --- a/sha2/Cargo.toml +++ b/sha2/Cargo.toml @@ -25,6 +25,7 @@ hex-literal = "0.1" default = ["std"] std = ["digest/std"] asm = ["sha2-asm"] +utils = ["utils"] # TODO: Remove this feature once is_aarch64_feature_detected!() is stabilised. # Only used on AArch64 Linux systems, when built without the crypto target_feature. diff --git a/sha2/src/lib.rs b/sha2/src/lib.rs index 04b9f5cf..f6cf9d25 100644 --- a/sha2/src/lib.rs +++ b/sha2/src/lib.rs @@ -55,40 +55,57 @@ //! [1]: https://en.wikipedia.org/wiki/SHA-2 //! [2]: https://github.com/RustCrypto/hashes #![no_std] -#![doc(html_logo_url = - "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] +#![doc(html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo_small.png")] // Give relevant error messages if the user tries to enable AArch64 asm on unsupported platforms. -#[cfg(all(feature = "asm-aarch64", target_arch = "aarch64", not(target_os = "linux")))] +#[cfg(all( + feature = "asm-aarch64", + target_arch = "aarch64", + not(target_os = "linux") +))] compile_error!("Your OS isn’t yet supported for runtime-checking of AArch64 features."); #[cfg(all(feature = "asm-aarch64", not(target_arch = "aarch64")))] compile_error!("Enable the \"asm\" feature instead of \"asm-aarch64\" on non-AArch64 systems."); -#[cfg(all(feature = "asm-aarch64", target_arch = "aarch64", target_feature = "crypto"))] +#[cfg(all( + feature = "asm-aarch64", + target_arch = "aarch64", + target_feature = "crypto" +))] compile_error!("Enable the \"asm\" feature instead of \"asm-aarch64\" when building for AArch64 systems with crypto extensions."); -#[cfg(all(not(feature = "asm-aarch64"), feature = "asm", target_arch = "aarch64", not(target_feature = "crypto"), target_os = "linux"))] +#[cfg(all( + not(feature = "asm-aarch64"), + feature = "asm", + target_arch = "aarch64", + not(target_feature = "crypto"), + target_os = "linux" +))] compile_error!("Enable the \"asm-aarch64\" feature on AArch64 if you want to use asm detected at runtime, or build with the crypto extensions support, for instance with RUSTFLAGS='-C target-cpu=native' on a compatible CPU."); extern crate block_buffer; extern crate fake_simd as simd; -#[macro_use] extern crate opaque_debug; -#[macro_use] pub extern crate digest; +#[macro_use] +extern crate opaque_debug; +#[macro_use] +pub extern crate digest; +#[cfg(feature = "asm-aarch64")] +extern crate libc; #[cfg(feature = "asm")] extern crate sha2_asm; #[cfg(feature = "std")] extern crate std; -#[cfg(feature = "asm-aarch64")] -extern crate libc; +#[cfg(feature = "asm-aarch64")] +mod aarch64; mod consts; +mod sha256; #[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] mod sha256_utils; +mod sha512; #[cfg(any(not(feature = "asm"), target_arch = "aarch64"))] mod sha512_utils; -#[cfg(feature = "asm-aarch64")] -mod aarch64; -mod sha256; -mod sha512; pub use digest::Digest; -pub use sha256::{Sha256, Sha224}; -pub use sha512::{Sha512, Sha384, Sha512Trunc224, Sha512Trunc256}; +pub use sha256::{Sha224, Sha256}; +#[cfg(feature = "utils")] +pub use sha256_utils; +pub use sha512::{Sha384, Sha512, Sha512Trunc224, Sha512Trunc256}; From 789e705e61328b8ac1c0389036f48223ed6e1710 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Wed, 18 Mar 2020 19:58:27 -0400 Subject: [PATCH 2/4] utils feature has no dependencies --- sha2/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sha2/Cargo.toml b/sha2/Cargo.toml index d3271d19..8f8d613c 100644 --- a/sha2/Cargo.toml +++ b/sha2/Cargo.toml @@ -25,7 +25,7 @@ hex-literal = "0.1" default = ["std"] std = ["digest/std"] asm = ["sha2-asm"] -utils = ["utils"] +utils = [] # TODO: Remove this feature once is_aarch64_feature_detected!() is stabilised. # Only used on AArch64 Linux systems, when built without the crypto target_feature. From a968a8db2bffae75fbb31596897be9088ddbb821 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Wed, 18 Mar 2020 20:22:02 -0400 Subject: [PATCH 3/4] Coalesce sha256_util export --- sha2/src/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/sha2/src/lib.rs b/sha2/src/lib.rs index f6cf9d25..4d0f3520 100644 --- a/sha2/src/lib.rs +++ b/sha2/src/lib.rs @@ -98,14 +98,12 @@ extern crate std; mod aarch64; mod consts; mod sha256; -#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))] -mod sha256_utils; +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64", feature = "utils"))] +pub mod sha256_utils; mod sha512; #[cfg(any(not(feature = "asm"), target_arch = "aarch64"))] mod sha512_utils; pub use digest::Digest; pub use sha256::{Sha224, Sha256}; -#[cfg(feature = "utils")] -pub use sha256_utils; pub use sha512::{Sha384, Sha512, Sha512Trunc224, Sha512Trunc256}; From c1afa054b869f26f42a1585b7855c22c206e9642 Mon Sep 17 00:00:00 2001 From: Deirdre Connolly Date: Tue, 24 Mar 2020 18:35:24 -0400 Subject: [PATCH 4/4] Rename flag to 'compress', export just compress* instead of whole module --- sha2/Cargo.toml | 2 +- sha2/src/lib.rs | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/sha2/Cargo.toml b/sha2/Cargo.toml index 8f8d613c..0c858aad 100644 --- a/sha2/Cargo.toml +++ b/sha2/Cargo.toml @@ -25,7 +25,7 @@ hex-literal = "0.1" default = ["std"] std = ["digest/std"] asm = ["sha2-asm"] -utils = [] +compress = [] # TODO: Remove this feature once is_aarch64_feature_detected!() is stabilised. # Only used on AArch64 Linux systems, when built without the crypto target_feature. diff --git a/sha2/src/lib.rs b/sha2/src/lib.rs index 4d0f3520..1730feda 100644 --- a/sha2/src/lib.rs +++ b/sha2/src/lib.rs @@ -98,12 +98,16 @@ extern crate std; mod aarch64; mod consts; mod sha256; -#[cfg(any(not(feature = "asm"), feature = "asm-aarch64", feature = "utils"))] -pub mod sha256_utils; +#[cfg(any(not(feature = "asm"), feature = "asm-aarch64", feature = "compress"))] +mod sha256_utils; mod sha512; -#[cfg(any(not(feature = "asm"), target_arch = "aarch64"))] +#[cfg(any(not(feature = "asm"), target_arch = "aarch64", feature = "compress"))] mod sha512_utils; pub use digest::Digest; pub use sha256::{Sha224, Sha256}; +#[cfg(feature = "compress")] +pub use sha256_utils::compress256; pub use sha512::{Sha384, Sha512, Sha512Trunc224, Sha512Trunc256}; +#[cfg(feature = "compress")] +pub use sha512_utils::compress512;