mirror of
https://github.com/openssl/openssl.git
synced 2025-03-31 20:10:45 +08:00
riscv: Use the optimized rvv AES-128/192/256-CBC.
Replace old CBC implementation with optimized AES-128/192/256-CBC in this patch. Signed-off-by: Phoebe Chen <phoebe.chen@sifive.com> Reviewed-by: Tomas Mraz <tomas@openssl.org> Reviewed-by: Paul Dale <pauli@openssl.org> Reviewed-by: Hugo Landau <hlandau@openssl.org> (Merged from https://github.com/openssl/openssl/pull/21923)
This commit is contained in:
parent
5e16a6276b
commit
562b4eb4c1
@ -454,6 +454,13 @@ void rv64i_zvkned_encrypt(const unsigned char *in, unsigned char *out,
|
||||
void rv64i_zvkned_decrypt(const unsigned char *in, unsigned char *out,
|
||||
const AES_KEY *key);
|
||||
|
||||
void rv64i_zvkned_cbc_encrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, const int enc);
|
||||
|
||||
void rv64i_zvkned_cbc_decrypt(const unsigned char *in, unsigned char *out,
|
||||
size_t length, const AES_KEY *key,
|
||||
unsigned char *ivec, const int enc);
|
||||
# elif defined(OPENSSL_CPUID_OBJ) && defined(__riscv) && __riscv_xlen == 32
|
||||
/* RISC-V 32 support */
|
||||
# include "riscv_arch.h"
|
||||
|
@ -71,31 +71,34 @@ static int cipher_hw_rv64i_zvkned_initkey(PROV_CIPHER_CTX *dat,
|
||||
|
||||
dat->ks = ks;
|
||||
|
||||
/* Zvkned only supports 128 and 256 bit keys for key schedule generation. */
|
||||
/*
|
||||
* Zvkned only supports 128 and 256 bit keys for key schedule generation.
|
||||
* For AES-192 case, we could fallback to `AES_set_encrypt_key`.
|
||||
* All Zvkned-based implementations use the same `encrypt-key` scheduling
|
||||
* for both encryption and decryption.
|
||||
*/
|
||||
if (keylen * 8 == 128 || keylen * 8 == 256) {
|
||||
if ((dat->mode == EVP_CIPH_ECB_MODE || dat->mode == EVP_CIPH_CBC_MODE)
|
||||
&& !dat->enc) {
|
||||
ret = rv64i_zvkned_set_decrypt_key(key, keylen * 8, ks);
|
||||
dat->block = (block128_f) rv64i_zvkned_decrypt;
|
||||
dat->stream.cbc = NULL;
|
||||
} else {
|
||||
ret = rv64i_zvkned_set_encrypt_key(key, keylen * 8, ks);
|
||||
dat->block = (block128_f) rv64i_zvkned_encrypt;
|
||||
dat->stream.cbc = NULL;
|
||||
}
|
||||
ret = rv64i_zvkned_set_encrypt_key(key, keylen * 8, ks);
|
||||
} else {
|
||||
if ((dat->mode == EVP_CIPH_ECB_MODE || dat->mode == EVP_CIPH_CBC_MODE)
|
||||
&& !dat->enc) {
|
||||
ret = AES_set_encrypt_key(key, keylen * 8, ks);
|
||||
dat->block = (block128_f) rv64i_zvkned_decrypt;
|
||||
dat->stream.cbc = NULL;
|
||||
ret = AES_set_encrypt_key(key, keylen * 8, ks);
|
||||
}
|
||||
|
||||
if (dat->mode == EVP_CIPH_CBC_MODE) {
|
||||
if (dat->enc) {
|
||||
dat->stream.cbc = (cbc128_f) rv64i_zvkned_cbc_encrypt;
|
||||
} else {
|
||||
ret = AES_set_encrypt_key(key, keylen * 8, ks);
|
||||
dat->block = (block128_f) rv64i_zvkned_encrypt;
|
||||
dat->stream.cbc = NULL;
|
||||
dat->stream.cbc = (cbc128_f) rv64i_zvkned_cbc_decrypt;
|
||||
}
|
||||
}
|
||||
|
||||
/* Zvkned supports aes-128/192/256 encryption and decryption. */
|
||||
if ((dat->mode == EVP_CIPH_ECB_MODE || dat->mode == EVP_CIPH_CBC_MODE) &&
|
||||
!dat->enc) {
|
||||
dat->block = (block128_f) rv64i_zvkned_decrypt;
|
||||
} else {
|
||||
dat->block = (block128_f) rv64i_zvkned_encrypt;
|
||||
}
|
||||
|
||||
if (ret < 0) {
|
||||
ERR_raise(ERR_LIB_PROV, PROV_R_KEY_SETUP_FAILED);
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user