↓ Skip to main content

Part 5: The Story of RSA-8

·523 words·3 mins·
Table of Contents
RSA-8 - This article is part of a series.
Part 5: This Article
Connecting the RSA-8 toy key to ssh-keygen

The 8-bit exercise is not just arithmetic. It gives us a mental model for understanding a real RSA key generated for SSH.

For example:

ssh-keygen -t rsa -b 2048

asks ssh-keygen to generate an RSA key with a roughly 2048-bit modulus.

Conceptual comparison
#

Educational RSA              Real RSA key generation
---------------              -----------------------
p = 11                       p = large generated prime
q = 13                       q = large generated prime
       \                         /
        +------ multiply -------+
                  |
                  v
n = 143                       n ~ 2048 bits

The RSA implementation uses cryptographically secure randomness supplied by the OS as part of generating suitable prime candidates. It then performs the required tests and calculations to construct the RSA key.

So it is more accurate to say:

When ssh-keygen generates an RSA key, the RSA implementation uses cryptographically secure random data from the OS to generate suitable large secret primes and construct the RSA public and private keys.

It is not best described as the operating-system kernel simply selecting p and q itself.

Not every SSH key is RSA
#

This distinction matters.

ssh-keygen -t rsa

uses RSA, so our p, q, n, e, and d mental model is relevant.

But:

ssh-keygen -t ed25519

uses Ed25519, an elliptic-curve signature system. It does not generate an RSA pair of primes p and q.

So the 8-bit story is specifically a way to understand RSA, not every form of public-key cryptography.

RSA-8 Revision Sheet
#

If I come back to this article months later, these are the points I want to remember.

RSA key construction
#

1. Generate distinct primes p and q
2. n = p * q
3. phi(n) = (p - 1)(q - 1)       # for distinct primes
4. Choose suitable public exponent e
5. Compute private exponent d as a modular inverse
6. Public key contains (e, n)
7. Private RSA information must remain secret

For our demo:

p = 11
q = 13
n = 143
phi(n) = 120
e = 7
d = 103

Public key  = (7,143)
Private key = (103,143)

Textbook encryption and decryption
#

Encrypt: c = m^e mod n
Decrypt: m = c^d mod n

Our message:

9 --public key--> 48 --private key--> 9

How our key is cracked
#

Public n = 143
      |
      v
143 = 11 * 13
      |
      v
phi(n) = 120
      |
      v
d = 7^-1 mod 120
      |
      v
d = 103
      |
      v
Private key recovered

The most important lesson
#

RSA does not hide the algorithm and it does not hide n or e.

Its classical security relies heavily on the difficulty of recovering appropriately generated large secret factors from the public modulus.

The 8-bit version fails instantly because:

143 = 11 * 13

The real system scales the same broad mathematical idea to numbers large enough for the required security level and combines it with carefully specified algorithms, padding, key-generation rules, and implementations.

For Memory Aid
#

RSA turns two secret primes into a public modulus; the toy key teaches us that if an attacker can efficiently recover those factors, they can reconstruct the private-key mathematics.

MySeq
Author
MySeq
myseq.github.io
RSA-8 - This article is part of a series.
Part 5: This Article

Related