Description
The SIMD256 (AVX2) branch of encapsulate1 and encapsulate2 generates incorrect results compared to the SIMD128 (NEON) and portable branches.
Root Cause
The root cause is incorrect endianness handling in the from_bytes and to_bytes methods in libcrux-ml-kem/src/vector/avx2.rs. These functions do not properly swap bytes when converting between byte arrays and SIMD vectors.
Impact
The issue is not obviously apparent if encapsulate1 and encapsulate2 always run on the same machine. In this case, the endianness error cancels out during the two calls, and the implementation still generates the correct key and message compared to the non-incremental version.
However, some scenarios like SPQR (Sparse Post-Quantum Ratchet) choose to run encapsulate1 and encapsulate2 on different machines. This leads to incorrect results if one party enters the SIMD256 branch and the other enters the SIMD128 or portable branch.