Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-14 Thread Tijl Coosemans
On Friday 11 June 2010 23:31:57 Dag-Erling Smørgrav wrote: > Tijl Coosemans writes: >> Dag-Erling Smørgrav writes: >>> #define FORCE_ASSIGN(type, var, value) \ >>> *(volatile type *)&(var) = (value) >> memset can be optimised away as well. The only way is to declare >> those variables vol

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-14 Thread Dag-Erling Smørgrav
Bernd Walter writes: > Dag-Erling Smørgrav writes: > > Those are freestanding environments, where printf() and puts() don't > > exist as far as the C standard is concerned. > Most controller environments have some kind of libc. They are still freestanding environments. Can we agree not to discu

Re: Protecting sensitive data [was Re: Cleanup for cryptographic algorithms vs. compiler optimizations]

2010-06-13 Thread C. P. Ghost
2010/6/14 Peter Jeremy : > On 2010-Jun-13 10:07:15 +0200, Dag-Erling Smørgrav wrote: >>You always overwrite passphrases, keys etc. as soon as you're done with >>them so they don't end up in a crash dump or on a swap disk or >>something. > > Which brings up an associated issue: By default, mlock(2)

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread C. P. Ghost
On Sun, Jun 13, 2010 at 11:35 PM, Bernd Walter wrote: > Crypto code wasn't aware of this problem and this is a way more > obviuous optimization than function exchange. > And I do believe that the programmers were clever people. > Alarming, isn't it? > Maybe paranoid users might consider compiling

Protecting sensitive data [was Re: Cleanup for cryptographic algorithms vs. compiler optimizations]

2010-06-13 Thread Peter Jeremy
On 2010-Jun-13 10:07:15 +0200, Dag-Erling Smørgrav wrote: >You always overwrite passphrases, keys etc. as soon as you're done with >them so they don't end up in a crash dump or on a swap disk or >something. Which brings up an associated issue: By default, mlock(2) can only be used by root process

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Bernd Walter
On Sun, Jun 13, 2010 at 11:41:03PM +0200, Dag-Erling Smørgrav wrote: > Bernd Walter writes: > > Dag-Erling Smørgrav writes: > > > The only way you can tell that gcc did it is if you break the rules, > > > such as by defining your own version of printf() or puts(). > > Our loader stages do this fo

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Patrick Lamaiziere
Le Sun, 13 Jun 2010 23:35:12 +0200, Bernd Walter a écrit : > Go back to the originating mail. > Crypto code wasn't aware of this problem and this is a way more > obviuous optimization than function exchange. > And I do believe that the programmers were clever people. > Alarming, isn't it? The re

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Dag-Erling Smørgrav
Bernd Walter writes: > Dag-Erling Smørgrav writes: > > The only way you can tell that gcc did it is if you break the rules, > > such as by defining your own version of printf() or puts(). > Our loader stages do this for good reasons. And in microcontroller > programming (surely out of FreeBSD sc

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Bernd Walter
On Mon, Jun 14, 2010 at 02:20:26AM +1000, Andrew Milton wrote: > +---[ Bernd Walter ]-- > | On Sun, Jun 13, 2010 at 05:44:29PM +0200, Dag-Erling Smørgrav wrote: > | > Bernd Walter writes: > | > > Amazing - this is one of the things which can get nasty if you try some > | >

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Bernd Walter
On Sun, Jun 13, 2010 at 06:14:11PM +0200, Dag-Erling Smørgrav wrote: > Bernd Walter writes: > > Dag-Erling Smørgrav writes: > > > Bernd Walter writes: > > > > Amazing - this is one of the things which can get nasty if you try > > > > some kind of microtuning. > > > Only if you break the rules.

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Andrew Milton
+---[ Bernd Walter ]-- | On Sun, Jun 13, 2010 at 05:44:29PM +0200, Dag-Erling Smørgrav wrote: | > Bernd Walter writes: | > > Amazing - this is one of the things which can get nasty if you try some | > > kind of microtuning. | > | > Only if you break the rules. Bad code is

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Dag-Erling Smørgrav
Bernd Walter writes: > Dag-Erling Smørgrav writes: > > Bernd Walter writes: > > > Amazing - this is one of the things which can get nasty if you try > > > some kind of microtuning. > > Only if you break the rules. Bad code is always bad, even if it > > sometimes works by accident. > To expect t

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Bernd Walter
On Sun, Jun 13, 2010 at 05:44:29PM +0200, Dag-Erling Smørgrav wrote: > Bernd Walter writes: > > Amazing - this is one of the things which can get nasty if you try some > > kind of microtuning. > > Only if you break the rules. Bad code is always bad, even if it > sometimes works by accident. To

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Dag-Erling Smørgrav
Bernd Walter writes: > Amazing - this is one of the things which can get nasty if you try some > kind of microtuning. Only if you break the rules. Bad code is always bad, even if it sometimes works by accident. DES -- Dag-Erling Smørgrav - d...@des.no __

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Bernd Walter
On Sun, Jun 13, 2010 at 12:44:03PM +0200, Matthias Andree wrote: > Am 13.06.2010, 00:52 Uhr, schrieb Bernd Walter: > > >>In more general terms, the compiler is allowed to make any changes it > >>likes to the program as long as the end result behaves exactly like it > >>would if it hadn't been chan

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Matthias Andree
Am 13.06.2010, 00:52 Uhr, schrieb Bernd Walter: In more general terms, the compiler is allowed to make any changes it likes to the program as long as the end result behaves exactly like it would if it hadn't been changed. This is called the "as if" rule. For instance, if you call printf() or f

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Bernd Walter
On Sun, Jun 13, 2010 at 12:17:50AM +, Bruce Cran wrote: > On Sun, Jun 13, 2010 at 12:52:16AM +0200, Bernd Walter wrote: > > I'm at least sure that the compiler can't if it is linked from another > > object file. > > Is that still true if LTO is enabled? Good question - I wasn't aware of LTO.

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-13 Thread Dag-Erling Smørgrav
Bernd Walter writes: > Dag-Erling Smørgrav writes: > > Bernd Walter writes: > > > I'm not sure when removing a memset is allowed. > > Always, if the compiler can determine that the data will not be used > > later. > I'm at least sure that the compiler can't if it is linked from another > object

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-12 Thread Bruce Cran
On Sun, Jun 13, 2010 at 12:52:16AM +0200, Bernd Walter wrote: > I'm at least sure that the compiler can't if it is linked from another > object file. Is that still true if LTO is enabled? -- Bruce Cran ___ freebsd-current@freebsd.org mailing list http:

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-12 Thread James R. Van Artsdalen
Bernd Walter wrote: > But calling my_abolsutely_not_inlineable_memset should work IMHO. Try gcc -fno-builtin-memset ___ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "f

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-12 Thread Bernd Walter
On Sat, Jun 12, 2010 at 07:35:26PM +0200, Dag-Erling Smørgrav wrote: > Bernd Walter writes: > > I'm not sure when removing a memset is allowed. > > Always, if the compiler can determine that the data will not be used > later. I'm at least sure that the compiler can't if it is linked from another

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-12 Thread Dag-Erling Smørgrav
Bernd Walter writes: > I'm not sure when removing a memset is allowed. Always, if the compiler can determine that the data will not be used later. In more general terms, the compiler is allowed to make any changes it likes to the program as long as the end result behaves exactly like it would if

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-12 Thread Bernd Walter
On Sat, Jun 12, 2010 at 05:35:28PM +0200, Ulrich Spörlein wrote: > On Fri, 11.06.2010 at 21:37:29 +0200, Dag-Erling Smørgrav wrote: > > Ulrich Spörlein writes: > > > optimizing compilers have a tendency to remove assignments that have > > > no side effects. The code in sys/crypto/sha2/sha2.c is do

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-12 Thread Ulrich Spörlein
On Fri, 11.06.2010 at 21:37:29 +0200, Dag-Erling Smørgrav wrote: > Ulrich Spörlein 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. [..

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-11 Thread Dag-Erling Smørgrav
Tijl Coosemans writes: > Dag-Erling Smørgrav writes: > > #define FORCE_ASSIGN(type, var, value) \ > > *(volatile type *)&(var) = (value) > memset can be optimised away as well. The only way is to declare those > variables volatile. Assigning through a volatile pointer, as in FORCE_ASSIGN

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-11 Thread Tijl Coosemans
On Friday 11 June 2010 21:37:29 Dag-Erling Smørgrav wrote: > Ulrich Spörlein 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 >>

Re: Cleanup for cryptographic algorithms vs. compiler optimizations

2010-06-11 Thread Dag-Erling Smørgrav
Ulrich Spörlein 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