Botan 3.11.0
Crypto and TLS for C&
primality.h
Go to the documentation of this file.
1/*
2* (C) 2018 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#ifndef BOTAN_PRIMALITY_TEST_H_
8#define BOTAN_PRIMALITY_TEST_H_
9
10#include <botan/types.h>
11#include <vector>
12
13namespace Botan {
14
15class BigInt;
19
20/**
21* Perform Lucas primality test
22* @see FIPS 186-4 C.3.3
23*
24* @warning it is possible to construct composite integers which pass
25* this test alone.
26*
27* @param n the positive integer to test
28* @param mod_n a pre-created Barrett_Reduction for n
29* @return true if n seems probably prime, false if n is composite
30*/
32
33/**
34* Perform Bailie-PSW primality test
35*
36* This is a combination of Miller-Rabin with base 2 and a Lucas test. No known
37* composite integer passes both tests, though it is conjectured that infinitely
38* many composite counterexamples exist.
39*
40* @param n the positive integer to test
41* @param mod_n a pre-created Barrett_Reduction for n
42* @return true if n seems probably prime, false if n is composite
43*/
45
46/**
47* Return required number of Miller-Rabin tests in order to
48* reach the specified probability of error.
49*
50* @param n_bits the bit-length of the integer being tested
51* @param prob chance of false positive is bounded by 1/2**prob
52* @param random is set if (and only if) the integer was randomly generated by us
53* and thus cannot have been maliciously constructed.
54*/
55size_t miller_rabin_test_iterations(size_t n_bits, size_t prob, bool random);
56
57/**
58* Perform a single Miller-Rabin test with specified base
59*
60* @param n the positive integer to test
61* @param mod_n a pre-created Barrett_Reduction for n
62* @param monty_n Montgomery parameters for n
63* @param a the base to check
64* @return result of primality test
65*/
67 const Barrett_Reduction& mod_n,
68 const Montgomery_Params& monty_n,
69 const BigInt& a);
70
71/**
72* Perform t iterations of a Miller-Rabin primality test with random bases
73*
74* @param n the positive integer to test
75* @param mod_n a pre-created Barrett_Reduction for n
76* @param rng a random number generator
77* @param t number of tests to perform
78*
79* @return result of primality test
80*/
82 const Barrett_Reduction& mod_n,
84 size_t t);
85
86/**
87* Generate DSA parameters using the FIPS 186 kosherizer
88* @param rng a random number generator
89* @param p_out where the prime p will be stored
90* @param q_out where the prime q will be stored
91* @param pbits how long p will be in bits
92* @param qbits how long q will be in bits
93* @return random seed used to generate this parameter set
94*/
95std::vector<uint8_t> generate_dsa_primes(
96 RandomNumberGenerator& rng, BigInt& p_out, BigInt& q_out, size_t pbits, size_t qbits);
97
98/**
99* Generate DSA parameters using the FIPS 186 kosherizer
100* @param rng a random number generator
101* @param p_out where the prime p will be stored
102* @param q_out where the prime q will be stored
103* @param pbits how long p will be in bits
104* @param qbits how long q will be in bits
105* @param seed the seed used to generate the parameters
106* @param offset optional offset from seed to start searching at
107* @return true if seed generated a valid DSA parameter set, otherwise
108 false. p_out and q_out are only valid if true was returned.
109*/
111 BigInt& p_out,
112 BigInt& q_out,
113 size_t pbits,
114 size_t qbits,
115 const std::vector<uint8_t>& seed,
116 size_t offset = 0);
117
118} // namespace Botan
119
120#endif
#define BOTAN_TEST_API
Definition api.h:41
bool is_lucas_probable_prime(const BigInt &C, const Barrett_Reduction &mod_C)
Definition primality.cpp:18
bool is_bailie_psw_probable_prime(const BigInt &n, const Barrett_Reduction &mod_n)
Definition primality.cpp:98
bool passes_miller_rabin_test(const BigInt &n, const Barrett_Reduction &mod_n, const Montgomery_Params &monty_n, const BigInt &a)
bool generate_dsa_primes(RandomNumberGenerator &rng, BigInt &p, BigInt &q, size_t pbits, size_t qbits, const std::vector< uint8_t > &seed_c, size_t offset)
Definition dsa_gen.cpp:54
size_t miller_rabin_test_iterations(size_t n_bits, size_t prob, bool random)
bool is_miller_rabin_probable_prime(const BigInt &n, const Barrett_Reduction &mod_n, RandomNumberGenerator &rng, size_t test_iterations)