#prime #miller-rabin #primality-test

rug-miller-rabin

A multi-threaded, arbitrary precision implementation of the Miller-Rabin primality test using rug (GMP)

1 unstable release

0.1.0 Mar 9, 2024

#1938 in Math

31 downloads per month
Used in 3 crates (via rust_ev_crypto_primitives)

LGPL-3.0+

17KB
181 lines

Miller Rabin Primality Test for rug (GMP)

Introduction

This crate implements a multi-threaded, arbitrary precision implementation of the Miller-Rabin primality test.

The implementation ist done for Integer from the crate rug, a high-level interface for GMP.

The crate is strongly inspired from the crate miller_rabin.

Installation

See rug for the requirements and installation steps.

Licence

Rug is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See the full text of the GNU LGPL for details.


lib.rs:

Miller-Rabin Test (multi-threaded) for Integer (rug / GMP)

The methog [is_prime] test if a given number is probably prime using the Miller-Rabin method with the given number of iterations.

Example

use miller_rabin::is_prime;

// Mersenne Prime (2^31 - 1)
let n: u64 = 0x7FFF_FFFF;
assert!(is_prime(&n, 16));

Feature

Per default the test will be run in parallel (using [rayon]). The test can run iteratively deactivate the default feature by importing the crate.

Dependencies

~22MB
~513K SLoC