idnits 2.17.1 draft-ietf-openpgp-rfc2440bis-20.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** It looks like you're using RFC 3978 boilerplate. You should update this to the boilerplate described in the IETF Trust License Policy document (see https://trustee.ietf.org/license-info), which is required now. -- Found old boilerplate from RFC 3978, Section 5.1 on line 22. -- Found old boilerplate from RFC 3978, Section 5.5, updated by RFC 4748 on line 4188. -- Found old boilerplate from RFC 3979, Section 5, paragraph 1 on line 4216. -- Found old boilerplate from RFC 3979, Section 5, paragraph 2 on line 4223. -- Found old boilerplate from RFC 3979, Section 5, paragraph 3 on line 4229. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- == There are 6 instances of lines with non-RFC6890-compliant IPv4 addresses in the document. If these are example addresses, they should be changed. -- The draft header indicates that this document obsoletes RFC2440, but the abstract doesn't seem to mention this, which it should. -- The draft header indicates that this document obsoletes RFC1991, but the abstract doesn't seem to mention this, which it should. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust Copyright Line does not match the current year -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- The document date (Mar 2007) is 6252 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 398 -- Looks like a reference, but probably isn't: '1' on line 3766 -- Looks like a reference, but probably isn't: '2' on line 398 -- Looks like a reference, but probably isn't: '3' on line 3775 == Missing Reference: 'Optional' is mentioned on line 2016, but not defined == Missing Reference: 'RFC 1951' is mentioned on line 2933, but not defined == Missing Reference: 'RFC 1950' is mentioned on line 2934, but not defined == Missing Reference: 'Binding-Signature-Revocation' is mentioned on line 3374, but not defined == Missing Reference: 'BS' is mentioned on line 3766, but not defined == Unused Reference: 'RFC2144' is defined on line 4097, but no explicit reference was found in the text == Unused Reference: 'RFC2822' is defined on line 4100, but no explicit reference was found in the text == Unused Reference: 'RFC3156' is defined on line 4102, but no explicit reference was found in the text == Unused Reference: 'RFC4086' is defined on line 4113, but no explicit reference was found in the text == Unused Reference: 'MAURER' is defined on line 4139, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 4150, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 4154, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 4157, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 4160, but no explicit reference was found in the text -- 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 2144 ** Obsolete normative reference: RFC 2822 (Obsoleted by RFC 5322) ** Obsolete normative reference: RFC 3447 (Obsoleted by RFC 8017) -- 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 2434 (Obsoleted by RFC 5226) Summary: 4 errors (**), 0 flaws (~~), 16 warnings (==), 28 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 1 Network Working Group Jon Callas 2 Internet-Draft PGP Corporation 3 Intended status: Standards Track 4 Expires September 2007 Lutz Donnerhacke 5 Mar 2007 7 Obsoletes: 1991, 2440 Hal Finney 8 PGP Corporation 10 David Shaw 12 Rodney Thayer 14 OpenPGP Message Format 15 draft-ietf-openpgp-rfc2440bis-20 17 Status of this Memo 19 By submitting this Internet-Draft, each author represents that any 20 applicable patent or other IPR claims of which he or she is aware 21 have been or will be disclosed, and any of which he or she becomes 22 aware will be disclosed, in accordance with Section 6 of BCP 79. 24 Internet-Drafts are working documents of the Internet Engineering 25 Task Force (IETF), its areas, and its working groups. Note that 26 other groups may also distribute working documents as 27 Internet-Drafts. 29 Internet-Drafts are draft documents valid for a maximum of six 30 months and may be updated, replaced, or obsoleted by other documents 31 at any time. It is inappropriate to use Internet-Drafts as reference 32 material or to cite them other than as "work in progress." 34 The list of current Internet-Drafts can be accessed at 35 http://www.ietf.org/1id-abstracts.html 37 The list of Internet-Draft Shadow Directories can be accessed at 38 http://www.ietf.org/shadow.html 40 Copyright Notice 42 Copyright (C) The IETF Trust (2007). 44 Abstract 46 This document is maintained in order to publish all necessary 47 information needed to develop interoperable applications based on 48 the OpenPGP format. It is not a step-by-step cookbook for writing an 49 application. It describes only the format and methods needed to 50 read, check, generate, and write conforming packets crossing any 51 network. It does not deal with storage and implementation questions. 52 It does, however, discuss implementation issues necessary to avoid 53 security flaws. 55 OpenPGP software uses a combination of strong public-key and 56 symmetric cryptography to provide security services for electronic 57 communications and data storage. These services include 58 confidentiality, key management, authentication, and digital 59 signatures. This document specifies the message formats used in 60 OpenPGP. 62 Table of Contents 64 Status of this Memo 1 65 Copyright Notice 1 66 Abstract 1 67 Table of Contents 3 68 1. Introduction 7 69 1.1. Terms 7 70 2. General functions 7 71 2.1. Confidentiality via Encryption 8 72 2.2. Authentication via Digital signature 9 73 2.3. Compression 9 74 2.4. Conversion to Radix-64 9 75 2.5. Signature-Only Applications 10 76 3. Data Element Formats 10 77 3.1. Scalar numbers 10 78 3.2. Multiprecision Integers 10 79 3.3. Key IDs 11 80 3.4. Text 11 81 3.5. Time fields 11 82 3.6. Keyrings 11 83 3.7. String-to-key (S2K) specifiers 11 84 3.7.1. String-to-key (S2K) specifier types 11 85 3.7.1.1. Simple S2K 12 86 3.7.1.2. Salted S2K 12 87 3.7.1.3. Iterated and Salted S2K 12 88 3.7.2. String-to-key usage 13 89 3.7.2.1. Secret key encryption 13 90 3.7.2.2. Symmetric-key message encryption 14 91 4. Packet Syntax 14 92 4.1. Overview 14 93 4.2. Packet Headers 14 94 4.2.1. Old-Format Packet Lengths 15 95 4.2.2. New-Format Packet Lengths 15 96 4.2.2.1. One-Octet Lengths 16 97 4.2.2.2. Two-Octet Lengths 16 98 4.2.2.3. Five-Octet Lengths 16 99 4.2.2.4. Partial Body Lengths 16 100 4.2.3. Packet Length Examples 17 101 4.3. Packet Tags 17 102 5. Packet Types 18 103 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 18 104 5.2. Signature Packet (Tag 2) 19 105 5.2.1. Signature Types 20 106 5.2.2. Version 3 Signature Packet Format 22 107 5.2.3. Version 4 Signature Packet Format 24 108 5.2.3.1. Signature Subpacket Specification 25 109 5.2.3.2. Signature Subpacket Types 27 110 5.2.3.3. Notes on Self-Signatures 27 111 5.2.3.4. Signature creation time 28 112 5.2.3.5. Issuer 28 113 5.2.3.6. Key expiration time 28 114 5.2.3.7. Preferred symmetric algorithms 28 115 5.2.3.8. Preferred hash algorithms 28 116 5.2.3.9. Preferred compression algorithms 29 117 5.2.3.10.Signature expiration time 29 118 5.2.3.11.Exportable Certification 29 119 5.2.3.12.Revocable 30 120 5.2.3.13.Trust signature 30 121 5.2.3.14.Regular expression 30 122 5.2.3.15.Revocation key 30 123 5.2.3.16.Notation Data 31 124 5.2.3.17.Key server preferences 32 125 5.2.3.18.Preferred key server 32 126 5.2.3.19.Primary User ID 32 127 5.2.3.20.Policy URI 32 128 5.2.3.21.Key Flags 33 129 5.2.3.22.Signer's User ID 34 130 5.2.3.23.Reason for Revocation 34 131 5.2.3.24.Features 35 132 5.2.3.25.Signature Target 35 133 5.2.3.26.Embedded Signature 35 134 5.2.4. Computing Signatures 36 135 5.2.4.1. Subpacket Hints 37 136 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) 37 137 5.4. One-Pass Signature Packets (Tag 4) 38 138 5.5. Key Material Packet 39 139 5.5.1. Key Packet Variants 39 140 5.5.1.1. Public Key Packet (Tag 6) 39 141 5.5.1.2. Public Subkey Packet (Tag 14) 39 142 5.5.1.3. Secret Key Packet (Tag 5) 39 143 5.5.1.4. Secret Subkey Packet (Tag 7) 39 144 5.5.2. Public Key Packet Formats 39 145 5.5.3. Secret Key Packet Formats 41 146 5.6. Compressed Data Packet (Tag 8) 43 147 5.7. Symmetrically Encrypted Data Packet (Tag 9) 43 148 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 44 149 5.9. Literal Data Packet (Tag 11) 44 150 5.10. Trust Packet (Tag 12) 45 151 5.11. User ID Packet (Tag 13) 46 152 5.12. User Attribute Packet (Tag 17) 46 153 5.12.1. The Image Attribute Subpacket 46 154 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) 47 155 5.14. Modification Detection Code Packet (Tag 19) 50 156 6. Radix-64 Conversions 50 157 6.1. An Implementation of the CRC-24 in "C" 51 158 6.2. Forming ASCII Armor 51 159 6.3. Encoding Binary in Radix-64 54 160 6.4. Decoding Radix-64 55 161 6.5. Examples of Radix-64 55 162 6.6. Example of an ASCII Armored Message 56 163 7. Cleartext signature framework 56 164 7.1. Dash-Escaped Text 57 165 8. Regular Expressions 57 166 9. Constants 58 167 9.1. Public Key Algorithms 58 168 9.2. Symmetric Key Algorithms 59 169 9.3. Compression Algorithms 59 170 9.4. Hash Algorithms 59 171 10. IANA Considerations 60 172 10.1. New String-to-Key specifier types 60 173 10.2. New Packets 60 174 10.2.1. User Attribute Types 60 175 10.2.1.1.Image Format Subpacket Types 60 176 10.2.2. New Signature Subpackets 61 177 10.2.2.1.Signature Notation Data Subpackets 61 178 10.2.2.2.Key Server Preference Extensions 61 179 10.2.2.3.Key Flags Extensions 61 180 10.2.2.4.Reason For Revocation Extensions 62 181 10.2.2.5.Implementation Features 62 182 10.2.3. New Packet Versions 62 183 10.3. New Algorithms 62 184 10.3.1. Public Key Algorithms 63 185 10.3.2. Symmetric Key Algorithms 63 186 10.3.3. Hash Algorithms 63 187 10.3.4. Compression Algorithms 63 188 10.4. Private or Experimental Parameters 63 189 10.5. Extension of the MDC System 64 190 10.6. Meta-Considerations 64 191 11. Packet Composition 65 192 11.1. Transferable Public Keys 65 193 11.2. Transferable Secret Keys 66 194 11.3. OpenPGP Messages 66 195 11.4. Detached Signatures 67 196 12. Enhanced Key Formats 67 197 12.1. Key Structures 67 198 12.2. Key IDs and Fingerprints 68 199 13. Notes on Algorithms 69 200 13.1. PKCS#1 Encoding In OpenPGP 69 201 13.1.1. EME-PKCS1-v1_5-ENCODE 70 202 13.1.2. EME-PKCS1-v1_5-DECODE 70 203 13.1.3. EMSA-PKCS1-v1_5 71 204 13.2. Symmetric Algorithm Preferences 72 205 13.3. Other Algorithm Preferences 72 206 13.3.1. Compression Preferences 72 207 13.3.2. Hash Algorithm Preferences 73 208 13.4. Plaintext 73 209 13.5. RSA 73 210 13.6. DSA 74 211 13.7. Elgamal 74 212 13.8. Reserved Algorithm Numbers 74 213 13.9. OpenPGP CFB mode 75 214 14. Security Considerations 76 215 15. Implementation Nits 79 216 16. Authors' Addresses 80 217 17. References (Normative) 81 218 18. References (Informative) 82 219 19. Full Copyright Statement 83 220 20. Intellectual Property 84 222 1. Introduction 224 This document provides information on the message-exchange packet 225 formats used by OpenPGP to provide encryption, decryption, signing, 226 and key management functions. It is a revision of RFC 2440, "OpenPGP 227 Message Format", which itself replaces RFC 1991, "PGP Message 228 Exchange Formats." 230 1.1. Terms 232 * OpenPGP - This is a definition for security software that uses 233 PGP 5.x as a basis, formalized in RFC 2440 and this document. 235 * PGP - Pretty Good Privacy. PGP is a family of software systems 236 developed by Philip R. Zimmermann from which OpenPGP is based. 238 * PGP 2.6.x - This version of PGP has many variants, hence the 239 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 240 cryptographic transforms. An informational RFC, RFC 1991, was 241 written describing this version of PGP. 243 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 244 the community and also in the predecessor of this document, RFC 245 1991. It has new formats and corrects a number of problems in 246 the PGP 2.6.x design. It is referred to here as PGP 5.x because 247 that software was the first release of the "PGP 3" code base. 249 * GnuPG - GNU Privacy Guard, also called GPG. GnuPG is an OpenPGP 250 implementation that avoids all encumbered algorithms. 251 Consequently, early versions of GnuPG did not include RSA public 252 keys. GnuPG may or may not have (depending on version) support 253 for IDEA or other encumbered algorithms. 255 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 256 PGP Corporation and are used with permission. The term "OpenPGP" 257 refers to the protocol described in this and related documents. 259 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 260 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 261 document are to be interpreted as described in RFC 2119. 263 The key words "PRIVATE USE", "HIERARCHICAL ALLOCATION", "FIRST COME 264 FIRST SERVED", "EXPERT REVIEW", "SPECIFICATION REQUIRED", "IESG 265 APPROVAL", "IETF CONSENSUS", and "STANDARDS ACTION" that appear in 266 this document when used to describe namespace allocation are to be 267 interpreted as described in RFC 2434. 269 2. General functions 271 OpenPGP provides data integrity services for messages and data files 272 by using these core technologies: 274 - digital signatures 276 - encryption 278 - compression 280 - radix-64 conversion 282 In addition, OpenPGP provides key management and certificate 283 services, but many of these are beyond the scope of this document. 285 2.1. Confidentiality via Encryption 287 OpenPGP combines symmetric-key encryption and public key encryption 288 to provide confidentiality. When made confidential, first the object 289 is encrypted using a symmetric encryption algorithm. Each symmetric 290 key is used only once, for a single object. A new "session key" is 291 generated as a random number for each object (sometimes referred to 292 as a session). Since it is used only once, the session key is bound 293 to the message and transmitted with it. To protect the key, it is 294 encrypted with the receiver's public key. The sequence is as 295 follows: 297 1. The sender creates a message. 299 2. The sending OpenPGP generates a random number to be used as a 300 session key for this message only. 302 3. The session key is encrypted using each recipient's public key. 303 These "encrypted session keys" start the message. 305 4. The sending OpenPGP encrypts the message using the session key, 306 which forms the remainder of the message. Note that the message 307 is also usually compressed. 309 5. The receiving OpenPGP decrypts the session key using the 310 recipient's private key. 312 6. The receiving OpenPGP decrypts the message using the session 313 key. If the message was compressed, it will be decompressed. 315 With symmetric-key encryption, an object may be encrypted with a 316 symmetric key derived from a passphrase (or other shared secret), or 317 a two-stage mechanism similar to the public-key method described 318 above in which a session key is itself encrypted with a symmetric 319 algorithm keyed from a shared secret. 321 Both digital signature and confidentiality services may be applied 322 to the same message. First, a signature is generated for the message 323 and attached to the message. Then, the message plus signature is 324 encrypted using a symmetric session key. Finally, the session key is 325 encrypted using public-key encryption and prefixed to the encrypted 326 block. 328 2.2. Authentication via Digital signature 330 The digital signature uses a hash code or message digest algorithm, 331 and a public-key signature algorithm. The sequence is as follows: 333 1. The sender creates a message. 335 2. The sending software generates a hash code of the message. 337 3. The sending software generates a signature from the hash code 338 using the sender's private key. 340 4. The binary signature is attached to the message. 342 5. The receiving software keeps a copy of the message signature. 344 6. The receiving software generates a new hash code for the 345 received message and verifies it using the message's signature. 346 If the verification is successful, the message is accepted as 347 authentic. 349 2.3. Compression 351 OpenPGP implementations SHOULD compress the message after applying 352 the signature but before encryption. 354 If an implementation does not implement compression, its authors 355 should be aware that most OpenPGP messages in the world are 356 compressed. Thus, it may even be wise for a space-constrained 357 implementation to implement decompression, but not compression. 359 Furthermore, compression has the added side-effect that some types 360 of attacks can be thwarted by the fact that slightly altered, 361 compressed data rarely uncompresses without severe errors. This is 362 hardly rigorous, but it is operationally useful. These attacks can 363 be rigorously prevented by implementing and using Modification 364 Detection Codes as described in sections following. 366 2.4. Conversion to Radix-64 368 OpenPGP's underlying native representation for encrypted messages, 369 signature certificates, and keys is a stream of arbitrary octets. 370 Some systems only permit the use of blocks consisting of seven-bit, 371 printable text. For transporting OpenPGP's native raw binary octets 372 through channels that are not safe to raw binary data, a printable 373 encoding of these binary octets is needed. OpenPGP provides the 374 service of converting the raw 8-bit binary octet stream to a stream 375 of printable ASCII characters, called Radix-64 encoding or ASCII 376 Armor. 378 Implementations SHOULD provide Radix-64 conversions. 380 2.5. Signature-Only Applications 382 OpenPGP is designed for applications that use both encryption and 383 signatures, but there are a number of problems that are solved by a 384 signature-only implementation. Although this specification requires 385 both encryption and signatures, it is reasonable for there to be 386 subset implementations that are non-conformant only in that they 387 omit encryption. 389 3. Data Element Formats 391 This section describes the data elements used by OpenPGP. 393 3.1. Scalar numbers 395 Scalar numbers are unsigned, and are always stored in big-endian 396 format. Using n[k] to refer to the kth octet being interpreted, the 397 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 398 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 399 n[3]). 401 3.2. Multiprecision Integers 403 Multiprecision Integers (also called MPIs) are unsigned integers 404 used to hold large integers such as the ones used in cryptographic 405 calculations. 407 An MPI consists of two pieces: a two-octet scalar that is the length 408 of the MPI in bits followed by a string of octets that contain the 409 actual integer. 411 These octets form a big-endian number; a big-endian number can be 412 made into an MPI by prefixing it with the appropriate length. 414 Examples: 416 (all numbers are in hexadecimal) 418 The string of octets [00 01 01] forms an MPI with the value 1. The 419 string [00 09 01 FF] forms an MPI with the value of 511. 421 Additional rules: 423 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 425 The length field of an MPI describes the length starting from its 426 most significant non-zero bit. Thus, the MPI [00 02 01] is not 427 formed correctly. It should be [00 01 01]. 429 Unused bits of an MPI MUST be zero. 431 Also note that when an MPI is encrypted, the length refers to the 432 plaintext MPI. It may be ill-formed in its ciphertext. 434 3.3. Key IDs 436 A Key ID is an eight-octet scalar that identifies a key. 437 Implementations SHOULD NOT assume that Key IDs are unique. The 438 section, "Enhanced Key Formats" below describes how Key IDs are 439 formed. 441 3.4. Text 443 Unless otherwise specified, the character set for text is the UTF-8 444 [RFC3629] encoding of Unicode [ISO10646]. 446 3.5. Time fields 448 A time field is an unsigned four-octet number containing the number 449 of seconds elapsed since midnight, 1 January 1970 UTC. 451 3.6. Keyrings 453 A keyring is a collection of one or more keys in a file or database. 454 Traditionally, a keyring is simply a sequential list of keys, but 455 may be any suitable database. It is beyond the scope of this 456 standard to discuss the details of keyrings or other databases. 458 3.7. String-to-key (S2K) specifiers 460 String-to-key (S2K) specifiers are used to convert passphrase 461 strings into symmetric-key encryption/decryption keys. They are used 462 in two places, currently: to encrypt the secret part of private keys 463 in the private keyring, and to convert passphrases to encryption 464 keys for symmetrically encrypted messages. 466 3.7.1. String-to-key (S2K) specifier types 468 There are three types of S2K specifiers currently supported, and 469 some reserved values: 471 ID S2K Type 472 -- --- ---- 473 0 Simple S2K 474 1 Salted S2K 475 2 Reserved value 476 3 Iterated and Salted S2K 477 100 to 110 Private/Experimental S2K 479 These are described as follows: 481 3.7.1.1. Simple S2K 483 This directly hashes the string to produce the key data. See below 484 for how this hashing is done. 486 Octet 0: 0x00 487 Octet 1: hash algorithm 489 Simple S2K hashes the passphrase to produce the session key. The 490 manner in which this is done depends on the size of the session key 491 (which will depend on the cipher used) and the size of the hash 492 algorithm's output. If the hash size is greater than the session key 493 size, the high-order (leftmost) octets of the hash are used as the 494 key. 496 If the hash size is less than the key size, multiple instances of 497 the hash context are created -- enough to produce the required key 498 data. These instances are preloaded with 0, 1, 2, ... octets of 499 zeros (that is to say, the first instance has no preloading, the 500 second gets preloaded with 1 octet of zero, the third is preloaded 501 with two octets of zeros, and so forth). 503 As the data is hashed, it is given independently to each hash 504 context. Since the contexts have been initialized differently, they 505 will each produce different hash output. Once the passphrase is 506 hashed, the output data from the multiple hashes is concatenated, 507 first hash leftmost, to produce the key data, with any excess octets 508 on the right discarded. 510 3.7.1.2. Salted S2K 512 This includes a "salt" value in the S2K specifier -- some arbitrary 513 data -- that gets hashed along with the passphrase string, to help 514 prevent dictionary attacks. 516 Octet 0: 0x01 517 Octet 1: hash algorithm 518 Octets 2-9: 8-octet salt value 520 Salted S2K is exactly like Simple S2K, except that the input to the 521 hash function(s) consists of the 8 octets of salt from the S2K 522 specifier, followed by the passphrase. 524 3.7.1.3. Iterated and Salted S2K 526 This includes both a salt and an octet count. The salt is combined 527 with the passphrase and the resulting value is hashed repeatedly. 528 This further increases the amount of work an attacker must do to try 529 dictionary attacks. 531 Octet 0: 0x03 532 Octet 1: hash algorithm 533 Octets 2-9: 8-octet salt value 534 Octet 10: count, a one-octet, coded value 536 The count is coded into a one-octet number using the following 537 formula: 539 #define EXPBIAS 6 540 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 542 The above formula is in C, where "Int32" is a type for a 32-bit 543 integer, and the variable "c" is the coded count, Octet 10. 545 Iterated-Salted S2K hashes the passphrase and salt data multiple 546 times. The total number of octets to be hashed is specified in the 547 encoded count in the S2K specifier. Note that the resulting count 548 value is an octet count of how many octets will be hashed, not an 549 iteration count. 551 Initially, one or more hash contexts are set up as with the other 552 S2K algorithms, depending on how many octets of key data are needed. 553 Then the salt, followed by the passphrase data is repeatedly hashed 554 until the number of octets specified by the octet count has been 555 hashed. The one exception is that if the octet count is less than 556 the size of the salt plus passphrase, the full salt plus passphrase 557 will be hashed even though that is greater than the octet count. 558 After the hashing is done the data is unloaded from the hash 559 context(s) as with the other S2K algorithms. 561 3.7.2. String-to-key usage 563 Implementations SHOULD use salted or iterated-and-salted S2K 564 specifiers, as simple S2K specifiers are more vulnerable to 565 dictionary attacks. 567 3.7.2.1. Secret key encryption 569 An S2K specifier can be stored in the secret keyring to specify how 570 to convert the passphrase to a key that unlocks the secret data. 571 Older versions of PGP just stored a cipher algorithm octet preceding 572 the secret data or a zero to indicate that the secret data was 573 unencrypted. The MD5 hash function was always used to convert the 574 passphrase to a key for the specified cipher algorithm. 576 For compatibility, when an S2K specifier is used, the special value 577 254 or 255 is stored in the position where the hash algorithm octet 578 would have been in the old data structure. This is then followed 579 immediately by a one-octet algorithm identifier, and then by the S2K 580 specifier as encoded above. 582 Therefore, preceding the secret data there will be one of these 583 possibilities: 585 0: secret data is unencrypted (no passphrase) 586 255 or 254: followed by algorithm octet and S2K specifier 587 Cipher alg: use Simple S2K algorithm using MD5 hash 589 This last possibility, the cipher algorithm number with an implicit 590 use of MD5 and IDEA, is provided for backward compatibility; it MAY 591 be understood, but SHOULD NOT be generated, and is deprecated. 593 These are followed by an Initial Vector of the same length as the 594 block size of the cipher for the decryption of the secret values, if 595 they are encrypted, and then the secret key values themselves. 597 3.7.2.2. Symmetric-key message encryption 599 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 600 packet at the front of a message. This is used to allow S2K 601 specifiers to be used for the passphrase conversion or to create 602 messages with a mix of symmetric-key ESKs and public-key ESKs. This 603 allows a message to be decrypted either with a passphrase or a 604 public key pair. 606 PGP 2.X always used IDEA with Simple string-to-key conversion when 607 encrypting a message with a symmetric algorithm. This is deprecated, 608 but MAY be used for backward-compatibility. 610 4. Packet Syntax 612 This section describes the packets used by OpenPGP. 614 4.1. Overview 616 An OpenPGP message is constructed from a number of records that are 617 traditionally called packets. A packet is a chunk of data that has a 618 tag specifying its meaning. An OpenPGP message, keyring, 619 certificate, and so forth consists of a number of packets. Some of 620 those packets may contain other OpenPGP packets (for example, a 621 compressed data packet, when uncompressed, contains OpenPGP 622 packets). 624 Each packet consists of a packet header, followed by the packet 625 body. The packet header is of variable length. 627 4.2. Packet Headers 629 The first octet of the packet header is called the "Packet Tag." It 630 determines the format of the header and denotes the packet contents. 631 The remainder of the packet header is the length of the packet. 633 Note that the most significant bit is the left-most bit, called bit 634 7. A mask for this bit is 0x80 in hexadecimal. 636 +---------------+ 637 PTag |7 6 5 4 3 2 1 0| 638 +---------------+ 639 Bit 7 -- Always one 640 Bit 6 -- New packet format if set 642 PGP 2.6.x only uses old format packets. Thus, software that 643 interoperates with those versions of PGP must only use old format 644 packets. If interoperability is not an issue, the new packet format 645 is preferred. Note that old format packets have four bits of packet 646 tags, and new format packets have six; some features cannot be used 647 and still be backward-compatible. 649 Also note that packets with a tag greater than or equal to 16 MUST 650 use new format packets. The old format packets can only express tags 651 less than or equal to 15. 653 Old format packets contain: 655 Bits 5-2 -- packet tag 656 Bits 1-0 - length-type 658 New format packets contain: 660 Bits 5-0 -- packet tag 662 4.2.1. Old-Format Packet Lengths 664 The meaning of the length-type in old-format packets is: 666 0 - The packet has a one-octet length. The header is 2 octets long. 668 1 - The packet has a two-octet length. The header is 3 octets long. 670 2 - The packet has a four-octet length. The header is 5 octets long. 672 3 - The packet is of indeterminate length. The header is 1 octet 673 long, and the implementation must determine how long the packet 674 is. If the packet is in a file, this means that the packet 675 extends until the end of the file. In general, an implementation 676 SHOULD NOT use indeterminate length packets except where the end 677 of the data will be clear from the context, and even then it is 678 better to use a definite length, or a new-format header. The 679 new-format headers described below have a mechanism for 680 precisely encoding data of indeterminate length. 682 4.2.2. New-Format Packet Lengths 684 New format packets have four possible ways of encoding length: 686 1. A one-octet Body Length header encodes packet lengths of up to 687 191 octets. 689 2. A two-octet Body Length header encodes packet lengths of 192 to 690 8383 octets. 692 3. A five-octet Body Length header encodes packet lengths of up to 693 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 694 encodes a four-octet scalar number.) 696 4. When the length of the packet body is not known in advance by 697 the issuer, Partial Body Length headers encode a packet of 698 indeterminate length, effectively making it a stream. 700 4.2.2.1. One-Octet Lengths 702 A one-octet Body Length header encodes a length of from 0 to 191 703 octets. This type of length header is recognized because the one 704 octet value is less than 192. The body length is equal to: 706 bodyLen = 1st_octet; 708 4.2.2.2. Two-Octet Lengths 710 A two-octet Body Length header encodes a length of from 192 to 8383 711 octets. It is recognized because its first octet is in the range 192 712 to 223. The body length is equal to: 714 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 716 4.2.2.3. Five-Octet Lengths 718 A five-octet Body Length header consists of a single octet holding 719 the value 255, followed by a four-octet scalar. The body length is 720 equal to: 722 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 723 (4th_octet << 8) | 5th_octet 725 This basic set of one, two, and five-octet lengths is also used 726 internally to some packets. 728 4.2.2.4. Partial Body Lengths 730 A Partial Body Length header is one octet long and encodes the 731 length of only part of the data packet. This length is a power of 2, 732 from 1 to 1,073,741,824 (2 to the 30th power). It is recognized by 733 its one octet value that is greater than or equal to 224, and less 734 than 255. The partial body length is equal to: 736 partialBodyLen = 1 << (1st_octet & 0x1f); 738 Each Partial Body Length header is followed by a portion of the 739 packet body data. The Partial Body Length header specifies this 740 portion's length. Another length header (one octet, two-octet, 741 five-octet, or partial) follows that portion. The last length header 742 in the packet MUST NOT be a partial Body Length header. Partial Body 743 Length headers may only be used for the non-final parts of the 744 packet. 746 Note also that the last Body Length header can be a zero-length 747 header. 749 An implementation MAY use Partial Body Lengths for data packets, be 750 they literal, compressed, or encrypted. The first partial length 751 MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 752 used for any other packet types. 754 4.2.3. Packet Length Examples 756 These examples show ways that new-format packets might encode the 757 packet lengths. 759 A packet with length 100 may have its length encoded in one octet: 760 0x64. This is followed by 100 octets of data. 762 A packet with length 1723 may have its length coded in two octets: 763 0xC5, 0xFB. This header is followed by the 1723 octets of data. 765 A packet with length 100000 may have its length encoded in five 766 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 768 It might also be encoded in the following octet stream: 0xEF, first 769 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 770 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 771 1693 octets of data. This is just one possible encoding, and many 772 variations are possible on the size of the Partial Body Length 773 headers, as long as a regular Body Length header encodes the last 774 portion of the data. 776 Please note that in all of these explanations, the total length of 777 the packet is the length of the header(s) plus the length of the 778 body. 780 4.3. Packet Tags 782 The packet tag denotes what type of packet the body holds. Note that 783 old format headers can only have tags less than 16, whereas new 784 format headers can have tags as great as 63. The defined tags (in 785 decimal) are: 787 0 -- Reserved - a packet tag MUST NOT have this value 788 1 -- Public-Key Encrypted Session Key Packet 789 2 -- Signature Packet 790 3 -- Symmetric-Key Encrypted Session Key Packet 791 4 -- One-Pass Signature Packet 792 5 -- Secret Key Packet 793 6 -- Public Key Packet 794 7 -- Secret Subkey Packet 795 8 -- Compressed Data Packet 796 9 -- Symmetrically Encrypted Data Packet 797 10 -- Marker Packet 798 11 -- Literal Data Packet 799 12 -- Trust Packet 800 13 -- User ID Packet 801 14 -- Public Subkey Packet 802 17 -- User Attribute Packet 803 18 -- Sym. Encrypted and Integrity Protected Data Packet 804 19 -- Modification Detection Code Packet 805 60 to 63 -- Private or Experimental Values 807 5. Packet Types 809 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 811 A Public-Key Encrypted Session Key packet holds the session key used 812 to encrypt a message. Zero or more Public-Key Encrypted Session Key 813 packets and/or Symmetric-Key Encrypted Session Key packets may 814 precede a Symmetrically Encrypted Data Packet, which holds an 815 encrypted message. The message is encrypted with the session key, 816 and the session key is itself encrypted and stored in the Encrypted 817 Session Key packet(s). The Symmetrically Encrypted Data Packet is 818 preceded by one Public-Key Encrypted Session Key packet for each 819 OpenPGP key to which the message is encrypted. The recipient of the 820 message finds a session key that is encrypted to their public key, 821 decrypts the session key, and then uses the session key to decrypt 822 the message. 824 The body of this packet consists of: 826 - A one-octet number giving the version number of the packet type. 827 The currently defined value for packet version is 3. 829 - An eight-octet number that gives the key ID of the public key 830 that the session key is encrypted to. If the session key is 831 encrypted to a subkey then the key ID of this subkey is used 832 here instead of the key ID of the primary key. 834 - A one-octet number giving the public key algorithm used. 836 - A string of octets that is the encrypted session key. This 837 string takes up the remainder of the packet, and its contents 838 are dependent on the public key algorithm used. 840 Algorithm Specific Fields for RSA encryption 842 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 844 Algorithm Specific Fields for Elgamal encryption: 846 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 848 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 850 The value "m" in the above formulas is derived from the session key 851 as follows. First the session key is prefixed with a one-octet 852 algorithm identifier that specifies the symmetric encryption 853 algorithm used to encrypt the following Symmetrically Encrypted Data 854 Packet. Then a two-octet checksum is appended which is equal to the 855 sum of the preceding session key octets, not including the algorithm 856 identifier, modulo 65536. This value is then encoded as described in 857 PKCS#1 block encoding EME-PKCS1-v1_5 in Section 12.1 of RFC 3447 to 858 form the "m" value used in the formulas above. See Section 13.1 of 859 this document for notes on OpenPGP's use of PKCS#1. 861 Note that when an implementation forms several PKESKs with one 862 session key, forming a message that can be decrypted by several 863 keys, the implementation MUST make a new PKCS#1 encoding for each 864 key. 866 An implementation MAY accept or use a Key ID of zero as a "wild 867 card" or "speculative" Key ID. In this case, the receiving 868 implementation would try all available private keys, checking for a 869 valid decrypted session key. This format helps reduce traffic 870 analysis of messages. 872 5.2. Signature Packet (Tag 2) 874 A signature packet describes a binding between some public key and 875 some data. The most common signatures are a signature of a file or a 876 block of text, and a signature that is a certification of a User ID. 878 Two versions of signature packets are defined. Version 3 provides 879 basic signature information, while version 4 provides an expandable 880 format with subpackets that can specify more information about the 881 signature. PGP 2.6.x only accepts version 3 signatures. 883 Implementations SHOULD accept V3 signatures. Implementations SHOULD 884 generate V4 signatures. 886 Note that if an implementation is creating an encrypted and signed 887 message that is encrypted to a V3 key, it is reasonable to create a 888 V3 signature. 890 5.2.1. Signature Types 892 There are a number of possible meanings for a signature, which are 893 indicated in a signature type octet in any given signature. Please 894 note that the vagueness of these meanings is not a flaw, but a 895 feature of the system. Because OpenPGP places final authority for 896 validity upon the receiver of a signature, it may be that one 897 signer's casual act might be more rigorous than some other 898 authority's positive act. See section 5.2.4, "Computing Signatures," 899 for detailed information on how to compute and verify signatures of 900 each type. 902 These meanings are: 904 0x00: Signature of a binary document. 905 This means the signer owns it, created it, or certifies that it 906 has not been modified. 908 0x01: Signature of a canonical text document. 909 This means the signer owns it, created it, or certifies that it 910 has not been modified. The signature is calculated over the text 911 data with its line endings converted to . 913 0x02: Standalone signature. 914 This signature is a signature of only its own subpacket 915 contents. It is calculated identically to a signature over a 916 zero-length binary document. Note that it doesn't make sense to 917 have a V3 standalone signature. 919 0x10: Generic certification of a User ID and Public Key packet. 920 The issuer of this certification does not make any particular 921 assertion as to how well the certifier has checked that the 922 owner of the key is in fact the person described by the User ID. 924 0x11: Persona certification of a User ID and Public Key packet. 925 The issuer of this certification has not done any verification 926 of the claim that the owner of this key is the User ID 927 specified. 929 0x12: Casual certification of a User ID and Public Key packet. 930 The issuer of this certification has done some casual 931 verification of the claim of identity. 933 0x13: Positive certification of a User ID and Public Key packet. 934 The issuer of this certification has done substantial 935 verification of the claim of identity. 937 Most OpenPGP implementations make their "key signatures" as 0x10 938 certifications. Some implementations can issue 0x11-0x13 939 certifications, but few differentiate between the types. 941 0x18: Subkey Binding Signature 942 This signature is a statement by the top-level signing key that 943 indicates that it owns the subkey. This signature is calculated 944 directly on the primary key and subkey, and not on any User ID 945 or other packets. A signature that binds a signing subkey MUST 946 have an embedded signature subpacket in this binding signature 947 which contains a 0x19 signature made by the signing subkey on 948 the primary key and subkey. 950 0x19 Primary Key Binding Signature 951 This signature is a statement by a signing subkey, indicating 952 that it is owned by the primary key and subkey. This signature 953 is calculated the same way as a 0x18 signature: directly on the 954 primary key and subkey, and not on any User ID or other packets. 956 0x1F: Signature directly on a key 957 This signature is calculated directly on a key. It binds the 958 information in the signature subpackets to the key, and is 959 appropriate to be used for subpackets that provide information 960 about the key, such as the revocation key subpacket. It is also 961 appropriate for statements that non-self certifiers want to make 962 about the key itself, rather than the binding between a key and 963 a name. 965 0x20: Key revocation signature 966 The signature is calculated directly on the key being revoked. A 967 revoked key is not to be used. Only revocation signatures by the 968 key being revoked, or by an authorized revocation key, should be 969 considered valid revocation signatures. 971 0x28: Subkey revocation signature 972 The signature is calculated directly on the subkey being 973 revoked. A revoked subkey is not to be used. Only revocation 974 signatures by the top-level signature key that is bound to this 975 subkey, or by an authorized revocation key, should be considered 976 valid revocation signatures. 978 0x30: Certification revocation signature 979 This signature revokes an earlier User ID certification 980 signature (signature class 0x10 through 0x13) or direct-key 981 signature (0x1F). It should be issued by the same key that 982 issued the revoked signature or an authorized revocation key. 983 The signature is computed over the same data as the certificate 984 that it revokes, and should have a later creation date than that 985 certificate. 987 0x40: Timestamp signature. 988 This signature is only meaningful for the timestamp contained in 989 it. 991 0x50: Third-Party Confirmation signature. 992 This signature is a signature over some other OpenPGP signature 993 packet(s). It is analogous to a notary seal on the signed data. 994 A third-party signature SHOULD include Signature Target 995 subpacket(s) to give easy identification. Note that we really do 996 mean SHOULD. There are plausible uses for this (such as a blind 997 party that only sees the signature, not the key nor source 998 document) that cannot include a target subpacket. 1000 5.2.2. Version 3 Signature Packet Format 1002 The body of a version 3 Signature Packet contains: 1004 - One-octet version number (3). 1006 - One-octet length of following hashed material. MUST be 5. 1008 - One-octet signature type. 1010 - Four-octet creation time. 1012 - Eight-octet key ID of signer. 1014 - One-octet public key algorithm. 1016 - One-octet hash algorithm. 1018 - Two-octet field holding left 16 bits of signed hash value. 1020 - One or more multiprecision integers comprising the signature. 1021 This portion is algorithm specific, as described below. 1023 The concatenation of the data to be signed, the signature type and 1024 creation time from the signature packet (5 additional octets) is 1025 hashed. The resulting hash value is used in the signature algorithm. 1026 The high 16 bits (first two octets) of the hash are included in the 1027 signature packet to provide a quick test to reject some invalid 1028 signatures. 1030 Algorithm Specific Fields for RSA signatures: 1032 - multiprecision integer (MPI) of RSA signature value m**d mod n. 1034 Algorithm Specific Fields for DSA signatures: 1036 - MPI of DSA value r. 1038 - MPI of DSA value s. 1040 The signature calculation is based on a hash of the signed data, as 1041 described above. The details of the calculation are different for 1042 DSA signatures than for RSA signatures. 1044 With RSA signatures, the hash value is encoded as described in 1045 PKCS#1 section 9.2.1 of RFC 3447 encoded using PKCS#1 encoding type 1046 EMSA-PKCS1-v1_5 as described in section 12.1 of RFC 3447. This 1047 requires inserting the hash value as an octet string into an ASN.1 1048 structure. The object identifier for the type of hash being used is 1049 included in the structure. The hexadecimal representations for the 1050 currently defined hash algorithms are: 1052 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 1054 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 1056 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 1058 - SHA224: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 1060 - SHA256: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 1062 - SHA384: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 1064 - SHA512: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 1066 The ASN.1 OIDs are: 1068 - MD5: 1.2.840.113549.2.5 1070 - RIPEMD-160: 1.3.36.3.2.1 1072 - SHA-1: 1.3.14.3.2.26 1074 - SHA224: 2.16.840.1.101.3.4.2.4 1076 - SHA256: 2.16.840.1.101.3.4.2.1 1078 - SHA384: 2.16.840.1.101.3.4.2.2 1080 - SHA512: 2.16.840.1.101.3.4.2.3 1082 The full hash prefixes for these are: 1084 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 1085 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 1086 0x04, 0x10 1088 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 1089 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 1091 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 1092 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 1094 SHA224: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1095 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 1096 0x00, 0x04, 0x1C 1098 SHA256: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1099 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 1100 0x00, 0x04, 0x20 1102 SHA384: 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1103 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 1104 0x00, 0x04, 0x30 1106 SHA512: 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1107 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 1108 0x00, 0x04, 0x40 1110 DSA signatures MUST use hashes that are equal in size to the number 1111 of bits of q, the group generated by the DSA key's generator value. 1112 If the output size of the chosen hash is larger than the number of 1113 bits of q, the hash result is truncated to fit by taking the number 1114 of leftmost bits equal to the number of bits of q. This (possibly 1115 truncated) hash function result is treated as a number and used 1116 directly in the DSA signature algorithm. 1118 5.2.3. Version 4 Signature Packet Format 1120 The body of a version 4 Signature Packet contains: 1122 - One-octet version number (4). 1124 - One-octet signature type. 1126 - One-octet public key algorithm. 1128 - One-octet hash algorithm. 1130 - Two-octet scalar octet count for following hashed subpacket 1131 data. Note that this is the length in octets of all of the 1132 hashed subpackets; a pointer incremented by this number will 1133 skip over the hashed subpackets. 1135 - Hashed subpacket data set. (zero or more subpackets) 1137 - Two-octet scalar octet count for the following unhashed 1138 subpacket data. Note that this is the length in octets of all of 1139 the unhashed subpackets; a pointer incremented by this number 1140 will skip over the unhashed subpackets. 1142 - Unhashed subpacket data set. (zero or more subpackets) 1143 - Two-octet field holding the left 16 bits of the signed hash 1144 value. 1146 - One or more multiprecision integers comprising the signature. 1147 This portion is algorithm specific, as described above. 1149 The concatenation of the data being signed and the signature data 1150 from the version number through the hashed subpacket data 1151 (inclusive) is hashed. The resulting hash value is what is signed. 1152 The left 16 bits of the hash are included in the signature packet to 1153 provide a quick test to reject some invalid signatures. 1155 There are two fields consisting of signature subpackets. The first 1156 field is hashed with the rest of the signature data, while the 1157 second is unhashed. The second set of subpackets is not 1158 cryptographically protected by the signature and should include only 1159 advisory information. 1161 The algorithms for converting the hash function result to a 1162 signature are described in a section below. 1164 5.2.3.1. Signature Subpacket Specification 1166 A subpacket data set consists of zero or more signature subpackets. 1167 In signature packets the subpacket data set is preceded by a 1168 two-octet scalar count of the length in octets of all the 1169 subpackets. A pointer incremented by this number will skip over the 1170 subpacket data set. 1172 Each subpacket consists of a subpacket header and a body. The header 1173 consists of: 1175 - the subpacket length (1, 2, or 5 octets) 1177 - the subpacket type (1 octet) 1179 and is followed by the subpacket specific data. 1181 The length includes the type octet but not this length. Its format 1182 is similar to the "new" format packet header lengths, but cannot 1183 have partial body lengths. That is: 1185 if the 1st octet < 192, then 1186 lengthOfLength = 1 1187 subpacketLen = 1st_octet 1189 if the 1st octet >= 192 and < 255, then 1190 lengthOfLength = 2 1191 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1193 if the 1st octet = 255, then 1194 lengthOfLength = 5 1195 subpacket length = [four-octet scalar starting at 2nd_octet] 1197 The value of the subpacket type octet may be: 1199 2 = signature creation time 1200 3 = signature expiration time 1201 4 = exportable certification 1202 5 = trust signature 1203 6 = regular expression 1204 7 = revocable 1205 9 = key expiration time 1206 10 = placeholder for backward compatibility 1207 11 = preferred symmetric algorithms 1208 12 = revocation key 1209 16 = issuer key ID 1210 20 = notation data 1211 21 = preferred hash algorithms 1212 22 = preferred compression algorithms 1213 23 = key server preferences 1214 24 = preferred key server 1215 25 = primary User ID 1216 26 = policy URI 1217 27 = key flags 1218 28 = signer's User ID 1219 29 = reason for revocation 1220 30 = features 1221 31 = signature target 1222 32 = embedded signature 1224 100 to 110 = private or experimental 1226 An implementation SHOULD ignore any subpacket of a type that it does 1227 not recognize. 1229 Bit 7 of the subpacket type is the "critical" bit. If set, it 1230 denotes that the subpacket is one that is critical for the evaluator 1231 of the signature to recognize. If a subpacket is encountered that is 1232 marked critical but is unknown to the evaluating software, the 1233 evaluator SHOULD consider the signature to be in error. 1235 An evaluator may "recognize" a subpacket, but not implement it. The 1236 purpose of the critical bit is to allow the signer to tell an 1237 evaluator that it would prefer a new, unknown feature to generate an 1238 error than be ignored. 1240 Implementations SHOULD implement "preferences" and the "reason for 1241 revocation" subpackets. Note, however, that if an implementation 1242 chooses not to implement some of the preferences, it is required to 1243 behave in a polite manner to respect the wishes of those users who 1244 do implement these preferences. 1246 5.2.3.2. Signature Subpacket Types 1248 A number of subpackets are currently defined. Some subpackets apply 1249 to the signature itself and some are attributes of the key. 1250 Subpackets that are found on a self-signature are placed on a 1251 certification made by the key itself. Note that a key may have more 1252 than one User ID, and thus may have more than one self-signature, 1253 and differing subpackets. 1255 A subpacket may be found either in the hashed or unhashed subpacket 1256 sections of a signature. If a subpacket is not hashed, then the 1257 information in it cannot be considered definitive because it is not 1258 part of the signature proper. 1260 5.2.3.3. Notes on Self-Signatures 1262 A self-signature is a binding signature made by the key the 1263 signature refers to. There are three types of self-signatures, the 1264 certification signatures (types 0x10-0x13), the direct-key signature 1265 (type 0x1f), and the subkey binding signature (type 0x18). For 1266 certification self-signatures, each User ID may have a 1267 self-signature, and thus different subpackets in those 1268 self-signatures. For subkey binding signatures, each subkey in fact 1269 has a self-signature. Subpackets that appear in a certification 1270 self-signature apply to the username, and subpackets that appear in 1271 the subkey self-signature apply to the subkey. Lastly, subpackets on 1272 the direct-key signature apply to the entire key. 1274 Implementing software should interpret a self-signature's preference 1275 subpackets as narrowly as possible. For example, suppose a key has 1276 two usernames, Alice and Bob. Suppose that Alice prefers the 1277 symmetric algorithm CAST5, and Bob prefers IDEA or TripleDES. If the 1278 software locates this key via Alice's name, then the preferred 1279 algorithm is CAST5, if software locates the key via Bob's name, then 1280 the preferred algorithm is IDEA. If the key is located by key ID, 1281 the algorithm of the primary User ID of the key provides the 1282 preferred symmetric algorithm. 1284 Revoking a self-signature or allowing it to expire has a semantic 1285 meaning that varies with the signature type. Revoking the 1286 self-signature on a User ID effectively retires that user name. The 1287 self-signature is a statement, "My name X is tied to my signing key 1288 K" and is corroborated by other users' certifications. If another 1289 user revokes their certification, they are effectively saying that 1290 they no longer believe that name and that key are tied together. 1291 Similarly, if the user themselves revokes their self-signature, it 1292 means the user no longer goes by that name, no longer has that email 1293 address, etc. Revoking a binding signature effectively retires that 1294 subkey. Revoking a direct-key signature cancels that signature. 1295 Please see the "Reason for Revocation" subpacket below for more 1296 relevant detail. 1298 Since a self-signature contains important information about the 1299 key's use, an implementation SHOULD allow the user to rewrite the 1300 self-signature, and important information in it, such as preferences 1301 and key expiration. 1303 It is good practice to verify that a self-signature imported into an 1304 implementation doesn't advertise features that the implementation 1305 doesn't support, rewriting the signature as appropriate. 1307 An implementation that encounters multiple self-signatures on the 1308 same object may resolve the ambiguity in any way it sees fit, but it 1309 is RECOMMENDED that priority be given to the most recent 1310 self-signature. 1312 5.2.3.4. Signature creation time 1314 (4 octet time field) 1316 The time the signature was made. 1318 MUST be present in the hashed area. 1320 5.2.3.5. Issuer 1322 (8 octet key ID) 1324 The OpenPGP key ID of the key issuing the signature. 1326 5.2.3.6. Key expiration time 1328 (4 octet time field) 1330 The validity period of the key. This is the number of seconds after 1331 the key creation time that the key expires. If this is not present 1332 or has a value of zero, the key never expires. This is found only on 1333 a self-signature. 1335 5.2.3.7. Preferred symmetric algorithms 1337 (array of one-octet values) 1339 Symmetric algorithm numbers that indicate which algorithms the key 1340 holder prefers to use. The subpacket body is an ordered list of 1341 octets with the most preferred listed first. It is assumed that only 1342 algorithms listed are supported by the recipient's software. 1343 Algorithm numbers are in section 9. This is only found on a 1344 self-signature. 1346 5.2.3.8. Preferred hash algorithms 1348 (array of one-octet values) 1349 Message digest algorithm numbers that indicate which algorithms the 1350 key holder prefers to receive. Like the preferred symmetric 1351 algorithms, the list is ordered. Algorithm numbers are in section 9. 1352 This is only found on a self-signature. 1354 5.2.3.9. Preferred compression algorithms 1356 (array of one-octet values) 1358 Compression algorithm numbers that indicate which algorithms the key 1359 holder prefers to use. Like the preferred symmetric algorithms, the 1360 list is ordered. Algorithm numbers are in section 9. If this 1361 subpacket is not included, ZIP is preferred. A zero denotes that 1362 uncompressed data is preferred; the key holder's software might have 1363 no compression software in that implementation. This is only found 1364 on a self-signature. 1366 5.2.3.10. Signature expiration time 1368 (4 octet time field) 1370 The validity period of the signature. This is the number of seconds 1371 after the signature creation time that the signature expires. If 1372 this is not present or has a value of zero, it never expires. 1374 5.2.3.11. Exportable Certification 1376 (1 octet of exportability, 0 for not, 1 for exportable) 1378 This subpacket denotes whether a certification signature is 1379 "exportable," to be used by other users than the signature's issuer. 1380 The packet body contains a Boolean flag indicating whether the 1381 signature is exportable. If this packet is not present, the 1382 certification is exportable; it is equivalent to a flag containing a 1383 1. 1385 Non-exportable, or "local," certifications are signatures made by a 1386 user to mark a key as valid within that user's implementation only. 1387 Thus, when an implementation prepares a user's copy of a key for 1388 transport to another user (this is the process of "exporting" the 1389 key), any local certification signatures are deleted from the key. 1391 The receiver of a transported key "imports" it, and likewise trims 1392 any local certifications. In normal operation, there won't be any, 1393 assuming the import is performed on an exported key. However, there 1394 are instances where this can reasonably happen. For example, if an 1395 implementation allows keys to be imported from a key database in 1396 addition to an exported key, then this situation can arise. 1398 Some implementations do not represent the interest of a single user 1399 (for example, a key server). Such implementations always trim local 1400 certifications from any key they handle. 1402 5.2.3.12. Revocable 1404 (1 octet of revocability, 0 for not, 1 for revocable) 1406 Signature's revocability status. The packet body contains a Boolean 1407 flag indicating whether the signature is revocable. Signatures that 1408 are not revocable have any later revocation signatures ignored. They 1409 represent a commitment by the signer that he cannot revoke his 1410 signature for the life of his key. If this packet is not present, 1411 the signature is revocable. 1413 5.2.3.13. Trust signature 1415 (1 octet "level" (depth), 1 octet of trust amount) 1417 Signer asserts that the key is not only valid, but also trustworthy, 1418 at the specified level. Level 0 has the same meaning as an ordinary 1419 validity signature. Level 1 means that the signed key is asserted to 1420 be a valid trusted introducer, with the 2nd octet of the body 1421 specifying the degree of trust. Level 2 means that the signed key is 1422 asserted to be trusted to issue level 1 trust signatures, i.e. that 1423 it is a "meta introducer". Generally, a level n trust signature 1424 asserts that a key is trusted to issue level n-1 trust signatures. 1425 The trust amount is in a range from 0-255, interpreted such that 1426 values less than 120 indicate partial trust and values of 120 or 1427 greater indicate complete trust. Implementations SHOULD emit values 1428 of 60 for partial trust and 120 for complete trust. 1430 5.2.3.14. Regular expression 1432 (null-terminated regular expression) 1434 Used in conjunction with trust signature packets (of level > 0) to 1435 limit the scope of trust that is extended. Only signatures by the 1436 target key on User IDs that match the regular expression in the body 1437 of this packet have trust extended by the trust signature subpacket. 1438 The regular expression uses the same syntax as the Henry Spencer's 1439 "almost public domain" regular expression package. A description of 1440 the syntax is found in a section below. 1442 5.2.3.15. Revocation key 1444 (1 octet of class, 1 octet of PK algorithm ID, 20 octets of 1445 fingerprint) 1447 Authorizes the specified key to issue revocation signatures for this 1448 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1449 then this means that the revocation information is sensitive. Other 1450 bits are for future expansion to other kinds of authorizations. This 1451 is found on a self-signature. 1453 If the "sensitive" flag is set, the keyholder feels this subpacket 1454 contains private trust information that describes a real-world 1455 sensitive relationship. If this flag is set, implementations SHOULD 1456 NOT export this signature to other users except in cases where the 1457 data needs to be available: when the signature is being sent to the 1458 designated revoker, or when it is accompanied by a revocation 1459 signature from that revoker. Note that it may be appropriate to 1460 isolate this subpacket within a separate signature so that it is not 1461 combined with other subpackets that need to be exported. 1463 5.2.3.16. Notation Data 1465 (4 octets of flags, 2 octets of name length (M), 1466 2 octets of value length (N), 1467 M octets of name data, 1468 N octets of value data) 1470 This subpacket describes a "notation" on the signature that the 1471 issuer wishes to make. The notation has a name and a value, each of 1472 which are strings of octets. There may be more than one notation in 1473 a signature. Notations can be used for any extension the issuer of 1474 the signature cares to make. The "flags" field holds four octets of 1475 flags. 1477 All undefined flags MUST be zero. Defined flags are: 1479 First octet: 0x80 = human-readable. This note value is text. 1480 Other octets: none. 1482 Notation names are arbitrary strings encoded in UTF-8. They reside 1483 two name spaces: The IETF name space and the user name space. 1485 The IETF name space is registered with IANA. These names MUST NOT 1486 contain the "@" character (0x40). This this is a tag for the user 1487 name space. 1489 Names in the user name space consist of a UTF-8 string tag followed 1490 by "@" followed by a DNS domain name. Note that the tag MUST NOT 1491 contain an "@" character. For example, the "sample" tag used by 1492 Example Corporation could be "sample@example.com". 1494 Names in a user space are owned and controlled by the owners of that 1495 domain. Obviously, it's of bad form to create a new name in a DNS 1496 space that you don't own. 1498 Since the user name space is in the form of an email address, 1499 implementers MAY wish to arrange for that address to reach a person 1500 who can be consulted about the use of the named tag. Note that due 1501 to UTF-8 encoding, not all valid user space name tags are valid 1502 email addresses. 1504 If there is a critical notation, the criticality applies to that 1505 specific notation and not to notations in general. 1507 5.2.3.17. Key server preferences 1509 (N octets of flags) 1511 This is a list of one-bit flags that indicate preferences that the 1512 key holder has about how the key is handled on a key server. All 1513 undefined flags MUST be zero. 1515 First octet: 0x80 = No-modify 1516 the key holder requests that this key only be modified or 1517 updated by the key holder or an administrator of the key server. 1519 This is found only on a self-signature. 1521 5.2.3.18. Preferred key server 1523 (String) 1525 This is a URI of a key server that the key holder prefers be used 1526 for updates. Note that keys with multiple User IDs can have a 1527 preferred key server for each User ID. Note also that since this is 1528 a URI, the key server can actually be a copy of the key retrieved by 1529 ftp, http, finger, etc. 1531 5.2.3.19. Primary User ID 1533 (1 octet, Boolean) 1535 This is a flag in a User ID's self signature that states whether 1536 this User ID is the main User ID for this key. It is reasonable for 1537 an implementation to resolve ambiguities in preferences, etc. by 1538 referring to the primary User ID. If this flag is absent, its value 1539 is zero. If more than one User ID in a key is marked as primary, the 1540 implementation may resolve the ambiguity in any way it sees fit, but 1541 it is RECOMMENDED that priority be given to the User ID with the 1542 most recent self-signature. 1544 When appearing on a self-signature on a User ID packet, this 1545 subpacket applies only to User ID packets. When appearing on a 1546 self-signature on a User Attribute packet, this subpacket applies 1547 only to User Attribute packets. That is to say, there are two 1548 different and independent "primaries" - one for User IDs, and one 1549 for User Attributes. 1551 5.2.3.20. Policy URI 1553 (String) 1554 This subpacket contains a URI of a document that describes the 1555 policy that the signature was issued under. 1557 5.2.3.21. Key Flags 1559 (N octets of flags) 1561 This subpacket contains a list of binary flags that hold information 1562 about a key. It is a string of octets, and an implementation MUST 1563 NOT assume a fixed size. This is so it can grow over time. If a list 1564 is shorter than an implementation expects, the unstated flags are 1565 considered to be zero. The defined flags are: 1567 First octet: 1569 0x01 - This key may be used to certify other keys. 1571 0x02 - This key may be used to sign data. 1573 0x04 - This key may be used to encrypt communications. 1575 0x08 - This key may be used to encrypt storage. 1577 0x10 - The private component of this key may have been split by 1578 a secret-sharing mechanism. 1580 0x20 - This key may be used for authentication. 1582 0x80 - The private component of this key may be in the 1583 possession of more than one person. 1585 Usage notes: 1587 The flags in this packet may appear in self-signatures or in 1588 certification signatures. They mean different things depending on 1589 who is making the statement -- for example, a certification 1590 signature that has the "sign data" flag is stating that the 1591 certification is for that use. On the other hand, the 1592 "communications encryption" flag in a self-signature is stating a 1593 preference that a given key be used for communications. Note 1594 however, that it is a thorny issue to determine what is 1595 "communications" and what is "storage." This decision is left wholly 1596 up to the implementation; the authors of this document do not claim 1597 any special wisdom on the issue, and realize that accepted opinion 1598 may change. 1600 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1601 self-signature only; they are meaningless on a certification 1602 signature. They SHOULD be placed only on a direct-key signature 1603 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1604 the key the flag applies to. 1606 5.2.3.22. Signer's User ID 1608 (String) 1610 This subpacket allows a keyholder to state which User ID is 1611 responsible for the signing. Many keyholders use a single key for 1612 different purposes, such as business communications as well as 1613 personal communications. This subpacket allows such a keyholder to 1614 state which of their roles is making a signature. 1616 This subpacket is not appropriate to use to refer to a User 1617 Attribute packet. 1619 5.2.3.23. Reason for Revocation 1621 (1 octet of revocation code, N octets of reason string) 1623 This subpacket is used only in key revocation and certification 1624 revocation signatures. It describes the reason why the key or 1625 certificate was revoked. 1627 The first octet contains a machine-readable code that denotes the 1628 reason for the revocation: 1630 0x00 - No reason specified (key revocations or cert revocations) 1631 0x01 - Key is superseded (key revocations) 1632 0x02 - Key material has been compromised (key revocations) 1633 0x03 - Key is retired and no longer used (key revocations) 1634 0x20 - User ID information is no longer valid (cert revocations) 1636 Following the revocation code is a string of octets which gives 1637 information about the reason for revocation in human-readable form 1638 (UTF-8). The string may be null, that is, of zero length. The length 1639 of the subpacket is the length of the reason string plus one. 1641 An implementation SHOULD implement this subpacket, include it in all 1642 revocation signatures, and interpret revocations appropriately. 1643 There are important semantic differences between the reasons, and 1644 there are thus important reasons for revoking signatures. 1646 If a key has been revoked because of a compromise, all signatures 1647 created by that key are suspect. However, if it was merely 1648 superseded or retired, old signatures are still valid. If the 1649 revoked signature is the self-signature for certifying a User ID, a 1650 revocation denotes that that user name is no longer in use. Such a 1651 revocation SHOULD include an 0x20 code. 1653 Note that any signature may be revoked, including a certification on 1654 some other person's key. There are many good reasons for revoking a 1655 certification signature, such as the case where the keyholder leaves 1656 the employ of a business with an email address. A revoked 1657 certification is no longer a part of validity calculations. 1659 5.2.3.24. Features 1661 (N octets of flags) 1663 The features subpacket denotes which advanced OpenPGP features a 1664 user's implementation supports. This is so that as features are 1665 added to OpenPGP that cannot be backwards-compatible, a user can 1666 state that they can use that feature. The flags are single bits that 1667 indicate that a given feature is supported. 1669 This subpacket is similar to a preferences subpacket, and only 1670 appears in a self-signature. 1672 An implementation SHOULD NOT use a feature listed when sending to a 1673 user who does not state that they can use it. 1675 Defined features are: 1677 First octet: 1679 0x01 - Modification Detection (packets 18 and 19) 1681 If an implementation implements any of the defined features, it 1682 SHOULD implement the features subpacket, too. 1684 An implementation may freely infer features from other suitable 1685 implementation-dependent mechanisms. 1687 5.2.3.25. Signature Target 1689 (1 octet PK algorithm, 1 octet hash algorithm, N octets hash) 1691 This subpacket identifies a specific target signature that a 1692 signature refers to. For revocation signatures, this subpacket 1693 provides explicit designation of which signature is being revoked. 1694 For a third-party or timestamp signature, this designates what 1695 signature is signed. All arguments are an identifier of that target 1696 signature. 1698 The N octets of hash data MUST be the size of the hash of the 1699 signature. For example, a target signature with a SHA-1 hash MUST 1700 have 20 octets of hash data. 1702 5.2.3.26. Embedded Signature 1704 (1 signature packet body) 1706 This subpacket contains a complete signature packet body as 1707 specified in section 5.2 above. It is useful when one signature 1708 needs to refer to, or be incorporated in, another signature. 1710 5.2.4. Computing Signatures 1712 All signatures are formed by producing a hash over the signature 1713 data, and then using the resulting hash in the signature algorithm. 1715 For binary document signatures (type 0x00), the document data is 1716 hashed directly. For text document signatures (type 0x01), the 1717 document is canonicalized by converting line endings to , 1718 and the resulting data is hashed. 1720 When a signature is made over a key, the hash data starts with the 1721 octet 0x99, followed by a two-octet length of the key, and then body 1722 of the key packet. (Note that this is an old-style packet header for 1723 a key packet with two-octet length.) A subkey binding signature 1724 (type 0x18) or primary key binding signature (type 0x19) then hashes 1725 the subkey using the same format as the main key (also using 0x99 as 1726 the first octet). Key revocation signatures (types 0x20 and 0x28) 1727 hash only the key being revoked. 1729 A certification signature (type 0x10 through 0x13) hashes the User 1730 ID being bound to the key into the hash context after the above 1731 data. A V3 certification hashes the contents of the User ID or 1732 attribute packet packet, without any header. A V4 certification 1733 hashes the constant 0xb4 for User ID certifications or the constant 1734 0xd1 for User Attribute certifications, followed by a four-octet 1735 number giving the length of the User ID or User Attribute data, and 1736 then the User ID or User Attribute data. 1738 When a signature is made over a signature packet (type 0x50), the 1739 hash data starts with the octet 0x88, followed by the four-octet 1740 length of the signature, and then the body of the signature packet. 1741 (Note that this is an old-style packet header for a signature packet 1742 with the length-of-length set to zero). The unhashed subpacket data 1743 of the signature packet being hashed is not included in the hash and 1744 the unhashed subpacket data length value is set to zero. 1746 Once the data body is hashed, then a trailer is hashed. A V3 1747 signature hashes five octets of the packet body, starting from the 1748 signature type field. This data is the signature type, followed by 1749 the four-octet signature time. A V4 signature hashes the packet body 1750 starting from its first field, the version number, through the end 1751 of the hashed subpacket data. Thus, the fields hashed are the 1752 signature version, the signature type, the public key algorithm, the 1753 hash algorithm, the hashed subpacket length, and the hashed 1754 subpacket body. 1756 V4 signatures also hash in a final trailer of six octets: the 1757 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1758 big-endian number that is the length of the hashed data from the 1759 signature packet (note that this number does not include these final 1760 six octets. 1762 After all this has been hashed in a single hash context the 1763 resulting hash field is used in the signature algorithm, and placed 1764 at the end of the signature packet. 1766 5.2.4.1. Subpacket Hints 1768 It is certainly possible for a signature to contain conflicting 1769 information in subpackets. For example, a signature may contain 1770 multiple copies of a preference or multiple expiration times. In 1771 most cases, an implementation SHOULD use the last subpacket in the 1772 signature, but MAY use any conflict resolution scheme that makes 1773 more sense. Please note that we are intentionally leaving conflict 1774 resolution to the implementer; most conflicts are simply syntax 1775 errors, and the wishy-washy language here allows a receiver to be 1776 generous in what they accept, while putting pressure on a creator to 1777 be stingy in what they generate. 1779 Some apparent conflicts may actually make sense -- for example, 1780 suppose a keyholder has an V3 key and a V4 key that share the same 1781 RSA key material. Either of these keys can verify a signature 1782 created by the other, and it may be reasonable for a signature to 1783 contain an issuer subpacket for each key, as a way of explicitly 1784 tying those keys to the signature. 1786 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) 1788 The Symmetric-Key Encrypted Session Key packet holds the 1789 symmetric-key encryption of a session key used to encrypt a message. 1790 Zero or more Public-Key Encrypted Session Key packets and/or 1791 Symmetric-Key Encrypted Session Key packets may precede a 1792 Symmetrically Encrypted Data Packet that holds an encrypted message. 1793 The message is encrypted with a session key, and the session key is 1794 itself encrypted and stored in the Encrypted Session Key packet or 1795 the Symmetric-Key Encrypted Session Key packet. 1797 If the Symmetrically Encrypted Data Packet is preceded by one or 1798 more Symmetric-Key Encrypted Session Key packets, each specifies a 1799 passphrase that may be used to decrypt the message. This allows a 1800 message to be encrypted to a number of public keys, and also to one 1801 or more passphrases. This packet type is new, and is not generated 1802 by PGP 2.x or PGP 5.0. 1804 The body of this packet consists of: 1806 - A one-octet version number. The only currently defined version 1807 is 4. 1809 - A one-octet number describing the symmetric algorithm used. 1811 - A string-to-key (S2K) specifier, length as defined above. 1813 - Optionally, the encrypted session key itself, which is decrypted 1814 with the string-to-key object. 1816 If the encrypted session key is not present (which can be detected 1817 on the basis of packet length and S2K specifier size), then the S2K 1818 algorithm applied to the passphrase produces the session key for 1819 decrypting the file, using the symmetric cipher algorithm from the 1820 Symmetric-Key Encrypted Session Key packet. 1822 If the encrypted session key is present, the result of applying the 1823 S2K algorithm to the passphrase is used to decrypt just that 1824 encrypted session key field, using CFB mode with an IV of all zeros. 1825 The decryption result consists of a one-octet algorithm identifier 1826 that specifies the symmetric-key encryption algorithm used to 1827 encrypt the following Symmetrically Encrypted Data Packet, followed 1828 by the session key octets themselves. 1830 Note: because an all-zero IV is used for this decryption, the S2K 1831 specifier MUST use a salt value, either a Salted S2K or an 1832 Iterated-Salted S2K. The salt value will insure that the decryption 1833 key is not repeated even if the passphrase is reused. 1835 5.4. One-Pass Signature Packets (Tag 4) 1837 The One-Pass Signature packet precedes the signed data and contains 1838 enough information to allow the receiver to begin calculating any 1839 hashes needed to verify the signature. It allows the Signature 1840 Packet to be placed at the end of the message, so that the signer 1841 can compute the entire signed message in one pass. 1843 A One-Pass Signature does not interoperate with PGP 2.6.x or 1844 earlier. 1846 The body of this packet consists of: 1848 - A one-octet version number. The current version is 3. 1850 - A one-octet signature type. Signature types are described in 1851 section 5.2.1. 1853 - A one-octet number describing the hash algorithm used. 1855 - A one-octet number describing the public key algorithm used. 1857 - An eight-octet number holding the key ID of the signing key. 1859 - A one-octet number holding a flag showing whether the signature 1860 is nested. A zero value indicates that the next packet is 1861 another One-Pass Signature packet that describes another 1862 signature to be applied to the same message data. 1864 Note that if a message contains more than one one-pass signature, 1865 then the signature packets bracket the message; that is, the first 1866 signature packet after the message corresponds to the last one-pass 1867 packet and the final signature packet corresponds to the first 1868 one-pass packet. 1870 5.5. Key Material Packet 1872 A key material packet contains all the information about a public or 1873 private key. There are four variants of this packet type, and two 1874 major versions. Consequently, this section is complex. 1876 5.5.1. Key Packet Variants 1878 5.5.1.1. Public Key Packet (Tag 6) 1880 A Public Key packet starts a series of packets that forms an OpenPGP 1881 key (sometimes called an OpenPGP certificate). 1883 5.5.1.2. Public Subkey Packet (Tag 14) 1885 A Public Subkey packet (tag 14) has exactly the same format as a 1886 Public Key packet, but denotes a subkey. One or more subkeys may be 1887 associated with a top-level key. By convention, the top-level key 1888 provides signature services, and the subkeys provide encryption 1889 services. 1891 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1892 packet. This tag was selected for reuse because no previous version 1893 of PGP ever emitted comment packets but they did properly ignore 1894 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1895 cause it to fail, providing a limited degree of backward 1896 compatibility. 1898 5.5.1.3. Secret Key Packet (Tag 5) 1900 A Secret Key packet contains all the information that is found in a 1901 Public Key packet, including the public key material, but also 1902 includes the secret key material after all the public key fields. 1904 5.5.1.4. Secret Subkey Packet (Tag 7) 1906 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1907 Key packet, and has exactly the same format. 1909 5.5.2. Public Key Packet Formats 1911 There are two versions of key-material packets. Version 3 packets 1912 were first generated by PGP 2.6. Version 4 keys first appeared in 1913 PGP 5.0, and are the preferred key version for OpenPGP. 1915 OpenPGP implementations MUST create keys with version 4 format. V3 1916 keys are deprecated; an implementation MUST NOT generate a V3 key, 1917 but MAY accept it. 1919 A version 3 public key or public subkey packet contains: 1921 - A one-octet version number (3). 1923 - A four-octet number denoting the time that the key was created. 1925 - A two-octet number denoting the time in days that this key is 1926 valid. If this number is zero, then it does not expire. 1928 - A one-octet number denoting the public key algorithm of this key 1930 - A series of multiprecision integers comprising the key material: 1932 - a multiprecision integer (MPI) of RSA public modulus n; 1934 - an MPI of RSA public encryption exponent e. 1936 V3 keys are deprecated. They contain three weaknesses in them. 1937 First, it is relatively easy to construct a V3 key that has the same 1938 key ID as any other key because the key ID is simply the low 64 bits 1939 of the public modulus. Secondly, because the fingerprint of a V3 key 1940 hashes the key material, but not its length, there is an increased 1941 opportunity for fingerprint collisions. Third, there are weaknesses 1942 in the MD5 hash algorithm that make developers prefer other 1943 algorithms. See below for a fuller discussion of key IDs and 1944 fingerprints. 1946 V2 keys are identical to the deprecated V3 keys except for the 1947 version number. An implementation MUST NOT generate them and MAY 1948 accept or reject them as it sees fit. 1950 The version 4 format is similar to the version 3 format except for 1951 the absence of a validity period. This has been moved to the 1952 signature packet. In addition, fingerprints of version 4 keys are 1953 calculated differently from version 3 keys, as described in section 1954 "Enhanced Key Formats." 1956 A version 4 packet contains: 1958 - A one-octet version number (4). 1960 - A four-octet number denoting the time that the key was created. 1962 - A one-octet number denoting the public key algorithm of this key 1964 - A series of multiprecision integers comprising the key material. 1965 This algorithm-specific portion is: 1967 Algorithm Specific Fields for RSA public keys: 1969 - multiprecision integer (MPI) of RSA public modulus n; 1971 - MPI of RSA public encryption exponent e. 1973 Algorithm Specific Fields for DSA public keys: 1975 - MPI of DSA prime p; 1977 - MPI of DSA group order q (q is a prime divisor of p-1); 1979 - MPI of DSA group generator g; 1981 - MPI of DSA public key value y (= g**x mod p where x is 1982 secret). 1984 Algorithm Specific Fields for Elgamal public keys: 1986 - MPI of Elgamal prime p; 1988 - MPI of Elgamal group generator g; 1990 - MPI of Elgamal public key value y (= g**x mod p where x is 1991 secret). 1993 5.5.3. Secret Key Packet Formats 1995 The Secret Key and Secret Subkey packets contain all the data of the 1996 Public Key and Public Subkey packets, with additional 1997 algorithm-specific secret key data appended, usually in encrypted 1998 form. 2000 The packet contains: 2002 - A Public Key or Public Subkey packet, as described above 2004 - One octet indicating string-to-key usage conventions. Zero 2005 indicates that the secret key data is not encrypted. 255 or 254 2006 indicates that a string-to-key specifier is being given. Any 2007 other value is a symmetric-key encryption algorithm identifier. 2009 - [Optional] If string-to-key usage octet was 255 or 254, a 2010 one-octet symmetric encryption algorithm. 2012 - [Optional] If string-to-key usage octet was 255 or 254, a 2013 string-to-key specifier. The length of the string-to-key 2014 specifier is implied by its type, as described above. 2016 - [Optional] If secret data is encrypted (string-to-key usage 2017 octet not zero), an Initial Vector (IV) of the same length as 2018 the cipher's block size. 2020 - Plain or encrypted multiprecision integers comprising the secret 2021 key data. These algorithm-specific fields are as described 2022 below. 2024 - If the string-to-key usage octet is zero or 255, then a 2025 two-octet checksum of the plaintext of the algorithm-specific 2026 portion (sum of all octets, mod 65536). If the string-to-key 2027 usage octet was 254, then a 20-octet SHA-1 hash of the plaintext 2028 of the algorithm-specific portion. This checksum or hash is 2029 encrypted together with the algorithm-specific fields (if 2030 string-to-key usage octet is not zero). Note that for all other 2031 values, a two-octet checksum is required. 2033 Algorithm Specific Fields for RSA secret keys: 2035 - multiprecision integer (MPI) of RSA secret exponent d. 2037 - MPI of RSA secret prime value p. 2039 - MPI of RSA secret prime value q (p < q). 2041 - MPI of u, the multiplicative inverse of p, mod q. 2043 Algorithm Specific Fields for DSA secret keys: 2045 - MPI of DSA secret exponent x. 2047 Algorithm Specific Fields for Elgamal secret keys: 2049 - MPI of Elgamal secret exponent x. 2051 Secret MPI values can be encrypted using a passphrase. If a 2052 string-to-key specifier is given, that describes the algorithm for 2053 converting the passphrase to a key, else a simple MD5 hash of the 2054 passphrase is used. Implementations MUST use a string-to-key 2055 specifier; the simple hash is for backward compatibility and is 2056 deprecated, though implementations MAY continue to use existing 2057 private keys in the old format. The cipher for encrypting the MPIs 2058 is specified in the secret key packet. 2060 Encryption/decryption of the secret data is done in CFB mode using 2061 the key created from the passphrase and the Initial Vector from the 2062 packet. A different mode is used with V3 keys (which are only RSA) 2063 than with other key formats. With V3 keys, the MPI bit count prefix 2064 (i.e., the first two octets) is not encrypted. Only the MPI 2065 non-prefix data is encrypted. Furthermore, the CFB state is 2066 resynchronized at the beginning of each new MPI value, so that the 2067 CFB block boundary is aligned with the start of the MPI data. 2069 With V4 keys, a simpler method is used. All secret MPI values are 2070 encrypted in CFB mode, including the MPI bitcount prefix. 2072 The two-octet checksum that follows the algorithm-specific portion 2073 is the algebraic sum, mod 65536, of the plaintext of all the 2074 algorithm-specific octets (including MPI prefix and data). With V3 2075 keys, the checksum is stored in the clear. With V4 keys, the 2076 checksum is encrypted like the algorithm-specific data. This value 2077 is used to check that the passphrase was correct. However, this 2078 checksum is deprecated; an implementation SHOULD NOT use it, but 2079 should rather use the SHA-1 hash denoted with a usage octet of 254. 2080 The reason for this is that there are some attacks that involve 2081 undetectably modifying the secret key. 2083 5.6. Compressed Data Packet (Tag 8) 2085 The Compressed Data packet contains compressed data. Typically, this 2086 packet is found as the contents of an encrypted packet, or following 2087 a Signature or One-Pass Signature packet, and contains a literal 2088 data packet. 2090 The body of this packet consists of: 2092 - One octet that gives the algorithm used to compress the packet. 2094 - The remainder of the packet is compressed data. 2096 A Compressed Data Packet's body contains an block that compresses 2097 some set of packets. See section "Packet Composition" for details on 2098 how messages are formed. 2100 ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE 2101 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 2102 implementation uses more bits of compression, PGP V2.6 cannot 2103 decompress it. 2105 ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style 2106 blocks. 2108 BZip2-compressed packets are compressed using the BZip2 [BZ2] 2109 algorithm. 2111 5.7. Symmetrically Encrypted Data Packet (Tag 9) 2113 The Symmetrically Encrypted Data packet contains data encrypted with 2114 a symmetric-key algorithm. When it has been decrypted, it contains 2115 other packets (usually a literal data packet or compressed data 2116 packet, but in theory other Symmetrically Encrypted Data Packets or 2117 sequences of packets that form whole OpenPGP messages). 2119 The body of this packet consists of: 2121 - Encrypted data, the output of the selected symmetric-key cipher 2122 operating in OpenPGP's variant of Cipher Feedback (CFB) mode. 2124 The symmetric cipher used may be specified in an Public-Key or 2125 Symmetric-Key Encrypted Session Key packet that precedes the 2126 Symmetrically Encrypted Data Packet. In that case, the cipher 2127 algorithm octet is prefixed to the session key before it is 2128 encrypted. If no packets of these types precede the encrypted data, 2129 the IDEA algorithm is used with the session key calculated as the 2130 MD5 hash of the passphrase, though this use is deprecated. 2132 The data is encrypted in CFB mode, with a CFB shift size equal to 2133 the cipher's block size. The Initial Vector (IV) is specified as all 2134 zeros. Instead of using an IV, OpenPGP prefixes a string of length 2135 equal to the block size of the cipher plus two to the data before it 2136 is encrypted. The first block-size octets (for example, 8 octets for 2137 a 64-bit block length) are random, and the following two octets are 2138 copies of the last two octets of the IV. For example, in an 8 octet 2139 block, octet 9 is a repeat of octet 7, and octet 10 is a repeat of 2140 octet 8. In a cipher of length 16, octet 17 is a repeat of octet 15 2141 and octet 18 is a repeat of octet 16. As a pedantic clarification, 2142 in both these examples, we consider the first octet to be numbered 2143 1. 2145 After encrypting the first block-size-plus-two octets, the CFB state 2146 is resynchronized. The last block-size octets of ciphertext are 2147 passed through the cipher and the block boundary is reset. 2149 The repetition of 16 bits in the random data prefixed to the message 2150 allows the receiver to immediately check whether the session key is 2151 incorrect. See the Security Considerations section for hints on the 2152 proper use of this "quick check." 2154 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 2156 An experimental version of PGP used this packet as the Literal 2157 packet, but no released version of PGP generated Literal packets 2158 with this tag. With PGP 5.x, this packet has been re-assigned and is 2159 reserved for use as the Marker packet. 2161 The body of this packet consists of: 2163 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 2165 Such a packet MUST be ignored when received. It may be placed at the 2166 beginning of a message that uses features not available in PGP 2.6.x 2167 in order to cause that version to report that newer software is 2168 necessary to process the message. 2170 5.9. Literal Data Packet (Tag 11) 2172 A Literal Data packet contains the body of a message; data that is 2173 not to be further interpreted. 2175 The body of this packet consists of: 2177 - A one-octet field that describes how the data is formatted. 2179 If it is a 'b' (0x62), then the literal packet contains binary data. 2180 If it is a 't' (0x74), then it contains text data, and thus may need 2181 line ends converted to local form, or other text-mode changes. The 2182 tag 'u' (0x75) means the same as 't', but also indicates that 2183 implementation believes that the literal data contains UTF-8 text. 2185 Early versions of PGP also defined a value of 'l' as a 'local' mode 2186 for machine-local conversions. RFC 1991 incorrectly stated this 2187 local mode flag as '1' (ASCII numeral one). Both of these local 2188 modes are deprecated. 2190 - File name as a string (one-octet length, followed by a file 2191 name). This may be a zero-length string. Commonly, if the source 2192 of the encrypted data is a file, this will be the name of the 2193 encrypted file. An implementation MAY consider the file name in 2194 the literal packet to be a more authoritative name than the 2195 actual file name. 2197 If the special name "_CONSOLE" is used, the message is considered to 2198 be "for your eyes only". This advises that the message data is 2199 unusually sensitive, and the receiving program should process it 2200 more carefully, perhaps avoiding storing the received data to disk, 2201 for example. 2203 - A four-octet number that indicates a date associated with the 2204 literal data. Commonly, the date might be the modification date 2205 of a file, or the time the packet was created, or a zero that 2206 indicates no specific time. 2208 - The remainder of the packet is literal data. 2210 Text data is stored with text endings (i.e. network-normal 2211 line endings). These should be converted to native line endings by 2212 the receiving software. 2214 5.10. Trust Packet (Tag 12) 2216 The Trust packet is used only within keyrings and is not normally 2217 exported. Trust packets contain data that record the user's 2218 specifications of which key holders are trustworthy introducers, 2219 along with other information that implementing software uses for 2220 trust information. The format of trust packets is defined by a given 2221 implementation. 2223 Trust packets SHOULD NOT be emitted to output streams that are 2224 transferred to other users, and they SHOULD be ignored on any input 2225 other than local keyring files. 2227 5.11. User ID Packet (Tag 13) 2229 A User ID packet consists of UTF-8 text that is intended to 2230 represent the name and email address of the key holder. By 2231 convention, it includes an RFC 2822 mail name-addr, but there are no 2232 restrictions on its content. The packet length in the header 2233 specifies the length of the User ID. 2235 5.12. User Attribute Packet (Tag 17) 2237 The User Attribute packet is a variation of the User ID packet. It 2238 is capable of storing more types of data than the User ID packet 2239 which is limited to text. Like the User ID packet, a User Attribute 2240 packet may be certified by the key owner ("self-signed") or any 2241 other key owner who cares to certify it. Except as noted, a User 2242 Attribute packet may be used anywhere that a User ID packet may be 2243 used. 2245 While User Attribute packets are not a required part of the OpenPGP 2246 standard, implementations SHOULD provide at least enough 2247 compatibility to properly handle a certification signature on the 2248 User Attribute packet. A simple way to do this is by treating the 2249 User Attribute packet as a User ID packet with opaque contents, but 2250 an implementation may use any method desired. 2252 The User Attribute packet is made up of one or more attribute 2253 subpackets. Each subpacket consists of a subpacket header and a 2254 body. The header consists of: 2256 - the subpacket length (1, 2, or 5 octets) 2258 - the subpacket type (1 octet) 2260 and is followed by the subpacket specific data. 2262 The only currently defined subpacket type is 1, signifying an image. 2263 An implementation SHOULD ignore any subpacket of a type that it does 2264 not recognize. Subpacket types 100 through 110 are reserved for 2265 private or experimental use. 2267 5.12.1. The Image Attribute Subpacket 2269 The image attribute subpacket is used to encode an image, presumably 2270 (but not required to be) that of the key owner. 2272 The image attribute subpacket begins with an image header. The first 2273 two octets of the image header contain the length of the image 2274 header. Note that unlike other multi-octet numerical values in this 2275 document, due to an historical accident this value is encoded as a 2276 little-endian number. The image header length is followed by a 2277 single octet for the image header version. The only currently 2278 defined version of the image header is 1, which is a 16 octet image 2279 header. The first three octets of a version 1 image header are thus 2280 0x10 0x00 0x01. 2282 The fourth octet of a version 1 image header designates the encoding 2283 format of the image. The only currently defined encoding format is 2284 the value 1 to indicate JPEG. Image format types 100 through 110 are 2285 reserved for private or experimental use. The rest of the version 1 2286 image header is made up of 12 reserved octets, all of which MUST be 2287 set to 0. 2289 The rest of the image subpacket contains the image itself. As the 2290 only currently defined image type is JPEG, the image is encoded in 2291 the JPEG File Interchange Format (JFIF), a standard file format for 2292 JPEG images. [JFIF] 2294 An implementation MAY try and determine the type of an image by 2295 examination of the image data if it is unable to handle a particular 2296 version of the image header or if a specified encoding format value 2297 is not recognized. 2299 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) 2301 The Symmetrically Encrypted Integrity Protected Data Packet is a 2302 variant of the Symmetrically Encrypted Data Packet. It is a new 2303 feature created for OpenPGP that addresses the problem of detecting 2304 a modification to encrypted data. It is used in combination with a 2305 Modification Detection Code Packet. 2307 There is a corresponding feature in the features signature subpacket 2308 that denotes that an implementation can properly use this packet 2309 type. An implementation MUST support decrypting these packets and 2310 SHOULD prefer generating them to the older Symmetrically Encrypted 2311 Data Packet when possible. Since this data packet protects against 2312 modification attacks, this standard encourages its proliferation. 2313 While blanket adoption of this data packet would create 2314 interoperability problems, rapid adoption is nevertheless important. 2315 An implementation SHOULD specifically denote support for this 2316 packet, but it MAY infer it from other mechanisms. 2318 For example, an implementation might infer from the use of a cipher 2319 such as AES or Twofish that a user supports this feature. It might 2320 place in the unhashed portion of another user's key signature a 2321 features subpacket. It might also present a user with an opportunity 2322 to regenerate their own self-signature with a features subpacket. 2324 This packet contains data encrypted with a symmetric-key algorithm 2325 and protected against modification by the SHA-1 hash algorithm. When 2326 it has been decrypted, it will typically contain other packets 2327 (often a literal data packet or compressed data packet). The last 2328 decrypted packet in this packet's payload MUST be a Modification 2329 Detection Code packet. 2331 The body of this packet consists of: 2333 - A one-octet version number. The only currently defined value is 2334 1. 2336 - Encrypted data, the output of the selected symmetric-key cipher 2337 operating in Cipher Feedback mode with shift amount equal to the 2338 block size of the cipher (CFB-n where n is the block size). 2340 The symmetric cipher used MUST be specified in a Public-Key or 2341 Symmetric-Key Encrypted Session Key packet that precedes the 2342 Symmetrically Encrypted Data Packet. In either case, the cipher 2343 algorithm octet is prefixed to the session key before it is 2344 encrypted. 2346 The data is encrypted in CFB mode, with a CFB shift size equal to 2347 the cipher's block size. The Initial Vector (IV) is specified as all 2348 zeros. Instead of using an IV, OpenPGP prefixes an octet string to 2349 the data before it is encrypted. The length of the octet string 2350 equals the block size of the cipher in octets, plus two. The first 2351 octets in the group, of length equal to the block size of the 2352 cipher, are random; the last two octets are each copies of their 2nd 2353 preceding octet. For example, with a cipher whose block size is 128 2354 bits or 16 octets, the prefix data will contain 16 random octets, 2355 then two more octets, which are copies of the 15th and 16th octets, 2356 respectively. Unlike the Symmetrically Encrypted Data Packet, no 2357 special CFB resynchronization is done after encrypting this prefix 2358 data. See OpenPGP CFB Mode below for more details. 2360 The repetition of 16 bits in the random data prefixed to the message 2361 allows the receiver to immediately check whether the session key is 2362 incorrect. 2364 The plaintext of the data to be encrypted is passed through the 2365 SHA-1 hash function, and the result of the hash is appended to the 2366 plaintext in a Modification Detection Code packet. The input to the 2367 hash function includes the prefix data described above; it includes 2368 all of the plaintext, and then also includes two octets of values 2369 0xD3, 0x14. These represent the encoding of a Modification Detection 2370 Code packet tag and length field of 20 octets. 2372 The resulting hash value is stored in a Modification Detection Code 2373 packet which MUST use the two octet encoding just given to represent 2374 its tag and length field. The body of the MDC packet is the 20 octet 2375 output of the SHA-1 hash. 2377 The Modification Detection Code packet is appended to the plaintext 2378 and encrypted along with the plaintext using the same CFB context. 2380 During decryption, the plaintext data should be hashed with SHA-1, 2381 including the prefix data as well as the packet tag and length field 2382 of the Modification Detection Code packet. The body of the MDC 2383 packet, upon decryption, is compared with the result of the SHA-1 2384 hash. 2386 Any failure of the MDC indicates that the message has been modified 2387 and MUST be treated as a security problem. Failures include a 2388 difference in the hash values, but also the absence of an MDC 2389 packet, or an MDC packet in any position other than the end of the 2390 plaintext. Any failure SHOULD be reported to the user. 2392 Note: future designs of new versions of this packet should consider 2393 rollback attacks since it will be possible for an attacker to change 2394 the version back to 1. 2396 NON-NORMATIVE EXPLANATION 2398 The MDC system, as packets 18 and 19 are called, were created to 2399 provide an integrity mechanism that is less strong than a 2400 signature, yet stronger than bare CFB encryption. 2402 It is a limitation of CFB encryption that damage to the 2403 ciphertext will corrupt the affected cipher blocks and the block 2404 following. Additionally, if data is removed from the end of a 2405 CFB-encrypted block, that removal is undetectable. (Note also 2406 that CBC mode has a similar limitation, but data removed from 2407 the front of the block is undetectable.) 2409 The obvious way to protect or authenticate an encrypted block is 2410 to digitally sign it. However, many people do not wish to 2411 habitually sign data, for a large number of reasons beyond the 2412 scope of this document. Suffice it to say that many people 2413 consider properties such as deniability to be as valuable as 2414 integrity. 2416 OpenPGP addresses this desire to have more security than raw 2417 encryption and yet preserve deniability with the MDC system. An 2418 MDC is intentionally not a MAC. Its name was not selected by 2419 accident. It is analogous to a checksum. 2421 Despite the fact that it is a relatively modest system, it has 2422 proved itself in the real world. It is an effective defense to 2423 several attacks that have surfaced since it has been created. It 2424 has met its modest goals admirably. 2426 Consequently, because it is a modest security system, it has 2427 modest requirements on the hash function(s) it employs. It does 2428 not rely on a hash function being collision-free, it relies on a 2429 hash function being one-way. If a forger, Frank, wishes to send 2430 Alice a (digitally) unsigned message that says, "I've always 2431 secretly loved you, signed Bob" it is far easier for him to 2432 construct a new message than it is to modify anything 2433 intercepted from Bob. (Note also that if Bob wishes to 2434 communicate secretly with Alice, but without authentication nor 2435 identification and with a threat model that includes forgers, he 2436 has a problem that transcends mere cryptography.) 2438 Note also that unlike nearly every other OpenPGP subsystem, 2439 there are no parameters in the MDC system. It hard-defines SHA-1 2440 as its hash function. This is not an accident. It is an 2441 intentional choice to avoid downgrade and cross-grade attacks 2442 while making a simple, fast system. (A downgrade attack would be 2443 an attack that replaced SHA-256 with SHA-1, for example. A 2444 cross-grade attack would replace SHA-1 with another 160-bit 2445 hash, such as RIPE-MD/160, for example.) 2447 However, given the present state of hash function cryptanalysis 2448 and cryptography, it may be desirable to upgrade the MDC system 2449 to a new hash function. See section 10.5 in the IANA 2450 considerations for guidance. 2452 5.14. Modification Detection Code Packet (Tag 19) 2454 The Modification Detection Code packet contains a SHA-1 hash of 2455 plaintext data which is used to detect message modification. It is 2456 only used with a Symmetrically Encrypted Integrity Protected Data 2457 packet. The Modification Detection Code packet MUST be the last 2458 packet in the plaintext data which is encrypted in the Symmetrically 2459 Encrypted Integrity Protected Data packet, and MUST appear in no 2460 other place. 2462 A Modification Detection Code packet MUST have a length of 20 2463 octets. 2465 The body of this packet consists of: 2467 - A 20-octet SHA-1 hash of the preceding plaintext data of the 2468 Symmetrically Encrypted Integrity Protected Data packet, 2469 including prefix data, the tag octet, and length octet of the 2470 Modification Detection Code packet. 2472 Note that the Modification Detection Code packet MUST always use a 2473 new-format encoding of the packet tag, and a one-octet encoding of 2474 the packet length. The reason for this is that the hashing rules for 2475 modification detection include a one-octet tag and one-octet length 2476 in the data hash. While this is a bit restrictive, it reduces 2477 complexity. 2479 6. Radix-64 Conversions 2481 As stated in the introduction, OpenPGP's underlying native 2482 representation for objects is a stream of arbitrary octets, and some 2483 systems desire these objects to be immune to damage caused by 2484 character set translation, data conversions, etc. 2486 In principle, any printable encoding scheme that met the 2487 requirements of the unsafe channel would suffice, since it would not 2488 change the underlying binary bit streams of the native OpenPGP data 2489 structures. The OpenPGP standard specifies one such printable 2490 encoding scheme to ensure interoperability. 2492 OpenPGP's Radix-64 encoding is composed of two parts: a base64 2493 encoding of the binary data, and a checksum. The base64 encoding is 2494 identical to the MIME base64 content-transfer-encoding [RFC2045]. 2496 The checksum is a 24-bit CRC converted to four characters of 2497 radix-64 encoding by the same MIME base64 transformation, preceded 2498 by an equals sign (=). The CRC is computed by using the generator 2499 0x864CFB and an initialization of 0xB704CE. The accumulation is done 2500 on the data before it is converted to radix-64, rather than on the 2501 converted data. A sample implementation of this algorithm is in the 2502 next section. 2504 The checksum with its leading equal sign MAY appear on the first 2505 line after the Base64 encoded data. 2507 Rationale for CRC-24: The size of 24 bits fits evenly into printable 2508 base64. The nonzero initialization can detect more errors than a 2509 zero initialization. 2511 6.1. An Implementation of the CRC-24 in "C" 2513 #define CRC24_INIT 0xb704ceL 2514 #define CRC24_POLY 0x1864cfbL 2516 typedef long crc24; 2517 crc24 crc_octets(unsigned char *octets, size_t len) 2518 { 2519 crc24 crc = CRC24_INIT; 2520 int i; 2522 while (len--) { 2523 crc ^= (*octets++) << 16; 2524 for (i = 0; i < 8; i++) { 2525 crc <<= 1; 2526 if (crc & 0x1000000) 2527 crc ^= CRC24_POLY; 2528 } 2529 } 2530 return crc & 0xffffffL; 2531 } 2533 6.2. Forming ASCII Armor 2535 When OpenPGP encodes data into ASCII Armor, it puts specific headers 2536 around the Radix-64 encoded data, so OpenPGP can reconstruct the 2537 data later. An OpenPGP implementation MAY use ASCII armor to protect 2538 raw binary data. OpenPGP informs the user what kind of data is 2539 encoded in the ASCII armor through the use of the headers. 2541 Concatenating the following data creates ASCII Armor: 2543 - An Armor Header Line, appropriate for the type of data 2545 - Armor Headers 2547 - A blank (zero-length, or containing only whitespace) line 2549 - The ASCII-Armored data 2551 - An Armor Checksum 2553 - The Armor Tail, which depends on the Armor Header Line. 2555 An Armor Header Line consists of the appropriate header line text 2556 surrounded by five (5) dashes ('-', 0x2D) on either side of the 2557 header line text. The header line text is chosen based upon the type 2558 of data that is being encoded in Armor, and how it is being encoded. 2559 Header line texts include the following strings: 2561 BEGIN PGP MESSAGE 2562 Used for signed, encrypted, or compressed files. 2564 BEGIN PGP PUBLIC KEY BLOCK 2565 Used for armoring public keys 2567 BEGIN PGP PRIVATE KEY BLOCK 2568 Used for armoring private keys 2570 BEGIN PGP MESSAGE, PART X/Y 2571 Used for multi-part messages, where the armor is split amongst Y 2572 parts, and this is the Xth part out of Y. 2574 BEGIN PGP MESSAGE, PART X 2575 Used for multi-part messages, where this is the Xth part of an 2576 unspecified number of parts. Requires the MESSAGE-ID Armor 2577 Header to be used. 2579 BEGIN PGP SIGNATURE 2580 Used for detached signatures, OpenPGP/MIME signatures, and 2581 cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE 2582 for detached signatures. 2584 Note that all these Armor Header Lines are to consist of a complete 2585 line. That is to say, there is always a line ending preceding the 2586 starting five dashes, and following the ending five dashes. The 2587 header lines, therefore, MUST start at the beginning of a line, and 2588 MUST NOT have text other than whitespace following them on the same 2589 line. These line endings are considered a part of the Armor Header 2590 Line for the purposes of determining the content they delimit. This 2591 is particularly important when computing a cleartext signature (see 2592 below). 2594 The Armor Headers are pairs of strings that can give the user or the 2595 receiving OpenPGP implementation some information about how to 2596 decode or use the message. The Armor Headers are a part of the 2597 armor, not a part of the message, and hence are not protected by any 2598 signatures applied to the message. 2600 The format of an Armor Header is that of a key-value pair. A colon 2601 (':' 0x38) and a single space (0x20) separate the key and value. 2602 OpenPGP should consider improperly formatted Armor Headers to be 2603 corruption of the ASCII Armor. Unknown keys should be reported to 2604 the user, but OpenPGP should continue to process the message. 2606 Note that some transport methods are sensitive to line length. While 2607 there is a limit of 76 characters for the Radix-64 data (section 2608 6.3), there is no limit to the length of Armor Headers. Care should 2609 be taken that the Armor Headers are short enough to survive 2610 transport. One way to do this is to repeat an Armor Header key 2611 multiple times with different values for each so that no one line is 2612 overly long. 2614 Currently defined Armor Header Keys are: 2616 - "Version", that states the OpenPGP implementation and version 2617 used to encode the message. 2619 - "Comment", a user-defined comment. OpenPGP defines all text to 2620 be in UTF-8. A comment may be any UTF-8 string. However, the 2621 whole point of armoring is to provide seven-bit-clean data. 2622 Consequently, if a comment has characters that are outside the 2623 US-ASCII range of UTF, they may very well not survive transport. 2625 - "MessageID", a 32-character string of printable characters. The 2626 string must be the same for all parts of a multi-part message 2627 that uses the "PART X" Armor Header. MessageID strings should be 2628 unique enough that the recipient of the mail can associate all 2629 the parts of a message with each other. A good checksum or 2630 cryptographic hash function is sufficient. 2632 The MessageID SHOULD NOT appear unless it is in a multi-part 2633 message. If it appears at all, it MUST be computed from the 2634 finished (encrypted, signed, etc.) message in a deterministic 2635 fashion, rather than contain a purely random value. This is to 2636 allow the legitimate recipient to determine that the MessageID 2637 cannot serve as a covert means of leaking cryptographic key 2638 information. 2640 - "Hash", a comma-separated list of hash algorithms used in this 2641 message. This is used only in cleartext signed messages. 2643 - "Charset", a description of the character set that the plaintext 2644 is in. Please note that OpenPGP defines text to be in UTF-8. An 2645 implementation will get best results by translating into and out 2646 of UTF-8. However, there are many instances where this is easier 2647 said than done. Also, there are communities of users who have no 2648 need for UTF-8 because they are all happy with a character set 2649 like ISO Latin-5 or a Japanese character set. In such instances, 2650 an implementation MAY override the UTF-8 default by using this 2651 header key. An implementation MAY implement this key and any 2652 translations it cares to; an implementation MAY ignore it and 2653 assume all text is UTF-8. 2655 The Armor Tail Line is composed in the same manner as the Armor 2656 Header Line, except the string "BEGIN" is replaced by the string 2657 "END". 2659 6.3. Encoding Binary in Radix-64 2661 The encoding process represents 24-bit groups of input bits as 2662 output strings of 4 encoded characters. Proceeding from left to 2663 right, a 24-bit input group is formed by concatenating three 8-bit 2664 input groups. These 24 bits are then treated as four concatenated 2665 6-bit groups, each of which is translated into a single digit in the 2666 Radix-64 alphabet. When encoding a bit stream with the Radix-64 2667 encoding, the bit stream must be presumed to be ordered with the 2668 most-significant-bit first. That is, the first bit in the stream 2669 will be the high-order bit in the first 8-bit octet, and the eighth 2670 bit will be the low-order bit in the first 8-bit octet, and so on. 2672 +--first octet--+-second octet--+--third octet--+ 2673 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 2674 +-----------+---+-------+-------+---+-----------+ 2675 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 2676 +--1.index--+--2.index--+--3.index--+--4.index--+ 2678 Each 6-bit group is used as an index into an array of 64 printable 2679 characters from the table below. The character referenced by the 2680 index is placed in the output string. 2682 Value Encoding Value Encoding Value Encoding Value Encoding 2683 0 A 17 R 34 i 51 z 2684 1 B 18 S 35 j 52 0 2685 2 C 19 T 36 k 53 1 2686 3 D 20 U 37 l 54 2 2687 4 E 21 V 38 m 55 3 2688 5 F 22 W 39 n 56 4 2689 6 G 23 X 40 o 57 5 2690 7 H 24 Y 41 p 58 6 2691 8 I 25 Z 42 q 59 7 2692 9 J 26 a 43 r 60 8 2693 10 K 27 b 44 s 61 9 2694 11 L 28 c 45 t 62 + 2695 12 M 29 d 46 u 63 / 2696 13 N 30 e 47 v 2697 14 O 31 f 48 w (pad) = 2698 15 P 32 g 49 x 2699 16 Q 33 h 50 y 2701 The encoded output stream must be represented in lines of no more 2702 than 76 characters each. 2704 Special processing is performed if fewer than 24 bits are available 2705 at the end of the data being encoded. There are three possibilities: 2707 1. The last data group has 24 bits (3 octets). No special 2708 processing is needed. 2710 2. The last data group has 16 bits (2 octets). The first two 6-bit 2711 groups are processed as above. The third (incomplete) data group 2712 has two zero-value bits added to it, and is processed as above. 2713 A pad character (=) is added to the output. 2715 3. The last data group has 8 bits (1 octet). The first 6-bit group 2716 is processed as above. The second (incomplete) data group has 2717 four zero-value bits added to it, and is processed as above. Two 2718 pad characters (=) are added to the output. 2720 6.4. Decoding Radix-64 2722 In Radix-64 data, characters other than those in the table, line 2723 breaks, and other white space probably indicate a transmission 2724 error, about which a warning message or even a message rejection 2725 might be appropriate under some circumstances. Decoding software 2726 must ignore all white space. 2728 Because it is used only for padding at the end of the data, the 2729 occurrence of any "=" characters may be taken as evidence that the 2730 end of the data has been reached (without truncation in transit). No 2731 such assurance is possible, however, when the number of octets 2732 transmitted was a multiple of three and no "=" characters are 2733 present. 2735 6.5. Examples of Radix-64 2737 Input data: 0x14fb9c03d97e 2738 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2739 8-bit: 00010100 11111011 10011100 | 00000011 11011001 11111110 2740 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 111110 2741 Decimal: 5 15 46 28 0 61 37 62 2742 Output: F P u c A 9 l + 2743 Input data: 0x14fb9c03d9 2744 Hex: 1 4 f b 9 c | 0 3 d 9 2745 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2746 pad with 00 2747 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2748 Decimal: 5 15 46 28 0 61 36 2749 pad with = 2750 Output: F P u c A 9 k = 2751 Input data: 0x14fb9c03 2752 Hex: 1 4 f b 9 c | 0 3 2753 8-bit: 00010100 11111011 10011100 | 00000011 2754 pad with 0000 2755 6-bit: 000101 001111 101110 011100 | 000000 110000 2756 Decimal: 5 15 46 28 0 48 2757 pad with = = 2758 Output: F P u c A w = = 2760 6.6. Example of an ASCII Armored Message 2762 -----BEGIN PGP MESSAGE----- 2763 Version: OpenPrivacy 0.99 2765 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2766 vBSFjNSiVHsuAA== 2767 =njUN 2768 -----END PGP MESSAGE----- 2770 Note that this example has extra indenting; an actual armored 2771 message would have no leading whitespace. 2773 7. Cleartext signature framework 2775 It is desirable to be able to sign a textual octet stream without 2776 ASCII armoring the stream itself, so the signed text is still 2777 readable without special software. In order to bind a signature to 2778 such a cleartext, this framework is used. (Note that this framework 2779 is not intended to be reversible. RFC 3156 defines another way to 2780 sign cleartext messages for environments that support MIME.) 2782 The cleartext signed message consists of: 2784 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2785 single line, 2787 - One or more "Hash" Armor Headers, 2789 - Exactly one empty line not included into the message digest, 2791 - The dash-escaped cleartext that is included into the message 2792 digest, 2794 - The ASCII armored signature(s) including the '-----BEGIN PGP 2795 SIGNATURE-----' Armor Header and Armor Tail Lines. 2797 If the "Hash" armor header is given, the specified message digest 2798 algorithm(s) are used for the signature. If there are no such 2799 headers, MD5 is used. If MD5 is the only hash used, then an 2800 implementation MAY omit this header for improved V2.x compatibility. 2801 If more than one message digest is used in the signature, the "Hash" 2802 armor header contains a comma-delimited list of used message 2803 digests. 2805 Current message digest names are described below with the algorithm 2806 IDs. 2808 An implementation SHOULD add a line break after the cleartext, but 2809 MAY omit it if the cleartext ends with a line break. This is for 2810 visual clarity. 2812 7.1. Dash-Escaped Text 2814 The cleartext content of the message must also be dash-escaped. 2816 Dash escaped cleartext is the ordinary cleartext where every line 2817 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2818 (0x2D) and space ' ' (0x20). This prevents the parser from 2819 recognizing armor headers of the cleartext itself. An implementation 2820 MAY dash escape any line, SHOULD dash escape lines commencing "From" 2821 followed by a space, and MUST dash escape any line commencing in a 2822 dash. The message digest is computed using the cleartext itself, not 2823 the dash escaped form. 2825 As with binary signatures on text documents, a cleartext signature 2826 is calculated on the text using canonical line endings. The 2827 line ending (i.e. the ) before the '-----BEGIN PGP 2828 SIGNATURE-----' line that terminates the signed text is not 2829 considered part of the signed text. 2831 When reversing dash-escaping, an implementation MUST strip the 2832 string "- " if it occurs at the beginning of a line, and SHOULD warn 2833 on "-" and any character other than a space at the beginning of a 2834 line. 2836 Also, any trailing whitespace -- spaces (0x20) and tabs (0x09) -- at 2837 the end of any line is removed when the cleartext signature is 2838 generated. 2840 8. Regular Expressions 2842 A regular expression is zero or more branches, separated by '|'. It 2843 matches anything that matches one of the branches. 2845 A branch is zero or more pieces, concatenated. It matches a match 2846 for the first, followed by a match for the second, etc. 2848 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2849 followed by '*' matches a sequence of 0 or more matches of the atom. 2850 An atom followed by '+' matches a sequence of 1 or more matches of 2851 the atom. An atom followed by '?' matches a match of the atom, or 2852 the null string. 2854 An atom is a regular expression in parentheses (matching a match for 2855 the regular expression), a range (see below), '.' (matching any 2856 single character), '^' (matching the null string at the beginning of 2857 the input string), '$' (matching the null string at the end of the 2858 input string), a '\' followed by a single character (matching that 2859 character), or a single character with no other significance 2860 (matching that character). 2862 A range is a sequence of characters enclosed in '[]'. It normally 2863 matches any single character from the sequence. If the sequence 2864 begins with '^', it matches any single character not from the rest 2865 of the sequence. If two characters in the sequence are separated by 2866 '-', this is shorthand for the full list of ASCII characters between 2867 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2868 ']' in the sequence, make it the first character (following a 2869 possible '^'). To include a literal '-', make it the first or last 2870 character. 2872 9. Constants 2874 This section describes the constants used in OpenPGP. 2876 Note that these tables are not exhaustive lists; an implementation 2877 MAY implement an algorithm not on these lists, so long as the 2878 algorithm number(s) are chosen from the private or experimental 2879 algorithm range. 2881 See the section "Notes on Algorithms" below for more discussion of 2882 the algorithms. 2884 9.1. Public Key Algorithms 2886 ID Algorithm 2887 -- --------- 2888 1 - RSA (Encrypt or Sign) [HAC] 2889 2 - RSA Encrypt-Only 2890 3 - RSA Sign-Only 2891 16 - Elgamal (Encrypt-Only), see [ELGAMAL] [HAC] 2892 17 - DSA (Digital Signature Algorithm) [FIPS186] [HAC] 2893 18 - Reserved for Elliptic Curve 2894 19 - Reserved for ECDSA 2895 20 - Reserved (formerly Elgamal Encrypt or Sign) 2896 21 - Reserved for Diffie-Hellman (X9.42, 2897 as defined for IETF-S/MIME) 2898 100 to 110 - Private/Experimental algorithm. 2900 Implementations MUST implement DSA for signatures, and Elgamal for 2901 encryption. Implementations SHOULD implement RSA keys. 2902 Implementations MAY implement any other algorithm. 2904 9.2. Symmetric Key Algorithms 2906 ID Algorithm 2907 -- --------- 2908 0 - Plaintext or unencrypted data 2909 1 - IDEA [IDEA] 2910 2 - TripleDES (DES-EDE, [SCHNEIER] [HAC] - 2911 168 bit key derived from 192) 2912 3 - CAST5 (128 bit key, as per RFC 2144) 2913 4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH] 2914 5 - Reserved 2915 6 - Reserved 2916 7 - AES with 128-bit key [AES] 2917 8 - AES with 192-bit key 2918 9 - AES with 256-bit key 2919 10 - Twofish with 256-bit key [TWOFISH] 2920 100 to 110 - Private/Experimental algorithm. 2922 Implementations MUST implement TripleDES. Implementations SHOULD 2923 implement AES-128 and CAST5. Implementations that interoperate with 2924 PGP 2.6 or earlier need to support IDEA, as that is the only 2925 symmetric cipher those versions use. Implementations MAY implement 2926 any other algorithm. 2928 9.3. Compression Algorithms 2930 ID Algorithm 2931 -- --------- 2932 0 - Uncompressed 2933 1 - ZIP [RFC 1951] 2934 2 - ZLIB [RFC 1950] 2935 3 - BZip2 [BZ2] 2936 100 to 110 - Private/Experimental algorithm. 2938 Implementations MUST implement uncompressed data. Implementations 2939 SHOULD implement ZIP. Implementations MAY implement any other 2940 algorithm. 2942 9.4. Hash Algorithms 2944 ID Algorithm Text Name 2945 -- --------- ---- ---- 2946 1 - MD5 [HAC] "MD5" 2947 2 - SHA-1 [FIPS180] "SHA1" 2948 3 - RIPE-MD/160 [HAC] "RIPEMD160" 2949 4 - Reserved 2950 5 - Reserved 2951 6 - Reserved 2952 7 - Reserved 2953 8 - SHA256 [FIPS180] "SHA256" 2954 9 - SHA384 [FIPS180] "SHA384" 2955 10 - SHA512 [FIPS180] "SHA512" 2956 11 - SHA224 [FIPS180] "SHA224" 2957 100 to 110 - Private/Experimental algorithm. 2959 Implementations MUST implement SHA-1. Implementations MAY implement 2960 other algorithms. MD5 is deprecated. 2962 10. IANA Considerations 2964 OpenPGP is highly parameterized and consequently there are a number 2965 of considerations for allocating parameters for extensions. This 2966 section describes how IANA should look at extensions to the protocol 2967 as described in this document. 2969 10.1. New String-to-Key specifier types 2971 OpenPGP S2K specifiers contain a mechanism for new algorithms to 2972 turn a string into a key. This specification creates a registry of 2973 S2K specifier types. The registry includes the S2K type, the name of 2974 the S2K and a reference to the defining specification. The initial 2975 values for this registry can be found in 3.7.1. Adding a new S2K 2976 specifier MUST be done through the IETF CONSENSUS method, as 2977 described in [RFC2434]. 2979 10.2. New Packets 2981 Major new features of OpenPGP are defined though new packet types. 2982 This specification creates a registry of packet types. The registry 2983 includes the packet type, the name of the packet and a reference to 2984 the defining specification. The initial values for this registry can 2985 be found in 4.3. Adding a new packet type MUST be done through the 2986 IETF CONSENSUS method, as described in [RFC2434]. 2988 10.2.1. User Attribute Types 2990 The User Attribute packet permits an extensible mechanism for other 2991 types of certificate identification. This specification creates a 2992 registry of User Attribute types. The registry includes the User 2993 Attribute type, the name of the User Attribute and a reference to 2994 the defining specification. The initial values for this registry can 2995 be found in 5.12. Adding a new User Attribute type MUST be done 2996 through the IETF CONSENSUS method, as described in [RFC2434]. 2998 10.2.1.1. Image Format Subpacket Types 3000 Within User Attribute packets, there is an extensible mechanism for 3001 other types of image-based user attributes. This specification 3002 creates a registry of Image Attribute subpacket types. The registry 3003 includes the Image Attribute subpacket type, the name of the Image 3004 Attribute subpacket and a reference to the defining specification. 3005 The initial values for this registry can be found in 5.12.1. Adding 3006 a new Image Attribute subpacket type MUST be done through the IETF 3007 CONSENSUS method, as described in [RFC2434]. 3009 10.2.2. New Signature Subpackets 3011 OpenPGP signatures contain a mechanism for signed (or unsigned) data 3012 to be added to them for a variety of purposes in the signature 3013 subpackets as discussed in section 5.2.3.1. This specification 3014 creates a registry of signature subpacket types. The registry 3015 includes the signature subpacket type, the name of the subpacket and 3016 a reference to the defining specification. The initial values for 3017 this registry can be found in 5.2.3.1. Adding a new signature 3018 subpacket MUST be done through the IETF CONSENSUS method, as 3019 described in [RFC2434]. 3021 10.2.2.1. Signature Notation Data Subpackets 3023 OpenPGP signatures further contain a mechanism for extensions in 3024 signatures. These are the Notation Data subpackets, which contain a 3025 key/value pair. Notations contain a user space which is completely 3026 unmanaged and an IETF space. 3028 This specification creates a registry of Signature Notation Data 3029 types. The registry includes the Signature Notation Data type, the 3030 name of the Signature Notation Data, its allowed values, and a 3031 reference to the defining specification. The initial values for this 3032 registry can be found in 5.2.3.16. Adding a new Signature Notation 3033 Data subpacket MUST be done through the EXPERT REVIEW method, as 3034 described in [RFC2434]. 3036 10.2.2.2. Key Server Preference Extensions 3038 OpenPGP signatures contain a mechanism for preferences to be 3039 specified about key servers. This specification creates a registry 3040 of key server preferences. The registry includes the key server 3041 preference, the name of the preference and a reference to the 3042 defining specification. The initial values for this registry can be 3043 found in 5.2.3.17. Adding a new key server preference MUST be done 3044 through the IETF CONSENSUS method, as described in [RFC2434]. 3046 10.2.2.3. Key Flags Extensions 3048 OpenPGP signatures contain a mechanism for flags to be specified 3049 about key usage. This specification creates a registry of key usage 3050 flags. The registry includes the key flags value, the name of the 3051 flag and a reference to the defining specification. The initial 3052 values for this registry can be found in 5.2.3.21. Adding a new key 3053 usage flag MUST be done through the IETF CONSENSUS method, as 3054 described in [RFC2434]. 3056 10.2.2.4. Reason For Revocation Extensions 3058 OpenPGP signatures contain a mechanism for flags to be specified 3059 about why a key was revoked. This specification creates a registry 3060 of reason-for-revocation flags. The registry includes the 3061 reason-for-revocation flags value, the name of the flag and a 3062 reference to the defining specification. The initial values for this 3063 registry can be found in 5.2.3.23. Adding a new feature flag MUST be 3064 done through the IETF CONSENSUS method, as described in [RFC2434]. 3066 10.2.2.5. Implementation Features 3068 OpenPGP signatures contain a mechanism for flags to be specified 3069 stating which optional features an implementation supports. This 3070 specification creates a registry of feature-implementation flags. 3071 The registry includes the feature-implementation flags value, the 3072 name of the flag and a reference to the defining specification. The 3073 initial values for this registry can be found in 5.2.3.24. Adding a 3074 new feature-implementation flag MUST be done through the IETF 3075 CONSENSUS method, as described in [RFC2434]. 3077 Also see section 10.6 for more information about when feature flags 3078 are needed. 3080 10.2.3. New Packet Versions 3082 The core OpenPGP packets all have version numbers, and can be 3083 revised by introducing a new version of an existing packet. This 3084 specification creates a registry of packet types. The registry 3085 includes the packet type, the number of the version and a reference 3086 to the defining specification. The initial values for this registry 3087 can be found in 5. Adding a new packet version MUST be done through 3088 the IETF CONSENSUS method, as described in [RFC2434]. 3090 10.3. New Algorithms 3092 Chapter 9 lists the core algorithms that OpenPGP uses. Adding in a 3093 new algorithm is usually simple. For example, adding in a new 3094 symmetric cipher usually would not need anything more than 3095 allocating a constant for that cipher. If that cipher had other than 3096 a 64-bit or 128-bit block size, there might need to be additional 3097 documentation describing how OpenPGP-CFB mode would be adjusted. 3098 Similarly, when DSA was expanded from a maximum of 1024-bit public 3099 keys to 3072-bit public keys, the revision of FIPS 186 contained 3100 enough information itself to allow implementation. Changes to this 3101 document were emphasis more than required. 3103 10.3.1. Public Key Algorithms 3105 OpenPGP specifies a number of public key algorithms. This 3106 specification creates a registry of public key algorithm 3107 identifiers. The registry includes the algorithm name, its key sizes 3108 and parameters, and a reference to the defining specification. The 3109 initial values for this registry can be found in section 9. Adding a 3110 new public key algorithm MUST be done through the IETF CONSENSUS 3111 method, as described in [RFC2434]. 3113 10.3.2. Symmetric Key Algorithms 3115 OpenPGP specifies a number of symmetric key algorithms. This 3116 specification creates a registry of symmetric key algorithm 3117 identifiers. The registry includes the algorithm name, its key sizes 3118 and block size, and a reference to the defining specification. The 3119 initial values for this registry can be found in section 9. Adding a 3120 new symmetric key algorithm MUST be done through the IETF CONSENSUS 3121 method, as described in [RFC2434]. 3123 10.3.3. Hash Algorithms 3125 OpenPGP specifies a number of hash algorithms. This specification 3126 creates a registry of hash algorithm identifiers. The registry 3127 includes the algorithm name, a text representation of that name, its 3128 block size, an OID hash prefix, and a reference to the defining 3129 specification. The initial values for this registry can be found in 3130 section 9 for the algorithm identifiers and text names, and section 3131 5.2.2 for the OIDs and expanded signature prefixes. Adding a new 3132 hash algorithm MUST be done through the IETF CONSENSUS method, as 3133 described in [RFC2434]. 3135 10.3.4. Compression Algorithms 3137 OpenPGP specifies a number of compression algorithms. This 3138 specification creates a registry of compression algorithm 3139 identifiers. The registry includes the algorithm name, and a 3140 reference to the defining specification. The initial values for this 3141 registry can be found in section 9.3. Adding a new compression key 3142 algorithm MUST be done through the IETF CONSENSUS method, as 3143 described in [RFC2434]. 3145 10.4. Private or Experimental Parameters 3147 S2K specifiers, Signature subpacket types, user attribute types, 3148 image format types, and algorithms described in Section 9 all 3149 reserve the range 100 to 110 for private and experimental use. 3150 Packet types reserve the range 60 to 63 for private and experimental 3151 use. These are intentionally managed with the PRIVATE USE method, as 3152 described in [RFC2434]. 3154 However, implementations need to be careful with these and promote 3155 them to full IANA-managed parameters when they grow beyond the 3156 original, limited system. 3158 10.5. Extension of the MDC System 3160 As described in the non-normative explanation in section 5.13, the 3161 MDC system is uniquely unparameterized in OpenPGP, and that this was 3162 an intentional decision to avoid cross-grade attacks. If the MDC 3163 system is extended to a stronger hash function, there must be care 3164 given to avoiding downgrade and cross-grade attacks. 3166 One simple way to do this is to create new packets for a new MDC. 3167 For example, instead of the MDC system using packets 18 and 19, a 3168 new MDC could use 20 and 21. This has obvious drawbacks (it uses two 3169 packet numbers for each new hash function in a space that is limited 3170 to a maximum of 60). 3172 Another simple way to extend the MDC system is to create new 3173 versions of packet 18, and reflect this in packet 19. For example, 3174 suppose that V2 of packet 18 implicitly used SHA-256. This would 3175 require packet 19 to have a length of 32 octets. The change in the 3176 version in packet 18 and the size of packet 19 prevent a downgrade 3177 attack. 3179 There are two drawbacks to this latter approach. The first is that 3180 using the version number of a packet to carry algorithm information 3181 is not tidy from a protocol-design standpoint. it is possible that 3182 there might be several versions of the MDC system in common use, but 3183 this untidiness would reflect untidiness in cryptographic consensus 3184 about hash function security. The second is that different versions 3185 of packet 19 would have to have unique sizes. If there were two 3186 versions each with 256-bit hashes, they could not both have 32-octet 3187 packet 19s without admitting the chance of a cross-grade attack. 3189 Yet another, complex approach to extend the MDC system would be a 3190 hybrid of the two above -- create a new pair of MDC packets that are 3191 fully parameterized, and yet protected from downgrade and 3192 cross-grade. 3194 Any change to the MDC system MUST be done through the IETF CONSENSUS 3195 method, as described in [RFC2434]. 3197 10.6. Meta-Considerations 3199 If OpenPGP is extended in a way that is not upwards-compatible, 3200 meaning that old implementations will not gracefully handle their 3201 absence of a new feature, the extension proposal can be declared in 3202 the key holder's self-signature as part of the Features signature 3203 subpacket. 3205 We cannot state definitively what extensions will not be 3206 upwards-compatible, but typically new algorithms are 3207 upwards-compatible, but new packets are not. 3209 If an extension proposal does not update the Features system, it 3210 SHOULD include an explanation of why this is unnecessary. If the 3211 proposal contains neither an extension to the Features system nor an 3212 explanation of why such an extension is unnecessary, the proposal 3213 SHOULD be rejected. 3215 11. Packet Composition 3217 OpenPGP packets are assembled into sequences in order to create 3218 messages and to transfer keys. Not all possible packet sequences are 3219 meaningful and correct. This section describes the rules for how 3220 packets should be placed into sequences. 3222 11.1. Transferable Public Keys 3224 OpenPGP users may transfer public keys. The essential elements of a 3225 transferable public key are: 3227 - One Public Key packet 3229 - Zero or more revocation signatures 3231 - One or more User ID packets 3233 - After each User ID packet, zero or more signature packets 3234 (certifications) 3236 - Zero or more User Attribute packets 3238 - After each User Attribute packet, zero or more signature packets 3239 (certifications) 3241 - Zero or more Subkey packets 3243 - After each Subkey packet, one signature packet, plus optionally 3244 a revocation. 3246 The Public Key packet occurs first. Each of the following User ID 3247 packets provides the identity of the owner of this public key. If 3248 there are multiple User ID packets, this corresponds to multiple 3249 means of identifying the same unique individual user; for example, a 3250 user may have more than one email address, and construct a User ID 3251 for each one. 3253 Immediately following each User ID packet, there are zero or more 3254 signature packets. Each signature packet is calculated on the 3255 immediately preceding User ID packet and the initial Public Key 3256 packet. The signature serves to certify the corresponding public key 3257 and User ID. In effect, the signer is testifying to his or her 3258 belief that this public key belongs to the user identified by this 3259 User ID. 3261 Within the same section as the User ID packets, there are zero or 3262 more User Attribute packets. Like the User ID packets, a User 3263 Attribute packet is followed by zero or more signature packets 3264 calculated on the immediately preceding User Attribute packet and 3265 the initial Public Key packet. 3267 User Attribute packets and User ID packets may be freely intermixed 3268 in this section, so long as the signatures that follow them are 3269 maintained on the proper User Attribute or User ID packet. 3271 After the User ID or Attribute packets there may be zero or more 3272 Subkey packets. In general, subkeys are provided in cases where the 3273 top-level public key is a signature-only key. However, any V4 key 3274 may have subkeys, and the subkeys may be encryption-only keys, 3275 signature-only keys, or general-purpose keys. V3 keys MUST NOT have 3276 subkeys. 3278 Each Subkey packet MUST be followed by one Signature packet, which 3279 should be a subkey binding signature issued by the top level key. 3280 For subkeys that can issue signatures, the subkey binding signature 3281 MUST contain an embedded signature subpacket with a primary key 3282 binding signature (0x19) issued by the subkey on the top level key. 3284 Subkey and Key packets may each be followed by a revocation 3285 Signature packet to indicate that the key is revoked. Revocation 3286 signatures are only accepted if they are issued by the key itself, 3287 or by a key that is authorized to issue revocations via a revocation 3288 key subpacket in a self-signature by the top level key. 3290 Transferable public key packet sequences may be concatenated to 3291 allow transferring multiple public keys in one operation. 3293 11.2. Transferable Secret Keys 3295 OpenPGP users may transfer secret keys. The format of a transferable 3296 secret key is the same as a transferable public key except that 3297 secret key and secret subkey packets are used instead of the public 3298 key and public subkey packets. Implementations SHOULD include 3299 self-signatures on any user IDs and subkeys, as this allows for a 3300 complete public key to be automatically extracted from the 3301 transferable secret key. Implementations MAY choose to omit the 3302 self-signatures, especially if a transferable public key accompanies 3303 the transferable secret key. 3305 11.3. OpenPGP Messages 3307 An OpenPGP message is a packet or sequence of packets that 3308 corresponds to the following grammatical rules (comma represents 3309 sequential composition, and vertical bar separates alternatives): 3311 OpenPGP Message :- Encrypted Message | Signed Message | 3312 Compressed Message | Literal Message. 3314 Compressed Message :- Compressed Data Packet. 3316 Literal Message :- Literal Data Packet. 3318 ESK :- Public Key Encrypted Session Key Packet | 3319 Symmetric-Key Encrypted Session Key Packet. 3321 ESK Sequence :- ESK | ESK Sequence, ESK. 3323 Encrypted Data :- Symmetrically Encrypted Data Packet | 3324 Symmetrically Encrypted Integrity Protected Data Packet 3326 Encrypted Message :- Encrypted Data | ESK Sequence, Encrypted Data. 3328 One-Pass Signed Message :- One-Pass Signature Packet, 3329 OpenPGP Message, Corresponding Signature Packet. 3331 Signed Message :- Signature Packet, OpenPGP Message | 3332 One-Pass Signed Message. 3334 In addition, decrypting a Symmetrically Encrypted Data Packet or a 3335 Symmetrically Encrypted Integrity Protected Data Packet as well as 3336 decompressing a Compressed Data packet must yield a valid OpenPGP 3337 Message. 3339 11.4. Detached Signatures 3341 Some OpenPGP applications use so-called "detached signatures." For 3342 example, a program bundle may contain a file, and with it a second 3343 file that is a detached signature of the first file. These detached 3344 signatures are simply a signature packet stored separately from the 3345 data that they are a signature of. 3347 12. Enhanced Key Formats 3349 12.1. Key Structures 3351 The format of an OpenPGP V3 key is as follows. Entries in square 3352 brackets are optional and ellipses indicate repetition. 3354 RSA Public Key 3355 [Revocation Self Signature] 3356 User ID [Signature ...] 3357 [User ID [Signature ...] ...] 3359 Each signature certifies the RSA public key and the preceding User 3360 ID. The RSA public key can have many User IDs and each User ID can 3361 have many signatures. V3 keys are deprecated. Implementations MUST 3362 NOT generate new V3 keys, but MAY continue to use existing ones. 3364 The format of an OpenPGP V4 key that uses multiple public keys is 3365 similar except that the other keys are added to the end as "subkeys" 3366 of the primary key. 3368 Primary-Key 3369 [Revocation Self Signature] 3370 [Direct Key Signature...] 3371 User ID [Signature ...] 3372 [User ID [Signature ...] ...] 3373 [User Attribute [Signature ...] ...] 3374 [[Subkey [Binding-Signature-Revocation] 3375 Primary-Key-Binding-Signature] ...] 3377 A subkey always has a single signature after it that is issued using 3378 the primary key to tie the two keys together. This binding signature 3379 may be in either V3 or V4 format, but SHOULD be V4. Subkeys that can 3380 issue signatures MUST have a V4 binding signature due to the 3381 REQUIRED embedded primary key binding signature. 3383 In the above diagram, if the binding signature of a subkey has been 3384 revoked, the revoked key may be removed, leaving only one key. 3386 In a V4 key, the primary key MUST be a key capable of certification. 3387 The subkeys may be keys of any other type. There may be other 3388 constructions of V4 keys, too. For example, there may be a 3389 single-key RSA key in V4 format, a DSA primary key with an RSA 3390 encryption key, or RSA primary key with an Elgamal subkey, etc. 3392 It is also possible to have a signature-only subkey. This permits a 3393 primary key that collects certifications (key signatures) but is 3394 used only used for certifying subkeys that are used for encryption 3395 and signatures. 3397 12.2. Key IDs and Fingerprints 3399 For a V3 key, the eight-octet key ID consists of the low 64 bits of 3400 the public modulus of the RSA key. 3402 The fingerprint of a V3 key is formed by hashing the body (but not 3403 the two-octet length) of the MPIs that form the key material (public 3404 modulus n, followed by exponent e) with MD5. Note that both V3 keys 3405 and MD5 are deprecated. 3407 A V4 fingerprint is the 160-bit SHA-1 hash of the octet 0x99, 3408 followed by the two-octet packet length, followed by the entire 3409 Public Key packet starting with the version field. The key ID is the 3410 low order 64 bits of the fingerprint. Here are the fields of the 3411 hash material, with the example of a DSA key: 3413 a.1) 0x99 (1 octet) 3415 a.2) high order length octet of (b)-(f) (1 octet) 3417 a.3) low order length octet of (b)-(f) (1 octet) 3419 b) version number = 4 (1 octet); 3421 c) time stamp of key creation (4 octets); 3423 d) algorithm (1 octet): 17 = DSA (example); 3425 e) Algorithm specific fields. 3427 Algorithm Specific Fields for DSA keys (example): 3429 e.1) MPI of DSA prime p; 3431 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 3433 e.3) MPI of DSA group generator g; 3435 e.4) MPI of DSA public key value y (= g**x mod p where x is secret). 3437 Note that it is possible for there to be collisions of key IDs -- 3438 two different keys with the same key ID. Note that there is a much 3439 smaller, but still non-zero probability that two different keys have 3440 the same fingerprint. 3442 Also note that if V3 and V4 format keys share the same RSA key 3443 material, they will have different key IDs as well as different 3444 fingerprints. 3446 Finally, the key ID and fingerprint of a subkey are calculated in 3447 the same way as for a primary key, including the 0x99 as the first 3448 octet (even though this is not a valid packet ID for a public 3449 subkey). 3451 13. Notes on Algorithms 3453 13.1. PKCS#1 Encoding In OpenPGP 3455 This standard makes use of the PKCS#1 functions EME-PKCS1-v1_5 and 3456 EMSA-PKCS1-v1_5. However, the calling conventions of these functions 3457 has changed in the past. To avoid potential confusion and 3458 interoperability problems, we are including local copies in this 3459 document, adapted from those in PKCS#1 v2.1 [RFC3447]. RFC-3447 3460 should be treated as the ultimate authority on PKCS#1 for OpenPGP. 3461 Nonetheless, we believe that there is value in having a 3462 self-contained document that avoids problems in the future with 3463 needed changes in the conventions. 3465 13.1.1. EME-PKCS1-v1_5-ENCODE 3467 Input: 3469 k = the length in octets of the key modulus 3471 M = message to be encoded, an octet string of length mLen, where 3472 mLen <= k - 11 3474 Output: 3476 EM = encoded message, an octet string of length k 3478 Error: "message too long" 3480 1. Length checking: If mLen > k - 11, output "message too long" and 3481 stop. 3483 2. Generate an octet string PS of length k - mLen - 3 consisting of 3484 pseudo-randomly generated nonzero octets. The length of PS will 3485 be at least eight octets. 3487 3. Concatenate PS, the message M, and other padding to form an 3488 encoded message EM of length k octets as 3490 EM = 0x00 || 0x02 || PS || 0x00 || M. 3492 4. Output EM. 3494 13.1.2. EME-PKCS1-v1_5-DECODE 3496 Input: 3498 EM = encoded message, an octet string 3500 Output: 3502 M = message, an octet string 3504 Error: "decryption error" 3506 To decode an EME-PKCS1_v1_5 message, separate the encoded message EM 3507 into an octet string PS consisting of nonzero octets and a message M 3508 as 3510 EM = 0x00 || 0x02 || PS || 0x00 || M. 3512 If the first octet of EM does not have hexadecimal value 0x00, if 3513 the second octet of EM does not have hexadecimal value 0x02, if 3514 there is no octet with hexadecimal value 0x00 to separate PS from M, 3515 or if the length of PS is less than 8 octets, output "decryption 3516 error" and stop. See also the security note in section 13 regarding 3517 differences in reporting between a decryption error and a padding 3518 error. 3520 13.1.3. EMSA-PKCS1-v1_5 3522 This encoding method is deterministic and only has an encoding 3523 operation. 3525 Option: 3527 Hash hash function (hLen denotes the length in octets of the hash 3528 function output) 3530 Input: 3532 M = message to be encoded 3534 mL = intended length in octets of the encoded message, at least tLen 3535 + 11, where tLen is the octet length of the DER encoding T of a 3536 certain value computed during the encoding operation 3538 Output: 3540 EM = encoded message, an octet string of length emLen 3542 Errors: "message too long"; "intended encoded message length too 3543 short" 3545 Steps: 3547 1. Apply the hash function to the message M to produce a hash value 3548 H: 3550 H = Hash(M). 3552 If the hash function outputs "message too long," output "message 3553 too long" and stop. 3555 2. Using the list in section 5.2.2, produce an ASN.1 DER value for 3556 the hash function used. Let T be the full hash prefix from 3557 section 5.2.2, and let tLen be the length in octets of T. 3559 3. If emLen < tLen + 11, output "intended encoded message length 3560 too short" and stop. 3562 4. Generate an octet string PS consisting of emLen - tLen - 3 3563 octets with hexadecimal value 0xff. The length of PS will be at 3564 least 8 octets. 3566 5. Concatenate PS, the hash prefix T, and other padding to form the 3567 encoded message EM as 3569 EM = 0x00 || 0x01 || PS || 0x00 || T. 3571 6. Output EM. 3573 13.2. Symmetric Algorithm Preferences 3575 The symmetric algorithm preference is an ordered list of algorithms 3576 that the keyholder accepts. Since it is found on a self-signature, 3577 it is possible that a keyholder may have multiple, different 3578 preferences. For example, Alice may have TripleDES only specified 3579 for "alice@work.com" but CAST5, Blowfish, and TripleDES specified 3580 for "alice@home.org". Note that it is also possible for preferences 3581 to be in a subkey's binding signature. 3583 Since TripleDES is the MUST-implement algorithm, if it is not 3584 explicitly in the list, it is tacitly at the end. However, it is 3585 good form to place it there explicitly. Note also that if an 3586 implementation does not implement the preference, then it is 3587 implicitly a TripleDES-only implementation. 3589 An implementation MUST NOT use a symmetric algorithm that is not in 3590 the recipient's preference list. When encrypting to more than one 3591 recipient, the implementation finds a suitable algorithm by taking 3592 the intersection of the preferences of the recipients. Note that the 3593 MUST-implement algorithm, TripleDES, ensures that the intersection 3594 is not null. The implementation may use any mechanism to pick an 3595 algorithm in the intersection. 3597 If an implementation can decrypt a message that a keyholder doesn't 3598 have in their preferences, the implementation SHOULD decrypt the 3599 message anyway, but MUST warn the keyholder that the protocol has 3600 been violated. For example, suppose that Alice, above, has software 3601 that implements all algorithms in this specification. Nonetheless, 3602 she prefers subsets for work or home. If she is sent a message 3603 encrypted with IDEA, which is not in her preferences, the software 3604 warns her that someone sent her an IDEA-encrypted message, but it 3605 would ideally decrypt it anyway. 3607 13.3. Other Algorithm Preferences 3609 Other algorithm preferences work similarly to the symmetric 3610 algorithm preference, in that they specify which algorithms the 3611 keyholder accepts. There are two interesting cases that other 3612 comments need to be made about, though, the compression preferences 3613 and the hash preferences. 3615 13.3.1. Compression Preferences 3617 Compression has been an integral part of PGP since its first days. 3619 OpenPGP and all previous versions of PGP have offered compression. 3620 In this specification, the default is for messages to be compressed, 3621 although an implementation is not required to do so. Consequently, 3622 the compression preference gives a way for a keyholder to request 3623 that messages not be compressed, presumably because they are using a 3624 minimal implementation that does not include compression. 3625 Additionally, this gives a keyholder a way to state that it can 3626 support alternate algorithms. 3628 Like the algorithm preferences, an implementation MUST NOT use an 3629 algorithm that is not in the preference vector. If the preferences 3630 are not present, then they are assumed to be [ZIP(1), 3631 UNCOMPRESSED(0)]. 3633 Additionally, an implementation MUST implement this preference to 3634 the degree of recognizing when to send an uncompressed message. A 3635 robust implementation would satisfy this requirement by looking at 3636 the recipient's preference and acting accordingly. A minimal 3637 implementation can satisfy this requirement by never generating a 3638 compressed message, since all implementations can handle messages 3639 that have not been compressed. 3641 13.3.2. Hash Algorithm Preferences 3643 Typically, the choice of a hash algorithm is something the signer 3644 does, rather than the verifier, because a signer rarely knows who is 3645 going to be verifying the signature. This preference, though, allows 3646 a protocol based upon digital signatures ease in negotiation. 3648 Thus, if Alice is authenticating herself to Bob with a signature, it 3649 makes sense for her to use a hash algorithm that Bob's software 3650 uses. This preference allows Bob to state in his key which 3651 algorithms Alice may use. 3653 Since SHA1 is the MUST-implement hash algorithm, if it is not 3654 explicitly in the list, it is tacitly at the end. However, it is 3655 good form to place it there explicitly. 3657 13.4. Plaintext 3659 Algorithm 0, "plaintext," may only be used to denote secret keys 3660 that are stored in the clear. Implementations MUST NOT use plaintext 3661 in Symmetrically Encrypted Data Packets; they must use Literal Data 3662 Packets to encode unencrypted or literal data. 3664 13.5. RSA 3666 There are algorithm types for RSA-signature-only, and 3667 RSA-encrypt-only keys. These types are deprecated. The "key flags" 3668 subpacket in a signature is a much better way to express the same 3669 idea, and generalizes it to all algorithms. An implementation SHOULD 3670 NOT create such a key, but MAY interpret it. 3672 An implementation SHOULD NOT implement RSA keys of size less than 3673 1024 bits. 3675 13.6. DSA 3677 An implementation SHOULD NOT implement DSA keys of size less than 3678 1024 bits. It MUST NOT implement a DSA key with a q size of less 3679 than 160 bits. DSA keys MUST also be a multiple of 64 bits, and the 3680 q size MUST be a multiple of 8 bits. The Digital Signature Standard 3681 (DSS) [FIPS186] specifies that DSA be used in one of the following 3682 ways: 3684 * 1024-bit key, 160-bit q, SHA-1, SHA-224, SHA-256, SHA-384 or 3685 SHA-512 hash 3687 * 2048-bit key, 224-bit q, SHA-224, SHA-256, SHA-384 or SHA-512 3688 hash 3690 * 2048-bit key, 256-bit q, SHA-256, SHA-384 or SHA-512 hash 3692 * 3072-bit key, 256-bit q, SHA-256, SHA-384 or SHA-512 hash 3694 The above key and q size pairs were chosen to best balance the 3695 strength of the key with the strength of the hash. Implementations 3696 SHOULD use one of the above key and q size pairs when generating DSA 3697 keys. If DSS compliance is desired, one of the specified SHA hashes 3698 must be used as well. [FIPS186] is the ultimate authority on DSS, 3699 and should be consulted for all questions of DSS compliance. 3701 Note that earlier versions of this standard only allowed a 160-bit q 3702 with no truncation allowed, so earlier implementations may not be 3703 able to handle signatures with a different q size or a truncated 3704 hash. 3706 13.7. Elgamal 3708 An implementation SHOULD NOT implement Elgamal keys of size less 3709 than 1024 bits. 3711 13.8. Reserved Algorithm Numbers 3713 A number of algorithm IDs have been reserved for algorithms that 3714 would be useful to use in an OpenPGP implementation, yet there are 3715 issues that prevent an implementer from actually implementing the 3716 algorithm. These are marked in the Public Algorithms section as 3717 "(reserved for)". 3719 The reserved public key algorithms, Elliptic Curve (18), ECDSA (19), 3720 and X9.42 (21) do not have the necessary parameters, parameter 3721 order, or semantics defined. 3723 Previous versions of OpenPGP permitted Elgamal [ELGAMAL] signatures 3724 with a public key identifier of 20. These are no longer permitted. 3725 An implementation MUST NOT generate such keys. An implementation 3726 MUST NOT generate Elgamal signatures. See [BLEICHENBACHER]. 3728 13.9. OpenPGP CFB mode 3730 OpenPGP does symmetric encryption using a variant of Cipher Feedback 3731 Mode (CFB mode). This section describes the procedure it uses in 3732 detail. This mode is what is used for Symmetrically Encrypted Data 3733 Packets; the mechanism used for encrypting secret key material is 3734 similar, but described in those sections above. 3736 In the description below, the value BS is the block size in octets 3737 of the cipher. Most ciphers have a block size of 8 octets. The AES 3738 and Twofish have a block size of 16 octets. Also note that the 3739 description below assumes that the IV and CFB arrays start with an 3740 index of 1 (unlike the C language, which assumes arrays start with a 3741 zero index). 3743 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 3744 and prefixes the plaintext with BS+2 octets of random data, such 3745 that octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB 3746 resynchronization after encrypting those BS+2 octets. 3748 Thus, for an algorithm that has a block size of 8 octets (64 bits), 3749 the IV is 10 octets long and octets 7 and 8 of the IV are the same 3750 as octets 9 and 10. For an algorithm with a block size of 16 octets 3751 (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate 3752 octets 15 and 16. Those extra two octets are an easy check for a 3753 correct key. 3755 Step by step, here is the procedure: 3757 1. The feedback register (FR) is set to the IV, which is all zeros. 3759 2. FR is encrypted to produce FRE (FR Encrypted). This is the 3760 encryption of an all-zero value. 3762 3. FRE is xored with the first BS octets of random data prefixed to 3763 the plaintext to produce C[1] through C[BS], the first BS octets 3764 of ciphertext. 3766 4. FR is loaded with C[1] through C[BS]. 3768 5. FR is encrypted to produce FRE, the encryption of the first BS 3769 octets of ciphertext. 3771 6. The left two octets of FRE get xored with the next two octets of 3772 data that were prefixed to the plaintext. This produces C[BS+1] 3773 and C[BS+2], the next two octets of ciphertext. 3775 7. (The resynchronization step) FR is loaded with C[3] through 3776 C[BS+2]. 3778 8. FR is encrypted to produce FRE. 3780 9. FRE is xored with the first BS octets of the given plaintext, 3781 now that we have finished encrypting the BS+2 octets of prefixed 3782 data. This produces C[BS+3] through C[BS+(BS+2)], the next BS 3783 octets of ciphertext. 3785 10. FR is loaded with C[BS+3] to C[BS + (BS+2)] (which is C11-C18 3786 for an 8-octet block). 3788 11. FR is encrypted to produce FRE. 3790 12. FRE is xored with the next BS octets of plaintext, to produce 3791 the next BS octets of ciphertext. These are loaded into FR and 3792 the process is repeated until the plaintext is used up. 3794 14. Security Considerations 3796 * As with any technology involving cryptography, you should check 3797 the current literature to determine if any algorithms used here 3798 have been found to be vulnerable to attack. 3800 * This specification uses Public Key Cryptography technologies. It 3801 is assumed that the private key portion of a public-private key 3802 pair is controlled and secured by the proper party or parties. 3804 * Certain operations in this specification involve the use of 3805 random numbers. An appropriate entropy source should be used to 3806 generate these numbers. See RFC 4086. 3808 * The MD5 hash algorithm has been found to have weaknesses, with 3809 collisions found in a number of cases. MD5 is deprecated for use 3810 in OpenPGP. Implementations MUST NOT generate new signatures 3811 using MD5 as a hash function. They MAY continue to consider old 3812 signatures that used MD5 as valid. 3814 * SHA-224 and SHA-384 require the same work as SHA-256 and SHA-512 3815 respectively. In general, there are few reasons to use them 3816 outside of DSS compatibility. You need a situation where one 3817 needs more security than smaller hashes, but does not want to 3818 have the full 256-bit or 512-bit data length. 3820 * Many security protocol designers think that it is a bad idea to 3821 use a single key for both privacy (encryption) and integrity 3822 (signatures). In fact, this was one of the motivating forces 3823 behind the V4 key format with separate signature and encryption 3824 keys. If you as an implementer promote dual-use keys, you should 3825 at least be aware of this controversy. 3827 * The DSA algorithm will work with any hash, but is sensitive to 3828 the quality of the hash algorithm. Verifiers should be aware 3829 that even if the signer used a strong hash, an attacker could 3830 have modified the signature to use a weak one. Only signatures 3831 using acceptably strong hash algorithms should be accepted as 3832 valid. 3834 * As OpenPGP combines many different asymmetric, symmetric, and 3835 hash algorithms, each with different measures of strength, care 3836 should be taken that the weakest element of an OpenPGP message 3837 is still sufficiently strong for the purpose at hand. While 3838 consensus about the the strength of a given algorithm may 3839 evolve, NIST Special Publication 800-57 [SP800-57] recommends 3840 the following list of equivalent strengths: 3842 Asymmetric | Hash | Symmetric 3843 key size | size | key size 3844 ------------+--------+----------- 3845 1024 160 80 3846 2048 224 112 3847 3072 256 128 3848 7680 384 192 3849 15360 512 256 3851 * There is a somewhat-related potential security problem in 3852 signatures. If an attacker can find a message that hashes to the 3853 same hash with a different algorithm, a bogus signature 3854 structure can be constructed that evaluates correctly. 3856 For example, suppose Alice DSA signs message M using hash 3857 algorithm H. Suppose that Mallet finds a message M' that has the 3858 same hash value as M with H'. Mallet can then construct a 3859 signature block that verifies as Alice's signature of M' with 3860 H'. However, this would also constitute a weakness in either H 3861 or H' or both. Should this ever occur, a revision will have to 3862 be made to this document to revise the allowed hash algorithms. 3864 * If you are building an authentication system, the recipient may 3865 specify a preferred signing algorithm. However, the signer would 3866 be foolish to use a weak algorithm simply because the recipient 3867 requests it. 3869 * Some of the encryption algorithms mentioned in this document 3870 have been analyzed less than others. For example, although CAST5 3871 is presently considered strong, it has been analyzed less than 3872 TripleDES. Other algorithms may have other controversies 3873 surrounding them. 3875 * In late summer 2002, Jallad, Katz, and Schneier published an 3876 interesting attack on the OpenPGP protocol and some of its 3877 implementations [JKS02]. In this attack, the attacker modifies a 3878 message and sends it to a user who then returns the erroneously 3879 decrypted message to the attacker. The attacker is thus using 3880 the user as a random oracle, and can often decrypt the message. 3882 Compressing data can ameliorate this attack. The incorrectly 3883 decrypted data nearly always decompresses in ways that defeats 3884 the attack. However, this is not a rigorous fix, and leaves open 3885 some small vulnerabilities. For example, if an implementation 3886 does not compress a message before encryption (perhaps because 3887 it knows it was already compressed), then that message is 3888 vulnerable. Because of this happenstance -- that modification 3889 attacks can be thwarted by decompression errors, an 3890 implementation SHOULD treat a decompression error as a security 3891 problem, not merely a data problem. 3893 This attack can be defeated by the use of Modification 3894 Detection, provided that the implementation does not let the 3895 user naively return the data to the attacker. An implementation 3896 MUST treat an MDC failure as a security problem, not merely a 3897 data problem. 3899 In either case, the implementation MAY allow the user access to 3900 the erroneous data, but MUST warn the user as to potential 3901 security problems should that data be returned to the sender. 3903 While this attack is somewhat obscure, requiring a special set 3904 of circumstances to create it, it is nonetheless quite serious 3905 as it permits someone to trick a user to decrypt a message. 3906 Consequently, it is important that: 3908 1. Implementers treat MDC errors and decompression failures as 3909 security problems. 3911 2. Implementers implement Modification Detection with all due 3912 speed and encourage its spread. 3914 3. Users migrate to implementations that support Modification 3915 Detection with all due speed. 3917 * PKCS#1 has been found to be vulnerable to attacks in which a 3918 system that reports errors in padding differently from errors in 3919 decryption becomes a random oracle that can leak the private key 3920 in mere millions of queries. Implementations must be aware of 3921 this attack and prevent it from happening. The simplest solution 3922 is report a single error code for all variants of decryption 3923 errors so as not to leak information to an attacker. 3925 * Some technologies mentioned here may be subject to government 3926 control in some countries. 3928 * In winter 2005, Serge Mister and Robert Zuccherato from Entrust 3929 released a paper describing a way that the "quick check" in 3930 OpenPGP CFB mode can be used with a random oracle to decrypt two 3931 octets of every cipher block [MZ05]. They recommend as 3932 prevention not using the quick check at all. 3934 Many implementers have taken this advice to heart for any data 3935 that is symmetrically encrypted and for which the session key is 3936 public-key encrypted. In this case, the quick check is not 3937 needed as the public key encryption of the session key should 3938 guarantee that it is the right session key. In other cases, the 3939 implementation should use the quick check with care. 3941 On the one hand, there is a danger to using it if there is a 3942 random oracle that can leak information to an attacker. In 3943 plainer language, there is a danger to using the quick check if 3944 timing information about the check can be exposed to an 3945 attacker, particularly via an automated service that allows 3946 rapidly repeated queries. 3948 On the other hand, it is inconvenient to the user to be informed 3949 that they typed in the wrong passphrase only after a petabyte of 3950 data is decrypted. There are many cases in cryptographic 3951 engineering where the implementer must use care and wisdom, and 3952 this is one. 3954 15. Implementation Nits 3956 This section is a collection of comments to help an implementer, 3957 particularly with an eye to backward compatibility. Previous 3958 implementations of PGP are not OpenPGP-compliant. Often the 3959 differences are small, but small differences are frequently more 3960 vexing than large differences. Thus, this is a non-comprehensive 3961 list of potential problems and gotchas for a developer who is trying 3962 to be backward-compatible. 3964 * The IDEA algorithm is patented, and yet it is required for PGP 3965 2.x interoperability. It is also the de-facto preferred 3966 algorithm for a V3 key with a V3 self-signature (or no 3967 self-signature). 3969 * When exporting a private key, PGP 2.x generates the header 3970 "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY 3971 BLOCK". All previous versions ignore the implied data type, and 3972 look directly at the packet data type. 3974 * PGP 2.0 through 2.5 generated V2 Public Key Packets. These are 3975 identical to the deprecated V3 keys except for the version 3976 number. An implementation MUST NOT generate them and may accept 3977 or reject them as it sees fit. Some older PGP versions generated 3978 V2 PKESK packets (Tag 1) as well. An implementation may accept 3979 or reject V2 PKESK packets as it sees fit, and MUST NOT generate 3980 them. 3982 * PGP 2.6.x will not accept key-material packets with versions 3983 greater than 3. 3985 * There are many ways possible for two keys to have the same key 3986 material, but different fingerprints (and thus key IDs). Perhaps 3987 the most interesting is an RSA key that has been "upgraded" to 3988 V4 format, but since a V4 fingerprint is constructed by hashing 3989 the key creation time along with other things, two V4 keys 3990 created at different times, yet with the same key material will 3991 have different fingerprints. 3993 * If an implementation is using zlib to interoperate with PGP 2.x, 3994 then the "windowBits" parameter should be set to -13. 3996 * The 0x19 back signatures were not required for signing subkeys 3997 until relatively recently. Consquently, there may be keys in the 3998 wild that do not have these back signatures. Implementing 3999 software may handle these keys as it sees fit. 4001 16. Authors' Addresses 4003 The working group can be contacted via the current chair: 4005 Derek Atkins 4006 IHTFP Consulting, Inc. 4007 6 Farragut Ave 4008 Somerville, MA 02144 USA 4009 Email: derek@ihtfp.com 4010 Tel: +1 617 623 3745 4012 The principal authors of this draft are: 4014 Jon Callas 4015 Email: jon@callas.org 4017 Lutz Donnerhacke 4018 IKS GmbH 4019 Wildenbruchstr. 15 4020 07745 Jena, Germany 4022 EMail: lutz@iks-jena.de 4024 Hal Finney 4025 Email: hal@finney.org 4027 David Shaw 4028 Email: dshaw@jabberwocky.com 4029 Rodney Thayer 4030 Email: rodney@tillerman.to 4032 This memo also draws on much previous work from a number of other 4033 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 4034 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Ben 4035 Laurie, Raph Levien, Colin Plumb, Will Price, David Shaw, William 4036 Stallings, Mark Weaver, and Philip R. Zimmermann. 4038 17. References (Normative) 4040 [AES] Advanced Encryption Standards Questions and Answers 4041 4044 4047 [BLOWFISH] Schneier, B. "Description of a New Variable-Length 4048 Key, 64-Bit Block Cipher (Blowfish)" Fast Software 4049 Encryption, Cambridge Security Workshop Proceedings 4050 (December 1993), Springer-Verlag, 1994, pp191-204 4051 4053 [BZ2] J. Seward, jseward@acm.org, "The Bzip2 and libbzip2 4054 home page" 4056 [ELGAMAL] T. Elgamal, "A Public-Key Cryptosystem and a 4057 Signature Scheme Based on Discrete Logarithms," 4058 IEEE Transactions on Information Theory, v. IT-31, 4059 n. 4, 1985, pp. 469-472. 4061 [FIPS180] Secure Hash Signature Standard (SHS) (FIPS PUB 4062 180-2). 4063 4066 [FIPS186] Digital Signature Standard (DSS) (FIPS PUB 186-2). 4067 4069 FIPS 186-3 describes keys greater than 1024 bits. 4070 The latest draft is at: 4071 4074 [HAC] Alfred Menezes, Paul van Oorschot, and Scott 4075 Vanstone, "Handbook of Applied Cryptography," CRC 4076 Press, 1996. 4077 4079 [IDEA] Lai, X, "On the design and security of block 4080 ciphers", ETH Series in Information Processing, 4081 J.L. Massey (editor), Vol. 1, Hartung-Gorre Verlag 4082 Knostanz, Technische Hochschule (Zurich), 1992 4084 [ISO10646] ISO/IEC 10646-1:1993. International Standard -- 4085 Information technology -- Universal Multiple-Octet 4086 Coded Character Set (UCS) -- Part 1: Architecture 4087 and Basic Multilingual Plane. 4089 [JFIF] JPEG File Interchange Format (Version 1.02). 4090 Eric Hamilton, C-Cube Microsystems, Milpitas, CA, 4091 September 1, 1992. 4093 [RFC2045] Borenstein, N. and N. Freed, "Multipurpose Internet 4094 Mail Extensions (MIME) Part One: Format of Internet 4095 Message Bodies.", RFC 2045, November 1996. 4097 [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC 4098 2144, May 1997. 4100 [RFC2822] Resnick, P., "Internet Message Format", RFC 2822. 4102 [RFC3156] M. Elkins, D. Del Torto, R. Levien, T. Roessler, 4103 "MIME Security with OpenPGP", RFC 3156, 4104 August 2001. 4106 [RFC3447] B. Kaliski and J. Staddon, "PKCS #1: RSA 4107 Cryptography Specifications Version 2.1", 4108 RFC 3447, February 2003. 4110 [RFC3629] Yergeau., F., "UTF-8, a transformation format of 4111 Unicode and ISO 10646", RFC 3629, November 2003. 4113 [RFC4086] Eastlake, D., Crocker, S. and J. Schiller, 4114 "Randomness Recommendations for Security", RFC 4115 4086, June 2005. 4117 [SCHNEIER] Schneier, B., "Applied Cryptography Second Edition: 4118 protocols, algorithms, and source code in C", 1996. 4120 [TWOFISH] B. Schneier, J. Kelsey, D. Whiting, D. Wagner, C. 4121 Hall, and N. Ferguson, "The Twofish Encryption 4122 Algorithm", John Wiley & Sons, 1999. 4124 18. References (Informative) 4126 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating Elgamal 4127 signatures without knowing the secret key," 4128 Eurocrypt 96. Note that the version in the 4129 proceedings has an error. A revised version is 4130 available at the time of writing from 4131 4134 [JKS02] Kahil Jallad, Jonathan Katz, Bruce Schneier 4135 "Implementation of Chosen-Ciphertext Attacks 4136 against PGP and GnuPG" 4137 http://www.counterpane.com/pgp-attack.html 4139 [MAURER] Ueli Maurer, "Modelling a Public-Key 4140 Infrastructure", Proc. 1996 European Symposium on 4141 Research in Computer Security (ESORICS' 96), 4142 Lecture Notes in Computer Science, Springer-Verlag, 4143 vol. 1146, pp. 325-350, Sep 1996. 4145 [MZ05] Serge Mister, Robert Zuccherato, "An Attack on 4146 CFB Mode Encryption As Used By OpenPGP," IACR 4147 ePrint Archive: Report 2005/033, 8 Feb 2005 4148 http://eprint.iacr.org/2005/033 4150 [RFC1423] Balenson, D., "Privacy Enhancement for Internet 4151 Electronic Mail: Part III: Algorithms, Modes, and 4152 Identifiers", RFC 1423, October 1993. 4154 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format 4155 Specification version 1.3.", RFC 1951, May 1996. 4157 [RFC1991] Atkins, D., Stallings, W. and P. Zimmermann, "PGP 4158 Message Exchange Formats", RFC 1991, August 1996. 4160 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 4161 Requirement Level", BCP 14, RFC 2119, March 1997. 4162 [RFC2434] Narten, T. and H. Alvestrand, "Guidelines for 4163 Writing an IANA Considerations Section in RFCs", 4164 BCP 26, RFC 2434, October 1998. 4166 [SP800-57] NIST Special Publication 800-57, Recommendation on 4167 Key Management 4168 4170 4173 19. Full Copyright Statement 4175 Copyright (C) 2007 by The IETF Trust. 4177 This document is subject to the rights, licenses and restrictions 4178 contained in BCP 78, and except as set forth therein, the authors 4179 retain all their rights. 4181 This document and the information contained herein are provided on 4182 an "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE 4183 REPRESENTS OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE 4184 IETF TRUST AND THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL 4185 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY 4186 WARRANTY THAT THE USE OF THE INFORMATION HEREIN WILL NOT INFRINGE 4187 ANY RIGHTS OR ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS 4188 FOR A PARTICULAR PURPOSE. 4190 This document and translations of it may be copied and furnished to 4191 others, and derivative works that comment on or otherwise explain it 4192 or assist in its implementation may be prepared, copied, published 4193 and distributed, in whole or in part, without restriction of any 4194 kind, provided that the above copyright notice and this paragraph 4195 are included on all such copies and derivative works. However, this 4196 document itself may not be modified in any way, such as by removing 4197 the copyright notice or references to the Internet Society or other 4198 Internet organizations, except as needed for the purpose of 4199 developing Internet standards in which case the procedures for 4200 copyrights defined in the Internet Standards process must be 4201 followed, or as required to translate it into languages other than 4202 English. 4204 The limited permissions granted above are perpetual and will not be 4205 revoked by the Internet Society or its successors or assigns. 4207 20. Intellectual Property 4209 The IETF takes no position regarding the validity or scope of any 4210 Intellectual Property Rights or other rights that might be claimed 4211 to pertain to the implementation or use of the technology described 4212 in this document or the extent to which any license under such 4213 rights might or might not be available; nor does it represent that 4214 it has made any independent effort to identify any such rights. 4215 Information on the procedures with respect to rights in RFC 4216 documents can be found in BCP 78 and BCP 79. 4218 Copies of IPR disclosures made to the IETF Secretariat and any 4219 assurances of licenses to be made available, or the result of an 4220 attempt made to obtain a general license or permission for the use 4221 of such proprietary rights by implementers or users of this 4222 specification can be obtained from the IETF on-line IPR repository 4223 at http://www.ietf.org/ipr. 4225 The IETF invites any interested party to bring to its attention any 4226 copyrights, patents or patent applications, or other proprietary 4227 rights that may cover technology that may be required to implement 4228 this standard. Please address the information to the IETF at 4229 ietf-ipr@ietf.org.