Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose sha256_utils behind a feature flag. #108

Merged
merged 4 commits into from Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions sha2/Cargo.toml
Expand Up @@ -25,6 +25,7 @@ hex-literal = "0.1"
default = ["std"]
std = ["digest/std"]
asm = ["sha2-asm"]
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.
Expand Down
47 changes: 31 additions & 16 deletions sha2/src/lib.rs
Expand Up @@ -55,40 +55,55 @@
//! [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;

mod consts;
#[cfg(any(not(feature = "asm"), feature = "asm-aarch64"))]
mod sha256_utils;
#[cfg(any(not(feature = "asm"), target_arch = "aarch64"))]
mod sha512_utils;
#[cfg(feature = "asm-aarch64")]
mod aarch64;
mod consts;
mod sha256;
#[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;
dconnolly marked this conversation as resolved.
Show resolved Hide resolved

pub use digest::Digest;
pub use sha256::{Sha256, Sha224};
pub use sha512::{Sha512, Sha384, Sha512Trunc224, Sha512Trunc256};
pub use sha256::{Sha224, Sha256};
pub use sha512::{Sha384, Sha512, Sha512Trunc224, Sha512Trunc256};