Skip to contentScholarGate
LibraryBookshelfDeskReview StudioAssistant
Sign in
On this page
IntuitionHow it worksWhen to use itStrengths & limitationsCommon pitfallsApplicationsFrequently asked🔒 Read the full methodSourcesRelated methods
Cite this pageSpotted an issue on this page? Report or suggest a fix →
Home›Cryptography›HMAC
Machine learningMessage authentication code

HMAC

Hash-Based Message Authentication Code · Also known as: HMAC, keyed hash function

HMAC (Hash-Based Message Authentication Code) is a cryptographic algorithm for authenticating messages using a secret key and a hash function. Standardized in RFC 2104 (1997), HMAC can be combined with any cryptographic hash function (SHA-256, SHA-3, etc.) to create a message authentication code (MAC). HMAC provides both data integrity and authentication, detecting both accidental corruption and deliberate tampering, and is widely used in web security (TLS/SSL), API authentication, and network protocols.

ScholarGate
  1. Machine learning
  2. v1
  3. 2 Sources
  4. PUBLISHED
Cite this page →
Tools & resources
Download slides
Learn & explore

Read the full method

Members only

Sign in with a free account to read this section.

Sign in

Method map

The neighbourhood of related methods — select a node to explore.

HMAC
AES (Rijndael)Differential Cryptanalys…RSA CryptosystemBlockchain ConsensusDeep Packet InspectionRing Signature

When to use it

HMAC is essential for message authentication in protocols where both parties share a secret key. Use HMAC when you need to verify that a message has not been modified and that it came from the authenticated source. Common applications include API authentication (signing requests with HMAC-SHA256), session management, and in TLS/SSL for additional authentication layers. HMAC is suitable for both high-speed and security-critical applications.

Strengths & limitations

Strengths
  • Provides both message integrity and authentication in a single operation
  • Simple and efficient to compute, with minimal computational overhead compared to digital signatures
  • Compatible with any underlying hash function, offering flexibility in algorithm choice
  • Theoretically proven secure if the underlying hash function behaves like a random oracle
Limitations
  • Requires secure shared key management; both sender and receiver must possess the same secret key
  • Does not provide non-repudiation; both parties can deny creating or authorizing a message
  • Vulnerable to key recovery if the underlying hash function is broken or misused
  • Timing attacks on HMAC comparison can leak information about the correct code if verification is not constant-time

Frequently asked

Why is HMAC better than just concatenating the key and message before hashing?

Simple concatenation (key || message) is vulnerable to length extension attacks. An attacker can compute HMAC(key || message || x) without knowing the key if they know the original HMAC. HMAC's nested design with separate padding prevents this attack.

How do I compare HMACs securely?

Use constant-time comparison functions (like secrets.compare_digest in Python) instead of standard string equality. This prevents timing attacks that allow an attacker to forge valid HMACs by observing how long comparison takes.

Can I use HMAC for key derivation?

HMAC alone is not a strong key derivation function. Use HKDF (HMAC-based Key Derivation Function) or PBKDF2 instead, which apply HMAC multiple times with additional randomness to generate cryptographic keys from passwords or shared secrets.

Is HMAC quantum-resistant?

HMAC's security relies on the underlying hash function. If the hash function is quantum-resistant, then HMAC is also quantum-resistant. SHA-3 and other post-quantum hash functions can be used with HMAC for future-proofing.

What hash function should I use with HMAC?

Use SHA-256 or SHA-3 for new systems. SHA-1 is deprecated for most uses. Avoid MD5. The choice depends on your security requirements and compatibility needs.

Sources

  1. Krawczyk, H., Bellare, M., & Crechanko, R. (1997). HMAC: Keyed-Hashing for Message Authentication. RFC 2104. link ↗
  2. Bellare, M., Canetti, R., & Krawczyk, H. (1996). Keying hash functions for message authentication. In Advances in Cryptology - CRYPTO 1996, LNCS 1109, pp. 1-15. DOI: 10.1007/3-540-68697-5_1 ↗

How to cite this page

ScholarGate. (2026, June 3). Hash-Based Message Authentication Code. ScholarGate. https://scholargate.app/en/cryptography/hmac

Related methods

AES (Rijndael)Differential CryptanalysisRSA Cryptosystem

Which method?

Set this method beside its closest kin and read them side by side — the library lays the books on the table; the choice is yours.

  • AES (Rijndael)Cryptography↔ compare
  • Differential CryptanalysisCryptography↔ compare
  • RSA CryptosystemCryptography↔ compare
Compare side by side →

Referenced by

AES (Rijndael)Blockchain ConsensusDeep Packet InspectionRing SignatureRSA Cryptosystem

Similar methods

SHA Hash FunctionDigital Signature SchemeTLS Protocol AnalysisDiffie-Hellman Key ExchangePost-Quantum Cryptography (Kyber)AES (Rijndael)Symmetric Key CryptanalysisRSA Cryptosystem Analysis

Related reference concepts

Message Authentication CodesCryptographic Hash FunctionsSymmetric CryptographyDigital SignaturesKey Exchange and EstablishmentTLS and Secure Channels

Spotted an issue on this page? Report or suggest a fix →

ScholarGate — HMAC (Hash-Based Message Authentication Code). Retrieved 2026-07-21 from https://scholargate.app/en/cryptography/hmac · Dataset: https://doi.org/10.5281/zenodo.20539026
Quick facts
Originator
Hugo Krawczyk
Subfamily
Message authentication code
Year
1997
Type
cryptographic authentication mechanism
Related methods
AES (Rijndael)Differential CryptanalysisRSA Cryptosystem
ScholarGate

A content-first reference library for research methods — what each one is, how it works, and where it comes from.

Open data (CC-BY)

Explore

  • Library
  • Search the library…
  • Browse by field
  • Fields
  • Journey
  • Compare
  • Which method?

Reference

  • Subjects
  • Atlas
  • Glossary
  • Methodology
  • Philosophy

Your tools

  • Bookshelf
  • Desk
  • Chat

Company

  • About
  • Pricing
  • Contact
  • Suggest a method

Entries are compiled from published sources for reference. Verifying the accuracy and suitability of any information for your own use remains your responsibility.

© 2026 ScholarGate · A research-method reference library
  • Privacy
  • Cookies
  • Terms
  • Delete account