XML-DSig Reference Transforms and Digest Algorithms
In an XML Digital Signature (XML-DSig) structure, the
<Reference> element identifies the target data to be
signed and defines the exact cryptographic and data-preparation
pipelines applied to that data. By utilizing child elements—specifically
<Transforms> and
<DigestMethod>—the <Reference>
element tells the validator how to normalize, filter, and hash the
payload to produce the final <DigestValue> for
verification.
The Role of the Reference Element
The <Reference> element connects the signature to
the signed data object. It typically contains a URI
attribute pointing to the data source (whether internal to the document,
external on a network, or detached) and houses the configuration for how
that data must be processed before the cryptographic signature is
generated or verified.
A standard <Reference> block contains three
primary components: 1. <Transforms>:
An ordered sequence of operations applied to the raw resource. 2.
<DigestMethod>: The hashing
algorithm applied to the transformed data. 3.
<DigestValue>: The base64-encoded
result of the digest calculation.
<Reference URI="#DataObjectId">
<Transforms>
<Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
<Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
</Transforms>
<DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
<DigestValue>dGhpcyBpcyBhIGhhc2ggZXhhbXBsZSAuLi4=</DigestValue>
</Reference>Specifying
Transformations via <Transforms>
The optional <Transforms> element contains one or
more <Transform> child elements. These elements
define an ordered pipeline of operations that manipulate the raw octet
stream or node-set before hashing occurs.
Each <Transform> specifies its logic using the
Algorithm attribute, which contains a URI identifying the
transformation standard:
- Canonicalization (C14N): Standardizes XML
formatting (such as whitespace, attribute ordering, and namespace
declarations) to ensure identical byte streams across different XML
parsers.
- Example URI:
http://www.w3.org/2001/10/xml-exc-c14n#(Exclusive XML Canonicalization).
- Example URI:
- Enveloped Signature Transform: Removes the
<Signature>element itself from the calculation when signing an entire document containing the signature, preventing recursive hashing issues.- Example URI:
http://www.w3.org/2000/09/xmldsig#enveloped-signature
- Example URI:
- XPath Filtering: Applies an XPath expression to select specific subsets of the XML document.
- XSLT Transforms: Applies an XSLT stylesheet to convert the XML structure prior to digest calculation.
The transformations execute sequentially: the output of the first
<Transform> serves as the input to the next until the
pipeline completes, yielding a canonical octet stream.
Specifying the
Digest Algorithm via <DigestMethod>
The mandatory <DigestMethod> element defines the
cryptographic hash function applied to the final output of the
transformation pipeline.
The algorithm is defined using the Algorithm attribute,
which points to a standard URI identifier for the hashing function.
Common digest algorithms include:
- SHA-256:
http://www.w3.org/2001/04/xmlenc#sha256 - SHA-384:
http://www.w3.org/2001/04/xmldsig-more#sha384 - SHA-512:
http://www.w3.org/2001/04/xmlenc#sha512 - SHA-1 (Legacy/Deprecated):
http://www.w3.org/2000/09/xmldsig#sha1
Execution and Verification Process
During generation and verification, the
<Reference> element dictates the following
step-by-step workflow:
- Dereferencing: The application uses the
URIattribute to retrieve the target data. - Transforming: The data passes through each
<Transform>in the order listed within<Transforms>. - Digesting: The resulting byte stream is hashed
using the algorithm declared in the
<DigestMethod>attribute. - Comparison / Storage: During signing, this hash is
base64-encoded and written into
<DigestValue>. During verification, the newly calculated hash is compared directly against the existing<DigestValue>.