Re: Cleanup for cryptographic algorithms vs. compiler optimizations



Ulrich Spörlein <uqs@xxxxxxxxxxxxx> 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
individually.

Alternatively, you can use something like this:

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

DES
--
Dag-Erling Smørgrav - des@xxxxxx
_______________________________________________
freebsd-current@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "freebsd-current-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: Memory alignment
    ... I think you've hit on a glitch in the standard there. ... Use of memset() to zero out memory is well-established, ... struct foo obj; ...
    (comp.lang.c)
  • Re: Cleanup for cryptographic algorithms vs. compiler optimizations
    ... zeroing variables, ... 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 ...
    (freebsd-current)
  • Re: Memory alignment
    ... struct b; ... Use of memset() to zero out memory is well-established, ... will cause a program termination, probably when the structure is accessed, even though ptr isn't written through or read from. ...
    (comp.lang.c)
  • Re: Cleanup for cryptographic algorithms vs. compiler optimizations
    ... of zeroing variables, ... there a canonical way to zero those variables and should we use them ... If you stick these variables in a struct, you can memset the struct ...
    (freebsd-current)
  • Re: Cleanup for cryptographic algorithms vs. compiler optimizations
    ... zeroing variables, ... 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 ... inlined functions are included in the optimizations. ...
    (freebsd-current)