Unit 3 Cryptography and Public Key Infrastrucutre
Unit 3 Cryptography and Public Key Infrastrucutre
Infrastructure
Introduction to Cryptography
Before going in detail to this chapter, we should know some basic
concepts of cryptography, which are explained below.
Cryptanalysis
(Sender) (Receiver)
Message Message
Encryption Decryption
Source Cipher text Destination
(plaintext) $%# (plaintext)
ABC ABC
Encryption Decryption
Key Key
Figure 3.1 Conventional encryption model
Encryption /
Decryption Key
(Same Key)
Figure 3.2 Symmetric key cryptography
Public Key
Receiver’s
Private Key
Sender
Receiver
- In this cryptography technique, there are two keys: a private key and a
public key.
- In this method, private key is used for individual and public key is
available for public.
- Public key is disclosed to all the users in network and private key is the
secret key known only to a particular user.
- Private key is never distributed by the receiver
- Public key used for encryption and private key is used for decryption.
- Example: RSA algorithm, Digital signature
Cryptographic systems are characterized along three independent
dimensions:
1. The type of operation (algorithm) used:
There are two general techniques substitution and transposition.
In substitution technique, each plaintext element (letter) is replaced or
mapped with another letter.
In transposition technique, elements in the plaintext are rearranged.
2. Number of keys used:
If both sender and receiver use the same key, the system is referred to
as symmetric, single-key, secret-key, or conventional encryption. If the
sender and receiver use different keys, the system is referred to as
asymmetric, two-key, or public-key encryption.
4 |C o m p u t e r a n d N e t w o r k S e c u r i t y
3. The way in which the plaintext is processed (Block cipher or Stream cipher):
A block cipher processes the input one block of elements at a time,
producing an output block for each input block.
A stream cipher processes the input elements continuously, producing
output one element at a time, as it goes along.
Cryptanalysis and Brute force attack
- Generally attackers try to attack in encryption to recover the key rather
than plaintext. There are two general approaches to attacking a
conventional encryption scheme Cryptanalysis and Brute force attack:
Cryptanalysis: The process of trying to break the cipher text to obtain the
original plain text is called cryptanalysis.
- It is study of ciphers and cipher text with a view of finding weaknesses in
them to retrieve plaintext from cipher text without necessarily knowing
the key or the algorithm.
- It is breaking the code, and the person attempting cryptanalysis is called
cryptanalyst.
Brute-force attack: The attacker tries every possible key on a piece of
cipher text until the plain text is achieved. On average, half of all possible
keys must be tried to achieve success.
Various types of cryptanalysis attacks are
- Cipher text only: in which the cryptanalyst tries to get the plaintext or the
decryption function from the knowledge of a piece of cipher text. It is
weakest among all methods.
- Known plain text: the cryptanalyst has access to a cipher text and its
corresponding plain text. Then attacker tries brute force attack to find
decryption function.
- Chosen plaintext: in which Plaintext message chosen by cryptanalyst and
obtain the corresponding cipher text with the secret key.
- Chosen cipher text: this is just opposite of previous attack, the
cryptanalysis can choose any cipher text he wants and obtain the
corresponding plaintext using a decryption. This is strongest among all
methods.
Cryptography and Public key infrastructure
It uses the same key for both It uses one key for encryption and
encryption and decryption. different key for decryption.
Figure: Figure:
a b c d e f g h I j k l m n o p q r s t u v w x y z
Cipher text
D E F G H I J K L M N O P Q R S T U V W X Y Z A B C
- For example:
If plaintext is aarush and bhagya
Cipher text is DDUXVK DQG EKDJBD
- So, by adding 3 as a key, you can encrypt your plaintext into cipher text
and by subtracting 3 from cipher text you can get back the plaintext.
- Now let‟ s assign the numeric value to each letter, then:
a b c d e f g h i j
0 1 2 3 4 5 6 7 8 9
k l m n o p q r s t
10 11 12 13 14 15 16 17 18 19
u v w x y z
20 21 22 23 24 25
Playfair cipher
- This technique has been used until the end of World War 1 by Britain. It is
a type of block cipher.
- It is the best known method of multiple-letter encryption cipher.
- Playfair algorithm is based on the use of a 5 X 5 matrix of letters
constructed using a keyword.
- Fill in letters of keyword in the matrix and fill the rest of matrix with other
letters.
- I and J are put in a single place (same position).
- For example using the keyword BHAGYA, the matrix will be like:
B H A G Y
C D E F I/J
K L M N O
P Q R S T
U V W X Z
8 |C o m p u t e r a n d N e t w o r k S e c u r i t y
- The matrix is constructed by filling in the letters of the keyword from left
to right and from top to bottom and then filling the remainder of the matrix
with the remainder letters in alphabetic order.
In the process of encryption in Playfair cipher:
- Break the plaintext into pairs of two consecutive letters, like „asmita‟ is
written as as mi ta
- If a pair is repeated letters, insert filler like „X‟ in the plaintext. E.g.
„balloon‟ is treated as ba lx lo on.
- If both letters falls in the same row of the key matrix, replace each with the
letter immediate to its right (wrapping back to start from end). E.g. “GY”
encrypts to “YB”.
- If both letters falls in the same column, replace each with the letter
immediately below it (again wrapping to top from bottom). E.g. “BU”
encrypts to “CB”.
- Otherwise each letter is replaced by the one in its row in the column of the
other letter of the pair. E.g. “DS” encrypts to “FQ” and “CY” encrypts to
“IB” or “JB” (as needed).
Advantage of this cipher is it is much improved over mono alphabetic
technique.
Disadvantage Actually still it can be broken due to limited structure of
plaintext.
Example of Playfair cipher
Generate cipher text for the plaintext “hide the gold in the tree stumps”,
and the keyword is “playfair example”.
In our example we have given the keyword „playfair example‟
First construct key matrix for the key, like:
P L A Y F
I/J R E X M
B C D G H
K N O Q S
T U V W Z
Cryptography and Public key infrastructure
- As shown in the above table, the encryption of letter „R‟ with key „M‟ is D.
- Now let‟ s take a simple example. Key is COUNTON and Plaintext is
VIGENERE CIPHER
- In the process of encryption, first repeat the key until the length of
plaintext.
- Take one by one letter from key and plaintext then we can get cipher text
letter from vigenere table (as shown in the above table, with the key letter
M and plaintext letter R, we get cipher text letter D).
Key C O U N T O N C O U N T O N
Plain
V I G E N E R E C I P H E R
Text
Cipher
X W A R G S E G Q C C A S E
Text
- Similarly for decryption, you need to find a X in row of key value (C), then
find corresponding plaintext letter in that column (V).
One Time Pad (OTP) Perfect cryptography
- OTP is specific subset of Vernam cipher. It is also called perfect cipher.
- It is basic yet solid method to protect short messages.
- It the most secure method and almost impossible to break it
mathematically.
- It is implemented using random key that is as long as the message. The
key is random so that cipher text is too random.
- Basic Idea: Cipher text should provide no “information” about Plaintext.
So OTP provide “perfect secrecy”.
- The key is to be used to encrypt and decrypt a single message, and then is
discarded. (The key in OTP never be reused.)
- Only two copies of the key are generated; one for sender and one for
receiver.
- Each new message requires a new key of the same length as the new
message.
- There is no statistical relationship between plaintext and cipher text, so
this method is very much hard to break.
In the process of encryption of OTP
- Add each corresponding letter of plaintext to the corresponding alphabet
of OTP.
- If the sum produced is greater than or equals to 26, subtract 26 from it.
- Translate each number of the sum back to corresponding alphabet. This
gives the output cipher text.
- Each key letter is used exactly once for only one message.
- Sender encrypts the message and then destroys the OTP. Receiver
decrypts the message using the same OTP and then destroys the OTP.
For example: plaintext is how are you?
One time pad is NCBTZQARX
12 |C o m p u t e r a n d N e t w o r k S e c u r i t y
H O W A R E Y O U
Plaintext
7 14 22 0 17 4 24 14 20
N C B T Z Q A R X
One Time Pad
13 2 1 19 25 16 0 17 23
20 16 23 19 42 20 24 31 43
Initial Total
Subtract 26,
20 16 23 19 16 20 24 5 17
If ≤ 26
Cipher text U Q X T Q U Y F R
Disadvantages
- There is a practical problem of making large set of random keys.
- There is a problem of key distribution and protection as for every
message, equal length of key is needed by both sender and receiver.
Hill cipher
- It is poly alphabetic cipher method developed by Lister Hill in 1929.
- The encryption algorithm takes m successive plaintext letters and
substitutes for them m cipher text letters.
- The substitution is determined by m linear equations in which each
character is assigned a numerical value (a = 0, b = 1 ... z = 25).
- For m = 3, the system can be described as follows:
c1 = (k11P1 + k12P2 + k13P3) mod 26
c2 = (k21P1 + k22P2 + k23P3) mod 26
c3 = (k31P1 + k32P2 + k33P3) mod 26
- And in general we can write like this:
Cryptography and Public key infrastructure
31
= 16 mod 26
325
5
= 8 = FIN (that is cipher text)
13
- For For example the message (plaintext) is “bhagya is also a good boy”
Key 5 2 1 4 6 3
Plaintext B h a g y a
i s a l s o
a g o o d b
o y x x x x
Steganography
- It is an art of hiding data.
- The word “steganography” derived from Greek words “stego” means
“cover” and “graphy” means “writing” So, Steganography means
“covered writing”. It also means “information hiding”. It conceals the
existence of the message.
- It is the art and science of communicating in such a way that the presence
of a message cannot be detected.
- Steganography and encryption are both used to ensure data
confidentiality. However the main difference between both of them is that
with encryption, anybody can see that both parties are communicating in
secret.
- While in case of steganography, nobody can see this communication. This
makes steganography more secure.
- In encryption, we scramble the message so the intruder can’t be
understood, while in steganography the secure message or plaintext (or
image) is embedded within another message (or even an image). The
embedded data will be confidential from the attacker.
16 |C o m p u t e r a n d N e t w o r k S e c u r i t y
- As per above figure we can say that secret data is being embedded inside
a cover to produce the stego file. At the receiving end, the stego file is
decoded to get the original data.
- There are mainly three types of steganography
1. Text steganography: in which message is encoded in text / documents.
2. Audio steganography: in which message is encoded in audio clip.
3. Image steganography: in which message is encoded in images.
- Some techniques have been used historically for steganography are:
Character marking:
- The secret message is overwritten in pencil. The marks are ordinarily not
visible unless the paper is held at an angle to bright light.
Invisible ink:
- The hash value is appended to the message at the source at a time when
the message is assumed or known to be correct. The receiver
authenticates that message by re-computing the hash value.
- The purpose of a hash function is to produce a "fingerprint" of a file,
message, or other block of data.
- To be useful for message authentication, a hash function H must have the
following properties:
H can be applied to a block of data of any size.
H produces a fixed-length output.
H(x) is relatively easy to compute for any given x.
Application of hash function
- Most general use of hash functions in digital signature and for data
integrity.
- Hashing is used in collision resolution techniques.
- It is also used for password authentication.
SHA – 1 (Secure Hash Algorithm – 1)
- (A 160-bit hash function which resembles the earlier MD5 algorithm. SHA
was designed by NIST & NSA in 1993, revised 1995 as SHA-1.
- SHA-1 produces a 160 bits hash value called message digest (output of
SHA-1).
- The message size of SHA-1 is 264-1 bits.
- The block size is 512 bits.
- The word size is 32 bits.
- Number of steps required for SHA-1 is 80 bits.
- SHA-1 uses modular arithmetic and logical binary operations.
The ideal SHA-1 has the following properties:
it is infeasible to find a message that has a given hash.
it is infeasible to modify a message without changing its hash.
it is infeasible to find two different messages with the same hash.
Cryptography and Public key infrastructure
Working of SHA 1
Divide the current 512 block into 16 sub blocks, each of which
containing 32 bits.
SHA has four rounds, each round has 20 steps. Each round takes
current 512 bit block.
So, SHA-1 makes total of 80 iterations.
Advantages
- This method is harder for brute force attack.
- It is also used in message authentication, OTP, software integrity,
password validity etc.
Disadvantages
- There should be a problem of “collision” in that algorithm, to avoid it,
some strong hash algorithm needed. And at the receiver end, exact
matches will result in success.
Application main application of SHA1 is digital signature.
- Authentic means that you know who created the document and you know
that it has not been altered in any way since that person created it.
- Digital signature schemes normally gives two algorithms: one for signing
which involves the user’s private key and one for verifying signatures
which involves the user’s public key. The output of this process is called
the “digital signature”.
- It is easily transportable, cannot be changed by someone else, and can
automatically time stamped.
- The main requirements of a digital signature are:
It is unique to the sender.
It should be recognizable and verifiable.
The difference between digital signature and hand written signature:
- The hand written signature is biologically linked where as digital
signature is something that is signed and produced by machine.
- If someone steals your machine, and with it your private key, they could
pretend to be you, legitimately. The same is not true for a handwritten
signature.
- Handwritten signatures are under the direct control of the signer, whereas
digital signatures must be applied by a computer commanded by the
signer.
- Forgery can be possible in case of hand written signature, while in digital
signature it is virtually impossible.
- Handwritten signatures are extremely simple, and easy to understand
whereas Digital signatures are complex to understand.
22 |C o m p u t e r a n d N e t w o r k S e c u r i t y
- The digital signature usually involves two processes: one performed by the
signer and the other by the receiVER of the digital signature.
- The digital signature uses the hash result which is unique to both the
signer and verifier.
- At the verification side, digital signature is checked by the reference of
the original message and a given public key.
- Finally the result is generated that the digital signature is verified or not.
Digital signatures fall into two categories
1. Direct digital signature
- Involve only communicating parties (sender and receiver).
- It assumed receiver has sender’s public-key.
- Digital signature made by sender signing entire message or hash with
private-key.
- The main drawback of this signature is that the validity of this scheme is
depends on the security of the sender’s private key. Sender can claim the
deny of the communication at any time when he wishes.
Cryptography and Public key infrastructure
Digital certificates
Certificate Distribution System or repository
Certification Authority (CA)
The CA is a trusted third party that authenticates entities taking part in an
electronic transact, it issues digital certificates.
That issues and verifies certificates. A certificate includes the public
key or information about the public key.
CA represents the people, processes and tools to create digital
certificate.
Who can be CA? The authority of acting as a CA has to be with
someone who everybody trusts. The governments in the various
countries decide who can and who cannot be a CA.
A CA is a reputed organization, such as a post office, financial
institution, software company, etc.
In some of the architectures, there are multiple levels of CAs in
which each higher level CA assures for its subordinate CA.
General tasks of CA are:
o Issuing certificates
o Revoking certificates
o Formulating a certificate policy
o Implementing the Certification Practice Statement (CPS)
Two of the world‟ s most famous CAs are VeriSign & Entrust.
Registration Authority (RA)
An RA is responsible for the interaction between clients and CAs.
The RA acts as a verifier for the certificate authority before digital
certificate is issued to the requestor.
RA accepting and verifying registration information about new user.
Generating keys on behalf of the end users.
General tasks of RA are:
o Receive entity requests and validate them
o Send the requests to the CA
26 |C o m p u t e r a n d N e t w o r k S e c u r i t y
- Minimize access to private keys: computers with private keys should have
minimum external connections.
- Use physical security to private keys: Protect private keys with
cryptographic hardware products. Cryptographic hardware does not
allow export of the private key to software where it could be attacked.
- Key should be destroyed properly at the end of its lifetime.
- Key should never be exposed in clear text.
- The key should not be shared. It should be stored securely.
- There should not be any copy of private key in case of digital signature.
- The key should be transported securely.
3.8 Trust models
- A trust model is a collection of rules that informs application on how to
decide the legality of a digital certificate.
- There are three main types of trust models used with PKI:
1. Hierarchical trust model
2. Bridge trust model
3. Hybrid trust model
Hierarchical trust model
- It is also known as a tree model in which a root CA residing at the top and
provides all the information. Intermediate CAs, leaf CAs and end entities
are also there.
Figure of hierarchical model is as below:
Leaf entities
Cryptography and Public key infrastructure
- The root CA generates certificates for the intermediate CAs, which in turn
generates certificates for the leaf CAs, and the leaf CAs generate
certificates for the end-entities (users, network devices, applications).
- This model allows tight control over certificate based activities.
- Root CA systems can have trusts between them and there can be trust
between intermediate and leaf CAs.
- The leaf CA is any CA that is at the end of the network or chain.
- This structure is helpful in creating hybrid structure.
- The root CA‟ s public keys are distributed to all entities and these are used
to verify the certificates.
Bridge trust model(Peer to peer trust model)
- In it, peer to peer relationship exists between roots CAs.
- In this model, certification process between organizations or departments
is possible.
- The root CAs can communicate each other, allowing cross verification.
Bidirectional trust is there.
- This model is useful in geographically dispersed organizations which are
working together.
Figure of this model is as below
In it, the letters of plain text are In it, in generating cipher text,
replaced by other letters or number plaintext remains the same but the
or symbols. order of character is shuffled
around
Each letter retains its position Each letter retains its identity but
changes its identity changes its position
Example: Caesar cipher Example: Rail fence cipher
34 |C o m p u t e r a n d N e t w o r k S e c u r i t y
Assignment
Short Questions
1 Define: Encryption, Decryption
Define Cryptanalysis. List out various cryptanalysis attacks.
Write a simple example for conversation of plaintext into cipher text
2
using Caesar cipher.
3 Define symmetric and asymmetric encryption. List out types of them.
4 Define hash function. Write down application of hash function.
Which key is used for encryption and decryption in symmetric and
5
asymmetric cryptography?
6 Define transposition technique.
Descriptive Questions
1 Draw and explain symmetric encryption model.
2 Write a short note on steganography.
Convert given plaintext into cipher text using Vigenere cipher:
3
Plaintext is: “GUJARAT UNIVERSITY” and Key is: “TECHNOLOGICAL”
4 Explain SHA-1 algorithm in short with block diagram.
5 Write a short note on digital signature.
6 Explain the steps of obtaining digital certificate.
7 Define centralized infrastructure. Write its limitations.
8 Explain bridge trust model.
9 Explain Playfair cipher with example.
10 Explain rail fence cipher with an example.
11 Explain private key protection.
Plaintext is: “SUMMER” and key is:
17 17 5
12 21 18 21
2 2 9
Solve it using hill cipher.
13 If key is: “computer”, write Playfair cipher key matrix.
Solve using Playfair cipher. Solve using Playfair cipher.
Key: “LARKSPUR” Key: “PRIMROSE”
14
Plaintext: “rocky mountain Plaintext: “hike the foothills”
meadow”
Solve using Playfair cipher. Solve using Playfair cipher.
Key: “charles” Key: “keyword”
15
Plaintext: “the scheme really Plaintext: “why don‟ t you?”
works”