User avatar
sodiboo pride_heart @sodiboo@gaysex.cloud
1mo
compilers famously love to optimize away all your code to make it execute faster without changing behavior, which is usually great news. but also, famously, sometimes the "slow" speed is the desirable behavior in cryptographic algorithms.

it is, to my understanding, generally accepted that compilers just don't understand this constraint, so it's often the case that constant-time algorithms are just written in raw assembly, because the compiler won't try to make that faster.

but like, is there any compiler that understands? is there any language where constant-time code / "no timing side channels" is at all possible to express in a way that the compiler isn't allowed to break those invariants?

by which i specifically mean: is there any vaguely high level programming language with these properties, such that "optimizations" broadly are possible, but the Dangerous optimizations can be reliably avoided when necessary to uphold security properties? not just an escape hatch to disable optimizations (or even a fine-grained way to opt out of specific optimizations). i mean a system to encode the actual invariant and where the
language semantics rely on this for correctness. maybe even, if i say that a value should be constant-time but the way i wrote it has a side channel before optimizations, the compiler should reject that too, the same way as returning the wrong type of value is unacceptable.

is there any tooling that does something like this? or which otherwise knows how to reason about such code in an interesting way? to be clear, the goal is not to write crypto code. my goal is to maybe learn a novel way to reason about code.
11
2
1
0
User avatar
celeste_hearts_lesbianceleste_hearts_transceleste_hearts_demisexual flori_ava_star:~cursor_blinking @star@amazonawaws.com
1mo
@sodiboo I think there are LLVM symbols that understand this? Don't quote me on that tho
1
0
4
0

User avatar
sodiboo pride_heart @sodiboo@gaysex.cloud
1mo
@star oh, wow, yeah! it actually seems like there is work to make this possible in LLVM and clang (and therefore C, which is actually huge for portability)

these resources I found within <1min of searching seem awfully recent:

discourse.llvm.org/t/rfc-constant-time-coding-support/87781
blog.trailofbits.com/2025/12/02/introducing-constant-time-support-for-llvm-to-protect-cryptographic-code/

so it's not clear to me that this is actually available today? at any rate, it seems "hacked on" after the fact (albeit that doesn't always have to be negative; lots of things were not part of original design but still turn out great). LLVM is definitely high level enough to be in scope for what i was asking about.

i was mainly wanting to see if there's anything at all built with this in mind from the start? like, I'm curious to see, would that radically change the design of the compiler pipeline? if duration-sensitivity was as prevalent in the rules as, say, pointer provenance?

GPUs kinda don't support branching properly, do they? i've seen a lot of GPU code be "wastefully parallel" to avoid branching, because like, the control flow is shared across several cores or something? i wonder what GPU people are up to. they seem to have a similar problem to cryptographers for an entirely different reason.
0
0
0
0