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

Secure memory wiping #7

Closed
tiran opened this issue Aug 7, 2013 · 5 comments
Closed

Secure memory wiping #7

tiran opened this issue Aug 7, 2013 · 5 comments

Comments

@tiran
Copy link
Contributor

tiran commented Aug 7, 2013

The patch in http://bugs.python.org/issue17405 might be interesting for cryptography. It contains my research on secure memory wiping and a C89 implementation of C11's memset_s() function.

Quote:
Compilers like GCC optimize away code like memset(var, 0, sizeof(var)) if the code occurs at the end of a function and var is not used anymore [1]. But security relevant code like hash and encryption use this to overwrite sensitive data with zeros.

The code in _sha3module.c uses memset() to clear its internal state. The other hash modules don't clear their internal states yet.

There exists a couple of solutions for the problem:

  • C11 [ISO/IEC 9899:2011] has a memset_s() function
  • MSVC has SecureZeroMemory()
  • GCC can disable the optimization with #pragma GCC optimize ("O0") since GCC 4.4
  • [2] contains an example for a custom implementation of memset_s() with volatile.

[1] http://gcc.gnu.org/bugzilla/show_bug.cgi?id=8537
[2] https://www.securecoding.cert.org/confluence/display/seccode/MSC06-C.+Be+aware+of+compiler+optimization+when+dealing+with+sensitive+data

@dstufft
Copy link
Member

dstufft commented Aug 7, 2013

I'm not sure this is going to be relevant for this. Ideally we won't be writing any crypto ourselves and will just be making an API over top of a backing library like OpenSSL.

@tiran
Copy link
Contributor Author

tiran commented Aug 7, 2013

Most crypto libs don't handle memory management themselves. The application is responsible for allocating and freeing blocks of memory. Usually a consumer of a crypto lib allocates a fixed size buffer on the stack and applies the buffer to a crypto function. The buffer should be whipped with memset_s() afterwards. The page [2] explains it in great detail.

@alex
Copy link
Member

alex commented Aug 7, 2013

Yup, we can add a with secure_wipe(bytes) as c_buffer (better name needed) thing

@reaperhulk reaperhulk added this to the Third Release milestone Feb 18, 2014
@public
Copy link
Member

public commented Mar 22, 2014

We can implement this for bytes yet our asymmetric API relies a lot on large secret ints :-/

@public
Copy link
Member

public commented Mar 25, 2014

I think #845 should close this for now?

@alex alex closed this as completed Mar 25, 2014
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

5 participants