All secret key
algorithms
& hash algorithms do the same thing but public key algorithms look
very different from each other.
The thing that is common among all of them is that each participant has two keys, public and private, and most of them are based on modular arithmetic.
e.g., 8 mod 10 =
8,
18 mod 10 = 8, 24 mod
10
= 4
8 mod 7 = 1,
18 mod 7 =
4, 24 mod 7
= 3
Example: addition mod 10
8 + 8 = 6, 1 + 9 = 0, 7 + 6 = 3See Fig. 6-1 for addition mod 10 Table:
Example: if k = 7, then 1987 is encrypted to 8654.
decryption is
done by adding the -k, the additive
inverse of k,
to each digit.
An additive
inverse of x is the
number you'd have to add to x to get 0.
Example:
if k = 7, then -k is 3 since 7+3 = 0 and thus
8654 will is decrypted to 1987.
In the above table (Fig.
6-1), each "0"
is the intersection of k and -k, e.g., 0 is the intersection of 3
and 7.
Example: multiplication mod 10
8 x 8 = 4, 1 x 9 = 9 , 7 x 6 = 2See Fig. 6-2 for multiplication mod 10 Table:
Example: if k = 7, then 1987 is encrypted to 7369
decryption is done by multiplying each digit by k-1 , the multiplicative inverse of k. A multiplicative inverse of k is the number to multiply by k to get 1.
Example: if k = 7, then k-1 is 3 since 7x3 = 1
In the above table (Fig.
6-2), each "1"
is the intersection of k and k-1.
Only the numbers {1,3,7,9} have
multiplicative inverse mod 10.
Euclide's Algorithm:
efficiently find multiplicative inverses mod n.
Given x and n, it finds a number y such that x.y mod n = 1
(if there is such y).
What is so special about the
set {1,3,7,9}?
These numbers are relatively
prime to 10, i.e., they do not share
with 10 any
common factors other than 1.
Note that 9 is not a prime number but it is relatively prime to
10.
How many numbers less than n
are
relatively prime to n?
This quantity is referred to
as Ø(n)
and is called the totient
function.
4 2 = 6, 8 8 = 6, 19 = 9 , 76 = 9
See Fig.
6-3 for exponentiation
mod 10 Table:

