-
Notifications
You must be signed in to change notification settings - Fork 86
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
Short-circuit in debug mode resulting in non-constant-time execution #43
Comments
Hi @brycx! Thanks for finding this and for the detailed write up. It seems you are correct that Rust's logical OR and AND operators short-circuit the evaluation at runtime (unless they are part of a Thanks so much for the patch! |
Hi @isislovecruft! I'm glad I could contribute to this great crate.
This comes as a surprise to me. Even though it's a very reasonable limitation, I haven't found any explicit mentions of this (either that debug should be avoided, or that only release is supported) in the README or the docs, which has made me assume otherwise. Personally, I think that it should be mentioned in the README and docs, that you only support release mode for security reasons and users should avoid debug, due to the reason you mentioned above. I also think this should be added to the RustSec advisory database, because if other people have assumed constant-time execution in debug mode, like myself, then they should be made aware of this. It would hopefully also increase the number of people who would read the additions to the aforementioned security limitations. What do you think? |
Hi @brycx, thanks for digging into this, this is great work. If you wanted, it would be great if you wrote up something on the methodology and results somewhere (like a blog or something). With regard to the debug-mode issue, it's true that it's not mentioned in the docs, and that's probably a documentation bug. It would be good to make that explicit, adding something like "Note that this crate includes additional debug assertions in debug builds; only release builds should be used in production", but I don't consider it a security issue, because debug mode is for debugging, not for running in production with secret data. For example, the |
Certainly, I can scribble something down once I've wrapped up the rest of my testing.
I think explicitly mentioning the constant-time execution would be good, to make it clear why it should be avoided. Perhaps "Note that this crate includes additional debug assertions in debug builds, which can cause the code not to run in constant-time. Only release builds should be used in production."?
That makes sense.
Should this also have a doc mention about debug builds in that case? |
Merged in for 1.0.1 and 2.0.1 |
I have been testing subtle using dudect, provided by dudect-bencher.
From what I can tell, there is a short-circuit in both
black_box
functions and theFrom<Choice> for bool
trait implementation forChoice
. This affects both stable and nightly, but in debug-mode only.I have only tested
ct_eq
.The asserts that seem to short-circuit are:
subtle/src/lib.rs
Line 79 in 558316b
subtle/src/lib.rs
Line 147 in 558316b
subtle/src/lib.rs
Line 163 in 558316b
Commit bf3888e changes the debug_assert OR to a strict evaluation.
Before applying commit bf3888e in #42, these were the t-tests that dudect-bencher reported
After applying commit bf3888e:
The tests can be found here: https://github.com/brycx/orion-dudect/tree/subtle-short-circuit/ct-bencher.
The text was updated successfully, but these errors were encountered: