From: Bernd Edlinger Date: Sat, 27 Sep 2025 20:14:04 +0000 (+0200) Subject: Fix riscv64 chacha crash due to unaligned data X-Git-Tag: 4.0-PRE-CLANG-FORMAT-WEBKIT~407 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22417bc14d6bde173425ba4f87c68be0cf394fa4;p=thirdparty%2Fopenssl.git 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 Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/28684) --- diff --git a/crypto/chacha/chacha_riscv.c b/crypto/chacha/chacha_riscv.c index 734444bfa88..6721eaa112a 100644 --- a/crypto/chacha/chacha_riscv.c +++ b/crypto/chacha/chacha_riscv.c @@ -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 {