Hacker News new | past | comments | ask | show | jobs | submit login

If you say "foo + 3", and foo is a uint8_t, then 3 is technically an int, so the addition will do an integer promotion.

If you say "foo + bar" and both are uint8_t, then both will be promoted to integer. That's how C works. Assigning the result to another uint8_t will truncate it.

Please do not write your own crypto library until you really understand how C works, especially including this kind of detail.




I understand the issue, but not the explanation.

Your example is different, this is because you're doing an addition. I can see how this could be a problem if you want to do a rotation (a << 4) + (a >> 60) and hence why you should use a ^ instead of a + here (example: https://github.com/gvanas/KeccakCodePackage/blob/master/SnP/... )


6.5.7.3 of the C99 standard specifies that each operand of a bit shift first undergoes integer promotion.


yesh! Alright I see the issue. This `int` then gets sign extended to a 64-bit register.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: