Antoon Purnal Profile picture
Jun 3 11 tweets 3 min read Read on X
I recently found an exploitable timing leak in the reference implementation of Kyber (ML-KEM), the soon-to-be NIST standard for post-quantum key encapsulation.

Let’s see if you can spot it in the source code - msg is secret: Image
“I don’t see it. Looks good to me?”

Sure does! It’s written to avoid any control-flow or data dependency on the message.

" ... "

Let’s look at an obviously insecure version of the same function. The following code leaks the bits of msg one by one: Image
Now let's inspect the x86 assembly for the first (secure!) version with clang, using the -Os option to optimize for size

Notice what happens? Image
“So the compiler helpfully reverts the side-channel countermeasure?”

Indeed, the secure and insecure source are compiled to the exact same x86 assembly
Image
“Looks like a small leak. Is it exploitable?”

Yes. During decaps, the leak can be used as a plaintext-checking oracle leading to key recovery.

“PoC || GTFO.”



Okay - here goes: github.com/antoonpurnal/c…
“Which compilers/options are affected?”

Blast radius of this particular security regression is limited to x86 Clang (v15-18), for several options including -Os, -O1 and several others.

Plain -O3, a common default, is (luckily) not affected. But some variations of it are.
“How novel is this?”

It’s known that compilers may break source-level side-channel resistance [1,2] and it was reported before that Clang may swap cmovs for branches [3].

Still, to my knowledge it’s been a while since it caused an exploitable leak in important crypto code?
“Optimizing compilers optimize. This is unsurprising. CT evaluation should happen at binary level.”

Couldn’t agree more. That’s our approach at @PqShield. But it’s not uncommon for crypto code to be distributed as source & compiled by users (w/ a mainstream optimizing compiler).
For more details, check out the piece I wrote for the PQShield website: pqshield.com/pqshield-plugs…
Many thanks to @cryptojedi for the swift and collaborative disclosure process.

References throughout thread:
[1]
[2]
[3] cl.cam.ac.uk/~rja14/Papers/…
leslyann-daniel.fr/ressources/pap…
electricdusk.com/cmov-conversio…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Antoon Purnal

Antoon Purnal Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(