# Message authentication code

> Mediated Wiki article. Canonical URL: https://mediated.wiki/source/Message_authentication_code
> Markdown URL: https://mediated.wiki/source/Message_authentication_code.md
> Source: https://en.wikipedia.org/wiki/Message_authentication_code
> Source revision: 1354881562
> License: Creative Commons Attribution-ShareAlike 4.0 International (https://creativecommons.org/licenses/by-sa/4.0/)

Information used for message authentication and integrity checking

In [cryptography](/source/Cryptography), a **message authentication code** (**MAC**), sometimes known as an **authentication tag**, is a short piece of information used for [authenticating](/source/Authentication) and [integrity](/source/Data_integrity)-checking a message. In other words, it is used to confirm that the message came from the stated sender (its authenticity) and has not been changed (its integrity). The MAC value allows verifiers (who also possess a secret key) to detect any changes to the message content.

## Terminology

The term **message integrity code** (**MIC**) is frequently substituted for the term *MAC*, especially in communications[1] to distinguish it from the use of the latter as *[Media Access Control address](/source/MAC_address)* (*MAC address*). However, some authors[2] use MIC to refer to a [message digest](/source/Message_digest), which aims only to uniquely but opaquely identify a single message. As such, it is recommended to avoid the term *message integrity code* (MIC), and instead use *[checksum](/source/Checksum)*, *[error detection code](/source/Error_detection_code)*, *[hash](/source/Hash_function)*, *keyed hash*, *message authentication code*, or *protected checksum*.[3]

## Definitions

Informally, a message authentication code system consists of three algorithms:

- A [key generation](/source/Key_generation) algorithm selects a key from the key space uniformly at random.

- A MAC generation algorithm efficiently returns a tag given the key and the message.

- A verifying algorithm efficiently verifies the authenticity of the message given the same key and the tag. That is, return *accepted* when the message and tag are not tampered with or forged, and otherwise return *rejected*.

A secure message authentication code must resist attempts by an adversary to [forge tags, for arbitrary, selected, or all messages](/source/Digital_signature_forgery), including under conditions of [known-](/source/Digital_signature_forgery) or [chosen-message](/source/Digital_signature_forgery). It should be computationally infeasible to compute a valid tag of the given message without knowledge of the key, even if for the worst case, we assume the adversary knows the tag of any message but the one in question.[4]

Formally, a **message authentication code** (**MAC**) system is a triple of efficient[5] algorithms (*G*, *S*, *V*) satisfying:

- *G* (key-generator) gives the key *k* on input [1*n*](/source/Unary_numeral_system), where *n* is the [security parameter](/source/Security_parameter).

- *S* (signing) outputs a tag *t* on the key *k* and the input string *x*.

- *V* (verifying) outputs *accepted* or *rejected* on inputs: the key *k*, the string *x* and the tag *t*.

*S* and *V* must satisfy the following:

- Pr [ *k* ← *G*(1*n*), *V*( *k*, *x*, *S*(*k*, *x*) ) = *accepted* ] = 1.[6]

A MAC is **unforgeable** if for every efficient adversary *A*

- Pr [ *k* ← *G*(1*n*), (*x*, *t*) ← *A**S*(*k*, · )(1*n*), *x* ∉ Query(*A**S*(*k*, · ), 1*n*), *V*(*k*, *x*, *t*) = *accepted*] < negl(*n*),

where *A**S*(*k*, · ) denotes that *A* has access to the oracle *S*(*k*, · ), and Query(*A**S*(*k*, · ), 1*n*) denotes the set of the queries on *S* made by *A*, which knows *n*. Clearly we require that any adversary cannot directly query the string *x* on *S*, since otherwise a valid tag can be easily obtained by that adversary.[7]

## Security

While MAC functions are similar to [cryptographic hash functions](/source/Cryptographic_hash_function), they possess different security requirements. To be considered secure, a MAC function must resist [existential forgery](/source/Existential_forgery) under [chosen-message attacks](/source/Digital_signature_forgery). This means that even if an attacker has access to an [oracle](/source/Oracle_machine) which possesses the secret key and generates MACs for messages of the attacker's choosing, the attacker cannot guess the MAC for other messages (which were not used to query the oracle) without performing infeasible amounts of computation.

MACs differ from [digital signatures](/source/Digital_signature) as MAC values are both generated and verified using the same secret key. This implies that the sender and receiver of a message must agree on the same key before initiating communications, as is the case with [symmetric encryption](/source/Symmetric_encryption). For the same reason, MACs do not provide the property of [non-repudiation](/source/Non-repudiation) offered by signatures specifically in the case of a network-wide [shared secret](/source/Shared_secret) key: any user who can verify a MAC is also capable of generating MACs for other messages. In contrast, a digital signature is generated using the private key of a key pair, which is public-key cryptography.[5] Since this private key is only accessible to its holder, a digital signature proves that a document was signed by none other than that holder. Thus, digital signatures do offer non-repudiation. However, non-repudiation can be provided by systems that securely bind key usage information to the MAC key; the same key is in the possession of two people, but one has a copy of the key that can be used for MAC generation while the other has a copy of the key in a [hardware security module](/source/Hardware_security_module) that only permits MAC verification. This is commonly done in the finance industry.[*[citation needed](https://en.wikipedia.org/wiki/Wikipedia:Citation_needed)*]

See also: [Key commitment](/source/Key_commitment)

While the primary goal of a MAC is to prevent forgery by adversaries without knowledge of the secret key, this is insufficient in certain scenarios. When an adversary is able to control the MAC key, stronger guarantees are needed, akin to [collision resistance](/source/Collision_resistance) or [preimage security](/source/Preimage_attack) in hash functions. For MACs, these concepts are known as *commitment* and *context-discovery* security.[8]

## Implementation

MAC algorithms can be constructed from other cryptographic primitives, like [cryptographic hash functions](/source/Cryptographic_hash_function) (as in the case of [HMAC](/source/HMAC)) or from [block cipher](/source/Block_cipher) algorithms ([OMAC](/source/OMAC_(cryptography)), [CCM](/source/CCM_mode), [GCM](/source/Galois%2FCounter_mode), and [PMAC](/source/PMAC_(cryptography))). However many of the fastest MAC algorithms, like [UMAC](/source/UMAC_(cryptography))-[VMAC](/source/VMAC) and [Poly1305-AES](/source/Poly1305-AES), are constructed based on [universal hashing](/source/Universal_hashing).[9]

Intrinsically keyed hash algorithms such as [SipHash](/source/SipHash) are also by definition MACs; they can be even faster than universal-hashing based MACs.[10]

Additionally, the MAC algorithm can deliberately combine two or more cryptographic primitives, so as to maintain protection even if one of them is later found to be vulnerable. For instance, in [Transport Layer Security](/source/Transport_Layer_Security) (TLS) versions before 1.2, the [input data](/source/Input_data) is split in halves that are each processed with a different hashing primitive ([SHA-1](/source/SHA-1) and [SHA-2](/source/SHA-2)) then [XORed](/source/Exclusive_or) together to output the MAC.

### One-time MAC

[Universal hashing](/source/Universal_hashing) and in particular [pairwise independent](/source/Pairwise_independent) hash functions provide a secure message authentication code as long as the key is used at most once. This can be seen as the [one-time pad](/source/One-time_pad) for authentication.[11]

The simplest such pairwise independent hash function is defined by the random key, *key* = (*a*, *b*), and the MAC tag for a message *m* is computed as *tag* = (*am* + *b*) mod *p*, where *p* is prime.

More generally, [*k*-independent hashing](/source/K-independent_hashing) functions provide a secure message authentication code as long as the key is used less than *k* times for *k*-ways independent hashing functions.

Message authentication codes and data origin authentication have been also discussed in the framework of [quantum cryptography](/source/Quantum_cryptography). By contrast to other cryptographic tasks, such as key distribution, for a rather broad class of quantum MACs it has been shown that quantum resources do not offer any advantage over unconditionally secure one-time classical MACs.[12]

## Standards

Various standards exist that define MAC algorithms. These include:

- FIPS PUB 113 *Computer Data Authentication*,[13] withdrawn in 2002,[14] defines an algorithm based on [DES](/source/Data_Encryption_Standard).

- FIPS PUB 198-1 *The Keyed-Hash Message Authentication Code (HMAC)*[15]

- NIST SP800-185 *SHA-3 Derived Functions: cSHAKE, KMAC, TupleHash, and ParallelHash*[16]

- [ISO/IEC 9797-1](/source/ISO%2FIEC_9797-1) *Mechanisms using a block cipher*[17]

- [ISO](/source/International_Organization_for_Standardization)/IEC 9797-2 *Mechanisms using a dedicated hash-function*[18]

- [ISO](/source/International_Organization_for_Standardization)/IEC 9797-3 *Mechanisms using a universal hash-function*[19]

- [ISO](/source/International_Organization_for_Standardization)/IEC 29192-6 *Lightweight cryptography - Message authentication codes*[20]

ISO/IEC 9797-1 and -2 define generic models and algorithms that can be used with any block cipher or hash function, and a variety of different parameters. These models and parameters allow more specific algorithms to be defined by nominating the parameters. For example, the FIPS PUB 113 algorithm is functionally equivalent to ISO/IEC 9797-1 MAC algorithm 1 with padding method 1 and a block cipher algorithm of DES.

## An example of MAC use

[21] In this example, the sender of a message runs it through a MAC algorithm to produce a MAC data tag. The message and the MAC tag are then sent to the receiver. The receiver in turn runs the message portion of the transmission through the same MAC algorithm using the same key, producing a second MAC data tag. The receiver then compares the first MAC tag received in the transmission to the second generated MAC tag. If they are identical, the receiver can safely assume that the message was not altered or tampered with during transmission ([data integrity](/source/Data_integrity)).

However, to allow the receiver to be able to detect [replay attacks](/source/Replay_attack), the message itself must contain data that assures that this same message can only be sent once (e.g. time stamp, [sequence number](/source/Cryptographic_nonce) or use of a [one-time MAC](#One-time_MAC)). Otherwise an attacker could – without even understanding its content – record this message and play it back at a later time, producing the same result as the original sender.

## See also

- [Checksum](/source/Checksum)

- [CMAC](/source/CMAC)

- [HMAC](/source/HMAC) (hash-based message authentication code)

- [MAA](/source/Message_Authenticator_Algorithm)

- [MMH-Badger MAC](/source/MMH-Badger_MAC)

- [Poly1305](/source/Poly1305)

- [Authenticated encryption](/source/Authenticated_encryption)

- [UMAC](/source/UMAC_(cryptography))

- [VMAC](/source/VMAC)

- [SipHash](/source/SipHash)

- [KMAC](/source/SHA-3#Additional_instances)

## Notes

1. **[^](#cite_ref-1)** [*IEEE Standard for Information Technology - Telecommunications and Information Exchange Between Systems - Local and Metropolitan Area Networks - Specific Requirements - Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications*](https://web.archive.org/web/20081013101112/http://standards.ieee.org/getieee802/download/802.11-2007.pdf) (PDF). (2007 revision). [IEEE-SA](/source/IEEE-SA). 12 June 2007. [doi](/source/Doi_(identifier)):[10.1109/IEEESTD.2007.373646](https://doi.org/10.1109%2FIEEESTD.2007.373646). [ISBN](/source/ISBN_(identifier)) [978-0-7381-5656-9](https://en.wikipedia.org/wiki/Special:BookSources/978-0-7381-5656-9). Archived from [the original](http://standards.ieee.org/getieee802/download/802.11-2007.pdf) (PDF) on 13 October 2008.

1. **[^](#cite_ref-2)** ["CS 513 System Security -- Hashes and Message Digests"](https://www.cs.cornell.edu/courses/cs513/2005fa/NL20.hashing.html). *www.cs.cornell.edu*. Retrieved 20 December 2023.

1. **[^](#cite_ref-rfc4949_3-0)** R. Shirey (August 2007). [*Internet Security Glossary, Version 2*](https://www.rfc-editor.org/rfc/rfc4949). Network Working Group. [doi](/source/Doi_(identifier)):[10.17487/RFC4949](https://doi.org/10.17487%2FRFC4949). [RFC](/source/Request_for_Comments) [4949](https://datatracker.ietf.org/doc/html/rfc4949). *Informational.* Obsoletes RFC [2828](https://www.rfc-editor.org/rfc/rfc2828).

1. **[^](#cite_ref-4)** The strongest adversary is assumed to have access to the signing algorithm without knowing the key. However, her final forged message must be different from any message she chose to query the signing algorithm before. See Pass's discussions before def 134.2.

1. ^ [***a***](#cite_ref-:1_5-0) [***b***](#cite_ref-:1_5-1) Theoretically, an efficient algorithm runs within probabilistic polynomial time.

1. **[^](#cite_ref-6)** Pass, def 134.1

1. **[^](#cite_ref-7)** Pass, def 134.2

1. **[^](#cite_ref-8)** Bhaumik, Ritam; Chakraborty, Bishwajit; Choi, Wonseok; Dutta, Avijit; Govinden, Jérôme; Shen, Yaobin (2024). ["The Committing Security of MACs with Applications to Generic Composition"](https://link.springer.com/chapter/10.1007/978-3-031-68385-5_14). In Reyzin, Leonid; Stebila, Douglas (eds.). *Advances in Cryptology – CRYPTO 2024*. Lecture Notes in Computer Science. Vol. 14923. Cham: Springer Nature Switzerland. pp. 425–462. [doi](/source/Doi_(identifier)):[10.1007/978-3-031-68385-5_14](https://doi.org/10.1007%2F978-3-031-68385-5_14). [ISBN](/source/ISBN_(identifier)) [978-3-031-68385-5](https://en.wikipedia.org/wiki/Special:BookSources/978-3-031-68385-5).

1. **[^](#cite_ref-9)** ["VMAC: Message Authentication Code using Universal Hashing"](http://www.fastcrypto.org/vmac/draft-krovetz-vmac-01.txt). *CFRG Working Group*. Retrieved 16 March 2010.

1. **[^](#cite_ref-SipHash_10-0)** Jean-Philippe Aumasson & [Daniel J. Bernstein](/source/Daniel_J._Bernstein) (18 September 2012). ["SipHash: a fast short-input PRF"](https://131002.net/siphash/siphash.pdf) (PDF).

1. **[^](#cite_ref-:0_11-0)** [Simmons, Gustavus](/source/Gustavus_Simmons) (1985). "Authentication theory/coding theory". *Advances in Cryptology – Proceedings of CRYPTO 84*. Berlin: Springer. pp. 411–431.

1. **[^](#cite_ref-12)** Nikolopoulos, Georgios M.; Fischlin, Marc (2020). ["Information-Theoretically Secure Data Origin Authentication with Quantum and Classical Resources"](https://doi.org/10.3390%2Fcryptography4040031). *Cryptography*. **4** (4): 31. [arXiv](/source/ArXiv_(identifier)):[2011.06849](https://arxiv.org/abs/2011.06849). [doi](/source/Doi_(identifier)):[10.3390/cryptography4040031](https://doi.org/10.3390%2Fcryptography4040031). [S2CID](/source/S2CID_(identifier)) [226956062](https://api.semanticscholar.org/CorpusID:226956062).

1. **[^](#cite_ref-13)** ["FIPS PUB 113 *Computer Data Authentication*"](https://web.archive.org/web/20110927022556/http://www.itl.nist.gov/fipspubs/fip113.htm). Archived from [the original](http://www.itl.nist.gov/fipspubs/fip113.htm) on 27 September 2011. Retrieved 10 October 2010.

1. **[^](#cite_ref-14)** ["Federal Information Processing Standards Publications, Withdrawn FIPS Listed by Number"](https://web.archive.org/web/20100801020458/http://www.itl.nist.gov/fipspubs/withdraw.htm). Archived from [the original](http://www.itl.nist.gov/fipspubs/withdraw.htm) on 1 August 2010. Retrieved 10 October 2010.

1. **[^](#cite_ref-15)** ["*The Keyed-Hash Message Authentication Code (HMAC)*"](http://csrc.nist.gov/publications/fips/fips198-1/FIPS-198-1_final.pdf) (PDF). Retrieved 20 December 2023.

1. **[^](#cite_ref-16)** [SHA-3 Derived Functions](https://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-185.pdf) nvlpubs.nist.gov

1. **[^](#cite_ref-17)** ["ISO/IEC 9797-1:2011"](https://www.iso.org/standard/50375.html). *ISO*. Retrieved 20 December 2023.

1. **[^](#cite_ref-18)** ["ISO/IEC 9797-2:2011"](https://www.iso.org/standard/51618.html). *ISO*. Retrieved 20 December 2023.

1. **[^](#cite_ref-19)** ["ISO/IEC 9797-3:2011"](https://www.iso.org/standard/51619.html). *ISO*. Retrieved 20 December 2023.

1. **[^](#cite_ref-20)** ["ISO/IEC 29192-6:2019"](https://www.iso.org/standard/71116.html). *ISO*. Retrieved 20 December 2023.

1. **[^](#cite_ref-21)** "Mac Security Overview", *Mac® Security Bible*, Wiley Publishing, Inc., 1 November 2011, pp. 1–26, [doi](/source/Doi_(identifier)):[10.1002/9781118257739.ch1](https://doi.org/10.1002%2F9781118257739.ch1), [ISBN](/source/ISBN_(identifier)) [9781118257739](https://en.wikipedia.org/wiki/Special:BookSources/9781118257739)

## References

- Goldreich, Oded (2001), *Foundations of cryptography I: Basic Tools*, Cambridge: Cambridge University Press, [ISBN](/source/ISBN_(identifier)) [978-0-511-54689-1](https://en.wikipedia.org/wiki/Special:BookSources/978-0-511-54689-1)

- Goldreich, Oded (2004), *Foundations of cryptography II: Basic Applications* (1. publ. ed.), Cambridge [u.a.]: Cambridge Univ. Press, [ISBN](/source/ISBN_(identifier)) [978-0-521-83084-3](https://en.wikipedia.org/wiki/Special:BookSources/978-0-521-83084-3)

- Pass, Rafael, [*A Course in Cryptography*](https://www.cs.cornell.edu/courses/cs4830/2010fa/lecnotes.pdf) (PDF), retrieved 31 December 2015[1]

## External links

- [RSA Laboratories entry on MACs](https://web.archive.org/web/20061020212439/http://www.rsasecurity.com/rsalabs/node.asp?id=2177)

- [Ron Rivest lecture on MACs](http://web.mit.edu/6.857/OldStuff/Fall97/lectures/lecture3.pdf)

v t e Cryptographic hash functions and message authentication codes List Comparison Known attacks Common functions MD5 (compromised) SHA-1 (compromised) SHA-2 SHA-3 BLAKE2 SHA-3 finalists BLAKE Grøstl JH Skein Keccak (winner) Other functions BLAKE3 CubeHash ECOH FSB Fugue GOST HAS-160 HAVAL Kupyna LSH Lane MASH-1 MASH-2 MD2 MD4 MD6 MDC-2 N-hash RIPEMD RadioGatún SIMD SM3 SWIFFT Shabal Snefru Streebog Tiger VSH Whirlpool Password hashing/ key stretching functions Argon2 Balloon bcrypt Catena crypt LM hash Lyra2 Makwa PBKDF2 scrypt yescrypt General purpose key derivation functions HKDF KDF1/KDF2 MAC functions CBC-MAC DAA GMAC HMAC NMAC OMAC/CMAC PMAC Poly1305 SipHash UMAC VMAC Authenticated encryption modes CCM ChaCha20-Poly1305 CWC EAX GCM IAPM OCB Attacks Collision attack Preimage attack Birthday attack Brute-force attack Rainbow table Side-channel attack Length extension attack Design Avalanche effect Hash collision Merkle–Damgård construction Sponge function HAIFA construction Standardization CAESAR Competition CRYPTREC NESSIE NIST hash function competition Password Hashing Competition NSA Suite B CNSA Utilization Hash-based cryptography Merkle tree Message authentication Proof of work Salt Pepper v t e Cryptography General History of cryptography Outline of cryptography Classical cipher Cryptographic protocol Authentication protocol Cryptographic primitive Cryptanalysis Cryptocurrency Cryptosystem Cryptographic nonce Cryptovirology Hash function Cryptographic hash function Key derivation function Secure Hash Algorithms Digital signature Kleptography Key (cryptography) Key exchange Key generator Key schedule Key stretching Keygen Machines Ransomware Random number generation Cryptographically secure pseudorandom number generator (CSPRNG) Pseudorandom noise (PRN) Secure channel Insecure channel Subliminal channel Encryption Decryption End-to-end encryption Harvest now, decrypt later Information-theoretic security Plaintext Codetext Ciphertext Shared secret Trapdoor function Trusted timestamping Key-based routing Onion routing Garlic routing Kademlia Mix network Mathematics Cryptographic hash function Block cipher Stream cipher Symmetric-key algorithm Authenticated encryption Public-key cryptography Quantum key distribution Quantum cryptography Post-quantum cryptography Message authentication code Random numbers Steganography Category

Authority control databases GND

1. **[^](#cite_ref-22)** 11-12-20C8

---
Adapted from the Wikipedia article [Message authentication code](https://en.wikipedia.org/wiki/Message_authentication_code) by Wikipedia contributors ([contributor history](https://en.wikipedia.org/wiki/Message_authentication_code?action=history)). Available under [Creative Commons Attribution-ShareAlike 4.0 International](https://creativecommons.org/licenses/by-sa/4.0/). Changes may have been made.
