[openssl/openssl] 86c69f: riscv: Clean up extension test macros

Christoph Müllner noreply at github.com
Thu Mar 16 02:14:30 UTC 2023


  Branch: refs/heads/master
  Home:   https://github.com/openssl/openssl
  Commit: 86c69fe84118f0dca656d9bfc1131052e2a8e9b8
      https://github.com/openssl/openssl/commit/86c69fe84118f0dca656d9bfc1131052e2a8e9b8
  Author: Christoph Müllner <christoph.muellner at vrull.eu>
  Date:   2023-03-16 (Thu, 16 Mar 2023)

  Changed paths:
    M crypto/modes/gcm128.c
    M include/crypto/aes_platform.h
    M include/crypto/riscv_arch.h
    M providers/implementations/ciphers/cipher_aes_ccm_hw.c
    A providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i.inc
    R providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i_zknd_zkne.inc
    A providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i.inc
    R providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i_zknd_zkne.inc
    M providers/implementations/ciphers/cipher_aes_gcm_hw.c
    A providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i.inc
    R providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i_zknd_zkne.inc
    A providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i.inc
    R providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i_zknd_zkne.inc
    M providers/implementations/ciphers/cipher_aes_hw.c
    A providers/implementations/ciphers/cipher_aes_hw_rv32i.inc
    R providers/implementations/ciphers/cipher_aes_hw_rv32i_zknd_zkne.inc
    A providers/implementations/ciphers/cipher_aes_hw_rv64i.inc
    R providers/implementations/ciphers/cipher_aes_hw_rv64i_zknd_zkne.inc
    M providers/implementations/ciphers/cipher_aes_ocb_hw.c
    M providers/implementations/ciphers/cipher_aes_xts_hw.c

  Log Message:
  -----------
  riscv: Clean up extension test macros

In RISC-V we have multiple extensions, that can be
used to accelerate processing.
The known extensions are defined in riscv_arch.def.
>From that file test functions of the following
form are generated: RISCV_HAS_$ext().

In recent commits new ways to define the availability
of these test macros have been defined. E.g.:
  #define RV32I_ZKND_ZKNE_CAPABLE   \
          (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())
  [...]
  #define RV64I_ZKND_ZKNE_CAPABLE   \
          (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE())

This leaves us with two different APIs to test capabilities.
Further, creating the same macros for RV32 and RV64 results
in duplicated code (see example above).

This inconsistent situation makes it hard to integrate
further code. So let's clean this up with the following steps:
* Replace RV32I_* and RV64I_* macros by RICSV_HAS_* macros
* Move all test macros into riscv_arch.h
* Use "AND" and "OR" to combine tests with more than one extension
* Rename include files for accelerated processing (remove extension
  postfix).

We end up with compile time tests for RV32/RV64 and run-time tests
for available extensions. Adding new routines (e.g. for vector crypto
instructions) should be straightforward.

Testing showed no regressions.

Signed-off-by: Christoph Müllner <christoph.muellner at vrull.eu>

Reviewed-by: Tomas Mraz <tomas at openssl.org>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20078)


  Commit: c8a641c39f524051900feac7175ca7300f151f85
      https://github.com/openssl/openssl/commit/c8a641c39f524051900feac7175ca7300f151f85
  Author: Christoph Müllner <christoph.muellner at vrull.eu>
  Date:   2023-03-16 (Thu, 16 Mar 2023)

  Changed paths:
    M crypto/aes/asm/aes-riscv64-zkn.pl
    A crypto/perlasm/riscv.pm

  Log Message:
  -----------
  riscv: aes: Move reusable Perl code into Perl module

Move helper functions and instruction encoding functions
into a riscv.pm Perl module to avoid pointless code duplication.

Signed-off-by: Christoph Müllner <christoph.muellner at vrull.eu>

Reviewed-by: Tomas Mraz <tomas at openssl.org>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20078)


  Commit: ac97cd6005878700653d8e50b6e7319728c523a1
      https://github.com/openssl/openssl/commit/ac97cd6005878700653d8e50b6e7319728c523a1
  Author: Christoph Müllner <christoph.muellner at vrull.eu>
  Date:   2023-03-16 (Thu, 16 Mar 2023)

  Changed paths:
    M crypto/perlasm/riscv.pm

  Log Message:
  -----------
  riscv.pm: Add improved error messages to read_reg code

