1 /*
2   ==============================================================================
3 
4    This file is part of the JUCE library.
5    Copyright (c) 2020 - Raw Material Software Limited
6 
7    JUCE is an open source library subject to commercial or open-source
8    licensing.
9 
10    By using JUCE, you agree to the terms of both the JUCE 6 End-User License
11    Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
12 
13    End User License Agreement: www.juce.com/juce-6-licence
14    Privacy Policy: www.juce.com/juce-privacy-policy
15 
16    Or: You may also use this code under the terms of the GPL v3 (see
17    www.gnu.org/licenses).
18 
19    JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
20    EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
21    DISCLAIMED.
22 
23   ==============================================================================
24 */
25 
26 namespace juce
27 {
28 
29 //==============================================================================
30 /**
31     Prime number creation class.
32 
33     This class contains static methods for generating and testing prime numbers.
34 
35     @see BigInteger
36 
37     @tags{Cryptography}
38 */
39 class JUCE_API  Primes
40 {
41 public:
42     //==============================================================================
43     /** Creates a random prime number with a given bit-length.
44 
45         The certainty parameter specifies how many iterations to use when testing
46         for primality. A safe value might be anything over about 20-30.
47 
48         The randomSeeds parameter lets you optionally pass it a set of values with
49         which to seed the random number generation, improving the security of the
50         keys generated.
51     */
52     static BigInteger createProbablePrime (int bitLength,
53                                            int certainty,
54                                         const int* randomSeeds = nullptr,
55                                            int numRandomSeeds = 0);
56 
57     /** Tests a number to see if it's prime.
58 
59         This isn't a bulletproof test, it uses a Miller-Rabin test to determine
60         whether the number is prime.
61 
62         The certainty parameter specifies how many iterations to use when testing - a
63         safe value might be anything over about 20-30.
64     */
65     static bool isProbablyPrime (const BigInteger& number, int certainty);
66 
67 
68 private:
69     Primes();
70 
71     JUCE_DECLARE_NON_COPYABLE (Primes)
72 };
73 
74 } // namespace juce
75