The Mechanics of Email Authentication: A Deep Dive into SPF, DKIM, and DMARC Alignment

An architectural breakdown of the RFC 5321 vs RFC 5322 identity split, DNS macro lookups, cryptographic canonicalization, and strict vs relaxed DMARC alignment.

To understand modern email authentication, one must first recognize the historical design flaw of SMTP: the separation of the transport envelope from the message content.

RFC 5321 defines the Envelope (used for routing by Mail Transfer Agents, specifically HELO/EHLO and MAIL FROM), while RFC 5322 defines the Message Header (what user email clients display in the From: line). Because these two layers can state completely different identities, attackers have exploited this split for spoofing.

SPF, DKIM, and DMARC exist to cryptographically tie these layers together.


1. Sender Policy Framework (SPF): Validating the Transport Envelope

SPF (RFC 7208) validates whether the sending MTA’s IP address is authorized by the domain in the Envelope MAIL FROM (also known as the Return-Path or bounce address).

v=spf1 ip4:192.0.2.0/24 include:_spf.google.com ~all

The 10-DNS-Lookup Hard Ceiling

SPF parsing requires MTAs to resolve DNS records. To prevent Denial of Service (DoS) attacks via infinite DNS amplification loops, RFC 7208 imposes a strict limit:

The Forwarding Problem

If a recipient has an automated forward rule (e.g., forwarding work emails to a personal inbox), the forwarding MTA delivers the email from its own IP address. The destination MTA checks SPF against the original MAIL FROM domain, sees the forwarding server’s IP (which is unauthorized), and marks SPF as Fail. SPF alone cannot survive email forwarding.


2. DomainKeys Identified Mail (DKIM): Cryptographic Integrity

DKIM (RFC 6376) provides tamper-evidence and identity assertion by attaching a cryptographic signature to the message headers.

DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple;
  d=example.com; s=202609;
  h=from:to:subject:date:message-id;
  bh=47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=;
  b=b64EncodedSignatureHere...

Canonicalization Algorithms (c=)

Email transport systems frequently modify whitespace, wrap lines, or reformat headers. DKIM uses canonicalization before hashing to prevent legitimate modifications from invalidating signatures:

The format is c=header_algo/body_algo (e.g., relaxed/simple).

The Two Hashes

Because DKIM signs message headers and the body hash, it survives forwarding as long as the forwarding server does not rewrite the signed headers or append disclaimers to the body.


3. DMARC: Enforcing Identifier Alignment

An attacker could send an email with:

Without DMARC (RFC 7489), the email passes both SPF and DKIM independently, yet successfully impersonates the CEO. DMARC solves this by requiring Identifier Alignment.

                           +---------------------------+
                           | RFC 5322 Header From:     |
                           | example.com               |
                           +-------------+-------------+
                                         |
                     +-------------------+-------------------+
                     |                                       |
                     v                                       v
         +-----------------------+               +-----------------------+
         | Envelope MAIL FROM    |               | DKIM Signature d=     |
         | sub.example.com       |               | example.com           |
         +-----------+-----------+               +-----------+-----------+
                     |                                       |
            SPF: PASS (IP valid)                   DKIM: PASS (Sig valid)
                     |                                       |
                     +------> Alignment Check <------+
                                         |
                            DMARC Alignment: PASS

Relaxed vs. Strict Alignment

Policy Execution (p=)


Summary Checklist for Mail Operators

  1. SPF verifies sender IP against the RFC 5321 envelope return path; it breaks under standard forwarding and must stay under 10 DNS lookups.
  2. DKIM provides cryptographic proof that the body and specified headers have not been tampered with.
  3. DMARC binds the technical authentication domains of SPF and DKIM to the user-visible RFC 5322 From: header. A message passes DMARC if at least one authenticated protocol (SPF or DKIM) aligns with the visible sender.
Sudhir Mishra
Senior Software Engineer at Cisco focusing on cloud security products, high-throughput streaming systems, and zero-trust data architectures.