-
Notifications
You must be signed in to change notification settings - Fork 460
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
Scalar
gets copied when moved revealing the secret value.
#586
Comments
I doubt Box makes sense, given this crates gets used without alloc. I suppose documentation could suggest that secrets be |
That was my suggestion to the best of my knowledge. Curious to know if this problem can be solved without alloc :) |
As has already been covered, in
As a general rule in Rust, types which impl https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html#stack-only-data-copy
It's important to note that not all FWIW the @RustCrypto Also note that in Rust leaving transient copies of secrets on the stack is very difficult to avoid. Moves can sometimes make memcpy-style copies of To ensure the stack is clean after running a cryptographic operation, the caller needs to handle clearing out sensitive data from the stack. |
Thanks for Clarification. More question;
Yeah, I am talking about Scalar being used to hold sensitive data.
I tried to emulate SecretKey here. It does not solve the problem. Please correct if I am wrong.
How can the caller be trusted with manually handling the sensitive data? They will often mess things up. Maybe a clear documentation as to how will be the way. |
An attacker who can read secret keys out of memory is generally outside the threat model of most cryptographic libraries. Note
This is an area where there aren't great solutions right now, and why I currently prefer that libraries don't attempt to include some half-baked solution. So I'm sorry but I don't have a good answer for you. You can read some past discussion on this subject here: The-DevX-Initiative/RCIG_Coordination_Repo#55 |
Here is the updated one.
Yeah, I saw Zeroize docs also mentioning about using
Will give it a read. Thank you sir! |
@RajeshRk18 is there something specific you're trying to illustrate with these examples? This example contains moves, because you are allocating As I've said repeatedly, and you've just quoted, moving a type can involve a memcpy. So showing an example of some convoluted code that allocates a key and then moves it around leaving copies on the stack is entirely expected. But even if it didn't, and you had code that didn't do anything explicitly that might leave a copy on the stack, rustc might choose to make a copy, e.g. to improve cache locality. There is pretty much nothing you can do in pure Rust code to avoid things like that. It's a fraught endeavor. |
You told here that wrapping is a move towards solving the problem(not entirely). So, I tried to show that this doesn't solve the problem at all. Maybe I've misunderstood what you were intending to say. My bad. |
That message concludes:
|
Scalar
holds array of elements that implementCopy
trait. Thus, array gets copied when moved which reveals the value.I have reproduced the issue here: https://gist.github.com/RajeshRk18/eb10e3506c83c196d69116e86e0910e5
I have made
Scalar
field to public to reproduce this issue.Impact:
Whenever an user does operations with its private key, there is a high chance that the private key gets revealed.
Recommendation:
Wrap the byte array with
Box
as cloning theBox
is cheap and now byte array won't be moved.Let the library user decide which Scalar type (Boxed/Unboxed) he will use according to the context.
The text was updated successfully, but these errors were encountered: