Skip to content

fix(kyber): Close potential side-channel vulnerability#534

Merged
thomwiggers merged 3 commits intomasterfrom
fix-kyber-div-sidechannel
Jan 25, 2024
Merged

fix(kyber): Close potential side-channel vulnerability#534
thomwiggers merged 3 commits intomasterfrom
fix-kyber-div-sidechannel

Conversation

@thomwiggers
Copy link
Member

Address the Kyber side-channel vulnerabilities that are potentially
introduced by the division in certain poly operations.

Closes #533

Address the Kyber side-channel vulnerabilities that are potentially
introduced by the division in certain poly operations.

Closes #533
@thomwiggers thomwiggers requested a review from cryptojedi January 4, 2024 07:47
@thomwiggers thomwiggers merged commit 3b43bc6 into master Jan 25, 2024
@thomwiggers thomwiggers deleted the fix-kyber-div-sidechannel branch January 25, 2024 10:58
smuellerDD added a commit to smuellerDD/leancrypto that referenced this pull request Jan 25, 2024
This is a port of issue PQClean/PQClean#534

Description from mupq/pqm4#320:

The function poly_tomsg from the reference implementation of Kyber
(which was copied into the M4-optimized implementations) would result
in a variable-time udiv instruction operating on secret data when
compiled with gcc using -Os. I tried a couple of versions from gcc 11
to gcc 13, but did not see any difference.

Description from mupq/pqm4#319

This bit of code or similar is used in your various implementations of
Kyber to compress a polynomial ring element into a (secret) message:

```
 t = (((a->coeffs[8 * i + j] << 1) + KYBER_Q / 2) / KYBER_Q) & 1;
```

To do so, it performs a division by Q that might not necessarily compile
to a multiplication instruction: looking at the output of some C
compilers using https://godbolt.org/z/sKn3TKKGq and
https://godbolt.org/z/8GqKoTfYh for example, a division instruction is
emitted even when -O3 is specified. Should a division instruction be
emitted, its execution time would likely be variable and leak
information about its secret input.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
infra-riderju74 added a commit to infra-riderju74/leancrypto that referenced this pull request Sep 28, 2025
This is a port of issue PQClean/PQClean#534

Description from mupq/pqm4#320:

The function poly_tomsg from the reference implementation of Kyber
(which was copied into the M4-optimized implementations) would result
in a variable-time udiv instruction operating on secret data when
compiled with gcc using -Os. I tried a couple of versions from gcc 11
to gcc 13, but did not see any difference.

Description from mupq/pqm4#319

This bit of code or similar is used in your various implementations of
Kyber to compress a polynomial ring element into a (secret) message:

```
 t = (((a->coeffs[8 * i + j] << 1) + KYBER_Q / 2) / KYBER_Q) & 1;
```

To do so, it performs a division by Q that might not necessarily compile
to a multiplication instruction: looking at the output of some C
compilers using https://godbolt.org/z/sKn3TKKGq and
https://godbolt.org/z/8GqKoTfYh for example, a division instruction is
emitted even when -O3 is specified. Should a division instruction be
emitted, its execution time would likely be variable and leak
information about its secret input.

Signed-off-by: Stephan Mueller <smueller@chronox.de>
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.

Update Kyber implementations for security improvements

2 participants