CNS Unit 2
CNS Unit 2
Asymmetric Key Encryption: Asymmetric Key Encryption is based on public and private key
encryption techniques. It uses two different key to encrypt and decrypt the message. It is more
secure that the symmetric key encryption techniques but is much slower.
1. Same algorithm and key used for encryption 1. Same algorithm but different keys used
and decryption. for encryption and decryption.
2. Parties share algorithm and key. 2. Parties share algorithm but each has one
key from a matched pair.
KEY MANAGEMENT
In cryptography, it is a very tedious task to distribute the public and private keys between
sender and receiver. If the key is known to the third party (forger/eavesdropper) then the
whole security mechanism becomes worthless. So, there comes the need to secure the
exchange of keys.
There are two aspects for Key Management:
1. Distribution of public keys.
2. Use of public-key encryption to distribute secrets.
Distribution of Public Key:
The public key can be distributed in four ways:
1. Public announcement
2. Publicly available directory
3. Public-key authority
4. Public-key certificates.
These are explained as following below:
1. Public Announcement: Here the public key is broadcasted to everyone. The major
weakness of this method is a forgery. Anyone can create a key claiming to be someone else
and broadcast it. Until forgery is discovered can masquerade as claimed user.
2. Publicly Available Directory: In this type, the public key is stored in a public directory.
Directories are trusted here, with properties like Participant Registration, access and allow to
modify values at any time, contains entries like {name, public-key}. Directories can be
accessed electronically still vulnerable to forgery or tampering.
3. Public Key Authority: It is similar to the directory but, improves security by tightening
control over the distribution of keys from the directory. It requires users to know the public
key for the directory. Whenever the keys are needed, real-time access to the directory is
made by the user to obtain any desired public key securely.
4. Public Certification : This time authority provides a certificate (which binds an identity
to the public key) to allow key exchange without real-time access to the public authority each
time. The certificate is accompanied by some other info such as period of validity, rights of
use, etc. All of this content is signed by the private key of the certificate authority and it can
be verified by anyone possessing the authority’s public key.
First sender and receiver both request CA for a certificate which contains a public key and
other information and then they can exchange these certificates and can start
communication.
THE RSA ALGORITHM
Introduction
. The RSA algorithm is the most popular and proven asymmetric key cryptographic algorithm.
A prime number is the one that is divisible only by 1 and itself. For instance, 3 is a prime
number, because it can be divided only by 1 or 3. Similarly, 5, 7, 11, 13, 17 ,... are prime
numbers.
The RSA algorithm is based on the mathematical fact that it is easy to find and multiply large
prime numbers together, but it is extremely difficult to factor their product. The private and
public keys in RSA are based on very large (made up of 100 or more digits) prime numbers.
The RSA Algorithm
2. Calculate N = P x Q.
Select the public key (i.e. the encryption key) E such that it is not a factor of (P-1) and (Q - 1).
4. Select the private key (i.e. the decryption key) D such that the following equation is true:
(D × E) mod (P - 1) x (Q - 1) = 1
5. For encryption, calculate the cipher text CT from the plain text PT as follows:
CT = PTE mod N
7. For decryption, calculate the plain text PT from the cipher text CT as follows:
PT = CTD mod N
Example of RSA
Let us take an example of this process to understand the concepts. For ease of reading, we shall
write the example values along with the algorithm steps.
2. Calculate N = P X Q.
We have, N = 7 x 17 = 119.
3. Select the public key (i.e. the encryption key) E such that it is not a factor of (P - 1) x (Q - 1).
4. Select the private key (i.e. the decryption key) D such that the following equation is true:
(D x E) mod (P-1) x (Q - 1) = 1
5. 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.
7. For decryption, calculate the plain text PT from the cipher text CT as follows:
PT = CTD mod N
Description of the Algorithm Let us assume that Alice and Bob want to agree upon a key to be used
for encrypting/decrypting messages that would be exchanged between them.
1. Firstly, Alice and Bob agree on two large prime numbers, n and g. These two integers need not be
kept secret. Alice and Bob can use an insecure channel to agree on them.
2. Alice chooses another large random number x, and calculates A such that:
A=gx mod n
4. Bob independently chooses another large random integer y and calculates B such that:
B=gy mod n
K1=Bx mod n
K2=Ay mod n
1. Firstly, Alice and Bob agree on two large prime numbers, n and g. These two integers need
not be kept secret. Alice and Bob can use an insecure channel to agree on them.
2.Alice chooses another large random number x, and calculates A such that:
4. Bob independently chooses another large random integer y and calculates B such that:
B=gy mod n
K1=Bx mod n
K2=AY mod n
AUTHENTICATION FUNCTIONS
A mechanism of source used to notify the integrity of messages
Assures the data required are exactly are sent i.e. no modification, no deletion or no
insertion.
When hash function is used to provide message authentication the hash function value
is often as a message digest
Message Authentication code (MAC):- The function of message, secret key that
produces a fixed length value that serves as that authenticator.
Hash Function: - A function that maps a message of any length into fixed length hash
value which serves as the authenticator.
MESSAGE AUTHENTICATION CODE (MAC)
An alternative authentication technique involves the use of a secret key to generate a
small fixed-size block of data, known as a cryptographic checksum or MAC, that is
appended to the message. This technique assumes that two communicating parties, say
A and B, share a common secret key K. When A has a message to send to B, it calculates
the MAC as a function of the message and the key:
MAC = MAC(K,M)
Where,
M= input message
C= MAC function
The message plus MAC are transmitted to the intended recipient. The recipient per-
forms the same calculation on the received message, using the same secret key,
to generate a new MAC. The received MAC is compared to the calculated MAC. If we
assume that only the receiver and the sender know the identity of the secret key, and if
the received MAC matches the calculated MAC, then
1. The receiver is assured that the message has not been altered. If an attacker alters
the message but does not alter the MAC, then the receiver’s calculation of the MAC will
differ from the received MAC. Because the attacker is respond to the alterations in the
message. Assumed not to know the secret key, the attacker cannot alter the MAC to
correspond to the alterations in the message.
2. The receiver is assured that the message is from the alleged sender.
3. If the message includes a sequence number (such as is used with HDLC, X.25, attacker
cannot successfully alter the sequence number. and TCP), then the receiver can be
assured of the proper sequence because an attacker cannot successfully alter the
sequence number.
A MAC function is similar to encryption. One difference is that the MAC algorithm
need not be reversible, as it must be for decryption. In general, the MAC function is a
many-to-one function. The domain of the function consists of messages of some
arbitrary length.
For example, suppose that we are using 100-bit messages and a 10-bit MAC. Then, there
are a total of 2100 different messages but only 210 different MACs. So, on average, each
MAC value is generated by a total of 2100/210 = 290 different messages. If a 5-bit key is
used, then there are 25 =32 different mappings from the set of messages to the set of
MAC values.
HASH FUNCTIONS
A hash function maps a variable-length message into a fixed-length hash value, or
message digest.
Virtually all cryptographic hash functions involve the iterative use of a compression
function.
The compression function used in secure hash algorithms falls into one of two
categories: a function specifically designed for the hash function or an algorithm based
on a symmetric block cipher. SHA and Whirlpool are examples of these two approaches,
respectively.
A hash function H accepts a variable-length block of data M as input and produces a fixed-size
hash value h = H(M). A “good” hash function has the property that the results of applying the
function to a large set of inputs will produce outputs that are evenly distributed and apparently
random. In general terms, the principal object of á hash function is data integrity.
Typically, the input is padded out to an integer multiple of some fixed length (e.g., 1024 bits),
and the padding includes the value of the length of the original message in bits. The length field
is a security measure to increase the difficulty for an attacker to produce an alternative
message with the same hash value.
Message Authentication
b. Only the hash code is encrypted, using symmetric encryption. This reduces the processing
burden for those applications that do not require confidentiality.
c. It is possible to use a hash function but no encryption for message authentication. The
technique assumes that the two communicating parties share a common secret value S. A
computes the hash value over the concatenation of M and S and appends the resulting hash
value to M. Because B possesses S, it can recomputed the hash value to verify. Because the
secret value itself is not sent, an opponent cannot modify an intercepted message and cannot
generate a false message.
d. Confidentiality can be added to the approach of method (c) by encrypting the entire message
plus the hash code.
Message authentication is achieved using a message authentication code (MAC), also known as
a keyed hash function. Typically, MACS are used between two parties that share a secret key to
authenticate information exchanged between those parties. A MAC function takes as input a
secret key and a data block and produces a hash value, referred to as the MAC. This can then be
transmitted with or stored with the protected message. If the integrity of the message needs to
be checked, the MAC function can be applied to the message and the result compared with the
stored MAC value. An attacker who alters the message will be unable to alter the MAC value
without knowledge of the secret key.
In fact, a MAC, that is, E(K, H(M)) is a function of a variable-length message M and a secret key
K, and it produces a fixed-size output that is secure against an opponent who does not know
the secret key.
Half Function
Half value is a fixed length value that uniquely identifies the data.
The following figure i.e. E(K, H(M)) is a function of a variable length message M and secret key K and
produces a fixed size output.
s
M iI M H
I
1 K Compare
1
E(K,H(M)) D
H E
MD5 ALGORITHM
Original number is 7391743
Operation Result
Multiply 7 by 3 21
Multiply 1 by 9 9
Multiply 9 by 1 9
Multiply 9 by 7 63
Multiply 3 by 4 12
Multiply 2 by 3 6
Example of message digest
7391753. Then, we multiply each digit in the number with the next digit (excluding it if it is
0) and disregarding the first digit of the multiplication operation, if the result is a two-digit
number.
1. It should be a one way function. That means given the message it should be easy to find out
its digest, and the reverse should be impossible.(getting back the message from its digest must
be infeasible)
2. No two different messages should produce a same digest. This requirement is stated as
collision free property.
MD5
MD 5 is a message digest algorithm developed by Ron Rivest. MD5 is quite fast and produces
128-bit message digests. Over the years, researchers have developed potential weaknesses in
MDS. However, so far, MD5 has been able to successfully defend itself against collisions. This
may not be guaranteed for too long, though.
After some initial processing, the input text is processed in 512-bit blocks (which are further
divided into 16 32-bit sub-blocks). The output of the algorithm is a set of four 32-bit blocks.
Which make up the 128-bit message digest.
Step 1: Padding: The first step in MD5 is to add padding bits to the original message. The aim of
this step is to make the length of the original message equal to a value, which is 64 bits less
than an exact multiple of 512. For example, if the length of the original message is 1000 bits, we
add a padding of 472 bits to make the length of the message 1472 bits. This is because, if we
add 64 to 1472, we get 1536, which is a multiple of 512 (because 1536 = 512 x 3).
Thus, after padding, the original message will have a length of 448 bits (64 bits less than 512),
960 bits (64 bits less than 1024), 1472 bits (64 bits less than 1536), etc. The padding consists of
a single 1-bit, followed by as many 0-bits, as required. Note that padding is always added, even
if the message length is already 64 bits less than a multiple of 512. Thus, if the message were
already of length say 448 bits, we will add a padding of 512 bits to make its length 960 bits.
Thus, the padding length is any value between 1 and 512.
Step 2: Append length after padding bits are added, the next step is to calculate the original
length of the message and add it to the end of the message, after padding. The length of the
message is calculated, excluding the padding bits. This length of the original message is now
expressed as a 64-bit value and these 64 bits are appended to the end of the original message +
padding.
Step 3: Divide the input into 512-bit blocks Now, we divide the input message into blocks, each
of length 512 bits.
Step 4: Initialize chaining variables In this step, four variables (called as chaining variables) are
initialized. They are called as A, B, C and D. Each of these is a 32-bit number. The initial
hexadecimal values of these chaining variables are shown below.
ep 5: Process blocks:
Copy the four chaining variables into four corresponding variables, a, b, c and d. After all the
initializations, the real algorithm begins. There is a loop that runs for as many 512-bit blocks as
are in the message. Now, we have four rounds. In each round, we process all the 16 sub-blocks
belonging to a block. The inputs to each round are: (a) all the 16 sub- blocks, (b) the variables a,
b, c, d and (c) some constants, designated as t.
All the four rounds vary in one major way: Step 1 of the four rounds has different
processing. The other steps in all the four rounds are the same. In each round, we have 16 input
sub-blocks, named M[0], M[1],..., M[15] or in general, M[i], where i varies from 0 to 15. As we
know, each sub-block consists of 32 bits.
1. A process P is first performed on b, c and d. This process P is different in all the four
rounds.
2. The variable a is added to the output of the process P (i.e. to the register abcd).
3. The message sub-block M[i] is added to the output of Step 2 (i.e. to the register abcd).
4. The constant t[k] is added to the output of Step 3 (i.e. to the register abcd).
5. The output of Step 4 (i.e. the contents of register abcd) is circular-left shifted by s bits.
6. The variable b is added to the output of Step 5 (i.e. to the register abcd).
7. The output of Step 6 becomes the new abcd for the next step.
SECURITY OF HASH FUNCTIONS AND MAC
Introduction:
We can group attacks on the basis of hash functions and MACs: brute-force attacks and
cryptanalysis.
Brute-Force Attacks: The nature of brute-force attacks differs somewhat for hash functions and
MACs.
Hash Functions:-The strength of a hash function against brute-force attacks depends on the
length of the hash code produced by the algorithm. There are three desirable properties:
One-way: For any given code h, it is computationally infeasible to find x such that H(x) = h.
Weak collision resistance: For any given block x, it is computationally infeasible to find y ≠x
with H(y) = H(x).
Strong collision resistance: It is computationally infeasible to find any pair (x, y) such that
H(x) = H(y).
For a hash code of length n, the level of effort required, as we have seen is proportional to the
following:
If strong collision resistance is required, then the value 2n/2 determines the strength of the hash
code against brute-force attacks. Thus a 128-bit code may be viewed as inadequate. The next
step up, if a hash code is treated as a sequence of 32 bits, is a 160-bit hash length. With a hash
length of 160 bits, the same search machine would require over four thousand years to find a
collision. However, even 160 bits is now considered weak.
To proceed, we need to state the desired security property of a MAC algorithm, which can be
expressed as follows:
Computation resistance: Given one or more text-MAC pairs [xi, C(K, xi)], it is computationally
infeasible to compute any text-MAC pair [x, C(K, x)] for any new input x ≠ x i.In other words, the
attacker would like to come up with the valid MAC code for a given message x. There are two
lines of attack possible: Attack the key space and attack the MAC value.
Hash Functions:-In past few years there has been considerable effort, and some successes, in
developing cryptanalytic attacks on hash functions. To understand these, we need to look at
the overall structure of a typical secure hash function, This structure, referred to as an iterated
hash function and is the structure of most hash functions in use today, including SHA and
Whirlpool. The hash function takes an input message and partitions it into L fixed-sized blocks
of b bits each. If necessary, the final block is padded to b bits. The final block also includes the
value of the total length of the input to the hash function. The inclusion of the length makes the
job of the opponent more difficult.
Message Authentication Codes:-There is much more variety in the structure of MACs than in
hash functions, so it is difficult to generalize about the cryptanalysis of MACs. Far less work has
been done on developing such attacks.
SHA-1 produces a hash value of 160 bits, In 2002, NIST produced a revised version of the
standard, With hash value lengths of 256, 384, and 512 bits, known as SHA-256, SHA-384, and
SHA 512, respectively. Structure and use the same types of modular arithmetic and logical
binary operations as SHA-1.A revised document Was issued as FIP PUB 180-3 in 2008, which
added a 224-bit version.
SHA-512 Logic
The algorithm takes as input a message with a maximum length of less than 2 128 bits and
produces as output a 512-bit message digest. The input is processed in 1024-bit blocks.
Comparison of SHA parameters:
Step 1: Append padding bits. The message is padded so that its length is congruent to 896
modulo 1024 [length = 896(mod 1024)]. Padding is always added, even if the message is already
of the desired length. Thus, the number of bit followed by the necessary number of 0 bits.
Padding bits is in the range of 1 to 1024.
Step 2: Append length. A block of 128 bits is appended to the message. This block is treated as
an unsigned 128-bit integer and contains the length of original message.
Step 3: Initialize hash buffer. A 512-bit buffer is used to hold intermediate and final results of
the hash function. These values are stored in big-endian format, which is the most significant
byte of a word in the low-address (leftmost) byte position. These words were obtained by
taking the first sixty-four bits of the fractional parts of the square roots of the first eight prime
numbers.
Step 4: Process message in 1024-bit (128-word) blocks. The heart of the algorithm is a module
that consists of 80 rounds this module is labeled F. Each round takes as input the 512-bit buffer
value, abcdefgh, and updates the contents of the buffer. At input to the first round, the buffer
has the value of the intermediate hash value, H-1. Each round t makes use of a 64-bit value W1,
derived from the current.
HMAC
HMAC stands for Hash-based Message Authentication Code. HMAC has been chosen as a
mandatory security implementation for the Internet Protocol (IP) security and is also used in
the Secure Socket Layer (SSL) protocol, widely used on the Internet. The fundamental idea
behind HMAC is to reuse the existing message digest algorithms, such as MD5 or SHA-1.It treats
the message digest as a black box. Additionally, it uses the shared symmetric key to encrypt the
message digest, which produces the output MAC. This is shown in figure below.
Let us now take a look at the internal working of HMAC. For this, let us start with the various
variables that will be used in our HMAC discussion. MD - The message digest/hash function
used (e.g. MD5, SHA-1, etc.) M= The input message whose MAC is to be calculated L = The
number of blocks in the message Mb = The number of bits in each block K = The shared
symmetric key to be used in HMAC ipad = A string 00110110 repeated b/8 times opad - A string
01011010 repeated b/8 times.
Step 1: Make the length of k equal to b.
Step 2: XOR K with ipad to produce S1 We XOR K (the output of Step 1) and ipad to produce a
variable called as $1.
Step 3: Append M to SI we now take the original message (M) and simply append it to the end
of S1 (which was calculated in Step 2).
Step 4: Message digest algorithm Now, the selected message digest algorithm (e.g. MD5. SHA-
1, etc) is applied to the output of Step 3 (i.e. to the combination of S1 and M). Let us call the
output of this operation as H.
Step 5: XOR K with opad to produce S2 Now, we XOR K (the output of Step 1) with opad to
produce a variable called as $2.
Step 6: Append H to S2 In this step, we take the message digest calculated in step 4 (i.e. H) and
simply append it to the end of $2 (which was calculated in Step 5).
Step 7: Message digest algorithm Now, the selected message digest algorithm (e.g. MD5. SHA-
1, etc) is applied to the output of Step 6 (i.e. to the concatenation of S2 and H). This is the final
MAC that we want.
Complete HMAC Operation
***************************************