Unit3 Notes
Unit3 Notes
Unit3 Notes
where p1 <p2 <…< pt are prime numbers and where each ai is a positive integer.
Eg, 91 = 7 * 13
3600 = 24 * 32 * 52
11011 = 7 * 112 * 13
If P is the set of all prime numbers, then any positive integer a can be written uniquely in the following
form:
It is easy to determine the greatest common divisor of two positive integers if we express each integer as the
product of primes
Eg 300 = 22 * 31 * 52
18 = 21 * 32
gcd(18, 300) = 21 * 31 * 50 = 6
The following relationship always holds: If k = gcd(a, b), then kp = min(ap, bp) for all p.
Miller-Rabin Algorithm
The algorithm due to Miller and Rabin [MILL75, RABI80] is typically used to test a large number for
primality.
TEST (n)
1. Find integers k, q, with k > 0, q odd, so that (n - 1 = 2kq);
2. Select a random integer a, 1 < a < n - 1;
3. if aqmod n = 1 then return("inconclusive");
4. for j = 0 to k - 1 do
5. if a2jqmod n = n - 1 then return("inconclusive");
6. return("composite");
Example 1: Let us apply the test to the prime number n = 29.
(n - 1) = 28 =22(7) = 2kq.
First, let us try a = 10.
Compute 107 mod 29 = 17,
(107)2 mod 29 = 28, and the test returns inconclusive.
So n is prime number.
Two theorems that play important roles in public-key cryptography are Fermat’s theorem and Euler’s
theorem
Definition:
If P is prime and a is a positive integer not divisible by p, then ap-1 ≡ 1 (mod p)
Fermat's little theorem is the basis for the Fermat primality test and is one of the fundamental results
of elementary number theory.
This theorem is useful in generating public key in RSA and Primality testing
Proof:
1) Consider the set of positive integers less than p:{1,2,3..p-1}
2) Multiply each element by a, modulo p to get the set
Example
a = 7, p = 19
• 72 = 49≡ 11 (mod 19)
• 74 = 72 x 72 = 121 ≡ 7 (mod 19)
• 78 = 74 x 74 = 7 x 7 = 49 ≡ 11 (mod 19)
• 716 ≡ 78 x 78 = 11 x 11 = 121 ≡ 7 (mod 19)
• ap-1 = 718 = 716 * 72 ≡ 7 * 11 ≡ 1 (mod 19)
Suppose that we have two prime numbers p and q, with p not equal to q. Then we can show that
n=pq.
ø(n)= ø(pq)= ø(p)* ø(q)=(p-1)*(q-1)
Examples:
1) ø(37) = 36 {ø(p)=p-1 for p (p prime)]
2) ø(21) = ø(3)* ø(7)= (3–1)x(7–1) = 2x6 = 12 where the 12 integers are {1,2,4,5,8,10,11,13,16,17, 19,
20}
[ ø(p.q)=(p-1)x(q-1) for p.q (p,q prime )]
Sample Examples
1. What is the value of Φ(13)?
Because 13 is a prime, Φ (13) = (13 −1) = 12.
2. What is the value of Φ (10)?
We can use the third rule: Φ (10) = Φ (2) × Φ (5) = 1 × 4 = 4, because 2 and 5 are primes.
3. What is the number of elements in Z14*?
The answer is Φ (14) = Φ (7) × Φ (2) = 6 × 1 = 6. The members are 1, 3, 5, 9, 11, and 13.
Euler’s theorem
Euler’s theorem states that for every a and n that are relatively prime:
a ø(n) ≡ 1(mod n)
Proof:
The above equation is true, if n is prime, because in that case ø(n)=(n-1) and Fermat’s theorem holds.
However it holds for any integer n.
1)Recall that ø(n)is the number of positive integers less than n that are relatively prime to n. consider the set
of such integers, labeled as follows:
R={x1,x2….x ø(n)}
That is, each element xi of R is a unique positive integer less than n with gcd(xi,n)=1.
The Chinese remainder theorem (CRT) is used to solve a set of congruent equations with one variable
but different moduli, which are relatively prime, as shown below:
Let m1, m2 …….mk be integers with gcd(mi, mj) = 1, whenever i≠ j. Let a1, a2 …… ak be integers, there
exists exactly one solution x (mod m1, m2 …..mk) to the simultaneous congruences
If n1,n2,..,nk are positive integers that are pairwise co-prime and a1,a2,…,ak are any integers, then CRT is
used to find the values of x that solves the following congruence simultaneously.
Value of x=(a1m1y1+a2m2y2+…+akmkyk)mod M
Where M=n1n2n3..nk
mi=M/ni
miyi=1 mod ni
Example 1:
Find the solution to the simultaneous equations: x ≡ 1 ( mod 5), x≡ 2 (mod 6), x≡ 3 (mod 7).
Solution
M=n1n2n3
M=5*6*7=210
mi=M/ni
m1=210/5=42
m2=210/6=35
m3=210/7=30
miyi=1 mod ni
42y1=1 mod 5
y1= 2
35y2= 1 mod 6
y2=5
30y3=1 mod 7
y3=2
x=(a1m1y1+a2m2y2+ a3m3y3)mod M
=((1*42*2)+(2*35*5)+(3*30*3)) mod 210
=193
Example 2:
Find an integer that has a remainder of 3 when divided by 7 and 13, but is divisible by 12.
Solution: This is a CRT problem. We can form three equations and solve them to find the value of x.
Example 3:
A bag has contained number of pens if you take out 3 pens at a time 2 pens are left. If you take out 4
pens at a time 1 pen is left and if you take out 5 pens at a time 3 pens are left in the bag. What is the number
of pens in the bag.
x ≡ 2 mod 3
x ≡ 1 mod 4
x ≡ 3 mod 5
a1=2
a2=1
a3=3
n1=3
n2=4
n3=5
M=n1n2n3
M=3*4*5=60
mi=M/ni
m1=60/3=20
m2=60/4=15
m3=60/5=12
miyi=1 mod ni
20y1=1 mod 3
Y1=2 mod 3
15y2= 1 mod 4
y2=3 mod 4
12y3=1 mod 5
y3=3 mod 5
x=(a1m1y1+a2m2y2+ a3m3y3)mod M
=((2*20*2)+(1*15*3)+(3*12*3)) mod 60
=233 mod 60
=53
DISCRETE LOGARITHMS.
Discrete logarithms are fundamental to a number of public-key algorithms. Discrete logarithms are
analogous to ordinary logarithms but are defined using modular arithmetic.
Discrete logarithms are fundamental to a number of public-key algorithms, including Diffie-Hellman key
exchange and the digital signature algorithm (DSA)
Where , Euler’s totient function, is the number of positive integers less than
and relatively prime to . Now consider the more general expression:
If a and n are relatively prime, then there is at least one integer m that satisfies
Equation, namely M= , . The least positive exponent m for which
Equation holds is referred to in several ways:
• The order of a(mod n)
• The exponent to which a belongs (mod n)
• The length of the period generated by a
The highest possible exponent to which a number can belong (mod n) is . If a number is of this order,
it is referred to as a primitive root of n .The importance of this notion is that if is a primitive root of , then
its powers
Logarithms for Modular Arithmetic
A primitive root of a prime number p is one whose powers modulo p generate all the integers from 1
to p - 1. That is, if ‘a’ is a primitive root of the prime number p, then the numbers
a mod p, a2 mod p,…, ap-1 mod p
are distinct and consist of the integers from 1 through p - 1 in some permutation.
For any integer b and a primitive root a of prime number p, we can find a unique exponent i such that
b≡ ai (mod p) where 0 … i … (p - 1)
The exponent i is referred to as the discrete logarithm of b for the base a, mod p.
We denote this value as dloga,p(b)
Note the following:
dloga,p(a) = 1 because a1 mod p = a
dloga,p(1) = 0 because a0 mod p = 1 mod p = 1
1 Plaintext This is the readable message or data that is fed into the algorithm as input.
Encryption
2 The encryption algorithm performs various transformations on the plaintext.
algorithm
This is a pair of keys that have been selected so that if one is used for
3 Public key
encryption, the other is used for decryption. The exact transformations
performed by the algorithm depend on the public or private key that is provided
Private
4 as input
Key
Decryption This algorithm accepts the ciphertext and the matching key and produces the
6
algorithm original plaintext.
Public key cryptography for providing confidentiality (secrecy)
The intended receiver, in possession of the matching private key, is able to invert the
transformation:
➢ In this case,A prepares a message to B and encrypts it using A’s private key before
transmitting it. B can decrypt the message using A’s public key. Because the message
was encrypted using A’s private key, only A could have prepared the message. Therefore,
the entire encrypted message serves as a digital signature.
➢ It is impossible to alter the message without access to A’s private key, so the message is
authenticated both in terms of source and in terms of data integrity.
It is, however, possible to provide both the authentication function and confidentiality by
a double use of the public-key scheme (above figure):
In this case, we begin as before by encrypting a message, using the sender’s private key.
This provides the digital signature. Next, we encrypt again, using the receiver’s public key. The
final ciphertext can be decrypted only by the intended receiver, who alone has the matching
private key. Thus, confidentiality is provided.
RSA
➢ It is the most common public key algorithm.
➢ This RSA name is get from its inventors first letter (Rivest (R), Shamir (S) and Adleman
(A)) in the year 1977.
➢ The RSA scheme is a block cipher in which the plaintext & ciphertext are integers
between 0 and n-1 for some ‘n’.
➢ A typical size for ‘n’ is 1024 bits or 309 decimal digits. That is, n is less than 21024
Description of the Algorithm:
➢ RSA algorithm uses an expression with exponentials.
➢ In RSA plaintext is encrypted in blocks, with each block having a binary value less than
some number n. that is, the block size must be less than or equal to log2(n)
➢ RSA uses two exponents ‘e’ and ‘d’ where e is public and d is private.
➢ Encryption and decryption are of following form, for some PlainText ‘M’ and
CipherText block ‘C’
Requirements:
The RSA algorithm to be satisfactory for public key encryption, the following requirements must
be met:
1. It is possible to find values of e, d n such that “ Med mod n =M ” for all M<n
2. It is relatively easy to calculate “ Me mod n “ and “ Cd mod n “for M<n
3. It is infeasible to determine “d” given ‘e’ & ‘n’. The “ Med mod n =M ” relationship
holds if ‘e’ & ‘d’ are multiplicative inverses modulo Ø(n).
Ø(n) is Euler Totient function
For p,q primes where p*q and p≠q.
Ø(n)= Ø(pq)=(p-1)(q-1)
Then the relation between ‘e’ & ‘d’ can be expressed as “ “
this is equivalent to saying
KEY MANAGEMENT
There are actually two distinct aspects to the use of public-key cryptography:
● The distribution of public keys
● The use of public-key encryption to distribute secret keys
1. Distribution of Public Keys
There are four different schemes
➢ Public announcement
➢ Publicly available directory
➢ Public-key authority
➢ Public-key certificates
A.Public announcement
Any participant can send his or her public key to any other participant or broadcast the
key to the community. Uncontrolled Public-Key Distribution
Limitation : Anyone can forge such a public announcement. That is, some user could pretend to be
user A and send a public key to another participant or broadcast such a public key. Authentication
is needed to avoid this problem.
B. Publicly Available Directory
A greater degree of security can be achieved by maintaining a publicly available dynamic
directory of public keys. Maintenance and distribution of the public directory would have to be the
responsibility of some trusted entity or organization.
i)The authority maintains a directory with a {name, public key} entry for each participant.
ii)Each participant registers a public key with the directory authority.
iii) Participants could also access the directory electronically.
Limitation :
An Adversary may impersonate by stealing the private key of public key directory and falsely send
the public key details.
An attacker may attack the records stored in the directory.
C. Public-key authority
Stronger security for public-key distribution can be achieved by providing tighter control
over the distribution of public keys from the directory.
Each participant reliably knows a public key for the authority, with only the authority
knowing the corresponding private key.
i) A sends a time stamped message to the public-key authority containing a request for the current
public key of B.
ii) The authority responds with a message that is encrypted using the authority's private key,
PRauth. Thus, A is able to decrypt the message using the authority's public key. Therefore, A is
assured
that the message originated with the authority. The message includes the following:
● B's public key, PUb which A can use to encrypt messages destined for B
● The original request, to enable A to match this response with the corresponding earlier request
and to verify that the original request was not altered before reception by the authority
● The original timestamp, so A can determine that this is not an old message from the authority
containing a key other than B's current public key
iii) A stores B's public key and also uses it to encrypt a message to B containing an identifier of
A (IDA) and a nonce (N1), which is used to identify this transaction uniquely.
iv) B retrieves A's public key from the authority in the same manner as A retrieved B's public
key.
v) At this point, public keys have been securely delivered to A and B, and they may begin their protected
exchange.
v) B sends a message to A encrypted with PUa and containing A's nonce (N1) as well as a new
nonce generated by B (N2) Because only B could have decrypted message (3), the presence of
N1 in message (6) assures A that the correspondent is B.
vi) A returns N2, encrypted using B's public key, to assure B that its correspondent is A.
Limitations : Bottleneck may occur in public authority. Tampering of records stored by the
authority may take place.
Typically, the third party is a certificate authority, such as a government agency or a financial
institution, that is trusted by the user community.
A user can present his or her public key to the authority in a secure manner, and obtain a
certificate. The user can then publish the certificate.
2. Secret Key Distribution with Confidentiality and Authentication
i) A uses B's public key to encrypt a message to B containing an identifier of A (IDA) and a
nonce (N1), which is used to identify this transaction uniquely.
ii) B sends a message to A encrypted with PUa and containing A's nonce (N1) as well as a new
nonce generated by B (N2)
iv) A returns N2 encrypted using B's public key, to assure B that its correspondent is A.
A selects a secret key Ks and sends M = E(PUb, E(PRa, Ks)) to B. Encryption of this message
with B's public key ensures that only B can read it; encryption with A's private key ensures that
only A could have sent it.
v) B computes D(PUa, D(PRb, M)) to recover the secret key.
Example 3:
MAN-IN-MIDDLE-ATTACK:
46
4. ‘B’ receives YD1 & calculate
5. ‘B’ transmits ‘YB’ to ‘A”
6. ‘D’ intercepts ‘YB’ and transmits YD2 to ‘A’ and ‘D’ calculate K1
7. A receives YD2 and calculates
At this point, Bob and Alice think that they share a secret key, but instead Bob and Darth share
secret key K1 and Alice and Darth share secret key K2. All future communication between Bob
and Alice is compromised in the following way.
The key exchange protocol is vulnerable to such an attack because it does not authenticate the
participants. This vulnerability can be overcome with the use of digital signatures and public-key
certificates.
Majority of public-key crypto (RSA, D-H) use either integer or polynomial arithmetic with very
large numbers/polynomials. It imposes a significant load in storing and processing keys and
messages. An alternatives to use elliptic curves; it offers same security with smaller bit sizes.
Real Elliptic Curves
Comparision of RSA/DSA (Diffie Hellman Algorithm
Elgamal Cryptography: Asymmetruc Key ( Encrp-pub key ,Decrypt-Private key)
`Let P=11;D=3;E1=2
E2=E1D mod p
E2= 23 mod 11
E2= 8 mod 11
E2=8
Private Key=3
Encryption:
R=4
C1=E1R mod p
C1=24 mod 11
C2=28672 mod 11 =6
C2=6
C.T ={5,6}
Decryption
Pt={6x(53)-1)mod 11
First: (53)-1)mod 11
(125)-1)mod 11
Pt=7