The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE 6 technical preview.
  4. Copyright (c) 2020 - Raw Material Software Limited
  5. You may use this code under the terms of the GPL v3
  6. (see www.gnu.org/licenses).
  7. For this technical preview, this file is not subject to commercial licensing.
  8. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  9. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  10. DISCLAIMED.
  11. ==============================================================================
  12. */
  13. namespace juce
  14. {
  15. //==============================================================================
  16. /**
  17. Prime number creation class.
  18. This class contains static methods for generating and testing prime numbers.
  19. @see BigInteger
  20. @tags{Cryptography}
  21. */
  22. class JUCE_API Primes
  23. {
  24. public:
  25. //==============================================================================
  26. /** Creates a random prime number with a given bit-length.
  27. The certainty parameter specifies how many iterations to use when testing
  28. for primality. A safe value might be anything over about 20-30.
  29. The randomSeeds parameter lets you optionally pass it a set of values with
  30. which to seed the random number generation, improving the security of the
  31. keys generated.
  32. */
  33. static BigInteger createProbablePrime (int bitLength,
  34. int certainty,
  35. const int* randomSeeds = nullptr,
  36. int numRandomSeeds = 0);
  37. /** Tests a number to see if it's prime.
  38. This isn't a bulletproof test, it uses a Miller-Rabin test to determine
  39. whether the number is prime.
  40. The certainty parameter specifies how many iterations to use when testing - a
  41. safe value might be anything over about 20-30.
  42. */
  43. static bool isProbablyPrime (const BigInteger& number, int certainty);
  44. private:
  45. Primes();
  46. JUCE_DECLARE_NON_COPYABLE (Primes)
  47. };
  48. } // namespace juce