Resources

People often ask me "How did you learn how to hack?" The answer: by reading. This page is a collection of the blog posts and other articles that I have accumulated over the years of my journey. Enjoy!

Finding bugs in implementations of HQC, the fifth post-quantum standard - 2238

QuarkslabPosted 18 Days Ago
  • In March of 2025, NIST standardized HQC as the last key encapsulation mechanism (KEM) for PQC algorithms. This article describes the finding of two critical bugs in the reference implementation of it.
  • Hamming Quasi-Cyclic (HQC) is a KEM based on code theory. It built as a replacement for public-key encryption schemes. KEMs are being on three algorithms. Key gen generates the key pair. Encapsulate takes the public key as input, and generates a shared secret, and encrypts it into ciphertext. The Decapsulate decrypts the ciphertext from the secret key, and recovers the shared secret.
  • At Quarkslab, they evaluate cryptographic implementations using a conformity testing, and resilience testing. Since cryptography is so hard to get correct, it's intersting to see how these folks test it internally. They started by using crypto-condor to do conformity checks on the reference implementation. The idea is to compare implementations to the standard for this.
  • Internally, they also have the tool DeltAFly for in-depth functional correctness. This is mainly for edge cases, differential fuzzing, and constant-time behaviour. While fuzzing LibOQS, they discovered two bugs in the HQC decapsulation function that, in parallel, led to a real bad bypass of security. This bug turned out to be in the reference implementation code.
  • During decapsulation, the public key is incorrectly extracted from the from key. This stems from a correctness bug in the system: invalid inputs return despite a request for explicit rejection. The output always succeeds because the boolean result is used as a mask for the return value.
  • The second bug is why the first bug can be triggered. The secret key object sk is built from the seed, sigma, and public key. However, in the code, the public key incorrectly extracts the public key from the sigma part. This means that the derived value is incorrect.
  • The normal flow is that if decryption fails, then it should use part of sigma (a rejection secret) to decrypt the data instead. This way, an attacker can't use it as a decryption oracle with errors, like the famous Bleichenbacher attack.
  • This leads to intercepted communication being possible to convince the server to use incorrect secrets. Additionally, an attacker can tell if the decryption was successful or not, creating the new for an oracle again. The article doesn't explain the impact of the bug itself but this is what I was able to gather from it. It's nothing like a complete breakage of the protocol.