Module 2
Module 2
The sequence of random numbers {Xn} is obtained via the following iterative
equation:
Xn+1 = (aXn + c) mod m
If m, a, c, and X0 are integers, then this technique will produce a sequence of
inte gers with each integer in the range 0 … Xn 6 m.
The selection of values for a, c, and m is critical in developing a good ran dom
number generator.
For example, consider a = c = 1. The sequence produced is obviously not
satisfactory.
Now consider the values a = 7, c = 0, m = 32, and X0 = 1. This generates the
sequence {7, 17, 23, 1, 7, etc.}, which is also clearly unsatisfactory. Of the 32
possible values, only four are used; thus, the sequence is said to have a period
of 4.
If, instead, we change the value of a to 5, then the sequence is {5, 25, 29, 17,
21, 9, 13, 1, 5, etc. }, which increases the period to 8.
A common criterion is that m be nearly equal to the maximum representable
nonnegative integer for a given computer. Thus, a value of m near to or equal
to 231 is typically chosen.
Park proposes three tests to be used in evaluating a random number generator:
T1: The function should be a full-period generating function. That is, the
function should generate all the numbers from 0 through m- 1 before repeating.
T2: The generated sequence should appear random.
1
Dept. of CSE(Data Science)
MODULE 2
o
These equations can be solved for a, c, and m.
Thus, although it is nice to be able to use a good PRNG, it is desirable to make
the actual sequence used nonreproducible, so that knowledge of part of the
sequence on the part of an opponent is insufficient to determine future elements
of the sequence.
This notation, explained more fully in Chapter 4, simply means that (p mod 4) = (q
mod 4) = 3.
2
Dept. of CSE(Data Science)
MODULE 2
For example, the prime numbers 7 and 11 satisfy 7 K 11 K 3(mod 4). Let n = p * q.
Next, choose a random number s, such that s is relatively prime to n; this is
equivalent to saying that neither p nor q is a factor of s.
Then the BBS genera tor produces a sequence of bits Bi according to the following
algorithm:
Thus, the least significant bit is taken at each iteration. Table 8.1 shows an example
of BBS operation.
Here, n = 192649 = 383 * 503, and the seed s = 101355.
The BBS is referred to as a cryptographically secure pseudorandom bit generator
(CSPRBG).
A pseudorandom bit generator is said to pass the next-bit test if there is not a
polynomial-time algorithm1 that, on input of the first k bits of an output sequence,
can predict the (k + 1)st bit with probability significantly greater than 1/2. In other
words, given the first k bits of the sequence, there is not a practical algorithm that
can even allow you to state that the next bit will be 1 (or 0) with probability greater
than 1/2.
3
Dept. of CSE(Data Science)
MODULE 2
4
Dept. of CSE(Data Science)
MODULE 2
performed by the algorithm depend on the public or private key that is provided as
input.
Ciphertext: This is the encrypted message produced as output. It depends on the
plaintext and the key. For a given message, two different keys will produce two different
ciphertexts.
Decryption algorithm: This algorithm accepts the ciphertext and the matching key and
produces the original plaintext.
2. Each user places one of the two keys in a public register or other accessible file. This
is the public key. The companion key is kept private. As Figure 9.1a suggests, each user
maintains a collection of public keys obtained from others.
3. If Bob wishes to send a confidential message to Alice, Bob encrypts the mes sage
using Alice’s public key.
4. When Alice receives the message, she decrypts it using her private key. No other
recipient can decrypt the message because only Alice knows Alice’s private key.
Table1: Summarizes some of the important aspects of symmetric and public key encryption.
5
Dept. of CSE(Data Science)
MODULE 2
Using Figure 2,
Y = E(PUb , X)
The intended receiver, in possession of the matching private key, is able to invert the
transformation:
X = D(PRb,Y)
Observing Y and having access to PUb, but not having access to PRb or X, must attempt
to recover X and/or PRb .
It is assumed that the adversary does have knowledge of the encryption (E) and
decryption (D) algorithms. If the adversary is interested only in this particular message,
then the focus of effort is to recover X by generating a plaintext estimate Xn.
an attempt is made to recover PR b by generating an estimate PR b.
Figure 1(b) and Figure 3, show the use of public-key encryption to provide authentication:
6
Dept. of CSE(Data Science)
MODULE 2
X = D(PUa,Y)
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.
In the preceding scheme, the entire message is encrypted, which, although validating
both author and contents, requires a great deal of storage.
Each document must be kept in plaintext to be used for practical purposes. A copy also
must be stored in ciphertext so that the origin and contents can be verified in case of a
dispute.
A more efficient way of achieving the same results is to encrypt a small block of bits
that is a function of the document. Such a block, called an authenticator, must have the
property that it is infeasible to change the document without changing the authenticator.
If the authenticator is encrypted with the sender’s private key, it serves as a signature
that verifies origin, content, and sequencing.
It is, however, possible to provide both the authentication function and confi dentiality
by a double use of the public-key scheme (Figure 4)
Z = E(PUb, E(PRa,X))
X = D(PUa, D(PRb,Z))
7
Dept. of CSE(Data Science)
MODULE 2
Depending on the application, the sender uses either the sender’s private key or the receiver’s
public key, or both, to perform some type of cryptographic function.
In broad terms, we can classify the use of public-key cryptosystems into three categories
1. Encryption/decryption: The sender encrypts a message with the recipient’s public key,
and the recipient decrypts the message with the recipient’s private key.
2. Digital signature: The sender “signs” a message with its private key. Signing is achieved
by a cryptographic algorithm applied to the message or to a small block of data that is
a function of the message.
3. Key exchange: Two sides cooperate to exchange a session key, which is a secret key
for symmetric encryption generated for use for a particular transaction (or session) and
valid for a short period of time.
8
Dept. of CSE(Data Science)
MODULE 2
4. Some algorithms are suitable for all three applications, whereas others can be used only
for one or two of these applications mentioned in Table 1.
Y = f(X) easy
X = f-1(Y) infeasible
easy is defined to mean a problem that can be solved in polynomial time as a function
of input length.
Thus, if the length of the input is n bits, then the time to compute the function is
proportional to na, where a is a fixed constant.
9
Dept. of CSE(Data Science)
MODULE 2
Such algorithms are said to belong to the class P. The term infeasible is a much fuzzier
concept.
For example, if the length of the input is n bits and the time to compute the function is
proportional to 2n, the problem is considered infeasible.
These measures are inadequate for cryptography, which requires that it be infeasible to
invert a function for virtually all inputs, not for the worst case or even average case.
definition of a trap-door one-way function, which is easy to calculate in one direction
and infeasible to calculate in the other direction un less certain additional information
is known.
We can summarize as follows: A trap door one-way function is a family of invertible
functions fk, such that
Y = fk(X) easy, if k and X are known
X = fk-1(Y) easy, if k and Y are known
X = fk-1(Y) infeasible, if Y is known but k is not known
10
Dept. of CSE(Data Science)
MODULE 2
The Rivest-Shamir-Adleman (RSA) scheme has since that time reigned supreme as the most
widely accepted and implemented general-purpose approach to public-key encryption.
The RSA scheme is a block cipher in which the plaintext and 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 .
C = Me mod n
M = Cd mod n = (Me)d mod n = Med mod n
Both sender and receiver must 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 PU = {e, n} and a private key of PR = {d, n}.
1. It is possible to find values of e, d, and n such that Med mod n = M for all M 6 n.
The preceding relationship holds if e and d are multiplicative inverses modulo ∅ (n), where
ed mod ∅ (n) = 1
11
Dept. of CSE(Data Science)
MODULE 2
That is, e and d are multiplicative inverses mod ∅ (n). Note that, according to the rules of
modular arithmetic, this is true only if d (and therefore e) is relatively prime to ∅ (n).
We are now ready to state the RSA [Link] ingredients are the following:
The private key consists of {d, n} and the public key consists of {e, n}. Suppose that user A
has published its public key and that user B wishes to send the message M to A. Then B
calculates C = Me mod n and transmits C. On receipt of this ci phertext, user A decrypts by
calculating M = Cd mod n.
Example:
Alice generates a public/private key pair; Bob encrypts using Alice’s public key; and Alice
decrypts using her private key. An example from [SING99] is shown in Figure 1. For this
example, the keys were generated as follows.
2. Calculate n = pq = 17 * 11 = 187.
12
Dept. of CSE(Data Science)
MODULE 2
In this simple example, the plaintext is an alpha numeric string. Each plaintext symbol is
assigned a unique code of two decimal digits (e.g., a = 00, A = 26).6 A plaintext block consists
of four decimal digits, or two alphanumeric characters.
Figure 2(a) illustrates the sequence of events for the encryption of multiple blocks, and Figure
2(b) gives a specific example. The circled numbers indicate the order in which operations are
performed.
13
Dept. of CSE(Data Science)
MODULE 2
Computational Aspects:
We now turn to the issue of the complexity of the computation required to use RSA. There are
actually two issues to consider: encryption/decryption and key generation.
x16 = x * x * x * x * x * x * x * x * x * x * x * x * x * x * x * x
Example: suppose we wish to calculate x11 mod n for some integers x and n. Observe
that x11 = x1+2+8 = (x)(x2)(x8). In this case, we compute x mod n, x2 mod n, x4 mod n,
and x8 mod n and then calculate [(x mod n) * (x2 mod n) * (x8 mod n)] mod n.
suppose we wish to find the value ab mod n with a, b, and m positive integers. If we
express b as a binary number bk bk-1………… b0, then we have
Figure 1 & Table shows an example of the execution of this algorithm. Note that the
variable c is not needed; it is included for explanatory purposes. The final value of c is
the value of the exponent.
14
Dept. of CSE(Data Science)
MODULE 2
Table: Result of the Fast Modular Exponentiation Algorithm for ab mod n, where a = 7, b =
560 = 1000110000, and n = 561
15
Dept. of CSE(Data Science)
MODULE 2
we can simplify the calculation of Vp and Vq using Fermat’s theorem, which states that ap-1 =1
(mod p) if p and a are relatively prime. Some thought should convince you that the following
are valid.
The quantities d mod (p- 1) and d mod (q- 1) can be precalculated. The end result is that the
calculation is approximately four times as fast as evaluating M = C d mod n directly.
KEY GENERATION
Before the application of the public-key cryptosystem, each par ticipant must generate a pair
of keys. This involves the following tasks.
First, consider the selection of p and q. Because the value of n = pq will be known to any
potential adversary, in order to prevent the discovery of p and q by exhaustive methods, these
primes must be chosen from a sufficiently large set (i.e., p and q must be large numbers).
At present, there are no useful techniques that yield arbitrarily large primes, so some other
means of tackling the problem is needed.
The procedure that is generally used is to pick at random an odd number of the desired order
of magnitude and test whether that number is prime.
the procedure for picking a prime number is as follows
1. Pick an odd integer n at random (e.g., using a pseudorandom number generator).
2. Pick an integer a 6 n at random.
3. Perform the probabilistic primality test, such as Miller–Rabin, with a as a parameter. If
n fails the test, reject the value n and go to step 1.
4. If n has passed a sufficient number of tests, accept n; otherwise, go to step 2.
However, remember that this process is per formed relatively infrequently: only when a new
pair (PU, PR) is needed.
16
Dept. of CSE(Data Science)
MODULE 2
Example: For example, if a prime on the order of magnitude of 2200 were sought, then about
ln(2200)/2 = 70 trials would be needed to find a prime.
Hardware fault-based attack: This involves inducing hardware faults in the processor that is
generating digital signatures.
Chosen ciphertext attacks: This type of attack exploits properties of the RSA algorithm.
Brute force:
The defense against the brute-force approach is the same for RSA as for other cryptosystems,
namely, use a large key space. Thus, the larger the number of bits in d, the better. However,
because the calculations involved, both in key generation and in encryption/decryption, are
complex, the larger the size of the key, the slower the system will run.
Factor n into its two prime factors. This enables calculation of ɸ(𝑛)=(p -1)*( q-1),
which, in turn, enables determination of 𝑑= e− 1𝑚 o 𝑑 (ɸ 𝑛).
Determine ɸ(𝑛) directly, without first determining p and q. Again, this enables
determination of 𝑑 = e− 1𝑚 o 𝑑 (ɸ𝑛).
Determine d directly, without first determining ɸ(𝑛).
17
Dept. of CSE(Data Science)
MODULE 2
Timing Attacks:
Timing Attacks demonstrated that a snooper can determine a private key by keeping
track of how long a computer takes to decipher messages.
Timing Attacks are based on observing how long it takes to compute the cryptographic
operations. Timing attacks are applicable not just to RSA, but to other public-key
cryptography systems.
This attack is alarming for two reasons: It comes from a completely unexpected
direction and it is a ciphertext-only attack.
The timing attack is a serious threat; there are simple countermeasures that can be used,
including using constant exponentiation time algorithms, adding random delays, or using blind
values in calculations.
Constant exponentiation time: Ensure that all exponentiations take the same amount
of time before returning a result. This is a simple fix but does degrade performance.
Random delay: Better performance could be achieved by adding a random delay to the
exponentiation algorithm to confuse the timing attack. Kocher points out that if
defenders don't add enough noise, attackers could still succeed by collecting additional
measurements to compensate for the random delays.
Blinding: Multiply the ciphertext by a random number before performing
exponentiation. This process prevents the attacker from knowing what ciphertext bits
are being processed inside the computer and therefore prevents the bit-by-bit analysis
essential to the timing attack.
To counter such attacks RSA Security, a leading RSA vendor and former holder of the RSA
patent, recommends modifying the plaintext using a procedure known as optimal asymmetric
encryption padding (OAEP).
18
Dept. of CSE(Data Science)
MODULE 2
19
Dept. of CSE(Data Science)
MODULE 2
are distinct and consist of the integers from 1 through p -1 in some permutation.
The Algorithm:
For this scheme, there are two publicly known numbers: a prime number q and an integer a that
is a primitive root of q. Suppose the users A and B wish to create a shared key.
User A selects a random integer XA< 6 and computes YA = a XA mod q. Similarly, user B
independently selects a random integer X B < 6 and computes YB = a XB mod q.
Each side keeps the X value private and makes the Y value avail able publicly to the other side.
Thus, XA is A’s private key and YA is A’s correspond ing public key, and similarly for B.
User A computes the key as K = (Y B)XA mod q and user B computes the key as K = (Y A)XB
mod q. These two calculations produce identical results:
20
Dept. of CSE(Data Science)
MODULE 2
Now consider an adversary who can observe the key exchange and wishes to determine the
secret key K.
Because XA and XB are private, an adversary only has the following ingredients to work with:
q, a, YA, and YB.
Thus, the adversary is forced to take a discrete logarithm to deter mine the key. For example,
to determine the private key of user B, an adversary must compute.
The adversary can then calculate the key K in the same manner as user B calculates it. That is,
the adversary can calculate K as
The security of the Diffie–Hellman key exchange lies in the fact that, while it is relatively easy
to calculate exponentials modulo a prime, it is very difficult to calculate discrete logarithms.
Example: Key exchange is based on the use of the prime number q = 353 and a primitive root
of 353, in this case a = 3. A and B select private keys XA = 97 and XB = 233, respectively. Each
computes its public key:
21
Dept. of CSE(Data Science)
MODULE 2
Both users can now calculate the key. The necessary public values q and a would need
to be known ahead of time. Alternatively, user A could pick values for q and a and
include those in the first message.
As an example of another use of the Diffie–Hellman algorithm, suppose that a group of
users (e.g., all users on a LAN) each generate a long-lasting private value Xi (for user
i) and calculate a public value Yi.
These public values, together with global public values for q and a, are stored in some
central directory. At any time, user j can access user i’s public value, calculate a secret
key, and use that to send an encrypted message to user A.
Because only i and j can determine the key, no other user can read the message
(confidential ity). Recipient i knows that only user j could have created a message using
this key (authentication). However, the technique does not protect against replay
attacks.
1. Darth prepares for the attack by generating two random private keys XD1 and XD2 and then
computing the corresponding public keys Y D1 and YD2.
22
Dept. of CSE(Data Science)
MODULE 2
3. Darth intercepts YA and transmits YD1 to Bob. Darth also calculates K2 = (Y A)XD2 mod q.
4. Bob receives YD1 and calculates K1 = (YD1) XB mod q.
6. Darth intercepts Y B and transmits YD2 to Alice. Darth calculates K1 = (Y B)XD1 mod q.
3. Darth sends Bob E(K1, M) or E(K1, M=), where M= is any message. In the first case, Darth
simply wants to eavesdrop on the communication without altering it. In the second case, Darth
wants to modify the message going to Bob.
The key exchange protocol is vulnerable to such an attack because it does not authenticate the
participants.
Consider the equation Q = kP where Q, P ∈ EP(a, b) and k 6 p. It is rela tively easy to calculate
Q given k and P, but it is hard to determine k given Q and P. This is called the discrete logarithm
problem for elliptic curves.
This is the group defined by the equation y2 mod 23 = (x3 + 9x + 17) mod 23. What is the
discrete logarithm k of Q = (4, 5) to the base P = (16, 5)? The brute-force method is to compute
multiples of P until Q is found. Thus,
Key exchange using elliptic curves can be done in the following manner.
23
Dept. of CSE(Data Science)
MODULE 2
First pick a large integer q, which is either a prime number p or an integer of the form 2m, and
elliptic curve parameters a and b.
This defines the elliptic group of points Eq(a, b). Next, pick a base point G = (x1, y1) in Ep(a,
b) whose order is a very large value n.
The order n of a point G on an elliptic curve is the smallest positive integer n such that nG = 0
and G are parameters of the cryptosystem known to all participants.
To break this scheme, an attacker would need to be able to compute k given G and kG, which
is assumed to be hard.
24
Dept. of CSE(Data Science)
MODULE 2
Note that A has used B’s public key PB. To decrypt the ciphertext, B multiplies the first point
in the pair by B’s private key and subtracts the result from the second point:
Example:
25
Dept. of CSE(Data Science)
MODULE 2
26
Dept. of CSE(Data Science)