tc_prime
Primality testing and prime generation for cryptography over the integers of
tc_bigint, after Bouncy Castle's
Primes: trial division, Miller-Rabin, the enhanced test of FIPS 186-4, and
Shawe-Taylor provable primes. no_std, no unsafe, Rust 1.85 or later.
Types
MrOutput<T>— what the enhanced Miller-Rabin test found: probably prime, or composite with or without a factor.StOutput<T>(shawe-taylor) — a provable prime, with the seed and counter the routine ends at.StError(shawe-taylor) — why the Shawe-Taylor routine gave no prime.
Traits
Primality— trial division, Miller-Rabin, the enhanced test and random probable primes, onFixedBigUint<N>,PaddedBigUintandBigUint.ShaweTaylor(shawe-taylor) — provable primes by FIPS 186-4 C.6 from atc_digestdigest and a seed.
Features
alloc(off by default) — the traits onPaddedBigUintandBigUint.shawe-taylor(off by default) —ShaweTaylor, which addstc_digestand turns onalloc.
Usage
use ;
use Primality;
type U256 = 256 / BITS as usize }>;
let p = U256from; // 2^127 - 1, a prime
assert!;
assert!;
Security
Every test and generator is variable time, as Bouncy Castle's are: only for
public values, or for candidates whose timing a caller accepts showing, as key
generation does. The random values come from the rand_core generator the
caller gives, which has to be cryptographically secure for key generation.
This is a learning port with no independent security audit.
License
Licensed under either the MIT license or the Apache License, Version 2.0, at your option.