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

Use of black_box is not recommended for security uses #12

Open
AaronFeickert opened this issue Aug 22, 2024 · 2 comments
Open

Use of black_box is not recommended for security uses #12

AaronFeickert opened this issue Aug 22, 2024 · 2 comments

Comments

@AaronFeickert
Copy link

The library currently uses core::hint::black_box as a fallback optimization barrier when needed for architecture support. However, its documentation specifically recommends against its use for cryptographic or security-focused use cases.

It may be useful to add documentation warning against this for architectures that would use it.

@cesarb
Copy link
Owner

cesarb commented Aug 27, 2024

As explained in the large comment within the fallback implementation, black_box is not used alone as the optimization barrier; it also uses #[inline(never)] for that function. Unfortunately, that's the best we can do without some sort of assembly (either inline assembly, or separately compiled assembly files) or help from the compiler. The alternative that was used before black_box was made stable (using a volatile read trick) is also not guaranteed to block optimizations.

I'll think about adding a warning to the crate's module-level documentation.

@AaronFeickert
Copy link
Author

Fair enough. I would certainly recommend more documentation about the nature of the optimization barriers used, so users can make a more informed decision based on use cases.

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

No branches or pull requests

2 participants