simon-git: putty (master): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Sat Jan 5 14:20:25 GMT 2019


TL;DR:
  8e399f9a Speed up and simplify mp_invert.

Repository:     https://git.tartarus.org/simon/putty.git
On the web:     https://git.tartarus.org/?p=simon/putty.git
Branch updated: master
Committer:      Simon Tatham <anakin at pobox.com>
Date:           2019-01-05 14:20:25

commit 8e399f9aa7f841ede085c2ea2dbe2f2382f4dd06
web diff https://git.tartarus.org/?p=simon/putty.git;a=commitdiff;h=8e399f9aa7f841ede085c2ea2dbe2f2382f4dd06;hp=4a0fa90979d43a6ba93ff8fa6a5ac81cf981e8d0
Author: Simon Tatham <anakin at pobox.com>
Date:   Sat Jan 5 13:47:26 2019 +0000

    Speed up and simplify mp_invert.
    
    When I was originally designing my knockoff of Stein's algorithm, I
    simplified it for my own understanding by replacing the step that
    turns a into (a-b)/2 with a step that simply turned it into a-b, on
    the basis that the next step would do the division by 2 in any case.
    This made it easier to get my head round in the first place, and in
    the initial Python prototype of the algorithm, it looked more sensible
    to have two different kinds of simple step rather than one simple and
    one complicated.
    
    But actually, when it's rewritten under the constraints of time
    invariance, the standard way is better, because we had to do the
    computation for both kinds of step _anyway_, and this way we sometimes
    make both of them useful at once instead of only ever using one.
    
    So I've put it back to the more standard version of Stein, which is a
    big improvement, because now we can run in at most 2n iterations
    instead of 3n _and_ the code implementing each step is simpler. A
    quick timing test suggests that modular inversion is now faster by a
    factor of about 1.75.
    
    Also, since I went to the effort of thinking up and commenting a pair
    of worst-case inputs for the iteration count of Stein's algorithm, it
    seems like an omission not to have made sure they were in the test
    suite! Added extra tests that include 2^128-1 as a modulus and 2^127
    as a value to invert.

 mpint.c            | 104 ++++++++++++++++++++++++++---------------------------
 test/cryptsuite.py |   5 +--
 2 files changed, 55 insertions(+), 54 deletions(-)



More information about the tartarus-commits mailing list