3 ms·
What if one made some trivial use of the block of memory after having performed the memset, say something like this: void dosomethingsensitive(void) {
by pwg 12y ago
What if one made some trivial use of the block of memory after having performed the memset, say something like this:
void
dosomethingsensitive(void)
{
uint8_t key[32];
...
/* Zero sensitive information. */
memset((volatile void *)key, 0, sizeof(key));
key[0] = key[1] + 1;
}
Would that thwart the optimizer, or would it also see through that usage and eliminate it as well?
- cperciva 12y agoThat just creates another dead store which will get eliminated.
- DSMan195276 12y agoYou should keep in mind that the memset call is almost guarenteed to be inlined. So your code actually looks like this: void dosomethingsensitive(void) { uint8_t key[32]; /* ... */ int i; for (i = 0; i < 32; i++) key[i] = 0; key[0] = key[1] + 1; } Assuming the optimizer is sufficiently smart, then it'll remove that 'for' and it'll remove the addition after it in the same fashion.