3 Message authentication codes

 

This chapter covers

  • Message authentication codes (MACs)
  • The security properties and the pitfalls of MACs
  • The widely adopted standards for MACs

Mix a hash function with a secret key and you obtain something called a message authentication code (MAC), a cryptographic primitive to protect the integrity of data. The addition of a secret key is the foundation behind any type of security: without keys there can be no confidentiality, and there can be no authentication. While hash functions can provide authentication or integrity for arbitrary data, they do that thanks to an additional trusted channel that cannot be tampered with. In this chapter, you will see how a MAC can be used to create such a trusted channel and what else it can do as well.

Note

For this chapter, you’ll need to have read chapter 2 on hash functions.

3.1 Stateless cookies, a motivating example for MACs

Let’s picture the following scenario: you are a web page. You’re bright, full of colors, and above all, you’re proud of serving a community of loyal users. To interact with you, visitors must first log in by sending you their credentials, which you must then validate. If the credentials match the ones that were used when the user first signed up, then you have successfully authenticated the user.

3.2 An example in code

3.3 Security properties of a MAC

3.3.1 Forgery of authentication tag

3.3.2 Lengths of authentication tag

3.3.3 Replay attacks

3.3.4 Verifying authentication tags in constant time

3.4 MAC in the real world

3.4.1 Message authentication

3.4.2 Deriving keys

3.4.3 Integrity of cookies

3.4.4 Hash tables

3.5 Message authentication codes (MACs) in practice

3.5.1 HMAC, a hash-based MAC

sitemap