Re:SSH gets protection against side-channel attacks
by cesarb on Friday June 21, 2019 @10:15AM
(#20242664)
> Compilers these days are very good at detecting "dummy" memsets to memory that's never read afterwards and optimize them away. You have to use some dirty tricks to get the compiler to do what you want (copious amounts of volatile helps).
Or you can use explicit_bzero(), which is designed for that use case.
Re:SSH gets protection against side-channel attacks
by loeg on Friday June 21, 2019 @10:45AM
(#20242906)
Sure, although this is a non-standard and potentially non-portable extension. memset_s in Annex K is standard, but all of Annex K is optional, and like the rest of Annex K, it has an awful interface.
Re:SSH gets protection against side-channel attacks
by rurban on Saturday June 22, 2019 @10:08AM
(#20249618)
explicit_bzero or SecureZeroMemory are all insecure against those new sidechannel attacks we are talking about here.
Only memset_s is.
You really need a mfence (full memory barrier), not just a compiler barrier, maybe even a clflush.
Re:SSH gets protection against side-channel attacks
by nickpsecurity on Friday June 21, 2019 @11:59AM
(#20243671)
You might find this paper interesting in regard to memsets optimized away:
https://www.usenix.org/system/files/conference/usenixsecurit...
I agree with you on a standard platform. Id get a company like Galois to build it. They already have and open-sourced the necessary tooling from thrir prior contracts.
There's also the problem of making sure that your internal API is sound and doesn't copy the key around. In languages like C it's relatively easy to achieve (because copying a buffer in C normally requires some explicit code) but in higher level languages you might easily mistakenly pass the key object by copy instead of reference, leaving some duplicate of the sensitive information in some other location in RAM.
I think there really should be some kind of industry-standard multiplatform library meant to deal with secret keys that would implement all that behind the scenes and offer a simple API. It's simply too easy to make a dumb mistake when implementing these things, and you won't notice anything is wrong until somebody attempts to actually recover the key somehow.