Skip to content

Commit 71ae2a6

Browse files
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.
1 parent 1f106f5 commit 71ae2a6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crypto/chacha/chacha_riscv.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ void ChaCha20_ctr32_v_zbb(unsigned char *out, const unsigned char *inp,
5151
void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp, size_t len,
5252
const unsigned int key[8], const unsigned int counter[4])
5353
{
54-
if (len > CHACHA_BLK_SIZE && RISCV_HAS_ZBB() && riscv_vlen() >= 128) {
54+
if (len > CHACHA_BLK_SIZE && RISCV_HAS_ZBB() && riscv_vlen() >= 128
55+
&& (size_t)out % sizeof(size_t) == 0
56+
&& (size_t)inp % sizeof(size_t) == 0) {
5557
if (RISCV_HAS_ZVKB()) {
5658
ChaCha20_ctr32_v_zbb_zvkb(out, inp, len, key, counter);
5759
} else {

0 commit comments

Comments
 (0)