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 /providers | |
parent | 04af51c276e7d785a194eb9ed199abf250c5b3b6 (diff) | |
download | openssl-new-86c69fe84118f0dca656d9bfc1131052e2a8e9b8.tar.gz |
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 'providers')
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_ccm_hw.c | 8 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i.inc (renamed from providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i_zknd_zkne.inc) | 4 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i.inc (renamed from providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i_zknd_zkne.inc) | 2 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_gcm_hw.c | 8 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i.inc (renamed from providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i_zknd_zkne.inc) | 4 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i.inc (renamed from providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i_zknd_zkne.inc) | 2 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_hw.c | 8 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_hw_rv32i.inc (renamed from providers/implementations/ciphers/cipher_aes_hw_rv32i_zknd_zkne.inc) | 4 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_hw_rv64i.inc (renamed from providers/implementations/ciphers/cipher_aes_hw_rv64i_zknd_zkne.inc) | 2 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_ocb_hw.c | 12 | ||||
-rw-r--r-- | providers/implementations/ciphers/cipher_aes_xts_hw.c | 12 |
11 files changed, 35 insertions, 31 deletions
diff --git a/providers/implementations/ciphers/cipher_aes_ccm_hw.c b/providers/implementations/ciphers/cipher_aes_ccm_hw.c index 5dbb74bdcc..a7e9fb4a21 100644 --- a/providers/implementations/ciphers/cipher_aes_ccm_hw.c +++ b/providers/implementations/ciphers/cipher_aes_ccm_hw.c @@ -61,10 +61,10 @@ static const PROV_CCM_HW aes_ccm = { # include "cipher_aes_ccm_hw_aesni.inc" #elif defined(SPARC_AES_CAPABLE) # include "cipher_aes_ccm_hw_t4.inc" -#elif defined(RV64I_ZKND_ZKNE_CAPABLE) -# include "cipher_aes_ccm_hw_rv64i_zknd_zkne.inc" -#elif defined(RV32I_ZBKB_ZKND_ZKNE_CAPABLE) && defined(RV32I_ZKND_ZKNE_CAPABLE) -# include "cipher_aes_ccm_hw_rv32i_zknd_zkne.inc" +#elif defined(__riscv) && __riscv_xlen == 64 +# include "cipher_aes_ccm_hw_rv64i.inc" +#elif defined(__riscv) && __riscv_xlen == 32 +# include "cipher_aes_ccm_hw_rv32i.inc" #else const PROV_CCM_HW *ossl_prov_aes_hw_ccm(size_t keybits) { diff --git a/providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i_zknd_zkne.inc b/providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i.inc index 345bc2faae..a09a1e8dd8 100644 --- a/providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i_zknd_zkne.inc +++ b/providers/implementations/ciphers/cipher_aes_ccm_hw_rv32i.inc @@ -52,9 +52,9 @@ static const PROV_CCM_HW rv32i_zbkb_zknd_zkne_ccm = { const PROV_CCM_HW *ossl_prov_aes_hw_ccm(size_t keybits) { - if (RV32I_ZBKB_ZKND_ZKNE_CAPABLE) + if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE()) return &rv32i_zbkb_zknd_zkne_ccm; - if (RV32I_ZKND_ZKNE_CAPABLE) + if (RISCV_HAS_ZKND_AND_ZKNE()) return &rv32i_zknd_zkne_ccm; return &aes_ccm; } diff --git a/providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i_zknd_zkne.inc b/providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i.inc index 2f23209d03..f37c36118c 100644 --- a/providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i_zknd_zkne.inc +++ b/providers/implementations/ciphers/cipher_aes_ccm_hw_rv64i.inc @@ -33,5 +33,5 @@ static const PROV_CCM_HW rv64i_zknd_zkne_ccm = { const PROV_CCM_HW *ossl_prov_aes_hw_ccm(size_t keybits) { - return RV64I_ZKND_ZKNE_CAPABLE ? &rv64i_zknd_zkne_ccm : &aes_ccm; + return RISCV_HAS_ZKND_AND_ZKNE() ? &rv64i_zknd_zkne_ccm : &aes_ccm; } diff --git a/providers/implementations/ciphers/cipher_aes_gcm_hw.c b/providers/implementations/ciphers/cipher_aes_gcm_hw.c index c7a98cdfbf..3887b4916e 100644 --- a/providers/implementations/ciphers/cipher_aes_gcm_hw.c +++ b/providers/implementations/ciphers/cipher_aes_gcm_hw.c @@ -142,10 +142,10 @@ static const PROV_GCM_HW aes_gcm = { # include "cipher_aes_gcm_hw_armv8.inc" #elif defined(PPC_AES_GCM_CAPABLE) # include "cipher_aes_gcm_hw_ppc.inc" -#elif defined(RV64I_ZKND_ZKNE_CAPABLE) -# include "cipher_aes_gcm_hw_rv64i_zknd_zkne.inc" -#elif defined(RV32I_ZBKB_ZKND_ZKNE_CAPABLE) && defined(RV32I_ZKND_ZKNE_CAPABLE) -# include "cipher_aes_gcm_hw_rv32i_zknd_zkne.inc" +#elif defined(__riscv) && __riscv_xlen == 64 +# include "cipher_aes_gcm_hw_rv64i.inc" +#elif defined(__riscv) && __riscv_xlen == 32 +# include "cipher_aes_gcm_hw_rv32i.inc" #else const PROV_GCM_HW *ossl_prov_aes_hw_gcm(size_t keybits) { diff --git a/providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i_zknd_zkne.inc b/providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i.inc index dd5878736e..32abd05210 100644 --- a/providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i_zknd_zkne.inc +++ b/providers/implementations/ciphers/cipher_aes_gcm_hw_rv32i.inc @@ -55,9 +55,9 @@ static const PROV_GCM_HW rv32i_zbkb_zknd_zkne_gcm = { const PROV_GCM_HW *ossl_prov_aes_hw_gcm(size_t keybits) { - if (RV32I_ZBKB_ZKND_ZKNE_CAPABLE) + if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE()) return &rv32i_zbkb_zknd_zkne_gcm; - if (RV32I_ZKND_ZKNE_CAPABLE) + if (RISCV_HAS_ZKND_AND_ZKNE()) return &rv32i_zknd_zkne_gcm; return &aes_gcm; } diff --git a/providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i_zknd_zkne.inc b/providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i.inc index 44325d8469..a89ab17811 100644 --- a/providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i_zknd_zkne.inc +++ b/providers/implementations/ciphers/cipher_aes_gcm_hw_rv64i.inc @@ -33,7 +33,7 @@ static const PROV_GCM_HW rv64i_zknd_zkne_gcm = { const PROV_GCM_HW *ossl_prov_aes_hw_gcm(size_t keybits) { - if (RV64I_ZKND_ZKNE_CAPABLE) + if (RISCV_HAS_ZKND_AND_ZKNE()) return &rv64i_zknd_zkne_gcm; else return &aes_gcm; diff --git a/providers/implementations/ciphers/cipher_aes_hw.c b/providers/implementations/ciphers/cipher_aes_hw.c index 074d04d878..1a59f24d35 100644 --- a/providers/implementations/ciphers/cipher_aes_hw.c +++ b/providers/implementations/ciphers/cipher_aes_hw.c @@ -142,10 +142,10 @@ const PROV_CIPHER_HW *ossl_prov_cipher_hw_aes_##mode(size_t keybits) \ # include "cipher_aes_hw_t4.inc" #elif defined(S390X_aes_128_CAPABLE) # include "cipher_aes_hw_s390x.inc" -#elif defined(RV64I_ZKND_ZKNE_CAPABLE) -# include "cipher_aes_hw_rv64i_zknd_zkne.inc" -#elif defined(RV32I_ZBKB_ZKND_ZKNE_CAPABLE) && defined(RV32I_ZKND_ZKNE_CAPABLE) -# include "cipher_aes_hw_rv32i_zknd_zkne.inc" +#elif defined(__riscv) && __riscv_xlen == 64 +# include "cipher_aes_hw_rv64i.inc" +#elif defined(__riscv) && __riscv_xlen == 32 +# include "cipher_aes_hw_rv32i.inc" #else /* The generic case */ # define PROV_CIPHER_HW_declare(mode) diff --git a/providers/implementations/ciphers/cipher_aes_hw_rv32i_zknd_zkne.inc b/providers/implementations/ciphers/cipher_aes_hw_rv32i.inc index d3173fa401..a23c08ac9e 100644 --- a/providers/implementations/ciphers/cipher_aes_hw_rv32i_zknd_zkne.inc +++ b/providers/implementations/ciphers/cipher_aes_hw_rv32i.inc @@ -96,7 +96,7 @@ static const PROV_CIPHER_HW rv32i_zbkb_zknd_zkne_##mode = { \ cipher_hw_aes_copyctx \ }; #define PROV_CIPHER_HW_select(mode) \ -if (RV32I_ZBKB_ZKND_ZKNE_CAPABLE) \ +if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE()) \ return &rv32i_zbkb_zknd_zkne_##mode; \ -if (RV32I_ZKND_ZKNE_CAPABLE) \ +if (RISCV_HAS_ZKND_AND_ZKNE()) \ return &rv32i_zknd_zkne_##mode; diff --git a/providers/implementations/ciphers/cipher_aes_hw_rv64i_zknd_zkne.inc b/providers/implementations/ciphers/cipher_aes_hw_rv64i.inc index 762d211ef8..3cf3c8e3a4 100644 --- a/providers/implementations/ciphers/cipher_aes_hw_rv64i_zknd_zkne.inc +++ b/providers/implementations/ciphers/cipher_aes_hw_rv64i.inc @@ -55,5 +55,5 @@ static const PROV_CIPHER_HW rv64i_zknd_zkne_##mode = { \ cipher_hw_aes_copyctx \ }; #define PROV_CIPHER_HW_select(mode) \ -if (RV64I_ZKND_ZKNE_CAPABLE) \ +if (RISCV_HAS_ZKND_AND_ZKNE()) \ return &rv64i_zknd_zkne_##mode; diff --git a/providers/implementations/ciphers/cipher_aes_ocb_hw.c b/providers/implementations/ciphers/cipher_aes_ocb_hw.c index 5b93d2b717..62d762d49b 100644 --- a/providers/implementations/ciphers/cipher_aes_ocb_hw.c +++ b/providers/implementations/ciphers/cipher_aes_ocb_hw.c @@ -103,7 +103,8 @@ static const PROV_CIPHER_HW aes_t4_ocb = { \ # define PROV_CIPHER_HW_select() \ if (SPARC_AES_CAPABLE) \ return &aes_t4_ocb; -#elif defined(RV64I_ZKND_ZKNE_CAPABLE) + +#elif defined(__riscv) && __riscv_xlen == 64 static int cipher_hw_aes_ocb_rv64i_zknd_zkne_initkey(PROV_CIPHER_CTX *vctx, const unsigned char *key, @@ -122,9 +123,10 @@ static const PROV_CIPHER_HW aes_rv64i_zknd_zkne_ocb = { \ NULL \ }; # define PROV_CIPHER_HW_select() \ - if (RV64I_ZKND_ZKNE_CAPABLE) \ + if (RISCV_HAS_ZKND_AND_ZKNE()) \ return &aes_rv64i_zknd_zkne_ocb; -#elif defined(RV32I_ZBKB_ZKND_ZKNE_CAPABLE) && defined(RV32I_ZKND_ZKNE_CAPABLE) + +#elif defined(__riscv) && __riscv_xlen == 32 static int cipher_hw_aes_ocb_rv32i_zknd_zkne_initkey(PROV_CIPHER_CTX *vctx, const unsigned char *key, @@ -158,9 +160,9 @@ static const PROV_CIPHER_HW aes_rv32i_zbkb_zknd_zkne_ocb = { \ NULL \ }; # define PROV_CIPHER_HW_select() \ - if (RV32I_ZBKB_ZKND_ZKNE_CAPABLE) \ + if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE()) \ return &aes_rv32i_zbkb_zknd_zkne_ocb; \ - if (RV32I_ZKND_ZKNE_CAPABLE) \ + if (RISCV_HAS_ZKND_AND_ZKNE()) \ return &aes_rv32i_zknd_zkne_ocb; #else # define PROV_CIPHER_HW_declare() diff --git a/providers/implementations/ciphers/cipher_aes_xts_hw.c b/providers/implementations/ciphers/cipher_aes_xts_hw.c index c8c9cbf19e..223b49b0b9 100644 --- a/providers/implementations/ciphers/cipher_aes_xts_hw.c +++ b/providers/implementations/ciphers/cipher_aes_xts_hw.c @@ -158,7 +158,8 @@ static const PROV_CIPHER_HW aes_xts_t4 = { \ # define PROV_CIPHER_HW_select_xts() \ if (SPARC_AES_CAPABLE) \ return &aes_xts_t4; -#elif defined(RV64I_ZKND_ZKNE_CAPABLE) + +#elif defined(__riscv) && __riscv_xlen == 64 static int cipher_hw_aes_xts_rv64i_zknd_zkne_initkey(PROV_CIPHER_CTX *ctx, const unsigned char *key, @@ -181,9 +182,10 @@ static const PROV_CIPHER_HW aes_xts_rv64i_zknd_zkne = { \ cipher_hw_aes_xts_copyctx \ }; # define PROV_CIPHER_HW_select_xts() \ -if (RV64I_ZKND_ZKNE_CAPABLE) \ +if (RISCV_HAS_ZKND_AND_ZKNE()) \ return &aes_xts_rv64i_zknd_zkne; -#elif defined(RV32I_ZBKB_ZKND_ZKNE_CAPABLE) && defined(RV32I_ZKND_ZKNE_CAPABLE) + +#elif defined(__riscv) && __riscv_xlen == 32 static int cipher_hw_aes_xts_rv32i_zknd_zkne_initkey(PROV_CIPHER_CTX *ctx, const unsigned char *key, @@ -221,9 +223,9 @@ static const PROV_CIPHER_HW aes_xts_rv32i_zbkb_zknd_zkne = { \ cipher_hw_aes_xts_copyctx \ }; # define PROV_CIPHER_HW_select_xts() \ -if (RV32I_ZBKB_ZKND_ZKNE_CAPABLE) \ +if (RISCV_HAS_ZBKB_AND_ZKND_AND_ZKNE()) \ return &aes_xts_rv32i_zbkb_zknd_zkne; \ -if (RV32I_ZKND_ZKNE_CAPABLE) \ +if (RISCV_HAS_ZKND_ZKNE()) \ return &aes_xts_rv32i_zknd_zkne; # else /* The generic case */ |