HSM KitHSM Kit
English

MAC Algorithms in Payment Security: ISO 9797, HMAC & CMAC

Payment Security# MAC# ISO 9797# HMAC# CMAC
Last Updated: April 3, 20264 min readBy HSM Kit Team
Need to calculate this now?
Use our free online HMAC Calculator tool.

Message Authentication Codes (MACs) are how payment systems verify that transaction data hasn't been tampered with. This guide covers the MAC algorithms used in banking and payment processing.

What is a MAC?

A MAC (Message Authentication Code) is a short piece of data used to verify both the integrity and authenticity of a message. Unlike a hash, a MAC requires a secret key — only someone with the key can generate or verify it.

MAC = MAC_Algorithm(Key, Message)

Properties:

  • Integrity: Any change to the message produces a different MAC
  • Authentication: Only parties with the key can generate valid MACs
  • Non-repudiation (with asymmetric schemes): Proves who sent the message

MAC vs Hash vs Signature

PropertyHashMACDigital Signature
Key requiredNoYes (symmetric)Yes (asymmetric)
IntegrityYesYesYes
AuthenticationNoYesYes
Non-repudiationNoNoYes
SpeedFastFastSlow
Use in paymentsKCVTransaction authCertificate signing

ISO 9797-1 MAC Algorithms

ISO 9797-1 defines MAC algorithms based on block ciphers (typically DES/3DES). These are the foundation of payment message authentication.

Algorithm 1 (CBC-MAC)

The simplest form: encrypt the message in CBC mode, use the last block as MAC.

MAC = DES_Encrypt(Key, last block of CBC chain)
  • Simple but has known weaknesses for variable-length messages
  • Still used in legacy systems

Algorithm 3 (Retail MAC / ANSI X9.19)

The most common payment MAC algorithm:

  1. Process all blocks except the last with single DES
  2. Apply 3DES to the final block
Intermediate = DES_Encrypt(Key_Left, data blocks)
MAC = 3DES_Encrypt(Key, last intermediate block)

This is the Retail MAC used throughout the payment industry. See our Retail MAC tool and ANSI X9.9/X9.19 tool.

Padding Methods

  • Method 1: Pad with zeros to block boundary
  • Method 2: Append 0x80 then zeros (ISO padding)

Use our ISO 9797-1 MAC tool to compute MACs with all algorithm and padding combinations.

AS2805 MAC (Australian EFTPOS)

AS2805 is the Australian standard for EFTPOS transactions, based on ISO 8583. It uses a specific MAC algorithm for transaction authentication.

Use our AS2805 MAC tool for AS2805-specific MAC calculations.

3DES CBC-MAC

A straightforward 3DES-based CBC-MAC:

MAC = 3DES_Encrypt(Key, last block of 3DES-CBC chain)

Used in various legacy payment and banking protocols. See our 3DES CBC-MAC tool.

HMAC — Modern Standard

HMAC (Hash-based MAC) uses a cryptographic hash function instead of a block cipher:

HMAC(K, m) = Hash((K ⊕ opad) || Hash((K ⊕ ipad) || m))

HMAC-SHA256

  • Most widely used modern MAC
  • Used in: TLS, JWT, REST API authentication, AWS signatures
  • 256-bit output, truncated to required length

HMAC-SHA512

  • Higher security variant
  • Used in high-security applications

Use our HMAC Calculator to compute HMAC-SHA256 and HMAC-SHA512.

AES-CMAC — Modern Payment MAC

CMAC (Cipher-based MAC) uses AES in a special mode to produce a MAC:

CMAC = AES_CBC_MAC with subkey derivation

Advantages over CBC-MAC:

  • Secure for variable-length messages
  • No padding oracle vulnerabilities
  • Used in modern payment standards (EMV, DUKPT AES)

Use our CMAC tool for AES-CMAC and 3DES-CMAC calculations.

MAC in Transaction Flow

Here's how MAC protects a typical ATM transaction:

1. ATM builds ISO 8583 message
2. ATM computes MAC over message fields using MAC key
3. MAC appended to message (field 64 or 128)
4. Message sent to host

5. Host receives message
6. Host computes MAC over same fields using same MAC key
7. Host compares computed MAC with received MAC
8. If match: message authentic. If mismatch: reject transaction.

The MAC key itself is typically a DUKPT-derived key (unique per transaction) — see our DUKPT guide.

MAC Key Management

MAC keys are working keys in the HSM key hierarchy:

  • Derived from Zone MAC Key (ZMK) or via DUKPT
  • Rotated regularly (daily, per-session, or per-transaction with DUKPT)
  • Stored encrypted under LMK in HSM

For HSM key management overview, see our HSM Key Management guide.

Choosing the Right MAC Algorithm

ScenarioRecommended MAC
Legacy ATM/POS (TDES)ISO 9797-1 Alg 3 (Retail MAC)
Modern payment (AES)AES-CMAC
REST API / WebHMAC-SHA256
Australian EFTPOSAS2805 MAC
EMV chip transactionsAES-CMAC

Try It Yourself

Related Tool
HMAC Calculator