Public Key Cryptography

 

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.

Modular Arithmetic

Example: addition mod 10
   8 + 8 = 6, 1 + 9 = 0, 7 + 6 = 3

See  Fig. 6-1 for addition  mod 10 Table:


Example: multiplication mod 10
   8 x 8 = 4, 1 x 9 = 9 , 7 x 6 = 2

See  Fig. 6-2 for multiplication  mod 10 Table:

then {1,2, ..., n-1} are all relatively prime and
thus Ø(n) = n-1.
then Ø(n) = (p-1)(q-1).
Fig. 6-3: since  Ø(10)=4, the ith column is the same as the i+4th column,
e=3 and d=7 are exponentiative inverses since 3.7=21= 1 mod 4

Encrypt/Decrypt:
encrypt m = 8: c = 83 = 2
decrypt c=2:  m = 27 = 8
Sign/Verify:
sign m = 8: s = 87 = 2

RSA: Rivist, Shamir & Adleman


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>.

encrypt/decrypt:
To encrypt a message m (<n):
c = me mod n
& To decrypt c: m = cd mod n

This 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):
s = md mod n
& To verify s: m = se 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!)

Efficiency of  RSA Operations:

Exponentiation

How to compute 12354 mod 678?
1232 = 123.123 = 15129 = 213 mod 678
1233 = 123.213 = 26199 = 435 mod 678
1234 = 123.435 = 53505 = 621 mod 678
......
12354 =     ......                 = 87  mod 678
This requires 54  small number multiplications and 54 small number divisions.
 

How to compute 12332 mod 678?

1232   = 123.123 = 15129     =  213 mod 678
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
This requires 5  multiplications and 5 divisions instead of 32.


To efficiently compute  12354 : 54 is represented in binary as:

1         1                  0              1                1              0
              |              |           |             |          |
  ((((   (1232)123          )2               )2123           )2123      )2
 
 
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.

Generating RSA Keys
 
Finding n:


Diffie-Hellman

    Alice and Bob agree on:  p (large prime) &  g < p.
 

             Alice                                                               Bob

Pick SA  (512-bit random number)                 Pick SB  (512-bit random number)
Compute TA = ( gSA) mod p                           Compute TB = (gSB) mod p

                     TA                         >>>          <<<                    TB   

Compute  X =     TB SA mod p                      Compute Y = TA SB mod p 

X is the same as Y! why?

       XTBSA  = gSBSA
       YTASB  = gSASB

No one can compute  g (SASB ) by knowing  g (SA )  & g (SB )


The bucket Brigade/Man-in-theMiddle Attach

 

                    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  Sprivate and  makes  Ti  public

If 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 T  and hen   computes:
                                   KBA = TA SB mod p

This requires PKI  (public Key Infrastructure) to manage  Ti