bn_nist: replace pointer bit-fiddling with ternary
authorAlois Klink <alois@aloisklink.com>
Sun, 16 Apr 2023 14:40:01 +0000 (15:40 +0100)
committerAlois Klink <alois@aloisklink.com>
Sun, 16 Apr 2023 15:45:21 +0000 (16:45 +0100)
commit326af4ad171b849ba1e76fd425d8f337718c4108
tree6b53a6c13812e1a1a6c3539811088498a3a35728
parent8835940db58229fc467cdea1eebf3f064352a086
bn_nist: replace pointer bit-fiddling with ternary

Bit-fiddling pointers is technically implementation defined behavior
in the C specification so the following code is not supported in all
platforms:

    PTR_SIZE_INT mask;
    void * a, b, c;
    int boolean_flag;

    mask = 0 - boolean_flag;
    /* Not guaranteed to be a valid ptr to a or b on all platforms  */
    a = (void *)
        ((((PTR_SIZE_INT) b & ~mask) | (((PTR_SIZE_INT)) c & mask)));

Using a ternary conditional operator is supported on all platforms
(i.e. `a = boolean_flag ? b : c;`).

On most modern compilers/CPUs, this will be faster, since it will
get converted to a CMOV instruction.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20748)
crypto/bn/bn_nist.c