MODULI(5)

๐Ÿ“ฆ
version 10.6p1 ยท 4 versions
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, centos-stream 10, centos-stream 9, debian bookworm, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

โœจ NAME โœจ

okay so the page is all about moduli ๐Ÿซถ (that's the Diffie-Hellman moduli, fr). it's from the File Formats Manual, so this is literally the file format bestie, not a command ๐Ÿ’…

๐Ÿ” DESCRIPTION ๐Ÿ”

okay so /etc/ssh/moduli is basically a list of prime numbers and generators that sshd(8) uses for the Diffie-Hellman Group Exchange key exchange method ๐Ÿฆ‹ it's giving secure and organized โœจ

making new moduli is lowkey a two-step glow up with ssh-keygen(1) ๐ŸŒธ

  • step one: an initial candidate pass with ssh-keygen -M generate digs up numbers that are likely to be useful ๐Ÿงš
  • step two: a primality testing pass with ssh-keygen -M screen gives you a high level of assurance that the numbers are prime and actually safe for Diffie-Hellman with sshd(8) ๐Ÿ’–

both passes spit out this same moduli format, so it's consistent no cap ๐Ÿ‘‘

the file is newline-separated records, one per modulus ๐ŸŽ€ each record has seven space-separated fields, and they go like this:

  • timestamp ๐Ÿ•ฐ๏ธ the time the modulus was last processed, written as YYYYMMDDHHMMSS
  • type ๐Ÿ”ข a decimal number for the internal structure of the prime modulus. the supported types are:
    • 0 โ€” unknown, not tested ๐Ÿ™ˆ
    • 2 โ€” "Safe" prime; (p-1)/2 is also prime โœจ
    • 4 โ€” Sophie Germain; 2p+1 is also prime ๐ŸŒˆ

ngl the candidates from ssh-keygen(1) start out as Sophie Germain primes (type 4) ๐Ÿ’… then more primality testing with ssh-keygen(1) turns them into safe prime moduli (type 2), which are the ones ready to go for sshd(8) ๐Ÿ”ฅ other types are not used by OpenSSH, so skip those vibes ๐Ÿ™…โ€โ™€๏ธ

  • tests ๐Ÿงช a decimal number showing which primality tests the number went through, stored as a bitmask:
    • 0x00 โ€” not tested ๐Ÿ’€
    • 0x01 โ€” composite number โ€“ not prime ๐Ÿšซ
    • 0x02 โ€” Sieve of Eratosthenes ๐ŸŒธ
    • 0x04 โ€” probabilistic Miller-Rabin primality tests ๐Ÿฆ‹

the ssh-keygen(1) candidate generation uses the Sieve of Eratosthenes (flag 0x02) ๐Ÿงš and the later ssh-keygen(1) primality tests are Miller-Rabin tests (flag 0x04) โœจ

  • trials ๐Ÿ” a decimal number for how many primality trials the modulus has gotten
  • size ๐Ÿ“ a decimal number for the size of the prime in bits
  • generator ๐ŸŽ the recommended generator to use with this modulus, in hexadecimal
  • modulus ๐Ÿ’œ the modulus itself, in hexadecimal

when Diffie-Hellman Group Exchange is happening, sshd(8) first estimates how big the modulus needs to be so there's enough Diffie-Hellman output to properly key the chosen symmetric cipher ๐Ÿ” then it randomly picks a modulus from /etc/ssh/moduli that best fits that size requirement ๐ŸŽฒ iykyk, it's a whole vibe โœจ


๐ŸŒŸ SEE ALSO ๐ŸŒŸ

ssh-keygen(1), sshd(8) ๐Ÿซถ

๐Ÿ“œ STANDARDS ๐Ÿ“œ

M. Friedl, N. Provos, and W. Simpson, Diffie-Hellman Group Exchange for the Secure Shell (SSH) Transport Layer Protocol, RFC 4419, March 2006 ๐Ÿ’–


okay that's the tea, bestie ๐Ÿซถโœจ this page came from Debian, April 16, 2022, and it's MODULI(5) all the way ๐Ÿ’…๐ŸŒธ

๐Ÿ“ฆ where this page comes from