Fix riscv64 chacha crash due to unaligned data

The linux-riscv64 test machine crashes due to unaligned data,
when the V extension is enabled, while QEMU seems to have no
problems with unaligned data.

So check for aligned data and fall back to C code in case the
input or output values are unaligned.

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/28684)
This commit is contained in:
Bernd Edlinger 2025-09-27 22:14:04 +02:00 committed by Tomas Mraz
parent 0e5e84c486
commit 22417bc14d
1 changed files with 3 additions and 1 deletions

View File

@ -51,7 +51,9 @@ void ChaCha20_ctr32_v_zbb(unsigned char *out, const unsigned char *inp,
void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp, size_t len,
const unsigned int key[8], const unsigned int counter[4])
{
if (len > CHACHA_BLK_SIZE && RISCV_HAS_ZBB() && riscv_vlen() >= 128) {
if (len > CHACHA_BLK_SIZE && RISCV_HAS_ZBB() && riscv_vlen() >= 128
&& (size_t)out % sizeof(size_t) == 0
&& (size_t)inp % sizeof(size_t) == 0) {
if (RISCV_HAS_ZVKB()) {
ChaCha20_ctr32_v_zbb_zvkb(out, inp, len, key, counter);
} else {