Replace set/add with cmov in secp256k1_gej_add_ge. #243

pull gmaxwell wants to merge 1 commits into bitcoin-core:master from gmaxwell:gej_add_cmov changing 4 files +44 −8
  1. gmaxwell commented at 0:44 am on April 22, 2015: contributor

    Use a conditional move of the same kind we use for the affine points in the storage type instead of multiplying with the infinity flag and adding. This results in fewer constructions to worry about for sidechannel behavior.

    It also might be faster: It doesn’t appear to benchmark as slower for me at least; but I think the CMOV is faster than the mul_int + add, but slower than the set+add; making it a wash.

  2. Replace set/add with cmov in secp256k1_gej_add_ge.
    Use a conditional move of the same kind we use for the affine points
     in the storage  type instead of multiplying  with the infinity flag
     and adding.  This results in fewer constructions to worry about for
     sidechannel behavior.
    
    It also might be faster: It doesn't appear to benchmark as slower for
     me at least; but I think  the CMOV is faster than the mul_int + add,
     but slower than the set+add;  making it a wash.
    bb0ea50de8
  3. gmaxwell commented at 0:46 am on April 22, 2015: contributor

    I also tried adding a fe_add_int (e.g. r[0]+=a;) that made do strictly no more work, but I couldn’t benchmark it as any faster; and it didn’t seem worth the additional code to review. … but inlined it should save a fair chunk of code size (one instruction vs … many). @sipa if you want I can post the trivial code for that.

    [I was specifically looking at what code paths touched the affine x,y to figure out if it would be valuable for a ‘small table’ implementation running on a platform with magnitude dependent multipliers to have a specially computed Z (using the effective-affine style isomorphism) to achieve a property where all the entries in the table had all the words in their field have the same log(2). ]

  4. sipa commented at 9:39 am on April 22, 2015: contributor
    I measure a gej_add_ge slowdown of 0.9% (consistently), and a signing slowdown of 0.2% or so (hard to measure exactly). ACK.
  5. sipa merged this on Apr 22, 2015
  6. sipa closed this on Apr 22, 2015

  7. sipa referenced this in commit 426fa52511 on Apr 22, 2015


gmaxwell sipa


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/secp256k1. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-11-24 10:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me