<div dir="ltr">Hi All,<div><br></div><div>1. With compiler optimization disabled, OpenSSL 1.0.2d function worked as it is. <br></div><div>2. Looks like in the below functions, typecast to unsigned char to is not going well when compiler optimization is enabled. Hence functions are modified to assign the return value to a volatile unsigned char and then return the volatile value. Things worked fine.</div><div><br></div><div>static inline unsigned char constant_time_lt_8(unsigned int a, unsigned int b)<br></div><div>static inline unsigned char constant_time_ge_8(unsigned int a, unsigned int b)</div><div>static inline unsigned char constant_time_is_zero_8(unsigned int a)</div><div>static inline unsigned char constant_time_eq_8(unsigned int a, unsigned int b)</div><div>static inline unsigned char constant_time_eq_int_8(int a, int b)</div><div>static inline unsigned char constant_time_select_8(unsigned char mask,</div><div><br></div><div>Matt, Jakob, Andy your explanations were really useful to route cause the issue to compiler specific. Thanks every one for the valuable time and fruitful discussion. </div><div><br></div><div>Regards</div><div>Jaya</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Dec 13, 2015 at 11:13 AM, Jayalakshmi bhat <span dir="ltr"><<a href="mailto:bhat.jayalakshmi@gmail.com" target="_blank">bhat.jayalakshmi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><p class="MsoNormal">Hi All,</p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Thanks for all the responses. As mentioned by Matt in the discussion
thread,constant_time_msb performs the copy the msb of the input to
all of the other bits so the return value should either be one of 0x00000000
or  0xffffffff.</p><p class="MsoNormal"></p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">I found another interesting thing,constant_time_msb worked
as it is without any changes, after I added a printf in
constant_time_is_zero_8 test routine to print the return value. I added the printf
just before comparing the return value with the expected value.</p><p class="MsoNormal"></p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">I have confirmed the failures by removing the printf and
printing any thing else other than the returned value.</p><p class="MsoNormal"></p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">Now based on the discussions here and print results I am
thinking, after constant_time_msb operation probably overflow bit is set in case of 0xffffffff.
And it is not cleared before comparing, hence compare fails. When I add a
printf to print the return value probably overflow flag got cleared and
things worked.</p><p class="MsoNormal"></p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">I am planning to attach the debugger to check the flags. I
will get back with debugger results.</p><p class="MsoNormal"></p>

<p class="MsoNormal"> </p>

<p class="MsoNormal">I have attached the test file.</p>

<p class="MsoNormal"> </p><p class="MsoNormal">Regards</p><p class="MsoNormal">Jaya</p>

<p class="MsoNormal"> </p></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 11, 2015 at 11:30 AM, Jeffrey Walton <span dir="ltr"><<a href="mailto:noloader@gmail.com" target="_blank">noloader@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>> 3. The compiler wasn't written by a fanatic who put<br>
>   the "right shift of negative signed values is<br>
>   undefined" rule above common sense.<br>
><br>
> This is only implementation-defined behavior, not undefined behavior.  It is<br>
> not permitted to crash the system or launch the missiles.  (n1256.pdf 6.5.7<br>
> paragraph 5.)<br>
<br>
</span>The potential problem with implementation defined is its not<br>
guaranteed to produce consistent results. Different compilers or<br>
different versions of the same compiler may arrive at different<br>
results.<br>
<br>
In this light, the crash might be welcomed to make it easy to find the<br>
trouble spot :)<br>
<div><div>_______________________________________________<br>
openssl-users mailing list<br>
To unsubscribe: <a href="https://mta.openssl.org/mailman/listinfo/openssl-users" rel="noreferrer" target="_blank">https://mta.openssl.org/mailman/listinfo/openssl-users</a><br>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>