Skip to content

Inversion (WIP) - #670

Merged
JasonGross merged 17 commits into
mit-plv:masterfrom
bshvass:master
Oct 27, 2020
Merged

Inversion (WIP)#670
JasonGross merged 17 commits into
mit-plv:masterfrom
bshvass:master

Conversation

@bshvass

@bshvass bshvass commented Mar 6, 2020

Copy link
Copy Markdown
Contributor

The following PR is an attempt at implementing a constant time inversion algorithm by D.J Bernstein (available at https://gcd.cr.yp.to/papers.html#safegcd).
At the moment it is just a subroutine, called divstep2 in the paper, which is implemented and proven functionally correct. This is the content of src/Arithmetic/Inv.v. It can be printed to C by the code in src/PushButtonSynthesis/TestInv.

Since it is only a subroutine, there is a C implementation of the remaining steps in test-inversion-c/test_bls.c (this is the inversion function; the main is a test).
An implementation using the divstep2 as generated by Fiat is also available in the RELIC toolkit (https://github.com/relic-toolkit/relic see commit bd87b62e0acb1d65b360d104059d29ebd676cd97)
This achieves quite a good performance (about twice as slow as hand optimized, non-constant time extended euclidean) and there are still many optimizations which can be done.

To be able to generate the full algorithm, however, we need bounded loops and/or function calls to be supported.
Also one optimization (which is the implementation presented in the Bernstein paper) requires multiplication of 64-bit numbers and saturated multi limbs numbers (e.g. 128-bit, 192-bit etc. (NOT mod p)). Is this something that is already supported? I was able to find a sat_mul function, but not one which was reifiable (in src/Arithmetic/Saturated.v).

Loading
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

Successfully merging this pull request may close these issues.

6 participants