RFC 4880
OpenPGP Message Format
Part 1 of 19 ๐
Okay bestie, welcome to RFC 4880: OpenPGP Message Format ๐ It's a Standards Track doc from November 2007, so this is an official protocol spec ๐
The crew who wrote it: J. Callas (PGP Corporation), L. Donnerhacke (IKS GmbH), H. Finney (PGP Corporation), D. Shaw, and R. Thayer. It obsoletes RFC 1991 and RFC 2440 ๐ฆ, so those are retired. The title block doesn't list anything it updates.
Status of This Memo โจ
Okay so this section is the "what kind of doc is this" bit. This document specifies an Internet standards track protocol for the Internet community, and it's asking for discussion and suggestions for improvements ๐ฌ. For the current standardization state and status, check the "Internet Official Protocol Standards" (STD 1) ๐. Distribution of this memo is unlimited, so share away ๐ธ.
Abstract ๐ง
The whole point of this doc is to publish every piece of info you need to build interoperable apps on the OpenPGP format ๐ซถ It is not a step-by-step cookbook for writing an application, though ๐ It describes only the format and methods needed to read, check, generate, and write conforming packets crossing any network. It doesn't deal with storage and implementation questions. It does, however, discuss implementation issues necessary to avoid security flaws ๐จ so pay attention to that part, periodt.
OpenPGP software uses a combination of strong public-key and symmetric cryptography to provide security services for electronic communications and data storage ๐ Those services include confidentiality, key management, authentication, and digital signatures ๐ This document specifies the message formats used in OpenPGP โจ
Table of Contents โจ
1. Introduction ....................................................5
1.1. Terms ......................................................5
2. General functions ...............................................6
2.1. Confidentiality via Encryption .............................6
2.2. Authentication via Digital Signature .......................7
2.3. Compression ................................................7
2.4. Conversion to Radix-64 .....................................8
2.5. Signature-Only Applications ................................8
3. Data Element Formats ............................................8
3.1. Scalar Numbers .............................................8
3.2. Multiprecision Integers ....................................9
3.3. Key IDs ....................................................9
3.4. Text .......................................................9
3.5. Time Fields ...............................................10
3.6. Keyrings ..................................................10
3.7. String-to-Key (S2K) Specifiers ............................10
3.7.1. String-to-Key (S2K) Specifier Types ................10
3.7.1.1. Simple S2K ................................10
3.7.1.2. Salted S2K ................................11
3.7.1.3. Iterated and Salted S2K ...................11
3.7.2. String-to-Key Usage ................................12
3.7.2.1. Secret-Key Encryption .....................12
3.7.2.2. Symmetric-Key Message Encryption ..........13
4. Packet Syntax ..................................................13
4.1. Overview ..................................................13
4.2. Packet Headers ............................................13
4.2.1. Old Format Packet Lengths ..........................14
4.2.2. New Format Packet Lengths ..........................15
4.2.2.1. One-Octet Lengths .........................15
4.2.2.2. Two-Octet Lengths .........................15
4.2.2.3. Five-Octet Lengths ........................15
4.2.2.4. Partial Body Lengths ......................16
4.2.3. Packet Length Examples .............................16
4.3. Packet Tags ...............................................17
5. Packet Types ...................................................17
5.1. Public-Key Encrypted Session Key Packets (Tag 1) ..........17
5.2. Signature Packet (Tag 2) ..................................19
5.2.1. Signature Types ....................................19
5.2.2. Version 3 Signature Packet Format ..................21
5.2.3. Version 4 Signature Packet Format ..................24
5.2.3.1. Signature Subpacket Specification .........25
5.2.3.2. Signature Subpacket Types .................27
5.2.3.3. Notes on Self-Signatures ..................27
5.2.3.4. Signature Creation Time ...................28
5.2.3.5. Issuer ....................................28
5.2.3.6. Key Expiration Time .......................28
5.2.3.7. Preferred Symmetric Algorithms ............28
5.2.3.8. Preferred Hash Algorithms .................29
5.2.3.9. Preferred Compression Algorithms ..........29
5.2.3.10. Signature Expiration Time ................29
5.2.3.11. Exportable Certification .................29
5.2.3.12. Revocable ................................30
5.2.3.13. Trust Signature ..........................30
5.2.3.14. Regular Expression .......................31
5.2.3.15. Revocation Key ...........................31
5.2.3.16. Notation Data ............................31
5.2.3.17. Key Server Preferences ...................32
5.2.3.18. Preferred Key Server .....................33
5.2.3.19. Primary User ID ..........................33
5.2.3.20. Policy URI ...............................33
5.2.3.21. Key Flags ................................33
5.2.3.22. Signer's User ID .........................34
5.2.3.23. Reason for Revocation ....................35
5.2.3.24. Features .................................36
5.2.3.25. Signature Target .........................36
5.2.3.26. Embedded Signature .......................37
5.2.4. Computing Signatures ...............................37
5.2.4.1. Subpacket Hints ...........................38
5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) .......38
5.4. One-Pass Signature Packets (Tag 4) ........................39
5.5. Key Material Packet .......................................40
5.5.1. Key Packet Variants ................................40
5.5.1.1. Public-Key Packet (Tag 6) .................40
5.5.1.2. Public-Subkey Packet (Tag 14) .............40
5.5.1.3. Secret-Key Packet (Tag 5) .................41
5.5.1.4. Secret-Subkey Packet (Tag 7) ..............41
5.5.2. Public-Key Packet Formats ..........................41
5.5.3. Secret-Key Packet Formats ..........................43
5.6. Compressed Data Packet (Tag 8) ............................45
5.7. Symmetrically Encrypted Data Packet (Tag 9) ...............45
5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) ..........46
5.9. Literal Data Packet (Tag 11) ..............................46
5.10. Trust Packet (Tag 12) ....................................47
5.11. User ID Packet (Tag 13) ..................................48
5.12. User Attribute Packet (Tag 17) ...........................48
5.12.1. The Image Attribute Subpacket .....................48
5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) ..49
5.14. Modification Detection Code Packet (Tag 19) ..............52
6. Radix-64 Conversions ...........................................53
6.1. An Implementation of the CRC-24 in "C" ....................54
6.2. Forming ASCII Armor .......................................54
6.3. Encoding Binary in Radix-64 ...............................57
6.4. Decoding Radix-64 .........................................58
6.5. Examples of Radix-64 ......................................59
6.6. Example of an ASCII Armored Message .......................59
7. Cleartext Signature Framework ..................................59
7.1. Dash-Escaped Text .........................................60
8. Regular Expressions ............................................61
9. Constants ......................................................61
9.1. Public-Key Algorithms .....................................62
9.2. Symmetric-Key Algorithms ..................................62
9.3. Compression Algorithms ....................................63
9.4. Hash Algorithms ...........................................63
10. IANA Considerations ...........................................63
10.1. New String-to-Key Specifier Types ........................64
10.2. New Packets ..............................................64
10.2.1. User Attribute Types ..............................64
10.2.1.1. Image Format Subpacket Types .............64
10.2.2. New Signature Subpackets ..........................64
10.2.2.1. Signature Notation Data Subpackets .......65
10.2.2.2. Key Server Preference Extensions .........65
10.2.2.3. Key Flags Extensions .....................65
10.2.2.4. Reason For Revocation Extensions .........65
10.2.2.5. Implementation Features ..................66
10.2.3. New Packet Versions ...............................66
10.3. New Algorithms ...........................................66
10.3.1. Public-Key Algorithms .............................66
10.3.2. Symmetric-Key Algorithms ..........................67
10.3.3. Hash Algorithms ...................................67
10.3.4. Compression Algorithms ............................67
11. Packet Composition ............................................67
11.1. Transferable Public Keys .................................67
11.2. Transferable Secret Keys .................................69
11.3. OpenPGP Messages .........................................69
11.4. Detached Signatures ......................................70
12. Enhanced Key Formats ..........................................70
12.1. Key Structures ...........................................70
12.2. Key IDs and Fingerprints .................................71
13. Notes on Algorithms ...........................................72
13.1. PKCS#1 Encoding in OpenPGP ...............................72
13.1.1. EME-PKCS1-v1_5-ENCODE .............................73
13.1.2. EME-PKCS1-v1_5-DECODE .............................73
13.1.3. EMSA-PKCS1-v1_5 ...................................74
13.2. Symmetric Algorithm Preferences ..........................75
13.3. Other Algorithm Preferences ..............................76
13.3.1. Compression Preferences ...........................76
13.3.2. Hash Algorithm Preferences ........................76
13.4. Plaintext ................................................77
13.5. RSA ......................................................77
13.6. DSA ......................................................77
13.7. Elgamal ..................................................78
13.8. Reserved Algorithm Numbers ...............................78
13.9. OpenPGP CFB Mode .........................................78
13.10. Private or Experimental Parameters ......................79
13.11. Extension of the MDC System .............................80
13.12. Meta-Considerations for Expansion .......................80
14. Security Considerations .......................................81
15. Implementation Nits ...........................................84
16. References ....................................................86
16.1. Normative References .....................................86
16.2. Informative References ...................................88
1. Introduction ๐
okay so this doc is all about the message-exchange packet formats that OpenPGP uses to do encryption, decryption, signing, and key management ๐ it's literally the rulebook for how all those pieces fit together, and I'm obsessed.
it's a revision of RFC 2440, "OpenPGP Message Format", which itself replaces RFC 1991, "PGP Message Exchange Formats" [RFC1991] [RFC2440]. so this is the newest glow-up of the whole family tree ๐ฆโจ
1.1. Terms โจ
okay so first, the vocab ๐ bestie, let's get the names straight ๐
- OpenPGP - this is a term for security software that uses PGP 5.x as a basis, formalized in RFC 2440 and this document. ๐
- PGP - Pretty Good Privacy. PGP is a family of software systems developed by Philip R. Zimmermann, and OpenPGP is based on it. ๐
- PGP 2.6.x - this version has tons of variants, which is why it's called PGP 2.6.x. It only used RSA, MD5, and IDEA for its cryptographic transforms. An informational RFC, RFC 1991, was written describing this version of PGP. ๐ฆ
- PGP 5.x - this version used to be called "PGP 3" in the community, and also 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. It's referred to here as PGP 5.x because that software was the first release of the "PGP 3" code base. ๐
- GnuPG - GNU Privacy Guard, also called GPG. GnuPG is an OpenPGP implementation that avoids all encumbered algorithms. Consequently, early versions of GnuPG did not include RSA public keys. GnuPG may or may not have (depending on version) support for IDEA or other encumbered algorithms. ๐ธ
"PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of PGP Corporation and are used with permission. The term "OpenPGP" refers to the protocol described in this and related documents. ๐
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [RFC2119]. ๐ง
The key words "PRIVATE USE", "HIERARCHICAL ALLOCATION", "FIRST COME FIRST SERVED", "EXPERT REVIEW", "SPECIFICATION REQUIRED", "IESG APPROVAL", "IETF CONSENSUS", and "STANDARDS ACTION" that appear in this document when used to describe namespace allocation are to be interpreted as described in [RFC2434]. ๐๏ธ
2. General functions ๐
OpenPGP provides data integrity services for messages and data files by using these core technologies: ๐ฅ
- digital signatures
- encryption
- compression
- Radix-64 conversion
In addition, OpenPGP provides key management and certificate services, but many of these are beyond the scope of this document. ๐ซถ
2.1. Confidentiality via Encryption ๐
OpenPGP combines symmetric-key encryption and public-key encryption to provide confidentiality. When made confidential, first the object is encrypted using a symmetric encryption algorithm. Each symmetric key is used only once, for a single object. A new "session key" is generated as a random number for each object (sometimes referred to as a session). Since it is used only once, the session key is bound to the message and transmitted with it. To protect the key, it is encrypted with the receiver's public key. The sequence is as follows: ๐
- 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 a two-stage mechanism similar to the public-key method described above in which a session key is itself encrypted with a symmetric algorithm keyed from a shared secret. ๐
Both digital signature and confidentiality services may be applied to the same message. First, a signature is generated for the message and attached to the message. Then the message plus signature is encrypted using a symmetric session key. Finally, the session key is encrypted using public-key encryption and prefixed to the encrypted block. โจ
2.2. Authentication via Digital Signature โ๏ธ
The digital signature uses a hash code or message digest algorithm, and a public-key signature algorithm. The sequence is as follows: ๐ฆ
- 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 SHOULD compress the message after applying the signature but before encryption. ๐
If an implementation does not implement compression, its authors should be aware that most OpenPGP messages in the world are compressed. Thus, it may even be wise for a space-constrained implementation to implement decompression, but not compression. ๐ง
Furthermore, compression has the added side effect that some types of attacks can be thwarted by the fact that slightly altered, compressed data rarely uncompresses without severe errors. This is hardly rigorous, but it is operationally useful. These attacks can be rigorously prevented by implementing and using Modification Detection Codes as described in sections following. ๐ก๏ธ
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 the use of blocks consisting of seven-bit, printable text. For transporting OpenPGP's native raw binary octets through channels that are not safe to raw binary data, a printable encoding of these binary octets is needed. OpenPGP provides the service of converting the raw 8-bit binary octet stream to a stream of printable ASCII characters, called Radix-64 encoding or ASCII Armor. ๐
Implementations SHOULD provide Radix-64 conversions. ๐ธ
2.5. Signature-Only Applications โ๏ธ
OpenPGP is designed for applications that use both encryption and signatures, but there are a number of problems that are solved by a signature-only implementation. Although this specification requires both encryption and signatures, it is reasonable for there to be subset implementations that are non-conformant 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. Multiprecision Integers (MPIs) ๐
Multiprecision integers (also called MPIs) are unsigned integers used to hold large integers such as 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. Thus, the MPI [00 02 01] is not formed correctly. It should be [00 01 01]. ๐
Unused bits of an MPI MUST be zero. ๐
Also note that when an MPI is encrypted, the length refers to the plaintext MPI. It may be ill-formed in its ciphertext. ๐ญ
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 ๐
Unless otherwise specified, the character set for text is the UTF-8 [RFC3629] 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. Keyrings ๐๏ธ
A keyring is a collection of one or more keys in a file or database. Traditionally, a keyring is simply a sequential list of keys, but may be any suitable database. It is beyond the scope of this standard to discuss the details of keyrings or other databases. ๐ซง
3.7. String-to-Key (S2K) Specifiers ๐ง
String-to-key (S2K) specifiers are used to convert passphrase strings into symmetric-key encryption/decryption keys. They are used in two places, currently: to encrypt the secret part of private keys in the private keyring, and to convert passphrases to encryption keys for symmetrically encrypted messages. ๐
3.7.1. String-to-Key (S2K) Specifier Types ๐ฐ
There are three types of S2K specifiers currently supported, and some reserved values: ๐
ID S2K Type
-- --------
0 Simple S2K
1 Salted S2K
2 Reserved value
3 Iterated and Salted S2K
100 to 110 Private/Experimental S2K
These are described in Sections 3.7.1.1 - 3.7.1.3. ๐
3.7.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 will depend on the cipher used) and the size of the hash algorithm's output. If the hash size is greater than 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 will 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.7.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.7.1.3. Iterated and Salted S2K ๐ง
okay so this one is the glow-up version ๐ it includes BOTH a salt AND an octet count. The salt gets mixed with the passphrase, and then the whole thing gets hashed over and over. That makes it so much more work for an attacker trying 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 squished into one octet using this formula ๐งฎ
#define EXPBIAS 6
count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS);
that's C, btw, where "Int32" is a 32-bit integer type, and "c" is the coded count (that's Octet 10) ๐ค
ngl the important bit: iterated-salted S2K keeps hashing the passphrase and salt, and the count tells you the total number of octets to hash, not an iteration count ๐ซถ so don't mix those two up bestie!!
at the start, one or more hash contexts get set up like with the other S2K algorithms, depending on how much key data you need ๐ then the salt, followed by the passphrase, gets hashed again and again until you've hit the octet count. the one exception: if the octet count is smaller than salt plus passphrase, the full salt plus passphrase still gets hashed, even though that's bigger than the count ๐ญ (main character energy, no notes)
when the hashing is done, the data gets unloaded from the hash context(s), same as the other S2K algorithms ๐ฆ
3.7.2. String-to-Key Usage ๐
okay the important vibe check here: Implementations SHOULD use salted or iterated-and-salted S2K specifiers, since simple S2K specifiers are way more vulnerable to dictionary attacks ๐จ get the salt in there, periodt ๐
3.7.2.1. Secret-Key Encryption ๐๏ธ
so an S2K specifier can live in the secret keyring and tell you how to turn a passphrase into the key that unlocks the secret data โจ older versions of PGP were kinda basic about it. they just stored a cipher algorithm octet in front of the secret data, or a zero if the data wasn't encrypted at all ๐ฅฑ and they always used MD5 to turn the passphrase into a key for that cipher.
for compatibility, when an S2K specifier is used, the special value 254 or 255 goes in the spot where the hash algorithm octet would've been in the old structure ๐ then comes a one-octet algorithm identifier, and then the S2K specifier, encoded like we said above ๐ซง
so the thing sitting in front of the secret data can be one of these:
0: secret data is unencrypted (no passphrase)
255 or 254: followed by algorithm octet and S2K specifier
Cipher alg: use Simple S2K algorithm using MD5 hash
ok the last one is the messy throwback: a cipher algorithm number with an implicit MD5 and IDEA. it's there purely for backward compatibility ๐ฐ๏ธ it MAY be understood, but SHOULD NOT be generated, and it's deprecated ๐ don't make new stuff like this!!
after all that, you get an Initial Vector the same length as the cipher's block size (for decrypting the secret values, if they're encrypted), and then the secret-key values themselves ๐ง
3.7.2.2. Symmetric-Key Message Encryption ๐
OpenPGP can make a Symmetric-key Encrypted Session Key (ESK) packet at the front of a message ๐ this lets you use S2K specifiers for the passphrase conversion, or mix symmetric-key ESKs with public-key ESKs in the same message. the result: the message can be decrypted with either a passphrase OR a public-key pair. iconic flexibility ๐
PGP 2.X always used IDEA with Simple string-to-key conversion when it encrypted a message with a symmetric algorithm ๐ฌ that's deprecated, but it MAY be used for backward-compatibility ๐ซถ
4. Packet Syntax ๐ฆโจ
this section is all about the packets OpenPGP uses ๐
4.1. Overview ๐ธ
an OpenPGP message is built from a bunch of records that everyone calls packets ๐ฎ a packet is a chunk of data with a tag that says what it means. a message, keyring, certificate, and so on are all made of packets. some packets can even hold other OpenPGP packets inside them (like a compressed data packet, which, once uncompressed, has OpenPGP packets in it) ๐ช
every packet is a packet header followed by the packet body ๐ and the header is variable length, so it's not always the same size bestie.
4.2. Packet Headers ๐
the first octet of the packet header is the "Packet Tag" ๐ท๏ธ it decides the header's format and tells you what the contents are. the rest of the header is the packet's length.
quick note: the most significant bit is the leftmost one, called bit 7. its mask is 0x80 in hex ๐ข
+---------------+
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 if you want to work with those versions, you've gotta be old format too, no exceptions. if interoperability isn't a concern, the new packet format is RECOMMENDED ๐ also, old format packets only have four bits for tags and new ones have six, so some features just can't be used and still stay backward-compatible. it's giving trade-off ๐ฅฒ
ALSO packets with a tag greater than or equal to 16 MUST use new format packets!! old format can only express tags up to 15, so that's the rule ๐ซ
old format packets hold:
Bits 5-2 -- packet tag
Bits 1-0 -- length-type
new format packets hold:
Bits 5-0 -- packet tag
4.2.1. Old Format Packet Lengths ๐
the length-type in old format packets means:
0: the packet has a one-octet length. header is 2 octets long ๐ท
1: the packet has a two-octet length. header is 3 octets long ๐ท
2: the packet has a four-octet length. header is 5 octets long ๐ท
3: the packet has an indeterminate length. header is 1 octet long, and the implementation has to figure out how long the packet is ๐ตโ๐ซ if the packet's in a file, that means it runs until the end of the file. in general, an implementation SHOULD NOT use indeterminate-length packets, except where the end of the data is obvious from context. and even then, a definite length or a new format header is better ๐ซ (the new format headers have a way to precisely encode data of indeterminate length, so you're covered ๐ฆ)
4.2.2. New Format Packet Lengths ๐งฎ
new format packets have four ways to encode length, bestie ๐
- 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. (this really encodes a four-octet scalar number, fr fr ๐ค)
- when the issuer doesn't know the length of the packet body in advance, Partial Body Length headers encode a packet of indeterminate length, basically making it a stream ๐
4.2.2.1. One-Octet Lengths ๐
a one-octet Body Length header encodes a length from 0 to 191 octets. you can spot it because the octet value is less than 192 โจ the body length is:
bodyLen = 1st_octet;
4.2.2.2. Two-Octet Lengths ๐
a two-octet Body Length header encodes a length from 192 to 8383 octets. you can recognize it because its first octet is in the range 192 to 223 ๐ the body length is:
bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
4.2.2.3. Five-Octet Lengths ๐ฆ
a five-octet Body Length header is one octet holding the value 255, followed by a four-octet scalar ๐ the body length is:
bodyLen = (2nd_octet << 24) | (3rd_octet << 16) |
(4th_octet << 8) | 5th_octet
this basic set of one, two, and five-octet lengths also gets reused internally by some packets ๐ซถ
4.2.2.4. Partial Body Lengths ๐งฉ
a Partial Body Length header is one octet long and only encodes the length of part of the data packet ๐ฐ the length is a power of 2, from 1 to 1,073,741,824 (that's 2 to the 30th power) ๐ฅ you can tell it's partial because its octet value is greater than or equal to 224, and less than 255. the Partial Body Length is:
partialBodyLen = 1 << (1st_octet & 0x1F);
each Partial Body Length header is followed by a chunk of packet body data, and the header says how long that chunk is โจ then another length header (one-octet, two-octet, five-octet, or partial) comes right after that chunk. the LAST length header in the packet MUST NOT be a Partial Body Length header ๐ญ they're only allowed for the non-final parts of the packet, periodt.
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 ๐ง and Partial Body Lengths MUST NOT be used for any other packet types ๐ซ
4.2.3. Packet Length Examples ๐ญ
these examples show ways new format packets might encode their lengths ๐ธ
a packet with length 100 might have its length encoded in one octet: 0x64. that's followed by 100 octets of data ๐
a packet with length 1723 might have its length encoded in two octets: 0xC5, 0xFB. the header is followed by the 1723 octets of data ๐
a packet with length 100000 might have its length encoded in five octets: 0xFF, 0x00, 0x01, 0x86, 0xA0 ๐ฆ
it could also be encoded in this octet stream: 0xEF, first 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 1693 octets of data ๐ that's just ONE possible encoding. there are lots of variations on the sizes of the Partial Body Length headers, as long as a regular Body Length header encodes the last portion of the data ๐ง
last thing: in all of these explanations, the total packet length is the length of the header(s) plus the length of the body ๐ซถ
4.3. Packet Tags ๐ท๏ธ
the packet tag says what type of packet the body holds ๐ old format headers can only have tags under 16, while new format headers can go up to 63. here are the defined tags (in decimal):
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
17 -- User Attribute Packet
18 -- Sym. Encrypted and Integrity Protected Data Packet
19 -- Modification Detection Code Packet
60 to 63 -- Private or Experimental Values
5. Packet Types ๐ง
5.1. Public-Key Encrypted Session Key Packets (Tag 1) ๐๐
okay so a Public-Key Encrypted Session Key packet is the little envelope that carries the session key โจ Zero or more of these, and/or Symmetric-Key Encrypted Session Key packets, can sit in front of a Symmetrically Encrypted Data Packet, which is where the actual encrypted message lives ๐ The message gets encrypted with the session key, and then the session key gets encrypted too and tucked into the Encrypted Session Key packet(s). The Symmetrically Encrypted Data Packet is preceded by one Public-Key Encrypted Session Key packet for each OpenPGP key the message is encrypted to ๐ So the recipient finds the session key that's been encrypted to their public key, decrypts it, and then uses it to unlock the message ๐ main character energy, literally.
The body of this packet is made up of:
- A one-octet number giving the version number of the packet type. The currently defined value for packet version is 3. ๐ง
- An eight-octet number that gives the Key ID of the public key the session key is encrypted to. If the session key is encrypted to a subkey, then the Key ID of this subkey is used here instead of the Key ID of the primary key. ๐๏ธ
- A one-octet number giving the public-key algorithm used. ๐ธ
- A string of octets that is the encrypted session key. This string takes up the remainder of the packet, and its contents depend on the public-key algorithm used. ๐
Algorithm Specific Fields for RSA encryption:
- multiprecision integer (MPI) of RSA encrypted value
m**e mod n. ๐ฅ
Algorithm Specific Fields for Elgamal encryption:
- MPI of Elgamal (Diffie-Hellman) value
g**k mod p. โจ - MPI of Elgamal (Diffie-Hellman) value
m * y**k mod p. ๐ฆ
Now the m in those formulas comes from the session key, and the process is giving math but make it cute ๐งฎ First, the session key gets prefixed with a one-octet algorithm identifier that names the symmetric encryption algorithm used on the following Symmetrically Encrypted Data Packet. Then a two-octet checksum gets appended. That checksum is equal to the sum of the preceding session key octets (not counting the algorithm identifier), modulo 65536. Last step: the result gets encoded as described in PKCS#1 block encoding EME-PKCS1-v1_5 in Section 7.2.1 of [RFC3447] to form the "m" value used in the formulas above. See Section 13.1 of this document for notes on OpenPGP's use of PKCS#1 ๐
Heads up, bestie: when an implementation forms several PKESKs with one session key, so that one message can be decrypted by several keys, the implementation MUST make a new PKCS#1 encoding for each key. No copy-pasting the encoding ๐ โโ๏ธ
An implementation MAY accept or use a Key ID of zero as a "wild card" or "speculative" Key ID ๐ In that case, the receiving implementation would try all available private keys and check for a valid decrypted session key. This format helps reduce traffic analysis of messages ๐ต๏ธโโ๏ธ iykyk.
5.2. Signature Packet (Tag 2) โ๏ธ๐
A Signature packet describes a binding between some public key and some data. The most common ones are a signature over a file or a block of text, and a signature that certifies a User ID ๐
Two versions of Signature packets are defined. Version 3 gives you basic signature information, while version 4 gives you an expandable format with subpackets that can specify more info about the signature ๐งฉ PGP 2.6.x only accepts version 3 signatures, so it's a little stuck in its ways ๐
Implementations SHOULD accept V3 signatures. Implementations SHOULD generate V4 signatures.
Note that if an implementation is creating an encrypted and signed message that is encrypted to a V3 key, it is reasonable to create a V3 signature ๐ซถ
5.2.1. Signature Types ๐
okay so a signature can mean a bunch of different things, and the meaning is stored in a signature type octet in each signature ๐ญ Please don't read the vagueness here as a flaw, because it's actually a feature of the system โจ OpenPGP puts the final say on validity in the hands of the receiver. So one signer's casual little act might end up being more rigorous than some other authority's official move ๐ See Section 5.2.4, "Computing Signatures", for detailed info on how to compute and verify signatures of each type.
The meanings go like this:
0x00: Signature of a binary document. ๐พ- This means the signer owns it, created it, or certifies that it has not been modified.
0x01: Signature of a canonical text document. ๐- This means the signer owns it, created it, or certifies that it has not been modified. The signature is calculated over the text data with its line endings converted to
<CR><LF>.
- This means the signer owns it, created it, or certifies that it has not been modified. The signature is calculated over the text data with its line endings converted to
0x02: Standalone signature. ๐งโโ๏ธ- This signature is a signature of only its own subpacket contents. It is calculated identically to a signature over a zero-length binary document. Note that it doesn't make sense to have a V3 standalone signature.
0x10: Generic certification of a User ID and Public-Key packet. ๐ชช- The issuer of this certification does not make any particular assertion as to how well the certifier has checked that the owner of the key is in fact the person described by the User ID.
0x11: Persona certification of a User ID and Public-Key packet. ๐ญ- The issuer of this certification has not done any verification of the claim that the owner of this key is the User ID specified.
0x12: Casual certification of a User ID and Public-Key packet. โ- The issuer of this certification has done some casual verification of the claim of identity.
0x13: Positive certification of a User ID and Public-Key packet. ๐- The issuer of this certification has done substantial verification of the claim of identity.
- Most OpenPGP implementations make their "key signatures" as
0x10certifications. Some implementations can issue0x11-0x13certifications, but few differentiate between the types. ๐
0x18: Subkey Binding Signature ๐- This signature is a statement by the top-level signing key that indicates that it owns the subkey. This signature is calculated directly on the primary key and subkey, and not on any User ID or other packets. A signature that binds a signing subkey MUST have an Embedded Signature subpacket in this binding signature that contains a
0x19signature made by the signing subkey on the primary key and subkey. ๐
- This signature is a statement by the top-level signing key that indicates that it owns the subkey. This signature is calculated directly on the primary key and subkey, and not on any User ID or other packets. A signature that binds a signing subkey MUST have an Embedded Signature subpacket in this binding signature that contains a
0x19: Primary Key Binding Signature ๐ค- This signature is a statement by a signing subkey, indicating that it is owned by the primary key and subkey. This signature is calculated the same way as a
0x18signature: directly on the primary key and subkey, and not on any User ID or other packets.
- This signature is a statement by a signing subkey, indicating that it is owned by the primary key and subkey. This signature is calculated the same way as a
0x1F: Signature directly on a key ๐- This signature is calculated directly on a key. It binds the information in the Signature subpackets to the key, and is appropriate to be used for subpackets that provide information about the key, such as the Revocation Key subpacket. It is also appropriate for statements that non-self certifiers want to make about the key itself, rather than the binding between a key and a name.
0x20: Key revocation signature ๐ซ- The signature is calculated directly on the key being revoked. A revoked key is not to be used. Only revocation signatures by the key being revoked, or by an authorized revocation key, should be considered valid revocation signatures.
0x28: Subkey revocation signature ๐ฅ- The signature is calculated directly on the subkey being revoked. A revoked subkey is not to be used. Only revocation signatures by the top-level signature key that is bound to this subkey, or by an authorized revocation key, should be considered valid revocation signatures.
0x30: Certification revocation signature ๐ซฅ- This signature revokes an earlier User ID certification signature (signature class
0x10through0x13) or direct-key signature (0x1F). It should be issued by the same key that issued the revoked signature or an authorized revocation key. The signature is computed over the same data as the certificate that it revokes, and should have a later creation date than that certificate.
- This signature revokes an earlier User ID certification signature (signature class
0x40: Timestamp signature. โฐ- This signature is only meaningful for the timestamp contained in it.
0x50: Third-Party Confirmation signature. ๐งพ- This signature is a signature over some other OpenPGP Signature packet(s). It is analogous to a notary seal on the signed data. A third-party signature SHOULD include Signature Target subpacket(s) to give easy identification. Note that we really do mean SHOULD. There are plausible uses for this (such as a blind party that only sees the signature, not the key or source document) that cannot include a target subpacket. ๐ซฃ
5.2.2. Version 3 Signature Packet Format ๐
okay so the body of a version 3 Signature Packet is basically a checklist ๐ and it's got:
- One-octet version number (3).
- One-octet length of following hashed material. MUST be 5.
- One-octet signature type.
- Four-octet creation time.
- Eight-octet Key ID of signer.
- One-octet public-key algorithm.
- One-octet hash algorithm.
- Two-octet field holding left 16 bits of signed hash value.
- One or more multiprecision integers comprising the signature. This part is algorithm specific, as described below โจ
so the data being signed, plus the signature type and creation time from the Signature packet (that's 5 extra octets, bestie ๐ซถ), all gets hashed together. That hash value is what goes into the signature algorithm. Then the high 16 bits (first two octets) of the hash get stuck into the Signature packet as a quick vibe check to reject some invalid signatures ๐๏ธ
Algorithm-Specific Fields for RSA signatures:
- multiprecision integer (MPI) of RSA signature value
m**d mod n.
Algorithm-Specific Fields for DSA signatures:
- MPI of DSA value r.
- MPI of DSA value s.
the signature calculation is based on a hash of the signed data, as we just covered ๐ but the details are different for DSA than for RSA, so pay attention ๐
For RSA signatures, the hash value gets encoded using PKCS#1 encoding type EMSA-PKCS1-v1_5, as described in Section 9.2 of RFC 3447. This means inserting the hash value as an octet string into an ASN.1 structure, and that structure also includes the object identifier for whichever hash type is being used. Here are the hexadecimal representations for the currently defined hash algorithms ๐
MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05
RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01
SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A
SHA224: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04
SHA256: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01
SHA384: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02
SHA512: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03
And the ASN.1 Object Identifiers (OIDs) are as follows ๐
MD5: 1.2.840.113549.2.5
RIPEMD-160: 1.3.36.3.2.1
SHA-1: 1.3.14.3.2.26
SHA224: 2.16.840.1.101.3.4.2.4
SHA256: 2.16.840.1.101.3.4.2.1
SHA384: 2.16.840.1.101.3.4.2.2
SHA512: 2.16.840.1.101.3.4.2.3
The full hash prefixes for these look like this ๐
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
SHA224: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05,
0x00, 0x04, 0x1C
SHA256: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05,
0x00, 0x04, 0x20
SHA384: 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05,
0x00, 0x04, 0x30
SHA512: 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86,
0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05,
0x00, 0x04, 0x40
okay the big DSA rule ๐จ DSA signatures MUST use hashes that are equal in size to the number of bits of q, the group generated by the DSA key's generator value.
and if the output size of your chosen hash is bigger than the number of bits of q, you chop it down to fit by keeping the leftmost bits, exactly as many as q has. Then that (possibly trimmed) hash result gets treated as a number and used directly in the DSA signature algorithm ๐ฅ
5.2.3. Version 4 Signature Packet Format ๐ฆ
the body of a version 4 Signature packet is giving full detail ๐ง and contains:
- 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 set (zero or more subpackets).
- Two-octet scalar octet count for the 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 set (zero or more subpackets).
- Two-octet field holding the left 16 bits of the signed hash value.
- One or more multiprecision integers comprising the signature. This part is algorithm specific, as described above.
so the concatenation of the data being signed and the signature data, from the version number through the hashed subpacket data (inclusive), gets hashed. That resulting hash value is what gets signed. The left 16 bits of the hash get included in the Signature packet as a quick test to reject some invalid signatures ๐
There are two fields made of Signature subpackets. The first one is hashed along with the rest of the signature data, while the second one is unhashed. That second set isn't cryptographically protected by the signature, so it should include only 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 ๐ธ
a subpacket data set is zero or more Signature subpackets. In Signature packets, the subpacket data set starts with a two-octet scalar count of the length in octets of all the subpackets. A pointer incremented by this number will skip over the whole subpacket data set ๐ฆ
each subpacket has a 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 after it โจ
The length includes the type octet but not the length field itself. Its format is similar to the "new" format packet header lengths, but it cannot have Partial Body Lengths. So 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 ๐
0 = Reserved
1 = Reserved
2 = Signature Creation Time
3 = Signature Expiration Time
4 = Exportable Certification
5 = Trust Signature
6 = Regular Expression
7 = Revocable
8 = Reserved
9 = Key Expiration Time
10 = Placeholder for backward compatibility
11 = Preferred Symmetric Algorithms
12 = Revocation Key
13 = Reserved
14 = Reserved
15 = Reserved
16 = Issuer
17 = Reserved
18 = Reserved
19 = Reserved
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 URI
27 = Key Flags
28 = Signer's User ID
29 = Reason for Revocation
30 = Features
31 = Signature Target
32 = Embedded Signature
100 To 110 = Private or experimental
An implementation SHOULD ignore any subpacket of a type that it does not recognize ๐ โโ๏ธ
Bit 7 of the subpacket type is the "critical" bit. When it's set, it means the subpacket is one that's critical for the evaluator of the signature to recognize. If the evaluator runs into a subpacket that's marked critical but is unknown to its software, the evaluator SHOULD consider the signature to be in error ๐จ
An evaluator may "recognize" a subpacket without actually implementing it. The whole point of the critical bit is to let the signer tell an evaluator, "hey, I'd rather you throw an error than ignore this new feature I'm using" ๐
Implementations SHOULD implement the three preferred algorithm subpackets (11, 21, and 22), as well as the "Reason for Revocation" subpacket. Note, however, that if an implementation chooses not to implement some of the preferences, it is required to behave in a polite manner to respect the wishes of those users who do implement these 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 certification made by the key itself. And a key can have more than one User ID, so it can have more than one self-signature with different subpackets ๐
a subpacket can show up in either the hashed or the unhashed subpacket sections of a signature. If a subpacket is not hashed, then the information in it can't be considered definitive, because it isn't part of the signature proper ๐ญ
5.2.3.3. Notes on Self-Signatures โจ
Okay so a self-signature is a binding signature made by the key that the signature is about ๐
. There are three flavors: 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 can have its own self-signature, so different subpackets can show up in each one. For subkey binding signatures, every subkey has its own self-signature too ๐. Subpackets in a certification self-signature apply to the user name, subpackets in the subkey self-signature apply to that 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 ๐ฆ. Say a key has two user names, Alice and Bob. Alice prefers the symmetric algorithm CAST5, and Bob prefers IDEA or TripleDES. 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, the algorithm of the primary User ID of the key gives the preferred symmetric algorithm ๐ง.
Revoking a self-signature, or letting it expire, means something different depending on the signature type ๐. Revoking the self-signature on a User ID basically retires that user name. The self-signature is a statement, "My name X is tied to my signing key K," and other users' certifications back it up ๐. If another user revokes their certification, they're saying they don't believe that name and that key go together anymore. Same deal if the users revoke their own self-signature: they no longer go by that name, no longer have that email address, etc. ๐ Revoking a binding signature retires that subkey, and revoking a direct-key signature cancels that signature. For more tea, check out the "Reason for Revocation" subpacket (Section 5.2.3.23) ๐ซถ.
Since a self-signature holds important info about how the key gets used, an implementation SHOULD let the user rewrite the self-signature and the important stuff in it, like preferences and key expiration ๐ฅ.
It's good practice to check that a self-signature imported into an implementation doesn't advertise features the implementation doesn't support, and to rewrite the signature as needed ๐งผ.
An implementation that runs into multiple self-signatures on the same object can resolve the ambiguity however it sees fit ๐, but it is RECOMMENDED that priority go to the most recent self-signature โญ.
5.2.3.4. Signature Creation Time โฐ
(4-octet time field)
This is the time the signature was made.
The Signature Creation Time MUST be present in the hashed area ๐.
5.2.3.5. Issuer ๐ชช
(8-octet Key ID)
This is the OpenPGP Key ID of the key that issued the signature ๐๏ธ.
5.2.3.6. Key Expiration Time โ
(4-octet time field)
This is the key's validity period: the number of seconds after the key creation time when the key expires. If this isn't present or has a value of zero, the key never expires ๐. This only shows up on a self-signature ๐.
5.2.3.7. Preferred Symmetric Algorithms ๐
(array of one-octet values)
These are the symmetric algorithm numbers the key holder prefers to use ๐. The subpacket body is an ordered list of octets, with the most preferred listed first. It's assumed that only the algorithms listed are supported by the recipient's software. Algorithm numbers live in Section 9. This is only found on a self-signature ๐ .
5.2.3.8. Preferred Hash Algorithms ๐ง
(array of one-octet values)
These are the message digest algorithm numbers that indicate which algorithms the key holder prefers to receive ๐ฌ. Like the preferred symmetric algorithms, the list is ordered. Algorithm numbers are in Section 9. This is only found on a self-signature ๐ซง.
5.2.3.9. Preferred Compression Algorithms ๐๏ธ
(array of one-octet values)
These are the compression algorithm numbers the key holder prefers to use ๐. Like the preferred symmetric algorithms, the list is ordered. Algorithm numbers are in Section 9. 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 is only found on a self-signature.
5.2.3.10. Signature Expiration Time โณ
(4-octet time field)
This is the signature's validity period: the number of seconds after the signature creation time when the signature expires. If this isn't present or has a value of zero, it never expires ๐ฆ.
5.2.3.11. Exportable Certification ๐ค
(1 octet of exportability, 0 for not, 1 for exportable)
This subpacket says whether a certification signature is "exportable," meaning 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, or "local," certifications are signatures a user makes to mark a key as valid within that user's own implementation only ๐.
So when an implementation gets a user's copy of a key ready to send to another user (this is the "exporting" process), 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 it can reasonably happen in some cases. For example, if an implementation lets keys be imported from a key database as well as from an exported key, this situation 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.12. 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 promise from the signer that they can't revoke their signature for the life of their key ๐ซถ. If this packet isn't present, the signature is revocable.
5.2.3.13. Trust Signature ๐ค
(1 octet "level" (depth), 1 octet of trust amount)
The signer says 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, meaning it's a "meta introducer" ๐ง . Generally, 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, read like this: 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.14. 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 this packet's body get trust extended by the trust Signature subpacket. The regular expression uses the same syntax as Henry Spencer's "almost public domain" regular expression [REGEX] package. You can find a description of the syntax in Section 8 below ๐.
5.2.3.15. Revocation Key ๐๏ธ
(1 octet of class, 1 octet of public-key algorithm ID, 20 octets of fingerprint)
This authorizes the specified key to issue revocation signatures for this key ๐ก๏ธ. The class octet MUST...
Correction for accuracy: the class octet must have bit 0x80 set. If bit 0x40 is set, the revocation information is sensitive. Other bits are for future expansion to other kinds of authorizations. This is found on a self-signature ๐.
If the "sensitive" flag is set, the keyholder feels this subpacket holds private trust information that describes a real-world sensitive relationship ๐คซ. When this flag is set, implementations SHOULD NOT export this signature to other users, except where the data has to be available: when the signature is being sent to the designated revoker, or when it comes with a revocation signature from that revoker ๐จ. Heads up: it may be a good idea to isolate this subpacket in a separate signature so it isn't combined with other subpackets that need to be exported ๐ .
5.2.3.16. 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" the issuer wants to put on the signature ๐ช. The notation has a name and a value, and each one is a string of octets. A signature can have more than one notation ๐ญ. Notations can be used for any extension the issuer of the signature cares to make ๐ธ. The "flags" field holds four octets of flags.
All undefined flags MUST be zero ๐ซ. The defined flags are as follows:
First octet: 0x80 = human-readable. This note value is text.
Other octets: none.
Notation names are arbitrary strings encoded in UTF-8 ๐. They live in two namespaces: the IETF namespace and the user namespace.
The IETF namespace is registered with IANA ๐๏ธ. These names MUST NOT contain the "@" character (0x40). That character is a tag for the user namespace, so it's off limits here ๐
โโ๏ธ.
Names in the user namespace consist of a UTF-8 string tag, followed by "@", followed by a DNS domain name. Note that the tag MUST NOT contain an "@" character. For example, the "sample" tag used by Example Corporation could be sample@example.com ๐.
Names in a user space are owned and controlled by the owners of that domain. Obviously, it's bad form to create a new name in a DNS space you don't own ๐ค.
Since the user namespace is in the form of an email address, implementers MAY wish to arrange for that address to reach a person who can be consulted about how the named tag is used ๐ง. Note that because of UTF-8 encoding, not every valid user space name tag is a valid email address ๐ค.
If there's a critical notation, the criticality applies to that specific notation, not to notations in general โ ๏ธ.
5.2.3.17. Key Server Preferences ๐ฅ๏ธ
(N octets of flags)
This is a list of one-bit flags that show the key holder's preferences for how the key is handled 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.18. Preferred Key Server ๐ธ
(String)
okay so this is a URI of a key server that the key holder prefers be used for updates ๐โจ bestie, keys with multiple User IDs can have a preferred key server for each User ID, which is so main character energy ๐ . and ngl this is a URI, so the key server can literally be a copy of the key fetched by ftp, http, finger, etc. ๐ฆ
5.2.3.19. 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 User ID for this key ๐. it's reasonable for an implementation to resolve ambiguities in preferences, etc. by looking at 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, but it is RECOMMENDED that priority be given to the User ID with the most recent self-signature ๐ซถ.
when this shows up on a self-signature on a User ID packet, the subpacket only applies to User ID packets. when it shows up on a self-signature on a User Attribute packet, it only applies to User Attribute packets. so yeah, there are two different and independent "primaries" ๐: one for User IDs, and one for User Attributes. iconic ๐.
5.2.3.20. Policy URI ๐
(String)
this subpacket contains a URI of a document that describes the policy under which the signature was issued ๐.
5.2.3.21. Key Flags ๐ฉ
(N octets of flags)
this subpacket holds a list of binary flags that tell you stuff about a key ๐. it's a string of octets, and an implementation MUST NOT assume a fixed size ๐ , because it can grow over time โจ. 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.
0x20 - This key may be used for authentication.
0x80 - The private component of this key may be in the possession of more than one person.
Usage notes ๐:
the flags can show up in self-signatures or in certification signatures, and they mean different things depending on who's making the statement ๐. like, a certification signature with the "sign data" flag is saying the certification is for that use. the "communications encryption" flag in a self-signature is stating a preference that a given key be used for communications. but ngl, it's a thorny issue to decide what counts as "communications" and what counts as "storage" ๐ญ. that decision is left wholly up to the implementation; the authors of this document do not claim any special wisdom on the issue and realize that accepted opinion may change ๐ธ.
The "split key" (0x10) and "group key" (0x80) flags are placed on a self-signature only; they are meaningless on a certification signature. They SHOULD be placed only on a direct-key signature (type 0x1F) or a subkey signature (type 0x18), one that refers to the key the flag applies to ๐ฅ.
5.2.3.22. Signer's User ID ๐
(String)
this subpacket lets a keyholder say which User ID is responsible for the signing ๐. lots of keyholders use a single key for different purposes, like business communications and personal communications ๐ง. this subpacket lets such a keyholder state which of their roles is making a signature โจ.
this subpacket is not appropriate to use to refer to a User Attribute packet ๐ โโ๏ธ.
5.2.3.23. 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 has a machine-readable code that denotes the reason for the revocation:
0 - No reason specified (key revocations or cert revocations) 1 - Key is superseded (key revocations) 2 - Key material has been compromised (key revocations) 3 - Key is retired and no longer used (key revocations) 32 - User ID information is no longer valid (cert revocations) 100-110 - Private Use
after the revocation code comes a string of octets that gives info about the Reason for Revocation in human-readable form (UTF-8) ๐. the string may be null, that is, of zero length. the length of the subpacket is the length of the reason string plus one. an implementation SHOULD implement this subpacket, include it in all revocation signatures, and interpret revocations appropriately ๐ซถ. there are important semantic differences between the reasons, and so there are important reasons for revoking signatures ๐ญ.
if a key has been revoked because of a compromise, all signatures created by that key are suspect ๐จ. but if it was merely superseded or retired, old signatures are still valid ๐. if the revoked signature is the self-signature for certifying a User ID, a revocation denotes that the user name is no longer in use. such a revocation SHOULD include a 0x20 code ๐ .
note that any signature may be revoked, including a certification on some other person's key ๐. there are lots of good reasons for revoking a certification signature, like when a keyholder leaves the employ of a business with an email address ๐ผ. a revoked certification is no longer part of validity calculations ๐ฆ.
5.2.3.24. Features ๐ง
(N octets of flags)
the Features subpacket shows which advanced OpenPGP features a user's implementation supports ๐. this is so that as features are added to OpenPGP that cannot be backwards-compatible, a user can say they can use that feature ๐. the flags are single bits that indicate a given feature is supported.
this subpacket is similar to a preferences subpacket, and only shows up in a self-signature ๐.
an implementation SHOULD NOT use a feature listed when sending to a user who does not state that they can use it ๐.
Defined features are:
First octet:
0x01 - Modification Detection (packets 18 and 19)
if an implementation implements any of the defined features, it SHOULD implement the Features subpacket, too ๐.
an implementation may freely infer features from other suitable implementation-dependent mechanisms โจ.
5.2.3.25. Signature Target ๐ฏ
(1 octet public-key algorithm, 1 octet hash algorithm, N octets hash)
this subpacket identifies a specific target signature that a signature refers to ๐ . for revocation signatures, this subpacket explicitly designates which signature is being revoked ๐. for a third-party or timestamp signature, this designates what signature is signed ๐ธ. all arguments are an identifier of that target signature.
the N octets of hash data MUST be the size of the hash of the signature ๐งฎ. for example, a target signature with a SHA-1 hash MUST have 20 octets of hash data ๐ค.
5.2.3.26. Embedded Signature ๐งธ
(1 signature packet body)
this subpacket contains a complete Signature packet body as specified in Section 5.2 above ๐. it's useful when one signature needs to refer to, or be incorporated in, another signature ๐ซถ.
5.2.4. Computing Signatures โ๏ธ
all signatures are formed by producing a hash over the signature data, and then using the resulting hash in the signature algorithm ๐ซ.
for binary document signatures (type 0x00), the document data is hashed directly ๐. for text document signatures (type 0x01), the document is canonicalized by converting line endings to <CR><LF>, and the resulting data is hashed ๐.
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 body of the key packet ๐. (note that this is an old-style packet header for a key packet with two-octet length.) a subkey binding signature (type 0x18) or primary key binding signature (type 0x19) then hashes the subkey using the same format as the main key (also using 0x99 as the first octet) ๐. key revocation signatures (types 0x20 and 0x28) hash only the key being revoked ๐.
a certification signature (type 0x10 through 0x13) hashes the User ID being bound to the key into the hash context after the above data ๐ชช. a V3 certification hashes the contents of the User ID or attribute packet packet, without any header. a V4 certification hashes the constant 0xB4 for User ID certifications or the constant 0xD1 for User Attribute certifications, followed by a four-octet number giving the length of the User ID or User Attribute data, and then the User ID or User Attribute data ๐งพ.
when a signature is made over a Signature packet (type 0x50), the hash data starts with the octet 0x88, followed by the four-octet length of the signature, and then the body of the Signature packet ๐๏ธ. (note that this is an old-style packet header for a Signature packet with the length-of-length set to zero.) the unhashed subpacket data of the Signature packet being hashed is not included in the hash, and the unhashed subpacket data length value is set to zero ๐.
once the data body is hashed, then a trailer is hashed ๐ฌ. a V3 signature hashes five octets of the packet body, starting from the signature type field. this 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. thus, 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 this has been hashed in a single hash context, 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 ๐ก
it is certainly possible for a signature to contain conflicting information in 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 MAY use any conflict resolution scheme that makes more sense. please note that we are intentionally leaving conflict resolution to the implementer ๐ซ ; most conflicts are simply syntax errors, and the wishy-washy language here allows a receiver to be generous in what they accept, while putting pressure on a creator to be stingy in what they generate ๐คญ.
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 of these keys can verify a signature created by the other, and 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 giving secret-keeper energy ๐คซ It holds the symmetric-key encryption of a session key, which is the key that actually encrypts a message. Zero or more Public-Key Encrypted Session Key packets and/or Symmetric-Key Encrypted Session Key packets can come before a Symmetrically Encrypted Data packet holding the encrypted message. The message gets encrypted with a session key, and that session key is then encrypted and stored in either the Encrypted Session Key packet or the Symmetric-Key Encrypted Session Key packet. Iconic layering ๐
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. So a message can be locked to a bunch of public keys AND one or more passphrases, which is so main character ๐ This packet type is new and is not generated by PGP 2.x or PGP 5.0, so it's a newer girl in town ๐ธ
The body of this packet consists 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 from the packet length and the S2K specifier size), then the S2K algorithm applied to the passphrase produces the session key for decrypting the file, using the symmetric cipher algorithm from the Symmetric-Key Encrypted Session Key packet. Brb, I'm obsessed with how efficient this is ๐ญ
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, using CFB mode with an IV of all zeros. The decryption result is a one-octet algorithm identifier that says which symmetric-key encryption algorithm was used to encrypt 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 ensure that the decryption key is not repeated even if the passphrase is reused. This is the part you cannot skip, bestie ๐จ
5.4. One-Pass Signature Packets (Tag 4) โ๏ธ
the One-Pass Signature packet shows up BEFORE the signed data and has enough info to let the receiver start calculating any hashes needed to verify the signature. That's the trick, because it means the Signature packet can go at the END of the message, so the signer can compute the whole signed message in one pass. Galaxy brain fr ๐
A One-Pass Signature does not interoperate with PGP 2.6.x or earlier. Those versions are giving "no thank you" ๐ โโ๏ธ
The body of this packet consists 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 like a little nesting doll situation and I'm here for it ๐ชโจ
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. So yes, this section is complex, and I'm not gonna pretend otherwise ๐ฉ
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). It's the opener, the main character, the one everybody follows ๐
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 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. Team roles, but make it cryptography ๐ซถ
Note: in PGP 2.6.x, tag 14 was intended to indicate a comment packet. This tag got 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. Such a clever little workaround, I'm obsessed ๐
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. So it's the public version PLUS the secret stuff, and yes the secret stuff is locked in ๐
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 has exactly the same format. Same vibe, smaller crew ๐
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 4 keys first appeared in PGP 5.0 and are the preferred key version for OpenPGP. Version 4 is the real one, bestie โจ
OpenPGP implementations MUST create keys with version 4 format. V3 keys are deprecated; an implementation MUST NOT generate a V3 key, but MAY accept it. So make new keys in v4, and if you get a v3 one, you can take it or leave it ๐ซ
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 multiprecision integers comprising the key material:
- a multiprecision integer (MPI) of RSA public modulus n;
- an MPI of RSA public encryption exponent e.
V3 keys are deprecated, and honestly they have three weaknesses, so let's roast 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. Second, because the fingerprint of a V3 key hashes the key material but not its length, there is an increased opportunity for fingerprint collisions. Third, there are weaknesses in the MD5 hash algorithm that make developers prefer other algorithms. See below for a fuller discussion of Key IDs and fingerprints. Not the vibe ๐ โโ๏ธ
V2 keys are identical to the deprecated V3 keys except for the version number. An implementation MUST NOT generate them and MAY accept or reject them as it sees fit. Basically a v2 key is just a v3 key with a different name tag, so same drama ๐ญ
The version 4 format is similar to the version 3 format except for the absence of a validity period. That has been moved to the Signature packet. In addition, fingerprints of version 4 keys are calculated differently from version 3 keys, as described in the section "Enhanced Key Formats". Glow-up energy โจ
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 multiprecision 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 mod pwhere 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 mod pwhere x is secret). ๐ง
5.5.3. Secret-Key Packet Formats ๐โจ
okay so the Secret-Key and Secret-Subkey packets are basically the public versions with a secret twist ๐ซถ They contain all the data of the Public-Key and Public-Subkey packets, plus extra algorithm-specific secret-key data tacked on the end, usually in encrypted form ๐ (the secret stuff is locked up, obviously).
The packet contains:
- A Public-Key or Public-Subkey packet, as described above.
- One octet indicating string-to-key usage conventions. Zero indicates that the secret-key data is not encrypted. 255 or 254 indicates that a string-to-key specifier is being given. Any other value is a symmetric-key encryption algorithm identifier.
- [Optional] If string-to-key usage octet was 255 or 254, a one-octet symmetric encryption algorithm.
- [Optional] If string-to-key usage octet was 255 or 254, 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 (string-to-key usage octet not zero), an Initial Vector (IV) of the same length as the cipher's block size.
- Plain or encrypted multiprecision integers comprising the secret key data. These algorithm-specific fields are as described below.
- If the string-to-key usage octet is zero or 255, then a two-octet checksum of the plaintext of the algorithm-specific portion (sum of all octets, mod 65536). If the string-to-key usage octet was 254, then a 20-octet SHA-1 hash of the plaintext of the algorithm-specific portion. This checksum or hash is encrypted together with the algorithm-specific fields (if string-to-key usage octet is not zero). Note that for all other values, a two-octet checksum is required.
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, that describes the algorithm for converting the passphrase to a key, else a simple MD5 hash of the passphrase is used. Implementations MUST use a string-to-key specifier; the simple hash is for backward compatibility and is deprecated, though implementations MAY continue to use existing private keys in the old format. 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 (i.e., 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 two-octet 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. However, this checksum is deprecated ๐ โโ๏ธ an implementation SHOULD NOT use it, but should rather use the SHA-1 hash denoted with a usage octet of 254. The reason for this is that there are some attacks that involve undetectably modifying the secret key. ๐ฑ
5.6. Compressed Data Packet (Tag 8) ๐๏ธ
The Compressed Data packet contains compressed data. Typically, this packet is found as the contents of an encrypted packet, or following a Signature or One-Pass Signature packet, and contains a literal data packet.
The body of this packet consists of:
- One octet that gives the algorithm used to compress the packet.
- Compressed data, which makes up the remainder of the packet.
A Compressed Data Packet's body contains an block that compresses some set of packets. See section "Packet Composition" for details on how messages are formed.
ZIP-compressed packets are compressed with raw RFC 1951 [RFC1951] DEFLATE blocks. Note that PGP V2.6 uses 13 bits of compression. If an implementation uses more bits of compression, PGP V2.6 cannot decompress it.
ZLIB-compressed packets are compressed with RFC 1950 [RFC1950] ZLIB-style blocks.
BZip2-compressed packets are compressed using the BZip2 [BZ2] algorithm.
5.7. Symmetrically Encrypted Data Packet (Tag 9) ๐๐
The Symmetrically Encrypted Data packet contains data encrypted with a symmetric-key algorithm. When it has been decrypted, it contains other packets (usually a literal data packet or compressed data packet, but in theory other Symmetrically Encrypted Data packets or sequences of packets that form whole OpenPGP messages).
The body of this packet consists of:
- Encrypted data, the output of the selected symmetric-key cipher operating in OpenPGP's variant of Cipher Feedback (CFB) mode.
The symmetric cipher used may be specified in a Public-Key or Symmetric-Key Encrypted Session Key packet that precedes the Symmetrically Encrypted Data packet. In that case, the cipher algorithm octet is prefixed to the session key before it is encrypted. If no packets of these types precede the encrypted data, the IDEA algorithm is used with the session key calculated as the MD5 hash of the passphrase, though this use is deprecated.
The data is encrypted in CFB mode, with a CFB shift size equal to the cipher's block size. The Initial Vector (IV) is specified as all zeros. Instead of using an IV, OpenPGP prefixes a string of length equal to the block size of the cipher plus two to the data before it is encrypted. The first block-size octets (for example, 8 octets for a 64-bit block length) are random, and the following two octets are copies of the last two octets of the IV. For example, in an 8-octet block, octet 9 is a repeat of octet 7, and octet 10 is a repeat of octet 8. In a cipher of length 16, octet 17 is a repeat of octet 15 and octet 18 is a repeat of octet 16. As a pedantic clarification, in both these examples, we consider the first octet to be numbered 1.
After encrypting the first block-size-plus-two octets, the CFB state is resynchronized. The last block-size octets of ciphertext are passed through the cipher and the block boundary is reset.
The repetition of 16 bits in the random data prefixed to the message allows the receiver to immediately check whether the session key is incorrect. See the "Security Considerations" section for hints on the proper use of this "quick check". ๐
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 generated Literal packets with this tag. With PGP 5.x, this packet has been reassigned and is reserved for use as the Marker packet.
The body of this packet consists of:
- The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
Such a packet MUST be ignored when received. It may be placed at the beginning of a message that uses features not available in PGP 2.6.x in order to cause that version to report that newer software is necessary to process the message. ๐
5.9. Literal Data Packet (Tag 11) ๐๐ธ
A Literal Data packet contains the body of a message; data that is not to be further interpreted.
The body of this packet consists of:
- A one-octet field that describes how the data is formatted.
If it is a 'b' (0x62), then the Literal packet contains binary data. If it is a 't' (0x74), then it contains text data, and thus may need line ends converted to local form, or other text-mode changes. The tag 'u' (0x75) means the same as 't', but also indicates that implementation believes that the literal data contains UTF-8 text.
Early versions of PGP also defined a value of 'l' as a 'local' mode for machine-local conversions. RFC 1991 [RFC1991] incorrectly stated this local mode flag as '1' (ASCII numeral one). Both of these local modes are deprecated.
- File name as a string (one-octet length, followed by a file name). This may be a zero-length string. Commonly, if the source of the encrypted data is a file, this will be the name of the encrypted file. An implementation MAY consider the file name in the Literal packet to be a more authoritative name than the actual file name.
If the special name "_CONSOLE" is used, the message is considered to be "for your eyes only". This advises that the message data is unusually sensitive, and the receiving program should process it more carefully, perhaps avoiding storing the received data to disk, for example. ๐คซ
- A four-octet number that indicates a date associated with the literal data. Commonly, the date might be the modification date of a file, or the time the packet was created, or a zero that indicates no specific time.
- The remainder of the packet is literal data.
Text data is stored with <CR><LF> text endings (i.e., network-normal line endings). These should be converted to native line endings by the receiving software.
5.10. Trust Packet (Tag 12) ๐ก๏ธ
The Trust packet is used only within keyrings and is not normally exported. Trust packets contain data that record the user's specifications of which key holders are trustworthy introducers, along with other information that implementing software uses for trust information. The format of Trust packets is defined by a given implementation.
Trust packets SHOULD NOT be emitted to output streams that are transferred to other users, and they SHOULD be ignored on any input other than local keyring files. ๐
5.11. User ID Packet (Tag 13) ๐ชช๐
A User ID packet consists of UTF-8 text that is intended to represent the name and email address of the key holder. By convention, it includes an RFC 2822 [RFC2822] mail name-addr, but there are no restrictions on its content. The packet length in the header specifies the length of the User ID. โจ
5.12. User Attribute Packet (Tag 17) ๐
okay so the User Attribute packet is basically a cousin of the User ID packet ๐ except it can store way more kinds of data than the User ID packet, which is limited to text ๐. Just like the User ID packet, a User Attribute packet may be certified by the key owner ("self-signed") or by any other key owner who cares to certify it ๐ซถ. Except as noted, a User Attribute packet may be used anywhere that a User ID packet may be used โจ.
User Attribute packets are not a required part of the OpenPGP standard, but implementations SHOULD provide at least enough compatibility to properly handle a certification signature on the User Attribute packet ๐. A simple way to do this is to treat the User Attribute packet as a User ID packet with opaque contents, but an implementation may use any method desired ๐ฆ.
The User Attribute packet is made up of one or more attribute subpackets ๐ง. Each subpacket has a subpacket header and a body. The header consists of:
- the subpacket length (1, 2, or 5 octets)
- the subpacket type (1 octet)
and it is followed by the subpacket specific data ๐ธ.
The only currently defined subpacket type is 1, signifying an image. An implementation SHOULD ignore any subpacket of a type that it does not recognize ๐. Subpacket types 100 through 110 are reserved for private or experimental use ๐ฎ.
5.12.1. The Image Attribute Subpacket ๐ธ
The Image Attribute subpacket is used to encode an image, presumably (but not required to be) that of the key owner ๐.
The Image Attribute subpacket begins with an image header. The first two octets of the image header contain the length of the image header. Note that unlike other multi-octet numerical values in this document, due to a historical accident this value is encoded as a little-endian number ๐. The image header length is followed by a single octet for the image header version. The only currently defined version of the image header is 1, which is a 16-octet image header. The first three octets of a version 1 image header are thus 0x10, 0x00, 0x01.
The fourth octet of a version 1 image header designates the encoding format of the image. The only currently defined encoding format is the value 1 to indicate JPEG. Image format types 100 through 110 are reserved for private or experimental use. The rest of the version 1 image header is made up of 12 reserved octets, all of which MUST be set to 0 ๐.
The rest of the image subpacket contains the image itself. As the only currently defined image type is JPEG, the image is encoded in the JPEG File Interchange Format (JFIF), a standard file format for JPEG images [JFIF] ๐.
An implementation MAY try to determine the type of an image by examination of the image data if it is unable to handle a particular version of the image header or if a specified encoding format value is not recognized ๐.
5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) ๐
The Symmetrically Encrypted Integrity Protected Data packet is a variant of the Symmetrically Encrypted Data packet. It is a new feature created for OpenPGP that addresses the problem of detecting a modification to encrypted data ๐ต๏ธโโ๏ธ. It is used in combination with a Modification Detection Code packet ๐ฆ.
There is a corresponding feature in the features Signature subpacket that denotes that an implementation can properly use this packet type ๐ . An implementation MUST support decrypting these packets and SHOULD prefer generating them to the older Symmetrically Encrypted Data packet when possible ๐ฅ. Since this data packet protects against modification attacks, this standard encourages its proliferation ๐ฃ. While blanket adoption of this data packet would create interoperability problems, rapid adoption is nevertheless important ๐ญ. An implementation SHOULD specifically denote support for this packet, but it MAY infer it from other mechanisms โจ.
For example, an implementation might infer from the use of a cipher such as Advanced Encryption Standard (AES) or Twofish that a user supports this feature. It might place in the unhashed portion of another user's key signature a Features subpacket. It might also present a user with an opportunity to regenerate their own self-signature with a Features subpacket ๐ง.
This packet contains data encrypted with a symmetric-key algorithm and protected against modification by the SHA-1 hash algorithm. When it has been decrypted, it will typically contain other packets (often a Literal Data packet or Compressed Data packet). The last decrypted packet in this packet's payload MUST be a Modification Detection Code packet ๐ฏ.
The body of this packet consists of:
- A one-octet version number. The only currently defined value is 1.
- Encrypted data, the output of the selected symmetric-key cipher operating in Cipher Feedback mode with shift amount equal to the block size of the cipher (CFB-n where n is the block size).
The symmetric cipher used MUST be specified in a Public-Key or Symmetric-Key Encrypted Session Key packet that precedes the Symmetrically Encrypted Data packet. In either case, the cipher algorithm octet is prefixed to the session key before it is encrypted ๐๏ธ.
The data is encrypted in CFB mode, with a CFB shift size equal to the cipher's block size. The Initial Vector (IV) is specified as all zeros. Instead of using an IV, OpenPGP prefixes an octet string to the data before it is encrypted. The length of the octet string equals the block size of the cipher in octets, plus two. The first octets in the group, of length equal to the block size of the cipher, are random; the last two octets are each copies of their 2nd preceding octet. For example, with a cipher whose block size is 128 bits or 16 octets, the prefix data will contain 16 random octets, then two more octets, which are copies of the 15th and 16th octets, respectively. Unlike the Symmetrically Encrypted Data Packet, no special CFB resynchronization is done after encrypting this prefix data. See "OpenPGP CFB Mode" below for more details ๐ธ.
The repetition of 16 bits in the random data prefixed to the message allows the receiver to immediately check whether the session key is incorrect ๐.
The plaintext of the data to be encrypted is passed through the SHA-1 hash function, and the result of the hash is appended to the plaintext in a Modification Detection Code packet. The input to the hash function includes the prefix data described above; it includes all of the plaintext, and then also includes two octets of values 0xD3, 0x14. These represent the encoding of a Modification Detection Code packet tag and length field of 20 octets ๐งฎ.
The resulting hash value is stored in a Modification Detection Code (MDC) packet, which MUST use the two octet encoding just given to represent its tag and length field. The body of the MDC packet is the 20-octet output of the SHA-1 hash ๐.
The Modification Detection Code packet is appended to the plaintext and encrypted along with the plaintext using the same CFB context ๐ซถ.
During decryption, the plaintext data should be hashed with SHA-1, including the prefix data as well as the packet tag and length field of the Modification Detection Code packet. The body of the MDC packet, upon decryption, is compared with the result of the SHA-1 hash ๐.
Any failure of the MDC indicates that the message has been modified and MUST be treated as a security problem. Failures include a difference in the hash values, but also the absence of an MDC packet, or an MDC packet in any position other than the end of the plaintext. Any failure SHOULD be reported to the user. ๐จ๐
Note: future designs of new versions of this packet should consider rollback attacks since it will be possible for an attacker to change the version back to 1 ๐.
NON-NORMATIVE EXPLANATION ๐ง
The MDC system, as packets 18 and 19 are called, were created to provide an integrity mechanism that is less strong than a signature, yet stronger than bare CFB encryption ๐.
It is a limitation of CFB encryption that damage to the ciphertext will corrupt the affected cipher blocks and the block following. Additionally, if data is removed from the end of a CFB-encrypted block, that removal is undetectable. (Note also that CBC mode has a similar limitation, but data removed from the front of the block is undetectable.) ๐ฌ
The obvious way to protect or authenticate an encrypted block is to digitally sign it. However, many people do not wish to habitually sign data, for a large number of reasons beyond the scope of this document. Suffice it to say that many people consider properties such as deniability to be as valuable as integrity ๐คทโโ๏ธ.
OpenPGP addresses this desire to have more security than raw encryption and yet preserve deniability with the MDC system. An MDC is intentionally not a MAC. Its name was not selected by accident. It is analogous to a checksum ๐งฉ.
Despite the fact that it is a relatively modest system, it has proved itself in the real world. It is an effective defense to several attacks that have surfaced since it has been created. It has met its modest goals admirably ๐.
Consequently, because it is a modest security system, it has modest requirements on the hash function(s) it employs. It does not rely on a hash function being collision-free, it relies on a hash function being one-way. If a forger, Frank, wishes to send Alice a (digitally) unsigned message that says, "I've always secretly loved you, signed Bob", it is far easier for him to construct a new message than it is to modify anything intercepted from Bob. (Note also that if Bob wishes to communicate secretly with Alice, but without authentication or identification and with a threat model that includes forgers, he has a problem that transcends mere cryptography.) ๐๐ญ
Note also that unlike nearly every other OpenPGP subsystem, there are no parameters in the MDC system. It hard-defines SHA-1 as its hash function. This is not an accident. It is an intentional choice to avoid downgrade and cross-grade attacks while making a simple, fast system. (A downgrade attack would be an attack that replaced SHA-256 with SHA-1, for example. A cross-grade attack would replace SHA-1 with another 160-bit hash, such as RIPE-MD/160, for example.) ๐ฆ
However, given the present state of hash function cryptanalysis and cryptography, it may be desirable to upgrade the MDC system to a new hash function. See Section 13.11 in the "IANA Considerations" for guidance ๐.
5.14. Modification Detection Code Packet (Tag 19) ๐ต๏ธโโ๏ธ
okay bestie, this packet holds a SHA-1 hash of the plaintext, and its whole job is catching anyone who messes with the message ๐ It's only used with a Symmetrically Encrypted Integrity Protected Data packet. The Modification Detection Code packet MUST be the last packet in the plaintext data that gets encrypted inside that Symmetrically Encrypted Integrity Protected Data packet, and it MUST appear in no other place. Main character placement only ๐
A Modification Detection Code packet MUST have a length of 20 octets. No exceptions, no debate ๐
The body is just one thing:
- A 20-octet SHA-1 hash of the preceding plaintext data of the Symmetrically Encrypted Integrity Protected Data packet, including prefix data, the tag octet, and length octet of the Modification Detection Code packet.
Also, the Modification Detection Code packet MUST always use a new format encoding of the packet tag, plus a one-octet encoding of the packet length. The reason is that the hashing rules for modification detection include a one-octet tag and a one-octet length in the data hash. It's a bit restrictive, ngl, but it keeps things simpler ๐ง โจ
6. Radix-64 Conversions ๐
So, like we said in the intro, OpenPGP's native format for objects is just a stream of arbitrary octets. Some systems need those objects to survive character set translation, data conversions, and other chaos ๐ญ
In theory, 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. OpenPGP picks one specific 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 part is identical to the MIME base64 content-transfer-encoding [RFC2045] ๐ธ
The checksum is a 24-bit Cyclic Redundancy Check (CRC), turned into four radix-64 characters using the same MIME base64 transformation, and it gets an equal sign (=) in front. The CRC uses the generator 0x864CFB and an initialization of 0xB704CE. The accumulation runs over the data before it gets converted to radix-64, not over the converted data. There's a sample implementation in the next section ๐
The checksum with its leading equal sign MAY appear on the first line after the base64 encoded data.
Rationale for CRC-24: 24 bits fits evenly into printable base64, and a nonzero initialization can catch more errors than a zero initialization. Smart, right? ๐ง
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 ๐ฆ
When OpenPGP encodes data into ASCII Armor, it wraps the Radix-64 encoded data in specific headers, so OpenPGP can rebuild the data later. An OpenPGP implementation MAY use ASCII armor to protect raw binary data. The headers also tell the user what kind of data is inside the armor ๐
Here's how you put ASCII Armor together. Concatenate the following:
- An Armor Header Line, appropriate for the type of data
- Armor Headers
- A blank (zero-length, or containing only whitespace) line
- The ASCII-Armored data
- An Armor Checksum
- The Armor Tail, which depends on the Armor Header Line
An Armor Header Line is the right header line text surrounded by 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 amongst Y parts, and this is the Xth part out of Y.BEGIN PGP MESSAGE, PART X: Used for multi-part messages, where this is the Xth part of an unspecified number of parts. Requires the MESSAGE-ID Armor Header to be used.BEGIN PGP SIGNATURE: Used for detached signatures, OpenPGP/MIME signatures, and cleartext signatures. Note that PGP 2.x usesBEGIN PGP MESSAGEfor detached signatures.
Every one of these Armor Header Lines has to be a complete line. That means there's always a line ending before the starting five dashes, and after the ending five dashes. The header lines MUST start at the beginning of a line, and MUST NOT have any text other than whitespace following them on the same line. Those line endings count as part of the Armor Header Line when working out what content they delimit, which matters a LOT for cleartext signatures (see below) ๐ซ
The Armor Headers are key-value string pairs that can tell the user or the receiving OpenPGP implementation 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 ๐
Each Armor Header is a key-value pair. A colon (:, 0x3A) and a single space (0x20) separate the key and the value. Wait, let me get this exact: the separator is a colon (':' 0x38) followed by a single space (0x20). OpenPGP should consider improperly formatted Armor Headers to be corruption of the ASCII Armor. Unknown keys should be reported to the user, but OpenPGP should continue to process the message.
Note that some transport methods are picky about line length. There's a 76-character limit for the Radix-64 data (Section 6.3), but there's no limit on how long Armor Headers can be. Make sure they're short enough to survive transport. One trick is to repeat an Armor Header key several times with different values, so no single line gets overly long ๐
These are the Armor Header Keys defined so far:
- "Version", which states the OpenPGP implementation and version used to encode the message.
- "Comment", a user-defined comment. OpenPGP defines all text to be in UTF-8. A comment may be any UTF-8 string. However, the whole point of armoring is to provide seven-bit-clean data. So if a comment has characters outside the US-ASCII range of UTF, they may very well not survive transport ๐ฌ
- "MessageID", a 32-character string of printable characters. The string must be the same for all parts of a multi-part message that uses the "PART X" Armor Header. MessageID strings should be unique enough that the recipient of the mail can associate all the parts of a message with each other. A good checksum or cryptographic hash function is sufficient.
The MessageID SHOULD NOT appear unless it's in a multi-part message. If it does appear at all, it MUST be computed from the finished (encrypted, signed, etc.) message in a deterministic fashion, rather than being a purely random value. This lets the legitimate recipient confirm that the MessageID can't serve as a covert means of leaking cryptographic key information ๐ต๏ธโโ๏ธ๐
- "Hash", a comma-separated list of hash algorithms used in this message. This is only used in cleartext signed messages.
- "Charset", a description of the character set the plaintext is in. OpenPGP defines text to be in UTF-8, and an implementation gets the best results by translating into and out of UTF-8. Easier said than done, though! Some communities are super happy with a character set 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 Armor Tail Line is composed the same way as the Armor Header Line, except the string "BEGIN" is replaced by the string "END" ๐
6.3. Encoding Binary in Radix-64 โจ
okay bestie, so the encoding process takes your input in 24-bit groups and turns each group into 4 encoded characters ๐ง Going left to right, you glue three 8-bit input groups together to make one 24-bit group. Then those 24 bits get split into four 6-bit groups, and each one becomes a single digit in the Radix-64 alphabet ๐ When you're encoding a bit stream, the bit stream must be presumed to be ordered with the most significant bit first. So the first bit is the high-order bit in the first 8-bit octet, the eighth bit is the low-order bit in that same octet, and so on ๐ซถ
+--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 referenced by the index gets placed in 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. ๐
Special processing is performed if fewer than 24 bits are available at the end of the data being encoded. 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 ๐
In Radix-64 data, characters other than those in the table, line breaks, and other white space probably indicate a transmission error, which is a vibe check for a warning message or even a message rejection, depending on the situation. Decoding software must ignore all white space โจ
Because it is used only for padding at the end of the data, the occurrence of any = characters may be taken as evidence that the end of the data has been reached (without truncation in transit). No such assurance is possible, however, when the number of octets transmitted was a multiple of three and no = characters are present ๐
6.5. Examples of Radix-64 ๐
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 +
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 =
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 ๐ฆ
-----BEGIN PGP MESSAGE-----
Version: OpenPrivacy 0.99
yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
vBSFjNSiVHsuAA==
=njUN
-----END PGP MESSAGE-----
Note that this example has extra indenting; an actual armored message would have no leading whitespace. ๐
7. Cleartext Signature Framework ๐
It is desirable to be able to sign a textual octet stream without ASCII armoring the stream itself, so the signed text is still readable without special software ๐ To bind a signature to such a cleartext, this framework is used. (Note that this framework is not intended to be reversible. RFC 3156 [RFC3156] defines another way to sign cleartext messages for environments that support MIME.) The 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 not included into the message digest,
- The dash-escaped cleartext that is included into 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(s) are used for the signature. If there are no such headers, MD5 is used. If MD5 is the only hash used, then an implementation MAY omit this header for improved V2.x compatibility. If more than one message digest is used in the signature, the "Hash" armor header contains a comma-delimited list of used message digests ๐
Current message digest names are described below with the algorithm IDs.
An implementation SHOULD add a line break after the cleartext, but MAY omit it if the cleartext ends with a line break. This is for visual clarity ๐
7.1. Dash-Escaped Text ๐
The cleartext content of the message must also be dash-escaped.
Dash-escaped cleartext is the ordinary cleartext where every line starting with a dash - (0x2D) is prefixed by the sequence dash - (0x2D) and space ' ' (0x20). This prevents the parser from recognizing armor headers of the cleartext itself. An implementation MAY dash-escape any line, SHOULD dash-escape lines commencing "From" followed by a space, and MUST dash-escape any line commencing in a dash. The message digest is computed using the cleartext itself, not the dash-escaped form ๐ฅ
As with binary signatures on text documents, a cleartext signature is calculated on the text using canonical <CR><LF> line endings. The line ending (i.e., the <CR><LF>) before the -----BEGIN PGP SIGNATURE----- line that terminates the signed text is not considered part of the signed text ๐
When reversing dash-escaping, an implementation MUST strip the string "- " if it occurs at the beginning of a line, and SHOULD warn on "-" and any character other than a space at the beginning of a line. โ ๏ธ
Also, any trailing whitespace -- spaces (0x20) and tabs (0x09) -- at the end of any line is removed when the cleartext signature is generated. ๐งน
8. Regular Expressions ๐ง
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.
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).
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. ๐ฆ
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, so long as the algorithm numbers are chosen from the private or experimental algorithm range. โจ
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) [HAC]
2 - RSA Encrypt-Only [HAC]
3 - RSA Sign-Only [HAC]
16 - Elgamal (Encrypt-Only) [ELGAMAL] [HAC]
17 - DSA (Digital Signature Algorithm) [FIPS186] [HAC]
18 - Reserved for Elliptic Curve
19 - Reserved for ECDSA
20 - Reserved (formerly 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 (1). RSA Encrypt-Only (2) and RSA Sign-Only are deprecated and SHOULD NOT be generated, but may be interpreted. See Section 13.5. See Section 13.8 for notes on Elliptic Curve (18), ECDSA (19), Elgamal Encrypt or Sign (20), and X9.42 (21). Implementations MAY implement any other algorithm. ๐ธ
9.2. Symmetric-Key Algorithms ๐โจ
okay so here's the lineup of symmetric ciphers, bestie ๐ each ID is the number that shows up in the packet, and it points at one specific cipher:
ID Algorithm
-- ---------
0 - Plaintext or unencrypted data
1 - IDEA [IDEA]
2 - TripleDES (DES-EDE, [SCHNEIER] [HAC] -
168 bit key derived from 192)
3 - CAST5 (128 bit key, as per [RFC2144])
4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH]
5 - Reserved
6 - Reserved
7 - AES with 128-bit key [AES]
8 - AES with 192-bit key
9 - AES with 256-bit key
10 - Twofish with 256-bit key [TWOFISH]
100 to 110 - Private/Experimental algorithm
So the rules for what you have to build ๐: TripleDES is a MUST, no cap ๐ญ. AES-128 and CAST5 are a SHOULD, which means they're super recommended ๐ซถ. If you need to talk to PGP 2.6 or earlier, you need IDEA, because that's the only symmetric cipher those versions use ๐. Anything else is a MAY, so you can go wild ๐ฆ.
9.3. Compression Algorithms ๐๏ธ๐
Here's the compression menu, and yes, the IDs work the same way:
ID Algorithm
-- ---------
0 - Uncompressed
1 - ZIP [RFC1951]
2 - ZLIB [RFC1950]
3 - BZip2 [BZ2]
100 to 110 - Private/Experimental algorithm
Uncompressed data is a MUST, so every implementation has to handle it ๐. ZIP is a SHOULD, so you really want it in there โจ. Everything else is a MAY ๐.
9.4. Hash Algorithms ๐ง๐
Next up are the hash algorithms, with both their IDs and the text names you'd spell out:
ID Algorithm Text Name
-- --------- ---------
1 - MD5 [HAC] "MD5"
2 - SHA-1 [FIPS180] "SHA1"
3 - RIPE-MD/160 [HAC] "RIPEMD160"
4 - Reserved
5 - Reserved
6 - Reserved
7 - Reserved
8 - SHA256 [FIPS180] "SHA256"
9 - SHA384 [FIPS180] "SHA384"
10 - SHA512 [FIPS180] "SHA512"
11 - SHA224 [FIPS180] "SHA224"
100 to 110 - Private/Experimental algorithm
SHA-1 is a MUST for implementations ๐. Other algorithms are a MAY ๐ฆ. And MD5 is deprecated, so please don't reach for it ๐.
10. IANA Considerations ๐๏ธ๐ธ
OpenPGP is super parameterized, which means there are a bunch of things to think about when you're allocating parameters for extensions. This section explains how IANA should look at extensions to the protocol described in this document ๐ง .
10.1. New String-to-Key Specifier Types ๐
OpenPGP S2K specifiers have a way for new algorithms to turn a string into a key ๐ช. This spec makes a registry of S2K specifier types. Each entry has the S2K type, the name of the S2K, and a reference to the spec that defines it. The starting values for this registry are in Section 3.7.1. Adding a new S2K specifier MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐.
10.2. New Packets ๐ฆ
Big new OpenPGP features get added through new packet types ๐. This spec makes a registry of packet types. Each entry has the packet type, the name of the packet, and a reference to the spec that defines it. The starting values are in Section 4.3. Adding a new packet type MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐ .
10.2.1. User Attribute Types ๐ชช
The User Attribute packet gives you an extensible way to identify certificates in other ways ๐ซ. This spec makes a registry of User Attribute types, with the User Attribute type, its name, and a reference to the defining spec. The starting values are in Section 5.12. Adding a new User Attribute type MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐.
10.2.1.1. Image Format Subpacket Types ๐ผ๏ธ
Inside User Attribute packets there's an extensible mechanism for other kinds of image-based user attributes ๐ธ. This spec makes a registry of Image Attribute subpacket types, with the Image Attribute subpacket type, the name of that subpacket, and a reference to the defining spec. The starting values are in Section 5.12.1. Adding a new Image Attribute subpacket type MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐ท.
10.2.2. New Signature Subpackets โ๏ธ
OpenPGP signatures have a mechanism where signed (or unsigned) data can be attached for all sorts of purposes, through the Signature subpackets covered in Section 5.2.3.1 ๐ง. This spec makes a registry of Signature subpacket types, with the subpacket type, its name, and a reference to the defining spec. The starting values are in Section 5.2.3.1. Adding a new Signature subpacket MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐.
10.2.2.1. Signature Notation Data Subpackets ๐
Signatures also have a way to add extensions, through the Notation Data subpackets ๐ซง. Each notation is a key/value pair, and notations live in two spaces: a user space that nobody manages at all, and an IETF space ๐.
This spec makes a registry of Signature Notation Data types. It has the Signature Notation Data type, its name, its allowed values, and a reference to the defining spec. The starting values are in Section 5.2.3.16. Adding a new Signature Notation Data subpacket MUST be done through the EXPERT REVIEW method, as described in [RFC2434] ๐งโ๐ฌ.
10.2.2.2. Key Server Preference Extensions ๐
Signatures can also say what they prefer about key servers ๐๏ธ. This spec makes a registry of key server preferences, with the preference value, its name, and a reference to the defining spec. The starting values are in Section 5.2.3.17. Adding a new key server preference MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐ซถ.
10.2.2.3. Key Flags Extensions ๐ฉ
Signatures have a way to set flags about how a key gets used ๐๏ธ. This spec makes a registry of key usage flags, with the key flags value, the flag's name, and a reference to the defining spec. The starting values are in Section 5.2.3.21. Adding a new key usage flag MUST be done through the IETF CONSENSUS method, as described in [RFC2434] โจ.
10.2.2.4. Reason for Revocation Extensions ๐ซ
Signatures can also set flags that explain why a key was revoked ๐ฅ. This spec makes a registry of "Reason for Revocation" flags, with the "Reason for Revocation" flags value, its name, and a reference to the defining spec. The starting values are in Section 5.2.3.23. Adding a new feature flag MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐ซ.
10.2.2.5. Implementation Features ๐ ๏ธ
Signatures have flags that say which optional features an implementation supports ๐๏ธ. This spec makes a registry of feature-implementation flags, with the feature-implementation flags value, its name, and a reference to the defining spec. The starting values are in Section 5.2.3.24. Adding a new feature-implementation flag MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐ฅ.
Also see Section 13.12 for more on when feature flags are needed ๐.
10.2.3. New Packet Versions ๐ข
The core OpenPGP packets all have version numbers, so you can revise one by introducing a new version of an existing packet ๐ฃ. This spec makes a registry of packet types, with the packet type, the number of the version, and a reference to the defining spec. The starting values are in Section 5. Adding a new packet version MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐ธ.
10.3. New Algorithms ๐งช
Section 9 lists the core algorithms OpenPGP uses ๐. Adding a new algorithm is usually pretty simple ๐ฅฐ. For example, a new symmetric cipher usually just needs a constant allocated for it. If that cipher had a block size other than 64 or 128 bits, there might need to be extra documentation about how OpenPGP-CFB mode would be adjusted ๐งฉ. Same vibe with DSA: when it went from a maximum of 1024-bit public keys to 3072-bit public keys, the newer FIPS 186 already had enough info for anyone to implement it ๐. Changes to this document were mostly made for emphasis ๐ฃ.
10.3.1. Public-Key Algorithms ๐๏ธ
OpenPGP has a bunch of public-key algorithms ๐. This spec makes a registry of public-key algorithm identifiers, with the algorithm name, its key sizes and parameters, and a reference to the defining spec. The starting values are in Section 9. Adding a new public-key algorithm MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐.
10.3.2. Symmetric-Key Algorithms ๐
OpenPGP also has a bunch of symmetric-key algorithms ๐ฌ. This spec makes a registry of symmetric-key algorithm identifiers, with the algorithm name, its key sizes and block size, and a reference to the defining spec. The starting values are in Section 9. Adding a new symmetric-key algorithm MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐.
10.3.3. Hash Algorithms ๐ง
OpenPGP has a bunch of hash algorithms too ๐ง. This spec makes a registry of hash algorithm identifiers, with the algorithm name, a text version of that name, its block size, an OID hash prefix, and a reference to the defining spec. The starting values for the identifiers and text names are in Section 9, and the OIDs and expanded signature prefixes are in Section 5.2.2 ๐. Adding a new hash algorithm MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐ซถ.
10.3.4. Compression Algorithms ๐๏ธ
OpenPGP has a bunch of compression algorithms as well ๐ซ. This spec makes a registry of compression algorithm identifiers, with the algorithm name and a reference to the defining spec. The starting values are in Section 9.3. Adding a new compression key algorithm MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐.
11. Packet Composition ๐งฉ๐ง
OpenPGP packets get assembled into sequences, and that's how you make messages and transfer keys ๐ฌ. Not every possible packet sequence makes sense or is correct ๐. This section lays out the rules for how packets should be put into sequences ๐ .
11.1. Transferable Public Keys โจ
Okay bestie, so OpenPGP users can transfer public keys ๐ Here are the essential elements of a transferable public key:
- 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 User Attribute packets
- After each User Attribute packet, zero or more Signature packets (certifications)
- Zero or more Subkey packets
- After each Subkey packet, one Signature packet, plus optionally a revocation
The Public-Key packet comes first ๐ Each User ID packet after it tells you who owns the key. If there are several User IDs, that's several ways of identifying the same unique individual. Like, a user might have more than one email address and make a User ID for each one ๐ธ
Right after each User ID packet, there are zero or more Signature packets. Each of those is calculated on the User ID packet right before it and on the initial Public-Key packet. The signature certifies the public key and the User ID. Basically the signer is saying they believe this public key belongs to the user named in that User ID ๐ฆ
Zero or more User Attribute packets also live in this section. Like User IDs, each User Attribute packet is followed by zero or more Signature packets, calculated on the User Attribute packet right before them and on the initial Public-Key packet ๐
User Attribute packets and User ID packets can be freely mixed in this section, as long as each signature stays attached to the right User Attribute or User ID packet. No mix-ups allowed ๐
After the User ID packet or Attribute packet, there may be zero or more Subkey packets. Usually subkeys show up when the top-level public key is signature-only. But ANY V4 key can have subkeys, and those subkeys can be encryption-only, signature-only, or general-purpose ๐ง V3 keys MUST NOT have subkeys, though. Not even a little bit ๐
Every Subkey packet MUST be followed by one Signature packet, which should be a subkey binding signature issued by the top-level key. For subkeys that can issue signatures, the subkey binding signature MUST contain an Embedded Signature subpacket with a primary key binding signature (0x19) issued by the subkey on the top-level key. That's the cross-check that ties everything together ๐ฅ
Subkey and Key packets may each be followed by a revocation Signature packet to say the key is revoked. Revocation signatures only get accepted if they come from the key itself, or from a key that's allowed to issue revocations through a Revocation Key subpacket in a self-signature by the top-level key ๐
Transferable public-key packet sequences can be concatenated, so you can transfer multiple public keys in one go โจ
11.2. Transferable Secret Keys ๐
OpenPGP users may transfer secret keys too. A transferable secret key has the same format as a transferable public key, except it uses secret-key and secret-subkey packets instead of public-key and public-subkey packets ๐ Implementations SHOULD include self-signatures on any user IDs and subkeys, because that lets a complete public key get extracted from the transferable secret key automatically. Implementations MAY choose to omit the self-signatures, especially if a transferable public key comes along with the transferable secret key ๐ซถ
11.3. OpenPGP Messages ๐จ
An OpenPGP message is a packet or a sequence of packets that matches these grammatical rules (comma means 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 Data :- Symmetrically Encrypted Data Packet |
Symmetrically Encrypted Integrity Protected Data Packet
Encrypted Message :- Encrypted Data | ESK Sequence, Encrypted Data.
One-Pass Signed Message :- One-Pass Signature Packet,
OpenPGP Message, Corresponding Signature Packet.
Signed Message :- Signature Packet, OpenPGP Message |
One-Pass Signed Message.
Also, decrypting a Symmetrically Encrypted Data packet or a Symmetrically Encrypted Integrity Protected Data packet, as well as decompressing a Compressed Data packet, must yield a valid OpenPGP Message. No shortcuts here, babe ๐
11.4. Detached Signatures ๐
Some OpenPGP apps use so-called "detached signatures". Like, a program bundle might contain a file, plus a second file that's a detached signature of the first one ๐ These are just a Signature packet stored separately from the data they sign โจ
12. Enhanced Key Formats ๐ธ
12.1. Key Structures ๐๏ธ
Here's the format of an OpenPGP V3 key. Entries in square brackets are optional, and ellipses mean repetition ๐
RSA Public Key
[Revocation Self Signature]
User ID [Signature ...]
[User ID [Signature ...] ...]
Each signature certifies the RSA public key and the User ID right before it. The RSA public key can have many User IDs, and each User ID can have many signatures ๐ V3 keys are deprecated. Implementations MUST NOT generate new V3 keys, but MAY continue to use existing ones ๐ฅ
A V4 key that uses multiple public keys is similar, except the other keys get added to the end as "subkeys" of the primary key ๐ฆ
Primary-Key
[Revocation Self Signature]
[Direct Key Signature...]
User ID [Signature ...]
[User ID [Signature ...] ...]
[User Attribute [Signature ...] ...]
[[Subkey [Binding-Signature-Revocation]
Primary-Key-Binding-Signature] ...]
A subkey always has a single signature after it, issued with the primary key to tie the two keys together ๐ซถ That binding signature may be in either V3 or V4 format, but SHOULD be V4. Subkeys that can issue signatures MUST have a V4 binding signature, due to the REQUIRED embedded primary key binding signature. Big deal, very important ๐ญ
In the diagram above, if a subkey's binding signature has been revoked, the revoked key may be removed, leaving only one key ๐ง
In a V4 key, the primary key MUST be a key capable of certification. The subkeys can be keys of any other type. There may be other ways to build V4 keys too. For example, there could be a single-key RSA key in V4 format, a DSA primary key with an RSA encryption key, or an RSA primary key with an Elgamal subkey, etc. ๐
It's also possible to have a signature-only subkey. This lets a primary key collect certifications (key signatures) while only certifying the subkeys that get used for encryption and signatures ๐
12.2. Key IDs and Fingerprints ๐
For a V3 key, the eight-octet Key ID is made of the low 64 bits of the public modulus of the RSA key โจ
The fingerprint of a V3 key is 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. Note that both V3 keys and MD5 are deprecated. Bad vibes, bestie ๐
A V4 fingerprint is the 160-bit SHA-1 hash of the octet 0x99, 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 are the fields of the hash material, using a DSA key as the example ๐ธ
a.1) 0x99 (1 octet)
a.2) high-order length octet of (b)-(e) (1 octet)
a.3) low-order length octet of (b)-(e) (1 octet)
b) version number = 4 (1 octet);
c) timestamp of key creation (4 octets);
d) algorithm (1 octet): 17 = DSA (example);
e) Algorithm-specific fields.
And the Algorithm-Specific Fields for the DSA example:
Algorithm-Specific Fields for DSA keys (example):
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 mod p where x is secret).
It's possible for Key IDs to collide, meaning two different keys with the same Key ID. Note that there's a much smaller, but still non-zero, chance that two different keys have 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 ๐ฆ
Finally, the Key ID and fingerprint of a subkey are calculated the same way as for a primary key, including the 0x99 as the first octet (even though that isn't a valid packet ID for a public subkey) ๐
13. Notes on Algorithms ๐งช
13.1. PKCS#1 Encoding in OpenPGP ๐
This standard uses the PKCS#1 functions EME-PKCS1-v1_5 and EMSA-PKCS1-v1_5. However, the calling conventions of these functions have changed in the past. To avoid confusion and interoperability problems, we include local copies in this document, adapted from those in PKCS#1 v2.1 [RFC3447]. RFC 3447 should be treated as the ultimate authority on PKCS#1 for OpenPGP. Still, we think it's valuable to have a self-contained document that avoids problems later if the conventions need changing ๐
13.1.1. EME-PKCS1-v1_5-ENCODE โจ
Input:
k = the length in octets of the key modulus
M = message to be encoded, an octet string of length mLen, where
mLen <= k - 11
Output:
EM = encoded message, an octet string of length k
Error:
"message too long"
Here's how the steps go ๐ง
- Length checking: If mLen > k - 11, output "message too long" and stop.
- Generate an octet string PS of length k - mLen - 3 consisting of pseudo-randomly generated nonzero octets. The length of PS will be at least eight octets.
- Concatenate PS, the message M, and other padding to form an encoded message EM of length k octets as:
EM = 0x00 || 0x02 || PS || 0x00 || M
- Output EM.
13.1.2. EME-PKCS1-v1_5-DECODE ๐
Input:
EM = encoded message, an octet string
Output:
M = message, an octet string
Error:
"decryption error"
To decode an EME-PKCS1_v1_5 message, split the encoded message EM into an octet string PS (made of nonzero octets) and a message M, like this:
EM = 0x00 || 0x02 || PS || 0x00 || M
If the first octet of EM does not have hexadecimal value 0x00, if the second octet of EM does not have hexadecimal value 0x02, if there is no octet with hexadecimal value 0x00 to separate PS from M, or if the length of PS is less than 8 octets, output "decryption error" and stop. See also the security note in Section 14 about the differences in reporting between a decryption error and a padding error ๐
13.1.3. EMSA-PKCS1-v1_5 โจ
okay so this one is the deterministic one ๐ It only has an encoding operation, no decoding, zero randomness, zero drama ๐ธ
Option:
Hash- a hash function in whichhLendenotes the length in octets of the hash function output
Input:
M= message to be encodedmL= intended length in octets of the encoded message, at leasttLen + 11, wheretLenis the octet length of the DER encodingTof a certain value computed during the encoding operation
Output:
EM= encoded message, an octet string of lengthemLen
Errors: "message too long"; "intended encoded message length too short" ๐
Steps:
- Apply the hash function to the message
Mto produce a hash valueH:H = Hash(M).If the hash function outputs "message too long," output "message too long" and stop. - Using the list in Section 5.2.2, produce an ASN.1 DER value for the hash function used. Let
Tbe the full hash prefix from Section 5.2.2, and lettLenbe the length in octets ofT. - If
emLen < tLen + 11, output "intended encoded message length too short" and stop. - Generate an octet string
PSconsisting ofemLen - tLen - 3octets with hexadecimal value0xFF. The length ofPSwill be at least 8 octets. ๐ซถ - Concatenate
PS, the hash prefixT, and other padding to form the encoded messageEMasEM = 0x00 || 0x01 || PS || 0x00 || T. - Output
EM.
13.2. 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 multiple, different preferences. Like, Alice might have only TripleDES for alice@work.com but CAST5, Blowfish, and TripleDES for alice@home.org. Main character energy, she's different at work and at home ๐
Preferences can also show up in a subkey's binding signature, so keep that in mind too.
TripleDES is the MUST-implement algorithm, so if it isn't explicitly in the list, it's tacitly at the end. It's still good form to place it there explicitly ๐ Also, if an implementation doesn't implement the preference at all, it's implicitly a TripleDES-only implementation. Iconic, honestly.
An implementation MUST NOT use a symmetric algorithm that is not in the recipient's preference list. When encrypting to more than one recipient, the implementation finds a suitable algorithm by taking the intersection of the preferences of the recipients. Note that the MUST-implement algorithm, TripleDES, ensures that the intersection is not null. The implementation may use any mechanism to pick an algorithm in the intersection โจ
If an implementation can decrypt a message that a keyholder doesn't have in their preferences, the implementation SHOULD decrypt the message anyway, but MUST warn the keyholder that the protocol has been violated. So say Alice has software that implements every algorithm in this spec, but she still prefers subsets for work or home. If someone sends her an IDEA-encrypted message (not in her preferences), her software warns her that someone sent her an IDEA-encrypted message, but ideally it would still decrypt it. Warn her, but don't leave her hanging ๐ฆ
13.3. 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 I need to talk about though: the compression preferences and the hash preferences.
13.3.1. Compression Preferences
compression has been part of PGP since its very first days ๐ง OpenPGP and every previous version of PGP have offered it. In this spec, the default is for messages to be compressed, although an implementation is not required to do so. So the compression preference is a way for a keyholder to ask that messages not be compressed, probably because they're using a minimal implementation without compression. It also lets a keyholder say it can support alternate algorithms. Clever, right? ๐
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)] ๐
Additionally, an implementation MUST implement this preference to the degree of recognizing when to send an uncompressed message. A robust implementation would satisfy this by looking at the recipient's preference and acting accordingly. A minimal implementation can satisfy it by never generating a compressed message, since all implementations can handle messages that haven't been compressed ๐
13.3.2. Hash Algorithm Preferences
typically the signer picks the hash algorithm, not the verifier, because a signer rarely knows who's going to verify the signature ๐ This preference though allows a protocol based on digital signatures to ease negotiation.
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. Very cute, very efficient ๐ธ
Since SHA1 is the MUST-implement hash algorithm, if it isn't explicitly in the list, it's tacitly at the end. Again, good form to place it there explicitly ๐
13.4. 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. Instead they must use Literal Data packets to encode unencrypted or literal data. No plaintext in the encrypted packets, bestie, that's a hard no ๐
13.5. RSA
there are algorithm types for RSA Sign-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 to all algorithms. An implementation SHOULD NOT create such a key, but MAY interpret it.
An implementation SHOULD NOT implement RSA keys of size less than 1024 bits โจ
13.6. DSA
an implementation SHOULD NOT implement DSA keys of size less than 1024 bits. It MUST NOT implement a DSA key with a q size of less than 160 bits. DSA keys MUST also be a multiple of 64 bits, and the q size MUST be a multiple of 8 bits. The Digital Signature Standard (DSS) [FIPS186] specifies that DSA be used in one of the following ways:
- 1024-bit key, 160-bit q, SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512 hash
- 2048-bit key, 224-bit q, SHA-224, SHA-256, SHA-384, or SHA-512 hash
- 2048-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash
- 3072-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash
The above key and q size pairs were chosen to best balance the strength of the key with the strength of the hash ๐ฆ Implementations SHOULD use one of the above key and q size pairs when generating DSA keys. If DSS compliance is desired, one of the specified SHA hashes must be used as well. [FIPS186] is the ultimate authority on DSS, so consult it for all questions of DSS compliance ๐
Note that earlier versions of this standard only allowed a 160-bit q with no truncation allowed, so earlier implementations may not be able to handle signatures with a different q size or a truncated hash. Old versions be like "not meโฆ" ๐
13.7. Elgamal
an implementation SHOULD NOT implement Elgamal keys of size less than 1024 bits ๐ธ
13.8. Reserved Algorithm Numbers
a bunch of algorithm IDs have been reserved for algorithms that would be useful in an OpenPGP implementation, but there are issues that stop an implementer from actually implementing them ๐ฅบ These are marked in Section 9.1, "Public-Key Algorithms", 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. Not yet, babe ๐
Previous versions of OpenPGP permitted Elgamal [ELGAMAL] signatures with a public-key identifier of 20. These are no longer permitted. An implementation MUST NOT generate such keys. An implementation MUST NOT generate Elgamal signatures. See [BLEICHENBACHER] ๐ซ
13.9. OpenPGP CFB Mode
OpenPGP does symmetric encryption using a variant of Cipher Feedback mode (CFB mode) ๐ง This section describes the procedure it uses in detail. This mode is what's used for Symmetrically Encrypted Data Packets. The mechanism for encrypting secret-key material is similar, and it's described in the sections above.
Quick note on the math: the value BS is the block size in octets of the cipher. Most ciphers have a block size of 8 octets. AES and Twofish have a block size of 16 octets. Also, this description assumes the IV and CFB arrays start with an index of 1 (unlike C, which starts arrays at zero) ๐ค
OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and prefixes the plaintext with BS+2 octets of random data, such that octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB resynchronization after encrypting those BS+2 octets.
So for an algorithm with a block size of 8 octets (64 bits), the IV is 10 octets long, and octets 7 and 8 of the IV are the same as octets 9 and 10. For an algorithm with a block size of 16 octets (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate octets 15 and 16. Those extra two octets are an easy check for a correct key โจ Iconic little safety net, honestly.
Step by step, here's 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
BSoctets of random data prefixed to the plaintext to produceC[1]throughC[BS], the firstBSoctets of ciphertext. - FR is loaded with
C[1]throughC[BS]. - FR is encrypted to produce FRE, the encryption of the first
BSoctets 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
C[BS+1]andC[BS+2], the next two octets of ciphertext. - (The resynchronization step) FR is loaded with
C[3]throughC[BS+2]. - FR is encrypted to produce FRE.
- FRE is xored with the first
BSoctets of the given plaintext, now that we've finished encrypting theBS+2octets of prefixed data. This producesC[BS+3]throughC[BS+(BS+2)], the nextBSoctets of ciphertext. - FR is loaded with
C[BS+3]toC[BS + (BS+2)](which isC11-C18for an 8-octet block). - FR is encrypted to produce FRE.
- FRE is xored with the next
BSoctets of plaintext, to produce the nextBSoctets of ciphertext. These are loaded into FR, and the process is repeated until the plaintext is used up. ๐
13.10. Private or Experimental Parameters
S2K specifiers, Signature subpacket types, user attribute types, image format types, and algorithms described in Section 9 all reserve the range 100 to 110 for private and experimental use. Packet types reserve the range 60 to 63 for private and experimental use. These are intentionally managed with the PRIVATE USE method, as described in [RFC2434] ๐ง
However, implementations need to be careful with these and promote them to full IANA-managed parameters when they grow beyond the original, limited system. Growing up is hard, but it's necessary ๐
13.11. Extension of the MDC System ๐ฆ
okay so, the non-normative bit in Section 5.13 explains that the MDC system is uniquely unparameterized in OpenPGP ๐ง. That was a deliberate choice to dodge cross-grade attacks ๐. If the MDC system ever gets extended to a stronger hash function, you have to be super careful to avoid downgrade and cross-grade attacks ๐.
One simple way is to make brand-new packets for the new MDC. Like, instead of the MDC system using packets 18 and 19, a new MDC could use 20 and 21. The obvious drawback is that this burns two packet numbers for every new hash function, and the whole space is capped at a maximum of 60 ๐ฅฒ.
Another simple way is to make new versions of packet 18 and reflect that in packet 19 โจ. For example, say V2 of packet 18 implicitly used SHA-256. Then packet 19 would have to be 32 octets long. The version change in packet 18 plus the size of packet 19 are what prevent a downgrade attack ๐ก๏ธ.
There are two drawbacks to this approach. First, using a packet's version number to carry algorithm info is not tidy from a protocol-design standpoint ๐ค. Several versions of the MDC system might end up in common use, but that messiness would just mirror the messiness in cryptographic consensus about hash function security ๐ซ . Second, different versions of packet 19 would need unique sizes. If two versions each had 256-bit hashes, they couldn't both use 32-octet packet 19s without admitting the chance of a cross-grade attack ๐ฑ.
Yet another approach, a complex one, would be a hybrid of the two above: create a new pair of MDC packets that are fully parameterized, and yet still protected from downgrade and cross-grade attacks ๐.
Real talk, any change to the MDC system MUST be done through the IETF CONSENSUS method, as described in [RFC2434] ๐.
13.12. Meta-Considerations for Expansion ๐งฉ
If OpenPGP gets extended in a way that isn't backwards-compatible, meaning old implementations won't gracefully handle the absence of a new feature, the extension proposal can be declared in the key holder's self-signature as part of the Features signature subpacket ๐.
We cannot state definitively what extensions will not be upwards-compatible. Typically, though, new algorithms are upwards-compatible, whereas new packets are not ๐.
If an extension proposal does not update the Features system, it SHOULD include an explanation of why this is unnecessary. If the proposal contains neither an extension to the Features system nor an explanation of why such an extension is unnecessary, the proposal SHOULD be rejected ๐ โโ๏ธ.
14. Security Considerations โจ
Okay bestie, this part is serious business. Read it all, no skipping ๐ญ๐ฅ
- 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 ๐.
- This specification uses Public-Key Cryptography technologies. It is assumed that the private key portion of a public-private key pair is controlled and secured 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 [RFC4086]) ๐ฒ.
- The MD5 hash algorithm has been found to have weaknesses, with collisions found in a number of cases. MD5 is deprecated for use in OpenPGP. Implementations MUST NOT generate new signatures using MD5 as a hash function. They MAY continue to consider old signatures that used MD5 as valid ๐.
- SHA-224 and SHA-384 require the same work as SHA-256 and SHA-512, respectively. In general, there are few reasons to use them outside of DSS compatibility. You need a situation where one needs more security than smaller hashes, but does not want to have the full 256-bit or 512-bit data length ๐ค.
- Many security protocol designers think 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 implementer promote dual-use keys, you should at least be aware of this controversy ๐.
- The DSA algorithm will work with any hash, but is sensitive to the quality of the hash algorithm. Verifiers should be aware that even if the signer used a strong hash, an attacker could have modified the signature to use a weak one. Only signatures using acceptably strong hash algorithms should be accepted as valid ๐ง.
- As OpenPGP combines many different asymmetric, symmetric, and hash algorithms, each with different measures of strength, care should be taken that the weakest element of an OpenPGP message is still sufficiently strong for the purpose at hand. While consensus about the strength of a given algorithm may evolve, NIST Special Publication 800-57 [SP800-57] recommends the following list of equivalent strengths ๐ช:
Asymmetric | Hash | Symmetric
key size | size | key size
------------+--------+-----------
1024 160 80
2048 224 112
3072 256 128
7680 384 192
15360 512 256
- There is a somewhat-related potential security problem in signatures. If an attacker can find a message that hashes to the same hash with a different algorithm, a bogus signature structure can be constructed that evaluates correctly ๐ฑ.
For example, suppose Alice DSA signs message M using hash algorithm H. Suppose that Mallet finds a message M' that has the same hash value as M with H'. Mallet can then construct a signature block that verifies as Alice's signature of M' with H'. However, this would also constitute a weakness in either H or H' or both. Should this ever occur, a revision will have to be made to this document to revise the allowed hash algorithms ๐จ.
- 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 TripleDES. Other algorithms may have other controversies surrounding them ๐ต๏ธโโ๏ธ.
- In late summer 2002, Jallad, Katz, and Schneier published an interesting attack on the OpenPGP protocol and some of its implementations [JKS02]. In this attack, the attacker modifies a message and sends it to a user who then returns the erroneously decrypted message to the attacker. The attacker is thus using the user as a random oracle, and can often decrypt the message ๐ญ.
Compressing data can ameliorate this attack. The incorrectly decrypted data nearly always decompresses in ways that defeat the attack. However, this is not a rigorous fix, and leaves open some small vulnerabilities. For example, if an implementation does not compress a message before encryption (perhaps because it knows it was already compressed), then that message is vulnerable. Because of this happenstance, that modification attacks can be thwarted by decompression errors, an implementation SHOULD treat a decompression error as a security problem, not merely a data problem ๐ง .
This attack can be defeated by the use of Modification Detection, provided that the implementation does not let the user naively return the data to the attacker. An implementation MUST treat an MDC failure as a security problem, not merely a data problem ๐ก๏ธ.
In either case, the implementation MAY allow the user access to the erroneous data, but MUST warn the user as to potential security problems should that data be returned to the sender โ ๏ธ.
While this attack is somewhat obscure, requiring a special set of circumstances to create it, it is nonetheless quite serious, as it permits someone to trick a user into decrypting a message. Consequently, it is important that:
- Implementers treat MDC errors and decompression failures as security problems.
- Implementers implement Modification Detection with all due speed and encourage its spread.
- Users migrate to implementations that support Modification Detection with all due speed.
- PKCS#1 has been found to be vulnerable to attacks in which a system that reports errors in padding differently from errors in decryption becomes a random oracle that can leak the private key in mere millions of queries. Implementations must be aware of this attack and prevent it from happening. The simplest solution is to report a single error code for all variants of decryption errors so as not to leak information to an attacker ๐.
- Some technologies mentioned here may be subject to government control in some countries ๐.
- In winter 2005, Serge Mister and Robert Zuccherato from Entrust released a paper describing a way that the "quick check" in OpenPGP CFB mode can be used with a random oracle to decrypt two octets of every cipher block [MZ05]. They recommend as prevention not using the quick check at all ๐ซฃ.
Many implementers have taken this advice to heart for any data that is symmetrically encrypted and for which the session key is public-key encrypted. In this case, the quick check is not needed, as the public-key encryption of the session key should guarantee that it is the right session key. In other cases, the implementation should use the quick check with care ๐ .
On the one hand, there is a danger to using it if there is a random oracle that can leak information to an attacker. In plainer language, there is a danger to using the quick check if timing information about the check can be exposed to an attacker, particularly via an automated service that allows rapidly repeated queries ๐ซ.
On the other hand, it is inconvenient to the user to be informed that they typed in the wrong passphrase only after a petabyte of data is decrypted ๐ฉ. There are many cases in cryptographic engineering where the implementer must use care and wisdom, and this is one ๐โจ.
15. Implementation Nits โจ
Okay bestie, this section is a grab bag of tips for implementers who want to stay backward-compatible ๐ Old PGP versions aren't OpenPGP compliant, and the tiny differences are honestly the most annoying ones ๐ญ So this is a non-comprehensive list of gotchas, the ones that'll trip you up if you're trying to play nice with older stuff ๐
- The IDEA algorithm is patented, and yet it's still required for PGP 2.x interoperability ๐ It's also the de-facto preferred algorithm for a V3 key with a V3 self-signature (or no self-signature). ๐ฅ
- When exporting a private key, PGP 2.x generates the header
BEGIN PGP SECRET KEY BLOCKinstead ofBEGIN PGP PRIVATE KEY BLOCK. All previous versions ignore the implied data type and look directly at the packet data type ๐ง - PGP 2.0 through 2.5 generated V2 Public-Key packets. These are identical to the deprecated V3 keys except for the version number. An implementation MUST NOT generate them and may accept or reject them as it sees fit ๐ โโ๏ธ Some older PGP versions generated V2 PKESK packets (Tag 1) as well. An implementation may accept or reject V2 PKESK packets as it sees fit, and MUST NOT generate them ๐
- PGP 2.6.x will not accept key-material packets with versions greater than 3 ๐ค
- There are many ways two keys can have the same key material but different fingerprints (and thus Key IDs) ๐ฆ Perhaps the most interesting one is an RSA key that has been "upgraded" to V4 format. A V4 fingerprint is constructed by hashing the key creation time along with other things, so two V4 keys created at different times, yet with the same key material, will have different fingerprints. It's giving plot twist ๐
- If an implementation is using zlib to interoperate with PGP 2.x, then the "windowBits" parameter should be set to -13 โญ
- The 0x19 back signatures weren't required for signing subkeys until relatively recently. Consequently, there may be keys out in the wild that don't have these back signatures. Implementing software may handle these keys as it sees fit ๐ธ
- OpenPGP doesn't put limits on the size of public keys. However, bigger keys aren't necessarily better keys! Larger keys take more computation time to use, and this can quickly become impractical ๐ฉ Different OpenPGP implementations may also use different upper bounds for public key sizes, so care should be taken when choosing sizes to maintain interoperability. As of 2007, most implementations have an upper bound of 4096 bits ๐
- ASCII armor is an optional feature of OpenPGP. The OpenPGP working group strives for a minimal set of mandatory-to-implement features, and since there could be useful implementations that only use binary object formats, this is not a "MUST" feature for an implementation ๐ซถ For example, an implementation that's using OpenPGP as a mechanism for file signatures may find ASCII armor unnecessary. OpenPGP lets an implementation declare what features it does and doesn't support, but ASCII armor is not one of those features. Since most implementations allow binary and armored objects to be used indiscriminately, an implementation that doesn't implement ASCII armor may find itself with compatibility issues with general-purpose implementations ๐ฌ Moreover, implementations of OpenPGP-MIME [RFC3156] already have a requirement for ASCII armor, so those implementations will necessarily have support ๐
16. References ๐
16.1. Normative References
[AES] NIST, FIPS PUB 197, "Advanced Encryption Standard
(AES)," November 2001.
http://csrc.nist.gov/publications/fips/fips197/fips-
197.{ps,pdf}
[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>
[BZ2] J. Seward, jseward@acm.org, "The Bzip2 and libbzip2
home page" <http://www.bzip.org/>
[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.
[FIPS180] Secure Hash Signature Standard (SHS) (FIPS PUB 180-
2).
<http://csrc.nist.gov/publications/fips/fips180-
2/fips180-2withchangenotice.pdf>
[FIPS186] Digital Signature Standard (DSS) (FIPS PUB 186-2).
<http://csrc.nist.gov/publications/fips/fips186-2/
fips186-2-change1.pdf> FIPS 186-3 describes keys
greater than 1024 bits. The latest draft is at:
<http://csrc.nist.gov/publications/drafts/
fips_186-3/Draft-FIPS-186-3%20_March2006.pdf>
[HAC] Alfred Menezes, Paul van Oorschot, and Scott
Vanstone, "Handbook of Applied Cryptography," CRC
Press, 1996.
<http://www.cacr.math.uwaterloo.ca/hac/>
[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
[ISO10646] ISO/IEC 10646-1:1993. International Standard --
Information technology -- Universal Multiple-Octet
Coded Character Set (UCS) -- Part 1: Architecture
and Basic Multilingual Plane.
[JFIF] JPEG File Interchange Format (Version 1.02). Eric
Hamilton, C-Cube Microsystems, Milpitas, CA,
September 1, 1992.
[RFC1950] Deutsch, P. and J-L. Gailly, "ZLIB Compressed Data
Format Specification version 3.3", RFC 1950, May
1996.
[RFC1951] Deutsch, P., "DEFLATE Compressed Data Format
Specification version 1.3", RFC 1951, May 1996.
[RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet
Mail Extensions (MIME) Part One: Format of Internet
Message Bodies", RFC 2045, November 1996
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
Requirement Levels", BCP 14, RFC 2119, March 1997.
[RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC
2144, May 1997.
[RFC2434] Narten, T. and H. Alvestrand, "Guidelines for
Writing an IANA Considerations Section in RFCs", BCP
26, RFC 2434, October 1998.
[RFC2822] Resnick, P., "Internet Message Format", RFC 2822,
April 2001.
[RFC3156] Elkins, M., Del Torto, D., Levien, R., and T.
Roessler, "MIME Security with OpenPGP", RFC 3156,
August 2001.
[RFC3447] Jonsson, J. and B. Kaliski, "Public-Key Cryptography
Standards (PKCS) #1: RSA Cryptography Specifications
Version 2.1", RFC 3447, February 2003.
[RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO
10646", STD 63, RFC 3629, November 2003.
[RFC4086] Eastlake, D., 3rd, Schiller, J., and S. Crocker,
"Randomness Requirements for Security", BCP 106, RFC
4086, June 2005.
[SCHNEIER] Schneier, B., "Applied Cryptography Second Edition:
protocols, algorithms, and source code in C", 1996.
[TWOFISH] B. Schneier, J. Kelsey, D. Whiting, D. Wagner, C.
Hall, and N. Ferguson, "The Twofish Encryption
Algorithm", John Wiley & Sons, 1999.
16.2. Informative References
[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>
[JKS02] Kahil Jallad, Jonathan Katz, Bruce Schneier
"Implementation of Chosen-Ciphertext Attacks against
PGP and GnuPG" http://www.counterpane.com/pgp-
attack.html
[MAURER] Ueli Maurer, "Modelling a Public-Key
Infrastructure", Proc. 1996 European Symposium on
Research in Computer Security (ESORICS' 96), Lecture
Notes in Computer Science, Springer-Verlag, vol.
1146, pp. 325-350, Sep 1996.
[MZ05] Serge Mister, Robert Zuccherato, "An Attack on CFB
Mode Encryption As Used By OpenPGP," IACR ePrint
Archive: Report 2005/033, 8 Feb 2005
http://eprint.iacr.org/2005/033
[REGEX] Jeffrey Friedl, "Mastering Regular Expressions,"
O'Reilly, ISBN 0-596-00289-0.
[RFC1423] Balenson, D., "Privacy Enhancement for Internet
Electronic Mail: Part III: Algorithms, Modes, and
Identifiers", RFC 1423, February 1993.
[RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP
Message Exchange Formats", RFC 1991, August 1996.
[RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R.
Thayer, "OpenPGP Message Format", RFC 2440, November
1998.
[SP800-57] NIST Special Publication 800-57, Recommendation on
Key Management
<http://csrc.nist.gov/publications/nistpubs/ 800-
57/SP800-57-Part1.pdf>
<http://csrc.nist.gov/publications/nistpubs/ 800-
57/SP800-57-Part2.pdf>
Acknowledgements ๐ซถ
This memo also draws on loads of previous work from a bunch of other authors, including: Derek Atkins, Charles Breed, Dave Del Torto, Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Ben Laurie, Raph Levien, Colin Plumb, Will Price, David Shaw, William Stallings, Mark Weaver, and Philip R. Zimmermann ๐ The people who came before really laid the groundwork, no cap ๐
Authors' Addresses ๐
The working group can be contacted via the current chair:
Derek Atkins
IHTFP Consulting, Inc.
4 Farragut Ave
Somerville, MA 02144 USA
EMail: derek@ihtfp.com
Tel: +1 617 623 3745
The principal authors of this document are as follows:
Jon Callas
EMail: jon@callas.org
Lutz Donnerhacke
IKS GmbH
Wildenbruchstr. 15
07745 Jena, Germany
EMail: lutz@iks-jena.de
Hal Finney
EMail: hal@finney.org
David Shaw
EMail: dshaw@jabberwocky.com
Rodney Thayer
EMail: rodney@canola-jones.com
Full Copyright Statement โจ
okay so the copyright bit is up first ๐ The IETF Trust owns the copyright for 2007, and this document is covered by the rights, licenses, and restrictions in BCP 78. Except for what BCP 78 says, the authors keep all their own rights ๐ฆ
The document and everything in it come "AS IS," no guarantees attached ๐ The contributor, the organization they represent or are sponsored by (if there is one), the Internet Society, the IETF Trust, and the Internet Engineering Task Force all say no to every warranty, stated or implied. That includes no promise that using the info won't infringe anyone's rights, and no promise it's merchantable or fit for a particular purpose ๐
Intellectual Property ๐
the IETF is not picking a side on whether any IPR or other rights claimed over the tech in this document are valid, how far they reach, or whether anyone can get a license for them. It also hasn't done any independent digging to find such rights ๐ If you want the details on how rights work for RFC documents, look in BCP 78 and BCP 79 ๐
Copies of IPR disclosures sent to the IETF Secretariat, plus any promised licenses, and the outcome of any attempt to get a general license or permission for implementers or users to use those proprietary rights, can be found in the IETF online IPR repository at http://www.ietf.org/ipr ๐ธ
The IETF invites anyone who knows about copyrights, patents, patent applications, or other proprietary rights that might cover technology needed to implement this standard to tell them about it. Send that info to the IETF at ietf-ipr@ietf.org ๐ซถ
๐ฆ where this page comes from
- ietf: rfc4880 2007-11
- ๐ girlified by claude-haiku-5-5 on : a language model's rewrite of the original, under its terms