Thread (5 messages) 5 messages, 3 authors, 2017-03-31

Re: [PATCH] crypto: gf128mul - define gf128mul_x_ble in gf128mul.h

From: Ondrej Mosnáček <omosnacek@gmail.com>
Date: 2017-03-31 09:17:35

Hi Jeff,

2017-03-31 8:05 GMT+02:00 Jeffrey Walton [off-list ref]:
quoted
quoted
Also note that '(b & ((u64)1 << 63)) ? 0x87 : 0x00;' is actually getting
compiled as '((s64)b >> 63) & 0x87', which is branchless and therefore makes the
new version more efficient than one might expect:

        sar    $0x3f,%rax
        and    $0x87,%eax

It could even be written the branchless way explicitly, but it shouldn't matter.
I think the definition using unsigned operations is more intuitive...
Let's just leave the clever tricks up to the compiler :)
It may be a good idea to use the one that provides constant time-ness
to help avoid leaking information.
That's a good point... I played around with various ways to write the
expression in Compiler Explorer [1] and indeed GCC fails to produce
constant-time code from my version on some architectures (e.g. the
32-bit ARM). The version with an explicit arithmetic right shift seems
to produce the most efficient code across platforms, so I'll rewrite
it like that for v3.

Thanks,
O.M.

[1] https://gcc.godbolt.org/
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help