Cleanup for cryptographic algorithms vs. compiler optimizations

Dag-Erling Smørgrav des at
Fri Jun 11 19:39:41 UTC 2010

Ulrich Spörlein <uqs at> writes:
> optimizing compilers have a tendency to remove assignments that have
> no side effects. The code in sys/crypto/sha2/sha2.c is doing a lot of
> zeroing variables, which is however optimized away.  [...]  Is there a
> canonical way to zero those variables and should we use them (memset
> perhaps? what are the performance implications?)

If you stick these variables in a struct, you can memset the struct to
zero them; if there are many of them, it may be faster than zeroing them

Alternatively, you can use something like this:

#define FORCE_ASSIGN(type, var, value) \
        *(volatile type *)&(var) = (value)

Dag-Erling Smørgrav - des at

More information about the freebsd-current mailing list