07.07.2023 Views

Implementing-cryptography-using-python

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 7 ■ Message Integrity 205

# You must encode your message before it is hashed.

message = b'This is a test of the emergency broadcast system; it is only

a test.'

rd = make_digest(message)

print (rd)

The preceding code listing should produce a digest for our intended message.

Your output should look identical to the output shown in Figure 7.1.

Figure 7.1: Binary digests

NIST Compliance

In the FIPS PUB 180-4 (Federal Information Processing Standards Publication),

the National Institute of Science and Technology (NIST) outlines a secure hash

standard that can be used to generate digests of messages and specifies secure

hash algorithms: SHA-1, SHA-224, SHA-256, SHA-384, SHA-512, SHA-512/224,

and SHA-512/256. Any change to a message results in a different message digest.

NIST provides a sample zip file that contains a file named HMAC.rsp. As you

study the inner workings of hashing, you should know about a common practice

with message authentication codes, which is to truncate the tag. In the NIST

example, you may notice the TLen parameter, which is the number of bytes that

the tag truncates. The truncating may benefit some applications that require a

hash function with a message digest length different than those provided by the

hash functions. In cases such as these, a truncated tag or digest should be used,

whereby a hash function with a more considerable tag length is applied to the

data to be hashed, and the resulting message digest is truncated by selecting an

appropriate number of the leftmost bits. To learn more about the guidelines on

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!