-
Notifications
You must be signed in to change notification settings - Fork 1k
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
[trivial] clear stack variable by function #438
Conversation
It's a fine structural change, but if you're going to break this out, can you perhaps make it a generic unsigned char clear that takes a point and length (which you'd use sizeof() on here)? --- and try to get the compiler to not optimize it out? Edit: on second thought, we may prefer a clear function per type, even if all they're doing is wrapping a generic one. (As a matter of principle, we should never silence a warning which is potentially hiding an actual problem. In this case the problem is that the compiler will simply optimize out this assignment). |
… 'volatile' keyword
178f16b
to
cdd4681
Compare
The new branch has two commits with two tentative examples for comment. They focus just on the In the first example commit 72c0ebb,
(As was assumed, it was indeed being optimized out before, but I didn't quote it here to save space) However, compiling the same with
So, this approach looks like it is not very universal. ugh. Taking a step back and looking at OpenSSL, they clear stack variables with a function named
So, this approach is also tried in cdd4681. The assembly in
This works perfectly with Also, for C++ there is discussion on the internet around a new Questions:
|
memset_s is an optional function in C11 (not C++11), and it doesn't seem like compilers are eager to implement it. |
10:59 < gmaxwell> glibc 2.25 has explicit_bzero |
closing in favor of #448 |
The bare
bits = 0;
raises a clang static analysis issue.The line was introduced in 2f6c801 (when
secp256k1_ecmult_gen()
lived insrc/ecmult_impl.h
) with the purpose of clearing stack variables that might have secret info.However, without that context, the purpose for clearing isn't obvious from reading the code. Aside from making clang happy, the function name should help it be understood.