In PKCS1 there's DigestInfo:
DigestInfo ::= SEQUENCE {
digestAlgorithm AlgorithmIdentifier,
digest OCTET STRING
}
AlgorithmIdentifier is defined in RFC5280:
AlgorithmIdentifier ::= SEQUENCE {
algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL }
PKCS1 provides DER encodings of DigestInfo for various hashing algorithms on page 43:
1. For the six hash functions mentioned in Appendix B.1, the DER
encoding T of the DigestInfo value is equal to the following:
MD2: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 02 05 00 04
10 || H.
MD5: (0x)30 20 30 0c 06 08 2a 86 48 86 f7 0d 02 05 05 00 04
10 || H.
SHA-1: (0x)30 21 30 09 06 05 2b 0e 03 02 1a 05 00 04 14 || H.
SHA-256: (0x)30 31 30 0d 06 09 60 86 48 01 65 03 04 02 01 05 00
04 20 || H.
SHA-384: (0x)30 41 30 0d 06 09 60 86 48 01 65 03 04 02 02 05 00
04 30 || H.
SHA-512: (0x)30 51 30 0d 06 09 60 86 48 01 65 03 04 02 03 05 00
04 40 || H.
If I create do asn1parse on one of those DER encodings (sha512) I get the following:
0:d=0 hl=2 l= 81 cons: SEQUENCE
2:d=1 hl=2 l= 13 cons: SEQUENCE
4:d=2 hl=2 l= 9 prim: OBJECT :sha512
15:d=2 hl=2 l= 0 prim: NULL
17:d=1 hl=2 l= 64 prim: OCTET STRING
algorithm is denoted by OBJECT and parameters is denoted by NULL. My question is...
If parameters is optional why is NULL present at all? Why do the strings provided in PKCS1 correspond to the above DER encoding instead of, say, this one (without the NULL)?:
0:d=0 hl=2 l= 79 cons: SEQUENCE
2:d=1 hl=2 l= 11 cons: SEQUENCE
4:d=2 hl=2 l= 9 prim: OBJECT :sha512
15:d=1 hl=2 l= 64 prim: OCTET STRING