idnits 2.17.1 draft-ietf-openpgp-crypto-refresh-01.txt: -(2755): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding -(2757): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding -(2759): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == There are 8 instances of lines with non-ascii characters in the document. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- -- The draft header indicates that this document obsoletes RFC4880, but the abstract doesn't seem to directly say this. It does mention RFC4880 though, so this could be OK. -- The draft header indicates that this document obsoletes RFC5581, but the abstract doesn't seem to mention this, which it should. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (5 February 2021) is 1176 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '0' on line 350 -- Looks like a reference, but probably isn't: '1' on line 3854 -- Looks like a reference, but probably isn't: '2' on line 350 -- Looks like a reference, but probably isn't: '3' on line 3863 == Missing Reference: 'Optional' is mentioned on line 2102, but not defined == Missing Reference: 'Binding-Signature-Revocation' is mentioned on line 3467, but not defined == Missing Reference: 'BS' is mentioned on line 3854, but not defined -- Possible downref: Non-RFC (?) normative reference: ref. 'AES' -- Possible downref: Non-RFC (?) normative reference: ref. 'BLOWFISH' -- Possible downref: Non-RFC (?) normative reference: ref. 'BZ2' -- Possible downref: Non-RFC (?) normative reference: ref. 'ELGAMAL' -- Possible downref: Non-RFC (?) normative reference: ref. 'FIPS180' -- Possible downref: Non-RFC (?) normative reference: ref. 'FIPS186' -- Possible downref: Non-RFC (?) normative reference: ref. 'HAC' -- Possible downref: Non-RFC (?) normative reference: ref. 'IDEA' -- Possible downref: Non-RFC (?) normative reference: ref. 'ISO10646' -- Possible downref: Non-RFC (?) normative reference: ref. 'JFIF' ** Downref: Normative reference to an Informational RFC: RFC 1950 ** Downref: Normative reference to an Informational RFC: RFC 1951 ** Downref: Normative reference to an Informational RFC: RFC 2144 ** Obsolete normative reference: RFC 2434 (Obsoleted by RFC 5226) ** Obsolete normative reference: RFC 2822 (Obsoleted by RFC 5322) ** Obsolete normative reference: RFC 3447 (Obsoleted by RFC 8017) ** Downref: Normative reference to an Informational RFC: RFC 3713 -- Possible downref: Non-RFC (?) normative reference: ref. 'SCHNEIER' -- Possible downref: Non-RFC (?) normative reference: ref. 'TWOFISH' -- Obsolete informational reference (is this intentional?): RFC 1991 (Obsoleted by RFC 4880) -- Obsolete informational reference (is this intentional?): RFC 2440 (Obsoleted by RFC 4880) Summary: 7 errors (**), 0 flaws (~~), 5 warnings (==), 22 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Network Working Group W. Koch, Ed. 3 Internet-Draft GnuPG e.V. 4 Obsoletes: 4880, 5581 (if approved) P. Wouters, Ed. 5 Intended status: Standards Track 5 February 2021 6 Expires: 9 August 2021 8 OpenPGP Message Format 9 draft-ietf-openpgp-crypto-refresh-01 11 Abstract 13 { Work in progress to update the OpenPGP specification from RFC4880 } 15 This document specifies the message formats used in OpenPGP. OpenPGP 16 provides encryption with public-key or symmetric cryptographic 17 algorithms, digital signatures, compression and key management. 19 This document is maintained in order to publish all necessary 20 information needed to develop interoperable applications based on the 21 OpenPGP format. It is not a step-by-step cookbook for writing an 22 application. It describes only the format and methods needed to 23 read, check, generate, and write conforming packets crossing any 24 network. It does not deal with storage and implementation questions. 25 It does, however, discuss implementation issues necessary to avoid 26 security flaws. 28 Status of This Memo 30 This Internet-Draft is submitted in full conformance with the 31 provisions of BCP 78 and BCP 79. 33 Internet-Drafts are working documents of the Internet Engineering 34 Task Force (IETF). Note that other groups may also distribute 35 working documents as Internet-Drafts. The list of current Internet- 36 Drafts is at https://datatracker.ietf.org/drafts/current/. 38 Internet-Drafts are draft documents valid for a maximum of six months 39 and may be updated, replaced, or obsoleted by other documents at any 40 time. It is inappropriate to use Internet-Drafts as reference 41 material or to cite them other than as "work in progress." 43 This Internet-Draft will expire on 9 August 2021. 45 Copyright Notice 47 Copyright (c) 2021 IETF Trust and the persons identified as the 48 document authors. All rights reserved. 50 This document is subject to BCP 78 and the IETF Trust's Legal 51 Provisions Relating to IETF Documents (https://trustee.ietf.org/ 52 license-info) in effect on the date of publication of this document. 53 Please review these documents carefully, as they describe your rights 54 and restrictions with respect to this document. Code Components 55 extracted from this document must include Simplified BSD License text 56 as described in Section 4.e of the Trust Legal Provisions and are 57 provided without warranty as described in the Simplified BSD License. 59 Table of Contents 61 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 4 62 1.1. Terms . . . . . . . . . . . . . . . . . . . . . . . . . . 4 63 2. General functions . . . . . . . . . . . . . . . . . . . . . . 5 64 2.1. Confidentiality via Encryption . . . . . . . . . . . . . 6 65 2.2. Authentication via Digital Signature . . . . . . . . . . 6 66 2.3. Compression . . . . . . . . . . . . . . . . . . . . . . . 7 67 2.4. Conversion to Radix-64 . . . . . . . . . . . . . . . . . 7 68 2.5. Signature-Only Applications . . . . . . . . . . . . . . . 8 69 3. Data Element Formats . . . . . . . . . . . . . . . . . . . . 8 70 3.1. Scalar Numbers . . . . . . . . . . . . . . . . . . . . . 8 71 3.2. Multiprecision Integers . . . . . . . . . . . . . . . . . 8 72 3.3. Key IDs . . . . . . . . . . . . . . . . . . . . . . . . . 9 73 3.4. Text . . . . . . . . . . . . . . . . . . . . . . . . . . 9 74 3.5. Time Fields . . . . . . . . . . . . . . . . . . . . . . . 9 75 3.6. Keyrings . . . . . . . . . . . . . . . . . . . . . . . . 9 76 3.7. String-to-Key (S2K) Specifiers . . . . . . . . . . . . . 9 77 3.7.1. String-to-Key (S2K) Specifier Types . . . . . . . . . 9 78 3.7.2. String-to-Key Usage . . . . . . . . . . . . . . . . . 12 79 4. Packet Syntax . . . . . . . . . . . . . . . . . . . . . . . . 13 80 4.1. Overview . . . . . . . . . . . . . . . . . . . . . . . . 13 81 4.2. Packet Headers . . . . . . . . . . . . . . . . . . . . . 13 82 4.2.1. Old Format Packet Lengths . . . . . . . . . . . . . . 14 83 4.2.2. New Format Packet Lengths . . . . . . . . . . . . . . 14 84 4.2.3. Packet Length Examples . . . . . . . . . . . . . . . 16 85 4.3. Packet Tags . . . . . . . . . . . . . . . . . . . . . . . 16 86 5. Packet Types . . . . . . . . . . . . . . . . . . . . . . . . 17 87 5.1. Public-Key Encrypted Session Key Packets (Tag 1) . . . . 18 88 5.2. Signature Packet (Tag 2) . . . . . . . . . . . . . . . . 19 89 5.2.1. Signature Types . . . . . . . . . . . . . . . . . . . 19 90 5.2.2. Version 3 Signature Packet Format . . . . . . . . . . 21 91 5.2.3. Version 4 Signature Packet Format . . . . . . . . . . 24 92 5.2.4. Computing Signatures . . . . . . . . . . . . . . . . 39 93 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) . . . 41 94 5.4. One-Pass Signature Packets (Tag 4) . . . . . . . . . . . 42 95 5.5. Key Material Packet . . . . . . . . . . . . . . . . . . . 43 96 5.5.1. Key Packet Variants . . . . . . . . . . . . . . . . . 43 97 5.5.2. Public-Key Packet Formats . . . . . . . . . . . . . . 43 98 5.5.3. Secret-Key Packet Formats . . . . . . . . . . . . . . 45 99 5.6. Compressed Data Packet (Tag 8) . . . . . . . . . . . . . 47 100 5.7. Symmetrically Encrypted Data Packet (Tag 9) . . . . . . . 48 101 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) . . . . 48 102 5.9. Literal Data Packet (Tag 11) . . . . . . . . . . . . . . 49 103 5.10. Trust Packet (Tag 12) . . . . . . . . . . . . . . . . . . 50 104 5.11. User ID Packet (Tag 13) . . . . . . . . . . . . . . . . . 50 105 5.12. User Attribute Packet (Tag 17) . . . . . . . . . . . . . 50 106 5.12.1. The Image Attribute Subpacket . . . . . . . . . . . 51 107 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 108 18) . . . . . . . . . . . . . . . . . . . . . . . . . . 51 109 5.14. Modification Detection Code Packet (Tag 19) . . . . . . . 55 110 6. Radix-64 Conversions . . . . . . . . . . . . . . . . . . . . 55 111 6.1. An Implementation of the CRC-24 in "C" . . . . . . . . . 56 112 6.2. Forming ASCII Armor . . . . . . . . . . . . . . . . . . . 56 113 6.3. Encoding Binary in Radix-64 . . . . . . . . . . . . . . . 59 114 6.4. Decoding Radix-64 . . . . . . . . . . . . . . . . . . . . 61 115 6.5. Examples of Radix-64 . . . . . . . . . . . . . . . . . . 61 116 6.6. Example of an ASCII Armored Message . . . . . . . . . . . 62 117 7. Cleartext Signature Framework . . . . . . . . . . . . . . . . 62 118 7.1. Dash-Escaped Text . . . . . . . . . . . . . . . . . . . . 63 119 8. Regular Expressions . . . . . . . . . . . . . . . . . . . . . 64 120 9. Constants . . . . . . . . . . . . . . . . . . . . . . . . . . 64 121 9.1. Public-Key Algorithms . . . . . . . . . . . . . . . . . . 65 122 9.2. Symmetric-Key Algorithms . . . . . . . . . . . . . . . . 65 123 9.3. Compression Algorithms . . . . . . . . . . . . . . . . . 66 124 9.4. Hash Algorithms . . . . . . . . . . . . . . . . . . . . . 67 125 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 68 126 10.1. New String-to-Key Specifier Types . . . . . . . . . . . 68 127 10.2. New Packets . . . . . . . . . . . . . . . . . . . . . . 68 128 10.2.1. User Attribute Types . . . . . . . . . . . . . . . . 68 129 10.2.2. New Signature Subpackets . . . . . . . . . . . . . . 69 130 10.2.3. New Packet Versions . . . . . . . . . . . . . . . . 70 131 10.3. New Algorithms . . . . . . . . . . . . . . . . . . . . . 70 132 10.3.1. Public-Key Algorithms . . . . . . . . . . . . . . . 71 133 10.3.2. Symmetric-Key Algorithms . . . . . . . . . . . . . . 71 134 10.3.3. Hash Algorithms . . . . . . . . . . . . . . . . . . 71 135 10.3.4. Compression Algorithms . . . . . . . . . . . . . . . 71 136 11. Packet Composition . . . . . . . . . . . . . . . . . . . . . 71 137 11.1. Transferable Public Keys . . . . . . . . . . . . . . . . 72 138 11.2. Transferable Secret Keys . . . . . . . . . . . . . . . . 73 139 11.3. OpenPGP Messages . . . . . . . . . . . . . . . . . . . . 73 140 11.4. Detached Signatures . . . . . . . . . . . . . . . . . . 74 141 12. Enhanced Key Formats . . . . . . . . . . . . . . . . . . . . 74 142 12.1. Key Structures . . . . . . . . . . . . . . . . . . . . . 74 143 12.2. Key IDs and Fingerprints . . . . . . . . . . . . . . . . 75 144 13. Notes on Algorithms . . . . . . . . . . . . . . . . . . . . . 76 145 13.1. PKCS#1 Encoding in OpenPGP . . . . . . . . . . . . . . . 76 146 13.1.1. EME-PKCS1-v1_5-ENCODE . . . . . . . . . . . . . . . 77 147 13.1.2. EME-PKCS1-v1_5-DECODE . . . . . . . . . . . . . . . 77 148 13.1.3. EMSA-PKCS1-v1_5 . . . . . . . . . . . . . . . . . . 78 149 13.2. Symmetric Algorithm Preferences . . . . . . . . . . . . 79 150 13.3. Other Algorithm Preferences . . . . . . . . . . . . . . 80 151 13.3.1. Compression Preferences . . . . . . . . . . . . . . 80 152 13.3.2. Hash Algorithm Preferences . . . . . . . . . . . . . 80 153 13.4. Plaintext . . . . . . . . . . . . . . . . . . . . . . . 81 154 13.5. RSA . . . . . . . . . . . . . . . . . . . . . . . . . . 81 155 13.6. DSA . . . . . . . . . . . . . . . . . . . . . . . . . . 81 156 13.7. Elgamal . . . . . . . . . . . . . . . . . . . . . . . . 82 157 13.8. Reserved Algorithm Numbers . . . . . . . . . . . . . . . 82 158 13.9. OpenPGP CFB Mode . . . . . . . . . . . . . . . . . . . . 82 159 13.10. Private or Experimental Parameters . . . . . . . . . . . 83 160 13.11. Extension of the MDC System . . . . . . . . . . . . . . 84 161 13.12. Meta-Considerations for Expansion . . . . . . . . . . . 85 162 14. Security Considerations . . . . . . . . . . . . . . . . . . . 85 163 15. Implementation Nits . . . . . . . . . . . . . . . . . . . . . 89 164 16. References . . . . . . . . . . . . . . . . . . . . . . . . . 90 165 16.1. Normative References . . . . . . . . . . . . . . . . . . 90 166 16.2. Informative References . . . . . . . . . . . . . . . . . 93 167 Appendix A. Acknowledgements . . . . . . . . . . . . . . . . . . 93 168 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 93 170 1. Introduction 172 { This is work in progress to update OpenPGP. Editorial notes are 173 enclosed in curly braces. } 175 This document provides information on the message-exchange packet 176 formats used by OpenPGP to provide encryption, decryption, signing, 177 and key management functions. It is a revision of RFC 4880, "OpenPGP 178 Message Format", which is a revision of RFC 2440, which itself 179 replaces RFC 1991, "PGP Message Exchange Formats" [RFC1991] [RFC2440] 180 [RFC4880]. 182 This document obsoletes: RFC 4880 (OpenPGP) and RFC 5581 (Camellia 183 cipher). 185 1.1. Terms 187 * OpenPGP - This is a term for security software that uses PGP 5 as 188 a basis, formalized in this document. 190 * PGP - Pretty Good Privacy. PGP is a family of software systems 191 developed by Philip R. Zimmermann from which OpenPGP is based. 193 * PGP 2 - This version of PGP has many variants; where necessary a 194 more detailed version number is used here. PGP 2 uses only RSA, 195 MD5, and IDEA for its cryptographic transforms. An informational 196 RFC, RFC 1991, was written describing this version of PGP. 198 * PGP 5 - This version of PGP is formerly known as "PGP 3" in the 199 community. It has new formats and corrects a number of problems 200 in the PGP 2 design. It is referred to here as PGP 5 because that 201 software was the first release of the "PGP 3" code base. 203 * GnuPG - GNU Privacy Guard, also called GPG. GnuPG is an OpenPGP 204 implementation that avoids all encumbered algorithms. 205 Consequently, early versions of GnuPG did not include RSA public 206 keys. 208 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of PGP 209 Corporation and are used with permission. The term "OpenPGP" refers 210 to the protocol described in this and related documents. 212 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 213 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 214 document are to be interpreted as described in [RFC2119]. 216 The key words "PRIVATE USE", "HIERARCHICAL ALLOCATION", "FIRST COME 217 FIRST SERVED", "EXPERT REVIEW", "SPECIFICATION REQUIRED", "IESG 218 APPROVAL", "IETF CONSENSUS", and "STANDARDS ACTION" that appear in 219 this document when used to describe namespace allocation are to be 220 interpreted as described in [RFC2434]. 222 2. General functions 224 OpenPGP provides data integrity services for messages and data files 225 by using these core technologies: 227 * digital signatures 229 * encryption 231 * compression 233 * Radix-64 conversion 235 In addition, OpenPGP provides key management and certificate 236 services, but many of these are beyond the scope of this document. 238 2.1. Confidentiality via Encryption 240 OpenPGP combines symmetric-key encryption and public-key encryption 241 to provide confidentiality. When made confidential, first the object 242 is encrypted using a symmetric encryption algorithm. Each symmetric 243 key is used only once, for a single object. A new "session key" is 244 generated as a random number for each object (sometimes referred to 245 as a session). Since it is used only once, the session key is bound 246 to the message and transmitted with it. To protect the key, it is 247 encrypted with the receiver's public key. The sequence is as 248 follows: 250 1. The sender creates a message. 252 2. The sending OpenPGP generates a random number to be used as a 253 session key for this message only. 255 3. The session key is encrypted using each recipient's public key. 256 These "encrypted session keys" start the message. 258 4. The sending OpenPGP encrypts the message using the session key, 259 which forms the remainder of the message. Note that the message 260 is also usually compressed. 262 5. The receiving OpenPGP decrypts the session key using the 263 recipient's private key. 265 6. The receiving OpenPGP decrypts the message using the session key. 266 If the message was compressed, it will be decompressed. 268 With symmetric-key encryption, an object may be encrypted with a 269 symmetric key derived from a passphrase (or other shared secret), or 270 a two-stage mechanism similar to the public-key method described 271 above in which a session key is itself encrypted with a symmetric 272 algorithm keyed from a shared secret. 274 Both digital signature and confidentiality services may be applied to 275 the same message. First, a signature is generated for the message 276 and attached to the message. Then the message plus signature is 277 encrypted using a symmetric session key. Finally, the session key is 278 encrypted using public-key encryption and prefixed to the encrypted 279 block. 281 2.2. Authentication via Digital Signature 283 The digital signature uses a hash code or message digest algorithm, 284 and a public-key signature algorithm. The sequence is as follows: 286 1. The sender creates a message. 288 2. The sending software generates a hash code of the message. 290 3. The sending software generates a signature from the hash code 291 using the sender's private key. 293 4. The binary signature is attached to the message. 295 5. The receiving software keeps a copy of the message signature. 297 6. The receiving software generates a new hash code for the received 298 message and verifies it using the message's signature. If the 299 verification is successful, the message is accepted as authentic. 301 2.3. Compression 303 OpenPGP implementations SHOULD compress the message after applying 304 the signature but before encryption. 306 If an implementation does not implement compression, its authors 307 should be aware that most OpenPGP messages in the world are 308 compressed. Thus, it may even be wise for a space-constrained 309 implementation to implement decompression, but not compression. 311 Furthermore, compression has the added side effect that some types of 312 attacks can be thwarted by the fact that slightly altered, compressed 313 data rarely uncompresses without severe errors. This is hardly 314 rigorous, but it is operationally useful. These attacks can be 315 rigorously prevented by implementing and using Modification Detection 316 Codes as described in sections following. 318 2.4. Conversion to Radix-64 320 OpenPGP's underlying native representation for encrypted messages, 321 signature certificates, and keys is a stream of arbitrary octets. 322 Some systems only permit the use of blocks consisting of seven-bit, 323 printable text. For transporting OpenPGP's native raw binary octets 324 through channels that are not safe to raw binary data, a printable 325 encoding of these binary octets is needed. OpenPGP provides the 326 service of converting the raw 8-bit binary octet stream to a stream 327 of printable ASCII characters, called Radix-64 encoding or ASCII 328 Armor. 330 Implementations SHOULD provide Radix-64 conversions. 332 2.5. Signature-Only Applications 334 OpenPGP is designed for applications that use both encryption and 335 signatures, but there are a number of problems that are solved by a 336 signature-only implementation. Although this specification requires 337 both encryption and signatures, it is reasonable for there to be 338 subset implementations that are non-conformant only in that they omit 339 encryption. 341 3. Data Element Formats 343 This section describes the data elements used by OpenPGP. 345 3.1. Scalar Numbers 347 Scalar numbers are unsigned and are always stored in big-endian 348 format. Using n[k] to refer to the kth octet being interpreted, the 349 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 350 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 351 n[3]). 353 3.2. Multiprecision Integers 355 Multiprecision integers (also called MPIs) are unsigned integers used 356 to hold large integers such as the ones used in cryptographic 357 calculations. 359 An MPI consists of two pieces: a two-octet scalar that is the length 360 of the MPI in bits followed by a string of octets that contain the 361 actual integer. 363 These octets form a big-endian number; a big-endian number can be 364 made into an MPI by prefixing it with the appropriate length. 366 Examples: 368 (all numbers are in hexadecimal) 370 The string of octets [00 01 01] forms an MPI with the value 1. The 371 string [00 09 01 FF] forms an MPI with the value of 511. 373 Additional rules: 375 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 377 The length field of an MPI describes the length starting from its 378 most significant non-zero bit. Thus, the MPI [00 02 01] is not 379 formed correctly. It should be [00 01 01]. 381 Unused bits of an MPI MUST be zero. 383 Also note that when an MPI is encrypted, the length refers to the 384 plaintext MPI. It may be ill-formed in its ciphertext. 386 3.3. Key IDs 388 A Key ID is an eight-octet scalar that identifies a key. 389 Implementations SHOULD NOT assume that Key IDs are unique. 390 Section 12 describes how Key IDs are formed. 392 3.4. Text 394 Unless otherwise specified, the character set for text is the UTF-8 395 [RFC3629] encoding of Unicode [ISO10646]. 397 3.5. Time Fields 399 A time field is an unsigned four-octet number containing the number 400 of seconds elapsed since midnight, 1 January 1970 UTC. 402 3.6. Keyrings 404 A keyring is a collection of one or more keys in a file or database. 405 Traditionally, a keyring is simply a sequential list of keys, but may 406 be any suitable database. It is beyond the scope of this standard to 407 discuss the details of keyrings or other databases. 409 3.7. String-to-Key (S2K) Specifiers 411 String-to-key (S2K) specifiers are used to convert passphrase strings 412 into symmetric-key encryption/decryption keys. They are used in two 413 places, currently: to encrypt the secret part of private keys in the 414 private keyring, and to convert passphrases to encryption keys for 415 symmetrically encrypted messages. 417 3.7.1. String-to-Key (S2K) Specifier Types 419 There are three types of S2K specifiers currently supported, and some 420 reserved values: 422 +============+==========================+ 423 | ID | S2K Type | 424 +============+==========================+ 425 | 0 | Simple S2K | 426 +------------+--------------------------+ 427 | 1 | Salted S2K | 428 +------------+--------------------------+ 429 | 2 | Reserved value | 430 +------------+--------------------------+ 431 | 3 | Iterated and Salted S2K | 432 +------------+--------------------------+ 433 | 100 to 110 | Private/Experimental S2K | 434 +------------+--------------------------+ 436 Table 1: S2K type registry 438 These are described in the subsections below. 440 3.7.1.1. Simple S2K 442 This directly hashes the string to produce the key data. See below 443 for how this hashing is done. 445 Octet 0: 0x00 446 Octet 1: hash algorithm 448 Simple S2K hashes the passphrase to produce the session key. The 449 manner in which this is done depends on the size of the session key 450 (which will depend on the cipher used) and the size of the hash 451 algorithm's output. If the hash size is greater than the session key 452 size, the high-order (leftmost) octets of the hash are used as the 453 key. 455 If the hash size is less than the key size, multiple instances of the 456 hash context are created -- enough to produce the required key data. 457 These instances are preloaded with 0, 1, 2, ... octets of zeros (that 458 is to say, the first instance has no preloading, the second gets 459 preloaded with 1 octet of zero, the third is preloaded with two 460 octets of zeros, and so forth). 462 As the data is hashed, it is given independently to each hash 463 context. Since the contexts have been initialized differently, they 464 will each produce different hash output. Once the passphrase is 465 hashed, the output data from the multiple hashes is concatenated, 466 first hash leftmost, to produce the key data, with any excess octets 467 on the right discarded. 469 3.7.1.2. Salted S2K 471 This includes a "salt" value in the S2K specifier -- some arbitrary 472 data -- that gets hashed along with the passphrase string, to help 473 prevent dictionary attacks. 475 Octet 0: 0x01 476 Octet 1: hash algorithm 477 Octets 2-9: 8-octet salt value 479 Salted S2K is exactly like Simple S2K, except that the input to the 480 hash function(s) consists of the 8 octets of salt from the S2K 481 specifier, followed by the passphrase. 483 3.7.1.3. Iterated and Salted S2K 485 This includes both a salt and an octet count. The salt is combined 486 with the passphrase and the resulting value is hashed repeatedly. 487 This further increases the amount of work an attacker must do to try 488 dictionary attacks. 490 Octet 0: 0x03 491 Octet 1: hash algorithm 492 Octets 2-9: 8-octet salt value 493 Octet 10: count, a one-octet, coded value 495 The count is coded into a one-octet number using the following 496 formula: 498 #define EXPBIAS 6 499 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 501 The above formula is in C, where "Int32" is a type for a 32-bit 502 integer, and the variable "c" is the coded count, Octet 10. 504 Iterated-Salted S2K hashes the passphrase and salt data multiple 505 times. The total number of octets to be hashed is specified in the 506 encoded count in the S2K specifier. Note that the resulting count 507 value is an octet count of how many octets will be hashed, not an 508 iteration count. 510 Initially, one or more hash contexts are set up as with the other S2K 511 algorithms, depending on how many octets of key data are needed. 512 Then the salt, followed by the passphrase data, is repeatedly hashed 513 until the number of octets specified by the octet count has been 514 hashed. The one exception is that if the octet count is less than 515 the size of the salt plus passphrase, the full salt plus passphrase 516 will be hashed even though that is greater than the octet count. 517 After the hashing is done, the data is unloaded from the hash 518 context(s) as with the other S2K algorithms. 520 3.7.2. String-to-Key Usage 522 Implementations SHOULD use salted or iterated-and-salted S2K 523 specifiers, as simple S2K specifiers are more vulnerable to 524 dictionary attacks. 526 3.7.2.1. Secret-Key Encryption 528 An S2K specifier can be stored in the secret keyring to specify how 529 to convert the passphrase to a key that unlocks the secret data. 530 Older versions of PGP just stored a cipher algorithm octet preceding 531 the secret data or a zero to indicate that the secret data was 532 unencrypted. The MD5 hash function was always used to convert the 533 passphrase to a key for the specified cipher algorithm. 535 For compatibility, when an S2K specifier is used, the special value 536 254 or 255 is stored in the position where the hash algorithm octet 537 would have been in the old data structure. This is then followed 538 immediately by a one-octet algorithm identifier, and then by the S2K 539 specifier as encoded above. 541 Therefore, preceding the secret data there will be one of these 542 possibilities: 544 0: secret data is unencrypted (no passphrase) 545 255 or 254: followed by algorithm octet and S2K specifier 546 Cipher alg: use Simple S2K algorithm using MD5 hash 548 This last possibility, the cipher algorithm number with an implicit 549 use of MD5 and IDEA, is provided for backward compatibility; it MAY 550 be understood, but SHOULD NOT be generated, and is deprecated. 552 These are followed by an Initial Vector of the same length as the 553 block size of the cipher for the decryption of the secret values, if 554 they are encrypted, and then the secret-key values themselves. 556 3.7.2.2. Symmetric-Key Message Encryption 558 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) packet 559 at the front of a message. This is used to allow S2K specifiers to 560 be used for the passphrase conversion or to create messages with a 561 mix of symmetric-key ESKs and public-key ESKs. This allows a message 562 to be decrypted either with a passphrase or a public-key pair. 564 PGP 2 always used IDEA with Simple string-to-key conversion when 565 encrypting a message with a symmetric algorithm. This is deprecated, 566 but MAY be used for backward-compatibility. 568 4. Packet Syntax 570 This section describes the packets used by OpenPGP. 572 4.1. Overview 574 An OpenPGP message is constructed from a number of records that are 575 traditionally called packets. A packet is a chunk of data that has a 576 tag specifying its meaning. An OpenPGP message, keyring, 577 certificate, and so forth consists of a number of packets. Some of 578 those packets may contain other OpenPGP packets (for example, a 579 compressed data packet, when uncompressed, contains OpenPGP packets). 581 Each packet consists of a packet header, followed by the packet body. 582 The packet header is of variable length. 584 4.2. Packet Headers 586 The first octet of the packet header is called the "Packet Tag". It 587 determines the format of the header and denotes the packet contents. 588 The remainder of the packet header is the length of the packet. 590 Note that the most significant bit is the leftmost bit, called bit 7. 591 A mask for this bit is 0x80 in hexadecimal. 593 ┌───────────────┐ 594 PTag │7 6 5 4 3 2 1 0│ 595 └───────────────┘ 596 Bit 7 -- Always one 597 Bit 6 -- New packet format if set 599 PGP 2.6.x only uses old format packets. Thus, software that 600 interoperates with those versions of PGP must only use old format 601 packets. If interoperability is not an issue, the new packet format 602 is RECOMMENDED. Note that old format packets have four bits of 603 packet tags, and new format packets have six; some features cannot be 604 used and still be backward-compatible. 606 Also note that packets with a tag greater than or equal to 16 MUST 607 use new format packets. The old format packets can only express tags 608 less than or equal to 15. 610 Old format packets contain: 612 Bits 5-2 -- packet tag 613 Bits 1-0 -- length-type 615 New format packets contain: 617 Bits 5-0 -- packet tag 619 4.2.1. Old Format Packet Lengths 621 The meaning of the length-type in old format packets is: 623 0 The packet has a one-octet length. The header is 2 octets long. 625 1 The packet has a two-octet length. The header is 3 octets long. 627 2 The packet has a four-octet length. The header is 5 octets long. 629 3 The packet is of indeterminate length. The header is 1 octet 630 long, and the implementation must determine how long the packet 631 is. If the packet is in a file, this means that the packet 632 extends until the end of the file. In general, an implementation 633 SHOULD NOT use indeterminate-length packets except where the end 634 of the data will be clear from the context, and even then it is 635 better to use a definite length, or a new format header. The new 636 format headers described below have a mechanism for precisely 637 encoding data of indeterminate length. 639 4.2.2. New Format Packet Lengths 641 New format packets have four possible ways of encoding length: 643 1. A one-octet Body Length header encodes packet lengths of up to 644 191 octets. 646 2. A two-octet Body Length header encodes packet lengths of 192 to 647 8383 octets. 649 3. A five-octet Body Length header encodes packet lengths of up to 650 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 651 encodes a four-octet scalar number.) 653 4. When the length of the packet body is not known in advance by the 654 issuer, Partial Body Length headers encode a packet of 655 indeterminate length, effectively making it a stream. 657 4.2.2.1. One-Octet Lengths 659 A one-octet Body Length header encodes a length of 0 to 191 octets. 660 This type of length header is recognized because the one octet value 661 is less than 192. The body length is equal to: 663 bodyLen = 1st_octet; 665 4.2.2.2. Two-Octet Lengths 667 A two-octet Body Length header encodes a length of 192 to 8383 668 octets. It is recognized because its first octet is in the range 192 669 to 223. The body length is equal to: 671 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 673 4.2.2.3. Five-Octet Lengths 675 A five-octet Body Length header consists of a single octet holding 676 the value 255, followed by a four-octet scalar. The body length is 677 equal to: 679 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 680 (4th_octet << 8) | 5th_octet 682 This basic set of one, two, and five-octet lengths is also used 683 internally to some packets. 685 4.2.2.4. Partial Body Lengths 687 A Partial Body Length header is one octet long and encodes the length 688 of only part of the data packet. This length is a power of 2, from 1 689 to 1,073,741,824 (2 to the 30th power). It is recognized by its one 690 octet value that is greater than or equal to 224, and less than 255. 691 The Partial Body Length is equal to: 693 partialBodyLen = 1 << (1st_octet & 0x1F); 695 Each Partial Body Length header is followed by a portion of the 696 packet body data. The Partial Body Length header specifies this 697 portion's length. Another length header (one octet, two-octet, five- 698 octet, or partial) follows that portion. The last length header in 699 the packet MUST NOT be a Partial Body Length header. Partial Body 700 Length headers may only be used for the non-final parts of the 701 packet. 703 Note also that the last Body Length header can be a zero-length 704 header. 706 An implementation MAY use Partial Body Lengths for data packets, be 707 they literal, compressed, or encrypted. The first partial length 708 MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 709 used for any other packet types. 711 4.2.3. Packet Length Examples 713 These examples show ways that new format packets might encode the 714 packet lengths. 716 A packet with length 100 may have its length encoded in one octet: 717 0x64. This is followed by 100 octets of data. 719 A packet with length 1723 may have its length encoded in two octets: 720 0xC5, 0xFB. This header is followed by the 1723 octets of data. 722 A packet with length 100000 may have its length encoded in five 723 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 725 It might also be encoded in the following octet stream: 0xEF, first 726 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 727 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 1693 728 octets of data. This is just one possible encoding, and many 729 variations are possible on the size of the Partial Body Length 730 headers, as long as a regular Body Length header encodes the last 731 portion of the data. 733 Please note that in all of these explanations, the total length of 734 the packet is the length of the header(s) plus the length of the 735 body. 737 4.3. Packet Tags 739 The packet tag denotes what type of packet the body holds. Note that 740 old format headers can only have tags less than 16, whereas new 741 format headers can have tags as great as 63. The defined tags (in 742 decimal) are as follows: 744 +==========+====================================================+ 745 | Tag | Packet Type | 746 +==========+====================================================+ 747 | 0 | Reserved - a packet tag MUST NOT have this value | 748 +----------+----------------------------------------------------+ 749 | 1 | Public-Key Encrypted Session Key Packet | 750 +----------+----------------------------------------------------+ 751 | 2 | Signature Packet | 752 +----------+----------------------------------------------------+ 753 | 3 | Symmetric-Key Encrypted Session Key Packet | 754 +----------+----------------------------------------------------+ 755 | 4 | One-Pass Signature Packet | 756 +----------+----------------------------------------------------+ 757 | 5 | Secret-Key Packet | 758 +----------+----------------------------------------------------+ 759 | 6 | Public-Key Packet | 760 +----------+----------------------------------------------------+ 761 | 7 | Secret-Subkey Packet | 762 +----------+----------------------------------------------------+ 763 | 8 | Compressed Data Packet | 764 +----------+----------------------------------------------------+ 765 | 9 | Symmetrically Encrypted Data Packet | 766 +----------+----------------------------------------------------+ 767 | 10 | Marker Packet | 768 +----------+----------------------------------------------------+ 769 | 11 | Literal Data Packet | 770 +----------+----------------------------------------------------+ 771 | 12 | Trust Packet | 772 +----------+----------------------------------------------------+ 773 | 13 | User ID Packet | 774 +----------+----------------------------------------------------+ 775 | 14 | Public-Subkey Packet | 776 +----------+----------------------------------------------------+ 777 | 17 | User Attribute Packet | 778 +----------+----------------------------------------------------+ 779 | 18 | Sym. Encrypted and Integrity Protected Data Packet | 780 +----------+----------------------------------------------------+ 781 | 19 | Modification Detection Code Packet | 782 +----------+----------------------------------------------------+ 783 | 60 to 63 | Private or Experimental Values | 784 +----------+----------------------------------------------------+ 786 Table 2: Packet type registry 788 5. Packet Types 789 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 791 A Public-Key Encrypted Session Key packet holds the session key used 792 to encrypt a message. Zero or more Public-Key Encrypted Session Key 793 packets and/or Symmetric-Key Encrypted Session Key packets may 794 precede a Symmetrically Encrypted Data Packet, which holds an 795 encrypted message. The message is encrypted with the session key, 796 and the session key is itself encrypted and stored in the Encrypted 797 Session Key packet(s). The Symmetrically Encrypted Data Packet is 798 preceded by one Public-Key Encrypted Session Key packet for each 799 OpenPGP key to which the message is encrypted. The recipient of the 800 message finds a session key that is encrypted to their public key, 801 decrypts the session key, and then uses the session key to decrypt 802 the message. 804 The body of this packet consists of: 806 * A one-octet number giving the version number of the packet type. 807 The currently defined value for packet version is 3. 809 * An eight-octet number that gives the Key ID of the public key to 810 which the session key is encrypted. If the session key is 811 encrypted to a subkey, then the Key ID of this subkey is used here 812 instead of the Key ID of the primary key. 814 * A one-octet number giving the public-key algorithm used. 816 * A string of octets that is the encrypted session key. This string 817 takes up the remainder of the packet, and its contents are 818 dependent on the public-key algorithm used. 820 Algorithm Specific Fields for RSA encryption: 822 - Multiprecision integer (MPI) of RSA encrypted value m**e mod n. 824 Algorithm Specific Fields for Elgamal encryption: 826 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 828 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 830 The value "m" in the above formulas is derived from the session key 831 as follows. First, the session key is prefixed with a one-octet 832 algorithm identifier that specifies the symmetric encryption 833 algorithm used to encrypt the following Symmetrically Encrypted Data 834 Packet. Then a two-octet checksum is appended, which is equal to the 835 sum of the preceding session key octets, not including the algorithm 836 identifier, modulo 65536. This value is then encoded as described in 837 PKCS#1 block encoding EME-PKCS1-v1_5 in Section 7.2.1 of [RFC3447] to 838 form the "m" value used in the formulas above. See Section 13.1 in 839 this document for notes on OpenPGP's use of PKCS#1. 841 Note that when an implementation forms several PKESKs with one 842 session key, forming a message that can be decrypted by several keys, 843 the implementation MUST make a new PKCS#1 encoding for each key. 845 An implementation MAY accept or use a Key ID of zero as a "wild card" 846 or "speculative" Key ID. In this case, the receiving implementation 847 would try all available private keys, checking for a valid decrypted 848 session key. This format helps reduce traffic analysis of messages. 850 5.2. Signature Packet (Tag 2) 852 A Signature packet describes a binding between some public key and 853 some data. The most common signatures are a signature of a file or a 854 block of text, and a signature that is a certification of a User ID. 856 Two versions of Signature packets are defined. Version 3 provides 857 basic signature information, while version 4 provides an expandable 858 format with subpackets that can specify more information about the 859 signature. PGP 2.6.x only accepts version 3 signatures. 861 Implementations SHOULD accept V3 signatures. Implementations SHOULD 862 generate V4 signatures. 864 Note that if an implementation is creating an encrypted and signed 865 message that is encrypted to a V3 key, it is reasonable to create a 866 V3 signature. 868 5.2.1. Signature Types 870 There are a number of possible meanings for a signature, which are 871 indicated in a signature type octet in any given signature. Please 872 note that the vagueness of these meanings is not a flaw, but a 873 feature of the system. Because OpenPGP places final authority for 874 validity upon the receiver of a signature, it may be that one 875 signer's casual act might be more rigorous than some other 876 authority's positive act. See Section 5.2.4 for detailed information 877 on how to compute and verify signatures of each type. 879 These meanings are as follows: 881 0x00: Signature of a binary document. 882 This means the signer owns it, created it, or certifies that it 883 has not been modified. 885 0x01: Signature of a canonical text document. 886 This means the signer owns it, created it, or certifies that it 887 has not been modified. The signature is calculated over the text 888 data with its line endings converted to . 890 0x02: Standalone signature. 891 This signature is a signature of only its own subpacket contents. 892 It is calculated identically to a signature over a zero-length 893 binary document. Note that it doesn't make sense to have a V3 894 standalone signature. 896 0x10: Generic certification of a User ID and Public-Key packet. 897 The issuer of this certification does not make any particular 898 assertion as to how well the certifier has checked that the owner 899 of the key is in fact the person described by the User ID. 901 0x11: Persona certification of a User ID and Public-Key packet. 902 The issuer of this certification has not done any verification of 903 the claim that the owner of this key is the User ID specified. 905 0x12: Casual certification of a User ID and Public-Key packet. 906 The issuer of this certification has done some casual verification 907 of the claim of identity. 909 0x13: Positive certification of a User ID and Public-Key packet. 910 The issuer of this certification has done substantial verification 911 of the claim of identity. Most OpenPGP implementations make their 912 "key signatures" as 0x10 certifications. Some implementations can 913 issue 0x11-0x13 certifications, but few differentiate between the 914 types. 916 0x18: Subkey Binding Signature. 917 This signature is a statement by the top-level signing key that 918 indicates that it owns the subkey. This signature is calculated 919 directly on the primary key and subkey, and not on any User ID or 920 other packets. A signature that binds a signing subkey MUST have 921 an Embedded Signature subpacket in this binding signature that 922 contains a 0x19 signature made by the signing subkey on the 923 primary key and subkey. 925 0x19: Primary Key Binding Signature. 926 This signature is a statement by a signing subkey, indicating that 927 it is owned by the primary key and subkey. This signature is 928 calculated the same way as a 0x18 signature: directly on the 929 primary key and subkey, and not on any User ID or other packets. 931 0x1F: Signature directly on a key. 932 This signature is calculated directly on a key. It binds the 933 information in the Signature subpackets to the key, and is 934 appropriate to be used for subpackets that provide information 935 about the key, such as the Revocation Key subpacket. It is also 936 appropriate for statements that non-self certifiers want to make 937 about the key itself, rather than the binding between a key and a 938 name. 940 0x20: Key revocation signature. 941 The signature is calculated directly on the key being revoked. A 942 revoked key is not to be used. Only revocation signatures by the 943 key being revoked, or by an authorized revocation key, should be 944 considered valid revocation signatures. 946 0x28: Subkey revocation signature. 947 The signature is calculated directly on the subkey being revoked. 948 A revoked subkey is not to be used. Only revocation signatures by 949 the top-level signature key that is bound to this subkey, or by an 950 authorized revocation key, should be considered valid revocation 951 signatures. 953 0x30: Certification revocation signature. 954 This signature revokes an earlier User ID certification signature 955 (signature class 0x10 through 0x13) or direct-key signature 956 (0x1F). It should be issued by the same key that issued the 957 revoked signature or an authorized revocation key. The signature 958 is computed over the same data as the certificate that it revokes, 959 and should have a later creation date than that certificate. 961 0x40: Timestamp signature. 962 This signature is only meaningful for the timestamp contained in 963 it. 965 0x50: Third-Party Confirmation signature. 966 This signature is a signature over some other OpenPGP Signature 967 packet(s). It is analogous to a notary seal on the signed data. 968 A third-party signature SHOULD include Signature Target 969 subpacket(s) to give easy identification. Note that we really do 970 mean SHOULD. There are plausible uses for this (such as a blind 971 party that only sees the signature, not the key or source 972 document) that cannot include a target subpacket. 974 5.2.2. Version 3 Signature Packet Format 976 The body of a version 3 Signature Packet contains: 978 * One-octet version number (3). 980 * One-octet length of following hashed material. MUST be 5. 982 - One-octet signature type. 984 - Four-octet creation time. 986 * Eight-octet Key ID of signer. 988 * One-octet public-key algorithm. 990 * One-octet hash algorithm. 992 * Two-octet field holding left 16 bits of signed hash value. 994 * One or more multiprecision integers comprising the signature. 995 This portion is algorithm specific, as described below. 997 The concatenation of the data to be signed, the signature type, and 998 creation time from the Signature packet (5 additional octets) is 999 hashed. The resulting hash value is used in the signature algorithm. 1000 The high 16 bits (first two octets) of the hash are included in the 1001 Signature packet to provide a quick test to reject some invalid 1002 signatures. 1004 Algorithm-Specific Fields for RSA signatures: 1006 * Multiprecision integer (MPI) of RSA signature value m**d mod n. 1008 Algorithm-Specific Fields for DSA signatures: 1010 * MPI of DSA value r. 1012 * MPI of DSA value s. 1014 The signature calculation is based on a hash of the signed data, as 1015 described above. The details of the calculation are different for 1016 DSA signatures than for RSA signatures. 1018 With RSA signatures, the hash value is encoded using PKCS#1 encoding 1019 type EMSA-PKCS1-v1_5 as described in Section 9.2 of [RFC3447]. This 1020 requires inserting the hash value as an octet string into an ASN.1 1021 structure. The object identifier for the type of hash being used is 1022 included in the structure. The hexadecimal representations for the 1023 currently defined hash algorithms are as follows: 1025 +============+======================================================+ 1026 | algorithm | hexadecimal represenatation | 1027 +============+======================================================+ 1028 | MD5 | 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 | 1029 +------------+------------------------------------------------------+ 1030 | RIPEMD-160 | 0x2B, 0x24, 0x03, 0x02, 0x01 | 1031 +------------+------------------------------------------------------+ 1032 | SHA-1 | 0x2B, 0x0E, 0x03, 0x02, 0x1A | 1033 +------------+------------------------------------------------------+ 1034 | SHA224 | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, | 1035 | | 0x02, 0x04 | 1036 +------------+------------------------------------------------------+ 1037 | SHA256 | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, | 1038 | | 0x02, 0x01 | 1039 +------------+------------------------------------------------------+ 1040 | SHA384 | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, | 1041 | | 0x02, 0x02 | 1042 +------------+------------------------------------------------------+ 1043 | SHA512 | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, | 1044 | | 0x02, 0x03 | 1045 +------------+------------------------------------------------------+ 1047 Table 3: Hash hexadecimal representations 1049 The ASN.1 Object Identifiers (OIDs) are as follows: 1051 +============+========================+ 1052 | algorithm | OID | 1053 +============+========================+ 1054 | MD5 | 1.2.840.113549.2.5 | 1055 +------------+------------------------+ 1056 | RIPEMD-160 | 1.3.36.3.2.1 | 1057 +------------+------------------------+ 1058 | SHA-1 | 1.3.14.3.2.26 | 1059 +------------+------------------------+ 1060 | SHA224 | 2.16.840.1.101.3.4.2.4 | 1061 +------------+------------------------+ 1062 | SHA256 | 2.16.840.1.101.3.4.2.1 | 1063 +------------+------------------------+ 1064 | SHA384 | 2.16.840.1.101.3.4.2.2 | 1065 +------------+------------------------+ 1066 | SHA512 | 2.16.840.1.101.3.4.2.3 | 1067 +------------+------------------------+ 1069 Table 4: Hash OIDs 1071 The full hash prefixes for these are as follows: 1073 +============+==========================================+ 1074 | algorithm | full hash prefix | 1075 +============+==========================================+ 1076 | MD5 | 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, | 1077 | | 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, | 1078 | | 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 | 1079 +------------+------------------------------------------+ 1080 | RIPEMD-160 | 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, | 1081 | | 0x2B, 0x24, 0x03, 0x02, 0x01, 0x05, | 1082 | | 0x00, 0x04, 0x14 | 1083 +------------+------------------------------------------+ 1084 | SHA-1 | 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, | 1085 | | 0x2B, 0x0E, 0x03, 0x02, 0x1A, 0x05, | 1086 | | 0x00, 0x04, 0x14 | 1087 +------------+------------------------------------------+ 1088 | SHA224 | 0x30, 0x2D, 0x30, 0x0D, 0x06, 0x09, | 1089 | | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, | 1090 | | 0x04, 0x02, 0x04, 0x05, 0x00, 0x04, 0x1C | 1091 +------------+------------------------------------------+ 1092 | SHA256 | 0x30, 0x31, 0x30, 0x0D, 0x06, 0x09, | 1093 | | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, | 1094 | | 0x04, 0x02, 0x01, 0x05, 0x00, 0x04, 0x20 | 1095 +------------+------------------------------------------+ 1096 | SHA384 | 0x30, 0x41, 0x30, 0x0D, 0x06, 0x09, | 1097 | | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, | 1098 | | 0x04, 0x02, 0x02, 0x05, 0x00, 0x04, 0x30 | 1099 +------------+------------------------------------------+ 1100 | SHA512 | 0x30, 0x51, 0x30, 0x0D, 0x06, 0x09, | 1101 | | 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, | 1102 | | 0x04, 0x02, 0x03, 0x05, 0x00, 0x04, 0x40 | 1103 +------------+------------------------------------------+ 1105 Table 5: Hash hexadecimal prefixes 1107 DSA signatures MUST use hashes that are equal in size to the number 1108 of bits of q, the group generated by the DSA key's generator value. 1110 If the output size of the chosen hash is larger than the number of 1111 bits of q, the hash result is truncated to fit by taking the number 1112 of leftmost bits equal to the number of bits of q. This (possibly 1113 truncated) hash function result is treated as a number and used 1114 directly in the DSA signature algorithm. 1116 5.2.3. Version 4 Signature Packet Format 1118 The body of a version 4 Signature packet contains: 1120 * One-octet version number (4). 1122 * One-octet signature type. 1124 * One-octet public-key algorithm. 1126 * One-octet hash algorithm. 1128 * Two-octet scalar octet count for following hashed subpacket data. 1129 Note that this is the length in octets of all of the hashed 1130 subpackets; a pointer incremented by this number will skip over 1131 the hashed subpackets. 1133 * Hashed subpacket data set (zero or more subpackets). 1135 * Two-octet scalar octet count for the following unhashed subpacket 1136 data. Note that this is the length in octets of all of the 1137 unhashed subpackets; a pointer incremented by this number will 1138 skip over the unhashed subpackets. 1140 * Unhashed subpacket data set (zero or more subpackets). 1142 * Two-octet field holding the left 16 bits of the signed hash value. 1144 * One or more multiprecision integers comprising the signature. 1145 This portion is algorithm specific, as described above. 1147 The concatenation of the data being signed and the signature data 1148 from the version number through the hashed subpacket data (inclusive) 1149 is hashed. The resulting hash value is what is signed. The left 16 1150 bits of the hash are included in the Signature packet to provide a 1151 quick test to reject some invalid signatures. 1153 There are two fields consisting of Signature subpackets. The first 1154 field is hashed with the rest of the signature data, while the second 1155 is unhashed. The second set of subpackets is not cryptographically 1156 protected by the signature and should include only advisory 1157 information. 1159 The algorithms for converting the hash function result to a signature 1160 are described in a section below. 1162 5.2.3.1. Signature Subpacket Specification 1164 A subpacket data set consists of zero or more Signature subpackets. 1165 In Signature packets, the subpacket data set is preceded by a two- 1166 octet scalar count of the length in octets of all the subpackets. A 1167 pointer incremented by this number will skip over the subpacket data 1168 set. 1170 Each subpacket consists of a subpacket header and a body. The header 1171 consists of: 1173 * the subpacket length (1, 2, or 5 octets), 1175 * the subpacket type (1 octet), 1177 and is followed by the subpacket-specific data. 1179 The length includes the type octet but not this length. Its format 1180 is similar to the "new" format packet header lengths, but cannot have 1181 Partial Body Lengths. That is: 1183 if the 1st octet < 192, then 1184 lengthOfLength = 1 1185 subpacketLen = 1st_octet 1187 if the 1st octet >= 192 and < 255, then 1188 lengthOfLength = 2 1189 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1191 if the 1st octet = 255, then 1192 lengthOfLength = 5 1193 subpacket length = [four-octet scalar starting at 2nd_octet] 1195 The value of the subpacket type octet may be: 1197 +============+========================================+ 1198 | Type | Description | 1199 +============+========================================+ 1200 | 0 | Reserved | 1201 +------------+----------------------------------------+ 1202 | 1 | Reserved | 1203 +------------+----------------------------------------+ 1204 | 2 | Signature Creation Time | 1205 +------------+----------------------------------------+ 1206 | 3 | Signature Expiration Time | 1207 +------------+----------------------------------------+ 1208 | 4 | Exportable Certification | 1209 +------------+----------------------------------------+ 1210 | 5 | Trust Signature | 1211 +------------+----------------------------------------+ 1212 | 6 | Regular Expression | 1213 +------------+----------------------------------------+ 1214 | 7 | Revocable | 1215 +------------+----------------------------------------+ 1216 | 8 | Reserved | 1217 +------------+----------------------------------------+ 1218 | 9 | Key Expiration Time | 1219 +------------+----------------------------------------+ 1220 | 10 | Placeholder for backward compatibility | 1221 +------------+----------------------------------------+ 1222 | 11 | Preferred Symmetric Algorithms | 1223 +------------+----------------------------------------+ 1224 | 12 | Revocation Key | 1225 +------------+----------------------------------------+ 1226 | 13 | Reserved | 1227 +------------+----------------------------------------+ 1228 | 14 | Reserved | 1229 +------------+----------------------------------------+ 1230 | 15 | Reserved | 1231 +------------+----------------------------------------+ 1232 | 16 | Issuer | 1233 +------------+----------------------------------------+ 1234 | 17 | Reserved | 1235 +------------+----------------------------------------+ 1236 | 18 | Reserved | 1237 +------------+----------------------------------------+ 1238 | 19 | Reserved | 1239 +------------+----------------------------------------+ 1240 | 20 | Notation Data | 1241 +------------+----------------------------------------+ 1242 | 21 | Preferred Hash Algorithms | 1243 +------------+----------------------------------------+ 1244 | 22 | Preferred Compression Algorithms | 1245 +------------+----------------------------------------+ 1246 | 23 | Key Server Preferences | 1247 +------------+----------------------------------------+ 1248 | 24 | Preferred Key Server | 1249 +------------+----------------------------------------+ 1250 | 25 | Primary User ID | 1251 +------------+----------------------------------------+ 1252 | 26 | Policy URI | 1253 +------------+----------------------------------------+ 1254 | 27 | Key Flags | 1255 +------------+----------------------------------------+ 1256 | 28 | Signer's User ID | 1257 +------------+----------------------------------------+ 1258 | 29 | Reason for Revocation | 1259 +------------+----------------------------------------+ 1260 | 30 | Features | 1261 +------------+----------------------------------------+ 1262 | 31 | Signature Target | 1263 +------------+----------------------------------------+ 1264 | 32 | Embedded Signature | 1265 +------------+----------------------------------------+ 1266 | 100 to 110 | Private or experimental | 1267 +------------+----------------------------------------+ 1269 Table 6: Subpacket type registry 1271 An implementation SHOULD ignore any subpacket of a type that it does 1272 not recognize. 1274 Bit 7 of the subpacket type is the "critical" bit. If set, it 1275 denotes that the subpacket is one that is critical for the evaluator 1276 of the signature to recognize. If a subpacket is encountered that is 1277 marked critical but is unknown to the evaluating software, the 1278 evaluator SHOULD consider the signature to be in error. 1280 An evaluator may "recognize" a subpacket, but not implement it. The 1281 purpose of the critical bit is to allow the signer to tell an 1282 evaluator that it would prefer a new, unknown feature to generate an 1283 error than be ignored. 1285 Implementations SHOULD implement the three preferred algorithm 1286 subpackets (11, 21, and 22), as well as the "Reason for Revocation" 1287 subpacket. Note, however, that if an implementation chooses not to 1288 implement some of the preferences, it is required to behave in a 1289 polite manner to respect the wishes of those users who do implement 1290 these preferences. 1292 5.2.3.2. Signature Subpacket Types 1294 A number of subpackets are currently defined. Some subpackets apply 1295 to the signature itself and some are attributes of the key. 1296 Subpackets that are found on a self-signature are placed on a 1297 certification made by the key itself. Note that a key may have more 1298 than one User ID, and thus may have more than one self-signature, and 1299 differing subpackets. 1301 A subpacket may be found either in the hashed or unhashed subpacket 1302 sections of a signature. If a subpacket is not hashed, then the 1303 information in it cannot be considered definitive because it is not 1304 part of the signature proper. 1306 5.2.3.3. Notes on Self-Signatures 1308 A self-signature is a binding signature made by the key to which the 1309 signature refers. There are three types of self-signatures, the 1310 certification signatures (types 0x10-0x13), the direct-key signature 1311 (type 0x1F), and the subkey binding signature (type 0x18). For 1312 certification self-signatures, each User ID may have a self- 1313 signature, and thus different subpackets in those self-signatures. 1315 For subkey binding signatures, each subkey in fact has a self- 1316 signature. Subpackets that appear in a certification self-signature 1317 apply to the user name, and subpackets that appear in the subkey 1318 self-signature apply to the subkey. Lastly, subpackets on the 1319 direct-key signature apply to the entire key. 1321 Implementing software should interpret a self-signature's preference 1322 subpackets as narrowly as possible. For example, suppose a key has 1323 two user names, Alice and Bob. Suppose that Alice prefers the 1324 symmetric algorithm CAST5, and Bob prefers IDEA or TripleDES. If the 1325 software locates this key via Alice's name, then the preferred 1326 algorithm is CAST5; if software locates the key via Bob's name, then 1327 the preferred algorithm is IDEA. If the key is located by Key ID, 1328 the algorithm of the primary User ID of the key provides the 1329 preferred symmetric algorithm. 1331 Revoking a self-signature or allowing it to expire has a semantic 1332 meaning that varies with the signature type. Revoking the self- 1333 signature on a User ID effectively retires that user name. The self- 1334 signature is a statement, "My name X is tied to my signing key K" and 1335 is corroborated by other users' certifications. If another user 1336 revokes their certification, they are effectively saying that they no 1337 longer believe that name and that key are tied together. Similarly, 1338 if the users themselves revoke their self-signature, then the users 1339 no longer go by that name, no longer have that email address, etc. 1340 Revoking a binding signature effectively retires that subkey. 1341 Revoking a direct-key signature cancels that signature. Please see 1342 Section 5.2.3.23 for more relevant detail. 1344 Since a self-signature contains important information about the key's 1345 use, an implementation SHOULD allow the user to rewrite the self- 1346 signature, and important information in it, such as preferences and 1347 key expiration. 1349 It is good practice to verify that a self-signature imported into an 1350 implementation doesn't advertise features that the implementation 1351 doesn't support, rewriting the signature as appropriate. 1353 An implementation that encounters multiple self-signatures on the 1354 same object may resolve the ambiguity in any way it sees fit, but it 1355 is RECOMMENDED that priority be given to the most recent self- 1356 signature. 1358 5.2.3.4. Signature Creation Time 1360 (4-octet time field) 1362 The time the signature was made. 1364 MUST be present in the hashed area. 1366 5.2.3.5. Issuer 1368 (8-octet Key ID) 1370 The OpenPGP Key ID of the key issuing the signature. 1372 5.2.3.6. Key Expiration Time 1374 (4-octet time field) 1376 The validity period of the key. This is the number of seconds after 1377 the key creation time that the key expires. If this is not present 1378 or has a value of zero, the key never expires. This is found only on 1379 a self-signature. 1381 5.2.3.7. Preferred Symmetric Algorithms 1383 (array of one-octet values) 1385 Symmetric algorithm numbers that indicate which algorithms the key 1386 holder prefers to use. The subpacket body is an ordered list of 1387 octets with the most preferred listed first. It is assumed that only 1388 algorithms listed are supported by the recipient's software. 1389 Algorithm numbers are in Section 9.2. This is only found on a self- 1390 signature. 1392 5.2.3.8. Preferred Hash Algorithms 1394 (array of one-octet values) 1396 Message digest algorithm numbers that indicate which algorithms the 1397 key holder prefers to receive. Like the preferred symmetric 1398 algorithms, the list is ordered. Algorithm numbers are in 1399 Section 9.4. This is only found on a self-signature. 1401 5.2.3.9. Preferred Compression Algorithms 1403 (array of one-octet values) 1405 Compression algorithm numbers that indicate which algorithms the key 1406 holder prefers to use. Like the preferred symmetric algorithms, the 1407 list is ordered. Algorithm numbers are in Section 9.3. If this 1408 subpacket is not included, ZIP is preferred. A zero denotes that 1409 uncompressed data is preferred; the key holder's software might have 1410 no compression software in that implementation. This is only found 1411 on a self-signature. 1413 5.2.3.10. Signature Expiration Time 1415 (4-octet time field) 1417 The validity period of the signature. This is the number of seconds 1418 after the signature creation time that the signature expires. If 1419 this is not present or has a value of zero, it never expires. 1421 5.2.3.11. Exportable Certification 1423 (1 octet of exportability, 0 for not, 1 for exportable) 1425 This subpacket denotes whether a certification signature is 1426 "exportable", to be used by other users than the signature's issuer. 1427 The packet body contains a Boolean flag indicating whether the 1428 signature is exportable. If this packet is not present, the 1429 certification is exportable; it is equivalent to a flag containing a 1430 1. 1432 Non-exportable, or "local", certifications are signatures made by a 1433 user to mark a key as valid within that user's implementation only. 1435 Thus, when an implementation prepares a user's copy of a key for 1436 transport to another user (this is the process of "exporting" the 1437 key), any local certification signatures are deleted from the key. 1439 The receiver of a transported key "imports" it, and likewise trims 1440 any local certifications. In normal operation, there won't be any, 1441 assuming the import is performed on an exported key. However, there 1442 are instances where this can reasonably happen. For example, if an 1443 implementation allows keys to be imported from a key database in 1444 addition to an exported key, then this situation can arise. 1446 Some implementations do not represent the interest of a single user 1447 (for example, a key server). Such implementations always trim local 1448 certifications from any key they handle. 1450 5.2.3.12. Revocable 1452 (1 octet of revocability, 0 for not, 1 for revocable) 1454 Signature's revocability status. The packet body contains a Boolean 1455 flag indicating whether the signature is revocable. Signatures that 1456 are not revocable have any later revocation signatures ignored. They 1457 represent a commitment by the signer that he cannot revoke his 1458 signature for the life of his key. If this packet is not present, 1459 the signature is revocable. 1461 5.2.3.13. Trust Signature 1463 (1 octet "level" (depth), 1 octet of trust amount) 1465 Signer asserts that the key is not only valid but also trustworthy at 1466 the specified level. Level 0 has the same meaning as an ordinary 1467 validity signature. Level 1 means that the signed key is asserted to 1468 be a valid trusted introducer, with the 2nd octet of the body 1469 specifying the degree of trust. Level 2 means that the signed key is 1470 asserted to be trusted to issue level 1 trust signatures, i.e., that 1471 it is a "meta introducer". Generally, a level n trust signature 1472 asserts that a key is trusted to issue level n-1 trust signatures. 1473 The trust amount is in a range from 0-255, interpreted such that 1474 values less than 120 indicate partial trust and values of 120 or 1475 greater indicate complete trust. Implementations SHOULD emit values 1476 of 60 for partial trust and 120 for complete trust. 1478 5.2.3.14. Regular Expression 1480 (null-terminated regular expression) 1482 Used in conjunction with trust Signature packets (of level > 0) to 1483 limit the scope of trust that is extended. Only signatures by the 1484 target key on User IDs that match the regular expression in the body 1485 of this packet have trust extended by the trust Signature subpacket. 1486 The regular expression uses the same syntax as the Henry Spencer's 1487 "almost public domain" regular expression [REGEX] package. A 1488 description of the syntax is found in Section 8. 1490 5.2.3.15. Revocation Key 1492 (1 octet of class, 1 octet of public-key algorithm ID, 20 octets of 1493 fingerprint) 1495 Authorizes the specified key to issue revocation signatures for this 1496 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1497 then this means that the revocation information is sensitive. Other 1498 bits are for future expansion to other kinds of authorizations. This 1499 is found on a self-signature. 1501 If the "sensitive" flag is set, the keyholder feels this subpacket 1502 contains private trust information that describes a real-world 1503 sensitive relationship. If this flag is set, implementations SHOULD 1504 NOT export this signature to other users except in cases where the 1505 data needs to be available: when the signature is being sent to the 1506 designated revoker, or when it is accompanied by a revocation 1507 signature from that revoker. Note that it may be appropriate to 1508 isolate this subpacket within a separate signature so that it is not 1509 combined with other subpackets that need to be exported. 1511 5.2.3.16. Notation Data 1513 (4 octets of flags, 2 octets of name length (M), 2 octets of value 1514 length (N), M octets of name data, N octets of value data) 1516 This subpacket describes a "notation" on the signature that the 1517 issuer wishes to make. The notation has a name and a value, each of 1518 which are strings of octets. There may be more than one notation in 1519 a signature. Notations can be used for any extension the issuer of 1520 the signature cares to make. The "flags" field holds four octets of 1521 flags. 1523 All undefined flags MUST be zero. Defined flags are as follows: 1525 First octet: 1527 +======+================+==========================+ 1528 | flag | shorthand | definition | 1529 +======+================+==========================+ 1530 | 0x80 | human-readable | This note value is text. | 1531 +------+----------------+--------------------------+ 1533 Table 7: Notation flag registry (first octet) 1535 Other octets: none. 1537 Notation names are arbitrary strings encoded in UTF-8. They reside 1538 in two namespaces: The IETF namespace and the user namespace. 1540 The IETF namespace is registered with IANA. These names MUST NOT 1541 contain the "@" character (0x40). This is a tag for the user 1542 namespace. 1544 Names in the user namespace consist of a UTF-8 string tag followed by 1545 "@" followed by a DNS domain name. Note that the tag MUST NOT 1546 contain an "@" character. For example, the "sample" tag used by 1547 Example Corporation could be "sample@example.com". 1549 Names in a user space are owned and controlled by the owners of that 1550 domain. Obviously, it's bad form to create a new name in a DNS space 1551 that you don't own. 1553 Since the user namespace is in the form of an email address, 1554 implementers MAY wish to arrange for that address to reach a person 1555 who can be consulted about the use of the named tag. Note that due 1556 to UTF-8 encoding, not all valid user space name tags are valid email 1557 addresses. 1559 If there is a critical notation, the criticality applies to that 1560 specific notation and not to notations in general. 1562 5.2.3.17. Key Server Preferences 1564 (N octets of flags) 1566 This is a list of one-bit flags that indicate preferences that the 1567 key holder has about how the key is handled on a key server. All 1568 undefined flags MUST be zero. 1570 First octet: 1572 +======+===========+============================================+ 1573 | flag | shorthand | definition | 1574 +======+===========+============================================+ 1575 | 0x80 | No-modify | The key holder requests that this key only | 1576 | | | be modified or updated by the key holder | 1577 | | | or an administrator of the key server. | 1578 +------+-----------+--------------------------------------------+ 1580 Table 8: Key server preferences flag registry (first octet) 1582 This is found only on a self-signature. 1584 5.2.3.18. Preferred Key Server 1586 (String) 1588 This is a URI of a key server that the key holder prefers be used for 1589 updates. Note that keys with multiple User IDs can have a preferred 1590 key server for each User ID. Note also that since this is a URI, the 1591 key server can actually be a copy of the key retrieved by ftp, http, 1592 finger, etc. 1594 5.2.3.19. Primary User ID 1596 (1 octet, Boolean) 1598 This is a flag in a User ID's self-signature that states whether this 1599 User ID is the main User ID for this key. It is reasonable for an 1600 implementation to resolve ambiguities in preferences, etc. by 1601 referring to the primary User ID. If this flag is absent, its value 1602 is zero. If more than one User ID in a key is marked as primary, the 1603 implementation may resolve the ambiguity in any way it sees fit, but 1604 it is RECOMMENDED that priority be given to the User ID with the most 1605 recent self-signature. 1607 When appearing on a self-signature on a User ID packet, this 1608 subpacket applies only to User ID packets. When appearing on a self- 1609 signature on a User Attribute packet, this subpacket applies only to 1610 User Attribute packets. That is to say, there are two different and 1611 independent "primaries" -- one for User IDs, and one for User 1612 Attributes. 1614 5.2.3.20. Policy URI 1616 (String) 1618 This subpacket contains a URI of a document that describes the policy 1619 under which the signature was issued. 1621 5.2.3.21. Key Flags 1623 (N octets of flags) 1625 This subpacket contains a list of binary flags that hold information 1626 about a key. It is a string of octets, and an implementation MUST 1627 NOT assume a fixed size. This is so it can grow over time. If a 1628 list is shorter than an implementation expects, the unstated flags 1629 are considered to be zero. The defined flags are as follows: 1631 First octet: 1633 +======+=================================================+ 1634 | flag | definition | 1635 +======+=================================================+ 1636 | 0x01 | This key may be used to certify other keys. | 1637 +------+-------------------------------------------------+ 1638 | 0x02 | This key may be used to sign data. | 1639 +------+-------------------------------------------------+ 1640 | 0x04 | This key may be used to encrypt communications. | 1641 +------+-------------------------------------------------+ 1642 | 0x08 | This key may be used to encrypt storage. | 1643 +------+-------------------------------------------------+ 1644 | 0x10 | The private component of this key may have been | 1645 | | split by a secret-sharing mechanism. | 1646 +------+-------------------------------------------------+ 1647 | 0x20 | This key may be used for authentication. | 1648 +------+-------------------------------------------------+ 1649 | 0x80 | The private component of this key may be in the | 1650 | | possession of more than one person. | 1651 +------+-------------------------------------------------+ 1653 Table 9: Key flags registry 1655 Usage notes: 1657 The flags in this packet may appear in self-signatures or in 1658 certification signatures. They mean different things depending on 1659 who is making the statement -- for example, a certification signature 1660 that has the "sign data" flag is stating that the certification is 1661 for that use. On the other hand, the "communications encryption" 1662 flag in a self-signature is stating a preference that a given key be 1663 used for communications. Note however, that it is a thorny issue to 1664 determine what is "communications" and what is "storage". This 1665 decision is left wholly up to the implementation; the authors of this 1666 document do not claim any special wisdom on the issue and realize 1667 that accepted opinion may change. 1669 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1670 self-signature only; they are meaningless on a certification 1671 signature. They SHOULD be placed only on a direct-key signature 1672 (type 0x1F) or a subkey signature (type 0x18), one that refers to the 1673 key the flag applies to. 1675 5.2.3.22. Signer's User ID 1677 (String) 1678 This subpacket allows a keyholder to state which User ID is 1679 responsible for the signing. Many keyholders use a single key for 1680 different purposes, such as business communications as well as 1681 personal communications. This subpacket allows such a keyholder to 1682 state which of their roles is making a signature. 1684 This subpacket is not appropriate to use to refer to a User Attribute 1685 packet. 1687 5.2.3.23. Reason for Revocation 1689 (1 octet of revocation code, N octets of reason string) 1691 This subpacket is used only in key revocation and certification 1692 revocation signatures. It describes the reason why the key or 1693 certificate was revoked. 1695 The first octet contains a machine-readable code that denotes the 1696 reason for the revocation: 1698 +=========+==================================+ 1699 | Code | Reason | 1700 +=========+==================================+ 1701 | 0 | No reason specified (key | 1702 | | revocations or cert revocations) | 1703 +---------+----------------------------------+ 1704 | 1 | Key is superseded (key | 1705 | | revocations) | 1706 +---------+----------------------------------+ 1707 | 2 | Key material has been | 1708 | | compromised (key revocations) | 1709 +---------+----------------------------------+ 1710 | 3 | Key is retired and no longer | 1711 | | used (key revocations) | 1712 +---------+----------------------------------+ 1713 | 32 | User ID information is no longer | 1714 | | valid (cert revocations) | 1715 +---------+----------------------------------+ 1716 | 100-110 | Private Use | 1717 +---------+----------------------------------+ 1719 Table 10: Reasons for revocation 1721 Following the revocation code is a string of octets that gives 1722 information about the Reason for Revocation in human-readable form 1723 (UTF-8). The string may be null, that is, of zero length. The 1724 length of the subpacket is the length of the reason string plus one. 1725 An implementation SHOULD implement this subpacket, include it in all 1726 revocation signatures, and interpret revocations appropriately. 1727 There are important semantic differences between the reasons, and 1728 there are thus important reasons for revoking signatures. 1730 If a key has been revoked because of a compromise, all signatures 1731 created by that key are suspect. However, if it was merely 1732 superseded or retired, old signatures are still valid. If the 1733 revoked signature is the self-signature for certifying a User ID, a 1734 revocation denotes that that user name is no longer in use. Such a 1735 revocation SHOULD include a 0x20 code. 1737 Note that any signature may be revoked, including a certification on 1738 some other person's key. There are many good reasons for revoking a 1739 certification signature, such as the case where the keyholder leaves 1740 the employ of a business with an email address. A revoked 1741 certification is no longer a part of validity calculations. 1743 5.2.3.24. Features 1745 (N octets of flags) 1747 The Features subpacket denotes which advanced OpenPGP features a 1748 user's implementation supports. This is so that as features are 1749 added to OpenPGP that cannot be backwards-compatible, a user can 1750 state that they can use that feature. The flags are single bits that 1751 indicate that a given feature is supported. 1753 This subpacket is similar to a preferences subpacket, and only 1754 appears in a self-signature. 1756 An implementation SHOULD NOT use a feature listed when sending to a 1757 user who does not state that they can use it. 1759 Defined features are as follows: 1761 First octet: 1763 +=========+============================================+ 1764 | feature | definition | 1765 +=========+============================================+ 1766 | 0x01 | Modification Detection (packets 18 and 19) | 1767 +---------+--------------------------------------------+ 1769 Table 11: Features registry 1771 If an implementation implements any of the defined features, it 1772 SHOULD implement the Features subpacket, too. 1774 An implementation may freely infer features from other suitable 1775 implementation-dependent mechanisms. 1777 5.2.3.25. Signature Target 1779 (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash) 1781 This subpacket identifies a specific target signature to which a 1782 signature refers. For revocation signatures, this subpacket provides 1783 explicit designation of which signature is being revoked. For a 1784 third-party or timestamp signature, this designates what signature is 1785 signed. All arguments are an identifier of that target signature. 1787 The N octets of hash data MUST be the size of the hash of the 1788 signature. For example, a target signature with a SHA-1 hash MUST 1789 have 20 octets of hash data. 1791 5.2.3.26. Embedded Signature 1793 (1 signature packet body) 1795 This subpacket contains a complete Signature packet body as specified 1796 in Section 5.2. It is useful when one signature needs to refer to, 1797 or be incorporated in, another signature. 1799 5.2.4. Computing Signatures 1801 All signatures are formed by producing a hash over the signature 1802 data, and then using the resulting hash in the signature algorithm. 1804 For binary document signatures (type 0x00), the document data is 1805 hashed directly. For text document signatures (type 0x01), the 1806 document is canonicalized by converting line endings to , and 1807 the resulting data is hashed. 1809 When a signature is made over a key, the hash data starts with the 1810 octet 0x99, followed by a two-octet length of the key, and then body 1811 of the key packet. (Note that this is an old-style packet header for 1812 a key packet with two-octet length.) A subkey binding signature 1813 (type 0x18) or primary key binding signature (type 0x19) then hashes 1814 the subkey using the same format as the main key (also using 0x99 as 1815 the first octet). Primary key revocation signatures (type 0x20) hash 1816 only the key being revoked. Subkey revocation signature (type 0x28) 1817 hash first the primary key and then the subkey being revoked. 1819 A certification signature (type 0x10 through 0x13) hashes the User ID 1820 being bound to the key into the hash context after the above data. A 1821 V3 certification hashes the contents of the User ID or attribute 1822 packet packet, without any header. A V4 certification hashes the 1823 constant 0xB4 for User ID certifications or the constant 0xD1 for 1824 User Attribute certifications, followed by a four-octet number giving 1825 the length of the User ID or User Attribute data, and then the User 1826 ID or User Attribute data. 1828 When a signature is made over a Signature packet (type 0x50), the 1829 hash data starts with the octet 0x88, followed by the four-octet 1830 length of the signature, and then the body of the Signature packet. 1831 (Note that this is an old-style packet header for a Signature packet 1832 with the length-of-length set to zero.) The unhashed subpacket data 1833 of the Signature packet being hashed is not included in the hash, and 1834 the unhashed subpacket data length value is set to zero. 1836 Once the data body is hashed, then a trailer is hashed. A V3 1837 signature hashes five octets of the packet body, starting from the 1838 signature type field. This data is the signature type, followed by 1839 the four-octet signature time. A V4 signature hashes the packet body 1840 starting from its first field, the version number, through the end of 1841 the hashed subpacket data. Thus, the fields hashed are the signature 1842 version, the signature type, the public-key algorithm, the hash 1843 algorithm, the hashed subpacket length, and the hashed subpacket 1844 body. 1846 V4 signatures also hash in a final trailer of six octets: the version 1847 of the Signature packet, i.e., 0x04; 0xFF; and a four-octet, big- 1848 endian number that is the length of the hashed data from the 1849 Signature packet (note that this number does not include these final 1850 six octets). 1852 After all this has been hashed in a single hash context, the 1853 resulting hash field is used in the signature algorithm and placed at 1854 the end of the Signature packet. 1856 5.2.4.1. Subpacket Hints 1858 It is certainly possible for a signature to contain conflicting 1859 information in subpackets. For example, a signature may contain 1860 multiple copies of a preference or multiple expiration times. In 1861 most cases, an implementation SHOULD use the last subpacket in the 1862 signature, but MAY use any conflict resolution scheme that makes more 1863 sense. Please note that we are intentionally leaving conflict 1864 resolution to the implementer; most conflicts are simply syntax 1865 errors, and the wishy-washy language here allows a receiver to be 1866 generous in what they accept, while putting pressure on a creator to 1867 be stingy in what they generate. 1869 Some apparent conflicts may actually make sense -- for example, 1870 suppose a keyholder has a V3 key and a V4 key that share the same RSA 1871 key material. Either of these keys can verify a signature created by 1872 the other, and it may be reasonable for a signature to contain an 1873 issuer subpacket for each key, as a way of explicitly tying those 1874 keys to the signature. 1876 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) 1878 The Symmetric-Key Encrypted Session Key packet holds the symmetric- 1879 key encryption of a session key used to encrypt a message. Zero or 1880 more Public-Key Encrypted Session Key packets and/or Symmetric-Key 1881 Encrypted Session Key packets may precede a Symmetrically Encrypted 1882 Data packet that holds an encrypted message. The message is 1883 encrypted with a session key, and the session key is itself encrypted 1884 and stored in the Encrypted Session Key packet or the Symmetric-Key 1885 Encrypted Session Key packet. 1887 If the Symmetrically Encrypted Data packet is preceded by one or more 1888 Symmetric-Key Encrypted Session Key packets, each specifies a 1889 passphrase that may be used to decrypt the message. This allows a 1890 message to be encrypted to a number of public keys, and also to one 1891 or more passphrases. This packet type is new and is not generated by 1892 PGP 2 or PGP version 5.0. 1894 The body of this packet consists of: 1896 * A one-octet version number. The only currently defined version is 1897 4. 1899 * A one-octet number describing the symmetric algorithm used. 1901 * A string-to-key (S2K) specifier, length as defined above. 1903 * Optionally, the encrypted session key itself, which is decrypted 1904 with the string-to-key object. 1906 If the encrypted session key is not present (which can be detected on 1907 the basis of packet length and S2K specifier size), then the S2K 1908 algorithm applied to the passphrase produces the session key for 1909 decrypting the file, using the symmetric cipher algorithm from the 1910 Symmetric-Key Encrypted Session Key packet. 1912 If the encrypted session key is present, the result of applying the 1913 S2K algorithm to the passphrase is used to decrypt just that 1914 encrypted session key field, using CFB mode with an IV of all zeros. 1915 The decryption result consists of a one-octet algorithm identifier 1916 that specifies the symmetric-key encryption algorithm used to encrypt 1917 the following Symmetrically Encrypted Data packet, followed by the 1918 session key octets themselves. 1920 Note: because an all-zero IV is used for this decryption, the S2K 1921 specifier MUST use a salt value, either a Salted S2K or an Iterated- 1922 Salted S2K. The salt value will ensure that the decryption key is 1923 not repeated even if the passphrase is reused. 1925 5.4. One-Pass Signature Packets (Tag 4) 1927 The One-Pass Signature packet precedes the signed data and contains 1928 enough information to allow the receiver to begin calculating any 1929 hashes needed to verify the signature. It allows the Signature 1930 packet to be placed at the end of the message, so that the signer can 1931 compute the entire signed message in one pass. 1933 A One-Pass Signature does not interoperate with PGP 2.6.x or earlier. 1935 The body of this packet consists of: 1937 * A one-octet version number. The current version is 3. 1939 * A one-octet signature type. Signature types are described in 1940 Section 5.2.1. 1942 * A one-octet number describing the hash algorithm used. 1944 * A one-octet number describing the public-key algorithm used. 1946 * An eight-octet number holding the Key ID of the signing key. 1948 * A one-octet number holding a flag showing whether the signature is 1949 nested. A zero value indicates that the next packet is another 1950 One-Pass Signature packet that describes another signature to be 1951 applied to the same message data. 1953 Note that if a message contains more than one one-pass signature, 1954 then the Signature packets bracket the message; that is, the first 1955 Signature packet after the message corresponds to the last one-pass 1956 packet and the final Signature packet corresponds to the first one- 1957 pass packet. 1959 5.5. Key Material Packet 1961 A key material packet contains all the information about a public or 1962 private key. There are four variants of this packet type, and two 1963 major versions. Consequently, this section is complex. 1965 5.5.1. Key Packet Variants 1967 5.5.1.1. Public-Key Packet (Tag 6) 1969 A Public-Key packet starts a series of packets that forms an OpenPGP 1970 key (sometimes called an OpenPGP certificate). 1972 5.5.1.2. Public-Subkey Packet (Tag 14) 1974 A Public-Subkey packet (tag 14) has exactly the same format as a 1975 Public-Key packet, but denotes a subkey. One or more subkeys may be 1976 associated with a top-level key. By convention, the top-level key 1977 provides signature services, and the subkeys provide encryption 1978 services. 1980 Note: in PGP version 2.6, tag 14 was intended to indicate a comment 1981 packet. This tag was selected for reuse because no previous version 1982 of PGP ever emitted comment packets but they did properly ignore 1983 them. Public-Subkey packets are ignored by PGP version 2.6 and do 1984 not cause it to fail, providing a limited degree of backward 1985 compatibility. 1987 5.5.1.3. Secret-Key Packet (Tag 5) 1989 A Secret-Key packet contains all the information that is found in a 1990 Public-Key packet, including the public-key material, but also 1991 includes the secret-key material after all the public-key fields. 1993 5.5.1.4. Secret-Subkey Packet (Tag 7) 1995 A Secret-Subkey packet (tag 7) is the subkey analog of the Secret Key 1996 packet and has exactly the same format. 1998 5.5.2. Public-Key Packet Formats 2000 There are two versions of key-material packets. Version 3 packets 2001 were first generated by PGP version 2.6. Version 4 keys first 2002 appeared in PGP 5 and are the preferred key version for OpenPGP. 2004 OpenPGP implementations MUST create keys with version 4 format. V3 2005 keys are deprecated; an implementation MUST NOT generate a V3 key, 2006 but MAY accept it. 2008 A version 3 public key or public-subkey packet contains: 2010 * A one-octet version number (3). 2012 * A four-octet number denoting the time that the key was created. 2014 * A two-octet number denoting the time in days that this key is 2015 valid. If this number is zero, then it does not expire. 2017 * A one-octet number denoting the public-key algorithm of this key. 2019 * A series of multiprecision integers comprising the key material: 2021 - a multiprecision integer (MPI) of RSA public modulus n; 2023 - an MPI of RSA public encryption exponent e. 2025 V3 keys are deprecated. They contain three weaknesses. First, it is 2026 relatively easy to construct a V3 key that has the same Key ID as any 2027 other key because the Key ID is simply the low 64 bits of the public 2028 modulus. Secondly, because the fingerprint of a V3 key hashes the 2029 key material, but not its length, there is an increased opportunity 2030 for fingerprint collisions. Third, there are weaknesses in the MD5 2031 hash algorithm that make developers prefer other algorithms. See 2032 below for a fuller discussion of Key IDs and fingerprints. 2034 V2 keys are identical to the deprecated V3 keys except for the 2035 version number. An implementation MUST NOT generate them and MAY 2036 accept or reject them as it sees fit. 2038 The version 4 format is similar to the version 3 format except for 2039 the absence of a validity period. This has been moved to the 2040 Signature packet. In addition, fingerprints of version 4 keys are 2041 calculated differently from version 3 keys, as described in 2042 Section 12. 2044 A version 4 packet contains: 2046 * A one-octet version number (4). 2048 * A four-octet number denoting the time that the key was created. 2050 * A one-octet number denoting the public-key algorithm of this key. 2052 * A series of multiprecision integers comprising the key material. 2053 This algorithm-specific portion is: 2055 Algorithm-Specific Fields for RSA public keys: 2057 - multiprecision integer (MPI) of RSA public modulus n; 2059 - MPI of RSA public encryption exponent e. 2061 Algorithm-Specific Fields for DSA public keys: 2063 - MPI of DSA prime p; 2065 - MPI of DSA group order q (q is a prime divisor of p-1); 2067 - MPI of DSA group generator g; 2069 - MPI of DSA public-key value y (= g**x mod p where x is secret). 2071 Algorithm-Specific Fields for Elgamal public keys: 2073 - MPI of Elgamal prime p; 2075 - MPI of Elgamal group generator g; 2077 - MPI of Elgamal public key value y (= g**x mod p where x is 2078 secret). 2080 5.5.3. Secret-Key Packet Formats 2082 The Secret-Key and Secret-Subkey packets contain all the data of the 2083 Public-Key and Public-Subkey packets, with additional algorithm- 2084 specific secret-key data appended, usually in encrypted form. 2086 The packet contains: 2088 * A Public-Key or Public-Subkey packet, as described above. 2090 * One octet indicating string-to-key usage conventions. Zero 2091 indicates that the secret-key data is not encrypted. 255 or 254 2092 indicates that a string-to-key specifier is being given. Any 2093 other value is a symmetric-key encryption algorithm identifier. 2095 * [Optional] If string-to-key usage octet was 255 or 254, a one- 2096 octet symmetric encryption algorithm. 2098 * [Optional] If string-to-key usage octet was 255 or 254, a string- 2099 to-key specifier. The length of the string-to-key specifier is 2100 implied by its type, as described above. 2102 * [Optional] If secret data is encrypted (string-to-key usage octet 2103 not zero), an Initial Vector (IV) of the same length as the 2104 cipher's block size. 2106 * Plain or encrypted multiprecision integers comprising the secret 2107 key data. These algorithm-specific fields are as described below. 2109 * If the string-to-key usage octet is zero or 255, then a two-octet 2110 checksum of the plaintext of the algorithm-specific portion (sum 2111 of all octets, mod 65536). If the string-to-key usage octet was 2112 254, then a 20-octet SHA-1 hash of the plaintext of the algorithm- 2113 specific portion. This checksum or hash is encrypted together 2114 with the algorithm-specific fields (if string-to-key usage octet 2115 is not zero). Note that for all other values, a two-octet 2116 checksum is required. 2118 Algorithm-Specific Fields for RSA secret keys: 2120 - multiprecision integer (MPI) of RSA secret exponent d. 2122 - MPI of RSA secret prime value p. 2124 - MPI of RSA secret prime value q (p < q). 2126 - MPI of u, the multiplicative inverse of p, mod q. 2128 Algorithm-Specific Fields for DSA secret keys: 2130 - MPI of DSA secret exponent x. 2132 Algorithm-Specific Fields for Elgamal secret keys: 2134 - MPI of Elgamal secret exponent x. 2136 Secret MPI values can be encrypted using a passphrase. If a string- 2137 to-key specifier is given, that describes the algorithm for 2138 converting the passphrase to a key, else a simple MD5 hash of the 2139 passphrase is used. Implementations MUST use a string-to-key 2140 specifier; the simple hash is for backward compatibility and is 2141 deprecated, though implementations MAY continue to use existing 2142 private keys in the old format. The cipher for encrypting the MPIs 2143 is specified in the Secret-Key packet. 2145 Encryption/decryption of the secret data is done in CFB mode using 2146 the key created from the passphrase and the Initial Vector from the 2147 packet. A different mode is used with V3 keys (which are only RSA) 2148 than with other key formats. With V3 keys, the MPI bit count prefix 2149 (i.e., the first two octets) is not encrypted. Only the MPI non- 2150 prefix data is encrypted. Furthermore, the CFB state is 2151 resynchronized at the beginning of each new MPI value, so that the 2152 CFB block boundary is aligned with the start of the MPI data. 2154 With V4 keys, a simpler method is used. All secret MPI values are 2155 encrypted in CFB mode, including the MPI bitcount prefix. 2157 The two-octet checksum that follows the algorithm-specific portion is 2158 the algebraic sum, mod 65536, of the plaintext of all the algorithm- 2159 specific octets (including MPI prefix and data). With V3 keys, the 2160 checksum is stored in the clear. With V4 keys, the checksum is 2161 encrypted like the algorithm-specific data. This value is used to 2162 check that the passphrase was correct. However, this checksum is 2163 deprecated; an implementation SHOULD NOT use it, but should rather 2164 use the SHA-1 hash denoted with a usage octet of 254. The reason for 2165 this is that there are some attacks that involve undetectably 2166 modifying the secret key. 2168 5.6. Compressed Data Packet (Tag 8) 2170 The Compressed Data packet contains compressed data. Typically, this 2171 packet is found as the contents of an encrypted packet, or following 2172 a Signature or One-Pass Signature packet, and contains a literal data 2173 packet. 2175 The body of this packet consists of: 2177 * One octet that gives the algorithm used to compress the packet. 2179 * Compressed data, which makes up the remainder of the packet. 2181 A Compressed Data Packet's body contains an block that compresses 2182 some set of packets. See Section 11 for details on how messages are 2183 formed. 2185 ZIP-compressed packets are compressed with raw [RFC1951] DEFLATE 2186 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 2187 implementation uses more bits of compression, PGP V2.6 cannot 2188 decompress it. 2190 ZLIB-compressed packets are compressed with [RFC1950] ZLIB-style 2191 blocks. 2193 BZip2-compressed packets are compressed using the BZip2 [BZ2] 2194 algorithm. 2196 5.7. Symmetrically Encrypted Data Packet (Tag 9) 2198 The Symmetrically Encrypted Data packet contains data encrypted with 2199 a symmetric-key algorithm. When it has been decrypted, it contains 2200 other packets (usually a literal data packet or compressed data 2201 packet, but in theory other Symmetrically Encrypted Data packets or 2202 sequences of packets that form whole OpenPGP messages). 2204 The body of this packet consists of: 2206 * Encrypted data, the output of the selected symmetric-key cipher 2207 operating in OpenPGP's variant of Cipher Feedback (CFB) mode. 2209 The symmetric cipher used may be specified in a Public-Key or 2210 Symmetric-Key Encrypted Session Key packet that precedes the 2211 Symmetrically Encrypted Data packet. In that case, the cipher 2212 algorithm octet is prefixed to the session key before it is 2213 encrypted. If no packets of these types precede the encrypted data, 2214 the IDEA algorithm is used with the session key calculated as the MD5 2215 hash of the passphrase, though this use is deprecated. 2217 The data is encrypted in CFB mode, with a CFB shift size equal to the 2218 cipher's block size. The Initial Vector (IV) is specified as all 2219 zeros. Instead of using an IV, OpenPGP prefixes a string of length 2220 equal to the block size of the cipher plus two to the data before it 2221 is encrypted. The first block-size octets (for example, 8 octets for 2222 a 64-bit block length) are random, and the following two octets are 2223 copies of the last two octets of the IV. For example, in an 8-octet 2224 block, octet 9 is a repeat of octet 7, and octet 10 is a repeat of 2225 octet 8. In a cipher of length 16, octet 17 is a repeat of octet 15 2226 and octet 18 is a repeat of octet 16. As a pedantic clarification, 2227 in both these examples, we consider the first octet to be numbered 1. 2229 After encrypting the first block-size-plus-two octets, the CFB state 2230 is resynchronized. The last block-size octets of ciphertext are 2231 passed through the cipher and the block boundary is reset. 2233 The repetition of 16 bits in the random data prefixed to the message 2234 allows the receiver to immediately check whether the session key is 2235 incorrect. See Section 14 for hints on the proper use of this "quick 2236 check". 2238 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 2240 An experimental version of PGP used this packet as the Literal 2241 packet, but no released version of PGP generated Literal packets with 2242 this tag. With PGP 5, this packet has been reassigned and is 2243 reserved for use as the Marker packet. 2245 The body of this packet consists of: 2247 * The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 2249 Such a packet MUST be ignored when received. It may be placed at the 2250 beginning of a message that uses features not available in PGP 2251 version 2.6 in order to cause that version to report that newer 2252 software is necessary to process the message. 2254 5.9. Literal Data Packet (Tag 11) 2256 A Literal Data packet contains the body of a message; data that is 2257 not to be further interpreted. 2259 The body of this packet consists of: 2261 * A one-octet field that describes how the data is formatted. 2263 If it is a "b" (0x62), then the Literal packet contains binary 2264 data. If it is a "t" (0x74), then it contains text data, and thus 2265 may need line ends converted to local form, or other text-mode 2266 changes. The tag "u" (0x75) means the same as "t", but also 2267 indicates that implementation believes that the literal data 2268 contains UTF-8 text. 2270 Early versions of PGP also defined a value of "l" as a 'local' 2271 mode for machine-local conversions. [RFC1991] incorrectly stated 2272 this local mode flag as "1" (ASCII numeral one). Both of these 2273 local modes are deprecated. 2275 * File name as a string (one-octet length, followed by a file name). 2276 This may be a zero-length string. Commonly, if the source of the 2277 encrypted data is a file, this will be the name of the encrypted 2278 file. An implementation MAY consider the file name in the Literal 2279 packet to be a more authoritative name than the actual file name. 2281 If the special name "_CONSOLE" is used, the message is considered 2282 to be "for your eyes only". This advises that the message data is 2283 unusually sensitive, and the receiving program should process it 2284 more carefully, perhaps avoiding storing the received data to 2285 disk, for example. 2287 * A four-octet number that indicates a date associated with the 2288 literal data. Commonly, the date might be the modification date 2289 of a file, or the time the packet was created, or a zero that 2290 indicates no specific time. 2292 * The remainder of the packet is literal data. 2294 Text data is stored with text endings (i.e., network- 2295 normal line endings). These should be converted to native line 2296 endings by the receiving software. 2298 5.10. Trust Packet (Tag 12) 2300 The Trust packet is used only within keyrings and is not normally 2301 exported. Trust packets contain data that record the user's 2302 specifications of which key holders are trustworthy introducers, 2303 along with other information that implementing software uses for 2304 trust information. The format of Trust packets is defined by a given 2305 implementation. 2307 Trust packets SHOULD NOT be emitted to output streams that are 2308 transferred to other users, and they SHOULD be ignored on any input 2309 other than local keyring files. 2311 5.11. User ID Packet (Tag 13) 2313 A User ID packet consists of UTF-8 text that is intended to represent 2314 the name and email address of the key holder. By convention, it 2315 includes an [RFC2822] mail name-addr, but there are no restrictions 2316 on its content. The packet length in the header specifies the length 2317 of the User ID. 2319 5.12. User Attribute Packet (Tag 17) 2321 The User Attribute packet is a variation of the User ID packet. It 2322 is capable of storing more types of data than the User ID packet, 2323 which is limited to text. Like the User ID packet, a User Attribute 2324 packet may be certified by the key owner ("self-signed") or any other 2325 key owner who cares to certify it. Except as noted, a User Attribute 2326 packet may be used anywhere that a User ID packet may be used. 2328 While User Attribute packets are not a required part of the OpenPGP 2329 standard, implementations SHOULD provide at least enough 2330 compatibility to properly handle a certification signature on the 2331 User Attribute packet. A simple way to do this is by treating the 2332 User Attribute packet as a User ID packet with opaque contents, but 2333 an implementation may use any method desired. 2335 The User Attribute packet is made up of one or more attribute 2336 subpackets. Each subpacket consists of a subpacket header and a 2337 body. The header consists of: 2339 * the subpacket length (1, 2, or 5 octets) 2341 * the subpacket type (1 octet) 2342 and is followed by the subpacket specific data. 2344 The only currently defined subpacket type is 1, signifying an image. 2345 An implementation SHOULD ignore any subpacket of a type that it does 2346 not recognize. Subpacket types 100 through 110 are reserved for 2347 private or experimental use. 2349 5.12.1. The Image Attribute Subpacket 2351 The Image Attribute subpacket is used to encode an image, presumably 2352 (but not required to be) that of the key owner. 2354 The Image Attribute subpacket begins with an image header. The first 2355 two octets of the image header contain the length of the image 2356 header. Note that unlike other multi-octet numerical values in this 2357 document, due to a historical accident this value is encoded as a 2358 little-endian number. The image header length is followed by a 2359 single octet for the image header version. The only currently 2360 defined version of the image header is 1, which is a 16-octet image 2361 header. The first three octets of a version 1 image header are thus 2362 0x10, 0x00, 0x01. 2364 The fourth octet of a version 1 image header designates the encoding 2365 format of the image. The only currently defined encoding format is 2366 the value 1 to indicate JPEG. Image format types 100 through 110 are 2367 reserved for private or experimental use. The rest of the version 1 2368 image header is made up of 12 reserved octets, all of which MUST be 2369 set to 0. 2371 The rest of the image subpacket contains the image itself. As the 2372 only currently defined image type is JPEG, the image is encoded in 2373 the JPEG File Interchange Format (JFIF), a standard file format for 2374 JPEG images [JFIF]. 2376 An implementation MAY try to determine the type of an image by 2377 examination of the image data if it is unable to handle a particular 2378 version of the image header or if a specified encoding format value 2379 is not recognized. 2381 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) 2383 The Symmetrically Encrypted Integrity Protected Data packet is a 2384 variant of the Symmetrically Encrypted Data packet. It is a new 2385 feature created for OpenPGP that addresses the problem of detecting a 2386 modification to encrypted data. It is used in combination with a 2387 Modification Detection Code packet. 2389 There is a corresponding feature in the features Signature subpacket 2390 that denotes that an implementation can properly use this packet 2391 type. An implementation MUST support decrypting these packets and 2392 SHOULD prefer generating them to the older Symmetrically Encrypted 2393 Data packet when possible. Since this data packet protects against 2394 modification attacks, this standard encourages its proliferation. 2395 While blanket adoption of this data packet would create 2396 interoperability problems, rapid adoption is nevertheless important. 2397 An implementation SHOULD specifically denote support for this packet, 2398 but it MAY infer it from other mechanisms. 2400 For example, an implementation might infer from the use of a cipher 2401 such as Advanced Encryption Standard (AES) or Twofish that a user 2402 supports this feature. It might place in the unhashed portion of 2403 another user's key signature a Features subpacket. It might also 2404 present a user with an opportunity to regenerate their own self- 2405 signature with a Features subpacket. 2407 This packet contains data encrypted with a symmetric-key algorithm 2408 and protected against modification by the SHA-1 hash algorithm. When 2409 it has been decrypted, it will typically contain other packets (often 2410 a Literal Data packet or Compressed Data packet). The last decrypted 2411 packet in this packet's payload MUST be a Modification Detection Code 2412 packet. 2414 The body of this packet consists of: 2416 * A one-octet version number. The only currently defined value is 2417 1. 2419 * Encrypted data, the output of the selected symmetric-key cipher 2420 operating in Cipher Feedback mode with shift amount equal to the 2421 block size of the cipher (CFB-n where n is the block size). 2423 The symmetric cipher used MUST be specified in a Public-Key or 2424 Symmetric-Key Encrypted Session Key packet that precedes the 2425 Symmetrically Encrypted Data packet. In either case, the cipher 2426 algorithm octet is prefixed to the session key before it is 2427 encrypted. 2429 The data is encrypted in CFB mode, with a CFB shift size equal to the 2430 cipher's block size. The Initial Vector (IV) is specified as all 2431 zeros. Instead of using an IV, OpenPGP prefixes an octet string to 2432 the data before it is encrypted. The length of the octet string 2433 equals the block size of the cipher in octets, plus two. The first 2434 octets in the group, of length equal to the block size of the cipher, 2435 are random; the last two octets are each copies of their 2nd 2436 preceding octet. For example, with a cipher whose block size is 128 2437 bits or 16 octets, the prefix data will contain 16 random octets, 2438 then two more octets, which are copies of the 15th and 16th octets, 2439 respectively. Unlike the Symmetrically Encrypted Data Packet, no 2440 special CFB resynchronization is done after encrypting this prefix 2441 data. See Section 13.9 for more details. 2443 The repetition of 16 bits in the random data prefixed to the message 2444 allows the receiver to immediately check whether the session key is 2445 incorrect. 2447 The plaintext of the data to be encrypted is passed through the SHA-1 2448 hash function, and the result of the hash is appended to the 2449 plaintext in a Modification Detection Code packet. The input to the 2450 hash function includes the prefix data described above; it includes 2451 all of the plaintext, and then also includes two octets of values 2452 0xD3, 0x14. These represent the encoding of a Modification Detection 2453 Code packet tag and length field of 20 octets. 2455 The resulting hash value is stored in a Modification Detection Code 2456 (MDC) packet, which MUST use the two octet encoding just given to 2457 represent its tag and length field. The body of the MDC packet is 2458 the 20-octet output of the SHA-1 hash. 2460 The Modification Detection Code packet is appended to the plaintext 2461 and encrypted along with the plaintext using the same CFB context. 2463 During decryption, the plaintext data should be hashed with SHA-1, 2464 including the prefix data as well as the packet tag and length field 2465 of the Modification Detection Code packet. The body of the MDC 2466 packet, upon decryption, is compared with the result of the SHA-1 2467 hash. 2469 Any failure of the MDC indicates that the message has been modified 2470 and MUST be treated as a security problem. Failures include a 2471 difference in the hash values, but also the absence of an MDC packet, 2472 or an MDC packet in any position other than the end of the plaintext. 2473 Any failure SHOULD be reported to the user. 2475 Note: future designs of new versions of this packet should consider 2476 rollback attacks since it will be possible for an attacker to change 2477 the version back to 1. 2479 NON-NORMATIVE EXPLANATION 2481 The MDC system, as packets 18 and 19 are called, were created to 2482 provide an integrity mechanism that is less strong than a 2483 signature, yet stronger than bare CFB encryption. 2485 It is a limitation of CFB encryption that damage to the ciphertext 2486 will corrupt the affected cipher blocks and the block following. 2487 Additionally, if data is removed from the end of a CFB-encrypted 2488 block, that removal is undetectable. (Note also that CBC mode has 2489 a similar limitation, but data removed from the front of the block 2490 is undetectable.) 2492 The obvious way to protect or authenticate an encrypted block is 2493 to digitally sign it. However, many people do not wish to 2494 habitually sign data, for a large number of reasons beyond the 2495 scope of this document. Suffice it to say that many people 2496 consider properties such as deniability to be as valuable as 2497 integrity. 2499 OpenPGP addresses this desire to have more security than raw 2500 encryption and yet preserve deniability with the MDC system. An 2501 MDC is intentionally not a MAC. Its name was not selected by 2502 accident. It is analogous to a checksum. 2504 Despite the fact that it is a relatively modest system, it has 2505 proved itself in the real world. It is an effective defense to 2506 several attacks that have surfaced since it has been created. It 2507 has met its modest goals admirably. 2509 Consequently, because it is a modest security system, it has 2510 modest requirements on the hash function(s) it employs. It does 2511 not rely on a hash function being collision-free, it relies on a 2512 hash function being one-way. If a forger, Frank, wishes to send 2513 Alice a (digitally) unsigned message that says, "I've always 2514 secretly loved you, signed Bob", it is far easier for him to 2515 construct a new message than it is to modify anything intercepted 2516 from Bob. (Note also that if Bob wishes to communicate secretly 2517 with Alice, but without authentication or identification and with 2518 a threat model that includes forgers, he has a problem that 2519 transcends mere cryptography.) 2521 Note also that unlike nearly every other OpenPGP subsystem, there 2522 are no parameters in the MDC system. It hard-defines SHA-1 as its 2523 hash function. This is not an accident. It is an intentional 2524 choice to avoid downgrade and cross-grade attacks while making a 2525 simple, fast system. (A downgrade attack would be an attack that 2526 replaced SHA2-256 with SHA-1, for example. A cross-grade attack 2527 would replace SHA-1 with another 160-bit hash, such as RIPE- 2528 MD/160, for example.) 2530 However, given the present state of hash function cryptanalysis 2531 and cryptography, it may be desirable to upgrade the MDC system to 2532 a new hash function. See Section 13.11 for guidance. 2534 5.14. Modification Detection Code Packet (Tag 19) 2536 The Modification Detection Code packet contains a SHA-1 hash of 2537 plaintext data, which is used to detect message modification. It is 2538 only used with a Symmetrically Encrypted Integrity Protected Data 2539 packet. The Modification Detection Code packet MUST be the last 2540 packet in the plaintext data that is encrypted in the Symmetrically 2541 Encrypted Integrity Protected Data packet, and MUST appear in no 2542 other place. 2544 A Modification Detection Code packet MUST have a length of 20 octets. 2546 The body of this packet consists of: 2548 * A 20-octet SHA-1 hash of the preceding plaintext data of the 2549 Symmetrically Encrypted Integrity Protected Data packet, including 2550 prefix data, the tag octet, and length octet of the Modification 2551 Detection Code packet. 2553 Note that the Modification Detection Code packet MUST always use a 2554 new format encoding of the packet tag, and a one-octet encoding of 2555 the packet length. The reason for this is that the hashing rules for 2556 modification detection include a one-octet tag and one-octet length 2557 in the data hash. While this is a bit restrictive, it reduces 2558 complexity. 2560 6. Radix-64 Conversions 2562 As stated in the introduction, OpenPGP's underlying native 2563 representation for objects is a stream of arbitrary octets, and some 2564 systems desire these objects to be immune to damage caused by 2565 character set translation, data conversions, etc. 2567 In principle, any printable encoding scheme that met the requirements 2568 of the unsafe channel would suffice, since it would not change the 2569 underlying binary bit streams of the native OpenPGP data structures. 2570 The OpenPGP standard specifies one such printable encoding scheme to 2571 ensure interoperability. 2573 OpenPGP's Radix-64 encoding is composed of two parts: a base64 2574 encoding of the binary data and a checksum. The base64 encoding is 2575 identical to the MIME base64 content-transfer-encoding [RFC2045]. 2577 The checksum is a 24-bit Cyclic Redundancy Check (CRC) converted to 2578 four characters of radix-64 encoding by the same MIME base64 2579 transformation, preceded by an equal sign (=). The CRC is computed 2580 by using the generator 0x864CFB and an initialization of 0xB704CE. 2581 The accumulation is done on the data before it is converted to radix- 2582 64, rather than on the converted data. A sample implementation of 2583 this algorithm is in the next section. 2585 The checksum with its leading equal sign MAY appear on the first line 2586 after the base64 encoded data. 2588 Rationale for CRC-24: The size of 24 bits fits evenly into printable 2589 base64. The nonzero initialization can detect more errors than a 2590 zero initialization. 2592 6.1. An Implementation of the CRC-24 in "C" 2594 #define CRC24_INIT 0xB704CEL 2595 #define CRC24_POLY 0x1864CFBL 2597 typedef long crc24; 2598 crc24 crc_octets(unsigned char *octets, size_t len) 2599 { 2600 crc24 crc = CRC24_INIT; 2601 int i; 2602 while (len--) { 2603 crc ^= (*octets++) << 16; 2604 for (i = 0; i < 8; i++) { 2605 crc <<= 1; 2606 if (crc & 0x1000000) 2607 crc ^= CRC24_POLY; 2608 } 2609 } 2610 return crc & 0xFFFFFFL; 2611 } 2613 6.2. Forming ASCII Armor 2615 When OpenPGP encodes data into ASCII Armor, it puts specific headers 2616 around the Radix-64 encoded data, so OpenPGP can reconstruct the data 2617 later. An OpenPGP implementation MAY use ASCII armor to protect raw 2618 binary data. OpenPGP informs the user what kind of data is encoded 2619 in the ASCII armor through the use of the headers. 2621 Concatenating the following data creates ASCII Armor: 2623 * An Armor Header Line, appropriate for the type of data 2624 * Armor Headers 2626 * A blank line 2628 * The ASCII-Armored data 2630 * An Armor Checksum 2632 * The Armor Tail, which depends on the Armor Header Line 2634 An Armor Header Line consists of the appropriate header line text 2635 surrounded by five (5) dashes ("-", 0x2D) on either side of the 2636 header line text. The header line text is chosen based upon the type 2637 of data that is being encoded in Armor, and how it is being encoded. 2638 Header line texts include the following strings: 2640 BEGIN PGP MESSAGE 2641 Used for signed, encrypted, or compressed files. 2643 BEGIN PGP PUBLIC KEY BLOCK 2644 Used for armoring public keys. 2646 BEGIN PGP PRIVATE KEY BLOCK 2647 Used for armoring private keys. 2649 BEGIN PGP MESSAGE, PART X/Y 2650 Used for multi-part messages, where the armor is split amongst Y 2651 parts, and this is the Xth part out of Y. 2653 BEGIN PGP MESSAGE, PART X 2654 Used for multi-part messages, where this is the Xth part of an 2655 unspecified number of parts. Requires the MESSAGE-ID Armor Header 2656 to be used. 2658 BEGIN PGP SIGNATURE 2659 Used for detached signatures, OpenPGP/MIME signatures, and 2660 cleartext signatures. Note that PGP 2 uses BEGIN PGP MESSAGE for 2661 detached signatures. 2663 Note that all these Armor Header Lines are to consist of a complete 2664 line. That is to say, there is always a line ending preceding the 2665 starting five dashes, and following the ending five dashes. The 2666 header lines, therefore, MUST start at the beginning of a line, and 2667 MUST NOT have text other than whitespace -- space (0x20), tab (0x09) 2668 or carriage return (0x0d) -- following them on the same line. These 2669 line endings are considered a part of the Armor Header Line for the 2670 purposes of determining the content they delimit. This is 2671 particularly important when computing a cleartext signature (see 2672 below). 2674 The Armor Headers are pairs of strings that can give the user or the 2675 receiving OpenPGP implementation some information about how to decode 2676 or use the message. The Armor Headers are a part of the armor, not a 2677 part of the message, and hence are not protected by any signatures 2678 applied to the message. 2680 The format of an Armor Header is that of a key-value pair. A colon 2681 (":" 0x38) and a single space (0x20) separate the key and value. 2682 OpenPGP should consider improperly formatted Armor Headers to be 2683 corruption of the ASCII Armor. Unknown keys should be reported to 2684 the user, but OpenPGP should continue to process the message. 2686 Note that some transport methods are sensitive to line length. While 2687 there is a limit of 76 characters for the Radix-64 data 2688 (Section 6.3), there is no limit to the length of Armor Headers. 2689 Care should be taken that the Armor Headers are short enough to 2690 survive transport. One way to do this is to repeat an Armor Header 2691 Key multiple times with different values for each so that no one line 2692 is overly long. 2694 Currently defined Armor Header Keys are as follows: 2696 * "Version", which states the OpenPGP implementation and version 2697 used to encode the message. 2699 * "Comment", a user-defined comment. OpenPGP defines all text to be 2700 in UTF-8. A comment may be any UTF-8 string. However, the whole 2701 point of armoring is to provide seven-bit-clean data. 2702 Consequently, if a comment has characters that are outside the US- 2703 ASCII range of UTF, they may very well not survive transport. 2705 * "MessageID", a 32-character string of printable characters. The 2706 string must be the same for all parts of a multi-part message that 2707 uses the "PART X" Armor Header. MessageID strings should be 2708 unique enough that the recipient of the mail can associate all the 2709 parts of a message with each other. A good checksum or 2710 cryptographic hash function is sufficient. 2712 The MessageID SHOULD NOT appear unless it is in a multi-part 2713 message. If it appears at all, it MUST be computed from the 2714 finished (encrypted, signed, etc.) message in a deterministic 2715 fashion, rather than contain a purely random value. This is to 2716 allow the legitimate recipient to determine that the MessageID 2717 cannot serve as a covert means of leaking cryptographic key 2718 information. 2720 * "Hash", a comma-separated list of hash algorithms used in this 2721 message. This is used only in cleartext signed messages. 2723 * "Charset", a description of the character set that the plaintext 2724 is in. Please note that OpenPGP defines text to be in UTF-8. An 2725 implementation will get best results by translating into and out 2726 of UTF-8. However, there are many instances where this is easier 2727 said than done. Also, there are communities of users who have no 2728 need for UTF-8 because they are all happy with a character set 2729 like ISO Latin-5 or a Japanese character set. In such instances, 2730 an implementation MAY override the UTF-8 default by using this 2731 header key. An implementation MAY implement this key and any 2732 translations it cares to; an implementation MAY ignore it and 2733 assume all text is UTF-8. 2735 The blank line can either be zero-length or contain only whitespace, 2736 that is spaces (0x20), tabs (0x09) or carriage returns (0x0d). 2738 The Armor Tail Line is composed in the same manner as the Armor 2739 Header Line, except the string "BEGIN" is replaced by the string 2740 "END". 2742 6.3. Encoding Binary in Radix-64 2744 The encoding process represents 24-bit groups of input bits as output 2745 strings of 4 encoded characters. Proceeding from left to right, a 2746 24-bit input group is formed by concatenating three 8-bit input 2747 groups. These 24 bits are then treated as four concatenated 6-bit 2748 groups, each of which is translated into a single digit in the 2749 Radix-64 alphabet. When encoding a bit stream with the Radix-64 2750 encoding, the bit stream must be presumed to be ordered with the most 2751 significant bit first. That is, the first bit in the stream will be 2752 the high-order bit in the first 8-bit octet, and the eighth bit will 2753 be the low-order bit in the first 8-bit octet, and so on. 2755 ┌──first octet──┬─second octet──┬──third octet──┐ 2756 │7 6 5 4 3 2 1 0│7 6 5 4 3 2 1 0│7 6 5 4 3 2 1 0│ 2757 ├───────────┬───┴───────┬───────┴───┬───────────┤ 2758 │5 4 3 2 1 0│5 4 3 2 1 0│5 4 3 2 1 0│5 4 3 2 1 0│ 2759 └──1.index──┴──2.index──┴──3.index──┴──4.index──┘ 2760 Each 6-bit group is used as an index into an array of 64 printable 2761 characters from the table below. The character referenced by the 2762 index is placed in the output string. 2764 +=====+========++=====+=========++=====+==========++=====+==========+ 2765 |Value|Encoding||Value|Encoding ||Value| Encoding ||Value| Encoding | 2766 +=====+========++=====+=========++=====+==========++=====+==========+ 2767 | 0|A || 17|R || 34| i || 51| z | 2768 +-----+--------++-----+---------++-----+----------++-----+----------+ 2769 | 1|B || 18|S || 35| j || 52| 0 | 2770 +-----+--------++-----+---------++-----+----------++-----+----------+ 2771 | 2|C || 19|T || 36| k || 53| 1 | 2772 +-----+--------++-----+---------++-----+----------++-----+----------+ 2773 | 3|D || 20|U || 37| l || 54| 2 | 2774 +-----+--------++-----+---------++-----+----------++-----+----------+ 2775 | 4|E || 21|V || 38| m || 55| 3 | 2776 +-----+--------++-----+---------++-----+----------++-----+----------+ 2777 | 5|F || 22|W || 39| n || 56| 4 | 2778 +-----+--------++-----+---------++-----+----------++-----+----------+ 2779 | 6|G || 23|X || 40| o || 57| 5 | 2780 +-----+--------++-----+---------++-----+----------++-----+----------+ 2781 | 7|H || 24|Y || 41| p || 58| 6 | 2782 +-----+--------++-----+---------++-----+----------++-----+----------+ 2783 | 8|I || 25|Z || 42| q || 59| 7 | 2784 +-----+--------++-----+---------++-----+----------++-----+----------+ 2785 | 9|J || 26|a || 43| r || 60| 8 | 2786 +-----+--------++-----+---------++-----+----------++-----+----------+ 2787 | 10|K || 27|b || 44| s || 61| 9 | 2788 +-----+--------++-----+---------++-----+----------++-----+----------+ 2789 | 11|L || 28|c || 45| t || 62| + | 2790 +-----+--------++-----+---------++-----+----------++-----+----------+ 2791 | 12|M || 29|d || 46| u || 63| / | 2792 +-----+--------++-----+---------++-----+----------++-----+----------+ 2793 | 13|N || 30|e || 47| v || | | 2794 +-----+--------++-----+---------++-----+----------++-----+----------+ 2795 | 14|O || 31|f || 48| w ||(pad)| = | 2796 +-----+--------++-----+---------++-----+----------++-----+----------+ 2797 | 15|P || 32|g || 49| x || | | 2798 +-----+--------++-----+---------++-----+----------++-----+----------+ 2799 | 16|Q || 33|h || 50| y || | | 2800 +-----+--------++-----+---------++-----+----------++-----+----------+ 2802 Table 12: Encoding for Radix-64 2804 The encoded output stream must be represented in lines of no more 2805 than 76 characters each. 2807 Special processing is performed if fewer than 24 bits are available 2808 at the end of the data being encoded. There are three possibilities: 2810 1. The last data group has 24 bits (3 octets). No special 2811 processing is needed. 2813 2. The last data group has 16 bits (2 octets). The first two 6-bit 2814 groups are processed as above. The third (incomplete) data group 2815 has two zero-value bits added to it, and is processed as above. 2816 A pad character (=) is added to the output. 2818 3. The last data group has 8 bits (1 octet). The first 6-bit group 2819 is processed as above. The second (incomplete) data group has 2820 four zero-value bits added to it, and is processed as above. Two 2821 pad characters (=) are added to the output. 2823 6.4. Decoding Radix-64 2825 In Radix-64 data, characters other than those in the table, line 2826 breaks, and other white space probably indicate a transmission error, 2827 about which a warning message or even a message rejection might be 2828 appropriate under some circumstances. Decoding software must ignore 2829 all white space. 2831 Because it is used only for padding at the end of the data, the 2832 occurrence of any "=" characters may be taken as evidence that the 2833 end of the data has been reached (without truncation in transit). No 2834 such assurance is possible, however, when the number of octets 2835 transmitted was a multiple of three and no "=" characters are 2836 present. 2838 6.5. Examples of Radix-64 2839 Input data: 0x14FB9C03D97E 2840 Hex: 1 4 F B 9 C | 0 3 D 9 7 E 2841 8-bit: 00010100 11111011 10011100 | 00000011 11011001 01111110 2842 6-bit: 000101 001111 101110 011100 | 000000 111101 100101 111110 2843 Decimal: 5 15 46 28 0 61 37 62 2844 Output: F P u c A 9 l + 2845 Input data: 0x14FB9C03D9 2846 Hex: 1 4 F B 9 C | 0 3 D 9 2847 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2848 pad with 00 2849 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2850 Decimal: 5 15 46 28 0 61 36 2851 pad with = 2852 Output: F P u c A 9 k = 2853 Input data: 0x14FB9C03 2854 Hex: 1 4 F B 9 C | 0 3 2855 8-bit: 00010100 11111011 10011100 | 00000011 2856 pad with 0000 2857 6-bit: 000101 001111 101110 011100 | 000000 110000 2858 Decimal: 5 15 46 28 0 48 2859 pad with = = 2860 Output: F P u c A w = = 2862 6.6. Example of an ASCII Armored Message 2864 -----BEGIN PGP MESSAGE----- 2865 Version: OpenPrivacy 0.99 2867 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2868 vBSFjNSiVHsuAA== 2869 =njUN 2870 -----END PGP MESSAGE----- 2872 Note that this example has extra indenting; an actual armored message 2873 would have no leading whitespace. 2875 7. Cleartext Signature Framework 2877 It is desirable to be able to sign a textual octet stream without 2878 ASCII armoring the stream itself, so the signed text is still 2879 readable without special software. In order to bind a signature to 2880 such a cleartext, this framework is used. (Note that this framework 2881 is not intended to be reversible. [RFC3156] defines another way to 2882 sign cleartext messages for environments that support MIME.) 2884 The cleartext signed message consists of: 2886 * The cleartext header "-----BEGIN PGP SIGNED MESSAGE-----" on a 2887 single line, 2889 * One or more "Hash" Armor Headers, 2891 * Exactly one blank line not included into the message digest, 2893 * The dash-escaped cleartext that is included into the message 2894 digest, 2896 * The ASCII armored signature(s) including the "-----BEGIN PGP 2897 SIGNATURE-----" Armor Header and Armor Tail Lines. 2899 If the "Hash" Armor Header is given, the specified message digest 2900 algorithm(s) are used for the signature. If there are no such 2901 headers, MD5 is used. If MD5 is the only hash used, then an 2902 implementation MAY omit this header for improved V2.x compatibility. 2903 If more than one message digest is used in the signature, the "Hash" 2904 armor header contains a comma-delimited list of used message digests. 2906 Current message digest names are described below with the algorithm 2907 IDs. 2909 An implementation SHOULD add a line break after the cleartext, but 2910 MAY omit it if the cleartext ends with a line break. This is for 2911 visual clarity. 2913 7.1. Dash-Escaped Text 2915 The cleartext content of the message must also be dash-escaped. 2917 Dash-escaped cleartext is the ordinary cleartext where every line 2918 starting with a dash "-" (0x2D) is prefixed by the sequence dash "-" 2919 (0x2D) and space ` ` (0x20). This prevents the parser from 2920 recognizing armor headers of the cleartext itself. An implementation 2921 MAY dash-escape any line, SHOULD dash-escape lines commencing "From" 2922 followed by a space, and MUST dash-escape any line commencing in a 2923 dash. The message digest is computed using the cleartext itself, not 2924 the dash-escaped form. 2926 As with binary signatures on text documents, a cleartext signature is 2927 calculated on the text using canonical line endings. The 2928 line ending (i.e., the ) before the "-----BEGIN PGP 2929 SIGNATURE-----" line that terminates the signed text is not 2930 considered part of the signed text. 2932 When reversing dash-escaping, an implementation MUST strip the string 2933 "-" if it occurs at the beginning of a line, and SHOULD warn on "-" 2934 and any character other than a space at the beginning of a line. 2936 Also, any trailing whitespace -- spaces (0x20), tabs (0x09) or 2937 carriage returns (0x0d) -- at the end of any line is removed when the 2938 cleartext signature is generated and verified. 2940 8. Regular Expressions 2942 A regular expression is zero or more branches, separated by "|". It 2943 matches anything that matches one of the branches. 2945 A branch is zero or more pieces, concatenated. It matches a match 2946 for the first, followed by a match for the second, etc. 2948 A piece is an atom possibly followed by "*", "+", or "?". An atom 2949 followed by "*" matches a sequence of 0 or more matches of the atom. 2950 An atom followed by "+" matches a sequence of 1 or more matches of 2951 the atom. An atom followed by "?" matches a match of the atom, or 2952 the null string. 2954 An atom is a regular expression in parentheses (matching a match for 2955 the regular expression), a range (see below), "." (matching any 2956 single character), "^" (matching the null string at the beginning of 2957 the input string), "$" (matching the null string at the end of the 2958 input string), a "\" followed by a single character (matching that 2959 character), or a single character with no other significance 2960 (matching that character). 2962 A range is a sequence of characters enclosed in "[]". It normally 2963 matches any single character from the sequence. If the sequence 2964 begins with "^", it matches any single character not from the rest of 2965 the sequence. If two characters in the sequence are separated by 2966 "-", this is shorthand for the full list of ASCII characters between 2967 them (e.g., "[0-9]" matches any decimal digit). To include a literal 2968 "]" in the sequence, make it the first character (following a 2969 possible "^"). To include a literal "-", make it the first or last 2970 character. 2972 9. Constants 2974 This section describes the constants used in OpenPGP. 2976 Note that these tables are not exhaustive lists; an implementation 2977 MAY implement an algorithm not on these lists, so long as the 2978 algorithm numbers are chosen from the private or experimental 2979 algorithm range. 2981 See Section 13 for more discussion of the algorithms. 2983 9.1. Public-Key Algorithms 2985 +========+===================================================+ 2986 | ID | Algorithm | 2987 +========+===================================================+ 2988 | 1 | RSA (Encrypt or Sign) [HAC] | 2989 +--------+---------------------------------------------------+ 2990 | 2 | RSA Encrypt-Only [HAC] | 2991 +--------+---------------------------------------------------+ 2992 | 3 | RSA Sign-Only [HAC] | 2993 +--------+---------------------------------------------------+ 2994 | 16 | Elgamal (Encrypt-Only) [ELGAMAL] [HAC] | 2995 +--------+---------------------------------------------------+ 2996 | 17 | DSA (Digital Signature Algorithm) [FIPS186] [HAC] | 2997 +--------+---------------------------------------------------+ 2998 | 18 | Reserved for Elliptic Curve | 2999 +--------+---------------------------------------------------+ 3000 | 19 | Reserved for ECDSA | 3001 +--------+---------------------------------------------------+ 3002 | 20 | Reserved (formerly Elgamal Encrypt or Sign) | 3003 +--------+---------------------------------------------------+ 3004 | 21 | Reserved for Diffie-Hellman (X9.42, as defined | 3005 | | for IETF-S/MIME) | 3006 +--------+---------------------------------------------------+ 3007 | 100 to | Private/Experimental algorithm | 3008 | 110 | | 3009 +--------+---------------------------------------------------+ 3011 Table 13: Public-key algorithm registry 3013 Implementations MUST implement DSA for signatures, and Elgamal for 3014 encryption. Implementations SHOULD implement RSA keys (1). RSA 3015 Encrypt-Only (2) and RSA Sign-Only (3) are deprecated and SHOULD NOT 3016 be generated, but may be interpreted. See Section 13.5. See 3017 Section 13.8 for notes on Elliptic Curve (18), ECDSA (19), Elgamal 3018 Encrypt or Sign (20), and X9.42 (21). Implementations MAY implement 3019 any other algorithm. 3021 9.2. Symmetric-Key Algorithms 3023 +========+=======================================+ 3024 | ID | Algorithm | 3025 +========+=======================================+ 3026 | 0 | Plaintext or unencrypted data | 3027 +--------+---------------------------------------+ 3028 | 1 | IDEA [IDEA] | 3029 +--------+---------------------------------------+ 3030 | 2 | TripleDES (DES-EDE, [SCHNEIER], [HAC] | 3031 | | - 168 bit key derived from 192) | 3032 +--------+---------------------------------------+ 3033 | 3 | CAST5 (128 bit key, as per [RFC2144]) | 3034 +--------+---------------------------------------+ 3035 | 4 | Blowfish (128 bit key, 16 rounds) | 3036 | | [BLOWFISH] | 3037 +--------+---------------------------------------+ 3038 | 5 | Reserved | 3039 +--------+---------------------------------------+ 3040 | 6 | Reserved | 3041 +--------+---------------------------------------+ 3042 | 7 | AES with 128-bit key [AES] | 3043 +--------+---------------------------------------+ 3044 | 8 | AES with 192-bit key | 3045 +--------+---------------------------------------+ 3046 | 9 | AES with 256-bit key | 3047 +--------+---------------------------------------+ 3048 | 10 | Twofish with 256-bit key [TWOFISH] | 3049 +--------+---------------------------------------+ 3050 | 11 | Camellia with 128-bit key [RFC3713] | 3051 +--------+---------------------------------------+ 3052 | 12 | Camellia with 192-bit key | 3053 +--------+---------------------------------------+ 3054 | 13 | Camellia with 256-bit key | 3055 +--------+---------------------------------------+ 3056 | 100 to | Private/Experimental algorithm | 3057 | 110 | | 3058 +--------+---------------------------------------+ 3060 Table 14: Symmetric-key algorithm registry 3062 Implementations MUST implement TripleDES. Implementations SHOULD 3063 implement AES-128 and CAST5. Implementations that interoperate with 3064 PGP 2.6 or earlier need to support IDEA, as that is the only 3065 symmetric cipher those versions use. Implementations MAY implement 3066 any other algorithm. 3068 9.3. Compression Algorithms 3070 +============+================================+ 3071 | ID | Algorithm | 3072 +============+================================+ 3073 | 0 | Uncompressed | 3074 +------------+--------------------------------+ 3075 | 1 | ZIP [RFC1951] | 3076 +------------+--------------------------------+ 3077 | 2 | ZLIB [RFC1950] | 3078 +------------+--------------------------------+ 3079 | 3 | BZip2 [BZ2] | 3080 +------------+--------------------------------+ 3081 | 100 to 110 | Private/Experimental algorithm | 3082 +------------+--------------------------------+ 3084 Table 15: Compression algorithm registry 3086 Implementations MUST implement uncompressed data. Implementations 3087 SHOULD implement ZIP. Implementations MAY implement any other 3088 algorithm. 3090 9.4. Hash Algorithms 3092 +============+================================+=============+ 3093 | ID | Algorithm | Text Name | 3094 +============+================================+=============+ 3095 | 1 | MD5 [HAC] | "MD5" | 3096 +------------+--------------------------------+-------------+ 3097 | 2 | SHA-1 [FIPS180] | "SHA1" | 3098 +------------+--------------------------------+-------------+ 3099 | 3 | RIPE-MD/160 [HAC] | "RIPEMD160" | 3100 +------------+--------------------------------+-------------+ 3101 | 4 | Reserved | | 3102 +------------+--------------------------------+-------------+ 3103 | 5 | Reserved | | 3104 +------------+--------------------------------+-------------+ 3105 | 6 | Reserved | | 3106 +------------+--------------------------------+-------------+ 3107 | 7 | Reserved | | 3108 +------------+--------------------------------+-------------+ 3109 | 8 | SHA2-256 [FIPS180] | "SHA256" | 3110 +------------+--------------------------------+-------------+ 3111 | 9 | SHA2-384 [FIPS180] | "SHA384" | 3112 +------------+--------------------------------+-------------+ 3113 | 10 | SHA2-512 [FIPS180] | "SHA512" | 3114 +------------+--------------------------------+-------------+ 3115 | 11 | SHA2-224 [FIPS180] | "SHA224" | 3116 +------------+--------------------------------+-------------+ 3117 | 100 to 110 | Private/Experimental algorithm | | 3118 +------------+--------------------------------+-------------+ 3120 Table 16: Hash algorithm registry 3122 Implementations MUST implement SHA-1. Implementations MAY implement 3123 other algorithms. MD5 is deprecated. 3125 10. IANA Considerations 3127 OpenPGP is highly parameterized, and consequently there are a number 3128 of considerations for allocating parameters for extensions. This 3129 section describes how IANA should look at extensions to the protocol 3130 as described in this document. 3132 10.1. New String-to-Key Specifier Types 3134 OpenPGP S2K specifiers contain a mechanism for new algorithms to turn 3135 a string into a key. This specification creates a registry of S2K 3136 specifier types. The registry includes the S2K type, the name of the 3137 S2K, and a reference to the defining specification. The initial 3138 values for this registry can be found in Section 3.7.1. Adding a new 3139 S2K specifier MUST be done through the IETF CONSENSUS method, as 3140 described in [RFC2434]. 3142 10.2. New Packets 3144 Major new features of OpenPGP are defined through new packet types. 3145 This specification creates a registry of packet types. The registry 3146 includes the packet type, the name of the packet, and a reference to 3147 the defining specification. The initial values for this registry can 3148 be found in Section 4.3. Adding a new packet type MUST be done 3149 through the IETF CONSENSUS method, as described in [RFC2434]. 3151 10.2.1. User Attribute Types 3153 The User Attribute packet permits an extensible mechanism for other 3154 types of certificate identification. This specification creates a 3155 registry of User Attribute types. The registry includes the User 3156 Attribute type, the name of the User Attribute, and a reference to 3157 the defining specification. The initial values for this registry can 3158 be found in Section 5.12. Adding a new User Attribute type MUST be 3159 done through the IETF CONSENSUS method, as described in [RFC2434]. 3161 10.2.1.1. Image Format Subpacket Types 3163 Within User Attribute packets, there is an extensible mechanism for 3164 other types of image-based User Attributes. This specification 3165 creates a registry of Image Attribute subpacket types. The registry 3166 includes the Image Attribute subpacket type, the name of the Image 3167 Attribute subpacket, and a reference to the defining specification. 3168 The initial values for this registry can be found in Section 5.12.1. 3169 Adding a new Image Attribute subpacket type MUST be done through the 3170 IETF CONSENSUS method, as described in [RFC2434]. 3172 10.2.2. New Signature Subpackets 3174 OpenPGP signatures contain a mechanism for signed (or unsigned) data 3175 to be added to them for a variety of purposes in the Signature 3176 subpackets as discussed in Section 5.2.3.1. This specification 3177 creates a registry of Signature subpacket types. The registry 3178 includes the Signature subpacket type, the name of the subpacket, and 3179 a reference to the defining specification. The initial values for 3180 this registry can be found in Section 5.2.3.1. Adding a new 3181 Signature subpacket MUST be done through the IETF CONSENSUS method, 3182 as described in [RFC2434]. 3184 10.2.2.1. Signature Notation Data Subpackets 3186 OpenPGP signatures further contain a mechanism for extensions in 3187 signatures. These are the Notation Data subpackets, which contain a 3188 key/value pair. Notations contain a user space that is completely 3189 unmanaged and an IETF space. 3191 This specification creates a registry of Signature Notation Data 3192 types. The registry includes the Signature Notation Data type, the 3193 name of the Signature Notation Data, its allowed values, and a 3194 reference to the defining specification. The initial values for this 3195 registry can be found in Section 5.2.3.16. Adding a new Signature 3196 Notation Data subpacket MUST be done through the EXPERT REVIEW 3197 method, as described in [RFC2434]. 3199 10.2.2.2. Key Server Preference Extensions 3201 OpenPGP signatures contain a mechanism for preferences to be 3202 specified about key servers. This specification creates a registry 3203 of key server preferences. The registry includes the key server 3204 preference, the name of the preference, and a reference to the 3205 defining specification. The initial values for this registry can be 3206 found in Section 5.2.3.17. Adding a new key server preference MUST 3207 be done through the IETF CONSENSUS method, as described in [RFC2434]. 3209 10.2.2.3. Key Flags Extensions 3211 OpenPGP signatures contain a mechanism for flags to be specified 3212 about key usage. This specification creates a registry of key usage 3213 flags. The registry includes the key flags value, the name of the 3214 flag, and a reference to the defining specification. The initial 3215 values for this registry can be found in Section 5.2.3.21. Adding a 3216 new key usage flag MUST be done through the IETF CONSENSUS method, as 3217 described in [RFC2434]. 3219 10.2.2.4. Reason for Revocation Extensions 3221 OpenPGP signatures contain a mechanism for flags to be specified 3222 about why a key was revoked. This specification creates a registry 3223 of "Reason for Revocation" flags. The registry includes the "Reason 3224 for Revocation" flags value, the name of the flag, and a reference to 3225 the defining specification. The initial values for this registry can 3226 be found in Section 5.2.3.23. Adding a new feature flag MUST be done 3227 through the IETF CONSENSUS method, as described in [RFC2434]. 3229 10.2.2.5. Implementation Features 3231 OpenPGP signatures contain a mechanism for flags to be specified 3232 stating which optional features an implementation supports. This 3233 specification creates a registry of feature-implementation flags. 3234 The registry includes the feature-implementation flags value, the 3235 name of the flag, and a reference to the defining specification. The 3236 initial values for this registry can be found in Section 5.2.3.24. 3237 Adding a new feature-implementation flag MUST be done through the 3238 IETF CONSENSUS method, as described in [RFC2434]. 3240 Also see Section 13.12 for more information about when feature flags 3241 are needed. 3243 10.2.3. New Packet Versions 3245 The core OpenPGP packets all have version numbers, and can be revised 3246 by introducing a new version of an existing packet. This 3247 specification creates a registry of packet types. The registry 3248 includes the packet type, the number of the version, and a reference 3249 to the defining specification. The initial values for this registry 3250 can be found in Section 5. Adding a new packet version MUST be done 3251 through the IETF CONSENSUS method, as described in [RFC2434]. 3253 10.3. New Algorithms 3255 Section 9 lists the core algorithms that OpenPGP uses. Adding in a 3256 new algorithm is usually simple. For example, adding in a new 3257 symmetric cipher usually would not need anything more than allocating 3258 a constant for that cipher. If that cipher had other than a 64-bit 3259 or 128-bit block size, there might need to be additional 3260 documentation describing how OpenPGP-CFB mode would be adjusted. 3261 Similarly, when DSA was expanded from a maximum of 1024-bit public 3262 keys to 3072-bit public keys, the revision of FIPS 186 contained 3263 enough information itself to allow implementation. Changes to this 3264 document were made mainly for emphasis. 3266 10.3.1. Public-Key Algorithms 3268 OpenPGP specifies a number of public-key algorithms. This 3269 specification creates a registry of public-key algorithm identifiers. 3270 The registry includes the algorithm name, its key sizes and 3271 parameters, and a reference to the defining specification. The 3272 initial values for this registry can be found in Section 9.1. Adding 3273 a new public-key algorithm MUST be done through the IETF CONSENSUS 3274 method, as described in [RFC2434]. 3276 10.3.2. Symmetric-Key Algorithms 3278 OpenPGP specifies a number of symmetric-key algorithms. This 3279 specification creates a registry of symmetric-key algorithm 3280 identifiers. The registry includes the algorithm name, its key sizes 3281 and block size, and a reference to the defining specification. The 3282 initial values for this registry can be found in Section 9.2. Adding 3283 a new symmetric-key algorithm MUST be done through the IETF CONSENSUS 3284 method, as described in [RFC2434]. 3286 10.3.3. Hash Algorithms 3288 OpenPGP specifies a number of hash algorithms. This specification 3289 creates a registry of hash algorithm identifiers. The registry 3290 includes the algorithm name, a text representation of that name, its 3291 block size, an OID hash prefix, and a reference to the defining 3292 specification. The initial values for this registry can be found in 3293 Section 9.4 for the algorithm identifiers and text names, and 3294 Section 5.2.2 for the OIDs and expanded signature prefixes. Adding a 3295 new hash algorithm MUST be done through the IETF CONSENSUS method, as 3296 described in [RFC2434]. 3298 10.3.4. Compression Algorithms 3300 OpenPGP specifies a number of compression algorithms. This 3301 specification creates a registry of compression algorithm 3302 identifiers. The registry includes the algorithm name and a 3303 reference to the defining specification. The initial values for this 3304 registry can be found in Section 9.3. Adding a new compression key 3305 algorithm MUST be done through the IETF CONSENSUS method, as 3306 described in [RFC2434]. 3308 11. Packet Composition 3310 OpenPGP packets are assembled into sequences in order to create 3311 messages and to transfer keys. Not all possible packet sequences are 3312 meaningful and correct. This section describes the rules for how 3313 packets should be placed into sequences. 3315 11.1. Transferable Public Keys 3317 OpenPGP users may transfer public keys. The essential elements of a 3318 transferable public key are as follows: 3320 * One Public-Key packet 3322 * Zero or more revocation signatures 3324 * One or more User ID packets 3326 * After each User ID packet, zero or more Signature packets 3327 (certifications) 3329 * Zero or more User Attribute packets 3331 * After each User Attribute packet, zero or more Signature packets 3332 (certifications) 3334 * Zero or more Subkey packets 3336 * After each Subkey packet, one Signature packet, plus optionally a 3337 revocation 3339 The Public-Key packet occurs first. Each of the following User ID 3340 packets provides the identity of the owner of this public key. If 3341 there are multiple User ID packets, this corresponds to multiple 3342 means of identifying the same unique individual user; for example, a 3343 user may have more than one email address, and construct a User ID 3344 for each one. 3346 Immediately following each User ID packet, there are zero or more 3347 Signature packets. Each Signature packet is calculated on the 3348 immediately preceding User ID packet and the initial Public-Key 3349 packet. The signature serves to certify the corresponding public key 3350 and User ID. In effect, the signer is testifying to his or her 3351 belief that this public key belongs to the user identified by this 3352 User ID. 3354 Within the same section as the User ID packets, there are zero or 3355 more User Attribute packets. Like the User ID packets, a User 3356 Attribute packet is followed by zero or more Signature packets 3357 calculated on the immediately preceding User Attribute packet and the 3358 initial Public-Key packet. 3360 User Attribute packets and User ID packets may be freely intermixed 3361 in this section, so long as the signatures that follow them are 3362 maintained on the proper User Attribute or User ID packet. 3364 After the User ID packet or Attribute packet, there may be zero or 3365 more Subkey packets. In general, subkeys are provided in cases where 3366 the top-level public key is a signature-only key. However, any V4 3367 key may have subkeys, and the subkeys may be encryption-only keys, 3368 signature-only keys, or general-purpose keys. V3 keys MUST NOT have 3369 subkeys. 3371 Each Subkey packet MUST be followed by one Signature packet, which 3372 should be a subkey binding signature issued by the top-level key. 3373 For subkeys that can issue signatures, the subkey binding signature 3374 MUST contain an Embedded Signature subpacket with a primary key 3375 binding signature (0x19) issued by the subkey on the top-level key. 3377 Subkey and Key packets may each be followed by a revocation Signature 3378 packet to indicate that the key is revoked. Revocation signatures 3379 are only accepted if they are issued by the key itself, or by a key 3380 that is authorized to issue revocations via a Revocation Key 3381 subpacket in a self-signature by the top-level key. 3383 Transferable public-key packet sequences may be concatenated to allow 3384 transferring multiple public keys in one operation. 3386 11.2. Transferable Secret Keys 3388 OpenPGP users may transfer secret keys. The format of a transferable 3389 secret key is the same as a transferable public key except that 3390 secret-key and secret-subkey packets are used instead of the public 3391 key and public-subkey packets. Implementations SHOULD include self- 3392 signatures on any User IDs and subkeys, as this allows for a complete 3393 public key to be automatically extracted from the transferable secret 3394 key. Implementations MAY choose to omit the self-signatures, 3395 especially if a transferable public key accompanies the transferable 3396 secret key. 3398 11.3. OpenPGP Messages 3400 An OpenPGP message is a packet or sequence of packets that 3401 corresponds to the following grammatical rules (comma represents 3402 sequential composition, and vertical bar separates alternatives): 3404 OpenPGP Message :- Encrypted Message | Signed Message | Compressed 3405 Message | Literal Message. 3407 Compressed Message :- Compressed Data Packet. 3409 Literal Message :- Literal Data Packet. 3411 ESK :- Public-Key Encrypted Session Key Packet | Symmetric-Key 3412 Encrypted Session Key Packet. 3414 ESK Sequence :- ESK | ESK Sequence, ESK. 3416 Encrypted Data :- Symmetrically Encrypted Data Packet | 3417 Symmetrically Encrypted Integrity Protected Data Packet 3419 Encrypted Message :- Encrypted Data | ESK Sequence, Encrypted Data. 3421 One-Pass Signed Message :- One-Pass Signature Packet, OpenPGP 3422 Message, Corresponding Signature Packet. 3424 Signed Message :- Signature Packet, OpenPGP Message | One-Pass 3425 Signed Message. 3427 In addition, decrypting a Symmetrically Encrypted Data packet or a 3428 Symmetrically Encrypted Integrity Protected Data packet as well as 3429 decompressing a Compressed Data packet must yield a valid OpenPGP 3430 Message. 3432 11.4. Detached Signatures 3434 Some OpenPGP applications use so-called "detached signatures". For 3435 example, a program bundle may contain a file, and with it a second 3436 file that is a detached signature of the first file. These detached 3437 signatures are simply a Signature packet stored separately from the 3438 data for which they are a signature. 3440 12. Enhanced Key Formats 3442 12.1. Key Structures 3444 The format of an OpenPGP V3 key is as follows. Entries in square 3445 brackets are optional and ellipses indicate repetition. 3447 RSA Public Key 3448 [Revocation Self Signature] 3449 User ID [Signature ...] 3450 [User ID [Signature ...] ...] 3452 Each signature certifies the RSA public key and the preceding User 3453 ID. The RSA public key can have many User IDs and each User ID can 3454 have many signatures. V3 keys are deprecated. Implementations MUST 3455 NOT generate new V3 keys, but MAY continue to use existing ones. 3457 The format of an OpenPGP V4 key that uses multiple public keys is 3458 similar except that the other keys are added to the end as "subkeys" 3459 of the primary key. 3461 Primary-Key 3462 [Revocation Self Signature] 3463 [Direct Key Signature...] 3464 User ID [Signature ...] 3465 [User ID [Signature ...] ...] 3466 [User Attribute [Signature ...] ...] 3467 [[Subkey [Binding-Signature-Revocation] 3468 Primary-Key-Binding-Signature] ...] 3470 A subkey always has a single signature after it that is issued using 3471 the primary key to tie the two keys together. This binding signature 3472 may be in either V3 or V4 format, but SHOULD be V4. Subkeys that can 3473 issue signatures MUST have a V4 binding signature due to the REQUIRED 3474 embedded primary key binding signature. 3476 In the above diagram, if the binding signature of a subkey has been 3477 revoked, the revoked key may be removed, leaving only one key. 3479 In a V4 key, the primary key MUST be a key capable of certification. 3480 The subkeys may be keys of any other type. There may be other 3481 constructions of V4 keys, too. For example, there may be a single- 3482 key RSA key in V4 format, a DSA primary key with an RSA encryption 3483 key, or RSA primary key with an Elgamal subkey, etc. 3485 It is also possible to have a signature-only subkey. This permits a 3486 primary key that collects certifications (key signatures), but is 3487 used only for certifying subkeys that are used for encryption and 3488 signatures. 3490 12.2. Key IDs and Fingerprints 3492 For a V3 key, the eight-octet Key ID consists of the low 64 bits of 3493 the public modulus of the RSA key. 3495 The fingerprint of a V3 key is formed by hashing the body (but not 3496 the two-octet length) of the MPIs that form the key material (public 3497 modulus n, followed by exponent e) with MD5. Note that both V3 keys 3498 and MD5 are deprecated. 3500 A V4 fingerprint is the 160-bit SHA-1 hash of the octet 0x99, 3501 followed by the two-octet packet length, followed by the entire 3502 Public-Key packet starting with the version field. The Key ID is the 3503 low-order 64 bits of the fingerprint. Here are the fields of the 3504 hash material, with the example of a DSA key: 3506 a.1) 0x99 (1 octet) 3508 a.2) high-order length octet of (b)-(e) (1 octet) 3509 a.3) low-order length octet of (b)-(e) (1 octet) 3511 b) version number = 4 (1 octet); 3513 c) timestamp of key creation (4 octets); 3515 d) algorithm (1 octet): 17 = DSA (example); 3517 e) Algorithm-specific fields. 3519 Algorithm-Specific Fields for DSA keys (example): 3521 e.1) MPI of DSA prime p; 3523 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 3525 e.3) MPI of DSA group generator g; 3527 e.4) MPI of DSA public-key value y (= g**x mod p where x is secret). 3529 Note that it is possible for there to be collisions of Key IDs -- two 3530 different keys with the same Key ID. Note that there is a much 3531 smaller, but still non-zero, probability that two different keys have 3532 the same fingerprint. 3534 Also note that if V3 and V4 format keys share the same RSA key 3535 material, they will have different Key IDs as well as different 3536 fingerprints. 3538 Finally, the Key ID and fingerprint of a subkey are calculated in the 3539 same way as for a primary key, including the 0x99 as the first octet 3540 (even though this is not a valid packet ID for a public subkey). 3542 13. Notes on Algorithms 3544 13.1. PKCS#1 Encoding in OpenPGP 3546 This standard makes use of the PKCS#1 functions EME-PKCS1-v1_5 and 3547 EMSA-PKCS1-v1_5. However, the calling conventions of these functions 3548 has changed in the past. To avoid potential confusion and 3549 interoperability problems, we are including local copies in this 3550 document, adapted from those in PKCS#1 v2.1 [RFC3447]. [RFC3447] 3551 should be treated as the ultimate authority on PKCS#1 for OpenPGP. 3552 Nonetheless, we believe that there is value in having a self- 3553 contained document that avoids problems in the future with needed 3554 changes in the conventions. 3556 13.1.1. EME-PKCS1-v1_5-ENCODE 3558 Input: 3560 k = the length in octets of the key modulus. 3562 M = message to be encoded, an octet string of length mLen, where 3563 mLen <= k - 11. 3565 Output: 3567 EM = encoded message, an octet string of length k. 3569 Error: "message too long". 3571 1. Length checking: If mLen > k - 11, output "message too long" and 3572 stop. 3574 2. Generate an octet string PS of length k - mLen - 3 consisting of 3575 pseudo-randomly generated nonzero octets. The length of PS will 3576 be at least eight octets. 3578 3. Concatenate PS, the message M, and other padding to form an 3579 encoded message EM of length k octets as 3581 EM = 0x00 || 0x02 || PS || 0x00 || M. 3583 4. Output EM. 3585 13.1.2. EME-PKCS1-v1_5-DECODE 3587 Input: 3589 EM = encoded message, an octet string 3591 Output: 3593 M = message, an octet string. 3595 Error: "decryption error". 3597 To decode an EME-PKCS1_v1_5 message, separate the encoded message EM 3598 into an octet string PS consisting of nonzero octets and a message M 3599 as follows 3601 EM = 0x00 || 0x02 || PS || 0x00 || M. 3603 If the first octet of EM does not have hexadecimal value 0x00, if the 3604 second octet of EM does not have hexadecimal value 0x02, if there is 3605 no octet with hexadecimal value 0x00 to separate PS from M, or if the 3606 length of PS is less than 8 octets, output "decryption error" and 3607 stop. See also the security note in Section 14 regarding differences 3608 in reporting between a decryption error and a padding error. 3610 13.1.3. EMSA-PKCS1-v1_5 3612 This encoding method is deterministic and only has an encoding 3613 operation. 3615 Option: 3617 Hash - a hash function in which hLen denotes the length in octets of 3618 the hash function output. 3620 Input: 3622 M = message to be encoded. 3624 emLen = intended length in octets of the encoded message, at least 3625 tLen + 11, where tLen is the octet length of the DER encoding T of 3626 a certain value computed during the encoding operation. 3628 Output: 3630 EM = encoded message, an octet string of length emLen. 3632 Errors: "message too long"; "intended encoded message length too 3633 short". 3635 Steps: 3637 1. Apply the hash function to the message M to produce a hash value 3638 H: 3640 H = Hash(M). 3642 If the hash function outputs "message too long," output "message 3643 too long" and stop. 3645 2. Using the list in Section 5.2.2, produce an ASN.1 DER value for 3646 the hash function used. Let T be the full hash prefix from 3647 Section 5.2.2, and let tLen be the length in octets of T. 3649 3. If emLen < tLen + 11, output "intended encoded message length too 3650 short" and stop. 3652 4. Generate an octet string PS consisting of emLen - tLen - 3 octets 3653 with hexadecimal value 0xFF. The length of PS will be at least 8 3654 octets. 3656 5. Concatenate PS, the hash prefix T, and other padding to form the 3657 encoded message EM as 3659 EM = 0x00 || 0x01 || PS || 0x00 || T. 3661 6. Output EM. 3663 13.2. Symmetric Algorithm Preferences 3665 The symmetric algorithm preference is an ordered list of algorithms 3666 that the keyholder accepts. Since it is found on a self-signature, 3667 it is possible that a keyholder may have multiple, different 3668 preferences. For example, Alice may have TripleDES only specified 3669 for "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 3670 "alice@home.org". Note that it is also possible for preferences to 3671 be in a subkey's binding signature. 3673 Since TripleDES is the MUST-implement algorithm, if it is not 3674 explicitly in the list, it is tacitly at the end. However, it is 3675 good form to place it there explicitly. Note also that if an 3676 implementation does not implement the preference, then it is 3677 implicitly a TripleDES-only implementation. 3679 An implementation MUST NOT use a symmetric algorithm that is not in 3680 the recipient's preference list. When encrypting to more than one 3681 recipient, the implementation finds a suitable algorithm by taking 3682 the intersection of the preferences of the recipients. Note that the 3683 MUST-implement algorithm, TripleDES, ensures that the intersection is 3684 not null. The implementation may use any mechanism to pick an 3685 algorithm in the intersection. 3687 If an implementation can decrypt a message that a keyholder doesn't 3688 have in their preferences, the implementation SHOULD decrypt the 3689 message anyway, but MUST warn the keyholder that the protocol has 3690 been violated. For example, suppose that Alice, above, has software 3691 that implements all algorithms in this specification. Nonetheless, 3692 she prefers subsets for work or home. If she is sent a message 3693 encrypted with IDEA, which is not in her preferences, the software 3694 warns her that someone sent her an IDEA-encrypted message, but it 3695 would ideally decrypt it anyway. 3697 13.3. Other Algorithm Preferences 3699 Other algorithm preferences work similarly to the symmetric algorithm 3700 preference, in that they specify which algorithms the keyholder 3701 accepts. There are two interesting cases that other comments need to 3702 be made about, though, the compression preferences and the hash 3703 preferences. 3705 13.3.1. Compression Preferences 3707 Compression has been an integral part of PGP since its first days. 3708 OpenPGP and all previous versions of PGP have offered compression. 3709 In this specification, the default is for messages to be compressed, 3710 although an implementation is not required to do so. Consequently, 3711 the compression preference gives a way for a keyholder to request 3712 that messages not be compressed, presumably because they are using a 3713 minimal implementation that does not include compression. 3714 Additionally, this gives a keyholder a way to state that it can 3715 support alternate algorithms. 3717 Like the algorithm preferences, an implementation MUST NOT use an 3718 algorithm that is not in the preference vector. If the preferences 3719 are not present, then they are assumed to be [ZIP(1), 3720 Uncompressed(0)]. 3722 Additionally, an implementation MUST implement this preference to the 3723 degree of recognizing when to send an uncompressed message. A robust 3724 implementation would satisfy this requirement by looking at the 3725 recipient's preference and acting accordingly. A minimal 3726 implementation can satisfy this requirement by never generating a 3727 compressed message, since all implementations can handle messages 3728 that have not been compressed. 3730 13.3.2. Hash Algorithm Preferences 3732 Typically, the choice of a hash algorithm is something the signer 3733 does, rather than the verifier, because a signer rarely knows who is 3734 going to be verifying the signature. This preference, though, allows 3735 a protocol based upon digital signatures ease in negotiation. 3737 Thus, if Alice is authenticating herself to Bob with a signature, it 3738 makes sense for her to use a hash algorithm that Bob's software uses. 3739 This preference allows Bob to state in his key which algorithms Alice 3740 may use. 3742 Since SHA1 is the MUST-implement hash algorithm, if it is not 3743 explicitly in the list, it is tacitly at the end. However, it is 3744 good form to place it there explicitly. 3746 13.4. Plaintext 3748 Algorithm 0, "plaintext", may only be used to denote secret keys that 3749 are stored in the clear. Implementations MUST NOT use plaintext in 3750 Symmetrically Encrypted Data packets; they must use Literal Data 3751 packets to encode unencrypted or literal data. 3753 13.5. RSA 3755 There are algorithm types for RSA Sign-Only, and RSA Encrypt-Only 3756 keys. These types are deprecated. The "key flags" subpacket in a 3757 signature is a much better way to express the same idea, and 3758 generalizes it to all algorithms. An implementation SHOULD NOT 3759 create such a key, but MAY interpret it. 3761 An implementation SHOULD NOT implement RSA keys of size less than 3762 1024 bits. 3764 13.6. DSA 3766 An implementation SHOULD NOT implement DSA keys of size less than 3767 1024 bits. It MUST NOT implement a DSA key with a q size of less 3768 than 160 bits. DSA keys MUST also be a multiple of 64 bits, and the 3769 q size MUST be a multiple of 8 bits. The Digital Signature Standard 3770 (DSS) [FIPS186] specifies that DSA be used in one of the following 3771 ways: 3773 * 1024-bit key, 160-bit q, SHA-1, SHA2-224, SHA2-256, SHA2-384, or 3774 SHA2-512 hash 3776 * 2048-bit key, 224-bit q, SHA2-224, SHA2-256, SHA2-384, or SHA2-512 3777 hash 3779 * 2048-bit key, 256-bit q, SHA2-256, SHA2-384, or SHA2-512 hash 3781 * 3072-bit key, 256-bit q, SHA2-256, SHA2-384, or SHA2-512 hash 3783 The above key and q size pairs were chosen to best balance the 3784 strength of the key with the strength of the hash. Implementations 3785 SHOULD use one of the above key and q size pairs when generating DSA 3786 keys. If DSS compliance is desired, one of the specified SHA hashes 3787 must be used as well. [FIPS186] is the ultimate authority on DSS, 3788 and should be consulted for all questions of DSS compliance. 3790 Note that earlier versions of this standard only allowed a 160-bit q 3791 with no truncation allowed, so earlier implementations may not be 3792 able to handle signatures with a different q size or a truncated 3793 hash. 3795 13.7. Elgamal 3797 An implementation SHOULD NOT implement Elgamal keys of size less than 3798 1024 bits. 3800 13.8. Reserved Algorithm Numbers 3802 A number of algorithm IDs have been reserved for algorithms that 3803 would be useful to use in an OpenPGP implementation, yet there are 3804 issues that prevent an implementer from actually implementing the 3805 algorithm. These are marked in Section 9.1 as "reserved for". 3807 The reserved public-key algorithms, Elliptic Curve (18), ECDSA (19), 3808 and X9.42 (21), do not have the necessary parameters, parameter 3809 order, or semantics defined. 3811 Previous versions of OpenPGP permitted Elgamal [ELGAMAL] signatures 3812 with a public-key identifier of 20. These are no longer permitted. 3813 An implementation MUST NOT generate such keys. An implementation 3814 MUST NOT generate Elgamal signatures. See [BLEICHENBACHER]. 3816 13.9. OpenPGP CFB Mode 3818 OpenPGP does symmetric encryption using a variant of Cipher Feedback 3819 mode (CFB mode). This section describes the procedure it uses in 3820 detail. This mode is what is used for Symmetrically Encrypted Data 3821 Packets; the mechanism used for encrypting secret-key material is 3822 similar, and is described in the sections above. 3824 In the description below, the value BS is the block size in octets of 3825 the cipher. Most ciphers have a block size of 8 octets. The AES and 3826 Twofish have a block size of 16 octets. Also note that the 3827 description below assumes that the IV and CFB arrays start with an 3828 index of 1 (unlike the C language, which assumes arrays start with a 3829 zero index). 3831 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and 3832 prefixes the plaintext with BS+2 octets of random data, such that 3833 octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB 3834 resynchronization after encrypting those BS+2 octets. 3836 Thus, for an algorithm that has a block size of 8 octets (64 bits), 3837 the IV is 10 octets long and octets 7 and 8 of the IV are the same as 3838 octets 9 and 10. For an algorithm with a block size of 16 octets 3839 (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate 3840 octets 15 and 16. Those extra two octets are an easy check for a 3841 correct key. 3843 Step by step, here is the procedure: 3845 1. The feedback register (FR) is set to the IV, which is all zeros. 3847 2. FR is encrypted to produce FRE (FR Encrypted). This is the 3848 encryption of an all-zero value. 3850 3. FRE is xored with the first BS octets of random data prefixed to 3851 the plaintext to produce C[1] through C[BS], the first BS octets 3852 of ciphertext. 3854 4. FR is loaded with C[1] through C[BS]. 3856 5. FR is encrypted to produce FRE, the encryption of the first BS 3857 octets of ciphertext. 3859 6. The left two octets of FRE get xored with the next two octets of 3860 data that were prefixed to the plaintext. This produces C[BS+1] 3861 and C[BS+2], the next two octets of ciphertext. 3863 7. (The resynchronization step) FR is loaded with C[3] through 3864 C[BS+2]. 3866 8. FR is encrypted to produce FRE. 3868 9. FRE is xored with the first BS octets of the given plaintext, 3869 now that we have finished encrypting the BS+2 octets of prefixed 3870 data. This produces C[BS+3] through C[BS+(BS+2)], the next BS 3871 octets of ciphertext. 3873 10. FR is loaded with C[BS+3] to C[BS + (BS+2)] (which is C11-C18 3874 for an 8-octet block). 3876 11. FR is encrypted to produce FRE. 3878 12. FRE is xored with the next BS octets of plaintext, to produce 3879 the next BS octets of ciphertext. These are loaded into FR, and 3880 the process is repeated until the plaintext is used up. 3882 13.10. Private or Experimental Parameters 3884 S2K specifiers, Signature subpacket types, User Attribute types, 3885 image format types, and algorithms described in Section 9 all reserve 3886 the range 100 to 110 for private and experimental use. Packet types 3887 reserve the range 60 to 63 for private and experimental use. These 3888 are intentionally managed with the PRIVATE USE method, as described 3889 in [RFC2434]. 3891 However, implementations need to be careful with these and promote 3892 them to full IANA-managed parameters when they grow beyond the 3893 original, limited system. 3895 13.11. Extension of the MDC System 3897 As described in the non-normative explanation in Section 5.13, the 3898 MDC system is uniquely unparameterized in OpenPGP. This was an 3899 intentional decision to avoid cross-grade attacks. If the MDC system 3900 is extended to a stronger hash function, care must be taken to avoid 3901 downgrade and cross-grade attacks. 3903 One simple way to do this is to create new packets for a new MDC. 3904 For example, instead of the MDC system using packets 18 and 19, a new 3905 MDC could use 20 and 21. This has obvious drawbacks (it uses two 3906 packet numbers for each new hash function in a space that is limited 3907 to a maximum of 60). 3909 Another simple way to extend the MDC system is to create new versions 3910 of packet 18, and reflect this in packet 19. For example, suppose 3911 that V2 of packet 18 implicitly used SHA-256. This would require 3912 packet 19 to have a length of 32 octets. The change in the version 3913 in packet 18 and the size of packet 19 prevent a downgrade attack. 3915 There are two drawbacks to this latter approach. The first is that 3916 using the version number of a packet to carry algorithm information 3917 is not tidy from a protocol-design standpoint. It is possible that 3918 there might be several versions of the MDC system in common use, but 3919 this untidiness would reflect untidiness in cryptographic consensus 3920 about hash function security. The second is that different versions 3921 of packet 19 would have to have unique sizes. If there were two 3922 versions each with 256-bit hashes, they could not both have 32-octet 3923 packet 19s without admitting the chance of a cross-grade attack. 3925 Yet another, complex approach to extend the MDC system would be a 3926 hybrid of the two above -- create a new pair of MDC packets that are 3927 fully parameterized, and yet protected from downgrade and cross- 3928 grade. 3930 Any change to the MDC system MUST be done through the IETF CONSENSUS 3931 method, as described in [RFC2434]. 3933 13.12. Meta-Considerations for Expansion 3935 If OpenPGP is extended in a way that is not backwards-compatible, 3936 meaning that old implementations will not gracefully handle their 3937 absence of a new feature, the extension proposal can be declared in 3938 the key holder's self-signature as part of the Features signature 3939 subpacket. 3941 We cannot state definitively what extensions will not be upwards- 3942 compatible, but typically new algorithms are upwards-compatible, 3943 whereas new packets are not. 3945 If an extension proposal does not update the Features system, it 3946 SHOULD include an explanation of why this is unnecessary. If the 3947 proposal contains neither an extension to the Features system nor an 3948 explanation of why such an extension is unnecessary, the proposal 3949 SHOULD be rejected. 3951 14. Security Considerations 3953 * As with any technology involving cryptography, you should check 3954 the current literature to determine if any algorithms used here 3955 have been found to be vulnerable to attack. 3957 * This specification uses Public-Key Cryptography technologies. It 3958 is assumed that the private key portion of a public-private key 3959 pair is controlled and secured by the proper party or parties. 3961 * Certain operations in this specification involve the use of random 3962 numbers. An appropriate entropy source should be used to generate 3963 these numbers (see [RFC4086]). 3965 * The MD5 hash algorithm has been found to have weaknesses, with 3966 collisions found in a number of cases. MD5 is deprecated for use 3967 in OpenPGP. Implementations MUST NOT generate new signatures 3968 using MD5 as a hash function. They MAY continue to consider old 3969 signatures that used MD5 as valid. 3971 * SHA2-224 and SHA2-384 require the same work as SHA2-256 and 3972 SHA2-512, respectively. In general, there are few reasons to use 3973 them outside of DSS compatibility. You need a situation where one 3974 needs more security than smaller hashes, but does not want to have 3975 the full 256-bit or 512-bit data length. 3977 * Many security protocol designers think that it is a bad idea to 3978 use a single key for both privacy (encryption) and integrity 3979 (signatures). In fact, this was one of the motivating forces 3980 behind the V4 key format with separate signature and encryption 3981 keys. If you as an implementer promote dual-use keys, you should 3982 at least be aware of this controversy. 3984 * The DSA algorithm will work with any hash, but is sensitive to the 3985 quality of the hash algorithm. Verifiers should be aware that 3986 even if the signer used a strong hash, an attacker could have 3987 modified the signature to use a weak one. Only signatures using 3988 acceptably strong hash algorithms should be accepted as valid. 3990 * As OpenPGP combines many different asymmetric, symmetric, and hash 3991 algorithms, each with different measures of strength, care should 3992 be taken that the weakest element of an OpenPGP message is still 3993 sufficiently strong for the purpose at hand. While consensus 3994 about the strength of a given algorithm may evolve, NIST Special 3995 Publication 800-57 [SP800-57] recommends the following list of 3996 equivalent strengths: 3998 +=====================+===========+====================+ 3999 | Asymmetric key size | Hash size | Symmetric key size | 4000 +=====================+===========+====================+ 4001 | 1024 | 160 | 80 | 4002 +---------------------+-----------+--------------------+ 4003 | 2048 | 224 | 112 | 4004 +---------------------+-----------+--------------------+ 4005 | 3072 | 256 | 128 | 4006 +---------------------+-----------+--------------------+ 4007 | 7680 | 384 | 192 | 4008 +---------------------+-----------+--------------------+ 4009 | 15360 | 512 | 256 | 4010 +---------------------+-----------+--------------------+ 4012 Table 17: Key length equivalences 4014 * There is a somewhat-related potential security problem in 4015 signatures. If an attacker can find a message that hashes to the 4016 same hash with a different algorithm, a bogus signature structure 4017 can be constructed that evaluates correctly. 4019 For example, suppose Alice DSA signs message M using hash 4020 algorithm H. Suppose that Mallet finds a message M' that has the 4021 same hash value as M with H'. Mallet can then construct a 4022 signature block that verifies as Alice's signature of M' with H'. 4023 However, this would also constitute a weakness in either H or H' 4024 or both. Should this ever occur, a revision will have to be made 4025 to this document to revise the allowed hash algorithms. 4027 * If you are building an authentication system, the recipient may 4028 specify a preferred signing algorithm. However, the signer would 4029 be foolish to use a weak algorithm simply because the recipient 4030 requests it. 4032 * Some of the encryption algorithms mentioned in this document have 4033 been analyzed less than others. For example, although CAST5 is 4034 presently considered strong, it has been analyzed less than 4035 TripleDES. Other algorithms may have other controversies 4036 surrounding them. 4038 * In late summer 2002, Jallad, Katz, and Schneier published an 4039 interesting attack on the OpenPGP protocol and some of its 4040 implementations [JKS02]. In this attack, the attacker modifies a 4041 message and sends it to a user who then returns the erroneously 4042 decrypted message to the attacker. The attacker is thus using the 4043 user as a random oracle, and can often decrypt the message. 4045 Compressing data can ameliorate this attack. The incorrectly 4046 decrypted data nearly always decompresses in ways that defeat the 4047 attack. However, this is not a rigorous fix, and leaves open some 4048 small vulnerabilities. For example, if an implementation does not 4049 compress a message before encryption (perhaps because it knows it 4050 was already compressed), then that message is vulnerable. Because 4051 of this happenstance -- that modification attacks can be thwarted 4052 by decompression errors -- an implementation SHOULD treat a 4053 decompression error as a security problem, not merely a data 4054 problem. 4056 This attack can be defeated by the use of Modification Detection, 4057 provided that the implementation does not let the user naively 4058 return the data to the attacker. An implementation MUST treat an 4059 MDC failure as a security problem, not merely a data problem. 4061 In either case, the implementation MAY allow the user access to 4062 the erroneous data, but MUST warn the user as to potential 4063 security problems should that data be returned to the sender. 4065 While this attack is somewhat obscure, requiring a special set of 4066 circumstances to create it, it is nonetheless quite serious as it 4067 permits someone to trick a user to decrypt a message. 4068 Consequently, it is important that: 4070 1. Implementers treat MDC errors and decompression failures as 4071 security problems. 4073 2. Implementers implement Modification Detection with all due 4074 speed and encourage its spread. 4076 3. Users migrate to implementations that support Modification 4077 Detection with all due speed. 4079 * PKCS#1 has been found to be vulnerable to attacks in which a 4080 system that reports errors in padding differently from errors in 4081 decryption becomes a random oracle that can leak the private key 4082 in mere millions of queries. Implementations must be aware of 4083 this attack and prevent it from happening. The simplest solution 4084 is to report a single error code for all variants of decryption 4085 errors so as not to leak information to an attacker. 4087 * Some technologies mentioned here may be subject to government 4088 control in some countries. 4090 * In winter 2005, Serge Mister and Robert Zuccherato from Entrust 4091 released a paper describing a way that the "quick check" in 4092 OpenPGP CFB mode can be used with a random oracle to decrypt two 4093 octets of every cipher block [MZ05]. They recommend as prevention 4094 not using the quick check at all. 4096 Many implementers have taken this advice to heart for any data 4097 that is symmetrically encrypted and for which the session key is 4098 public-key encrypted. In this case, the quick check is not needed 4099 as the public-key encryption of the session key should guarantee 4100 that it is the right session key. In other cases, the 4101 implementation should use the quick check with care. 4103 On the one hand, there is a danger to using it if there is a 4104 random oracle that can leak information to an attacker. In 4105 plainer language, there is a danger to using the quick check if 4106 timing information about the check can be exposed to an attacker, 4107 particularly via an automated service that allows rapidly repeated 4108 queries. 4110 On the other hand, it is inconvenient to the user to be informed 4111 that they typed in the wrong passphrase only after a petabyte of 4112 data is decrypted. There are many cases in cryptographic 4113 engineering where the implementer must use care and wisdom, and 4114 this is one. 4116 15. Implementation Nits 4118 This section is a collection of comments to help an implementer, 4119 particularly with an eye to backward compatibility. Previous 4120 implementations of PGP are not OpenPGP compliant. Often the 4121 differences are small, but small differences are frequently more 4122 vexing than large differences. Thus, this is a non-comprehensive 4123 list of potential problems and gotchas for a developer who is trying 4124 to be backward-compatible. 4126 * The IDEA algorithm is patented, and yet it is required for PGP 2 4127 interoperability. It is also the de-facto preferred algorithm for 4128 a V3 key with a V3 self-signature (or no self-signature). 4130 * When exporting a private key, PGP 2 generates the header "BEGIN 4131 PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY BLOCK". 4132 All previous versions ignore the implied data type, and look 4133 directly at the packet data type. 4135 * PGP versions 2.0 through 2.5 generated V2 Public-Key packets. 4136 These are identical to the deprecated V3 keys except for the 4137 version number. An implementation MUST NOT generate them and may 4138 accept or reject them as it sees fit. Some older PGP versions 4139 generated V2 PKESK packets (Tag 1) as well. An implementation may 4140 accept or reject V2 PKESK packets as it sees fit, and MUST NOT 4141 generate them. 4143 * PGP version 2.6 will not accept key-material packets with versions 4144 greater than 3. 4146 * There are many ways possible for two keys to have the same key 4147 material, but different fingerprints (and thus Key IDs). Perhaps 4148 the most interesting is an RSA key that has been "upgraded" to V4 4149 format, but since a V4 fingerprint is constructed by hashing the 4150 key creation time along with other things, two V4 keys created at 4151 different times, yet with the same key material will have 4152 different fingerprints. 4154 * If an implementation is using zlib to interoperate with PGP 2, 4155 then the "windowBits" parameter should be set to -13. 4157 * The 0x19 back signatures were not required for signing subkeys 4158 until relatively recently. Consequently, there may be keys in the 4159 wild that do not have these back signatures. Implementing 4160 software may handle these keys as it sees fit. 4162 * OpenPGP does not put limits on the size of public keys. However, 4163 larger keys are not necessarily better keys. Larger keys take 4164 more computation time to use, and this can quickly become 4165 impractical. Different OpenPGP implementations may also use 4166 different upper bounds for public key sizes, and so care should be 4167 taken when choosing sizes to maintain interoperability. As of 4168 2007 most implementations have an upper bound of 4096 bits. 4170 * ASCII armor is an optional feature of OpenPGP. The OpenPGP 4171 working group strives for a minimal set of mandatory-to-implement 4172 features, and since there could be useful implementations that 4173 only use binary object formats, this is not a "MUST" feature for 4174 an implementation. For example, an implementation that is using 4175 OpenPGP as a mechanism for file signatures may find ASCII armor 4176 unnecessary. OpenPGP permits an implementation to declare what 4177 features it does and does not support, but ASCII armor is not one 4178 of these. Since most implementations allow binary and armored 4179 objects to be used indiscriminately, an implementation that does 4180 not implement ASCII armor may find itself with compatibility 4181 issues with general-purpose implementations. Moreover, 4182 implementations of OpenPGP-MIME [RFC3156] already have a 4183 requirement for ASCII armor so those implementations will 4184 necessarily have support. 4186 16. References 4188 16.1. Normative References 4190 [AES] NIST, "FIPS PUB 197, Advanced Encryption Standard (AES)", 4191 November 2001, 4192 . 4195 [BLOWFISH] Schneier, B., "Description of a New Variable-Length Key, 4196 64-Bit Block Cipher (Blowfish)", Fast Software Encryption, 4197 Cambridge Security Workshop Proceedings Springer-Verlag, 4198 1994, pp191-204, December 1993, 4199 . 4201 [BZ2] Seward, J., "The Bzip2 and libbzip2 home page", 2010, 4202 . 4204 [ELGAMAL] Elgamal, T., "A Public-Key Cryptosystem and a Signature 4205 Scheme Based on Discrete Logarithms", IEEE Transactions on 4206 Information Theory v. IT-31, n. 4, 1985, pp. 469-472, 4207 1985. 4209 [FIPS180] National Institute of Standards and Technology, U.S. 4210 Department of Commerce, "Secure Hash Standard (SHS), FIPS 4211 180-4", August 2015, 4212 . 4214 [FIPS186] National Institute of Standards and Technology, U.S. 4215 Department of Commerce, "Digital Signature Standard (DSS), 4216 FIPS 186-4", July 2013, 4217 . 4219 [HAC] Menezes, A.J., Oorschot, P.v., and S. Vanstone, "Handbook 4220 of Applied Cryptography", 1996. 4222 [IDEA] Lai, X., "On the design and security of block ciphers", 4223 ETH Series in Information Processing, J.L. Massey 4224 (editor) Vol. 1, Hartung-Gorre Verlag Konstanz, Technische 4225 Hochschule (Zurich), 1992. 4227 [ISO10646] International Organization for Standardization, 4228 "Information Technology - Universal Multiple-octet coded 4229 Character Set (UCS) - Part 1: Architecture and Basic 4230 Multilingual Plane", ISO Standard 10646-1, May 1993. 4232 [JFIF] CA, E.H.M., "JPEG File Interchange Format (Version 4233 1.02).", September 1996. 4235 [RFC1950] Deutsch, P. and J-L. Gailly, "ZLIB Compressed Data Format 4236 Specification version 3.3", RFC 1950, 4237 DOI 10.17487/RFC1950, May 1996, 4238 . 4240 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format Specification 4241 version 1.3", RFC 1951, DOI 10.17487/RFC1951, May 1996, 4242 . 4244 [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet Mail 4245 Extensions (MIME) Part One: Format of Internet Message 4246 Bodies", RFC 2045, DOI 10.17487/RFC2045, November 1996, 4247 . 4249 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 4250 Requirement Levels", BCP 14, RFC 2119, 4251 DOI 10.17487/RFC2119, March 1997, 4252 . 4254 [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC 2144, 4255 DOI 10.17487/RFC2144, May 1997, 4256 . 4258 [RFC2434] Narten, T. and H. Alvestrand, "Guidelines for Writing an 4259 IANA Considerations Section in RFCs", RFC 2434, 4260 DOI 10.17487/RFC2434, October 1998, 4261 . 4263 [RFC2822] Resnick, P., Ed., "Internet Message Format", RFC 2822, 4264 DOI 10.17487/RFC2822, April 2001, 4265 . 4267 [RFC3156] Elkins, M., Del Torto, D., Levien, R., and T. Roessler, 4268 "MIME Security with OpenPGP", RFC 3156, 4269 DOI 10.17487/RFC3156, August 2001, 4270 . 4272 [RFC3447] Jonsson, J. and B. Kaliski, "Public-Key Cryptography 4273 Standards (PKCS) #1: RSA Cryptography Specifications 4274 Version 2.1", RFC 3447, DOI 10.17487/RFC3447, February 4275 2003, . 4277 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 4278 10646", STD 63, RFC 3629, DOI 10.17487/RFC3629, November 4279 2003, . 4281 [RFC3713] Matsui, M., Nakajima, J., and S. Moriai, "A Description of 4282 the Camellia Encryption Algorithm", RFC 3713, 4283 DOI 10.17487/RFC3713, April 2004, 4284 . 4286 [RFC4086] Eastlake 3rd, D., Schiller, J., and S. Crocker, 4287 "Randomness Requirements for Security", BCP 106, RFC 4086, 4288 DOI 10.17487/RFC4086, June 2005, 4289 . 4291 [SCHNEIER] Schneier, B., "Applied Cryptography Second Edition: 4292 protocols, algorithms, and source code in C", 1996. 4294 [TWOFISH] Schneier, B., Kelsey, J., Whiting, D., Wagner, D., Hall, 4295 C., and N. Ferguson, "The Twofish Encryption Algorithm", 4296 1999. 4298 16.2. Informative References 4300 [BLEICHENBACHER] 4301 Bleichenbacher, D., "Generating ElGamal Signatures Without 4302 Knowing the Secret Key", Lecture Notes in Computer 4303 Science Volume 1070, pp. 10-18, 1996. 4305 [JKS02] Jallad, K., Katz, J., and B. Schneier, "Implementation of 4306 Chosen-Ciphertext Attacks against PGP and GnuPG", 2002, 4307 . 4309 [MZ05] Mister, S. and R. Zuccherato, "An Attack on CFB Mode 4310 Encryption As Used By OpenPGP", IACR ePrint Archive Report 4311 2005/033, 8 February 2005, 4312 . 4314 [REGEX] Friedl, J., "Mastering Regular Expressions", 4315 ISBN 0-596-00289-0, August 2002. 4317 [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP Message 4318 Exchange Formats", RFC 1991, DOI 10.17487/RFC1991, August 4319 1996, . 4321 [RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R. Thayer, 4322 "OpenPGP Message Format", RFC 2440, DOI 10.17487/RFC2440, 4323 November 1998, . 4325 [RFC4880] Callas, J., Donnerhacke, L., Finney, H., Shaw, D., and R. 4326 Thayer, "OpenPGP Message Format", RFC 4880, 4327 DOI 10.17487/RFC4880, November 2007, 4328 . 4330 [SP800-57] NIST, "Recommendation on Key Management", NIST Special 4331 Publication 800-57, March 2007, 4332 . 4335 Appendix A. Acknowledgements 4337 This memo also draws on much previous work from a number of other 4338 authors, including: Derek Atkins, Charles Breed, Dave Del Torto, Marc 4339 Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Ben Laurie, 4340 Raph Levien, Colin Plumb, Will Price, David Shaw, William Stallings, 4341 Mark Weaver, and Philip R. Zimmermann. 4343 Authors' Addresses 4344 Werner Koch (editor) 4345 GnuPG e.V. 4346 Rochusstr. 44 4347 40479 Duesseldorf 4348 Germany 4350 Email: wk@gnupg.org 4351 URI: https://gnupg.org/verein 4353 Paul Wouters (editor) 4355 Email: pwouters@redhat.com