Question: is constant time in the roadmap, anywhere? Just asking. The question comes from the fact that LLVM has been at odds with constant-time since forever. Yet: Introducing constant-time support for LLVM to protect cryptographic code - The Trail of Bits Blog
If the LLVM PR was merged (it isn’t), you could do this as long as Crystal uses the correct version of LLVM:
lib LibIntrinsics
fun ct_select_i64 = "llvm.ct.select.i64"(Bool, Int64, Int64) : Int64
end
fun constant_time_lookup(secret_idx : Int32, table : Int64*) : Int64
result = 0_i64
i = 0
while i < 8
cond = i == secret_idx
result |= LibIntrinsics.ct_select_i64(cond, table[i], 0_i64)
i &+= 1
end
result
end
1 Like
I believe it makes sense for Crystal to wait until LLVM figures this out so that we can easily adopt it.
1 Like