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

Optionally support Zeroize with the right disclaimers #31

Open
AtropineTears opened this issue Nov 27, 2021 · 4 comments
Open

Optionally support Zeroize with the right disclaimers #31

AtropineTears opened this issue Nov 27, 2021 · 4 comments

Comments

@AtropineTears
Copy link

Hello,

I have compiled a list of reasons on why Zeroize Support would be good for this library. This is a continuation of #28 and #29

Reasons

  1. Zeroize Support is supported in top cryptography libraries like a multitude of Dalek's libraries.
  2. Zeroize Support is easy to implement using the Zeroize Derive Trait.
  3. Adding Zeroize Support would make this library stand out better.
  4. Zeroize Support will help others with using your library in a secure manner.
  5. Zeroize is a secure dependency that is well maintained.
  6. You can always add Zeroize as an optional dependency.
  7. It would add a simple .zeroize() method and ability to clear memory on drop

Personal Reasons

My personal reason is that I am developing two cryptography libraries that require Zeroize support. I would really appreciate it if Zeroize was implemented.

@thomwiggers
Copy link
Member

thomwiggers commented Dec 1, 2021

Honestly, I'm not too convinced by the reasons you give. Please forgive me for being a bit blunt here, but I want to make clear that the security gains here can be subtle and don't necessary transfer in the same ways you expect:

  1. Zeroize Support is supported in top cryptography libraries like a multitude of Dalek's libraries.

Dalek implements everything in Rust and might have more control over what they're doing with the variables, secret keys and stack than we do. PQ also has special challenges here, as discussed previously, due to the XXL stack usage. "$other_library does it" doesn't really transfer.

  1. Zeroize Support will help others with using your library in a secure manner.

Does it? If you care about leaking memory values then the stack space used outside of anything Zeroize can cover should be a major concern, and there's not much we can do about this at this point. Indeed, Zeroize might give a false sense of security.

  1. Zeroize Support is easy to implement using the Zeroize Derive Trait.
  2. Adding Zeroize Support would make this library stand out better.
  3. Zeroize is a secure dependency that is well maintained.
  4. You can always add Zeroize as an optional dependency.
  5. It would add a simple .zeroize() method and ability to clear memory on drop

These are not security arguments, but rather arguments about marketing and why it won't be a big maintenance burden. I'm not worried about that.

However, I guess there's a somewhat higher probability that the secret key structs will be heap-allocated, in which case Zeroize might be more helpful than not doing anything. I would merge a PR (you want to be changing pqcrypto-template) that adds it optionally, and it should be accompanied by a relevant piece of text in the READMEs about what Zeroise does and does not supply.

@thomwiggers thomwiggers changed the title [Zeroize-Support] List of Reasons On Why To Implement Zeroize Support Optionally support Zeroize with the right disclaimers Dec 1, 2021
@thomwiggers
Copy link
Member

I am developing two cryptography libraries that require Zeroize support.

Off-topic advice; I would take a careful look at what Zeroize does and does not protect in your particular usecase and what promises you make about that. Managing memory is hard :)

@AtropineTears
Copy link
Author

Thank you for the thorough response. I will look into learning more about Zeroize and other related information before proceeding. Much appreciated.

@niluxv
Copy link

niluxv commented Apr 26, 2022

The main thing to worry about is probably secret memory being swapped out (to potentially unencrypted swap). The only proper solution is that the user configures ephemerally encrypted swap. (Although it is probably more likely for the heap to get swapped out, the stack could be swapped too, and as pointed out zeroizing the stack is not really possible.)

In any case, @AtropineTears, if you allocate secrets on the heap it might make sense to use a special "secure" allocator, like the one in libsodium. Such allocators do not only zeroize on deallocation, but will also ask the operating system nicely whether it could consider to not swap the memory out. (I have written something similar in rust but that is too much WIP to recommend.)

And note that even without support from this library you could just create a newtype wrapper around a secret key and implement zeroize on drop for that.

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

3 participants