[1]https://fsharpforfunandprofit.com/series/designing-with-type...
https://engineering.foursquare.com/going-rogue-part-2-phanto...
Extending that, passing a secure type to an insecure function should result in a warning at least.
log_printf( password.cleartext()); // error
log_printf( password.safehash()); // okayYour comment reminded me of taint mode in Perl. https://perldoc.perl.org/perlsec.html#Taint-mode
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.
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.
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
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` :(
Assuming we’re talking about Scala and not C.
https://www.theverge.com/2018/5/3/17316684/twitter-password-...
Introducing a separate type for passwords doesn’t solve this issue.
Whether it's a password or an "unparsed client data" structure or whatever.
I find this exciting from a problem-solving point of view, because for one, this is potentially a hard, ground-shifting problem. And on the other hand, languages like scala, haskell or rust have the tools to make this kind of requirements simple. There's an interesting time coming.
And in a language with deconstructors, you can remove the secret from memory after it has been used. This in turn reduces the window of vulnerability against memory disclosure attacks, especially in shared virtualized environments.