Chapter three
Chapter three
Content
3.1 Basic cryptographic terms
3.2 Historical background 3.6.3 Digital Signature
3.3 Cipher Techniques 3.6.3.1 Using Public Key
3.3.1 Transposition Cipher 3.6.3.2 Using Message Digest
3.3.2 Substitution Cipher 3.6.3.2.1 MD4family
3.4 Conventional encryption algorithms 3.6.3.2.2 SHA family
3.5 Cryptanalysis 3.6.3.2.3 RIPEMD
3.6 Cryptographic Systems 3.6.4 Public key Infrastructure (PKI)
3.6.1 Symmetric key cryptography 3.6.4.1.1 Trusted Third Party
3.6.1.1 DES 3.6.4.1.2 Certification
3.6.1.2 3DES 3.6.4.1.3 Key Distribution
3.6.1.3 AES 3.6.4.1.4 PKI Topology
3.6.1.4 Block Cipher Modes 3.6.4.1.5 Enrollment and Revocation
3.6.2 Public key cryptography Procedures
3.6.2.1 Diffie-Hellman
3.6.2.2 RSA
Introduction: Cryptography
❑ Comes from the Greek kryptós which means ‘hidden’ and gráphein, ‘to write’)
is the study of designing the techniques of cryptosystem.
❑ It is the science and study of secret writing (practice and study of hiding
information)
❑ It is the art and science of making a cryptosystem that is capable of providing
information security.
❑ It deals with the actual securing of digital data.
❑ It refers to the design of mechanisms based on mathematical algorithms that
provide fundamental information security services.
❑ You can think of cryptography as the establishment of a large toolkit containing
different techniques in security applications.
3.1 Basic cryptographic terms
❑ Plaintext : The information in its original form. This is also
known as cleartext.
❑ Ciphertext : The information after it has been obfuscated by
the encryption algorithm.
❑ Algorithm: The method of manipulation that is used to
change the plaintext into ciphertext and vice versa.
❑ Secrete Key : The input data into the algorithm that
transforms the plaintext into the ciphertext or the ciphertext
into the plaintext that is only known by sender and receiver.
❑ Encryption/Enciphering: The process of changing the
plaintext into ciphertext.
❑ Decryption/Deciphering: The process of changing the
ciphertext into plaintext.
Cont…
❑ Cryptography: The art of concealing information using encryption.
Note
21
Affine ciphers
Affine ciphers
The affine cipher uses a pair of keys in which the first key is from Z26* and the
second is from Z26. The size of the key domain is 26 × 12 = 312.
Use an affine cipher to encrypt the message “hello” with the key pair (7, 2).
Affine ciphers
Use the affine cipher to decrypt the message “ZEBBW” with the key pair (7, 2) in
modulus 26.
Solution
Cont…
Cont…
Or we can use Vigenère table.
Vigenère Table
Hill Cipher
It is a polyalphabetic substitution cipher.
Developed by mathematician Laster Hill in 1929.
Encrypts a group of letters: digraph, trigraph or
polygraph.
Based on linear algebra.
Keyword is given as 𝑛𝑥𝑛 matrix.
C = KP mod 26 (encryption)
▪ You can read about Diffie-Hellman, DSS, and Elliptic Curve Cryptography
(ECC) algorithms
70
3.3.1 RSA - Asymmetric Cryptosystem Example
▪ The most widely used public-key cryptosystem is RSA
▪ RSA is from Ron Rivesh, Adi Shamir and Leonard Adleman
(in 1977)
▪ It is a block cipher in which the plaintext and ciphertext are
integers between 0 and m-1 for some m
▪ The private and public keys are constructed from very large
prime numbers (consisting of hundreds of decimal digits)
▪ Principle: No mathematical method is yet known to efficiently
find the prime factors of large numbers
▪ Breaking RSA is equivalent to finding the prime factors: this is
known to be computationally infeasible, i.e., security is based
on the difficulty of factoring large integers
▪ It is only the person who has produced the keys from the
prime numbers who can decrypt messages 71
▪ RSA - Key Generating Algorithm
1. Choose two large prime numbers, p and q
2. Compute n = pq and (phi) φ = (p-1)(q-1)
3. Choose an integer e, 1 < e < φ, such that GCD(e, φ) = 1
(Note: The Greatest Common Divisor of two integers is the
largest positive integer that exactly divides both integers) or e
and φ are relatively prime (two integers are relatively prime if
their only common positive integer factor is 1)
4. Determine the secret exponent d, 1 < d < φ, such that
φ divides (ed-1); i.e., the remainder of (ed-1)/φ is zero
5. The public key is the pair of integers (e, n) and the private key
is (d, n), i.e., 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
▪ Keep all the values d, p, q and φ secret
▪ n is known as the modulus
▪ e is known as the public exponent or encryption exponent
▪ d is known as the secret exponent or decryption exponent
72
▪ RSA- Encryption
▪ Sender A does the following
▪ Obtains the recipient B's public key (e, n)
▪ Represents the plaintext message as a positive integer M
▪ Computes the ciphertext C = Me mod n
▪ Sends the ciphertext C to B
▪ RSA- Decryption
▪ Recipient B does the following
▪ Uses his/her private key (d, n) to compute M = Cd mod n
▪ Extracts the plaintext from the message representative M
▪ Compared to DES, RSA is computationally more complex;
encryption is 100-1000 times slower than DES
▪ Hence encryption systems use RSA to exchange only shared
keys (for symmetric cryptosystems) in a secure way 73
▪ RSA Simple Example - Key Generation
1. Choose two prime numbers: p=11, q=3
2. n = pq = 11*3 = 33
φ = (p-1)(q-1) = 10*2 = 20
3. Choose e, 1 < e < φ; we choose e=3
Check GCD(e, φ) = GCD(3, 20) = 1 (i.e., 3 and 20 are
relatively prime)
4. Determine d, 1<d<φ, such that φ divides ed-1 (or 20 divides
3d-1)
Simple testing (d = 2, 3, ...) gives d = 7
Check: ed-1 = 3*7 - 1 = 20, which is divisible by φ (20)
5. Public key = (e, n) = (3, 33)
Private key = (d, n) = (7, 33)
74
▪ RSA- Encryption Example
▪ Now say we want to encrypt the message M = 7
▪ C = Me mod n = 73 mod 33 = 343 mod 33 = 13
▪ Hence the ciphertext C = 13
▪ RSA- Decryption Example
▪ For decryption, we compute
▪ M = Cd mod n = 137 mod 33 = 7
75
▪ RSA - More Meaningful Example
▪ Message: ATTACKxATxSEVEN
▪ Group the characters into blocks of three and compute a
message representative integer for each block
▪ ATT ACK XAT XSE VEN
▪ In the same way that a decimal number can be
represented as the sum of powers of ten,
(e.g., 135 = 1 x 102 + 3 x 101 + 5 x 100), we could
represent our blocks of three characters in base 26 using
A=0, B=1, C=2, ..., Z=25
▪ ATT = 0 x 262 + 19 x 261 + 19 x 260 = 513
ACK = 0 x 262 + 2 x 261 + 10 x 260 = 62
XAT = 23 x 262 + 0 x 261 + 19 x 260 = 15567
XSE = 23 x 262 + 18 x 261 + 4 x 260 = 16020
VEN = 21 x 262 + 4 x 261 + 13 x 260 = 14313
76
1. Generate two prime numbers: p=137 and q=131
2. n = pq = 137*131 = 17,947
φ = (p-1)(q-1) = 136*130 = 17680
3. Choose e = 3
Check GCD(3,17680)=1 (i.e., e and φ are relatively prime)
4. Determine d, 1<d<φ, such that φ divides ed-1 (or 17680
divides 3d-1); d = 11787; (11787*3-1)/17680 = 2
5. Hence
▪ Public key, (e, n) = (3, 17947) and
▪ Private key (d, n) = (11787, 17947)
77
▪ To encrypt the first integer that represents "ATT“ (513), we have
▪ C = Me mod n = 5133 mod 17947 = 8363
▪ We can verify that our private key is valid by decrypting
▪ M = Cd mod n = 836311787 mod 17947 = 513
▪ Overall, our plaintext is represented by the set of integers m
▪ (513, 62, 15567, 16020, 14313)
▪ After decryption, these numbers are converted to their textual
equivalents by successively dividing by 26 and taking the
remainders
▪ We compute the corresponding ciphertext integers
C = Me mod n
▪ (8363, 5017, 11884, 9546, 13366)
78
▪ Do public and private keys form a unique pair?
Iteration on i using d=(φ*i+1)/e, i.e., φ divides ed-1
i d
i d
n 33 1 7.00000 n 17947 1 5,893.66667
φ 20 2 13.66667 e 3 2 11,787.00000
e 3 3 20.33333 φ 17680 3 17,680.33333
d 7 4 27.00000
d 11787 4 23,573.66667
φ divides ed-1 5 33.66667
φ divides ed-1 5 29,467.00000
20 divides 3*d-1 6 40.33333
17680 divides 3*d-1 6 35,360.33333
7 47.00000
8 53.66667 7 41,253.66667
8 47,147.00000
80
3.3.2 Digital Signature
▪ Confidentiality ensures that messages cannot be intercepted and
read by eavesdroppers, i.e., encryption protects against passive
attack
▪ A different requirement is to protect against active attack
(falsification of data and transactions). Protection against such
attacks is known as message authentication
▪ A message, file, document, or other collection of data is said to
be authentic when it is genuine (not altered) and comes from its
alleged source
▪ A digital signature is not used to ensure the confidentiality of a
message, but rather to guarantee who sent the message, i.e.,
authentication (nonrepudiation); it proves who the sender is
▪ Nonrepudation can be source repudiation (denial of transmission
of message by source) or destination repudiation (denial of
receipt of message by destination)
▪ Just as with handwritten signatures, digital signing should be
done in a way that is verifiable and nonforgeable
81
▪ Digital signature is also used for Message Integrity; it ensures
that messages are protected against modification
▪ Note: authentication may mean both nonrepudation and data
integrity and sometimes only data integrity
▪ Digital Signature for Assurance
▪ Consider the situation where Bob has just sold Alice
something for 500 Birr through a deal that is made by e-mail
▪ Alice sends an e-mail accepting to pay 500 Birr
▪ Two issues need to be taken care of in addition to
authentication
▪ Alice needs to be assured that Bob will not modify the
amount and show that Alice promised to pay more than
500 Birr
▪ Bob needs to be assured that Alice will not deny that she
sends the message, i.e., source repudiation
82
▪ If Alice signs the message digitally, the two issues will be
solved so that her signature is uniquely tied to its content
Bob’s change will be noticed and Alice also cannot deny
▪ There are several ways to place digital signatures; One
popular way is to use public-key cryptosystem such as RSA,
i.e., message encryption by itself can provide measure of
authentication
▪ Digital signature reverses the asymmetric encryption process
83
Notation: KX- : Private key of X
KX+ : Public key of X
▪ Alice encrypts the message using her private key
C = E(KA-, M) – this is Alice’s signature
▪ Sends the encrypted message to Bob
▪ Bob then decrypts the signature using Alice’s public key
M = D(KA+, C)
▪ If Bob can decrypt it with Alice’s public key, the message
must have been encrypted by Alice; No one else has Alice’s
private key, and therefore no one else could have created a
ciphertext that could be decrypted with Alice’s public key –
nonforgeable and verifiable
▪ Therefore, the encrypted message serves as a digital
signature
▪ In addition, it is impossible to alter the message without
access to Alice’s private key, so the message is authenticated
both in terms of source and in terms of data integrity
84
▪ But anyone can decrypt the message using Alice’s public key if
it is not important that the message be kept secret
▪ To combine both confidentiality and authentication
▪ Alice has to first encrypt the message using her private key
▪ Then encrypt the message with Bob’s public key
C = E(KB+, E(KA-, M))
▪ Sends the encrypted message to Bob
▪ Bob decrypts the message using his private key
▪ Bob then decrypts the message using Alice’s public key
M = D(KA+, D(KB-, C))
▪ Disadvantage: The public-key algorithm must be applied four
times rather than two which has an impact on efficiency
85
▪ Symmetric encryption can also be used for authentication
▪ A message transmitted from source A to destination B is
encrypted using a secret key shared by only A and B. If no
other party knows the key, then confidentiality is provided:
No other party can recover the plaintext of the message; B
is also assured that the message was generated by A
(authentication)
▪ But, Alice can deny that she has sent the message; Bob can
also modify the amount
87
▪ Hash Functions
▪ A hash function H takes a message m of arbitrary length and
produces a fixed size bit string h, h = H(m)
▪ When the hash value h is sent with the message m (not
encrypted), it enables to determine whether m has been
modified or not; the principal objective of a hash function is
data integrity
▪ When a hash function is used to provide message integrity, the
hash function value h is often referred to as a message digest
▪ The two most common hashing algorithms are MD5 (Message
Digest version 5) which produces a 128-bit hash and Secure
Hash Algorithm or SHA (SHA-1 and later versions like SHA-
256) by NIST which produces a 160-bit message digest
88
▪ Example
▪ Assume we want to send the number 12345 and use hashing
to make sure there were no changes to this transmission
▪ The chosen algorithm (highly simplified) is
▪ Multiply the data by 56,789
▪ Invert the result
▪ Chop off all but the first four characters
Multiply: 12345 x 56789 = 701060205
Invert: 502060107
Truncate: 5020
▪ Hence 5020 is the hash value that is sent along with 12345
▪ The receiver follows the same steps to hash the message; if
the results match then there was no modification
▪ A typical hash combines encryption and truncation or padding to
get to a fixed-size authentication value
89
▪ If m is changed to m’, its hash h’ = H(m’) will be different from
h = H(m) and can be easily detected
▪ Alice first computes a message digest and encrypts it with her
private key
▪ E(KA-, H(m)) is sent with m so that Bob knows that it comes from
Alice by decrypting it with her public key
▪ Bob decrypts the digest and calculates the message digest; if they
match he knows the message has not been altered
91
▪ The message digest can be encrypted using symmetric encryption
if it is assumed that only the sender and receiver share the
encryption key
95
▪ Hashing also has other applications
▪ For example, it can be used for intrusion detection and virus
detection. Store H(F) for each file on a system and secure the
hash values (e.g., on a CD-R that is kept secure). One can
later determine if a file has been modified by recomputing
H(F). An intruder would need to change F without changing
H(F)
96
3.3.3 Symmetric Key Distribution
▪ For symmetric encryption to work, the two parties to an
exchange must share the same key, and that key must be
protected from access by others
▪ Frequent key changes are usually desirable to limit the amount
of data compromised if an attacker learns the key
▪ Symmetric Key Distribution Using Symmetric Encryption
▪ Key distribution can be achieved in a number of ways. For two
parties A and B, the following can be used
1. A key could be selected by A and physically delivered to B
2. A third party could select the key and physically deliver it to A
and B
▪ The above two are manual delivery of a key and difficult in
a distributed system where any given host or terminal
may need to engage in exchanges with many other hosts
and terminals over time and each device needs a number
of keys supplied dynamically
97
3. If A and B have previously and recently used a key, one
party could transmit the new key to the other, using the old
key to encrypt the new key
▪ The problem with this option is if an attacker ever
succeeds in gaining access to one of the keys
4. If A and B each have an encrypted connection to a third
party C, C could deliver a key on the encrypted links to A
and B
▪ This is preferable and two kinds of keys are used
▪ Permanent key: used between entities for the purpose
of distributing session keys
▪ Session key: when two end systems (hosts, terminals,
etc.) wish to communicate, they establish a logical
connection (e.g., virtual circuit). For the duration of
that logical connection, called a session, all user data
are encrypted with a one-time session key. At the
conclusion of the session, the session key is
98
destroyed
▪ Option 4 requires a Key Distribution Center (KDC) that determines
which systems are allowed to communicate with each other
▪ The operation of a KDC is as follows
1. When host A wishes to set up a connection to host B, it
transmits a connection request packet to the KDC. The
communication between A and the KDC is encrypted using a
master key (or permanent key) shared only by A and the KDC
2. If the KDC approves the connection request, it generates a
unique one-time session key. It encrypts the session key using
the permanent key it shares with A and delivers the encrypted
session key to A. Similarly, it encrypts the session key using the
permanent key it shares with B and delivers the encrypted
session key to B
3. A and B can now set up a logical connection and exchange
messages and data, all encrypted using the temporary session
key
99
▪ The automated key distribution approach provides the flexibility and
dynamic characteristics needed to allow a number of users to
access a number of servers and for the servers to exchange data
with each other. The most widely used application that implements
this approach is Kerberos (details later in Chapter 5)
▪ Benefits of Session Keys
▪ The session key is safely discarded when the channel is no
longer used
▪ When a key is used very often it becomes vulnerable. Thus by
using the permanent key less often, we make them less
vulnerable
▪ Replay attacks can be avoided (i.e., using the key later after the
session ends to pretend as one of the communicating parties)
▪ Such a combination of long-lasting and cheaper (more
temporary) session keys is a good choice
100
▪ Symmetric Key Distribution Using Asymmetric Encryption
▪ Because of the inefficiency of public key cryptosystems, they
are almost never used for the direct encryption of sizable block
of data, but are limited to relatively small blocks
▪ One of the most important uses of a public-key cryptosystem is
to encrypt secret keys for distribution
▪ Assume that A and B have exchanged public keys
1. A uses B’s public key to encrypt a message (m1) to B
containing an identifier of A (IDA) and a nonce (N1), which is
used to identify this transaction uniquely
m1 = E(KB+, IDA+N1)
2. B sends a message (m2) to A encrypted with A’s public key
and containing A’s nonce N1 as well as a new nonce N2
generated by B. Because only B could have decrypted
message m1, the presence of N1 in message m2 assures A
that the correspondent is B
101
m2 = E(KA+, N1+N2)
3. A returns N2, encrypted using B’s public key, to assure B
that its correspondent is A
m = E(KB+, N2)
4. A selects a secret key Ks and sends M = E(KB+, E(KA-, 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. B computes to recover the secret key
▪ This scheme ensures both confidentiality and authentication
(steps 1 and 2) in the exchange of a secret key
102
3.3.4 Public Key Distribution
▪ Public Announcement of Public Keys
▪ Send a public key to any other participant or broadcast the
key to the community
▪ But anyone can forge such a public announcement, i.e.,
some user could pretend to be a legitimate user and send a
public key to another participant or broadcast it; or Trudy can
send Alice a public key pretending to be Bob
▪ Public-key Infrastructure
▪ We need a body that certifies the public key is that of the
party (a person, a router, etc.) we wish to communicate with,
i.e., Certification/Certificate Authority (CA) that signs
(certifies) the public key; an example is VeriSign
▪ Public-Key Infrastructure (PKI) is the set of hardware,
software, people, policies, and procedures needed to create,
manage, store, distribute, and revoke digital certificates
based on asymmetric cryptography 103
▪ Users publish certificates with the X.509 standard (for formatting
certificates)
▪ A certificate is a public key and some naming “stuff”, digitally
signed by someone you trust (third party), i.e., the CA
▪ The resulting certificate will contain information like user’s
name/ID, user’s public key, name of CA, start date of certificate,
and length of time it is valid
▪ When Bob sends a message (encrypted with his private key) and
his CA-signed certificate, Alice uses the CA’s public key to check
the validity of Bob’s certificate and extract Bob’s public key
▪ The Internet Engineering Task Force (IETF) Public Key
Infrastructure X.509 (PKIX) working group has been the driving
force for deploying a certificate-based architecture on the Internet
108