I ran some tests using qemu-ppc64le and was able to reproduce the issue, although the failures appear to be very sporadic:
https://github.com/aidenfoxivey/liboqs/actions/runs/16788186098/job/47547291113
Using the same compiler configuration, Valgrind consistently reports issues in encaps/decaps (also in the Frodo-SHAKE versions, which neverthless appear to return the correct results):
/home/liboqs/build# valgrind tests/test_kem_mem FrodoKEM-640-AES 1
==82868== Invalid read of size 8
==82868== at 0x1147D0: OQS_KEM_frodokem_640_aes_encaps (kem.c:151)
==82868== by 0x10C397: kem_test_correctness (test_kem_mem.c:93)
==82868== Address 0x1ffeffffb0 is on thread 1's stack
==82868== 320 bytes below stack pointer
...
These errors disappear when auto-vectorization is disabled in the frodo_sample_n function using: #pragma GCC optimize("no-tree-vectorize")
I’m not certain about the root cause yet. My current guess is that there’s a subtle aliasing or alignment issue:
- ppc64le vector instructions typically require 16- or 32-byte alignment.
- Frodo code contains several pointer casts (e.g., 16->32 bits, 8->16 bits) that might be tricky with strict aliasing rules, which I believe are used in the liboqs builds.
Originally posted by @bhess in #2068
Originally posted by @bhess in #2068