In the following we generate an RSA key pair with a given number of bits in the modulus [ECC key pair]:
Generating a key pair |
Outline
We can generate a 512-bit key pair with:
$ openssl genrsa 512 -text -----BEGIN RSA PRIVATE KEY----- MIIBOQIBAAJBAL1SAt58PHEWe2Ds1xtDXv8kbbCcBD1q8MAQxw9XrbAzGBleYStx Bzb9jL2C/jRIXSVUVF8Mfufn1I8kG5OSXHcCAwEAAQJAEBZk+gTymeWALHdTvBRY gTPWQlivn4xz0s5aK/qWXs+DAJpAVpoHH4US57X8ib6hnfaDJ7P/sdp+hMcipSiF 6QIhAPgvX05NDj+qdLcbtt+6L/syPNdnb5Q6W0+JtV4veC7rAiEAw0gg9JUAvaP4 Mn+xiaR4fJWKFTSyx5CIr+XGqJmCnaUCIHk2ac3MRJFDpw1nM8HBJX4B40Uw94Xl moMWNsZxWLlRAiAbPZaLR7XAvnzC3pkvcCf2iQ2oA5/kwr6ueskJf9B+mQIgQ9Wc eq6ZN0mP/BWi8YE/uRftTPu5CzTzbX7Qddwupsc= -----END RSA PRIVATE KEY-----
An example run with a 512-bit modulus is:
openssl genrsa 512 -text > list.key type list.key openssl rsa -in list.key -noout -text
And which we get:
-----BEGIN RSA PRIVATE KEY----- MIIBOgIBAAJBAPs2nvLJASJzQe+fvkK/cbPI/BHkLyb9GG/M41fvdXuTjiP81Zke cX70rKOjd/AX/+3pZ1mEeUP8N2wiDBS7DJ8CAwEAAQJAVzsnRH0BtNm66p9YrMrX i6tdxEStDufR5XiK9Q0EiY0KLgSHttGtZyTeXXH32PPTQgIUl7NbJb7jV/Jou/mE QQIhAP9FB7lXU17rXwBv9URJmaUClj74f43n3Z7oSMnOfDhhAiEA++6epsEY1h0U 5XftF92S4frj2bzZA97yxH2Hg4+ZZP8CIQCUZ7h+2zMACwy3P1+zLKrjkOZyg5v8 jyF8IgU3NhFn4QIgDBQGmywKyskeJVo4jbpbvmXO4rOBHARmUzFJe+84hXUCIBZ+ zwh6uM7TF4MZwP1wEK0Uba8scjqFvwhHNvYgBbG0 -----END RSA PRIVATE KEY----- Private-Key: (512 bit) modulus: 00:fb:36:9e:f2:c9:01:22:73:41:ef:9f:be:42:bf: 71:b3:c8:fc:11:e4:2f:26:fd:18:6f:cc:e3:57:ef: 75:7b:93:8e:23:fc:d5:99:1e:71:7e:f4:ac:a3:a3: 77:f0:17:ff:ed:e9:67:59:84:79:43:fc:37:6c:22: 0c:14:bb:0c:9f publicExponent: 65537 (0x10001) privateExponent: 57:3b:27:44:7d:01:b4:d9:ba:ea:9f:58:ac:ca:d7: 8b:ab:5d:c4:44:ad:0e:e7:d1:e5:78:8a:f5:0d:04: 89:8d:0a:2e:04:87:b6:d1:ad:67:24:de:5d:71:f7: d8:f3:d3:42:02:14:97:b3:5b:25:be:e3:57:f2:68: bb:f9:84:41 prime1: 00:ff:45:07:b9:57:53:5e:eb:5f:00:6f:f5:44:49: 99:a5:02:96:3e:f8:7f:8d:e7:dd:9e:e8:48:c9:ce: 7c:38:61 prime2: 00:fb:ee:9e:a6:c1:18:d6:1d:14:e5:77:ed:17:dd: 92:e1:fa:e3:d9:bc:d9:03:de:f2:c4:7d:87:83:8f: 99:64:ff exponent1: 00:94:67:b8:7e:db:33:00:0b:0c:b7:3f:5f:b3:2c: aa:e3:90:e6:72:83:9b:fc:8f:21:7c:22:05:37:36: 11:67:e1 exponent2: 0c:14:06:9b:2c:0a:ca:c9:1e:25:5a:38:8d:ba:5b: be:65:ce:e2:b3:81:1c:04:66:53:31:49:7b:ef:38: 85:75 coefficient: 16:7e:cf:08:7a:b8:ce:d3:17:83:19:c0:fd:70:10: ad:14:6d:af:2c:72:3a:85:bf:08:47:36:f6:20:05: b1:b4
With this we get \(N\) (modulus), \(p\) (prime1) and \(q\) (prime2), and where:
\(N=pq\)
We have \(d\) (privateExponent) for the decryption value, \(e\) (publicExponent), and where we can encrypt a message (\(M\)) with:
\(C = M^e \pmod N\)
and decrypt to give:
\(M = C^d \pmod N\)
The key pair thus contains \(e, N, d, p\) and \(q\) for a key pair of \((e,N)\) and \((d,N)\). It also has the values of \(dQ\) (exponent1), \(dP\) (exponent2) and \(InvQ\) (coefficient). The value of \(dQ\) is:
\(dQ = d \pmod {p-1}\)
and \(dP\) is:
\(dP = d \pmod {q-1}\)
and we also have:
\(InvQ = q^{-1} \pmod p\)
We can use the values of \(dQ\), \(dP\) and \(InvQ\) to reduce the computational resource for the decrpytion. This uses Chinese remainder theory with:
\(c=M^e \pmod N\)
To decrypt, we use less complex exponents:
\(m_1=c^{dQ} \pmod {q}\)
\(m_2=c^{dP} \pmod {p}\)
and then compute:
\(h=InvQ \times (m_1-m_2) \pmod p\)
The recovered message (\(m\)) is then:
\(m=m_2+h \times q \pmod N\)