opyebDNSSECLab

Turning a DNSKEY into a DS record — key tag and digest, step by step

Practice · 8 min

In one line: How to derive the key tag from a DNSKEY and build a SHA-256 DS record, with a worked example and the order in which parent and child zones are updated.

The DNSSEC chain of trust starts with one sentence: a DS record in the parent zone points at a DNSKEY in the child zone. That DS record is computed mechanically from the DNSKEY, and the arithmetic is easy to get wrong by hand.

1. What a DS record carries

FieldMeaning
Key Tag16-bit checksum over the DNSKEY RDATA; identifies which key is meant.
AlgorithmThe DNSKEY's signing algorithm number (8, 13, 14, 15…).
Digest Type1 = SHA-1, 2 = SHA-256, 4 = SHA-384. Use 2 for new records.
DigestHash of the owner name plus the complete DNSKEY RDATA.

2. The key tag (RFC 4034 Appendix B)

The DNSKEY RDATA is Flags (2 bytes), Protocol (1), Algorithm (1) and the public key. The key tag adds that byte string in 16-bit words and folds the carry back in.

  1. Start with ac = 0.
  2. For each byte at index i: even i adds byte << 8, odd i adds byte.
  3. Add (ac >> 16) & 0xFFFF once.
  4. The low 16 bits are the key tag.

Algorithm 1 (RSA/MD5) is the exception: its key tag is the most significant 16 bits of the least significant 24 bits of the modulus. You should not create Algorithm 1 keys, but old zones still require this rule to match.

3. The digest input

digest_input = wire(owner_name) || DNSKEY_RDATA
digest       = SHA-256(digest_input)
  • wire(owner_name): lower-cased, each label as length byte + label bytes, closed with 0x00. Example: example.com. → 07 65 78 61 6d 70 6c 65 03 63 6f 6d 00.
  • DNSKEY_RDATA: the decoded Flags, Protocol, Algorithm and public key bytes, not the Base64 text.

The most common mistake is leaving out the owner name. The same key under example.com. and www.example.com. produces two completely different DS digests.

4. Worked example: one P-256 KSK

example.com. 3600 IN DNSKEY 257 3 13 ERITFBUWFxgZGhscHR4fICEiIyQlJicoKSorLC0uLzAxMjM0NTY3ODk6Ozw9Pj9AQUJDREVGR0hJSktMTU5PUA==
ItemValue
Key Tag2612
Algorithm13 (ECDSAP256SHA256)
SHA-256 DSexample.com. IN DS 2612 13 2 F5E2852FC6FBC055DEFFFEB7C57498E265F85E4CF9692E0CED34705378830B0C
SHA-384 DSexample.com. IN DS 2612 13 4 8A63C54EDD23513EF217A739A7DF8EBE3E55345788B089EF79B780A1C342EF8414C2E1609D04C1F5715D99AE445B31AF

Paste the record into panel ① of DNSSECLab and the same values appear, ready to copy in BIND format.

5. Where it goes and in what order

  1. Create the KSK in the child zone and publish its DNSKEY.
  2. Compute the DS from that DNSKEY.
  3. Add the DS at the delegation in the parent zone, or enter it in the registrar's DS field (usually as a hex digest).
  4. Confirm the parent answers with the DS, then sign the child zone.
  5. Check with dig +dnssec example.com DS and dig +dnssec example.com DNSKEY that the tags line up.

6. Checklist

  • Does the DS key tag equal the DNSKEY key tag?
  • Does the DS algorithm equal the DNSKEY algorithm?
  • Is the digest type 2 (SHA-256) or better?
  • Does the owner name match the delegation exactly?
  • Is the parent DS TTL short enough to allow a rollover?

If any answer is no, validating resolvers treat the child zone as bogus.

Computing a single DS record makes the relationship between the key tag and the digest concrete.

Open DNSSECLab

Frequently asked questions

Must the DS key tag match the DNSKEY key tag?

Yes. The DS Key Tag, Algorithm and Digest Type must all correspond to the DNSKEY being referenced; otherwise validation fails.

Can the DS live in the child zone file?

No. The DS belongs in the parent zone at the delegation point. A DS at the child apex is ignored by resolvers, and the DNSSECLab linter warns about it.

SHA-256 or SHA-384?

SHA-256 (digest type 2) is sufficient and the most widely supported. SHA-384 is used where policy demands a longer digest; some operators publish both.

References

Read next

0 bytes of your input sent to a server (advertising and affiliate widgets excluded)