On systems where Devel::StackTrace is available, we can use this module
to create more usable error messages. Further, don't print error
messages in case of official register aliases, but simply accept them.

Signed-off-by: Christoph Müllner <christoph.muellner at vrull.eu>

Reviewed-by: Tomas Mraz <tomas at openssl.org>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20078)


  Commit: 75623ed8d01555e7c719f3b1c598e555c0878da0
      https://github.com/openssl/openssl/commit/75623ed8d01555e7c719f3b1c598e555c0878da0
  Author: Christoph Müllner <christoph.muellner at vrull.eu>
  Date:   2023-03-16 (Thu, 16 Mar 2023)

  Changed paths:
    M crypto/modes/asm/ghash-riscv64.pl
    M crypto/perlasm/riscv.pm

  Log Message:
  -----------
  riscv: GCM: Use riscv.pm

A recent commit introduced a Perl module for common code.
This patch changes the GCM code to use this module, removes duplicated code,
and moves the instruction encoding functions into the module.

Signed-off-by: Christoph Müllner <christoph.muellner at vrull.eu>

Reviewed-by: Tomas Mraz <tomas at openssl.org>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20078)


  Commit: b24684369b76df8b226fe9aa95fca2bccfc6a175
      https://github.com/openssl/openssl/commit/b24684369b76df8b226fe9aa95fca2bccfc6a175
  Author: Christoph Müllner <christoph.muellner at vrull.eu>
  Date:   2023-03-16 (Thu, 16 Mar 2023)

  Changed paths:
    M crypto/modes/asm/ghash-riscv64.pl
    M crypto/modes/gcm128.c
    M crypto/perlasm/riscv.pm

  Log Message:
  -----------
  riscv: GCM: Simplify GCM calculation

The existing GCM calculation provides some potential
for further optimizations. Let's use the demo code
from the RISC-V cryptography extension groups
(https://github.com/riscv/riscv-crypto), which represents
the extension architect's intended use of the clmul instruction.

The GCM calculation depends on bit and byte reversal.
Therefore, we use the corresponding instructions to do that
(if available at run-time).

The resulting computation becomes quite compact and passes
all tests.

Note, that a side-effect of this change is a reduced register
usage in .gmult(), which opens the door for an efficient .ghash()
implementation.

Signed-off-by: Christoph Müllner <christoph.muellner at vrull.eu>

Reviewed-by: Tomas Mraz <tomas at openssl.org>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20078)


  Commit: f3fed0d5fc11a3406951884b9739a93639697a56
      https://github.com/openssl/openssl/commit/f3fed0d5fc11a3406951884b9739a93639697a56
  Author: Christoph Müllner <christoph.muellner at vrull.eu>
  Date:   2023-03-16 (Thu, 16 Mar 2023)

  Changed paths:
    M crypto/modes/asm/ghash-riscv64.pl
    M crypto/modes/gcm128.c

  Log Message:
  -----------
  riscv: GCM: Implement GHASH()

RISC-V currently only offers a GMULT() callback for accelerated
processing. Let's implement the missing piece to have GHASH()
available as well. Like GMULT(), we provide a variant for
systems with the Zbkb extension (including brev8).

The integration follows the existing pattern for GMULT()
in RISC-V. We keep the C implementation as we need to decide
if we can call an optimized routine at run-time.
The C implementation is the fall-back in case we don't have
any extensions available that can be used to accelerate
the calculation.

Tested with all combinations of possible extensions
on QEMU (limiting the available instructions accordingly).
No regressions observed.

Signed-off-by: Christoph Müllner <christoph.muellner at vrull.eu>

Reviewed-by: Tomas Mraz <tomas at openssl.org>
Reviewed-by: Paul Dale <pauli at openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20078)


Compare: https://github.com/openssl/openssl/compare/04af51c276e7...f3fed0d5fc11


More information about the openssl-commits mailing list