You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Issue 1 Multiplication instruction is not constant time on any hardware. The throughput changes based on arguments. This means depending on input arguments any function using this operation will not be constant time.
Issue 3not isn't constant time. xor arg, -1 generally is. With not it can take <1 cycle depending on value, and where in the pipeline it is located.
Issue 4 If/Conditional isn't constant time. This is literally the behavior constant time algorithms attempt to avoid. Go subtle has a good reference on this how to do branching swaps.
Also if you implement the go example in pure rust. It becomes a cmp arg, arg; cmov out, arg;. This fails to be constant time the same reason as equality checking. The speculative execution can increase the time of branching by 10x (since other operations may get re-preformed). That works out to ~200-400 more cycles for false then true.
Issue 5:
The operations present here will fail to make the function:
fn compare_keys(x:&[u8;256],y:&[u8;256) -> bool{for i in0..256{if x[i] != y[i]{returnfalse;}}true
One cannot just twiddle integer operations and get it to be constant time.
The text was updated successfully, but these errors were encountered:
Full write of everything that is broken
Issue 1 Multiplication instruction is not constant time on any hardware. The throughput changes based on arguments. This means depending on input arguments any function using this operation will not be constant time.
Issue 2 Branching is never constant time. On Intel CPU's branches are generally assumed
true
, whenfalse
this incurs a full pipeline flush. So the delta between T/F is around 40+ cycles. Here is what constant time integer equality looks likeIssue 3
not
isn't constant time.xor arg, -1
generally is. Withnot
it can take <1 cycle depending on value, and where in the pipeline it is located.Issue 4 If/Conditional isn't constant time. This is literally the behavior constant time algorithms attempt to avoid. Go subtle has a good reference on this how to do branching swaps.
Also if you implement the go example in pure rust. It becomes a
cmp arg, arg; cmov out, arg;
. This fails to be constant time the same reason as equality checking. The speculative execution can increase the time of branching by 10x (since other operations may get re-preformed). That works out to ~200-400 more cycles for false then true.Issue 5:
The operations present here will fail to make the function:
One cannot just twiddle integer operations and get it to be constant time.
The text was updated successfully, but these errors were encountered: