# GHSA-753p-wrj5-g8fj: PQClean has a correctness error in HQC decapsulation

> An indexing error in PQClean's HQC implementation mishandles secret keys, potentially allowing attackers to bypass implicit rejection and recover shared secrets from malformed ciphertexts.

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 11 Dec 2024

## What is GHSA-753p-wrj5-g8fj?

GHSA-753p-wrj5-g8fj is a vulnerability in pqcrypto-hqc, published on 11 Dec 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

### Impact

A correctness error has been identified in the reference implementation of the HQC key encapsulation mechanism. Due to an indexing error, part of the secret key is incorrectly treated as non-secret data. This results in an incorrect shared secret value being returned when the decapsulation function is called with a malformed ciphertext.

No concrete attack exploiting the error has been identified at this point. However, the error involves mishandling of the secret key, and in principle this presents a security vulnerability.

### Patches

PQClean does not have a release process, as it is a collection of implementations. If you obtained a HQC implementation from PQClean, please update to a version that includes the fixes proposed in https://github.com/PQClean/PQClean/pull/578. 

Please also [refer to our security policy](https://github.com/PQClean/PQClean/blob/master/SECURITY.md).

### Workarounds

Manually patching is always possible

### Further details

In the 2023/04/30 version of the HQC specification and reference implementation, an extra field (sigma) was added to the secret key structure to enable implicit rejection of malformed ciphertexts. The logic to retrieve the public key from the secret key in the decapsulation function was not updated accordingly. As a result, sigma is treated as part of the public key. Later in the decapsulation call, a incorrectly constructed comparison check allows this error to go through undetected. Due to how these two bugs interfere with each other, the decapsulation function never uses sigma to perform implicit rejection; instead, it accepts malformed ciphertexts and returns shared secrets based on their decryptions.

### References

This issue was first reported in OQS https://github.com/open-quantum-safe/liboqs/security/advisories/GHSA-gpf4-vrrw-r8v7. The vulnerability was identified by Célian Glénaz and Dahmun Goudarzi (Quarkslab).

## Which versions are affected by GHSA-753p-wrj5-g8fj?

2 open source packages ship an affected version, including pqcrypto-hqc.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `pqcrypto-hqc` | crates.io | All versions | 0.2.1 |
| `pqcrypto-hqc` | crates.io | All versions | 0.2.1 |

## How do I fix GHSA-753p-wrj5-g8fj?

Upgrade pqcrypto-hqc to 0.2.1 or later.

## Is GHSA-753p-wrj5-g8fj being exploited?

There is no known exploitation of GHSA-753p-wrj5-g8fj in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-753p-wrj5-g8fj and fix it if it is affected.

What it is: GHSA-753p-wrj5-g8fj is a vulnerability in pqcrypto-hqc, published on 11 Dec 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of GHSA-753p-wrj5-g8fj in the wild and no public exploit code.

Affected packages and fixed versions:
- pqcrypto-hqc (crates.io): affected all versions; fixed in 0.2.1
- pqcrypto-hqc (crates.io): affected all versions; fixed in 0.2.1

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-753p-wrj5-g8fj/ (Markdown: https://insights.sbomify.com/GHSA-753p-wrj5-g8fj/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-753p-wrj5-g8fj

---
From sbomify Insights: https://insights.sbomify.com/GHSA-753p-wrj5-g8fj/
Summaries are generated and may contain mistakes; the official description above is the record.
