3 ms·
Not sure if types will force the compiler to do things like constant time comparisons and overwrite sensitive information as it goes out of scope. I think Java
by Gibbon1 9y ago
Not sure if types will force the compiler to do things like constant time comparisons and overwrite sensitive information as it goes out of scope.
I think Java, C#, and C/C++ the compiler will decide that code to clear memory just before it goes out of scope has no side effects and optimize that code away.
- zenhack 9y agoYou can definitely rig up the erasure to happen in a destructor (C++) or Drop implementation (Rust). Convincing the compiler not to optimize it out is tricky, but many cryptographic libraries include that functionality. The c11 standard has a memset_s function with the right semantics, but there are other ways to implement it. Re: constant time operations, I don't know of any language or system that does this currently. But a while back I was kicking around the idea with a friend and we came to a design that I'm pretty sure would work. Never got around to implementation though; so many projects, so little time.
- chriswarbo 9y agoWe can absolutely use types to ensure that our algorithms are constant time, e.g. https://www.usenix.org/conference/usenixsecurity16/technical-sessions/presentation/almeida https://www.usenix.org/conference/usenixsecurity16/technical... We can use types to enforce the big-O runtime of our functions too, e.g. ensuring that a mergesort implementation runs in O(nlogn) steps: https://www.twanvl.nl/blog/agda/sorting https://www.twanvl.nl/blog/agda/sorting I have no idea about doing these things in Java/C/C++/C# though; anything we try to enforce can be trivially broken by `NULL` :(