Zeroing memory on free

I have some code which handles sensitive data. I’m manually zeroing important items using std.crypto.secureZero(), but eventually I’m going to forget something.

All of my allocations are made in a per-session arena allocator, is there a way I can get at the arena before destruction and just zero it entirely?

I can see how to do this with a FixedBufferAllocator, but then I lose dynamic sizing. Perhaps there’s a way to hook an allocator to zero as each item is freed?

1 Like

The language cannot handle this use case correctly until something like this is implemented.

5 Likes

This whole issue thread is fascinating, even if I don’t understand all of the detail.

From a pragmatic point of view, I was planning to handle this app-side rather than relying on the language by adding small randomised delays around crypto operations to help prevent timing attacks.

I am not a crypto/security expert, and certainly won’t be making claims about the real-world safety of my code. However, I’m finding std.crypto (mostly) very capable and understandable for my uses.

Regardless, my original question was about zeroing memory automatically on free. I’ve just stumbled on this great set of example allocators which I think explains most of what I need GitHub - nektro/gimme: A yummy collection of useful Allocators.

5 Likes