Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HQC implementations don't match round 4 #1949

Closed
celi0n opened this issue Dec 19, 2024 · 2 comments
Closed

HQC implementations don't match round 4 #1949

celi0n opened this issue Dec 19, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@celi0n
Copy link

celi0n commented Dec 19, 2024

The HQC post quantum KEM implementation in both Java and C# are not matching the reference implementation for round 4 https://pqc-hqc.org/implementation.html. A sigma variable was added on round 3 (2023/04/30) to provide explicit rejection. bouncy castle implementations instead return ss=0 when decapsulation failed

if (result == 0)
{ //abort
for (int i = 0; i < getSessionKeySize(); i++)
{
ss[i] = 0;
}
}
}

Be aware that there are 2 bugs in this part of the reference implementation (not fixed yet) that make it deviate from the specifications (GHSA-gpf4-vrrw-r8v7).

Also, the code is using non constant time comparison for u, v and d with Arrays.equal where the reference implementation (even in round 3) use constant time comparison with vect_compare.

if (!Arrays.areEqual(u, u2Bytes))
{
result = 0;
}
if (!Arrays.areEqual(v, v2Bytes))
{
result = 0;
}
if (!Arrays.areEqual(d, dPrime))
{
result = 0;
}

I don't report this as a security issue as bouncycastle's website states these are available for experimenting.

Célian Glénaz (Quarkslab)

@winfriedgerlach winfriedgerlach added the bug Something isn't working label Dec 19, 2024
@roy-basmacier roy-basmacier self-assigned this Dec 19, 2024
@roy-basmacier
Copy link

Hey @celi0n,

I patched HQC to match the 2024-10-30 reference implementation along with the bug fix.

Thanks for the detailed report,
Roy

@dghgit
Copy link
Contributor

dghgit commented Dec 21, 2024

New beta has been pushed to https://downloads.bouncycastle.org/betas/ updates should appear on github shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants