Unit 4
Unit 4
• Error Control-
• Congestion Control-
Port Numbers
Services
Sequence Numbers
Segments
Connection
Transition Diagram
Flow and Error Control
Silly Window Syndrome
Table Well-known ports used by TCP
Port Protocol Description
7 Echo Echoes a received datagram back to the sender
9 Discard Discards any datagram that is received
11 Users Active users
13 Daytime Returns the date and the time
20 FTP, Data File Transfer Protocol (data connection)
21 FTP, Control File Transfer Protocol (control connection)
23 TELNET Terminal Network
25 SMTP Simple Mail Transfer Protocol
53 DNS Domain Name Server
67 BOOTP Bootstrap Protocol
80 HTTP Hypertext Transfer Protocol
111 RPC Remote Procedure Call
TCP segments
❑ The bytes of data being transferred in each
connection are numbered by TCP.
The numbering starts with a randomly
generated number.
❑ The value of the sequence number field in a
segment defines the number of the first data
byte contained in that segment.
❑ The value of the acknowledgment field in a
segment defines the number of the next byte a
communicating party expects to receive. The
acknowledgment number is cumulative.
* 16
Example 1
Imagine a TCP connection is transferring a file of 6000 bytes. The
first byte is numbered 10010. What are the sequence numbers for
each segment if data are sent in five segments with the first four
segments carrying 1000 bytes and the last segment carrying 2000
bytes?
Solution
The following shows the sequence number for each segment:
Segment 1 ==> sequence number: 10,010 (range: 10,010 to 11,009)
Segment 2 ==> sequence number: 11,010 (range: 11,010 to 12,009)
Segment 3 ==> sequence number: 12,010 (range: 12,010 to 13,009)
Segment 4 ==> sequence number: 13,010 (range: 13,010 to 14,009)
Segment 5 ==> sequence number: 14,010 (range: 14,010 to 16,009)
TCP Segment format
Format of TCP Segment
⚫ Source Port:
⚫ Destination Port:
⚫ Sequence Number:
⚫ Acknowledgement Number:
⚫ Header Length:
⚫ Reserved:
⚫ It specifies the size of sender’s receiving window, i.e., the buffer space available
⚫ Checksum:
⚫ Urgent Pointer:
⚫ Options:
⚫ Data:
No protocol exists!!
❑ Now let us improve the protocol by making it a three-way handshake. The initiator of
the original proposal must acknowledge the response. Assuming no messages are lost,
blue army #2 will get the acknowledgement, but the commander of blue army #1 will
now hesitate. After all, he does not know if his acknowledgement got through, and if it
did not, he knows that blue army #2 will not attack. We could now make a four-way
handshake protocol, but that does not help either. In fact, it can be proven that no
protocol exists that works.
❑ To see the relevance of the two-army problem to releasing connections, rather than to
military affairs, just substitute ‘‘disconnect’’ for ‘‘attack.’’ If neither side is prepared to
disconnect until it is convinced that the other side is prepared to disconnect too, the
disconnection will never happen.
Connection Release (contd.)
• Three-way-handshake + timer
6-14, c,d
For example, suppose the receiver has a 4096-byte buffer, as shown in next Figure. If the
sender transmits a 2048-byte segment that is correctly received, the receiver will
acknowledge the segment. However, since it now has only 2048 bytes of buffer space (until
the application removes some data from the buffer), it will advertise a window of 2048
starting at the next byte expected.
Now the sender transmits another 2048 bytes, which are acknowledged, but the advertised
window is of size 0. The sender must stop until the application process on the receiving
host has removed some data from the buffer, at which time TCP can advertise a larger
window and more data can be sent.
When the window is 0, the sender may not normally send segments, with two exceptions.
First, urgent data may be sent, for example, to allow the user to kill the process running on
the remote machine. Second, the sender may send a 1-byte segment to force the receiver
to reannounce the next byte expected and the window size. This packet is called a window
probe. The TCP standard explicitly provides this option to prevent deadlock if a window
update ever gets lost. Senders are not required to transmit data as soon as they come in
from the application. Neither are receivers required to send acknowledgements as soon as
possible.
TCP Transmission Policy
TCP Sliding Window
❑ One approach that many TCP implementations use to optimize this situation is
called delayed acknowledgements. The idea is to delay acknowledgements and
window updates for up to 500 msec in the hope of acquiring some data on which
to hitch a free ride. Assuming the terminal echoes within 500 msec, only one
41-byte packet now need be sent back by the remote side, cutting the packet count
and bandwidth usage in half.
Port Numbers
User Datagram
Applications
Introduction to UDP
❑ User Datagram Protocol (UDP) is a connectionless,
unreliable transport protocol.
❑ Like TCP, UDP also provides process-to-process
communication.
❑ Unlike TCP, it does not provide flow control and
error control mechanisms.
❑ It is connectionless, therefore, it transfers data
without establishing a connection.
❑ It is less complex and is simple than TCP, and easy
to implement.
UDP
The UDP header
43
Well-known ports used by UDP
Type of
Connection Connection oriented protocol Connection less protocol
Data is read as a byte stream, thus no distinguishing Packets are sent individually and after the
Streaming of data
indications are transmitted to the signal message arrival the packets are rearranged
Data Flow Control TCP controls the flow of data UDP does not have an option for flow control
The Session Layer
55
Presentation Layer
Presentation layer
Temporal compression
In temporal compression, redundant frames are
removed. When we watch television, for example, we
receive 30 frames per second. However, most of the
consecutive frames are almost the same. For example, in
a static scene in which someone is talking, most frames
are the same except for the segment around the speaker’s
lips, which changes from one frame to the next.
Figure MPEG frames
Audio compression
Audio compression can be used for speech or music.
For speech we need to compress a 64 kHz digitized
signal, while for music we need to compress a 1.411
MHz signal. Two categories of techniques are used
for audio compression:
predictive encoding
and
perceptual encoding.
Predictive encoding
In predictive encoding, the differences between samples are
encoded instead of encoding all the sampled values. This
type of compression is normally used for speech. Several
standards have been defined such as GSM (13 kbps), G.729
(8 kbps), and G.723.3 (6.4 or 5.3 kbps). Detailed discussions
of these techniques are beyond the scope of this book.
Cipher
Plain Text Encryption Decryption Plain Text
Text
Algorithm Algorithm
Key A Key B
• Encryption algorithms are standardized & published
• The key which is an input to the algorithm is secret
– Key is a string of numbers or characters
– If same key is used for encryption & decryption the algorithm is called
symmetric
– If different keys are used for encryption & decryption the algorithm is
called asymmetric
Encryption
Symmetric Algorithms
• Algorithms in which the key for encryption and
decryption are the same are Symmetric
– Example: Caesar Cipher
• Types:
1. Block Ciphers
– Encrypt data one block at a time (typically 64 bits, or 128 bits)
– Used for a single message
2. Stream Ciphers
– Encrypt data one bit or one byte at a time
– Used if data is a constant stream of information
Symmetric Encryption
Key Strength
• Strength of algorithm is determined by the size of the key
– The longer the key the more difficult it is to crack
• Key length is expressed in bits
– Typical key sizes vary between 48 bits and 448 bits
• Set of possible keys for a cipher is called key space
– For 40-bit key there are 240 possible keys
– For 128-bit key there are 2128 possible keys
– Each additional bit added to the key length doubles the security
• To crack the key the hacker has to use brute-force
(i.e. try all the possible keys till a key that works is found)
– Super Computer can crack a 56-bit key in 24 hours
– It will take 272 times longer to crack a 128-bit key
(Longer than the age of the universe)
Substitution Ciphers
Caesar Cipher
• Caesar Cipher is a method in which each letter in the
alphabet is rotated by three letters as shown
ABCDEFGHIJKLMNOPQRSTUVWXYZ
DEFGHIJKLMNOPQRSTUVWXYZABC
Substitution Ciphers
Caesar Cipher
Encryption
Cipher Text
Plain Text
Cipher:
Message:
Message: Caesar Cipher
Dwwdfn Dw
Attack At Dawn Algorithm
Gdyq
Key (3)
Decryption
Cipher Text
Plain Text
Cipher:
Message:
Caesar Cipher Message:
Dwwdfn Dw
Algorithm Attack at Dawn
Gdyq
Key (3)
ABCDEFGH I JKLMNOPQRSTUVWXYZ
Message: Encrypted
Cipher: Message:
Bob, I love you. Monoalphabetic Gnu, n etox dhz.
Alice Cipher tenvj
Key
Substitution Cipher
Using a key to shift alphabet
Transposition Cipher
Columnar Transposition
• This involves rearrangement of characters on the plain text into
columns
• The following example shows how letters are transformed
– If the letters are not exact multiples of the transposition size there may be
a few short letters in the last column which can be padded with an
infrequent letter such as x or z
Plain Cipher
Text Text
THISI TSSOH
SAMES OANIW
SAGET HAASO
OSHOW LRSTO
HOWAC IMGHW
OLUMN UTPIR
ARTRA SEEOA
NSPOS MROOK
ITION ISTWC
WORKS NASNS
Ciphers
Shannon’s Characteristics of “Good” Ciphers
• The amount of secrecy needed should determine the
amount of labor appropriate for the encryption and
decryption.
• The set of keys and the enciphering algorithm
should be free from complexity.
• The implementation of the process should be as
simple as possible.
• Errors in ciphering should not propagate and cause
corruption of further information in the message.
• The size of the enciphered text should be no larger
than the text of the original message.
Encryption Systems
Properties of Trustworthy Systems
• It is based on sound mathematics.
– Good cryptographic algorithms are are derived from
solid principles.
• It has been analyzed by competent experts and
found to be sound.
– Since it is hard for the writer to envisage all possible
attacks on the algorithm
• It has stood the “test of time.”
– Over time people continue to review both mathematical
foundations of an algorithm and the way it builds upon
those foundations.
– The flaws in most algorithms are discovered soon after
their release.
Cryptanalysis
Techniques
• Cryptanalysis is the process of breaking an encryption code
– Tedious and difficult process
• Several techniques can be used to deduce the algorithm
– Attempt to recognize patterns in encrypted messages, to be able to
break subsequent ones by applying a straightforward decryption
algorithm
– Attempt to infer some meaning without even breaking the
encryption, such as noticing an unusual frequency of communication
or determining something by whether the communication was short
or long
– Attempt to deduce the key, in order to break subsequent messages
easily
– Attempt to find weaknesses in the implementation or environment
of use of encryption
– Attempt to find general weaknesses in an encryption algorithm,
without necessarily having intercepted any messages
Data Encryption Standard (DES) Basics
• Goal of DES is to completely scramble the data and
key so that every bit of cipher text depends on every
bit of data and ever bit of key
• DES is a block Cipher Algorithm
– Encodes plaintext in 64 bit chunks
– One parity bit for each of the 8 bytes thus it reduces to
56 bits
• It is the most used algorithm
– Standard approved by US National Bureau of Standards
for Commercial and nonclassified US government use in
1993
Data Encryption Standard (DES) Basics
• DES run in reverse to decrypt
• Cracking DES
– 1997: 140 days
– 1999: 14 hours
• TripleDES uses DES 3 times in
tandem
– Output from 1 DES is input
to next DES
Symmetric Encryption
Limitations
Cipher
Plain Text Plain Text
Cipher Text Cipher
❑ The idea! The idea of RSA is based on the fact that it is difficult to
factorize a large integer. The public key consists of two numbers
where one number is multiplication of two large prime numbers.
And private key is also derived from the same two prime
numbers.
❑ So if somebody can factorize the large number, the private key is
compromised. Therefore encryption strength totally lies on the key
size and if we double or triple the key size, the strength of
encryption increases exponentially. RSA keys can be typically 1024
or 2048 bits long, but experts believe that 1024 bit keys could be
broken in the near future. But till now it seems to be an infeasible
task.
Asymmetric Encryption
RSA Algorithm
• Choose two large prime numbers p & q
• Compute n=pq and z=(p-1)(q-1)
• Choose number e, less than n, which has no common factor
(other than 1) with z
• Find number d, such that ed – 1 is exactly divisible by z
• Keys are generated using n, d, e
– Public key is (n,e)
– Private key is (n, d)
• Encryption: c = me mod n
– m is plain text
– c is cipher text
• Decryption: m = cd mod n
• Public key is shared and the private key is hidden
Asymmetric Encryption
RSA