OpenPGP tag 18/19 confusion description

Can someone please clear some MDC and data encryption for me? rfc 4880 says:

The plaintext data to be encrypted is transmitted through the SHA-1 hash function, and the result of the hash is added to the plaintext in the Modification Detection Code Package. The entry into the hash function includes the prefix data above; it includes all plaintext, and then includes two octets of values ​​0xD3, 0x14. These are encodings. A package of tag definition code for the modification and a length field of 20 octets.

at first it seems that mdc (without its header data) is simple: sha1([data]) -> hash_value

then the second sentence to the semicolon makes it look like sha1(OpenPGP_CFB_extra_data + [data]) -> hash_value

the material after the semicolon makes it seem like I should do sha1([data] + "\xd3\x14") -> hash_value . (this doesn’t make sense at all, but it seems to be what is written)

what's happening?

after receiving the correct MDC, what is done with it? Is it his own package or is something like this (in my understanding) done ?:

 tag18_header + encrypt(plaintext + "\xd3\x14" + 20 byte hash) 
+4
source share
1 answer

After reading RFC 4880 and parts of GnuPG, the source code ( g10 / cipher.c seems to be the place where this is processed), I interpret it like this:

  • 0xd3 is an MDC package tag.
  • 0x14 - MDC packet length (20 bytes).

The MDC hash is calculated as follows:

 MCD_hash = SHA-1(OpenPGP_CFB_extra_data + [plaintext] + "\xd3\x14") 

This is then added to the plaintext message and encrypted:

 encrypt(OpenPGP_CFB_extra_data + [plaintext] + "\xd3\x14" + MDC_hash) 

When decrypting, this hash is checked by calculating the SHA-1 of everything except the last 20 bytes, and comparing the result with the last 20 bytes, as RFC 4880 writes ( p. 50 ):

When decrypting, plaintext data must be hashed using SHA-1, including prefix data, as well as tag tag and packet length of the modification detection code. The body of the MDC packet during decryption is compared with the result of the SHA-1 hash.

+3
source

All Articles