Earlier quoted context omitted.
A design such that it would actually make sense for a compiler to mark code that should permit data-dependent CPU optimizations differently from code that should not. This could be done using an opcode prefix, which would bloat code but would work perfectly. Or it could use an RFLAGS bit or a bit in MXCSR or a new register, etc. Almost anything would be better than an MSR that is only accessible to privileged code.
> Or it could use an RFLAGS bit or a bit in MXCSR or a new register, etc. > Almost anything would be better than an MSR that is only accessible to privileged code. ARM does that: their flag (DIT) is accessible by non-privileged code. If you know the architecture has that flag, either because your -march= is recent enough or because the operating system told you so through the hwcaps or the emulated id registers, you…
Constant-time support coming to LLVM: Protecting cryptographic code
51–60 of 62 posts
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#52This has been a sore point in a lot of discussions regarding compiler optimizations and cryptographic code, how compilers and compiler engineers are sabotaging the efforts of cryptographers in making sure there are no side-channels in their code. The issue has never been the compiler, and has always been the language: there was never a way to express the right intention from within C (or most other languages, really)…
> how compilers and compiler engineers are sabotaging the efforts of cryptographers I'm not exposed to this space very often, so maybe you or someone else could give me some context. "Sabotage" is a deliberate effort to ruin/hinder something. Are compiler engineers deliberately hindering the efforts of cryptographers? If yes... is there a reason why? Some long-running feud or something? Or, through the course of thei…
A lot of software engineer are seeing this as compiler engineer only caring about performance as opposed to other aspect such as debuggability, safety, compile time and productivity etc... I think that's where the "sabotage" comes from. Basically the focus on performance at the detriment of other things.
My 2 cents : The core problem is programmers expecting invariant and properties not defined in the languange standard. The compiler only garanty things as defined in the standard, expecting anything else is problematic.
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#53I think __builtin_ct_select and __builtin_ct_expr would be good ideas. (They could also be implemented in GCC in future, as well as LLVM.) In some cases it might be necessary to consider the possibility of invalid memory accesses (and avoid the side-channels when doing so). (The example given in the article works around this issue, but I don't know if there are any situations where this will not help.)
The names are pretty unattractive (which is not uncommon for C) though to the point one would want to avoid them in the code.
#define ct_select __builtin_ct_select
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#54Re: Constant-time support coming to LLVM: Protecting cryptographic code
#55Earlier quoted context omitted.
> Or it could use an RFLAGS bit or a bit in MXCSR or a new register, etc. > Almost anything would be better than an MSR that is only accessible to privileged code. ARM does that: their flag (DIT) is accessible by non-privileged code. If you know the architecture has that flag, either because your -march= is recent enough or because the operating system told you so through the hwcaps or the emulated id registers, you…
The one reason I can imagine to make it privileged-only is that it could be high-overhead to switch: if a CPU conditioned various kinds of predictors on it, it might have to flush those predictors when toggling it.
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#56I'd love if this could make it into Rust... but I'm wondering if it'd be a bit of a burden on the creators of alternative backends (e.g. Cranelift), since if they implemented it naively, they would be unsuitable for compiling cryptographic code using it.
Technically any new feature that requires backend support is an additional burden on backend devs. There's nothing special about constant-time builtins in this respect.
> since if they implemented it naively
Strictly speaking, whether an implementation is naive is independent of whether it is correct. An implementation that purports to be constant time while not actually being constant time is wrong, no matter how naive or sophisticated the implementation may be.
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#57Earlier quoted context omitted.
Why would you like register and auto to have meaning?
Because for timing-sensitive code, those are important. If a variable is really a register, cache-based timing attacks just don't happen, because there is no cache in between.
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#58Earlier quoted context omitted.
Sorry, I may be missing the point here, but reading that page doesn’t immediately make it obvious to me what that feature is. Is it some constant time execution mechanism that you can enable / disable on a per-thread basis to do… what exactly?
It turns off CPU features that could cause execution time to vary in a way that depends on the data being operated on.
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#59Earlier quoted context omitted.
It turns off CPU features that could cause execution time to vary in a way that depends on the data being operated on.
Isn’t that exactly what you want for constant time algorithms? So why does the grandparent cite this article as Intel preventing LLVM’s techniques from working?
Re: Constant-time support coming to LLVM: Protecting cryptographic code
#60"Constant-Time Coding Support in LLVM: Protecting Cryptographic Code at the Compiler Level" (2025-10) PDF: https://llvm.org/devmtg/2025-10/slides/quick_talks/alexandre... :
> Circumvent Branch-base Timing Attacks