PRIME(3)
π
PRIME(3) β like, the prime(3) page from your Library Functions Manual, bestie
okay so first things first, this is section 3 of the Library Functions Manual, and it's all about prime numbers. yes, those primes. the big ones. the cryptographic ones. grab a strawberry π and let's go.
β¨ NAME β¨
genprime, gensafeprime, genstrongprime, DSAprimes, probably_prime, smallprimetest β prime number generation, babes. that's the whole vibe. π₯
πΈ SYNOPSIS πΈ
#include <u.h>
#include <libc.h>
#include <mp.h>
#include <libsec.h>
int smallprimetest(mpint *p)
int probably_prime(mpint *p, int nrep)
void genprime(mpint *p, int n, int nrep)
void gensafeprime(mpint *p, mpint *alpha, int n, int accuracy)
void genstrongprime(mpint *p, int n, int nrep)
void DSAprimes(mpint *q, mpint *p, uchar seed[SHA1dlen])
like, look at all those includes. u.h, libc.h, mp.h, libsec.h β you need them all, no skipping. π
π¦ DESCRIPTION π¦
Public key algorithms abound in prime numbers, like genuinely obsessed with them. so the following routines either generate primes or test numbers for primality. that's it. that's the whole job. π
π the vibes, function by function
π smallprimetest
checks for divisibility by the first 10000 primes. it returns 0 if p is not divisible by the primes and -1 if it is. quick little vibe check, lowkey. β¨
π probably_prime
uses the Miller-Rabin test to test p. it returns non-zero if p is probably prime. the probability of it not being prime is 1/4**nrep. so like, crank up nrep if you want to be sure sure. ngl that's the whole deal. π
πΈ genprime
generates a random n bit prime. since it uses the Miller-Rabin test, nrep is the repetition count passed to probably_prime. easy. π«Ά
β gensafeprime
generates an n-bit prime p and a generator alpha of the multiplicative group of integers mod p. there is a prime q such that p-1=2*q. safe prime behavior, we love to see it. π
π₯ genstrongprime
generates a prime, p, with the following properties, and yes you're getting all three:
(p-1)/2is prime. thereforep-1has a large prime factor,p'.p'-1has a large prime factorp+1has a large prime factor
strong prime said "i have layers" and honestly? iconic. π
π§ DSAprimes
generates two primes, q and p, using the NIST recommended algorithm for DSA primes. q divides p-1. the random seed used is also returned, so that skeptics can later confirm the computation. transparency slay. π
β οΈ ok bestie listen: Be patient; this is a slow algorithm. like, actually slow. go make a snack, hydrate, come back. π
π SOURCE π
/src/libsec
π SEE ALSO π
aes(3), blowfish(3), des(3), elgamal(3), rsa(3)
and that's the page!! π it's PRIME(3) from the Library Functions Manual, section 3, straight outta /src/libsec β stay cryptographic, bestie, mwah π
πβ¨
π¦ where this page comes from
- alpine 3.24: plan9port-doc 0_git20260208-r0 Β· LPL-1.02
- arch rolling: plan9port 20261021-2 Β· custom
- nixos 26.05: plan9port 0-unstable-2025-11-10
- nixos 26.05: plan9port-wayland 0-unstable-2025-11-26
- nixpkgs unstable: plan9port 0-unstable-2025-11-10
- nixpkgs unstable: plan9port-wayland 0-unstable-2025-11-26
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms