3 ms·
Why wouldn't you make key volatile? Shouldn't that solve all the problems? Or is it because it would be to slow because the compiler can't do that many optimiza
by Genmutant 12y ago
Why wouldn't you make key volatile? Shouldn't that solve all the problems? Or is it because it would be to slow because the compiler can't do that many optimizations in the rest of the function any more?
- cperciva 12y agoYes, making key volatile would force the zeroing to happen; and yes, you don't want to do that because it would absolutely kill your code performance.
- theseoafs 12y agoCan't you just cast it to a `volatile uint8_t *` at some later point when you need to ensure that we've zeroed the memory?
- mikeash 12y agoThat's discussed in the article. Volatile ultimately applies to the storage, so a sufficiently smart compiler may be able to deduce that you're lying to it with the cast and elide the write.
- jbert 12y agoCan you play the game the other way and "fail safe"? i.e. declare the storage volatile but running your crypto code on a non-volatile ptr to it (obtained via cast) to get your performance back? If the compiler then generates enough smarts to work out that the non-volatile ptr you've passed into your crypto code is referring to volatile storage, then you keep security but get a (noticeable in testing?) performance hit. I guess that's not as good as your solution though.