Skip to content

Fix broken AVX2 cmov that skips FO implicit rejection (key recovery) - #5

Closed
007bsd wants to merge 1 commit into
Cosmian:developfrom
007bsd:cosmian-fix-avx2-cmov
Closed

007bsd wants to merge 1 commit into
Cosmian:developfrom
007bsd:cosmian-fix-avx2-cmov

Conversation

@007bsd

@007bsd 007bsd commented Aug 16, 2026

Copy link
Copy Markdown

Problem

The AVX2 cmov in src/avx2/verify.rs builds its blend mask with _mm256_set1_epi64x(b as i64). For b == 1 every byte's high bit is 0 and _mm256_blendv_epi8 copies nothing, so the routine is a no-op.

That cmov is the Fujisaki-Okamoto implicit-rejection step in decapsulation (called with len == 32, entirely through the vector loop). On an invalid ciphertext the rejection secret is never applied, so the returned shared secret depends on the decrypted plaintext of the attacker-chosen ciphertext. This is a chosen-ciphertext plaintext-checking oracle and allows recovery of a reused static secret key. Only the opt-in avx2 feature is affected; the reference backend is correct.

This fork inherits the defect from the upstream Argyle-Software/kyber code.

Fix

Negate b once to 0x00/0xFF and broadcast per byte with _mm256_set1_epi8, matching the pq-crystals reference; remove the now-redundant scalar-tail negation. Identical to the upstream fix in Argyle-Software#119.

The AVX2 cmov built its blend mask with _mm256_set1_epi64x(b as i64), so for
b == 1 every byte's high bit is 0 and _mm256_blendv_epi8 copies nothing. cmov is
the Fujisaki-Okamoto implicit-rejection step in decapsulation (len == 32, wholly
through the vector loop), so on an invalid ciphertext the rejection value was
never applied, turning decapsulation into a chosen-ciphertext plaintext-checking
oracle and enabling static key recovery.

Fix: negate b once to 0x00/0xFF and broadcast per byte with _mm256_set1_epi8,
matching the pq-crystals reference; drop the redundant scalar-tail negation.
Identical to the upstream fix in Argyle-Software#119.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant