RFC 2440
OpenPGP Message Format
RFC 2440: OpenPGP Message Format ๐ (Part 1 of 13)
okay bestie, RFC 2440 is the spec for OpenPGP, the message format for encrypting, signing, and managing keys ๐โจ this part covers the front matter and the intro, and the rest drops in the next parts ๐
- Who wrote it: J. Callas (Network Associates), L. Donnerhacke (IN-Root-CA Individual Network e.V.), H. Finney (Network Associates), and R. Thayer (EIS Corporation) ๐
- Category: Standards Track ๐ฆ
- Date: November 1998 ๐
- Obsoletes and updates: the title block doesn't list anything this RFC obsoletes or updates ๐ง
it does build on an earlier spec though: RFC 1991, "PGP Message Exchange Formats" ๐
Status of this Memo ๐
so this is an Internet standards track protocol for the Internet community ๐ it's asking for discussion and suggestions for improvements ๐ฃ๏ธ for the current standardization state and status, you check the "Internet Official Protocol Standards" (STD 1) ๐ and distribution of this memo is unlimited ๐
Copyright Notice ๐ฅ
Copyright (C) The Internet Society (1998). All Rights Reserved. ๐
IESG Note ๐จ
this part is really important, so read it twice ๐ the document defines a bunch of tag values, but it doesn't describe a way to add new tags for new features ๐ญ normally the Internet Assigned Numbers Authority (IANA) handles allocating new values for future expansion, and RFCs usually define the procedure IANA should follow ๐ง BUT there are subtle (and not so subtle) interactions between new features and existing ones in this protocol that could seriously cut down overall security ๐ so this document does not define an extension procedure ๐ if you want new tag values (say, for new encryption algorithms), you forward the request to the IESG Security Area Directors, or to the appropriate IETF Working Group for consideration ๐ซถ
Abstract โจ
this document is maintained to publish all the info you need to build interoperable applications based on the OpenPGP format ๐ฆ it's not a step-by-step cookbook for writing an app ๐ฐ it only describes the format and methods needed to read, check, generate, and write conforming packets crossing any network ๐ฆ storage and implementation questions are out of scope ๐ โโ๏ธ it does, however, discuss implementation issues needed to avoid security flaws ๐ก๏ธ
Open-PGP software combines strong public-key and symmetric cryptography to give security services for electronic communications and data storage ๐ those services are confidentiality, key management, authentication, and digital signatures ๐ this document specifies the message formats used in OpenPGP ๐
Table of Contents ๐๏ธ
Status of this Memo 1
IESG Note 1
Abstract 1
Table of Contents 2
1. Introduction 4
1.1. Terms 5
2. General functions 5
2.1. Confidentiality via Encryption 5
2.2. Authentication via Digital signature 6
2.3. Compression 7
2.4. Conversion to Radix-64 7
2.5. Signature-Only Applications 7
3. Data Element Formats 7
3.1. Scalar numbers 8
3.2. Multi-Precision Integers 8
3.3. Key IDs 8
3.4. Text 8
3.5. Time fields 9
3.6. String-to-key (S2K) specifiers 9
3.6.1. String-to-key (S2k) specifier types 9
3.6.1.1. Simple S2K 9
3.6.1.2. Salted S2K 10
3.6.1.3. Iterated and Salted S2K 10
3.6.2. String-to-key usage 11
3.6.2.1. Secret key encryption 11
3.6.2.2. Symmetric-key message encryption 11
4. Packet Syntax 12
4.1. Overview 12
4.2. Packet Headers 12
4.2.1. Old-Format Packet Lengths 13
4.2.2. New-Format Packet Lengths 13
4.2.2.1. One-Octet Lengths 14
4.2.2.2. Two-Octet Lengths 14
4.2.2.3. Five-Octet Lengths 14
4.2.2.4. Partial Body Lengths 14
4.2.3. Packet Length Examples 14
4.3. Packet Tags 15
5. Packet Types 16
5.1. Public-Key Encrypted Session Key Packets (Tag 1) 16
5.2. Signature Packet (Tag 2) 17
5.2.1. Signature Types 17
5.2.2. Version 3 Signature Packet Format 19
5.2.3. Version 4 Signature Packet Format 21
5.2.3.1. Signature Subpacket Specification 22
5.2.3.2. Signature Subpacket Types 24
5.2.3.3. Signature creation time 25
5.2.3.4. Issuer 25
5.2.3.5. Key expiration time 25
5.2.3.6. Preferred symmetric algorithms 25
5.2.3.7. Preferred hash algorithms 25
5.2.3.8. Preferred compression algorithms 26
5.2.3.9. Signature expiration time 26
5.2.3.10.Exportable Certification 26
5.2.3.11.Revocable 27
5.2.3.12.Trust signature 27
5.2.3.13.Regular expression 27
5.2.3.14.Revocation key 27
5.2.3.15.Notation Data 28
5.2.3.16.Key server preferences 28
5.2.3.17.Preferred key server 29
5.2.3.18.Primary user id 29
5.2.3.19.Policy URL 29
5.2.3.20.Key Flags 29
5.2.3.21.Signer's User ID 30
5.2.3.22.Reason for Revocation 30
5.2.4. Computing Signatures 31
5.2.4.1. Subpacket Hints 32
5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 32
5.4. One-Pass Signature Packets (Tag 4) 33
5.5. Key Material Packet 34
5.5.1. Key Packet Variants 34
5.5.1.1. Public Key Packet (Tag 6) 34
5.5.1.2. Public Subkey Packet (Tag 14) 34
5.5.1.3. Secret Key Packet (Tag 5) 35
5.5.1.4. Secret Subkey Packet (Tag 7) 35
5.5.2. Public Key Packet Formats 35
5.5.3. Secret Key Packet Formats 37
5.6. Compressed Data Packet (Tag 8) 38
5.7. Symmetrically Encrypted Data Packet (Tag 9) 39
5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 39
5.9. Literal Data Packet (Tag 11) 40
5.10. Trust Packet (Tag 12) 40
5.11. User ID Packet (Tag 13) 41
6. Radix-64 Conversions 41
6.1. An Implementation of the CRC-24 in "C" 42
6.2. Forming ASCII Armor 42
6.3. Encoding Binary in Radix-64 44
6.4. Decoding Radix-64 46
6.5. Examples of Radix-64 46
6.6. Example of an ASCII Armored Message 47
7. Cleartext signature framework 47
7.1. Dash-Escaped Text 47
8. Regular Expressions 48
9. Constants 49
9.1. Public Key Algorithms 49
9.2. Symmetric Key Algorithms 49
9.3. Compression Algorithms 50
9.4. Hash Algorithms 50
10. Packet Composition 50
10.1. Transferable Public Keys 50
10.2. OpenPGP Messages 52
10.3. Detached Signatures 52
11. Enhanced Key Formats 52
11.1. Key Structures 52
11.2. Key IDs and Fingerprints 53
12. Notes on Algorithms 54
12.1. Symmetric Algorithm Preferences 54
12.2. Other Algorithm Preferences 55
12.2.1. Compression Preferences 56
12.2.2. Hash Algorithm Preferences 56
12.3. Plaintext 56
12.4. RSA 56
12.5. Elgamal 57
12.6. DSA 58
12.7. Reserved Algorithm Numbers 58
12.8. OpenPGP CFB mode 58
13. Security Considerations 59
14. Implementation Nits 60
15. Authors and Working Group Chair 62
16. References 63
17. Full Copyright Statement 65
1. Introduction ๐ธ
okay so this document covers the message-exchange packet formats OpenPGP uses for encryption, decryption, signing, and key management ๐โจ it builds on the foundation from RFC 1991, "PGP Message Exchange Formats" ๐
the next part picks up at Section 1.1, Terms, so stay tuned bestie ๐ง๐
1.1. Terms
- OpenPGP ๐: security software that uses PGP 5.x as its basis.
- PGP โจ: Pretty Good Privacy! It's a whole family of software systems developed by Philip R. Zimmermann, and OpenPGP is based on it.
- PGP 2.6.x ๐ฆ: This version has lots of variants, which is why we call it "PGP 2.6.x." It only used RSA, MD5, and IDEA for its cryptographic transforms. An informational RFC, RFC 1991, was written to describe this version.
- PGP 5.x ๐ธ: This version used to be called "PGP 3" in the community and in the predecessor of this document, RFC 1991. It has new formats and fixes a bunch of problems in the PGP 2.6.x design. We call it PGP 5.x because that software was the first release of the "PGP 3" code base.
"PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of Network Associates, Inc. and are used with permission. ๐
This document uses the terms "MUST", "SHOULD", and "MAY" as defined in RFC 2119, along with the negated forms of those terms. ๐
2. General functions ๐
OpenPGP gives you data integrity for messages and data files using these core technologies:
- digital signatures
- encryption
- compression
- radix-64 conversion
It also does key management and certificate services, but a lot of that is beyond the scope of this document. ๐ซถ
2.1. Confidentiality via Encryption ๐
OpenPGP uses two encryption methods for confidentiality: symmetric-key encryption and public key encryption. With public-key encryption, the object gets encrypted with a symmetric encryption algorithm. Each symmetric key is used only once. A new "session key" is generated as a random number for each message. Since it's only used once, the session key is bound to the message and sent along with it. To protect the key, it's encrypted with the receiver's public key. The sequence goes like this:
- The sender creates a message.
- The sending OpenPGP generates a random number to be used as a session key for this message only.
- The session key is encrypted using each recipient's public key. These "encrypted session keys" start the message.
- The sending OpenPGP encrypts the message using the session key, which forms the remainder of the message. Note that the message is also usually compressed.
- The receiving OpenPGP decrypts the session key using the recipient's private key.
- The receiving OpenPGP decrypts the message using the session key. If the message was compressed, it will be decompressed.
With symmetric-key encryption, an object may be encrypted with a symmetric key derived from a passphrase (or other shared secret). Or you can use a two-stage mechanism, similar to the public-key method above, where a session key is itself encrypted with a symmetric algorithm keyed from a shared secret. ๐
Digital signature and confidentiality services can both be applied to the same message. First, a signature is generated for the message and attached to it. Then the message plus signature gets encrypted using a symmetric session key. Finally, the session key is encrypted using public-key encryption and prefixed to the encrypted block. It's giving layers! ๐
2.2. Authentication via Digital signature โ๏ธ
The digital signature uses a hash code or message digest algorithm, plus a public-key signature algorithm. The sequence goes like this:
- The sender creates a message.
- The sending software generates a hash code of the message.
- The sending software generates a signature from the hash code using the sender's private key.
- The binary signature is attached to the message.
- The receiving software keeps a copy of the message signature.
- The receiving software generates a new hash code for the received message and verifies it using the message's signature. If the verification is successful, the message is accepted as authentic. ๐
2.3. Compression ๐๏ธ
OpenPGP implementations MAY compress the message after applying the signature but before encryption. โจ
2.4. Conversion to Radix-64 ๐ง
OpenPGP's underlying native representation for encrypted messages, signature certificates, and keys is a stream of arbitrary octets. Some systems only permit blocks made of seven-bit, printable text. So, to move OpenPGP's native raw binary octets through channels that aren't safe for raw binary data, you need a printable encoding of those octets. OpenPGP provides a service that converts the raw 8-bit binary octet stream into a stream of printable ASCII characters, called Radix-64 encoding or ASCII Armor. ๐ฆ
Implementations SHOULD provide Radix-64 conversions. ๐
Note that many applications, particularly messaging applications, will want more advanced features as described in the OpenPGP-MIME document, RFC 2015. An application that implements OpenPGP for messaging SHOULD implement OpenPGP-MIME. ๐จ
2.5. Signature-Only Applications โ๏ธ
OpenPGP is designed for applications that use both encryption and signatures. But there are a number of problems that a signature-only implementation solves. Although this specification requires both encryption and signatures, it's reasonable for there to be subset implementations that are non-comformant only in that they omit encryption. ๐
3. Data Element Formats ๐งฉ
This section describes the data elements used by OpenPGP. ๐
3.1. Scalar numbers ๐ข
Scalar numbers are unsigned and are always stored in big-endian format. Using n[k] to refer to the kth octet being interpreted, the value of a two-octet scalar is:
((n[0] << 8) + n[1])
The value of a four-octet scalar is:
((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + n[3])
3.2. Multi-Precision Integers ๐งฎ
Multi-Precision Integers (also called MPIs) are unsigned integers used to hold large integers, like the ones used in cryptographic calculations. ๐ฅ
An MPI consists of two pieces: a two-octet scalar that is the length of the MPI in bits, followed by a string of octets that contain the actual integer.
These octets form a big-endian number. A big-endian number can be made into an MPI by prefixing it with the appropriate length.
Examples:
(all numbers are in hexadecimal)
The string of octets [00 01 01] forms an MPI with the value 1. The string [00 09 01 FF] forms an MPI with the value of 511.
Additional rules:
The size of an MPI is:
((MPI.length + 7) / 8) + 2 octets
The length field of an MPI describes the length starting from its most significant non-zero bit. So the MPI [00 02 01] is not formed correctly. It should be [00 01 01]. ๐
3.3. Key IDs ๐
A Key ID is an eight-octet scalar that identifies a key. Implementations SHOULD NOT assume that Key IDs are unique. The section, "Enhanced Key Formats" below describes how Key IDs are formed. ๐
3.4. Text ๐
The default character set for text is the UTF-8 [RFC2279] encoding of Unicode [ISO10646]. ๐
3.5. Time fields โฐ
A time field is an unsigned four-octet number containing the number of seconds elapsed since midnight, 1 January 1970 UTC. ๐
3.6. String-to-key (S2K) specifiers ๐๏ธ
String-to-key (S2K) specifiers are used to convert passphrase strings into symmetric-key encryption/decryption keys. Right now, they're used in two places: to encrypt the secret part of private keys in the private keyring, and to convert passphrases to encryption keys for symmetrically encrypted messages. ๐
3.6.1. String-to-key (S2k) specifier types ๐ซ
There are three types of S2K specifiers currently supported, as follows:
3.6.1.1. Simple S2K ๐ฅ
This directly hashes the string to produce the key data. See below for how this hashing is done.
Octet 0: 0x00
Octet 1: hash algorithm
Simple S2K hashes the passphrase to produce the session key. The manner in which this is done depends on the size of the session key (which depends on the cipher used) and the size of the hash algorithm's output. If the hash size is greater than or equal to the session key size, the high-order (leftmost) octets of the hash are used as the key.
If the hash size is less than the key size, multiple instances of the hash context are created, enough to produce the required key data. These instances are preloaded with 0, 1, 2, ... octets of zeros. That is to say, the first instance has no preloading, the second gets preloaded with 1 octet of zero, the third is preloaded with two octets of zeros, and so forth.
As the data is hashed, it is given independently to each hash context. Since the contexts have been initialized differently, they'll each produce different hash output. Once the passphrase is hashed, the output data from the multiple hashes is concatenated, first hash leftmost, to produce the key data, with any excess octets on the right discarded. ๐ง
3.6.1.2. Salted S2K ๐ง
This includes a "salt" value in the S2K specifier (some arbitrary data) that gets hashed along with the passphrase string, to help prevent dictionary attacks. ๐ก๏ธ
Octet 0: 0x01
Octet 1: hash algorithm
Octets 2-9: 8-octet salt value
Salted S2K is exactly like Simple S2K, except that the input to the hash function(s) consists of the 8 octets of salt from the S2K specifier, followed by the passphrase.
3.6.1.3. Iterated and Salted S2K ๐
This includes both a salt and an octet count. The salt is combined with the passphrase, and the resulting value is hashed repeatedly. This further increases the amount of work an attacker must do to try dictionary attacks. ๐ค
Octet 0: 0x03
Octet 1: hash algorithm
Octets 2-9: 8-octet salt value
Octet 10: count, a one-octet, coded value
The count is coded into a one-octet number using the following formula:
#define EXPBIAS 6
count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS);
The above formula is in C, where "Int32" is a type for a 32-bit integer, and the variable "c" is the coded count, Octet 10.
Iterated-Salted S2K hashes the passphrase and salt data multiple times. The total number of octets to be hashed is specified in the encoded count in the S2K specifier. Note that the resulting count value is an octet count of how many octets will be hashed, not an iteration count. ๐งพ
Initially, one or more hash contexts are set up as with the other S2K algorithms, depending on how many octets of key data are needed. Then the salt, followed by the passphrase data, is repeatedly hashed until the number of octets specified by the octet count has been hashed. The one exception: if the octet count is less than the size of the salt plus passphrase, the full salt plus passphrase will be hashed even though that's greater than the octet count. ๐โโ๏ธ
After the hashing is done, the data is unloaded from the hash context(s) as with the other S2K algorithms. ๐ท
3.6.2. String-to-key usage ๐๏ธ
Implementations SHOULD use salted or iterated-and-salted S2K specifiers, as simple S2K specifiers are more vulnerable to dictionary attacks. ๐จ
3.6.2.1. Secret key encryption ๐
okay so an S2K specifier can be stored right in the secret keyring ๐๏ธ, and its whole job is to explain how to turn your passphrase into the key that unlocks the secret data ๐. back in the old PGP days ๐, they just stuck a cipher algorithm octet in front of the secret data, or a zero if it wasn't encrypted at all. and MD5 was always the hash used to turn the passphrase into a key for that cipher. so basic ๐
for compatibility, when an S2K specifier is used, the special value 255 gets stored where the hash algorithm octet would have been in the old structure. then comes a one-octet algorithm identifier, and right after that, the S2K specifier encoded the way we just talked about โจ
so before the secret data, there will be one of these possibilities:
0: secret data is unencrypted (no pass phrase)
255: followed by algorithm octet and S2K specifier
Cipher alg: use Simple S2K algorithm using MD5 hash
the last one, the cipher algorithm number with MD5 and IDEA implicitly baked in, is only there for backward compatibility ๐ฅ. it MAY be understood, but it SHOULD NOT be generated, and it is deprecated. not it ๐ โโ๏ธ
after all that, you get an 8-octet Initial Vector for decrypting the secret values (if they're encrypted), and then the secret key values themselves ๐
3.6.2.2. Symmetric-key message encryption ๐ฆ
okay so OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) packet at the front of a message ๐. why is this iconic? it lets S2K specifiers handle the passphrase conversion, or lets you mix symmetric-key ESKs with public-key ESKs in one message. the result is a message that can be decrypted with either a passphrase or a public key. two doors, one room ๐ชโจ
PGP 2.X always used IDEA with Simple string-to-key conversion when it encrypted a message with a symmetric algorithm. this is deprecated, but it MAY be used for backward-compatibility ๐ซถ
4. Packet Syntax โจ
this section describes the packets used by OpenPGP ๐
4.1. Overview ๐ง
an OpenPGP message is built out of a bunch of records that are traditionally called packets ๐ฆ. a packet is a chunk of data with a tag that says what it means. an OpenPGP message, keyring, certificate, and so on is made up of a number of packets. some packets can contain other OpenPGP packets inside them ๐. for example, a compressed data packet, once uncompressed, contains OpenPGP packets. russian dolls, but make it crypto ๐ช
each packet is a packet header followed by the packet body. the packet header is variable length ๐
4.2. Packet Headers ๐
the first octet of the packet header is called the "Packet Tag." it decides the format of the header and says what the packet contains. the rest of the packet header is the length of the packet ๐
note that the most significant bit is the left-most bit, called bit 7. a mask for this bit is 0x80 in hexadecimal ๐ข
+---------------+
PTag |7 6 5 4 3 2 1 0|
+---------------+
Bit 7 -- Always one
Bit 6 -- New packet format if set
PGP 2.6.x only uses old format packets. so software that interoperates with those versions of PGP must only use old format packets ๐. if interop isn't an issue, either format may be used. just know that old format packets have four bits of content tags, and new format packets have six, so some features can't be used and still be backward-compatible ๐ซ
old format packets contain:
Bits 5-2 -- content tag
Bits 1-0 - length-type
new format packets contain:
Bits 5-0 -- content tag
4.2.1. Old-Format Packet Lengths ๐
here's what the length-type means in old-format packets:
0- The packet has a one-octet length. The header is 2 octets long.1- The packet has a two-octet length. The header is 3 octets long.2- The packet has a four-octet length. The header is 5 octets long.3- The packet is of indeterminate length. The header is 1 octet long, and the implementation must determine how long the packet is. if the packet is in a file, that means it extends until the end of the file. generally, an implementation SHOULD NOT use indeterminate length packets except where the end of the data is clear from the context. and even then, it's better to use a definite length, or a new-format header ๐ค. the new-format headers described below have a mechanism for precisely encoding data of indeterminate length, so there's a glow-up option ๐
4.2.2. New-Format Packet Lengths ๐ธ
new format packets have four possible ways of encoding length:
- A one-octet Body Length header encodes packet lengths of up to 191 octets.
- A two-octet Body Length header encodes packet lengths of 192 to 8383 octets.
- A five-octet Body Length header encodes packet lengths of up to 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually encodes a four-octet scalar number.)
- When the length of the packet body isn't known in advance by the issuer, Partial Body Length headers encode a packet of indeterminate length, effectively making it a stream ๐
4.2.2.1. One-Octet Lengths 1๏ธโฃ
a one-octet Body Length header encodes a length from 0 to 191 octets. you can spot this type because the one octet value is less than 192. the body length is equal to:
bodyLen = 1st_octet;
4.2.2.2. Two-Octet Lengths โ๏ธ
a two-octet Body Length header encodes a length from 192 to 8383 octets. it's recognized because its first octet is in the range 192 to 223. the body length is equal to:
bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
4.2.2.3. Five-Octet Lengths ๐๏ธ
a five-octet Body Length header is a single octet holding the value 255, followed by a four-octet scalar. the body length is equal to:
bodyLen = (2nd_octet << 24) | (3rd_octet << 16) |
(4th_octet << 8) | 5th_octet
4.2.2.4. Partial Body Lengths ๐งฉ
a Partial Body Length header is one octet long and encodes the length of only part of the data packet. this length is a power of 2, from 1 to 1,073,741,824 (2 to the 30th power). you recognize it by its one octet value being greater than or equal to 224, and less than 255. the partial body length is equal to:
partialBodyLen = 1 << (1st_octet & 0x1f);
each Partial Body Length header is followed by a portion of the packet body data. the Partial Body Length header specifies that portion's length. another length header (one octet, two-octet, or partial) follows that portion. the last length header in the packet MUST NOT be a partial Body Length header ๐ซ. partial Body Length headers may only be used for the non-final parts of the packet ๐โโ๏ธ
4.2.3. Packet Length Examples ๐
these examples show ways new-format packets might encode their lengths ๐ซง
a packet with length 100 may have its length encoded in one octet: 0x64. this is followed by 100 octets of data.
a packet with length 1723 may have its length coded in two octets: 0xC5, 0xFB. this header is followed by the 1723 octets of data.
a packet with length 100000 may have its length encoded in five octets: 0xFF, 0x00, 0x01, 0x86, 0xA0.
it might also be encoded in this octet stream: 0xEF, then the first 32768 octets of data; 0xE1, then the next two octets of data; 0xE0, then the next one octet of data; 0xF0, then the next 65536 octets of data; 0xC5, 0xDD, then the last 1693 octets of data. that's just one possible encoding, and there are lots of variations on the size of the Partial Body Length headers, as long as a regular Body Length header encodes the last portion of the data. also, the last Body Length header can be a zero-length header ๐ค
an implementation MAY use Partial Body Lengths for data packets, whether they're literal, compressed, or encrypted. the first partial length MUST be at least 512 octets long. Partial Body Lengths MUST NOT be used for any other packet types ๐ โโ๏ธ
one more thing: in all of these explanations, the total length of the packet is the length of the header(s) plus the length of the body ๐
4.3. Packet Tags ๐ท๏ธ
the packet tag tells you what type of packet the body holds. old format headers can only have tags less than 16, whereas new format headers can have tags as great as 63. a packet tag must not have the value 0, and the defined tags (in decimal) are:
0 -- Reserved - a packet tag must not have this value
1 -- Public-Key Encrypted Session Key Packet
2 -- Signature Packet
3 -- Symmetric-Key Encrypted Session Key Packet
4 -- One-Pass Signature Packet
5 -- Secret Key Packet
6 -- Public Key Packet
7 -- Secret Subkey Packet
8 -- Compressed Data Packet
9 -- Symmetrically Encrypted Data Packet
10 -- Marker Packet
11 -- Literal Data Packet
12 -- Trust Packet
13 -- User ID Packet
14 -- Public Subkey Packet
60 to 63 -- Private or Experimental Values
5. Packet Types ๐
5.1. Public-Key Encrypted Session Key Packets (Tag 1) ๐โจ
okay bestie, so a Public-Key Encrypted Session Key packet (PKESK) is basically the little envelope that carries the session key used to encrypt a message ๐ You can have zero or more Encrypted Session Key packets (Public-Key or Symmetric-Key) sitting in front of a Symmetrically Encrypted Data Packet, which is the actual encrypted message ๐ The message gets locked with the session key, and then the session key gets locked up inside these PKESK packets. There's one PKESK for every OpenPGP key the message is encrypted to. So when the recipient shows up, they hunt for the session key that's locked to their public key, decrypt it, and then use it to open the message. main character energy, fr ๐
The body of this packet is:
- A one-octet number for the version of the packet type. The version that's currently defined is 3. An implementation should accept a version of 2 but not generate one, since it's the same as V3 in every other way ๐ธ
- An eight-octet key ID of the public key the session key is encrypted to ๐
- A one-octet number for the public key algorithm that was used ๐ง
- A string of octets that is the encrypted session key. This string fills the rest of the packet, and what's inside depends on the public key algorithm ๐ฆ
Algorithm Specific Fields for RSA encryption:
- An MPI (multiprecision integer) holding the RSA encrypted value, which is
m**e mod n.
Algorithm Specific Fields for Elgamal encryption:
- An MPI for the Elgamal (Diffie-Hellman) value
g**k mod p. - An MPI for the Elgamal (Diffie-Hellman) value
m * y**k mod p.
Now here's where the m in those formulas comes from ๐ง First, you prefix the session key with a one-octet algorithm identifier, which names the symmetric algorithm used to encrypt the Symmetrically Encrypted Data Packet that follows. Then you append a two-octet checksum. That checksum is the sum of the session key octets (not counting the algorithm identifier), taken modulo 65536. After that, you pad the whole thing the way PKCS-1 block type 02 [RFC2313] describes, and the result is the m value used in the formulas above ๐ซถ
Note that when an implementation makes several PKESKs from one session key, so the same message can be decrypted by several keys, the implementation MUST make new PKCS-1 padding for each key. no shortcuts, bestie ๐ โโ๏ธ
An implementation MAY accept or use a Key ID of zero as a "wild card" or "speculative" Key ID. In that case, the receiver tries all of its available private keys and checks for a valid decrypted session key. Honestly this format is iconic because it helps reduce traffic analysis of messages ๐ต๏ธโโ๏ธโจ
5.2. Signature Packet (Tag 2) โ๏ธ๐
A signature packet describes a binding between a public key and some data. The most common ones are a signature on a file or a block of text, and a signature that certifies a user ID ๐
There are two versions of signature packets. Version 3 gives you basic signature info, while version 4 is an expandable format with subpackets that can say a lot more about the signature ๐ PGP 2.6.x only accepts version 3 signatures, so it's giving old-school ๐ฐ๏ธ
Implementations MUST accept V3 signatures. Implementations SHOULD generate V4 signatures. Implementations MAY generate a V3 signature that PGP 2.6.x can verify ๐
Note that if you're creating an encrypted and signed message that's encrypted to a V3 key, it's reasonable to create a V3 signature. makes sense, periodt ๐
5.2.1. Signature Types ๐ฆ
A signature's signature type octet tells you what that signature means. Here are the possible meanings:
0x00: Signature of a binary document. Usually this means the signer owns it, created it, or certifies that it hasn't been changed ๐ฆ0x01: Signature of a canonical text document. Usually this means the signer owns it, created it, or certifies that it hasn't been changed. The signature is calculated over the text with its line endings converted to<CR><LF>and trailing blanks removed ๐0x02: Standalone signature. This one is a signature of only its own subpacket contents. It's calculated the same way as a signature over a zero-length binary document. Also, it doesn't make sense to have a V3 standalone signature ๐0x10: Generic certification of a User ID and Public Key packet. The issuer doesn't make any particular claim about how well they checked that the key owner is really the person in the user ID. Note that all PGP "key signatures" are this type of certification ๐0x11: Persona certification of a User ID and Public Key packet. The issuer hasn't verified at all that the key owner is the person named in the user ID ๐0x12: Casual certification of a User ID and Public Key packet. The issuer did some casual verification of the identity claim ๐ธ0x13: Positive certification of a User ID and Public Key packet. The issuer did substantial verification of the identity claim ๐ช
Please note that the vagueness in these certification claims is not a flaw, it's a feature ๐ซถ PGP puts final authority for validity in the hands of the receiver, so one authority's casual certification might actually be more rigorous than another authority's positive certification. These classes let a certification authority make fine-grained claims, which is honestly so smart โจ
0x18: Subkey Binding Signature. This is a statement by the top-level signing key that it owns the subkey. It's calculated directly on the subkey itself, not on any User ID or other packets ๐0x1F: Signature directly on a key. This is calculated directly on a key. It binds the information in the signature subpackets to the key, which makes it right for subpackets that tell you about the key, like the revocation key subpacket. It also fits statements that non-self certifiers want to make about the key itself, rather than about the link between a key and a name ๐๏ธ0x20: Key revocation signature. This is calculated directly on the key being revoked. A revoked key is not to be used. Only revocation signatures from the key being revoked, or from an authorized revocation key, should be considered valid revocation signatures ๐ซ0x28: Subkey revocation signature. This is calculated directly on the subkey being revoked. A revoked subkey is not to be used. Only revocation signatures from the top-level signature key bound to this subkey, or from an authorized revocation key, should be considered valid revocation signatures ๐0x30: Certification revocation signature. This one revokes an earlier user ID certification signature (signature classes0x10through0x13). It should be issued by the same key that issued the revoked signature, or by an authorized revocation key. The signature should have a later creation date than the signature it revokes ๐0x40: Timestamp signature. This signature is only meaningful for the timestamp it contains โฐ
5.2.2. Version 3 Signature Packet Format ๐งพ
The body of a version 3 Signature Packet contains:
- A one-octet version number (3).
- A one-octet length of the following hashed material. It MUST be 5.
- A one-octet signature type.
- A four-octet creation time.
- An eight-octet key ID of the signer ๐
- A one-octet public key algorithm.
- A one-octet hash algorithm.
- A two-octet field holding the left 16 bits of the signed hash value.
- One or more multi-precision integers that make up the signature. This part depends on the algorithm, as described below ๐งฎ
The data being signed gets hashed first. Then the signature type and creation time from the signature packet get hashed too, which adds 5 more octets. The resulting hash value is what goes into the signature algorithm. The high 16 bits (the first two octets) of the hash are included in the signature packet, so a receiver can quickly reject some invalid signatures ๐
Algorithm Specific Fields for RSA signatures:
- An MPI holding the RSA signature value, which is
m**d.
Algorithm Specific Fields for DSA signatures:
- An MPI for the DSA value
r. - An MPI for the DSA value
s.
The signature calculation is based on a hash of the signed data, as described above. The details differ between DSA and RSA signatures ๐ท
With RSA signatures, the hash value is encoded as described in PKCS-1 section 10.1.2, "Data encoding", which produces an ASN.1 value of type DigestInfo. That value then gets padded using PKCS-1 block type 01 [RFC2313]. To do this, the hash value has to be inserted as an octet string into an ASN.1 structure, and the structure includes the object identifier for the hash type being used. Here are the hexadecimal representations for the hash algorithms that are currently defined:
MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02
MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05
RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01
SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A
And here are the ASN.1 OIDs:
MD2: 1.2.840.113549.2.2
MD5: 1.2.840.113549.2.5
RIPEMD-160: 1.3.36.3.2.1
SHA-1: 1.3.14.3.2.26
The full hash prefixes for these are:
MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86,
0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00,
0x04, 0x10
MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86,
0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00,
0x04, 0x10
RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24,
0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14
SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E,
0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14
DSA signatures MUST use hashes with a size of 160 bits, to match q, the size of the group generated by the DSA key's generator value. The hash function result is treated as a 160-bit number and used directly in the DSA signature algorithm ๐ฅ
5.2.3. Version 4 Signature Packet Format โจ
okay so the body of a version 4 Signature Packet has these fields, in this order ๐
- One-octet version number (4).
- One-octet signature type.
- One-octet public key algorithm.
- One-octet hash algorithm.
- Two-octet scalar octet count for following hashed subpacket
data. Note that this is the length in octets of all of the hashed
subpackets; a pointer incremented by this number will skip over
the hashed subpackets.
- Hashed subpacket data. (zero or more subpackets)
- Two-octet scalar octet count for following unhashed subpacket
data. Note that this is the length in octets of all of the
unhashed subpackets; a pointer incremented by this number will
skip over the unhashed subpackets.
- Unhashed subpacket data. (zero or more subpackets)
- Two-octet field holding left 16 bits of signed hash value.
- One or more multi-precision integers comprising the signature.
This portion is algorithm specific, as described above.
so here's the vibe: the data being signed gets hashed, and then the signature data from the version number through the hashed subpacket data (inclusive) gets hashed too ๐ฅ the resulting hash value is what actually gets signed. the left 16 bits of that hash get tucked into the signature packet as a quick test to reject some invalid signatures, which is honestly so smart ๐ง
there are two fields made of signature subpackets. the first one is hashed along with the rest of the signature data, and the second one is unhashed. the second set isn't cryptographically protected by the signature, so it should only hold advisory information ๐ซถ
the algorithms for turning the hash function result into a signature are described in a section below ๐ฆ
5.2.3.1. Signature Subpacket Specification
the subpacket fields are zero or more signature subpackets, and each set of subpackets is preceded by a two-octet scalar count of the length of that set ๐
each subpacket has a subpacket header and a body. the header is made of:
- the subpacket length (1, 2, or 5 octets)
- the subpacket type (1 octet)
and then the subpacket-specific data comes right after ๐
the length includes the type octet but not this length. the format is similar to the "new" format packet header lengths, but it cannot have partial body lengths. basically:
if the 1st octet < 192, then
lengthOfLength = 1
subpacketLen = 1st_octet
if the 1st octet >= 192 and < 255, then
lengthOfLength = 2
subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
if the 1st octet = 255, then
lengthOfLength = 5
subpacket length = [four-octet scalar starting at 2nd_octet]
the subpacket type octet can be any of these values ๐
2 = signature creation time
3 = signature expiration time
4 = exportable certification
5 = trust signature
6 = regular expression
7 = revocable
9 = key expiration time
10 = placeholder for backward compatibility
11 = preferred symmetric algorithms
12 = revocation key
16 = issuer key ID
20 = notation data
21 = preferred hash algorithms
22 = preferred compression algorithms
23 = key server preferences
24 = preferred key server
25 = primary user id
26 = policy URL
27 = key flags
28 = signer's user id
29 = reason for revocation
100 to 110 = internal or user-defined
if an implementation runs into a subpacket of a type it doesn't recognize, it SHOULD ignore that subpacket ๐ that's the rule, no drama.
bit 7 of the subpacket type is the "critical" bit ๐จ if it's set, the subpacket is one that's critical for the evaluator of the signature to recognize. if a critical-marked subpacket shows up and the evaluating software doesn't know it, the evaluator SHOULD consider the signature to be in error. so serious, I'm obsessed.
an evaluator can "recognize" a subpacket without actually implementing it. the whole point of the critical bit is that the signer can tell an evaluator "hey, I'd rather you throw an error than ignore this new, unknown feature" ๐ธ
Implementations SHOULD implement "preferences" โจ
5.2.3.2. Signature Subpacket Types
a bunch of subpackets are defined right now. some apply to the signature itself and some are attributes of the key. subpackets found on a self-signature get placed on a user id certification made by the key itself. a key can have more than one user id, so it can also have more than one self-signature, with different subpackets in each one ๐
a self-signature is a binding signature made by the key the signature refers to. there are three types of self-signatures: the certification signatures (types 0x10-0x13), the direct-key signature (type 0x1f), and the subkey binding signature (type 0x18). for certification self-signatures, each user ID may have its own self-signature, so the subpackets can differ between them. for subkey binding signatures, each subkey actually has a self-signature. subpackets that show up in a certification self-signature apply to the username, subpackets in the subkey self-signature apply to the subkey, and subpackets on the direct key signature apply to the entire key ๐ฆ
implementing software should interpret a self-signature's preference subpackets as narrowly as possible, and here's why it's so iconic ๐ say a key has two usernames, Alice and Bob. Alice prefers the symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. if the software finds this key through Alice's name, the preferred algorithm is CAST5. if it finds the key through Bob's name, the preferred algorithm is IDEA. if the key is located by key id, then the algorithm of the default user id of the key provides the default symmetric algorithm ๐
a subpacket can show up in either the hashed or the unhashed subpacket sections of a signature. if a subpacket isn't hashed, the information in it can't be considered definitive, because it isn't part of the signature proper ๐ โโ๏ธ
5.2.3.3. Signature creation time
(4 octet time field)
this is the time the signature was made โฐ
it MUST be present in the hashed area. no exceptions bestie ๐
5.2.3.4. Issuer
(8 octet key ID)
the OpenPGP key ID of the key that issued the signature ๐
5.2.3.5. Key expiration time
(4 octet time field)
this is the validity period of the key. it's the number of seconds after the key creation time that the key expires. if this is not present or has a value of zero, the key never expires. this only shows up on a self-signature ๐ง
5.2.3.6. Preferred symmetric algorithms
(sequence of one-octet values)
these are symmetric algorithm numbers that show which algorithms the key holder prefers to use. the subpacket body is an ordered list of octets, with the most preferred one listed first. it's assumed that only the listed algorithms are supported by the recipient's software. for the algorithm numbers, check section 9. this only shows up on a self-signature ๐ซถ
5.2.3.7. Preferred hash algorithms
(array of one-octet values)
these are message digest algorithm numbers that show which algorithms the key holder prefers to receive. just like the preferred symmetric algorithms, the list is ordered. the algorithm numbers are in section 6. this only shows up on a self-signature ๐
5.2.3.8. Preferred compression algorithms
(array of one-octet values)
these are compression algorithm numbers that show which algorithms the key holder prefers to use. just like the preferred symmetric algorithms, the list is ordered. the algorithm numbers are in section 6. if this subpacket isn't included, ZIP is preferred. a zero means uncompressed data is preferred, and the key holder's software might not have any compression software in that implementation ๐๏ธ this only shows up on a self-signature โจ
5.2.3.9. Signature expiration time
(4 octet time field)
this is the validity period of the signature. it's the number of seconds after the signature creation time that the signature expires. if this is not present or has a value of zero, it never expires ๐ท
5.2.3.10. Exportable Certification
(1 octet of exportability, 0 for not, 1 for exportable)
this subpacket says whether a certification signature is "exportable", which means other users besides the signature's issuer can use it ๐ฆ the packet body holds a boolean flag for whether the signature is exportable. if this packet isn't present, the certification is exportable, which is the same as a flag containing a 1.
non-exportable certifications (also called "local" ones) are signatures a user makes to mark a key as valid inside that user's own implementation only. so when an implementation gets a user's copy of a key ready to send to another user (that's the "exporting" part), any local certification signatures get deleted from the key ๐งน
the receiver of a transported key "imports" it, and likewise trims any local certifications. in normal operation there won't be any, as long as the import happens on an exported key. but there are situations where this can reasonably happen. for example, if an implementation lets keys be imported from a key database as well as from an exported key, then this can come up ๐
some implementations don't represent the interest of a single user (a key server is one example). those implementations always trim local certifications from any key they handle ๐
5.2.3.11. Revocable
(1 octet of revocability, 0 for not, 1 for revocable)
this is the signature's revocability status. the packet body holds a boolean flag for whether the signature is revocable. signatures that aren't revocable have any later revocation signatures ignored. they're a commitment by the signer that they can't revoke the signature for the life of their key, which is a big promise ๐ if this packet isn't present, the signature is revocable.
5.2.3.12. Trust signature
(1 octet "level" (depth), 1 octet of trust amount)
the signer is asserting that the key is not only valid, but also trustworthy, at the specified level ๐ซถ level 0 means the same thing as an ordinary validity signature. level 1 means the signed key is asserted to be a valid trusted introducer, and the 2nd octet of the body specifies the degree of trust. level 2 means the signed key is asserted to be trusted to issue level 1 trust signatures, which makes it a "meta introducer" ๐ in general, a level n trust signature asserts that a key is trusted to issue level n-1 trust signatures.
the trust amount is in a range from 0-255. values less than 120 mean partial trust, and values of 120 or greater mean complete trust. implementations SHOULD emit values of 60 for partial trust and 120 for complete trust ๐
5.2.3.13. Regular expression
(null-terminated regular expression)
this is used together with trust signature packets (of level > 0) to limit the scope of the trust being extended ๐ฅ only signatures by the target key on user IDs that match the regular expression in the body of this packet get trust extended by the trust signature subpacket. the regular expression uses the same syntax as Henry Spencer's "almost public domain" regular expression package. a description of that syntax is in a section below ๐ง
5.2.3.14. Revocation key ๐๏ธ
(1 octet of class, 1 octet of algid, 20 octets of fingerprint)
Okay so this subpacket is basically the "you're allowed to revoke me" pass ๐
. It authorizes the specified key to issue revocation signatures for this key. The class octet must have bit 0x80 set. If bit 0x40 is set, that means the revocation information is sensitive ๐. The other bits are saved for future kinds of permissions ๐ธ. This one lives on a self-signature.
If the "sensitive" flag is set, the keyholder is saying this subpacket holds private trust info about a real-world sensitive relationship ๐คซ. In that case, implementations SHOULD NOT export this signature to other users, except where the data actually needs to be out there: when the signature is being sent to the designated revoker, or when it comes with a revocation signature from that revoker. It may also be appropriate to isolate this subpacket in its own signature, so it isn't bundled with other subpackets that need to be exported ๐ง.
5.2.3.15. Notation Data ๐
(4 octets of flags, 2 octets of name length (M),
2 octets of value length (N),
M octets of name data,
N octets of value data)
This subpacket describes a "notation" that the issuer wants to put on the signature ๐ฆ. A notation has a name and a value, and each one is a string of octets. A signature can hold more than one notation, and they can be used for any extension the issuer cares about. The "flags" field holds four octets of flags.
All undefined flags MUST be zero. The defined flags are:
First octet: 0x80 = human-readable. This note is text, a note
from one person to another, and has no
meaning to software.
Other octets: none.
5.2.3.16. Key server preferences ๐
(N octets of flags)
This is a list of flags that show what the key holder would like to happen to the key on a key server ๐. All undefined flags MUST be zero.
First octet: 0x80 = No-modify
the key holder requests that this key only be modified or updated
by the key holder or an administrator of the key server.
This is found only on a self-signature.
5.2.3.17. Preferred key server ๐
(String)
This is a URL for a key server the key holder would prefer be used for updates โจ. Keys with multiple user ids can have a preferred key server for each user id, which is so iconic. Also, since it's a URL, the key server can actually be a copy of the key fetched by ftp, http, finger, etc. ๐
5.2.3.18. Primary user id ๐
(1 octet, boolean)
This is a flag in a user id's self signature that says whether this user id is the main one for this key ๐. It's reasonable for an implementation to settle preference ambiguities, and so on, by checking the primary user id. If this flag is absent, its value is zero. If more than one user id in a key is marked as primary, the implementation may resolve the ambiguity in any way it sees fit ๐คทโโ๏ธ.
5.2.3.19. Policy URL ๐
(String)
This subpacket holds a URL pointing to a document that describes the policy the signature was issued under ๐ซถ.
5.2.3.20. Key Flags ๐ฉ
(Octet string)
This subpacket holds a list of binary flags with info about a key ๐. It's a string of octets, and an implementation MUST NOT assume a fixed size. That's so it can grow over time, which is giving future-proof energy ๐ฎ. If a list is shorter than an implementation expects, the unstated flags are considered to be zero. The defined flags are:
First octet:
0x01 - This key may be used to certify other keys.
0x02 - This key may be used to sign data.
0x04 - This key may be used to encrypt communications.
0x08 - This key may be used to encrypt storage.
0x10 - The private component of this key may have been split by a
secret-sharing mechanism.
0x80 - The private component of this key may be in the possession
of more than one person.
Usage notes:
The flags in this packet can show up in self-signatures or in certification signatures, and they mean different things depending on who's making the statement ๐ง. For example, a certification signature with the "sign data" flag is saying the certification is for that use. The "communications encryption" flag in a self-signature, though, is stating a preference that a given key be used for communications. Fair warning, it's a thorny issue to decide what counts as "communications" versus "storage" ๐. That decision is left completely up to the implementation. The authors of this document don't claim any special wisdom on the topic, and they realize accepted opinion may change ๐.
The "split key" (0x10) and "group key" (0x80) flags go on a self-signature only. They're meaningless on a certification signature ๐
โโ๏ธ. They SHOULD be placed only on a direct-key signature (type 0x1f) or a subkey signature (type 0x18), meaning one that refers to the key the flag applies to ๐.
5.2.3.21. Signer's User ID ๐ญ
This subpacket lets a keyholder say which user id is responsible for the signing ๐ . Lots of keyholders use one key for different things, like business communications and personal ones. This subpacket lets them say which of their roles is making a given signature ๐.
5.2.3.22. Reason for Revocation ๐ฅ
(1 octet of revocation code, N octets of reason string)
This subpacket is only used in key revocation and certification revocation signatures ๐. It describes why the key or certificate was revoked.
The first octet holds a machine-readable code for the reason:
0x00 - No reason specified (key revocations or cert revocations)
0x01 - Key is superceded (key revocations)
0x02 - Key material has been compromised (key revocations)
0x03 - Key is no longer used (key revocations)
0x20 - User id information is no longer valid (cert revocations)
After the revocation code comes a string of octets that explains the reason in human-readable form (UTF-8) โ๏ธ. The string may be null, meaning zero length. The length of the subpacket is the length of the reason string plus one ๐งฎ.
5.2.4. Computing Signatures ๐ง
All signatures are formed by hashing the signature data, and then using the resulting hash in the signature algorithm ๐ฅ.
The signature data is simple to work out for document signatures (types 0x00 and 0x01), where the document itself is the data ๐. For standalone signatures, it's a null string.
When a signature is made over a key, the hash data starts with the octet 0x99, followed by a two-octet length of the key, and then the body of the key packet. (Note that this is an old-style packet header for a key packet with a two-octet length ๐ค.) A subkey signature (type 0x18) then hashes the subkey, using the same format as the main key. Key revocation signatures (types 0x20 and 0x28) hash only the key being revoked ๐.
A certification signature (types 0x10 through 0x13) hashes the user id being bound to the key into the hash context, after the data above. A V3 certification hashes the contents of the name packet, without any header ๐. A V4 certification hashes the constant 0xb4 (which is an old-style packet header with the length-of-length set to zero), a four-octet number giving the length of the username, and then the username data ๐ซ .
Once the data body is hashed, a trailer gets hashed too ๐ฌ. A V3 signature hashes five octets of the packet body, starting from the signature type field. That data is the signature type, followed by the four-octet signature time. A V4 signature hashes the packet body starting from its first field, the version number, through the end of the hashed subpacket data. So the fields hashed are the signature version, the signature type, the public key algorithm, the hash algorithm, the hashed subpacket length, and the hashed subpacket body ๐ง .
V4 signatures also hash in a final trailer of six octets: the version of the signature packet, i.e. 0x04; 0xFF; and a four-octet, big-endian number that is the length of the hashed data from the signature packet (note that this number does not include these final six octets ๐ท.
After all of this has been hashed, the resulting hash field is used in the signature algorithm and placed at the end of the signature packet โ .
5.2.4.1. Subpacket Hints ๐ก
An implementation SHOULD put the two mandatory subpackets, creation time and issuer, first in the subpacket list, just to make them easier for the implementer to find ๐.
It's totally possible for a signature to contain conflicting info in its subpackets ๐ต. For example, a signature may contain multiple copies of a preference or multiple expiration times. In most cases, an implementation SHOULD use the last subpacket in the signature, but it MAY use any conflict resolution scheme that makes more sense. Please note that conflict resolution is intentionally left to the implementer ๐ซถ. Most conflicts are simply syntax errors, and this wishy-washy language lets a receiver be generous in what it accepts, while putting pressure on a creator to be stingy in what it generates ๐งโโ๏ธ.
Some apparent conflicts may actually make sense ๐. For example, suppose a keyholder has a V3 key and a V4 key that share the same RSA key material. Either key can verify a signature created by the other, so it may be reasonable for a signature to contain an issuer subpacket for each key, as a way of explicitly tying those keys to the signature ๐ฏโโ๏ธ.
5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) ๐
okay so this packet is the bestie who holds a session key and locks it up with a symmetric algorithm ๐ The Symmetric-Key Encrypted Session Key packet holds the symmetric-key encryption of a session key used to encrypt a message. Zero or more Encrypted Session Key packets and/or Symmetric-Key Encrypted Session Key packets can come before a Symmetrically Encrypted Data Packet that holds an encrypted message. The message gets encrypted with a session key, and that session key is itself encrypted and stored in either the Encrypted Session Key packet or the Symmetric-Key Encrypted Session Key packet. Iconic energy ๐
If the Symmetrically Encrypted Data Packet is preceded by one or more Symmetric-Key Encrypted Session Key packets, each one specifies a passphrase that may be used to decrypt the message. This means one message can be encrypted to a bunch of public keys AND to one or more pass phrases, which is so clever ๐ง This packet type is new, and it is not generated by PGP 2.x or PGP 5.0 ๐ธ
The body of this packet is made up of:
- A one-octet version number. The only currently defined version is 4.
- A one-octet number describing the symmetric algorithm used.
- A string-to-key (S2K) specifier, length as defined above.
- Optionally, the encrypted session key itself, which is decrypted with the string-to-key object.
If the encrypted session key is not present (you can tell by the packet length and the S2K specifier size), then the S2K algorithm applied to the passphrase produces the session key for decrypting the file. It uses the symmetric cipher algorithm from the Symmetric-Key Encrypted Session Key packet โจ
If the encrypted session key is present, the result of applying the S2K algorithm to the passphrase is used to decrypt just that encrypted session key field. This happens in CFB mode with an IV of all zeros. The decryption result is a one-octet algorithm identifier, which says what symmetric-key encryption algorithm was used on the following Symmetrically Encrypted Data Packet, followed by the session key octets themselves ๐ฆ
Note: because an all-zero IV is used for this decryption, the S2K specifier MUST use a salt value, either a Salted S2K or an Iterated-Salted S2K. The salt value will insure that the decryption key is not repeated even if the passphrase is reused. ๐จ this is the part you do not skip, bestie ๐
5.4. One-Pass Signature Packets (Tag 4) ๐ฆ
The One-Pass Signature packet comes before the signed data and has enough info for the receiver to start calculating any hashes needed to verify the signature. It lets the Signature Packet sit at the end of the message, so the signer can compute the entire signed message in one pass. Main character energy, literally ๐
A One-Pass Signature does not interoperate with PGP 2.6.x or earlier ๐
The body of this packet is made up of:
- A one-octet version number. The current version is 3.
- A one-octet signature type. Signature types are described in section 5.2.1.
- A one-octet number describing the hash algorithm used.
- A one-octet number describing the public key algorithm used.
- An eight-octet number holding the key ID of the signing key.
- A one-octet number holding a flag showing whether the signature is nested. A zero value indicates that the next packet is another One-Pass Signature packet that describes another signature to be applied to the same message data.
Note that if a message contains more than one one-pass signature, then the signature packets bracket the message. That means the first signature packet after the message corresponds to the last one-pass packet, and the final signature packet corresponds to the first one-pass packet. It's giving nested doll energy ๐ช
5.5. Key Material Packet ๐
A key material packet contains all the information about a public or private key. There are four variants of this packet type, and two major versions. Consequently, this section is complex ๐ญ but we're gonna get through it together, bestie ๐ซถ
5.5.1. Key Packet Variants ๐
5.5.1.1. Public Key Packet (Tag 6)
A Public Key packet starts a series of packets that forms an OpenPGP key (sometimes called an OpenPGP certificate) โจ
5.5.1.2. Public Subkey Packet (Tag 14)
A Public Subkey packet (tag 14) has exactly the same format as a Public Key packet, but it denotes a subkey. One or more subkeys may be associated with a top-level key. By convention, the top-level key provides signature services, and the subkeys provide encryption services ๐
Note: in PGP 2.6.x, tag 14 was intended to indicate a comment packet. This tag was picked for reuse because no previous version of PGP ever emitted comment packets, but they did properly ignore them. Public Subkey packets are ignored by PGP 2.6.x and do not cause it to fail, which gives a limited degree of backward compatibility ๐ฅน
5.5.1.3. Secret Key Packet (Tag 5)
A Secret Key packet contains all the information that is found in a Public Key packet, including the public key material. It also includes the secret key material after all the public key fields ๐คซ
5.5.1.4. Secret Subkey Packet (Tag 7)
A Secret Subkey packet (tag 7) is the subkey analog of the Secret Key packet, and it has exactly the same format ๐ง
5.5.2. Public Key Packet Formats ๐
There are two versions of key-material packets. Version 3 packets were first generated by PGP 2.6. Version 2 packets are identical in format to Version 3 packets, but they were generated by PGP 2.5 or before. V2 packets are deprecated and they MUST NOT be generated. PGP 5.0 introduced version 4 packets, with new fields and semantics. PGP 2.6.x will not accept key-material packets with versions greater than 3 ๐ โโ๏ธ
OpenPGP implementations SHOULD create keys with version 4 format. An implementation MAY generate a V3 key to ensure interoperability with old software. Note, however, that V4 keys correct some security deficiencies in V3 keys, and those deficiencies are described below. An implementation MUST NOT create a V3 key with a public key algorithm other than RSA ๐ฅ
A version 3 public key or public subkey packet contains:
- A one-octet version number (3).
- A four-octet number denoting the time that the key was created.
- A two-octet number denoting the time in days that this key is valid. If this number is zero, then it does not expire.
- A one-octet number denoting the public key algorithm of this key.
- A series of multi-precision integers comprising the key material:
- a multiprecision integer (MPI) of RSA public modulus n;
- an MPI of RSA public encryption exponent e.
V3 keys SHOULD only be used for backward compatibility, because of three weaknesses in them ๐ First, it is relatively easy to construct a V3 key that has the same key ID as any other key, because the key ID is simply the low 64 bits of the public modulus. Secondly, the fingerprint of a V3 key hashes the key material but not its length, which increases the opportunity for fingerprint collisions. Third, there are minor weaknesses in the MD5 hash algorithm that make developers prefer other algorithms. See below for a fuller discussion of key IDs and fingerprints ๐
The version 4 format is similar to the version 3 format, except for the absence of a validity period. This has been moved to the signature packet. In addition, fingerprints of version 4 keys are calculated differently from version 3 keys, as described in section "Enhanced Key Formats" ๐ธ
A version 4 packet contains:
- A one-octet version number (4).
- A four-octet number denoting the time that the key was created.
- A one-octet number denoting the public key algorithm of this key.
- A series of multi-precision integers comprising the key material. This algorithm-specific portion is:
Algorithm Specific Fields for RSA public keys:
- multiprecision integer (MPI) of RSA public modulus n;
- MPI of RSA public encryption exponent e.
Algorithm Specific Fields for DSA public keys:
- MPI of DSA prime p;
- MPI of DSA group order q (q is a prime divisor of p-1);
- MPI of DSA group generator g;
- MPI of DSA public key value y (= g**x where x is secret).
Algorithm Specific Fields for Elgamal public keys:
- MPI of Elgamal prime p;
- MPI of Elgamal group generator g;
- MPI of Elgamal public key value y (= g**x where x is secret).
5.5.3. Secret Key Packet Formats ๐๏ธ
The Secret Key and Secret Subkey packets contain all the data of the Public Key and Public Subkey packets, with additional algorithm-specific secret key data appended, in encrypted form ๐
The packet contains:
- A Public Key or Public Subkey packet, as described above.
- One octet indicating string-to-key usage conventions. 0 indicates that the secret key data is not encrypted. 255 indicates that a string-to-key specifier is being given. Any other value is a symmetric-key encryption algorithm specifier.
- [Optional] If string-to-key usage octet was 255, a one-octet symmetric encryption algorithm.
- [Optional] If string-to-key usage octet was 255, a string-to-key specifier. The length of the string-to-key specifier is implied by its type, as described above.
- [Optional] If secret data is encrypted, an eight-octet Initial Vector (IV).
- Encrypted multi-precision integers comprising the secret key data. These algorithm-specific fields are as described below.
- A two-octet checksum of the plaintext of the algorithm-specific portion (sum of all octets, mod 65536).
Algorithm Specific Fields for RSA secret keys:
- multiprecision integer (MPI) of RSA secret exponent d.
- MPI of RSA secret prime value p.
- MPI of RSA secret prime value q (p < q).
- MPI of u, the multiplicative inverse of p, mod q.
Algorithm Specific Fields for DSA secret keys:
- MPI of DSA secret exponent x.
Algorithm Specific Fields for Elgamal secret keys:
- MPI of Elgamal secret exponent x.
Secret MPI values can be encrypted using a passphrase. If a string-to-key specifier is given, it describes the algorithm for converting the passphrase to a key. Otherwise, a simple MD5 hash of the passphrase is used. Implementations SHOULD use a string-to-key specifier; the simple hash is there for backward compatibility. The cipher for encrypting the MPIs is specified in the secret key packet ๐ง
Encryption and decryption of the secret data is done in CFB mode, using the key created from the passphrase and the Initial Vector from the packet. A different mode is used with V3 keys (which are only RSA) than with other key formats. With V3 keys, the MPI bit count prefix (that's the first two octets) is not encrypted. Only the MPI non-prefix data is encrypted. Furthermore, the CFB state is resynchronized at the beginning of each new MPI value, so that the CFB block boundary is aligned with the start of the MPI data ๐งฉ
With V4 keys, a simpler method is used. All secret MPI values are encrypted in CFB mode, including the MPI bitcount prefix โจ
The 16-bit checksum that follows the algorithm-specific portion is the algebraic sum, mod 65536, of the plaintext of all the algorithm-specific octets (including MPI prefix and data). With V3 keys, the checksum is stored in the clear. With V4 keys, the checksum is encrypted like the algorithm-specific data. This value is used to check that the passphrase was correct ๐ฅณ
5.6. Compressed Data Packet (Tag 8) ๐
okay so the Compressed Data packet is literally a box of compressed data ๐ฆโจ Usually you'll find it inside an encrypted packet, or right after a Signature or One-Pass Signature packet, and the stuff inside is typically literal data packets. ngl it's giving neat little gift wrap ๐
The body has two parts:
- One octet that tells you which algorithm was used to compress the packet. ๐๏ธ
- Everything after that is the compressed data itself. ๐
A Compressed Data Packet's body holds a block that compresses some set of packets. For how the messages actually get put together, check out the section "Packet Composition" ๐งฉ
Now the algorithm bit, bestie ๐ ZIP-compressed packets use raw DEFLATE blocks from [RFC1951]... no wait, it's cited in the text as RFC 1951, so raw RFC 1951 DEFLATE blocks ๐ธ And here's the tea: PGP V2.6 only does 13 bits of compression. If your implementation uses more bits than that, PGP V2.6 is not able to decompress it ๐ Oof, so be careful about that one.
ZLIB-compressed packets use RFC 1950 ZLIB-style blocks instead ๐ฆ
5.7. Symmetrically Encrypted Data Packet (Tag 9) ๐
The Symmetrically Encrypted Data packet holds data that's been encrypted with a symmetric-key algorithm. Once it's decrypted, it'll usually have other packets inside it, like literal data packets or compressed data packets ๐
The body of this packet is:
- The encrypted data, which is the output of the chosen symmetric-key cipher running in PGP's own flavour of Cipher Feedback (CFB) mode. ๐
Okay, here's where it gets spicy ๐ถ๏ธ The symmetric cipher can be named in a Public-Key or Symmetric-Key Encrypted Session Key packet that comes right before this one. When that happens, the cipher algorithm octet gets stuck onto the front of the session key before the session key is encrypted. If there aren't any packets of those types in front of the encrypted data, the IDEA algorithm gets used, with the session key worked out as the MD5 hash of the passphrase ๐
The data is encrypted in CFB mode, and the CFB shift size matches the cipher's block size. The Initial Vector (IV) is all zeros. Instead of using an IV, OpenPGP sticks a 10-octet string onto the front of the data before encrypting it. The first eight octets are random, and the 9th and 10th octets are copies of the 7th and 8th octets, in that order ๐ง After those first 10 octets get encrypted, the CFB state gets resynchronized, but only if the cipher block size is 8 octets or less. The last 8 octets of ciphertext get run through the cipher, and then the block boundary is reset โจ
That repeated 16 bits hiding inside the 80 bits of random data at the front is so clever ๐ญ It lets the receiver instantly check whether the session key is wrong.
5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) ๐
An experimental version of PGP used this packet as the Literal packet, but no released version of PGP ever made Literal packets with this tag. With PGP 5.x, the tag got reassigned and is now reserved for the Marker packet ๐ซถ
The body of this packet is:
- The three octets 0x50, 0x47, 0x50, which spell "PGP" in UTF-8. ๐
Such a packet MUST be ignored when received. Lowkey iconic, though: it can be placed at the beginning of a message that uses features PGP 2.6.x doesn't have, so that version reports that newer software is needed to process the message ๐ฆ
5.9. Literal Data Packet (Tag 11) ๐
A Literal Data packet holds the body of a message: data that isn't meant to be interpreted any further ๐
The body of this packet is:
- A one-octet field that says how the data is formatted. ๐
If that octet is 'b' (0x62), the literal packet holds binary data. If it's 't' (0x74), it holds text data, which may need its line ends converted to the local form or have other text-mode changes applied ๐ RFC 1991 also defined 'l' as a 'local' mode for machine-local conversions, but that's deprecated now ๐ โโ๏ธ
- The file name as a string (one-octet length, then the file name), if the encrypted data should be saved as a file. ๐
If the special name "_CONSOLE" is used, the message is treated as "for your eyes only" ๐ This basically means the message data is super sensitive, so the receiving program should handle it more carefully, maybe by not saving the received data to disk, for example. Main character security energy ๐ค
- A four-octet number giving the modification date of the file, or the creation time of the packet, or a zero, which means the present time โฐ
- The rest of the packet is the literal data itself. โจ
Text data is stored with <CR><LF> text endings, which are the network-normal line endings. The receiving software should convert these to native line endings ๐
5.10. Trust Packet (Tag 12) ๐
The Trust packet is only used inside keyrings and isn't normally exported. These packets hold data that records the user's choices about which key holders are trustworthy introducers, along with other info that implementing software uses for trust decisions ๐
Trust packets SHOULD NOT be emitted to output streams that get transferred to other users, and they SHOULD be ignored on any input other than local keyring files. Keep these private, bestie ๐คซ
5.11. User ID Packet (Tag 13) ๐ซถ
A User ID packet holds data meant to represent the name and email address of the key holder. By convention it includes an RFC 822 mail name, but there are no restrictions on what it contains ๐ธ The packet length in the header tells you how long the user ID is. If it's text, it's encoded in UTF-8 ๐
6. Radix-64 Conversions ๐ฆ
As we said in the introduction, OpenPGP's native representation for objects is a stream of arbitrary octets, and some systems need these objects to be immune to damage from character set translation, data conversions, and so on ๐
In principle, any printable encoding scheme that met the requirements of the unsafe channel would work, since it wouldn't change the underlying binary bit streams of the native OpenPGP data structures. The OpenPGP standard specifies one such printable encoding scheme so everyone stays interoperable ๐
OpenPGP's Radix-64 encoding has two parts: a base64 encoding of the binary data, and a checksum โจ The base64 encoding is identical to the MIME base64 content-transfer-encoding [RFC2231, Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to protect the raw binary data ๐
The checksum is a 24-bit CRC, converted to four characters of radix-64 encoding by the same MIME base64 transformation, and it's preceded by an equals sign (=). The CRC is computed using the generator 0x864CFB and an initialization of 0xB704CE. The accumulation happens on the data before it gets converted to radix-64, not on the converted data ๐งฎ A sample implementation of this algorithm is in the next section ๐
The checksum with its leading equal sign MAY appear on the first line after the Base64 encoded data ๐ธ
Why 24 bits? Because 24 bits fits evenly into printable base64 ๐ And the nonzero initialization can detect more errors than a zero initialization would ๐ฅ
6.1. An Implementation of the CRC-24 in "C" ๐ง
#define CRC24_INIT 0xb704ceL
#define CRC24_POLY 0x1864cfbL
typedef long crc24;
crc24 crc_octets(unsigned char *octets, size_t len)
{
crc24 crc = CRC24_INIT;
int i;
while (len--) {
crc ^= (*octets++) << 16;
for (i = 0; i < 8; i++) {
crc <<= 1;
if (crc & 0x1000000)
crc ^= CRC24_POLY;
}
}
return crc & 0xffffffL;
}
6.2. Forming ASCII Armor ๐
okay so when OpenPGP armors data ๐ฆ, it wraps the data in special headers so it can rebuild everything on the other end. The headers also tell the user what kind of data is inside. it's giving organization โจ
Putting an ASCII Armor together means concatenating these pieces, in this order:
- An Armor Header Line that fits the type of data
- Armor Headers
- A blank line (zero-length, or only whitespace) ๐ธ
- The ASCII-Armored data
- An Armor Checksum
- The Armor Tail, which depends on the Armor Header Line
An Armor Header Line is the header line text wrapped in five (5) dashes (-, 0x2D) on each side. The text depends on what kind of data is being armored and how it's being encoded. These are the header line texts:
BEGIN PGP MESSAGE: used for signed, encrypted, or compressed files. ๐BEGIN PGP PUBLIC KEY BLOCK: used for armoring public keys ๐BEGIN PGP PRIVATE KEY BLOCK: used for armoring private keys ๐BEGIN PGP MESSAGE, PART X/Y: used for multi-part messages, where the armor is split across Y parts, and this is part X out of Y. ๐งฉBEGIN PGP MESSAGE, PART X: used for multi-part messages where this is part X of an unspecified number of parts. This one requires the MESSAGE-ID Armor Header to be used. ๐BEGIN PGP SIGNATURE: used for detached signatures, OpenPGP/MIME signatures, and signatures following clearsigned messages. Note that PGP 2.x s BEGIN PGP MESSAGE for detached signatures. โ๏ธ
The Armor Headers are key-value pairs that can give the user, or the receiving OpenPGP implementation, some info about how to decode or use the message. They're part of the armor, not part of the message, so no signatures applied to the message protect them. lowkey important to know ๐ง
Each header is a key and a value, separated by a colon (:, 0x38) and a single space (0x20). If OpenPGP sees an Armor Header that's formatted wrong, it should treat that as corruption of the ASCII Armor ๐. Unknown keys should be reported to the user, but OpenPGP should keep processing the message anyway.
These are the Armor Header Keys defined so far:
- "Version", which states the OpenPGP version used to encode the message. ๐ท๏ธ
- "Comment", a user-defined comment. ๐ฌ
- "MessageID", a 32-character string of printable characters. The string must be the same for every part of a multi-part message that uses the "PART X" Armor Header. MessageID strings should be unique enough that the recipient can tie all the parts of a message together. A good checksum or cryptographic hash function is enough for this. ๐
- "Hash", a comma-separated list of the hash algorithms used in this message. This is only used in clear-signed messages. โจ
- "Charset", a description of the character set the plaintext is in. OpenPGP defines text to be UTF-8 by default, and an implementation gets the best results by translating into and out of UTF-8. Easier said than done though! Some communities are happy with something like ISO Latin-5 or a Japanese character set and have no need for UTF-8. In those cases an implementation MAY override the UTF-8 default by using this header key. An implementation MAY implement this key and any translations it cares to, and an implementation MAY ignore it and assume all text is UTF-8. ๐
The MessageID SHOULD NOT appear unless it's in a multi-part message. If it shows up at all, it MUST be computed from the finished (encrypted, signed, etc.) message in a deterministic way, not be a purely random value. The point is that the legitimate recipient can confirm the MessageID can't be used as a sneaky way to leak cryptographic key information ๐ต๏ธโโ๏ธ. no thoughts, just security vibes
The Armor Tail Line is built the same way as the Armor Header Line, except the string "BEGIN" gets swapped for "END." ๐ซถ
6.3. Encoding Binary in Radix-64 ๐
okay the encoding process takes 24-bit groups of input bits and turns each one into 4 encoded characters ๐ง. You go left to right, and a 24-bit input group is made by sticking three 8-bit input groups together. Those 24 bits get split into four 6-bit groups, and each 6-bit group becomes one digit in the Radix-64 alphabet. When you encode a bit stream, it has to be treated as most-significant-bit first. So the first bit in the stream is the high-order bit of the first octet, and the eighth bit is the low-order bit of that same octet, and so on. the way that this keeps everything in order is so satisfying ๐ญ
+--first octet--+-second octet--+--third octet--+
|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|
+-----------+---+-------+-------+---+-----------+
|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|
+--1.index--+--2.index--+--3.index--+--4.index--+
Each 6-bit group is used as an index into an array of 64 printable characters, from the table below. The character that index points to goes into the output string. ๐
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
The encoded output stream must be represented in lines of no more than 76 characters each. ๐
Some special processing happens if there are fewer than 24 bits left at the end of the data. There are three possibilities:
- The last data group has 24 bits (3 octets). No special processing is needed. โ
- The last data group has 16 bits (2 octets). The first two 6-bit groups are processed as above. The third (incomplete) data group has two zero-value bits added to it, and is processed as above. A pad character (
=) is added to the output. ๐ฉท - The last data group has 8 bits (1 octet). The first 6-bit group is processed as above. The second (incomplete) data group has four zero-value bits added to it, and is processed as above. Two pad characters (
=) are added to the output. ๐
6.4. Decoding Radix-64 ๐
Any characters outside the base64 alphabet get ignored in Radix-64 data. Decoding software must ignore all line breaks and any other characters not found in the table above. ๐
In Radix-64 data, characters other than those in the table, plus line breaks and other white space, probably mean there was a transmission error ๐จ. A warning message, or even rejecting the message, might be appropriate in some situations.
Because = is only used for padding at the end of the data, seeing any = characters can be taken as evidence that the end of the data was reached without truncation in transit. โจ No such assurance is possible, though, when the number of octets transmitted was a multiple of three and no = characters are present. so don't trust vibes alone ๐
6.5. Examples of Radix-64 ๐ฆ
Here's the first example, with the input data 0x14fb9c03d97e broken down step by step ๐งฎ:
Input data: 0x14fb9c03d97e
Hex: 1 4 f b 9 c | 0 3 d 9 7 e
8-bit: 00010100 11111011 10011100 | 00000011 11011001
11111110
6-bit: 000101 001111 101110 011100 | 000000 111101 100111
111110
Decimal: 5 15 46 28 0 61 37 62
Output: F P u c A 9 l +
And here's the second example, with the input 0x14fb9c03d9. The last group only has one octet, so it gets padded with zeros, and the output gets an = ๐ธ:
Input data: 0x14fb9c03d9
Hex: 1 4 f b 9 c | 0 3 d 9
8-bit: 00010100 11111011 10011100 | 00000011 11011001
pad with 00
6-bit: 000101 001111 101110 011100 | 000000 111101 100100
Decimal: 5 15 46 28 0 61 36
pad with =
Output: F P u c A 9 k =
And the third example, with the input 0x14fb9c03. Here the last group has two leftover bits to pad, so the output gets two = characters ๐
:
Input data: 0x14fb9c03
Hex: 1 4 f b 9 c | 0 3
8-bit: 00010100 11111011 10011100 | 00000011
pad with 0000
6-bit: 000101 001111 101110 011100 | 000000 110000
Decimal: 5 15 46 28 0 48
pad with = =
Output: F P u c A w = =
6.6. Example of an ASCII Armored Message ๐ง
Here's a full example of an ASCII Armored message. It's giving real protocol energy ๐:
-----BEGIN PGP MESSAGE-----
Version: OpenPrivacy 0.99
yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
vBSFjNSiVHsuAA==
=njUN
-----END PGP MESSAGE-----
Note that this example is indented by two spaces. ๐
7. Cleartext signature framework ๐ฅ
It's really desirable to sign a textual octet stream without ASCII armoring the stream itself. That way the signed text is still readable without any special software ๐. To bind a signature to that kind of cleartext, this framework is used. (Note that RFC 2015 defines another way to clear sign messages for environments that support MIME. ๐)
A cleartext signed message consists of:
- The cleartext header
-----BEGIN PGP SIGNED MESSAGE-----on a single line, - One or more "Hash" Armor Headers,
- Exactly one empty line that is not included in the message digest,
- The dash-escaped cleartext that is included in the message digest,
- The ASCII armored signature(s), including the
-----BEGIN PGP SIGNATURE-----Armor Header and Armor Tail Lines. โ๏ธ
If the "Hash" armor header is given, the specified message digest algorithm is used for the signature. If there are no such headers, MD5 is used. An implementation MAY omit them for V2.x compatibility. ๐ซ If more than one message digest is used in the signature, the "Hash" armor header contains a comma-delimited list of the message digests used. โจ
Current message digest names are described below with the algorithm IDs. ๐
7.1. Dash-Escaped Text โจ
Okay bestie, the cleartext content has to be dash-escaped too ๐ซถ no skipping this part!!
Dash-escaped cleartext is the ordinary cleartext where every line starting with a dash - (0x2D) gets the prefix - (a dash, then a space ' ' (0x20)) slapped on the front. Why? It stops the parser from mistaking the cleartext's own lines for armor headers ๐ that's the whole point. And the message digest is computed on the actual cleartext, not the dash-escaped version, so the text itself stays the star of the show ๐
As with binary signatures on text documents, a cleartext signature is calculated on the text using canonical <CR><LF> line endings. The line ending (aka the <CR><LF>) right before the -----BEGIN PGP SIGNATURE----- line that ends the signed text is NOT considered part of the signed text ๐ so don't count it, periodt.
Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of any line is ignored when the cleartext signature is calculated. Lowkey a relief for anyone who's ever left a stray space at the end of a line ๐ญ
8. Regular Expressions ๐
Okay so a regular expression is zero or more branches, separated by '|'. It matches anything that matches one of the branches.
A branch is zero or more pieces, concatenated. It matches a match for the first, followed by a match for the second, etc.
A piece is an atom possibly followed by '*', '+', or '?'. An atom followed by '*' matches a sequence of 0 or more matches of the atom. An atom followed by '+' matches a sequence of 1 or more matches of the atom. An atom followed by '?' matches a match of the atom, or the null string. Iconic pattern-building, no notes ๐ฆ
An atom is a regular expression in parentheses (matching a match for the regular expression), a range (see below), '.' (matching any single character), '^' (matching the null string at the beginning of the input string), '$' (matching the null string at the end of the input string), a '\' followed by a single character (matching that character), or a single character with no other significance (matching that character). So many options, it's giving buffet ๐
A range is a sequence of characters enclosed in '[]'. It normally matches any single character from the sequence. If the sequence begins with '^', it matches any single character NOT from the rest of the sequence. If two characters in the sequence are separated by '-', this is shorthand for the full list of ASCII characters between them (e.g. '[0-9]' matches any decimal digit). To include a literal ']' in the sequence, make it the first character (following a possible '^'). To include a literal '-', make it the first or last character. Those brackets are sneaky, bestie, read them twice โจ
9. Constants ๐
This section describes the constants used in OpenPGP.
Note that these tables are not exhaustive lists; an implementation MAY implement an algorithm not on these lists. Lots of room to grow here ๐
See the section "Notes on Algorithms" below for more discussion of the algorithms.
9.1. Public Key Algorithms ๐
ID Algorithm
-- ---------
1 - RSA (Encrypt or Sign)
2 - RSA Encrypt-Only
3 - RSA Sign-Only
16 - Elgamal (Encrypt-Only), see [ELGAMAL]
17 - DSA (Digital Signature Standard)
18 - Reserved for Elliptic Curve
19 - Reserved for ECDSA
20 - Elgamal (Encrypt or Sign)
21 - Reserved for Diffie-Hellman (X9.42,
as defined for IETF-S/MIME)
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement DSA for signatures, and Elgamal for encryption. Implementations SHOULD implement RSA keys. Implementations MAY implement any other algorithm. The must-haves are DSA and Elgamal, no debate ๐
9.2. Symmetric Key Algorithms ๐
ID Algorithm
-- ---------
0 - Plaintext or unencrypted data
1 - IDEA [IDEA]
2 - Triple-DES (DES-EDE, as per spec -
168 bit key derived from 192)
3 - CAST5 (128 bit key, as per RFC 2144)
4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH]
5 - SAFER-SK128 (13 rounds) [SAFER]
6 - Reserved for DES/SK
7 - Reserved for AES with 128-bit key
8 - Reserved for AES with 192-bit key
9 - Reserved for AES with 256-bit key
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement Triple-DES. Implementations SHOULD implement IDEA and CAST5. Implementations MAY implement any other algorithm. Triple-DES is the one you can't skip ๐ซถ
9.3. Compression Algorithms ๐๏ธ
ID Algorithm
-- ---------
0 - Uncompressed
1 - ZIP (RFC 1951)
2 - ZLIB (RFC 1950)
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement uncompressed data. Implementations SHOULD implement ZIP. Implementations MAY implement ZLIB. Uncompressed is the non-negotiable baseline, ZIP is the recommended glow-up โจ
9.4. Hash Algorithms ๐ง
ID Algorithm Text Name
-- --------- ---- ----
1 - MD5 "MD5"
2 - SHA-1 "SHA1"
3 - RIPE-MD/160 "RIPEMD160"
4 - Reserved for double-width SHA (experimental)
5 - MD2 "MD2"
6 - Reserved for TIGER/192 "TIGER192"
7 - Reserved for HAVAL (5 pass, 160-bit)
"HAVAL-5-160"
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement SHA-1. Implementations SHOULD implement MD5. SHA-1 is the must-have, MD5 is the should-have, and everything else is a vibe check ๐ฅน
10. Packet Composition ๐ง
OpenPGP packets are assembled into sequences in order to create messages and to transfer keys. Not all possible packet sequences are meaningful and correct. This describes the rules for how packets should be placed into sequences. Think of it like a playlist: the order matters, babe ๐ถ
10.1. Transferable Public Keys ๐๏ธ
OpenPGP users may transfer public keys. The essential elements of a transferable public key are:
- One Public Key packet
- Zero or more revocation signatures
- One or more User ID packets
- After each User ID packet, zero or more signature packets (certifications)
- Zero or more Subkey packets
- After each Subkey packet, one signature packet, optionally a revocation.
The Public Key packet occurs first. Each of the following User ID packets provides the identity of the owner of this public key. If there are multiple User ID packets, this corresponds to multiple means of identifying the same unique individual user; for example, a user may have more than one email address, and construct a User ID for each one. Multiple profiles, one main character ๐
Immediately following each User ID packet, there are zero or more signature packets. Each signature packet is calculated on the immediately preceding User ID packet and the initial Public Key packet. The signature serves to certify the corresponding public key and user ID. In effect, the signer is testifying to his or her belief that this public key belongs to the user identified by this user ID. It's a testimony, bestie, like a notarized vibe check ๐ฆ
After the User ID packets there may be one or more Subkey packets. In general, subkeys are provided in cases where the top-level public key is a signature-only key. However, any V4 key may have subkeys, and the subkeys may be encryption-only keys, signature-only keys, or general-purpose keys. Subkeys are the side characters that can do everything ๐ญ
Each Subkey packet must be followed by one Signature packet, which should be a subkey binding signature issued by the top level key. Every subkey needs its receipt, no exceptions ๐งพ
Subkey and Key packets may each be followed by a revocation Signature packet to indicate that the key is revoked. Revocation signatures are only accepted if they are issued by the key itself, or by a key that is authorized to issue revocations via a revocation key subpacket in a self-signature by the top level key. Only the right people can cancel a key, okay? ๐ โโ๏ธ
Transferable public key packet sequences may be concatenated to allow transferring multiple public keys in one operation. Bulk key delivery, efficient and iconic ๐
10.2. OpenPGP Messages ๐ฌ
An OpenPGP message is a packet or sequence of packets that corresponds to the following grammatical rules (comma represents sequential composition, and vertical bar separates alternatives):
OpenPGP Message :- Encrypted Message | Signed Message |
Compressed Message | Literal Message.
Compressed Message :- Compressed Data Packet.
Literal Message :- Literal Data Packet.
ESK :- Public Key Encrypted Session Key Packet |
Symmetric-Key Encrypted Session Key Packet.
ESK Sequence :- ESK | ESK Sequence, ESK.
Encrypted Message :- Symmetrically Encrypted Data Packet |
ESK Sequence, Symmetrically Encrypted Data Packet.
One-Pass Signed Message :- One-Pass Signature Packet,
OpenPGP Message, Corresponding Signature Packet.
Signed Message :- Signature Packet, OpenPGP Message |
One-Pass Signed Message.
In addition, decrypting a Symmetrically Encrypted Data packet and decompressing a Compressed Data packet must yield a valid OpenPGP Message. The grammar is the dress code, and everything has to match it ๐
10.3. Detached Signatures ๐
Some OpenPGP applications use so-called "detached signatures." For example, a program bundle may contain a file, and with it a second file that is a detached signature of the first file. These detached signatures are simply a signature packet stored separately from the data that they are a signature of. Like a sticky note on the side of the package, no cap ๐งธ
11. Enhanced Key Formats ๐ธ
11.1. Key Structures ๐๏ธ
The format of an OpenPGP V3 key is as follows. Entries in square brackets are optional and ellipses indicate repetition.
RSA Public Key
[Revocation Self Signature]
User ID [Signature ...]
[User ID [Signature ...] ...]
Each signature certifies the RSA public key and the preceding user ID. The RSA public key can have many user IDs and each user ID can have many signatures. Lots of friends, lots of endorsements ๐ฅฐ
The format of an OpenPGP V4 key that uses two public keys is similar except that the other keys are added to the end as 'subkeys' of the primary key.
Primary-Key
[Revocation Self Signature]
[Direct Key Self Signature...]
User ID [Signature ...]
[User ID [Signature ...] ...]
[[Subkey [Binding-Signature-Revocation]
Primary-Key-Binding-Signature] ...]
A subkey always has a single signature after it that is issued using the primary key to tie the two keys together. This binding signature may be in either V3 or V4 format, but V4 is preferred, of course. V4 is the clear favourite, obviously ๐
In the above diagram, if the binding signature of a subkey has been revoked, the revoked binding signature may be removed, leaving only one signature. Clean-up time, but make sure the right one goes ๐งน
In a key that has a main key and subkeys, the primary key MUST be a key capable of signing. The subkeys may be keys of any other type. There may be other constructions of V4 keys, too. For example, there may be a single-key RSA key in V4 format, a DSA primary key with an RSA encryption key, or RSA primary key with an Elgamal subkey, etc. Mix and match, the primary key just has to be able to sign โจ
It is also possible to have a signature-only subkey. This permits a primary key that collects certifications (key signatures) but is only used for certifying subkeys that are used for encryption and signatures. A key that just hoards endorsements and delegates everything else? Iconic management energy ๐
11.2. Key IDs and Fingerprints ๐โจ
okay so for a V3 key, the eight-octet key ID is the low 64 bits of the public modulus of the RSA key ๐
the fingerprint of a V3 key gets made by hashing the body (but not the two-octet length) of the MPIs that form the key material (public modulus n, followed by exponent e) with MD5 ๐ง
a V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet Tag, followed by the two-octet packet length, followed by the entire Public Key packet starting with the version field. the key ID is the low order 64 bits of the fingerprint. here's how the hash material is laid out, using a DSA key as the example ๐
a.1) 0x99 (1 octet)
a.2) high order length octet of (b)-(f) (1 octet)
a.3) low order length octet of (b)-(f) (1 octet)
b) version number = 4 (1 octet);
c) time stamp of key creation (4 octets);
d) algorithm (1 octet): 17 = DSA (example);
e) Algorithm specific fields.
and the algorithm specific fields for DSA keys (example) look like this ๐
e.1) MPI of DSA prime p;
e.2) MPI of DSA group order q (q is a prime divisor of p-1);
e.3) MPI of DSA group generator g;
e.4) MPI of DSA public key value y (= g**x where x is secret).
now the important bit ๐จ it's possible for key IDs to collide, meaning two different keys with the same key ID. way less likely, but still not zero, is two different keys sharing the same fingerprint ๐ฅบ
also, if V3 and V4 format keys share the same RSA key material, they'll have different key IDs and different fingerprints ๐
12. Notes on Algorithms ๐
12.1. Symmetric Algorithm Preferences ๐
the symmetric algorithm preference is an ordered list of algorithms that the keyholder accepts. since it lives on a self-signature, a keyholder can have different preferences depending on the identity. like, Alice might have TripleDES only for "alice@work.com" but CAST5, Blowfish, and TripleDES for "alice@home.org" ๐ผ๐ก
preferences can also show up in a subkey's binding signature, fyi ๐ซถ
since TripleDES is the MUST-implement algorithm, if it isn't explicitly in the list, it's tacitly at the end. but it's good form to put it there explicitly ๐ and if an implementation doesn't implement the preference at all, it's implicitly a TripleDES-only implementation ๐ญ
An implementation MUST not use a symmetric algorithm that is not in the recipient's preference list. when you're encrypting to more than one recipient, the implementation finds a suitable algorithm by taking the intersection of the preferences of the recipients. the MUST-implement algorithm, TripleDES, is what guarantees the intersection isn't null โจ the implementation can use any mechanism it likes to pick an algorithm in that intersection ๐
if an implementation can decrypt a message that a keyholder doesn't have in their preferences, it SHOULD decrypt the message anyway, but it MUST warn the keyholder that the protocol has been violated. (example time: suppose Alice's software implements every algorithm in this specification. she still prefers subsets for work or home. if she gets a message encrypted with IDEA, which isn't in her preferences, the software warns her that someone sent her an IDEA-encrypted message, but ideally it would decrypt it anyway ๐)
an implementation that's striving for backward compatibility MAY consider a V3 key with a V3 self-signature to be an implicit preference for IDEA, and no ability to do TripleDES. this is technically non-compliant, but an implementation MAY violate the above rule in this case only and use IDEA to encrypt the message, provided the message creator is warned ๐ฅน ideally though, the implementation would follow the rule by actually generating two messages, because the OpenPGP user's implementation might not have IDEA, and then it couldn't read the message. so, an implementation MAY, but SHOULD NOT use IDEA in an algorithm conflict with a V3 key. periodt ๐
12.2. Other Algorithm Preferences โจ
other algorithm preferences work similarly to the symmetric algorithm preference, in that they specify which algorithms the keyholder accepts. there are two interesting cases worth commenting on, though: the compression preferences and the hash preferences ๐
12.2.1. Compression Preferences ๐๏ธ
compression has been an integral part of PGP since its first days. OpenPGP and all previous versions of PGP have offered compression ๐ซ and in this specification, the default is for messages to be compressed, although an implementation is not required to do so. so the compression preference gives a keyholder a way to request that messages not be compressed, presumably because they're using a minimal implementation without compression. it also gives a keyholder a way to state that it can support alternate algorithms ๐ฆ
like the algorithm preferences, an implementation MUST NOT use an algorithm that is not in the preference vector. if the preferences aren't present, they're assumed to be [ZIP(1), UNCOMPRESSED(0)] ๐
12.2.2. Hash Algorithm Preferences ๐
typically, the signer chooses the hash algorithm, not the verifier, because a signer doesn't usually know who's going to verify the signature. this preference, though, makes it easier for a protocol based on digital signatures to negotiate ๐ค
so if Alice is authenticating herself to Bob with a signature, it makes sense for her to use a hash algorithm that Bob's software uses. this preference lets Bob state, in his key, which algorithms Alice may use ๐
12.3. Plaintext ๐ โโ๏ธ
algorithm 0, "plaintext", may only be used to denote secret keys that are stored in the clear. implementations must not use plaintext in Symmetrically Encrypted Data Packets. they must use Literal Data Packets to encode unencrypted or literal data ๐ธ
12.4. RSA ๐
there are algorithm types for RSA-signature-only and RSA-encrypt-only keys. these types are deprecated ๐ฅ the "key flags" subpacket in a signature is a much better way to express the same idea, and it generalizes that to all algorithms. an implementation SHOULD NOT create such a key, but it MAY interpret one ๐
an implementation SHOULD NOT implement RSA keys of size less than 768 bits ๐ซ
it's permissible for an implementation to support RSA merely for backward compatibility. for example, such an implementation would support V3 keys with IDEA symmetric cryptography. this is an exception to the other MUST-implement rules ๐ an implementation that supports RSA in V4 keys MUST implement the MUST-implement features ๐
12.5. Elgamal โก
if an Elgamal key is going to be used for both signing and encryption, extra care must be taken when creating the key ๐ง
an ElGamal key consists of a generator g, a prime modulus p, a secret exponent x, and a public value y = g^x mod p ๐ข
the generator and prime must be chosen so that solving the discrete log problem is intractable. the group g should generate the multiplicative group mod p-1 or a large subgroup of it, and the order of g should have at least one large prime factor. a good choice is to use a "strong" Sophie-Germain prime when choosing p, so that both p and (p-1)/2 are primes. honestly this choice is so good that implementors SHOULD do it, because it avoids a small subgroup attack ๐ก๏ธโจ
in addition, a result of Bleichenbacher [BLEICHENBACHER] shows that if the generator g has only small prime factors, and if g divides the order of the group it generates, then signatures can be forged ๐ฑ in particular, choosing g=2 is a bad choice if the group order may be even. on the other hand, a generator of 2 is a fine choice for an encryption-only key, because it makes encryption faster ๐๏ธ
while verifying Elgamal signatures, it's important to test that r and s are less than p. if this test isn't done, signatures can be trivially forged by using large r values of approximately twice the length of p. this attack is also discussed in the Bleichenbacher paper ๐
details on safe use of Elgamal signatures can be found in [MENEZES], which covers all the weaknesses described above ๐
if an implementation allows Elgamal signatures, it MUST use the algorithm identifier 20 for an Elgamal public key that can sign ๐
an implementation SHOULD NOT implement Elgamal keys of size less than 768 bits. for long-term security, Elgamal keys should be 1024 bits or longer ๐
12.6. DSA ๐ถ
an implementation SHOULD NOT implement DSA keys of size less than 768 bits. note that present DSA is limited to a maximum of 1024 bit keys, which are recommended for long-term use ๐
12.7. Reserved Algorithm Numbers ๐
a number of algorithm IDs have been reserved for algorithms that would be useful in an OpenPGP implementation, but there are issues that stop an implementor from actually implementing them. these are marked in the Public Algorithms section as "(reserved for)" ๐ซฃ
the reserved public key algorithms, Elliptic Curve (18), ECDSA (19), and X9.42 (21), don't have the necessary parameters, parameter order, or semantics defined ๐
the reserved symmetric key algorithm, DES/SK (6), doesn't have semantics defined ๐คทโโ๏ธ
the reserved hash algorithms, TIGER192 (6) and HAVAL-5-160 (7), don't have OIDs. the reserved algorithm number 4, reserved for a double-width variant of SHA1, isn't presently defined ๐
we have reserver three algorithm IDs for the US NIST's Advanced Encryption Standard. this algorithm will work with (at least) 128, 192, and 256-bit keys. we expect it to be selected from the candidate algorithms in the year 2000 ๐บ๐ธโจ
12.8. OpenPGP CFB mode ๐ฆ
okay so OpenPGP does symmetric encryption using a variant of Cipher Feedback Mode (CFB mode) ๐ this section walks through exactly how it works, step by step. This is the mode used for Symmetrically Encrypted Data Packets. The mechanism for encrypting secret key material is similar, but it's described in those sections above ๐ธ
OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and prefixes the plaintext with ten octets of random data, such that octets 9 and 10 match octets 7 and 8. โจ It does a CFB "resync" after encrypting those ten octets.
Note that for an algorithm that has a larger block size than 64 bits, the equivalent function will be done with that entire block. For example, a 16-octet block algorithm would operate on 16 octets, and then produce two octets of check, and then work on 16-octet blocks. ๐ง
Step by step, here is the procedure:
- The feedback register (FR) is set to the IV, which is all zeros. ๐
- FR is encrypted to produce FRE (FR Encrypted). This is the encryption of an all-zero value.
- FRE is xored with the first 8 octets of random data prefixed to the plaintext to produce C1-C8, the first 8 octets of ciphertext.
- FR is loaded with C1-C8.
- FR is encrypted to produce FRE, the encryption of the first 8 octets of ciphertext.
- The left two octets of FRE get xored with the next two octets of data that were prefixed to the plaintext. This produces C9-C10, the next two octets of ciphertext. ๐
- (The resync step) FR is loaded with C3-C10.
- FR is encrypted to produce FRE.
- FRE is xored with the first 8 octets of the given plaintext, now that we have finished encrypting the 10 octets of prefixed data. This produces C11-C18, the next 8 octets of ciphertext.
- FR is loaded with C11-C18.
- FR is encrypted to produce FRE.
- FRE is xored with the next 8 octets of plaintext, to produce the next 8 octets of ciphertext. These are loaded into FR and the process is repeated until the plaintext is used up. ๐
13. Security Considerations ๐ฅ
okay bestie, this part is serious, so read it carefully ๐ซถ as with any technology involving cryptography, you should check the current literature to determine if any algorithms used here have been found to be vulnerable to attack. crypto is a moving target, no cap.
This specification uses Public Key Cryptography technologies. Possession of the private key portion of a public-private key pair is assumed to be controlled by the proper party or parties. ๐
Certain operations in this specification involve the use of random numbers. An appropriate entropy source should be used to generate these numbers. See RFC 1750. ๐ฒ
The MD5 hash algorithm has been found to have weaknesses (pseudo-collisions in the compress function) that make some people deprecate its use. They consider the SHA-1 algorithm better. ๐
Many security protocol designers think that it is a bad idea to use a single key for both privacy (encryption) and integrity (signatures). In fact, this was one of the motivating forces behind the V4 key format with separate signature and encryption keys. If you as an implementor promote dual-use keys, you should at least be aware of this controversy. ๐
The DSA algorithm will work with any 160-bit hash, but it is sensitive to the quality of the hash algorithm, if the hash algorithm is broken, it can leak the secret key. The Digital Signature Standard (DSS) specifies that DSA be used with SHA-1. RIPEMD-160 is considered by many cryptographers to be as strong. An implementation should take care which hash algorithms are used with DSA, as a weak hash can not only allow a signature to be forged, but could leak the secret key. These same considerations about the quality of the hash algorithm apply to Elgamal signatures. ๐ญ
If you are building an authentication system, the recipient may specify a preferred signing algorithm. However, the signer would be foolish to use a weak algorithm simply because the recipient requests it. ๐
Some of the encryption algorithms mentioned in this document have been analyzed less than others. For example, although CAST5 is presently considered strong, it has been analyzed less than Triple-DES. Other algorithms may have other controversies surrounding them. ๐ง
Some technologies mentioned here may be subject to government control in some countries. ๐
14. Implementation Nits ๐ ๏ธ
this section is a collection of comments to help an implementer, particularly with an eye to backward compatibility. previous implementations of PGP are not OpenPGP-compliant. often the differences are small, but small differences are frequently more vexing than large differences. so here's a list of potential problems and gotchas for a developer who is trying to be backward-compatible ๐
- PGP 5.x does not accept V4 signatures for anything other than key material.
- PGP 5.x does not recognize the "five-octet" lengths in new-format headers or in signature subpacket lengths.
- PGP 5.0 rejects an encrypted session key if the keylength differs from the S2K symmetric algorithm. This is a bug in its validation function.
- PGP 5.0 does not handle multiple one-pass signature headers and trailers. Signing one will compress the one-pass signed literal and prefix a V3 signature instead of doing a nested one-pass signature.
- When exporting a private key, PGP 2.x generates the header "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY BLOCK". All previous versions ignore the implied data type, and look directly at the packet data type.
- In a clear-signed signature, PGP 5.0 will figure out the correct hash algorithm if there is no "Hash:" header, but it will reject a mismatch between the header and the actual algorithm used. The "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x rejects the "Hash:" header and assumes MD5. There are a number of enhanced variants of PGP 2.6.x that have been modified for SHA-1 signatures. โ๏ธ
- PGP 5.0 can read an RSA key in V4 format, but can only recognize it with a V3 keyid, and can properly use only a V3 format RSA key.
- Neither PGP 5.x nor PGP 6.0 recognize Elgamal Encrypt and Sign keys. They only handle Elgamal Encrypt-only keys.
- There are many ways possible for two keys to have the same key material, but different fingerprints (and thus key ids). Perhaps the most interesting is an RSA key that has been "upgraded" to V4 format, but since a V4 fingerprint is constructed by hashing the key creation time along with other things, two V4 keys created at different times, yet with the same key material will have different fingerprints. ๐คฏ
- If an implementation is using zlib to interoperate with PGP 2.x, then the "windowBits" parameter should be set to -13. โ๏ธ
15. Authors and Working Group Chair โญ
the working group can be contacted via the current chair:
John W. Noerenberg, II
Qualcomm, Inc
6455 Lusk Blvd
San Diego, CA 92131 USA
Phone: +1 619-658-3510
EMail: jwn2@qualcomm.com
the principal authors of this memo are:
Jon Callas
Network Associates, Inc.
3965 Freedom Circle
Santa Clara, CA 95054, USA
Phone: +1 408-346-5860
EMail: jon@pgp.com, jcallas@nai.com
Lutz Donnerhacke
IKS GmbH
Wildenbruchstr. 15
07745 Jena, Germany
Phone: +49-3641-675642
EMail: lutz@iks-jena.de
Hal Finney
Network Associates, Inc.
3965 Freedom Circle
Santa Clara, CA 95054, USA
EMail: hal@pgp.com
Rodney Thayer
EIS Corporation
Clearwater, FL 33767, USA
EMail: rodney@unitran.com
this memo also draws on much previous work from a number of other authors who include: Derek Atkins, Charles Breed, Dave Del Torto, Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph Levien, Colin Plumb, Will Price, William Stallings, Mark Weaver, and Philip R. Zimmermann. ๐
16. References ๐โจ
okay bestie, these are the receipts ๐งพ every paper and RFC this spec leans on. don't skip any of them ๐
[BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal
signatures without knowing the secret key,"
Eurocrypt 96. Note that the version in the
proceedings has an error. A revised version is
available at the time of writing from
<ftp://ftp.inf.ethz.ch/pub/publications/papers/ti/isc
/ElGamal.ps>
[BLOWFISH] Schneier, B. "Description of a New Variable-Length
Key, 64-Bit Block Cipher (Blowfish)" Fast Software
Encryption, Cambridge Security Workshop Proceedings
(December 1993), Springer-Verlag, 1994, pp191-204
<http://www.counterpane.com/bfsverlag.html>
[DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved
international version of PGP", ftp://ftp.iks-
jena.de/mitarb/lutz/crypt/software/pgp/
[ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a
Signature Scheme Based on Discrete Logarithms," IEEE
Transactions on Information Theory, v. IT-31, n. 4,
1985, pp. 469-472.
[IDEA] Lai, X, "On the design and security of block
ciphers", ETH Series in Information Processing, J.L.
Massey (editor), Vol. 1, Hartung-Gorre Verlag
Knostanz, Technische Hochschule (Zurich), 1992
[ISO-10646] ISO/IEC 10646-1:1993. International Standard --
Information technology -- Universal Multiple-Octet
Coded Character Set (UCS) -- Part 1: Architecture
and Basic Multilingual Plane. UTF-8 is described in
Annex R, adopted but not yet published. UTF-16 is
described in Annex Q, adopted but not yet published.
[MENEZES] Alfred Menezes, Paul van Oorschot, and Scott
Vanstone, "Handbook of Applied Cryptography," CRC
Press, 1996.
[RFC822] Crocker, D., "Standard for the format of ARPA
Internet text messages", STD 11, RFC 822, August
1982.
[RFC1423] Balenson, D., "Privacy Enhancement for Internet
Electronic Mail: Part III: Algorithms, Modes, and
Identifiers", RFC 1423, October 1993.
[RFC1641] Goldsmith, D. and M. Davis, "Using Unicode with
MIME", RFC 1641, July 1994.
[RFC1750] Eastlake, D., Crocker, S. and J. Schiller,
"Randomness Recommendations for Security", RFC 1750,
December 1994.
[RFC1951] Deutsch, P., "DEFLATE Compressed Data Format
Specification version 1.3.", RFC 1951, May 1996.
[RFC1983] Malkin, G., "Internet Users' Glossary", FYI 18, RFC
1983, August 1996.
[RFC1991] Atkins, D., Stallings, W. and P. Zimmermann, "PGP
Message Exchange Formats", RFC 1991, August 1996.
[RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy
(PGP)", RFC 2015, October 1996.
[RFC2231] Borenstein, N. and N. Freed, "Multipurpose Internet
Mail Extensions (MIME) Part One: Format of Internet
Message Bodies.", RFC 2231, November 1996.
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Level", BCP 14, RFC 2119, March 1997.
[RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC
2144, May 1997.
[RFC2279] Yergeau., F., "UTF-8, a transformation format of
Unicode and ISO 10646", RFC 2279, January 1998.
[RFC2313] Kaliski, B., "PKCS #1: RSA Encryption Standard
version 1.5", RFC 2313, March 1998.
[SAFER] Massey, J.L. "SAFER K-64: One Year Later", B.
Preneel, editor, Fast Software Encryption, Second
International Workshop (LNCS 1008) pp212-241,
Springer-Verlag 1995
17. Full Copyright Statement ๐
okay the legal bit, but make it cute ๐ Copyright (C) The Internet Society (1998). All Rights Reserved.
you're allowed to copy and share this doc, and to make derivative works that comment on or explain it or help implement it. you can prepare, copy, publish and distribute those, in whole or in part, without restriction of any kind, as long as the above copyright notice and this paragraph are included on all such copies and derivative works. however, this document itself may not be modified in any way, such as by removing the copyright notice or references to the Internet Society or other Internet organizations. the exceptions are developing Internet standards (then the procedures for copyrights defined in the Internet Standards process must be followed) or translating it into languages other than English. ๐ธ
the limited permissions above are perpetual and will not be revoked by the Internet Society or its successors or assigns. ๐ฆ
and the disclaimer, which is serious even with my whole vibe ๐ญ
This document and the information contained herein is provided on an "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. ๐ซถ
๐ฆ where this page comes from
- ietf: rfc2440 1998-11
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms