blob: 9a595730b8d3ef54d1ab17f09e73d2ed0f0d80ee [file] [log] [blame]
rsccfa37a72004-04-10 18:53:55 +00001.TH PRIME 3
2.SH NAME
3genprime, gensafeprime, genstrongprime, DSAprimes, probably_prime, smallprimetest \- prime number generation
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.br
9.B #include <mp.h>
10.br
11.B #include <libsec.h>
12.PP
13.B
14int smallprimetest(mpint *p)
15.PP
16.B
17int probably_prime(mpint *p, int nrep)
18.PP
19.B
20void genprime(mpint *p, int n, int nrep)
21.PP
22.B
23void gensafeprime(mpint *p, mpint *alpha, int n, int accuracy)
24.PP
25.B
26void genstrongprime(mpint *p, int n, int nrep)
27.PP
28.B
29void DSAprimes(mpint *q, mpint *p, uchar seed[SHA1dlen])
30.SH DESCRIPTION
31.PP
32Public key algorithms abound in prime numbers. The following routines
33generate primes or test numbers for primality.
34.PP
35.I Smallprimetest
36checks for divisibility by the first 10000 primes. It returns 0
37if
38.I p
39is not divisible by the primes and \-1 if it is.
40.PP
41.I Probably_prime
42uses the Miller-Rabin test to test
43.IR p .
44It returns non-zero if
45.I P
46is probably prime. The probability of it not being prime is
471/4**\fInrep\fR.
48.PP
49.I Genprime
50generates a random
51.I n
52bit prime. Since it uses the Miller-Rabin test,
53.I nrep
54is the repetition count passed to
55.IR probably_prime .
56.I Gensafegprime
57generates an
58.IR n -bit
59prime
60.I p
61and a generator
62.I alpha
63of the multiplicative group of integers mod \fIp\fR;
64there is a prime \fIq\fR such that \fIp-1=2*q\fR.
65.I Genstrongprime
66generates a prime,
67.IR p ,
68with the following properties:
69.IP \-
70(\fIp\fR-1)/2 is prime. Therefore
71.IR p -1
72has a large prime factor,
73.IR p '.
74.IP \-
75.IR p '-1
76has a large prime factor
77.IP \-
78.IR p +1
79has a large prime factor
80.PP
81.I DSAprimes
82generates two primes,
83.I q
84and
85.IR p,
86using the NIST recommended algorithm for DSA primes.
87.I q
88divides
89.IR p -1.
90The random seed used is also returned, so that skeptics
91can later confirm the computation. Be patient; this is a
92slow algorithm.
93.SH SOURCE
rscb5fdffe2004-04-19 19:22:56 +000094.B /usr/local/plan9/src/libsec
rsccfa37a72004-04-10 18:53:55 +000095.SH SEE ALSO
rscbf8a59f2004-04-11 03:42:27 +000096.IR aes (3)
97.IR blowfish (3),
98.IR des (3),
99.IR elgamal (3),
100.IR rsa (3),