Turning a DNSKEY into a DS record — key tag and digest, step by step
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
| Field | Meaning |
|---|---|
| Key Tag | 16-bit checksum over the DNSKEY RDATA; identifies which key is meant. |
| Algorithm | The DNSKEY's signing algorithm number (8, 13, 14, 15…). |
| Digest Type | 1 = SHA-1, 2 = SHA-256, 4 = SHA-384. Use 2 for new records. |
| Digest | Hash 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.
- Start with
ac = 0. - For each byte at index i: even i adds
byte << 8, odd i addsbyte. - Add
(ac >> 16) & 0xFFFFonce. - 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 with0x00. 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==
| Item | Value |
|---|---|
| Key Tag | 2612 |
| Algorithm | 13 (ECDSAP256SHA256) |
| SHA-256 DS | example.com. IN DS 2612 13 2 F5E2852FC6FBC055DEFFFEB7C57498E265F85E4CF9692E0CED34705378830B0C |
| SHA-384 DS | example.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
- Create the KSK in the child zone and publish its DNSKEY.
- Compute the DS from that DNSKEY.
- Add the DS at the delegation in the parent zone, or enter it in the registrar's DS field (usually as a hex digest).
- Confirm the parent answers with the DS, then sign the child zone.
- Check with
dig +dnssec example.com DSanddig +dnssec example.com DNSKEYthat 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 DNSSECLabFrequently 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
- RFC 4034 — Resource Records for the DNS Security Extensions
- RFC 4509 — Use of SHA-256 in DNSSEC Delegation Signer (DS) Resource Records
- IANA — DS RR Digest Types
Read next
- DNSKEY flags and algorithms — telling KSK from ZSK and choosing oneWhat flags 256 and 257 mean together with the SEP and REVOKE bits, why protocol must be 3, and how to choose between algorithms 8, 13, 14, 15 and 16.
- BIND zone syntax — $ORIGIN, $TTL, @ and a correct SOAZone file structure and omission rules, what each SOA timer means, and the CNAME, MX and TXT details that are most often wrong.
- CAA, SPF and TXT lint — the mistakes that block certificates and emailCAA flags, tags and values, the SPF ten-lookup limit, the single-SPF rule, and splitting TXT strings at 255 bytes.