Topic 27 Simple Hash Functions
Topic 27 Simple Hash Functions
Network Security
1
Simple Hash Functions
Objectives of the Topic
• After completing this topic, a student will be able
to
– explain working of simple hash functions.
2
Simple Hash Functions
Figures and material in this topic have been
adapted from
• “Network Security Essentials : Applications and
Standards”, 2014, by William Stallings.
3
Simple Hash Functions
• A hash function accepts a variable-length block
of data M as input and produces a fixed-size hash
value h = H(M).
4
Simple Hash Functions
• 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.
5
Simple Hash Functions
• A change to any bit or bits in M results, with high
probability, in a change to the hash code.
• The principal object of a hash function is data
integrity.
6
Simple Hash Functions
Simple Hash Functions:
• All hash functions operate using the following
general principles.
• The input (message, file, etc.) is viewed as a
sequence of n-bit blocks.
7
Simple Hash Functions
• The input is processed one block at a time in an
iterative fashion to produce an n-bit hash
function.
• One of the simplest hash functions is the bit-by-
bit exclusive-OR (XOR) of every block.
8
Simple Hash Functions
• If
• Then,
9
Simple Hash Functions
Simple Hash Function Using Bitwise XOR
10
Simple Hash Functions
• This operation produces a simple parity for each
bit position and is known as a longitudinal
redundancy check.
• It is reasonably effective for random data as a
data integrity check.
11
Simple Hash Functions
• Each n-bit hash value is equally likely.
• Thus, the probability that a data error will result
in an unchanged hash value is 2-n.
• With more predictably formatted data, the
function is less effective.
12
Simple Hash Functions
• For example, in most normal text files, the high-
order bit of each octet is always zero.
• With a 128-bit hash value, effectiveness of the
hash function is reduced from 2-128 to 2-112 on this
type of data.
13
Simple Hash Functions
• A simple way to improve matters is to perform a
1-bit circular shift, or rotation, on the hash value
after each block is processed.
• The procedure can be summarized as:
14
Simple Hash Functions
• 1. Initially set the n-bit hash value to zero.
• 2. Process each successive n-bit block of data:
• a. Rotate the current hash value to the left by
one bit.
• b. XOR the block into the hash value.
15
Simple Hash Functions
• This has the effect of “randomizing” the input
more completely and overcoming any regularities
that appear in the input.
• Data security is at stake when an encrypted hash
code is used with a plaintext message.
16
Simple Hash Functions
• A technique originally proposed by the National
Bureau of Standards used the simple XOR applied
to 64-bit blocks of the message and then an
encryption of the entire message using the cipher
block chaining (CBC) mode.
17
Simple Hash Functions
• Given a message consisting of a sequence of 64-
bit blocks X1, X2, . . ., XN, define the hash code C as
the block-by-block XOR or all blocks and append
the hash code as the final block:
18
Simple Hash Functions
• Next, encrypt the entire message plus hash code
using CBC mode to produce the encrypted
message Y1, Y2, . . ., YN-1
• Ciphertext of this message can be manipulated so
that it is not detectable by the hash code.
19