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

Potential security vulnerability: non-constant-time usages of division #108

Open
tarcieri opened this issue Dec 15, 2023 · 4 comments
Open

Comments

@tarcieri
Copy link

The Kyber reference implementation has been updated to eliminate usages of division out of timing-variability concerns: pq-crystals/kyber@dda29cc

It would probably be good to do something similar, e.g.

t[k] = (((((t[k] as u32) << 10) + KYBER_Q as u32 / 2) / KYBER_Q as u32) & 0x3ff)

@xvzcf
Copy link

xvzcf commented Dec 15, 2023

This division by Q also occurs when compressing a polynomial ring element into a (secret) message during decapsulation:

t = (((t << 1) + KYBER_Q as i16 / 2) / KYBER_Q as i16) & 1;

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.

@bwesterb
Copy link
Contributor

Fixed in this fork. bwesterb@b5c6ad1

@tarcieri tarcieri changed the title Remove usages of division? Potential security vulnerability: non-constant-time usages of division Feb 2, 2024
@tarcieri
Copy link
Author

tarcieri commented Feb 2, 2024

We have a request to file a RUSTSEC advisory for this vulnerability, although we'll wait to hear back on a potential fix before publishing it: https://github.com/rustsec/advisory-db/pull/1872/files

@Shnatsel
Copy link

Shnatsel commented Feb 9, 2024

Heads up: this issue has been included in the RustSec advisory database. It will be surfaced by tools such as cargo-audit or Dependabot from now on.

Once a fix is released to crates.io, please open a pull request to update the advisory with the patched version, or file an issue on the advisory database repository.

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

No branches or pull requests

4 participants