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

Runtime check and optional no_std #40

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lisicky
Copy link
Contributor

@lisicky lisicky commented Jan 13, 2023

Despite that the previous PR #39 fixes compilation without x86 SIMDs flags, there is the case when a user of cryptoxide compiles for x86 and tries to execute code with cryptoxide can get an error SIGILL, because the code branch below works only in compile time.

By this PR I suggest adding a runtime SIMD support check and making cryptoxide std friendly because the is_x86_feature_detected is only available in the std. But I left the possibility to build cryptoxide as no_std by disabling default features. I can make an update for README.MD with instructions on how it can be done. That no_std manner I got from https://github.com/marshallpierce/rust-base64 and https://github.com/iqlusioninc/crates/tree/main/bip32 repos.

#[cfg(target_feature = "avx2")]
const HAS_AVX2: bool = true;
#[cfg(not(target_feature = "avx2"))]
const HAS_AVX2: bool = false;
if HAS_AVX2 {
return avx2::compress_b(&mut self.h, &mut self.t, buf, last);
}

@vincenthz
Copy link
Collaborator

in term of runtime check I think it's good, but not adding back std (or adding dependencies) is a stronger priority of mine for cryptoxide. Likely I imagine, adding a cpu.rs module with some inline assembly / cpuid checks. we need a very small subset of std::is_x86_feature_detected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants