07.07.2023 Views

Implementing-cryptography-using-python

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

60 Chapter 2 ■ Cryptographic Protocols and Perfect Secrecy

Message Authentication Codes

Hash-based Message Authentication Code (HMAC) is a key-based message

digest algorithm that can be used for verifying the integrity of the message, to

verify the authenticity of the sender of the message, or both. HMAC has been

widely adopted for use in various systems and domains, such as server-toserver

communications, Web Service APIs, etc. A well-known use of HMAC

is in Amazon’s AWS API calls where the signature is generated using HMAC.

HMAC can use a variety of hashing algorithms, like MD5, SHA1, SHA256,

etc. The HMAC function is not process intensive, so it has been widely accepted,

and it is easy to implement in mobile and embedded devices while maintaining

decent security. The following code example shows how to generate an HMAC-

MD5 digest with Python:

import hmac

from hashlib import md5

key = b'DECLARATION'

h = hmac.new(key,b'',md5)

# add content

h.update('We hold these truths to be self-evident, that all men are

created equal')

# print the HMAC digest

print (h.hexdigest())

Perfect Forward Secrecy

In our exploration of cryptography, perfect forward secrecy (PFS), also known

as forward secrecy (FS), is a set of key agreement protocols that gives the participants

in the message exchange assurances that their session keys will not be

compromised even if the private key of the server is compromised. PFS protects

past cryptographic sessions against future compromises of passwords or secret

keys. The compromise of a single session key will not affect any data other than

that exchanged in the particular session by generating a unique session key for

each individual session; PFS further protects data on the transport layer of a

network that uses common SSL/TLS protocols such as OpenSSL. In the past,

OpenSSL was affected by the Heartbleed exploit. If PFS is used, encrypted

communications and sessions recorded that may have become compromised

cannot be used to decrypt future communications.

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

Saved successfully!

Ooh no, something went wrong!