Amazing fact about Ø(n):
x m mod n = x m mod Ø(n) mod n
Special case: if m = 1 mod Ø(n), then for any number x,
Example: For n =10, Ø(10)=4:x mmod n = x mod n.
m = 5
= 1 mod 4:
x = 3: 35mod
10 = 3 & x = 6: 65mod
10 = 6 &
in general: x5mod
10 = x mod 10
m = 9
= 1 mod 4: x = 3: 39mod
10 = 3 & x = 6: 69mod
10 = 6 &
in general: x9mod
10 = x mod 10
An exponentiative inverse of e is the number d such that:
Example: For
n= 10, Ø(10)=4:
Example:
Example:
verify s=2: m = 23 = 8
In
public cryptography:
Key length: variable (long for security, short for efficiency),
most common value is 512 bits.
Block size: plain text is variable less than key length &
cipher text length equals key length.Thus RSA is used for encrypting small amount of data like secret key & then we use secret key cryptography for encrypting/decrypting
large amount of data.
RSA Algorithm:
generate
public & private keys pair:
1. choose two large primes p and q.
(typically 256 bits each & keep them secret).
2. compute n = p.q & Ø(n) = (p-1)(q-1).
(it is very hard to factor n into p & q).
3. choose a number e that is relatively prime to Ø(n).
4. find a number d that is the multiplicative inverse of
e mod Ø(n), i.e., e.d = 1 mod Ø(n).
5. your public key: <e,n> & private key: <d,n>.
To encrypt a message m (<n):
& To decrypt c: m = cd mod nc = me mod nThis works since:
cd mod n = (me)d mod n
= me.d mod n
= m mod n // since e.d = 1 mod Ø(n)
= m // since m < n
sign/verify:
To sign a message m (<n):
& To verify s: m = se mod ns = md mod n
This also works since: se mod n = me.d mod n = m mod n = m
Why is RSA Secure:
Every one knows the public key: <e, n>.
To find the private key <d,n> you need to know Ø(n) since
e.d = 1 mod Ø(n).
To know Ø(n) you need to p and q since Ø(n) = (p-1).(q-1).
Thus to break RSA you should know how to factor n to find p and q.
Factoring a big number like n is hard.
(the best technique to factor 512 bit number will take 30,000 MIPS-years!)
Exponentiation
How to compute 12354 mod 678?
1232 = 123.123 = 15129 = 213 mod 678This requires 54 small number multiplications and 54 small number divisions.
1233 = 123.213 = 26199 = 435 mod 678
1234 = 123.435 = 53505 = 621 mod 678
......
12354 = ...... = 87 mod 678
How to compute 12332 mod 678?
1232 = 123.123 = 15129 = 213 mod 678This requires 5 multiplications and 5 divisions instead of 32.
1234 = 213.213 = 45369 = 621 mod 678
1238 = 621.621 = 385641 = 537 mod 678
12316 = 537.537 = 288369 = 219 mod 678
12332 = 219.219 = 47961 = 501 mod 678
To efficiently compute 12354 : 54 is represented in binary as:
1 1 0 1 1 0| | | | |
Generating RSA Keys
This requires 8 multiplications and 8 divisions instead of 32.
Each 1 requires two multipliactions and two divisions
and each 0 requires one multipliaction and one division.
Thus in the above we have three 1s and two 0s that yeilds 3.2+2.1=8
(we ignore the leading 1).
Another example: y14 , 14 is represented in binary as:
1 1 1 0
| | |
(( ( y2) y )2y )2
This requires 5 multiplication's and 5 divisions instead of 32.
test: pick a
< n
if
(an-1 mod
n)
!= 1
then
n is not prime
else
n is prime // the probability of
being
wrong is 1 in 1013
Finding e:
Instead of selecting p, q
and
then e (see
RSA algorithm ),
we will select e first then p
and
q.
Two popular values for e
are: 3
and 65537 (216
+ 1).
These makes public key
operations
on message m faster
(encryption and signature
verification is me):
m3 requires 2 multiplications & 2 divisions.
m65537 requires 17 multiplactions & 17 divisions (binary value of e is 1. 15 0s .1).
p = (2x+1)*3+2 &
q = (2y+1)*3+2
To ensure that (p-1) relatively prime to 3 we chooseIf e = 65537: randomly choose p and q and and make sure that
(p-1) = 1 mod 3 or p = 2 mod 3.
Hence choose p as k*3+2 and to make sure that p is odd let k=2x+1.
Thus p = (2x+1)*3 + 2.
Once we selected p and q,
then n
= p.q and
Ø(n) =
(p-1)(q-1).
Finding d:
How to fine d such
that e.d = 1 mod Ø(n) ?
Use Euclid algorithm
(see
Section
7.4, page 187 of textbook).
The RSA keys:
public key:
<3|65537,
n> private key: <d
, n>.
Alice
and
Bob agree on: p (large prime) & g
< p.
Alice BobPick SA (512-bit random number) Pick SB (512-bit random number)
Compute TA = ( gSA) mod p Compute TB = (gSB) mod pTA >>> <<< TB
Compute X = TB SA mod p Compute Y = TA SB mod p
X is the same as Y! why?X = TBSA = gSBSA
Y = TASB = gSASB
No one can compute g (SASB ) by knowing g (SA ) & g (SB )
Alice Mr. X Bob
Pick SA Pick SX Pick SB
Compute: TA = gSA mod p TX = gSX mod p TB = gSB mod p
TA
>>
TA
..
TX
>>
TX
TX
<<
TX
..
TB
<<
TB
Compute:
KAX
= TX SA mod
p
KAX = TA SX
mod p
KBX = TX
SB
mod p
KBX = TB SX
mod p
Possible Defense
Each person i picks Si and computes Ti = gSi mod p
and Keeps Si private and makes Ti publicIf Alice like to communicate with Bob,
she finds TB and computes:
KAB = TB SA mod p
Then tells Bob she likes to communicate with him.
Bob finds TA and hen computes:
KBA = TA SB mod pThis requires PKI (public Key Infrastructure) to manage Ti