Git Product home page Git Product logo

ecpp-verifier's Introduction

Collection of primality certificates and an open source tool that can be used to verify them.

Application can verify Atkin-Goldwasser-Kilian-Morain Certificate, Pocklington certificate and Brillhart, Lehmer, Selfridge certificate (Theorem 15) based primality proofs, commonly generated by the Primo application.

Read more on primality testing

When verifying primality certificates, it also checks if the number is not vulnerable to Special Number Field Sieve, as primes of this form have effective bit size reduced by a third (i.e. 3072 bit SNFS-vulnerable prime is about as easy to attack as a 2048 bit prime).

Installation

From distribution files

Download the most recent release .whl file from github:

curl -s https://api.github.com/repos/tomato42/ecpp-verifier/releases/latest \
| grep "browser_download_url.*whl" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -i -

Or manually, by visiting latest release and downloading the .whl file from there.

Install it using pip:

pip3 install ecpp-*.whl

Verify that it can be executed:

ecpp --help

Install gmpy2 package to double the performance of certificate verification:

pip3 install gmpy2

From sources

Clone this repository:

git clone https://github.com/tomato42/ecpp-verifier.git
cd ecpp-verifier

Install dependencies (for example on Fedora):

dnf install python3-ecdsa python3-gmpy2

Or from PyPI:

pip3 install ecdsa[gmpy2]

(Note: as gmpy2 is a binary package you will need to install development headers for python and the gmp library. Alternatively, you can skip installation of gmpy2 at the cost of halved performance).

Make sure you have installed ecdsa package version 0.15 or newer. Older versions have significant performance issues and certificate verification will take ages.

Run ecpp for the first time:

PYTHONPATH=src ./ecpp --help

Usage

Matching certificates to primes in OpenSSH moduli file

To check if you have primality certificates for all the primes in your OpenSSH moduli file, you can use ecpp with -m switch:

ecpp -m /etc/ssh/moduli

This will succeed for example for moduli file released with OpenSSH 8.2p1, listing certificates for each prime.

Verifying primality certificates for primes in moduli file

To verify the matching certificates you can combine the -m switch with the -v switch:

ecpp -m /etc/ssh/moduli -v

This will succeed if the script finds matching certificates and verifies them as valid.

Note: it will require significantly more time to execute than just the -m option. It's also a single-threaded process, see #12.

Generating primality certificates for primes in moduli file for OpenSSH

If there are some primes without primality certificates, you can generate input files for Primo into in/ directory.

ecpp -m /etc/ssh/moduli -p

Now, open Primo downloaded from link above, extract archive and start GUI on a reasonably powerful machine (at this moment, Primo can work with up to 64 cores).

  • From Menu, select Setup..., set number of cores your system have (hyper-threading is not much useful)
  • In tab Certification, select 3000 dd (decimal digits) in Trial Division Parameters and click Build prime table button.
  • Then click Load. Select all the .in files in the in/ directory created by the previous step and click Open.
  • After long time, you will get certificates in *.out files in the same directory.

Verify primality certificates

In previous step, we got certificates for primes. Now we need to verify them. This can be done with the following command for one certificate:

ecpp -i in/primo-B412D0397A9D9-07E.out

The job can be simply parallelized so if we want to verify all the certificates we got, we can use GNU parallel to get results in parallel, in this example using 16 parallel processes:

parallel -j16 "echo {} && ecpp -i {}" ::: in/*.out

Now, we can add the primality certificates to src/ecpp/certificates/ directory.

Matching certificates to primes in OpenSSH moduli file again

Running ecpp again as in the first example should confirm we have a certificate for each prime in the moduli file now.

ecpp -m /etc/ssh/moduli

ecpp-verifier's People

Contributors

beldmit avatar jakuje avatar t184256 avatar tomato42 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

ecpp-verifier's Issues

SSH protocol support

add ability to connect to SSH server, save the prime that it advertised and verify if it is a safe prime

Permission denied when verifying Primo output

I’ve run Primo as separate user account, but the output files are readable. However:

tglase@tglase:/opt/primo/ecpp-verifier $ parallel -j5 -i sh -c "echo {} && python3 
in/primo-B42E8004547B2-001.out
in/primo-B42E8004547B2-005.out
in/primo-B42E8004547B2-002.out
in/primo-B42E8004547B2-004.out
in/primo-B42E8004547B2-003.out
Traceback (most recent call last):
  File "/opt/primo/ecpp-verifier/ecpp", line 404, in <module>
    main()
  File "/opt/primo/ecpp-verifier/ecpp", line 377, in main
    cert = read_config(input_file, False)
  File "/opt/primo/ecpp-verifier/ecpp", line 68, in read_config
    with open(filename, "r+") as fp:
PermissionError: [Errno 13] Permission denied: 'in/primo-B42E8004547B2-001.out'
[…]

The file is readable though:

tglase@tglase:/opt/primo/ecpp-verifier $ ll in/primo-B42E8004547B2-001.out
-rw-r--r-- 1 primo primo 29288 22. Aug 01:16 in/primo-B42E8004547B2-001.out
tglase@tglase:/opt/primo/ecpp-verifier $ head -1 in/primo-B42E8004547B2-001.out
[PRIMO - Primality Certificate]

TLS protocol support

add ability to connect to TLS server, save the prime it proposed and verify if it is a safe prime

Multi-core support for verification

Verification of multiple primality certificates is embarrassingly parallel, it would be nice to be able to use multiple cores to do that.

Document usage

We should have a manual that explains:

  • which dependencies are necessary to install
  • how to use ecpp to verify a moduli file
  • how to generate new primality certificates

Add CI

We should add unit tests and CI that will run them.

Detailed progress reporting during verification

Because verifying even a modest certificate (1536 bit prime) takes good half a minute and can take more than an hour for big primes (8196 bit), it would be nice to have a progress bar or completion percentage reported

.pem file support

add ability to load primes from .pem files with DH parameters and verifying that they are safe primes

Pitfalls when running on Debian

It would be kind to add this to the documentation:


You can install all prerequisites from the repository, no need for pip3 or to compile anything:

sudo apt-get install python3-gmpy2 python3-ecdsa

However, you cannot run the file directly as its shebang points to Python 2, which you probably don’t have installed any more. So use…

PYTHONPATH=src python3 ./ecpp --help

… etc. (that is, put a python3 before the script name).

Instructions unclear

The readme only ever mentions -m modulifile for verification, but https://www.redhat.com/en/blog/understanding-and-verifying-security-diffie-hellman-parameters has the user run -v -m modulifile.

When exactly do we need this, and what’s the difference?

My use case is to check whether the moduli I generated are good (or rather, if there are any bad lines, and if so, which, so I can remove them). I have so far run -m modulifile run once, found missing primes, ran Primo, and am now verifying the Primo outfiles. I would then move all outfiles that pass both tests (prime and not SNFS) to src/ecpp/certificates/myname/ and then run… what exactly, with -v? If so, why is this not in the README? If not, what is -v for?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.