diff options
author | Christoph Müllner <christoph.muellner@vrull.eu> | 2023-01-17 19:31:58 +0100 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2023-03-16 13:12:19 +1100 |
commit | 86c69fe84118f0dca656d9bfc1131052e2a8e9b8 (patch) | |
tree | e753c237e45ffaa2e24f7a4e8877b51fd9120a18 /include | |
parent | 04af51c276e7d785a194eb9ed199abf250c5b3b6 (diff) |
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@vrull.eu>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20078)
Diffstat (limited to 'include')
-rw-r--r-- | include/crypto/aes_platform.h | 3 | ||||
-rw-r--r-- | include/crypto/riscv_arch.h | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/include/crypto/aes_platform.h b/include/crypto/aes_platform.h index 5572e52a43..402727f914 100644 --- a/include/crypto/aes_platform.h +++ b/include/crypto/aes_platform.h @@ -434,7 +434,6 @@ void aes256_t4_xts_decrypt(const unsigned char *in, unsigned char *out, # elif defined(OPENSSL_CPUID_OBJ) && defined(__riscv) && __riscv_xlen == 64 /* RISC-V 64 support */ # include "riscv_arch.h" -# define RV64I_ZKND_ZKNE_CAPABLE (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE()) int rv64i_zkne_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); @@ -447,8 +446,6 @@ void rv64i_zknd_decrypt(const unsigned char *in, unsigned char *out, # elif defined(OPENSSL_CPUID_OBJ) && defined(__riscv) && __riscv_xlen == 32 /* RISC-V 32 support */ # include "riscv_arch.h" -# define RV32I_ZKND_ZKNE_CAPABLE (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE()) -# define RV32I_ZBKB_ZKND_ZKNE_CAPABLE (RV32I_ZKND_ZKNE_CAPABLE && RISCV_HAS_ZBKB()) int rv32i_zkne_set_encrypt_key(const unsigned char *userKey, const int bits, AES_KEY *key); diff --git a/include/crypto/riscv_arch.h b/include/crypto/riscv_arch.h index 89a40bea84..0e0f946ddc 100644 --- a/include/crypto/riscv_arch.h +++ b/include/crypto/riscv_arch.h @@ -56,4 +56,9 @@ static const size_t kRISCVNumCaps = # include "riscv_arch.def" ; +/* Extension combination tests. */ +#define RISCV_HAS_ZBB_AND_ZBC() (RISCV_HAS_ZBB() && RISCV_HAS_ZBC()) +#define RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE() (RISCV_HAS_ZBKB() && RISCV_HAS_ZKND() && RISCV_HAS_ZKNE()) +#define RISCV_HAS_ZKND_AND_ZKNE() (RISCV_HAS_ZKND() && RISCV_HAS_ZKNE()) + #endif |