View Source OpenPGP.ModificationDetectionCodePacket (OpenPGP v0.6.2)
Represents structured data for Modification Detection Code Packet.
Example:
iex> alias OpenPGP.ModificationDetectionCodePacket
...> data = :crypto.hash(:sha, <<"Hello!", 0xD3, 0x14>>)
...> ModificationDetectionCodePacket.decode(data)
{
%ModificationDetectionCodePacket{
sha: <<24, 124, 192, 238, 22, 94, 219, 146, 73, 3, 220, 145, 130, 2, 184, 60, 245, 227, 44, 17>>
},
<<>>
}
RFC4880
5.14. Modification Detection Code Packet (Tag 19)
The Modification Detection Code packet contains a SHA-1 hash of plaintext data, which is used to detect message modification. It is only used with a Symmetrically Encrypted Integrity Protected Data packet. The Modification Detection Code packet MUST be the last packet in the plaintext data that is encrypted in the Symmetrically Encrypted Integrity Protected Data packet, and MUST appear in no other place.
A Modification Detection Code packet MUST have a length of 20 octets.
The body of this packet consists of:
- A 20-octet SHA-1 hash of the preceding plaintext data of the Symmetrically Encrypted Integrity Protected Data packet, including prefix data, the tag octet (0xD3), and length octet of the Modification Detection Code packet (0x14).
Note that the Modification Detection Code packet MUST always use a new format encoding of the packet tag, and a one-octet encoding of the packet length. The reason for this is that the hashing rules for modification detection include a one-octet tag and one-octet length in the data hash. While this is a bit restrictive, it reduces complexity.
Summary
Functions
Encode Modification Detection Code (MDC) Packet and append to the input binary. Returns binary with MDC appended.
Decode packet given input binary. Returns structured packet and remaining binary (empty string). Expects input binary to be 20 octets long (the length of SHA-1).
Validates input binary/plaintext with a Modification Detection Code (MDC) Packet. Returns :ok on success. Raises on failure. Expect last 22 octets of payload to represent MDC Packet.
Types
@type t() :: %OpenPGP.ModificationDetectionCodePacket{sha: <<_::160>>}
Functions
Encode Modification Detection Code (MDC) Packet and append to the input binary. Returns binary with MDC appended.
Decode packet given input binary. Returns structured packet and remaining binary (empty string). Expects input binary to be 20 octets long (the length of SHA-1).
Validates input binary/plaintext with a Modification Detection Code (MDC) Packet. Returns :ok on success. Raises on failure. Expect last 22 octets of payload to represent MDC Packet.