Asymmetric Encryption
Sam Goto
This is an open study of the RSA encryption scheme (source).
Problem
Bob wants to send a secret message m to Alice without having to rely on a shared secret (symmetric keys)
Background
- In 1970, James Ellis, a british engineer and mathematician was working on an idea for "non-secret encryption": lock and unlock are inverse operations.
- Alice could buy a
lock, open it, keep thekey, and send thelockto Bob. - Bob uses the
lockto lock aboxwith the hiddenmessageinside and send theboxback to Alice. - With its
key, Alice could open theboxto get themessage. - Ellis never arrived at a mathematic formulation, but he had an intuitive sense of how it should work: an
encryptionkey and adecryptionkey. - The decryption key performs the inverse, or the undo operation, that was applied to the encryption key.
- Alice could buy a
- In 1973, Clifford Cocks (cryptographer) looked into a special kind of reversable function a trap door function.
- A known
publicfunctionf(x) = ythat was easy to compute but hard to invert: givenyit is hard to computex, unless you haveprivateinformation available. - So, if you wanted to send you a message, you'd use
f(m) = yand send you thepublicresulty, which nobody but you (who have a special piece ofprivateinformation), would be able to compute the inverse offto invertyinto them. - For this he turned into modular exponentiation.
- He knew that computing discrete logarithms was hard for computers: given
aanksuch thatb ^ k = a, it is really hard to computeb. - So, if Alice provided
eandnpublicly (the lock), Bob could send a message to Alicemby calculatingc = m ^ e % nand sendcto Alice (and no one would be able to invertcintom, because it would be involving computing a discrete logarithm)
This observation was also cleverly used on the diffie helmann key exchange protocol here.
- This would construct a confidential lock, but not a correct one: given
c,eandnit is not possible to invert back tom, including for Alice - So, he tried to build a trap door in the lock such that (a) only Alice could use it to invert
cback intomand (b)mwas inverted correctly. - Something that makes reversing this easier for Alice but hard for everybody else.
- So, he proposed: what if unlocking could be performed by taking
cand raising it to some other private exponent,d, to undo the operation and arrive atm? - That is, can we construct
e,dandnsuch that for everym:- If
c = m ^ e % nis the message Alice gets from Bob - And Alice computed
c ^ d % n=(m ^ e % n) ^ d % n=m ^ e ^ d % n=m ^ (e * d) % n=m. - Then Bob's
m= Alice'smandc,eandncould be madepublic.
- If
- So, he needed to find a way to make Alice construct a
eanddsuch that it lead (correctly) tomwhile making it hard for anyone else to findd(confidential). - So, he needed a second one way function for generating
d, and for this he looked back at Euclid, Euler and Fermat's little theorem.
- A known
- In ~300BC, Euclid devised the fundamental theorem of arithmetic: every number can be represented uniquely as a product of prime numbers
- He also knew that computing the prime factorization was known to be a hard problem
- So, imagine Alice picked two big prime numbers, say,
pandqand multiplied then to constructn = p * q. - That is, given
n, it was known to be hard to computepandq, unless you have eitherporq. - So, that was a trapdoor: something that is easy to do if you have Alice's
privateinformation (porq) but hard otherwise. - So, Cocks started to look for function that depended on knowing the factorization of
n. - For that he looked back to Euler.
- In the ~1700s, Euler was investigating the distribution of prime numbers.
- One important function he defined as the
phi(b)function.
Not super important to understand it, but it measures the breakability of a number.
phi(n)outputs how many integers less than or equal to n that do not share. A common factor with n. e.g.phi(8)=4(1, 3, 5 and 7)- What's interesting about
phi(n), thatphi(n)is hard to calculate except in one case: prime numbers. - If
nis prime,phi(n) = n - 1:phi(n)is easy to compute for primes. - It was also known that
phi(n)was multiplicative: i.e.phi(a * b)=phi(a) * phi(b) - If
nis the product of two primesaandbthenphi(n) = phi(a * b) = phi(a) * p(b) = (a - 1) * (b - 1)is easy to compute - And that was the trapdoor that Cocks was looking for: if you know the prime factorization
aandbofn, thanphi(n)is easy to compute as(a - 1) * (b - 1), but hard to compute otherwise - But, how could he connect this trapdoor to the previously one he devised? For that, he turned back into Fermat and Euler:
- One important function he defined as the
- Fermat-Euler's theorem states that for every
m,m ^ phi(n) % n = 1(ifmandnare coprime positive integers)- First, we can always exponentiate
1bykand we'll always getk, i.e.1 ^ k = 1:- Therefore
(m ^ phi(n)) ^ k % n = 1 ^ k - i.e.
m ^ (k * phi(n)) % n = 1
- Therefore
- Second, we can always multiply both sides by
m:1 * m = m:- Therefore
m * (m ^ (k * phi(n)) % n) = m * 1
- Therefore
- i.e.
m ^ (k * phi(n) + 1) % n = m
- First, we can always exponentiate
- That allowed Cocks to put things back together
- From before:
- Bob can encrypt
mwithc = m ^ e % n, giveneandnfrom Alice, and know that it is going to be hard to invertm. - Alice knows that
- She could take
cand applyc ^ d % nto arrive atmwhich is the same asm.- She knows that
m ^ (k * phi(n) + 1) % n = m(Euler's theorem) - So, Alice can construct
e,dandnsuch thatm ^ (e * d) % n=m
- She knows that
- Bob can encrypt
- Alice can pick
e,dandnsuch that(e * d) = k * phi(n) + 1- i.e.
d = (k * phi(n) + 1) / e
- i.e.
- Corretness
- If Alice chooses
eandnsuch thatdas above, that would makem ^ (e * d) % n = mintom ^ (k * phi(n) + 1) % n = mwhich we know to be true (Euler)
- If Alice chooses
- Confidentiality
- Alice would know that the value that she picked for
d, giveneandn, is only computable if you can solvephi(n), which is only known if you can factorizen - That is known to be hard, unless you know what
pandq(which only Alice knows!)
- Alice would know that the value that she picked for
- From before:
Try it yourself!
Use the demo below to send messages from Bob to Alice!
- Bob wants to send a message
m= to Alice - Alice, picks two large prime number,
p= andq= - Alice computes
n=p * q=p * q=b - Alices computes
phi(n), which is easy for her since knows the factorization ofnbut hard for everybody else - Alice computes
phi(n)=phi(p * q)=phi(p) * phi(q)=(p - 1) * (q - 1)=(p - 1) * (q - 1)=phi - Alice picks some small public exponent
e= , an odd number that does not share a factor withphi(n) - Alice computes
d=(2 * phi(n) + 1 ) / e=d - Alice shares
n= n ande= e, her public key (the open lock) - Bob computes
c=m ^ e % n=m ^ e % n= c and - Bob sends
c= c to Alice - Alice computes
r=c ^ d % n=c ^ d % n=r - Alice knows that
r=r=m=m