]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Fix riscv64 chacha crash due to unaligned data
authorBernd Edlinger <bernd.edlinger@hotmail.de>
Sat, 27 Sep 2025 20:14:04 +0000 (22:14 +0200)
committerTomas Mraz <tomas@openssl.org>
Wed, 1 Oct 2025 15:51:30 +0000 (17:51 +0200)
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)

(cherry picked from commit 22417bc14d6bde173425ba4f87c68be0cf394fa4)

crypto/chacha/chacha_riscv.c

index 734444bfa88b7a38f8990a7bf8ecc0fa22b6b075..6721eaa112a9d6751cc39ca8093fd87e0c805e98 100644 (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 {