Constant-time support lands in LLVM: Protecting cryptographic code at the compiler level

85 points by sknebel


cyberia

It looks like the author has changed the title and the link: https://blog.trailofbits.com/2025/11/25/constant-time-support-coming-to-llvm-protecting-cryptographic-code-at-the-compiler-level/

Now "coming to" rather than "lands in" LLVM.

skade

My theory why the post was removed: It’s incomplete and looks a bit drafty. For example, it does actually not link to any changes that have landed in LLVM, and indeed most of the PRs are still open: https://github.com/llvm/llvm-project/pulls?q=author%3Awizardengineer+is%3Apr

That kind of contradicts the title of the post.

So, benign reading: someone hit the publish button by accident. That also explains why they changed the slug without redirect and de-published the post.

0x2ba22e11

Oooh! Great news for cryptographers, I think.

Congratulations @david_chisnall.

fanf

Neat. Pleasing to see this was based on a paper by @david_chisnall, Laurent Simon, and Ross Anderson from 2018. (The paper also discusses secure erasure, but it seems that explicit_bzero() / memset_explicit() are still just library functions, and compiler developers have not yet been persuaded it needs a builtin.)

I’m curious what kind of string operations they have in mind for future work.

And I would have thought that general constant-time expressions need more annotation than just a wrapper. Apart from control flow, the other non-constant-time operation is accessing memory. If an expression is constant time there must be tight control over how it accesses memory, which typically means that addresses don’t depend on any secret values. (So, not actually constant time, just avoiding a side-channel that leaks secrets.) I suppose a simple but useful possibility might be to ensure that array indexes are statically known, assuming that array base addresses are not secret.

robinhundt

This is great! When I learned about side channel attacks and constant time operations, I was quite surprised to find out that many cryptographic implementations rely on essentially hoping that the compiler doesn't mess up constant timeness of bit-masking operations combined with optimization barriers like volatile reads (e.g. the commonly used rust crate subtle does this).

letmetweakit

Trail of Bits always delivers imo.

valpackett

Wow, finally!! Nice.

Since i386 lacks cmov,

"i586" certainly doesn't.. I vividly remember installing Debian from a "more modern" laptop onto a disk intended for a VIA machine (for reasons), and said machine being unable to boot due to missing cmov! Downgrading to an "i486" kernel fixed it.

accelbread

Nice! hopefully GCC picks this up at some point.

kxli
Comment removed by author