1 ! Copyright (C) 2009 Doug Coleman.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators.short-circuit help.markup help.syntax kernel
4 math math.functions math.primes random ;
12 { $description "Tests consecutive numbers and returns the next safe prime. A safe prime is desirable in cryptography applications such as Diffie-Hellman and SRP6." } ;
14 HELP: random-safe-prime
19 { $description "Returns a safe prime number " { $snippet "numbits" } " bits in length, with the topmost bit set to one." } ;
26 { $description "Tests whether the number is a safe prime. A safe prime " { $snippet "p" } " must be prime, as must " { $snippet "(p - 1) / 2" } "." } ;
29 ARTICLE: "math.primes.safe" "Safe prime numbers"
30 "The " { $vocab-link "math.primes.safe" } " vocabulary implements words to calculate safe prime numbers. Safe primes are of the form p = 2q + 1, where p,q are prime. Safe primes have desirable qualities for cryptographic applications." $nl
32 "Testing if a number is a safe prime:"
33 { $subsection safe-prime? }
34 "Generating safe prime numbers:"
35 { $subsection next-safe-prime }
36 { $subsection random-safe-prime } ;
38 ABOUT: "math.primes.safe"