Unit-Iii 2
Unit-Iii 2
WHAT IS CRYPTOGRAPHY
Cryptography
Secret-key Public-key
Cryptography(symmetric Cryptography(Asymmetri Hash Function
key) c key)
• Secret-key Cryptography(Symmetric key) :
• Single key is used for both encryption and decryption
• Hash function :
• It uses mathematical transformation to irreversibly “encrypt” information .
ASYMMETRIC CRYPTOGRAPHY
• The size of cipher text is the same or smaller than the • The size of cipher text is the same or larger than the
original plain text. original plain text.
• In symmetric key encryption, resource utilization is low • In asymmetric key encryption, resource utilization is
as compared to asymmetric key encryption. high.
• It is efficient as it is used for handling large amount of • It is comparatively less efficient as it can handle a small
data. amount of data.
• Security is less as only one key is used for both • It is more secure as two keys are used here- one for
encryption and decryption purpose. encryption and the other for decryption.
• The Mathematical Representation is as follows-
• The Mathematical Representation is as follows-
P = D(Kd, E (Ke,P))
P = D (K, E(K, P))
where Ke –> encryption key
• where K –> encryption and decryption key
• Kd –> decryption key
P –> plain text
D –> Decryption
D –> Decryption
E(Ke, P) –> Encryption of plain text using encryption
E(K, P) –> Encryption of plain text using K
key Ke. P –> plain text
PUBLIC AND PRIVATE KEYS
• A public key is freely available and published by the private key owner.
Anyone who would then like to send the publisher of the public key an
encrypted message can do so, by encrypting the message using the
published public key and sending it to the holder of the private key.
• No one else can decrypt the message because the corresponding private key
is held securely by the intended recipient.
• Once the public key-encrypted message is received, the recipient can
decrypt the message using the private key
• The preceding diagram illustrates how a sender encrypts data P using the recipient’s
public key and
encryption function, and produces an output of encrypted data C, which is then
transmitted over the
network to the receiver.
• Once it reaches the receiver, it can be decrypted using the receiver’s private key by
feeding the C-encrypted data into the decryption function, which will output plaintext P.
• This way, the private key remains on the receiver’s side, and there is no need to share
ASYMMETRIC CRYPTOGRAPHY
ALGORITHMS
• Public key algorithms are slower in terms of computation than symmetric key algorithms.
• Therefore ,they are not commonly used in the encryption of large files or the actual data that
requires encryption.
• They are usually used to exchange keys for symmetric algorithms.
• Once the keys are established securely, symmetric key algorithms can be used to encrypt
the data.
• Public key cryptography algorithms are based on various underlying mathematical functions.
• The three main categories of asymmetric algorithms are described here.
• Integer factorization
• Discrete logarithm
• Elliptic curves
INTEGER FACTORIZATION
• Integer factorization schemes are based on the hard problem that large
integers are extremely hard to factor. RSA is a prime example of this type of
algorithm.
• Def: The prime factors of a positive integer are the prime numbers that
divide that integer exactly. The process of finding these numbers is called
integer factorization, or prime factorization
DISCRETE LOGARITHM
• The elliptic curve algorithm is based on the discrete logarithm problem discussed previously,
but in the context of elliptic curves. An elliptic curve is an algebraic cubic curve over a field,
which can be defined by an equation, as shown here. The curve is non-singular, which means
that it has no self-intersections. It has two variables a and b, as well as a point of infinity:
y2 = x3 + ax + b
• Here, a and b are integers whose values are elements of the field on which the elliptic curve is
defined.
• Elliptic curves can be defined over reals, rational numbers, complex numbers, or finite fields.
• For cryptographic purposes, an elliptic curve over prime finite fields is used instead of real
numbers.
• The most prominently used cryptosystems based on elliptic curves are the Elliptic Curve Digital
Sig- Natures Algorithm (ECDSA) and the Elliptic Curve Diffie-Hellman (ECDH) key exchange.
INTRODUCING RSA
• RSA was invented in 1977 by Ron Rivest, Adi Shamir, and Leonard Adelman,
hence the name RSA.
• This type of public key cryptography is based on the integer factorization
problem, where the multiplication of two large prime numbers is easy, but it
is difficult to factor the product (the result of the multiplication) back into the
two original numbers.
FOLLOWING STEPS:
• 1. Modulus generation:
• Select p and q , which are very large prime numbers.
• Multiply p and q, n=p.q to generate modulus n.
• Calculate N = P x Q
• We have, N = 7 x 17 = 119.
• Choose the public key (i.e., the encryption key) E such that it is not an element of (P -1) x (Q – 1)
• Let us find (7 - 1) x (17 -1) = 6 x 16 = 96
• The factors of 96 are 2, 2, 2, 2, 2, and 3 (because 96 = 2 x 2 x 2 x 2 x 2 x 3).
• Therefore, it can select E such that none of the factors of E is 2 and 3. We cannot choose E as 4 (because it has 2 as a factor), 15
(because it has 3 as a factor) and 6 (because it has 2 and 3 both as factors).
• Let us choose E as 5 (it can have been any other number that does not its factors as 2 and 3).
• Choose the private key (i.e., the decryption key) D including the following equation is true: (D x E) mod (P – 1) x (Q – 1) = 1
• Let us substitute the values of E, P, and Q in the equation.
• We have (D x 5) mod (7 – 1) x (17 – 1) = 1.
• That is, (D x 5) mod (6) x (16) = 1.
• That is, (D x 5) mod (96) = 1
• After some calculations, let us take D = 77. Then the following is true: (77 x 5) mod (96) = 385 mod 96 = 1 which is what we wanted.
• For encryption, calculate the cipher text (CT) from the plain text (PT) as follows: CT = PTE mod N
• Let us assume that we want to encrypt plain text 10. Then, we have
• CT = 10^5 mod 119 = 100000 mod 119 = 40.
• Send CT as the cipher text to the receiver. Send 40 as the cipher text to the receiver.
• For decryption, calculate the plain text (PT) from the cipher text (CT) as follows:
• PT = CT^D mod N
• PT = CT^D mod N
• That is, PT = 4077mod 119 = 10, which was the original plaintext of step5.
ELLIPTIC CURVE CRYPTOGRAPHY
• Total Pairs in EC is 5 12 4 10
6 10 5 8
• Total Points :
7 10 6 10
• (12,0), (11,2),(11,4),(7,3), 7 9
8 12
(9,3) 8 11
9 3
• (10,3),(7,10),(9,10),(10,10), 9 9
10 9
(0,4) 10 9
11 4
• (0,9),(3,6),(4,6),(6,6),(3,7), 12 1 11 4
(4,7),(6,7), 12 0
POINT DOUBLING AND POINT ADDITION
• If P== Q
• S = 3 x12 +a/ 2.Y1 Mod p
• If P != Q
• S = Y2 - Y1 / X2 - X1
• X3 =S2-x1-x2 mod p
• Y3 = S(x1-x3)-y1
HASH FUNCTION?
• Hash functions are used to create fixed-length digests of arbitrarily long input strings. Hash
functions are keyless, and they provide a data integrity service. They are usually built using
iterated and dedicated hash function construction techniques.
• A cryptographic hash function combines the message-passing capabilities of hash functions
with security properties.
• Various families of hash functions are available, such as MD, SHA1, SHA-2, SHA-3, RIPEMD,
and Whirlpool.
• Hash functions are commonly used for digital signatures and MACs, such as HMACs
• Hash Uses
• Digital signatures.
• Digital fingerprints.
• Logging sensitive data.
• Saving passwords.
• Blockchain.
HASH FUNCTION [CONT..]
• Hash functions are also typically used to provide data integrity services. These can
be used both as one-way functions and to construct other cryptographic primitives,
such as MACs and digital signatures.
• There are two practical properties of hash functions that must be met depending on
the level of integrity required:
• Compression of arbitrary messages into fixed-length digests
• Easy to compute
• The following list describes the most common secure hash algorithms (SHAs):
• SHA-0: This is a 160-bit function introduced by the U.S. National Institute of Standards and
Technology (NIST) in 1993.
• SHA-1: SHA-1 was introduced in 1995 by NIST as a replacement for SHA-0. This is also a 160-bit
hash function. SHA-1 is used commonly in SSL(Secure Sockets Layer) and TLS (Transport Layer
Security)implementations. It should be noted that SHA-1 is now considered insecure, and it is
being deprecated by certificate authorities. Its usage is discouraged in any new
implementations.
• SHA-2: This category includes four functions defined by the number of bits of the hash: SHA-
224, SHA-256, SHA-384, and SHA-512.
• SHA-3: This is the latest family of SHA functions. SHA3-224, SHA3-256, SHA3-384, and SHA3-512
are members of this family. SHA-3 is a NIST-standardized version of Keccak.
SECURE HASH ALGORITHMS [CONT..]
• RIPEMD: RIPEMD is the acronym for RACE Integrity Primitives Evaluation
Message Digest. It is based on the design ideas used to build MD4. There are
multiple versions of RIPEMD, including 128-bit, 160-bit, 256-bit, and 320-bit.
• Whirlpool: This is based on a modified version of the Rijndael cipher known as
W. It uses the Miyaguchi-Preneel compression function, which is a type of one-
way function used for the compression of two fixed-length inputs into a single
fixed-length output. It is a single-block length compression function.
SHA-256
• SHA-256 has an input message size limit of 264 - 1 bits. The block size is 512 bits, and it has a word size
of 32 bits. The output is a 256-bit digest. The compression function processes a 512-bit message block
and a 256-bit intermediate hash value. There are two main components of this function:
• the compression function
• message schedule.
• Pre-processing:
• Padding of the message is used to adjust the length of a block to 512 bits if it is smaller than the required block
size of 512 bits.
• Parsing the message into message blocks, which ensures that the message and its padding are divided into
equal blocks of 512 bits.
• Setting up the initial hash value, which consists of the eight 32-bit words obtained by taking the first 32 bits of
the fractional parts of the square roots of the first eight prime numbers. These initial values are fixed and
chosen to initialize the process. They provide a level of confidence that no backdoor exists in the algorithm.
HASH COMPUTATION
• The structure of SHA-3 is very different from that of SHA-1 and SHA-2. The key idea behind SHA-3
is based on unkeyed permutations, as opposed to other typical hash function constructions that
used keyed permutations. Keccak also does not make use of the Merkle-Damgard transformation
that is commonly used to handle arbitrary-length input messages in hash functions.
• A newer approach, called sponge and squeeze construction, is used in Keccak. It is a random
permutation model. Different variants of SHA-3 have been standardized, such as SHA3-224, SHA3-
256, SHA3-384, SHA3-512, SHAKE128, and SHAKE256. SHAKE128 and SHAKE256 are extendable-
output functions (XOFs), which allow the output to be extended to any desired length.
• The following diagram shows the sponge and squeeze model, which is the basis of SHA-3 or
Keccak. Analogous to a sponge, the data (m input data) is first absorbed into the sponge after
applying padding. It is then changed into a subset of the permutation state using XOR (exclusive
OR), and then the output is squeezed out of the sponge function that represents the transformed
state. The rate r is the input block size of the sponge function, while capacity c determines the
security level:
• In the preceding diagram, state size b is calculated
by adding bit rate r and capacity bits c. r and c can
be any values as long as sizes of r + c are 25, 50,
100, 200, 400, 800, or 1,600. The state is a 3-
dimensional bit matrix. The initial state is set to 0.
• The data m is entered into the absorb phase block
by block via XOR ⊕ after applying padding.
• The following table shows the value of bit rate r
(block size) and capacity c required to achieve the
desired output hash size under the most efficient
setting of r + c = 1600
Kpb = (p, a, b, q, A, B)
• The private key is a randomly chosen integer d in step 2:
Kpr = d
• Now, the signature can be generated using the private and public keys.
• An ephemeral key Ke is chosen, where 0 < Ke < q. It should be ensured that Ke is truly
random and that no two signatures have the same key; otherwise, the private key can be
calculated.
• Another value R is calculated using R = Ke A—that is, by multiplying A (the generator
point) and the random ephemeral key.
• Initialize a variable r with the x coordinate value of point R so that r = xR.
• The signature can be calculated as follows:
• S = (h(m)+dr)Ke-1 mod q
• Here, m is the message for which the signature is being computed, and h(m) is the
hash of the message m.
• 4. Signature verification is carried out by following this process:
• Auxiliary value w is calculated as w = s-1mod q
• Auxiliary value u1 = w. h(m) mod q
• Auxiliary value u2 = w. r mod q
• Calculate point P, P = u1*A + u2*B