CVSROOT:        /cvs
Module name:    src
Changes by:     js...@cvs.openbsd.org   2022/05/07 01:47:24

Modified files:
        lib/libcrypto/bn: bn_nist.c 

Log message:
Avoid strict aliasing violations in BN_nist_mod_*()

The optimised code path switches from processing data via unsigned long to
processing data via unsigned int, which requires type punning. This is
currently attempted via a union (for one case), however this fails since
a pointer to a union member is passed to another function (these unions
were added to "fix strict-aliasing compiler warning" - it would seem the
warnings stopped but the undefined behaviour remained). The second case
does not use a union and simply casts from one type to another.

Undefined behaviour is currently triggered when compiling with clang 14
using -03 and -fstrict-aliasing, while disabling assembly (in order to use
this C code). The resulting binary produces incorrect results.

Avoid strict aliasing violations by copying from an unsigned long array to
an unsigned int array, then copying back the result. Any sensible compiler
will omit the copies, while avoiding undefined behaviour that would result
from unsafe type punning via pointer type casting.

Thanks to Guido Vranken for reporting the issue and testing the fix.

ok tb@

Reply via email to