Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upIt doesn't work #4
Comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
valarauca commentedDec 19, 2016
•
edited
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, whenfalsethis 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
notisn't constant time.xor arg, -1generally is. Withnotit 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.