Cryptography Reference
In-Depth Information
If called with only an input, this application defaults to the hardcoded keypair.
If you run this, you see
jdavies@localhost$ rsa -e abc
40f73315d3f74703904e51e1c72686801de06a55417110e56280f1f8471a3802406d2110011e1f38
7f7b4c43258b0a1eedc558a3aac5aa2d20cf5e0d65d80db3
The output is hex encoded as before. Notice that although you only encrypted
three bytes of input, you got back 64 bytes of output. The modulus is 512 bits,
so the output must also be 512 bits.
You can see this decoded:
jdavies@localhost$ rsa -d \ 0x40f73315d3f74703904e51e1c7\
2686801de06a55417110e56280f1f8471a3802406d2110011e1f387f\
7b4c43258b0a1eedc558a3aac5aa2d20cf5e0d65d80db3
616263
The decryption routine decrypts, removes the padding, and returns the origi-
nal input “616263” (the hex values of the ASCII characters a , b , and c ). Note that
if you try to decrypt with the public key, you get gibberish; once encrypted, the
message can only be decrypted using the private key.
PROCEDURE FOR GENERATING RSA KEYPAIRS
Although code to generate RSA keypairs isn't examined here, it's not
prohibitively diffi cult to do so. The procedure is as follows:
1. Select two random prime numbers p and q .
2. Compute the modulus n = pq .
3. Compute the totient function (p-1)(q-1)
4. Select a random public exponent e < Ƶ (n) (as previously mentioned,
65,537 is a popular choice).
5. Perform a modular inversion (to be introduced shortly) to compute the
private exponent d: de % n = 1 .
You also likely noticed that your computer slowed to a crawl while decrypt-
ing; encrypting isn't too bad, because of the choice of public exponent (65,537).
Decrypting is slow — not unusably slow, but also not something you want to
try to do more than a few times a minute. It should come as no surprise to you
that reams of research have been done into methods of speeding up the RSA
decryption operation. None of them are examined here; they mostly involve
keeping track of the interim steps in the original computation of the private key
and taking advantage of some useful mathematical properties thereof.
So, because public-key cryptography can be used to exchange secrets, why
did Chapter 2 spend so much time (besides the fact that it's interesting) looking
at private-key cryptography? Well, public-key cryptography is painfully slow.
There are actually ways to speed it up — the implementation presented here
Search WWH ::




Custom Search