-
Notifications
You must be signed in to change notification settings - Fork 271
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
Zeroing out secrets #102
Zeroing out secrets #102
Conversation
BTW, I see that some times you use |
This sounds like a good idea to me (even though it's not perfect).
This sounds like a bad idea at first glance, also because it has the potential to break downstream code. But maybe it's not even a bad thing if we want to promote safe code: If you want be careful with your secrets (e.g., and want them to be zeroed out in memory after usage), then you'll need to be careful when assigning them to other variables. I'm not sure if I like that change or not to be honest.
Well, at those code locations we assume that our code ensures that the call FFI function such that will always work. In other words: If the FFI call fails, this is either a bug in our code or in secp256k1, but it has nothing to do with code calling rust-secp256k1 functions. So there is no reason to signal an error to the library user, these calls are not supposed to fail. |
@real-or-random Yeah, example: https://play.rust-lang.org/?gist=404181cf18a18bcc2fee5bdd04acd6b7 |
I know we don't like dependencies too much but zeroize sounds like the right approach and it's small enough to pin a version / review changes from time to time. re pinning memory: I don't see how this is related to secure zeroing. Do you have a specific scenario in mind? |
@real-or-random This wouldn't be possible if the memory was pinned: (Assuming I understand the Pin API correctly) i.e. the same but with a Box: (meaning the memory of the secret it self won't be moved) |
Semantically I believe the compiler is smart enough in this case to just construct the original BTW, we can't use |
I'm very ambivalent about this PR. Getting rid of |
I think I think that the only problem with |
Drop is definitely not guaranteed to run. In addition to the things you describe, you can call |
You're right. |
@apoelstra Any idea how an Pinnable version of |
Every time I try to do this I conclude it's simply impossible. |
After playing a lot with (so in my library for example the secrets are only on the heap) |
I think I'm going to concept NAK this PR. It is a very incomplete solution and sends the following misleading messages:
It also hurts usability, which may imply increased security to the more Puritan-minded of our users.. |
Yeah I now(after seeing that without heap it's not a real option to do this correctly) think it might be better for the user of the library to pin and implement this himself. |
Agreed, this is too incomplete. Feel free to discuss this further, but I'm closing for now. |
Hi,
I Implemented the
Drop
trait toSecretKey
andSharedSecret
withwrite_volatile
to zero out the structs when they get dropped.this should be essentially the same as
memset_s
meaning the compiler shouldn't optimize this out (https://doc.rust-lang.org/std/ptr/fn.write_volatile.html)For this I had to remove the Copy trait because Copy types can't implement Drop.