2
$\begingroup$

I'm really grinding my teeth against digest calculation explanation in the CMS standard.

Let's consider the case when the signedAttrs are present.

The first paragraph says

initial input to the message digest calculation process is the "value" of the encapsulated content being signed.

To me that implies that whatever digest value that will be signed, somehow "starts" with being the digest of the message.

The second paragraph says:

When the [signedAttrs] field is present, however, the result is the message
digest of the complete DER encoding of the SignedAttrs value
contained in the signedAttrs field.

To me this does sound like the result is solely derived from the signedAttrs value, but then the first paragraph seems to be contradictory because it said that no matter what, the digest must start with encapsulated content. The second paragraph does then mention that the content hash will be indirectly included, because it must be present, but to me that still doesn't negate implication made in the first paragraph.

P.S. Based on OpenSSL implementation, I figure that the "correct" behavior is only hashing signedAttrs.

$\endgroup$

1 Answer 1

4
$\begingroup$

Consider the two cases.

without signedAttrs: first we hash the content, then we sign that hash. The first thing we do is hash the content.

with signedAttrs: first we hash the content, call it hash1; then we construct signedAttrs which includes hash1 in the message-digest attribute; then we hash signedAttrs, call it hash2; then we sign hash2. Only hash2 is used in the digital signature operation, but to compute hash2 we must previously have the value of signedAtttrs, and to have the value of signedAttrs we must previously have hash1, which is the hash of the content, so the first thing we do is hash the content.

Either way the first thing we do is hash the content which uses the content at input. Since this is the first thing we do, the initial input is the content. And in particular the value octets, not the tag and length, which is the actual point being specified in that paragraph.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.