Ccs Unit III Notes
Ccs Unit III Notes
A Prime number is an integer that has no integer factors other than 1 and itself. On the other hand, it is
called composite number.
A primality testing is a test to determine whether or not a given number is prime, as opposed to
actually decomposing the number into its constituent prime factors (which is known as prime
factorization) Use multiple points if necessary.
The primality test provides the probability of whether or not a large number is prime. Several theorems
including Fermat’s theorem provide idea of primality test. Cryptography schemes such as RSA
algorithm heavily based on primality test.
Types of Primality Testing
Naive Algorithm
• It is used to divide the given input number p by all the integers starting from 2 to √p-1.
• If any one of them is a divisor, then the input number p is not a prime.
• Otherwise considered as prime number.
Algorithm
• Pick any integer p that is greater than 2.
• Try to divide p by all integers starting from 2 to the square root of p.
• If p is divisible by any one of these integers we can conclude that p is composite.
• Else p is a prime number.
Sieve of Eratosthenes Method
• For very small prime numbers we can use the Sieve of eratosthenes method.
• This method is best method for small numbers; say all those less than 10,000,000,000.
Algorithm
• List out all the integers that are less than equal to n and greater than one.
• Find the square root of n.
• Remove all the multiples of all primes that are less than or equal to √n.
• The numbers that are left remaining are the prime numbers.
Miller Rabin Primality Test
• Rabin developed a new primality test called Miller Rabin Primality test.
• This test was based on Millers idea.
• The Millers Rabin primality test is a probabilistic algorithm like Solovay Strassen and it
relies on equality or a set of equalities.
• This test holds true only for the prime numbers which is a fast method of determining the
primality of a given number by using probabilistic method.
• This method is advantageous over all the other primality testing methods.
Factorization
• Factorization of a given positive integer n is the process of finding out the positive
integers x and y such that the product of x and y equals to n and also x and y are greater
than 1.
• The values x and y are called factors of n. Factorization can be performed for any
positive integer greater than 1.
• If a number is not factored then it is called a prime number.
• For example n = 10 can be factored into two positive integers x and y where x=5 and
y=2.
• However the number n =11cant be factored since it is a prime number.
• Factorization of a composite number does not produce unique result.
Prime Factorization Method
• Prime Factorization can be obtained for the above results by further factoring the factors
that happen to be composite number.
• Factoring a composite integer is a challenging problem and also takes more computing
power.
• In addition to this composite numbers are not used in most of the cryptographic
algorithms.
• There are many factorizing algorithms to find factors or divisor of a given positive
integer.
Trial Division Method
• It is the simplest way of finding the factors or divisor of a given positive integer n.
• This method is a very similar method to sieve of eratosthenes method.
• This method divides the given number of all the integers that are greater than 1 and less
than or equal to √n.
Euler’s Theorem
As is the case for Fermat’s theorem, an alternative form of the theorem is also useful:
THE CHINESE REMAINDER THEOREM
One of the most useful results of number theory is the Chinese remainder theorem (CRT).
In essence, the CRT says it is possible to reconstruct integers in a certain range from their
residues modulo a set of pair wise relatively prime moduli.
The CRT can be stated in several ways.
We present here a formulation that is most useful from the point of view of this text.
An alternative formulation is explored in Problem. Let
By the definition of Mi, it is relatively prime to mi and therefore has a unique multiplicative
Inverse mod mi. So Equation is well defined and produces a unique value c i .We can now
compute
One of the useful features of the Chinese remainder theorem is that it provides a way to
manipulate (potentially very large) numbers mod M in terms of tuples of smaller numbers. This
can be useful when M is 150 digits or more. However, note that it is necessary to know
beforehand the factorization of M.
Both the sender and receiver know the value of n. the sender knows the value of e and
only the receiver knows the value of d. thus, this is a public key encryption algorithm with a
public key of KU = {e, n} and a private key of KR = {d, n}. For this 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 = M mod n for all M < n.
2. It is relatively easy to calculate Me and Cd for all values of M < n.
3. It is infeasible to determine d given e and n.
Let us focus on the first requirement. We need to find the relationship of the form:
Med = M mod n
Given two prime numbers p and q and two integers, n and m, such that n=pq and 0<m<n, and
arbitrary integer k, the following relationship holds
where Ф(n) – Euler totient function, which is the number of positive integers less than n and
relatively prime to n. we can achieve the desired relationship, if
ed = kФ(n)+1
This is equivalent to saying:
ed ≡ 1 mod Ф(n)
d = e-1 mod Ф(n)
That is, e and d are multiplicative inverses mod Ф(n). According to the rule of modular
arithmetic, this is true only if d (and therefore e) is relatively prime to Ф(n). Equivalently,
gcd(Ф(n), d) = 1.
We are now ready to state the RSA scheme. The ingredients are the following:
p, q, two prime numbers (private, chosen)
n = pq (public, calculated)
e, with gcd(Ф (n), e) = 1; 1 <e < Ф (n) (public, chosen)
d≡K e-1 (mod Ф (n)) (private, calculated)
The steps involved in RSA algorithm for generating the key are
The resulting keys are public key PU = {7, 187} and private key PR = {23, 187}.
The example shows the use of these keys for a plaintext input of M= 88. For encryption, we need
to calculate C = 887 mod 187.
887 mod 187 = [(884 mod 187) × (882 mod 187)× (881 mod 187)] mod 187
881 mod 187 = 88
882 mod 187 = 7744 mod 187 = 77
884 mod 187 = 59,969,536 mod 187 = 132
887 mod 187 = (88 × 77 × 132) mod 187 = 894,432 mod 187 = 11
1123 mod 187 = [(111 mod 187) × (112 mod 187) × (114 mod 187)× (118 mod 187) × (118
mod 187)] mod 187
111 mod 187 = 11
112 mod 187 = 121
114 mod 187 = 14,641 mod 187 = 55
118 mod 187 = 214,358,881 mod 187 = 33
1123 mod 187 = (11 × 121 × 55 × 33 × 33) mod 187 = 79,720,245 mod 187 = 88
Security of RSA:
Use large key space (i.e) large number of bits in e and d the better secured but problems is,
1. Increases computing power
2. Factoring Problem
Attack:
If the system does fastly the modular multiplication in majority of cases but takes longer
time in few cases. The average is also longer.
The attack is done bit by bit
Start with left most bit bk,
Suppose first j bits are known.
For a given cipher text the attacker completes the j iteration.
If the bit is set then d<- (d * a) mod n.
1. Constant exponentiation time: All exponentiations take the same amount of time before
returning a result. This is a simple fix but does degrade performance.
2. Random delay: Better performance could be achieved by adding a random delay to the
exponentiation algorithm to confuse the timing attack.
3. Blinding: Multiply the cipher text by a random number before performing
exponentiation. This process prevents the attacker from knowing what cipher text bits are
being processed inside the computer and therefore prevents the bit-by-bit analysis
essential to the timing attack.
KEY MANAGEMENT
There are two uses of public key cryptography regarding the issues of key distribution. They are
1. Distribution of public keys
2. Use of public key encryption to distribute secret keys
5.10.1 Distribution of Public Keys
Several techniques have been proposed for the distribution of public keys. Virtually all these
proposals can be grouped into the following general schemes:
a) Public announcement
b) Publicly available directory
c) Public-key authority
d) Public-key certificates
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.
Until such time as user A discovers the forgery and alerts other participants, the forger is
able to read all encrypted messages intended for A and can use the forged keys for
authentication.
1. The authority maintains a directory with a {name, public key} entry for each participant.
2. Each participant registers a public key with the directory authority. Registration would
have to be in person or by some form of secure authenticated communication.
3. A participant may replace the existing key with a new one at any time, due to either the
key has been used for a large amount of data, or the corresponding private key has been
compromised in some way.
4. Participants could also access the directory electronically. For this purpose, secure,
authenticated communication from the authority to the participant is mandatory
Figure 2.32 Public-Key Publications
Vulnerabilities:
2. The authority responds with a message that is encrypted using the authority's private key,
PRauthThus, 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, PUbwhich 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
3. 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.
4,5 B retrieves A's public key from the authority in the same manner as A retrieved B's public
key.
6.B sends a message to A encrypted with KUaand 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.
7. A returns N2, encrypted using B's public key, to assure B that its correspondent is A.
Thus, a total of seven messages are required. However, the initial four messages need be
used only infrequently because both A and B can save the other's public key for future use, a
technique known as caching.
Disadvantages:
Bottle neck at the authority.
The scenario of Figure 2.34 is attractive, yet it has some drawbacks. The public-key
authority could be somewhat of a bottleneck in the system, for a user must appeal to the authority
for a public key for every other user that it wishes to contact. As before, the directory of names
and public keys maintained by the authority is vulnerable to tampering.
An alternative approach is to use certificates that can be used by participants to exchange
keys without contacting a public-key authority.
A certificate consists of a public key plus an identifier of the key owner, with the whole
block signed by a trusted third party.
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. Anyone needed this user's public key can
obtain the certificate and verify that it is valid by way of the attached trusted signature.
1. Any participant can read a certificate to determine the name and public key of the certificate's
owner.
2. Any participant can verify that the certificate originated from the certificate authority and is
not counterfeit.
3. Only the certificate authority can create and update certificates.
These requirements are satisfied by the original proposal in. Denning added the following
additional requirement:
4. Any participant can verify the currency of the certificate.
A certificate scheme is illustrated in Figure 2.35. Each participant applies to the
certificate authority, supplying a public key and requesting a certificate.
whereKRauth is the private key used by the authority and T is a timestamp.”A” may then pass this
certificate on to any other participant, who reads and verifies the certificate as follows:
The recipient uses the authority's public key, KUauthto decrypt the certificate. Because the
certificate is readable only using the authority's public key, this verifies that the certificate came
from the certificate authority.
The elements IDAand KUaprovide the recipient with the name and public key of the
certificate's holder. The timestamp T validates the currency of the certificate.
2.10.2 Public-Key distribution of Secret Keys using public key cryptography:
1. A generates a public/private key pair {KU a,KRa} and transmits a message to B consisting of
KUa and an identifier of A,IDA.
2. B generatesa secret key Ks, and transmits it to A, encrypted with A’s public key.
3. A computes DKRa [EKUa [Ks]] to recover the secret key. Because only A can decrypt the
message, only A and B will know the identity of Ks.
4. A discards KUa and KRa and B discards KUa.
Advantages:
No keys exist before the start of the communication no key exist after the completion of
communication
Secure from eaves dropping
Disadvatages:
Replay attack
Meet in the middle attack
A generates a public/private key pair {PUa, PRa} and transmits a message intended for B
consisting of PUaand an identifier of A, IDA.
D intercepts the message, creates its own public/private key pair {PUd, PRd} and
transmits PUs 0 0 IDA to B.
B generates a secret key, Ks, and transmits E(PUs, Ks).
D intercepts the message and learns Ks by computing D(PRd, E(PUd, Ks)).
D transmits E(PUa, Ks) to A.
(b) Secret Key Distribution with Confidentiality and Authentication:
1. A uses B’s public key to encrypt a message to B containing an identifier of A (ID A) and a
nonce (N1),which is used to identify this transaction uniquely.
2. B sends a message to A encrypted with KU a and containing A’s decrypted message
(1),the presence of N1 in message (2) assures A that correspondent is B.
3. A returns N2, encrypted using B’s public key, to assurer B that its correspondent is A.
4. A select a secret key Ks and sends M = EKUb[EKRa[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.
5. Computes DKUa[DKRb[M]]to recover thesecret key.
First, we define a primitive root of a prime number p as one whose power generate all the
integers from 1 to (p-1) i.e., if ‘a’ is a primitive root of a prime number p, then the numbers
a mod p, a2 mod p, … ap-1 mod p
are distinct and consists of integers from 1 to (p-1) in some permutation.
For any integer ‘b’ and a primitive root ‘a’ of a 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 discrete logarithm.
The Algorithm
Figure 2.37 summarizes the Diffie-Hellman key exchange algorithm.There are publicly
known numbers: a prime number ‘q’ and an integer α that is primitive root of q. suppose users A
and B wish to exchange a key. User A selects a random integer X A< q and computes YA = α XA
mod q.
The protocol depicted in figure 2.38 is insecure against a man-in-the-middle attack. Suppose
Alice and Bob wish to exchange keys, and Darth is the adversary. The attack proceeds as
follows:
1. Darth prepares for the attack by generating two random private keys XD1 and XD2 and then
computing the corresponding public keys YD1 and YD2.
2. Alice transmits YA to Bob.
3. Darth intercepts YA and transmits YD1 to Bob. Darth also calculates K2 = (YA) XD2 mod q.
4. Bob receives YD1 and calculates K1 = (YD1) XB mod q.
5. Bob transmits XA to Alice.
6. Darth intercepts XA and transmits YD2 to Alice. Darth calculates K1 = (YB) XD1 mod q.
7. Alice receives YD2 and calculates K2 = (YD2) XA mod q.
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 K 2. All future communication between Bob
and Alice is compromised in the following way:
1. Alice sends an encrypted message M: E(K2, M).
2. Darth intercepts the encrypted message and decrypts it, to recover M.
3. Darth sends Bob E(K1, M) or E(K1, M'), where M' is any message
Example:
Key exchange is based on the use of the prime number q = 353 and a primitive root of 353, in
this case α = 3. A and B select secret keys XA= 97 and XB= 233, respectively.
Each computes its public key:
A computes YA=397 mod 353 = 40.
B computes YB= 3233 mod 353 = 248.
After they exchange public keys, each can compute the common secret key:
A computes K = (YB)XAmod 353 = 24897 mod 353 = 160.
B computes K = (YA)XBmod 353 = 40 233 mod 353 = 160.
Elliptic Curves:
An elliptic Curve is a Cubic equation of the form
Y2+axy+by = x3+cx2+dx +e
A special addition operation is defined over elliptic curves and with the inclusion of a point “O”
called point at infinity.
If three points are on a line intersecting an elliptic curve, then their sum is equal to this
point at infinity O (which acts as the identity element for this addition operation)
An elliptic group over the Galois Field E p(a,b) is obtained by computing x3+ax+b mod p
for 0≤ x≤ p. The constants a&b are non-negative integers smaller than the prime number p must
satisfy the condition.
4a3 + 27b2 mod p ≠ 0
For each value of x, one needs to determine whether or not it is a quadratic residue.
If not then the point is not in the elliptic group Ep (a,b)
Let the points P = (x1,y1) and Q = (X2,Y2) be in the elliptic group Ep (a,b) and O be the point at
infinity.
The rules for addition over the elliptic group Ep (a,b) are:
1. P+O = O+P = P
2.If x2 = x1 and y2 = -y1, that is P = (x1,y1) and Q = (X2,Y2) = (x1,-y1) = -P Then P+Q = O
and
Elliptic curve cryptography can be used to encrypt the plain text message M, into
ciphertext. The plain text message M is encoded into a point P M from the finite set of points in
the elliptic group, Ep(a,b).
The first step consists in choosing a generator point, G ε E p(a, b) , such that the smallest value of
n for which nG = o is a very large prime number.
The elliptic group Ep(a,b) and the generator point G are made public.
Each user select a private key,nA< n and compute the public key PA as PA = nAG
To encrypt the message point PM for Bob (B),
Alice (A) choses a random integer k and compute the ciphertext pair of points Pc
After receiving the ciphertext pair of points, P C, Bob multiplies the firstpoint,(KG) with his
private key nB and then adds the result to the second point in the ciphertext pair of points (P M +
KPB)
Only Bob knowing the private key nB, can remove nB(KG) from the second point of the
ciphertext pair of point, i.e (PM + KPB), and hence retrieve the plaintext information PM
1. The cryptographic strength of elliptic curve encryption lies in the difficulty for a crypt analyst
to determine the secret random number k from KP & P itself.
2. The fastest method to solve this problem (known as elliptic curve logarithm problem is the
pollard factorization method).
3. The computational complexity for breaking the elliptic curve cryptosystem, using the pollard
method is 3.3 x 1010 MIPS years for an elliptic curve key size of only 150bits.
4. For comparison the fastest method to break RSA, using General Number Field Sieve method
to factor the composite integer n in to the two prime p & q requires 2x10 11 MIPS years for a 768
bit RSA key & 3x 1011 MIPS years for a RSA key length 1024
5. If the RSA key length is increased to 2048 bits, the GNES method will need 3x10 20 MIPS
years to factor n whereas increasing the elliptic curve key length to only 24 bits will impose a
computational complexity of 1.6x1028 MIPS years.