Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It doesn't work #4

Open
valarauca opened this issue Dec 19, 2016 · 0 comments
Open

It doesn't work #4

valarauca opened this issue Dec 19, 2016 · 0 comments

Comments

@valarauca
Copy link

valarauca commented Dec 19, 2016

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, when false this incurs a full pipeline flush. So the delta between T/F is around 40+ cycles. Here is what constant time integer equality looks like

Issue 3 not 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 in 0..256 {
           if x[i] != y[i] {
                  return false;
           }
      }
      true

One cannot just twiddle integer operations and get it to be constant time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant