Files
plan9port/man/man3/prime.3
Dmitri Vereshchagin 10564b1175 tmac/tmac.an: define .MR in a groff compatible way
groff 1.23.0 added .MR to its -man macro package.  The NEWS file states
that the inclusion of the macro "was prompted by its introduction to
Plan 9 from User Space's troff in August 2020."  From d32deab it seems
that the name for Plan 9 from User Space's implementation was suggested
by groff maintainer G. Brandon Robinson.

Not sure if the intention was to make these definitions compatible, but
it would be nice if they were.

Currently, Plan 9 from User Space's .MR expects its second argument to
be parenthesized.  groff's .MR does not.  This results in extra
parentheses appearing in manual references when viewing Plan 9 from User
Space's manual pages on a system using groff.
2025-07-27 09:58:50 -04:00

101 lines
1.9 KiB
Groff

.TH PRIME 3
.SH NAME
genprime, gensafeprime, genstrongprime, DSAprimes, probably_prime, smallprimetest \- prime number generation
.SH SYNOPSIS
.B #include <u.h>
.br
.B #include <libc.h>
.br
.B #include <mp.h>
.br
.B #include <libsec.h>
.PP
.B
int smallprimetest(mpint *p)
.PP
.B
int probably_prime(mpint *p, int nrep)
.PP
.B
void genprime(mpint *p, int n, int nrep)
.PP
.B
void gensafeprime(mpint *p, mpint *alpha, int n, int accuracy)
.PP
.B
void genstrongprime(mpint *p, int n, int nrep)
.PP
.B
void DSAprimes(mpint *q, mpint *p, uchar seed[SHA1dlen])
.SH DESCRIPTION
.PP
Public key algorithms abound in prime numbers. The following routines
generate primes or test numbers for primality.
.PP
.I Smallprimetest
checks for divisibility by the first 10000 primes. It returns 0
if
.I p
is not divisible by the primes and \-1 if it is.
.PP
.I Probably_prime
uses the Miller-Rabin test to test
.IR p .
It returns non-zero if
.I P
is probably prime. The probability of it not being prime is
1/4**\fInrep\fR.
.PP
.I Genprime
generates a random
.I n
bit prime. Since it uses the Miller-Rabin test,
.I nrep
is the repetition count passed to
.IR probably_prime .
.I Gensafegprime
generates an
.IR n -bit
prime
.I p
and a generator
.I alpha
of the multiplicative group of integers mod \fIp\fR;
there is a prime \fIq\fR such that \fIp-1=2*q\fR.
.I Genstrongprime
generates a prime,
.IR p ,
with the following properties:
.IP \-
(\fIp\fR-1)/2 is prime. Therefore
.IR p -1
has a large prime factor,
.IR p '.
.IP \-
.IR p '-1
has a large prime factor
.IP \-
.IR p +1
has a large prime factor
.PP
.I DSAprimes
generates two primes,
.I q
and
.IR p,
using the NIST recommended algorithm for DSA primes.
.I q
divides
.IR p -1.
The random seed used is also returned, so that skeptics
can later confirm the computation. Be patient; this is a
slow algorithm.
.SH SOURCE
.B \*9/src/libsec
.SH SEE ALSO
.MR aes 3
.MR blowfish 3 ,
.MR des 3 ,
.MR elgamal 3 ,
.MR rsa 3 ,