[Cryptography] Exotic Operations in Primitive Construction

Nemo nemo at self-evident.org
Thu Oct 1 13:21:32 EDT 2020


John Denker <jsd at av8n.com> writes:

> It is hard to imagine a subtle bug in shift or rotate.  (There are
> ways of misusing the instructions, but they're not subtle.)

Ever try left-shifting an int by 32 on x86? (Hint: x86 only uses the low
5 bits of the shift count.)

This is why left-shift by the word size is undefined behavior in C, and
thus ((x)<<(b)|(x>>(32-b))) is technically only valid for 0 < b < 32.

I suppose whether this is "subtle" is a matter of opinion.

 - Nemo


More information about the cryptography mailing list