[openssl/openssl] 326af4: bn_nist: replace pointer bit-fiddling with ternary

Alois Klink noreply at github.com
Mon Apr 17 22:07:52 UTC 2023


  Branch: refs/heads/master
  Home:   https://github.com/openssl/openssl
  Commit: 326af4ad171b849ba1e76fd425d8f337718c4108
      https://github.com/openssl/openssl/commit/326af4ad171b849ba1e76fd425d8f337718c4108
  Author: Alois Klink <alois at aloisklink.com>
  Date:   2023-04-16 (Sun, 16 Apr 2023)

  Changed paths:
    M crypto/bn/bn_nist.c

  Log Message:
  -----------
  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 at openssl.org>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20748)


  Commit: f659f7a1c70709caa1727bb0b7f836d170d35bb5
      https://github.com/openssl/openssl/commit/f659f7a1c70709caa1727bb0b7f836d170d35bb5
  Author: Alois Klink <alois at aloisklink.com>
  Date:   2023-04-16 (Sun, 16 Apr 2023)

  Changed paths:
    M crypto/bn/bn_nist.c

  Log Message:
  -----------
  bn_nist: remove unused type-punning union `u`

We no longer need to cast function pointers to PTR_SIZE_INT.

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


  Commit: dcfeb617477dd957f69e713cbc61fd4dca0f2db4
      https://github.com/openssl/openssl/commit/dcfeb617477dd957f69e713cbc61fd4dca0f2db4
  Author: Alois Klink <alois at aloisklink.com>
  Date:   2023-04-16 (Sun, 16 Apr 2023)

  Changed paths:
    M crypto/bn/bn_local.h

  Log Message:
  -----------
  bn_local: remove unused `PTR_SIZE_INT` definition

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


Compare: https://github.com/openssl/openssl/compare/8835940db582...dcfeb617477d


More information about the openssl-commits mailing list