1 2 3 4 5 6 7Network Working Group J. Callas 8Request for Comments: 4880 PGP Corporation 9Obsoletes: 1991, 2440 L. Donnerhacke 10Category: Standards Track IKS GmbH 11 H. Finney 12 PGP Corporation 13 D. Shaw 14 R. Thayer 15 November 2007 16 17 18 OpenPGP Message Format 19 20Status of This Memo 21 22 This document specifies an Internet standards track protocol for the 23 Internet community, and requests discussion and suggestions for 24 improvements. Please refer to the current edition of the "Internet 25 Official Protocol Standards" (STD 1) for the standardization state 26 and status of this protocol. Distribution of this memo is unlimited. 27 28Abstract 29 30 This document is maintained in order to publish all necessary 31 information needed to develop interoperable applications based on the 32 OpenPGP format. It is not a step-by-step cookbook for writing an 33 application. It describes only the format and methods needed to 34 read, check, generate, and write conforming packets crossing any 35 network. It does not deal with storage and implementation questions. 36 It does, however, discuss implementation issues necessary to avoid 37 security flaws. 38 39 OpenPGP software uses a combination of strong public-key and 40 symmetric cryptography to provide security services for electronic 41 communications and data storage. These services include 42 confidentiality, key management, authentication, and digital 43 signatures. This document specifies the message formats used in 44 OpenPGP. 45 46 47 48 49 50 51 52 53 54 55 56 57 58Callas, et al Standards Track [Page 1] 59 60RFC 4880 OpenPGP Message Format November 2007 61 62 63Table of Contents 64 65 1. Introduction ....................................................5 66 1.1. Terms ......................................................5 67 2. General functions ...............................................6 68 2.1. Confidentiality via Encryption .............................6 69 2.2. Authentication via Digital Signature .......................7 70 2.3. Compression ................................................7 71 2.4. Conversion to Radix-64 .....................................8 72 2.5. Signature-Only Applications ................................8 73 3. Data Element Formats ............................................8 74 3.1. Scalar Numbers .............................................8 75 3.2. Multiprecision Integers ....................................9 76 3.3. Key IDs ....................................................9 77 3.4. Text .......................................................9 78 3.5. Time Fields ...............................................10 79 3.6. Keyrings ..................................................10 80 3.7. String-to-Key (S2K) Specifiers ............................10 81 3.7.1. String-to-Key (S2K) Specifier Types ................10 82 3.7.1.1. Simple S2K ................................10 83 3.7.1.2. Salted S2K ................................11 84 3.7.1.3. Iterated and Salted S2K ...................11 85 3.7.2. String-to-Key Usage ................................12 86 3.7.2.1. Secret-Key Encryption .....................12 87 3.7.2.2. Symmetric-Key Message Encryption ..........13 88 4. Packet Syntax ..................................................13 89 4.1. Overview ..................................................13 90 4.2. Packet Headers ............................................13 91 4.2.1. Old Format Packet Lengths ..........................14 92 4.2.2. New Format Packet Lengths ..........................15 93 4.2.2.1. One-Octet Lengths .........................15 94 4.2.2.2. Two-Octet Lengths .........................15 95 4.2.2.3. Five-Octet Lengths ........................15 96 4.2.2.4. Partial Body Lengths ......................16 97 4.2.3. Packet Length Examples .............................16 98 4.3. Packet Tags ...............................................17 99 5. Packet Types ...................................................17 100 5.1. Public-Key Encrypted Session Key Packets (Tag 1) ..........17 101 5.2. Signature Packet (Tag 2) ..................................19 102 5.2.1. Signature Types ....................................19 103 5.2.2. Version 3 Signature Packet Format ..................21 104 5.2.3. Version 4 Signature Packet Format ..................24 105 5.2.3.1. Signature Subpacket Specification .........25 106 5.2.3.2. Signature Subpacket Types .................27 107 5.2.3.3. Notes on Self-Signatures ..................27 108 5.2.3.4. Signature Creation Time ...................28 109 5.2.3.5. Issuer ....................................28 110 5.2.3.6. Key Expiration Time .......................28 111 112 113 114Callas, et al Standards Track [Page 2] 115 116RFC 4880 OpenPGP Message Format November 2007 117 118 119 5.2.3.7. Preferred Symmetric Algorithms ............28 120 5.2.3.8. Preferred Hash Algorithms .................29 121 5.2.3.9. Preferred Compression Algorithms ..........29 122 5.2.3.10. Signature Expiration Time ................29 123 5.2.3.11. Exportable Certification .................29 124 5.2.3.12. Revocable ................................30 125 5.2.3.13. Trust Signature ..........................30 126 5.2.3.14. Regular Expression .......................31 127 5.2.3.15. Revocation Key ...........................31 128 5.2.3.16. Notation Data ............................31 129 5.2.3.17. Key Server Preferences ...................32 130 5.2.3.18. Preferred Key Server .....................33 131 5.2.3.19. Primary User ID ..........................33 132 5.2.3.20. Policy URI ...............................33 133 5.2.3.21. Key Flags ................................33 134 5.2.3.22. Signer's User ID .........................34 135 5.2.3.23. Reason for Revocation ....................35 136 5.2.3.24. Features .................................36 137 5.2.3.25. Signature Target .........................36 138 5.2.3.26. Embedded Signature .......................37 139 5.2.4. Computing Signatures ...............................37 140 5.2.4.1. Subpacket Hints ...........................38 141 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) .......38 142 5.4. One-Pass Signature Packets (Tag 4) ........................39 143 5.5. Key Material Packet .......................................40 144 5.5.1. Key Packet Variants ................................40 145 5.5.1.1. Public-Key Packet (Tag 6) .................40 146 5.5.1.2. Public-Subkey Packet (Tag 14) .............40 147 5.5.1.3. Secret-Key Packet (Tag 5) .................41 148 5.5.1.4. Secret-Subkey Packet (Tag 7) ..............41 149 5.5.2. Public-Key Packet Formats ..........................41 150 5.5.3. Secret-Key Packet Formats ..........................43 151 5.6. Compressed Data Packet (Tag 8) ............................45 152 5.7. Symmetrically Encrypted Data Packet (Tag 9) ...............45 153 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) ..........46 154 5.9. Literal Data Packet (Tag 11) ..............................46 155 5.10. Trust Packet (Tag 12) ....................................47 156 5.11. User ID Packet (Tag 13) ..................................48 157 5.12. User Attribute Packet (Tag 17) ...........................48 158 5.12.1. The Image Attribute Subpacket .....................48 159 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) ..49 160 5.14. Modification Detection Code Packet (Tag 19) ..............52 161 6. Radix-64 Conversions ...........................................53 162 6.1. An Implementation of the CRC-24 in "C" ....................54 163 6.2. Forming ASCII Armor .......................................54 164 6.3. Encoding Binary in Radix-64 ...............................57 165 6.4. Decoding Radix-64 .........................................58 166 6.5. Examples of Radix-64 ......................................59 167 168 169 170Callas, et al Standards Track [Page 3] 171 172RFC 4880 OpenPGP Message Format November 2007 173 174 175 6.6. Example of an ASCII Armored Message .......................59 176 7. Cleartext Signature Framework ..................................59 177 7.1. Dash-Escaped Text .........................................60 178 8. Regular Expressions ............................................61 179 9. Constants ......................................................61 180 9.1. Public-Key Algorithms .....................................62 181 9.2. Symmetric-Key Algorithms ..................................62 182 9.3. Compression Algorithms ....................................63 183 9.4. Hash Algorithms ...........................................63 184 10. IANA Considerations ...........................................63 185 10.1. New String-to-Key Specifier Types ........................64 186 10.2. New Packets ..............................................64 187 10.2.1. User Attribute Types ..............................64 188 10.2.1.1. Image Format Subpacket Types .............64 189 10.2.2. New Signature Subpackets ..........................64 190 10.2.2.1. Signature Notation Data Subpackets .......65 191 10.2.2.2. Key Server Preference Extensions .........65 192 10.2.2.3. Key Flags Extensions .....................65 193 10.2.2.4. Reason For Revocation Extensions .........65 194 10.2.2.5. Implementation Features ..................66 195 10.2.3. New Packet Versions ...............................66 196 10.3. New Algorithms ...........................................66 197 10.3.1. Public-Key Algorithms .............................66 198 10.3.2. Symmetric-Key Algorithms ..........................67 199 10.3.3. Hash Algorithms ...................................67 200 10.3.4. Compression Algorithms ............................67 201 11. Packet Composition ............................................67 202 11.1. Transferable Public Keys .................................67 203 11.2. Transferable Secret Keys .................................69 204 11.3. OpenPGP Messages .........................................69 205 11.4. Detached Signatures ......................................70 206 12. Enhanced Key Formats ..........................................70 207 12.1. Key Structures ...........................................70 208 12.2. Key IDs and Fingerprints .................................71 209 13. Notes on Algorithms ...........................................72 210 13.1. PKCS#1 Encoding in OpenPGP ...............................72 211 13.1.1. EME-PKCS1-v1_5-ENCODE .............................73 212 13.1.2. EME-PKCS1-v1_5-DECODE .............................73 213 13.1.3. EMSA-PKCS1-v1_5 ...................................74 214 13.2. Symmetric Algorithm Preferences ..........................75 215 13.3. Other Algorithm Preferences ..............................76 216 13.3.1. Compression Preferences ...........................76 217 13.3.2. Hash Algorithm Preferences ........................76 218 13.4. Plaintext ................................................77 219 13.5. RSA ......................................................77 220 13.6. DSA ......................................................77 221 13.7. Elgamal ..................................................78 222 13.8. Reserved Algorithm Numbers ...............................78 223 224 225 226Callas, et al Standards Track [Page 4] 227 228RFC 4880 OpenPGP Message Format November 2007 229 230 231 13.9. OpenPGP CFB Mode .........................................78 232 13.10. Private or Experimental Parameters ......................79 233 13.11. Extension of the MDC System .............................80 234 13.12. Meta-Considerations for Expansion .......................80 235 14. Security Considerations .......................................81 236 15. Implementation Nits ...........................................84 237 16. References ....................................................86 238 16.1. Normative References .....................................86 239 16.2. Informative References ...................................88 240 2411. Introduction 242 243 This document provides information on the message-exchange packet 244 formats used by OpenPGP to provide encryption, decryption, signing, 245 and key management functions. It is a revision of RFC 2440, "OpenPGP 246 Message Format", which itself replaces RFC 1991, "PGP Message 247 Exchange Formats" [RFC1991] [RFC2440]. 248 2491.1. Terms 250 251 * OpenPGP - This is a term for security software that uses PGP 5.x 252 as a basis, formalized in RFC 2440 and this document. 253 254 * PGP - Pretty Good Privacy. PGP is a family of software systems 255 developed by Philip R. Zimmermann from which OpenPGP is based. 256 257 * PGP 2.6.x - This version of PGP has many variants, hence the term 258 PGP 2.6.x. It used only RSA, MD5, and IDEA for its cryptographic 259 transforms. An informational RFC, RFC 1991, was written 260 describing this version of PGP. 261 262 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in the 263 community and also in the predecessor of this document, RFC 1991. 264 It has new formats and corrects a number of problems in the PGP 265 2.6.x design. It is referred to here as PGP 5.x because that 266 software was the first release of the "PGP 3" code base. 267 268 * GnuPG - GNU Privacy Guard, also called GPG. GnuPG is an OpenPGP 269 implementation that avoids all encumbered algorithms. 270 Consequently, early versions of GnuPG did not include RSA public 271 keys. GnuPG may or may not have (depending on version) support 272 for IDEA or other encumbered algorithms. 273 274 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of PGP 275 Corporation and are used with permission. The term "OpenPGP" refers 276 to the protocol described in this and related documents. 277 278 279 280 281 282Callas, et al Standards Track [Page 5] 283 284RFC 4880 OpenPGP Message Format November 2007 285 286 287 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 288 "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 289 document are to be interpreted as described in [RFC2119]. 290 291 The key words "PRIVATE USE", "HIERARCHICAL ALLOCATION", "FIRST COME 292 FIRST SERVED", "EXPERT REVIEW", "SPECIFICATION REQUIRED", "IESG 293 APPROVAL", "IETF CONSENSUS", and "STANDARDS ACTION" that appear in 294 this document when used to describe namespace allocation are to be 295 interpreted as described in [RFC2434]. 296 2972. General functions 298 299 OpenPGP provides data integrity services for messages and data files 300 by using these core technologies: 301 302 - digital signatures 303 304 - encryption 305 306 - compression 307 308 - Radix-64 conversion 309 310 In addition, OpenPGP provides key management and certificate 311 services, but many of these are beyond the scope of this document. 312 3132.1. Confidentiality via Encryption 314 315 OpenPGP combines symmetric-key encryption and public-key encryption 316 to provide confidentiality. When made confidential, first the object 317 is encrypted using a symmetric encryption algorithm. Each symmetric 318 key is used only once, for a single object. A new "session key" is 319 generated as a random number for each object (sometimes referred to 320 as a session). Since it is used only once, the session key is bound 321 to the message and transmitted with it. To protect the key, it is 322 encrypted with the receiver's public key. The sequence is as 323 follows: 324 325 1. The sender creates a message. 326 327 2. The sending OpenPGP generates a random number to be used as a 328 session key for this message only. 329 330 3. The session key is encrypted using each recipient's public key. 331 These "encrypted session keys" start the message. 332 333 334 335 336 337 338Callas, et al Standards Track [Page 6] 339 340RFC 4880 OpenPGP Message Format November 2007 341 342 343 4. The sending OpenPGP encrypts the message using the session key, 344 which forms the remainder of the message. Note that the message 345 is also usually compressed. 346 347 5. The receiving OpenPGP decrypts the session key using the 348 recipient's private key. 349 350 6. The receiving OpenPGP decrypts the message using the session key. 351 If the message was compressed, it will be decompressed. 352 353 With symmetric-key encryption, an object may be encrypted with a 354 symmetric key derived from a passphrase (or other shared secret), or 355 a two-stage mechanism similar to the public-key method described 356 above in which a session key is itself encrypted with a symmetric 357 algorithm keyed from a shared secret. 358 359 Both digital signature and confidentiality services may be applied to 360 the same message. First, a signature is generated for the message 361 and attached to the message. Then the message plus signature is 362 encrypted using a symmetric session key. Finally, the session key is 363 encrypted using public-key encryption and prefixed to the encrypted 364 block. 365 3662.2. Authentication via Digital Signature 367 368 The digital signature uses a hash code or message digest algorithm, 369 and a public-key signature algorithm. The sequence is as follows: 370 371 1. The sender creates a message. 372 373 2. The sending software generates a hash code of the message. 374 375 3. The sending software generates a signature from the hash code 376 using the sender's private key. 377 378 4. The binary signature is attached to the message. 379 380 5. The receiving software keeps a copy of the message signature. 381 382 6. The receiving software generates a new hash code for the received 383 message and verifies it using the message's signature. If the 384 verification is successful, the message is accepted as authentic. 385 3862.3. Compression 387 388 OpenPGP implementations SHOULD compress the message after applying 389 the signature but before encryption. 390 391 392 393 394Callas, et al Standards Track [Page 7] 395 396RFC 4880 OpenPGP Message Format November 2007 397 398 399 If an implementation does not implement compression, its authors 400 should be aware that most OpenPGP messages in the world are 401 compressed. Thus, it may even be wise for a space-constrained 402 implementation to implement decompression, but not compression. 403 404 Furthermore, compression has the added side effect that some types of 405 attacks can be thwarted by the fact that slightly altered, compressed 406 data rarely uncompresses without severe errors. This is hardly 407 rigorous, but it is operationally useful. These attacks can be 408 rigorously prevented by implementing and using Modification Detection 409 Codes as described in sections following. 410 4112.4. Conversion to Radix-64 412 413 OpenPGP's underlying native representation for encrypted messages, 414 signature certificates, and keys is a stream of arbitrary octets. 415 Some systems only permit the use of blocks consisting of seven-bit, 416 printable text. For transporting OpenPGP's native raw binary octets 417 through channels that are not safe to raw binary data, a printable 418 encoding of these binary octets is needed. OpenPGP provides the 419 service of converting the raw 8-bit binary octet stream to a stream 420 of printable ASCII characters, called Radix-64 encoding or ASCII 421 Armor. 422 423 Implementations SHOULD provide Radix-64 conversions. 424 4252.5. Signature-Only Applications 426 427 OpenPGP is designed for applications that use both encryption and 428 signatures, but there are a number of problems that are solved by a 429 signature-only implementation. Although this specification requires 430 both encryption and signatures, it is reasonable for there to be 431 subset implementations that are non-conformant only in that they omit 432 encryption. 433 4343. Data Element Formats 435 436 This section describes the data elements used by OpenPGP. 437 4383.1. Scalar Numbers 439 440 Scalar numbers are unsigned and are always stored in big-endian 441 format. Using n[k] to refer to the kth octet being interpreted, the 442 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 443 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 444 n[3]). 445 446 447 448 449 450Callas, et al Standards Track [Page 8] 451 452RFC 4880 OpenPGP Message Format November 2007 453 454 4553.2. Multiprecision Integers 456 457 Multiprecision integers (also called MPIs) are unsigned integers used 458 to hold large integers such as the ones used in cryptographic 459 calculations. 460 461 An MPI consists of two pieces: a two-octet scalar that is the length 462 of the MPI in bits followed by a string of octets that contain the 463 actual integer. 464 465 These octets form a big-endian number; a big-endian number can be 466 made into an MPI by prefixing it with the appropriate length. 467 468 Examples: 469 470 (all numbers are in hexadecimal) 471 472 The string of octets [00 01 01] forms an MPI with the value 1. The 473 string [00 09 01 FF] forms an MPI with the value of 511. 474 475 Additional rules: 476 477 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 478 479 The length field of an MPI describes the length starting from its 480 most significant non-zero bit. Thus, the MPI [00 02 01] is not 481 formed correctly. It should be [00 01 01]. 482 483 Unused bits of an MPI MUST be zero. 484 485 Also note that when an MPI is encrypted, the length refers to the 486 plaintext MPI. It may be ill-formed in its ciphertext. 487 4883.3. Key IDs 489 490 A Key ID is an eight-octet scalar that identifies a key. 491 Implementations SHOULD NOT assume that Key IDs are unique. The 492 section "Enhanced Key Formats" below describes how Key IDs are 493 formed. 494 4953.4. Text 496 497 Unless otherwise specified, the character set for text is the UTF-8 498 [RFC3629] encoding of Unicode [ISO10646]. 499 500 501 502 503 504 505 506Callas, et al Standards Track [Page 9] 507 508RFC 4880 OpenPGP Message Format November 2007 509 510 5113.5. Time Fields 512 513 A time field is an unsigned four-octet number containing the number 514 of seconds elapsed since midnight, 1 January 1970 UTC. 515 5163.6. Keyrings 517 518 A keyring is a collection of one or more keys in a file or database. 519 Traditionally, a keyring is simply a sequential list of keys, but may 520 be any suitable database. It is beyond the scope of this standard to 521 discuss the details of keyrings or other databases. 522 5233.7. String-to-Key (S2K) Specifiers 524 525 String-to-key (S2K) specifiers are used to convert passphrase strings 526 into symmetric-key encryption/decryption keys. They are used in two 527 places, currently: to encrypt the secret part of private keys in the 528 private keyring, and to convert passphrases to encryption keys for 529 symmetrically encrypted messages. 530 5313.7.1. String-to-Key (S2K) Specifier Types 532 533 There are three types of S2K specifiers currently supported, and 534 some reserved values: 535 536 ID S2K Type 537 -- -------- 538 0 Simple S2K 539 1 Salted S2K 540 2 Reserved value 541 3 Iterated and Salted S2K 542 100 to 110 Private/Experimental S2K 543 544 These are described in Sections 3.7.1.1 - 3.7.1.3. 545 5463.7.1.1. Simple S2K 547 548 This directly hashes the string to produce the key data. See below 549 for how this hashing is done. 550 551 Octet 0: 0x00 552 Octet 1: hash algorithm 553 554 Simple S2K hashes the passphrase to produce the session key. The 555 manner in which this is done depends on the size of the session key 556 (which will depend on the cipher used) and the size of the hash 557 558 559 560 561 562Callas, et al Standards Track [Page 10] 563 564RFC 4880 OpenPGP Message Format November 2007 565 566 567 algorithm's output. If the hash size is greater than the session key 568 size, the high-order (leftmost) octets of the hash are used as the 569 key. 570 571 If the hash size is less than the key size, multiple instances of the 572 hash context are created -- enough to produce the required key data. 573 These instances are preloaded with 0, 1, 2, ... octets of zeros (that 574 is to say, the first instance has no preloading, the second gets 575 preloaded with 1 octet of zero, the third is preloaded with two 576 octets of zeros, and so forth). 577 578 As the data is hashed, it is given independently to each hash 579 context. Since the contexts have been initialized differently, they 580 will each produce different hash output. Once the passphrase is 581 hashed, the output data from the multiple hashes is concatenated, 582 first hash leftmost, to produce the key data, with any excess octets 583 on the right discarded. 584 5853.7.1.2. Salted S2K 586 587 This includes a "salt" value in the S2K specifier -- some arbitrary 588 data -- that gets hashed along with the passphrase string, to help 589 prevent dictionary attacks. 590 591 Octet 0: 0x01 592 Octet 1: hash algorithm 593 Octets 2-9: 8-octet salt value 594 595 Salted S2K is exactly like Simple S2K, except that the input to the 596 hash function(s) consists of the 8 octets of salt from the S2K 597 specifier, followed by the passphrase. 598 5993.7.1.3. Iterated and Salted S2K 600 601 This includes both a salt and an octet count. The salt is combined 602 with the passphrase and the resulting value is hashed repeatedly. 603 This further increases the amount of work an attacker must do to try 604 dictionary attacks. 605 606 Octet 0: 0x03 607 Octet 1: hash algorithm 608 Octets 2-9: 8-octet salt value 609 Octet 10: count, a one-octet, coded value 610 611 612 613 614 615 616 617 618Callas, et al Standards Track [Page 11] 619 620RFC 4880 OpenPGP Message Format November 2007 621 622 623 The count is coded into a one-octet number using the following 624 formula: 625 626 #define EXPBIAS 6 627 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 628 629 The above formula is in C, where "Int32" is a type for a 32-bit 630 integer, and the variable "c" is the coded count, Octet 10. 631 632 Iterated-Salted S2K hashes the passphrase and salt data multiple 633 times. The total number of octets to be hashed is specified in the 634 encoded count in the S2K specifier. Note that the resulting count 635 value is an octet count of how many octets will be hashed, not an 636 iteration count. 637 638 Initially, one or more hash contexts are set up as with the other S2K 639 algorithms, depending on how many octets of key data are needed. 640 Then the salt, followed by the passphrase data, is repeatedly hashed 641 until the number of octets specified by the octet count has been 642 hashed. The one exception is that if the octet count is less than 643 the size of the salt plus passphrase, the full salt plus passphrase 644 will be hashed even though that is greater than the octet count. 645 After the hashing is done, the data is unloaded from the hash 646 context(s) as with the other S2K algorithms. 647 6483.7.2. String-to-Key Usage 649 650 Implementations SHOULD use salted or iterated-and-salted S2K 651 specifiers, as simple S2K specifiers are more vulnerable to 652 dictionary attacks. 653 6543.7.2.1. Secret-Key Encryption 655 656 An S2K specifier can be stored in the secret keyring to specify how 657 to convert the passphrase to a key that unlocks the secret data. 658 Older versions of PGP just stored a cipher algorithm octet preceding 659 the secret data or a zero to indicate that the secret data was 660 unencrypted. The MD5 hash function was always used to convert the 661 passphrase to a key for the specified cipher algorithm. 662 663 For compatibility, when an S2K specifier is used, the special value 664 254 or 255 is stored in the position where the hash algorithm octet 665 would have been in the old data structure. This is then followed 666 immediately by a one-octet algorithm identifier, and then by the S2K 667 specifier as encoded above. 668 669 670 671 672 673 674Callas, et al Standards Track [Page 12] 675 676RFC 4880 OpenPGP Message Format November 2007 677 678 679 Therefore, preceding the secret data there will be one of these 680 possibilities: 681 682 0: secret data is unencrypted (no passphrase) 683 255 or 254: followed by algorithm octet and S2K specifier 684 Cipher alg: use Simple S2K algorithm using MD5 hash 685 686 This last possibility, the cipher algorithm number with an implicit 687 use of MD5 and IDEA, is provided for backward compatibility; it MAY 688 be understood, but SHOULD NOT be generated, and is deprecated. 689 690 These are followed by an Initial Vector of the same length as the 691 block size of the cipher for the decryption of the secret values, if 692 they are encrypted, and then the secret-key values themselves. 693 6943.7.2.2. Symmetric-Key Message Encryption 695 696 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) packet 697 at the front of a message. This is used to allow S2K specifiers to 698 be used for the passphrase conversion or to create messages with a 699 mix of symmetric-key ESKs and public-key ESKs. This allows a message 700 to be decrypted either with a passphrase or a public-key pair. 701 702 PGP 2.X always used IDEA with Simple string-to-key conversion when 703 encrypting a message with a symmetric algorithm. This is deprecated, 704 but MAY be used for backward-compatibility. 705 7064. Packet Syntax 707 708 This section describes the packets used by OpenPGP. 709 7104.1. Overview 711 712 An OpenPGP message is constructed from a number of records that are 713 traditionally called packets. A packet is a chunk of data that has a 714 tag specifying its meaning. An OpenPGP message, keyring, 715 certificate, and so forth consists of a number of packets. Some of 716 those packets may contain other OpenPGP packets (for example, a 717 compressed data packet, when uncompressed, contains OpenPGP packets). 718 719 Each packet consists of a packet header, followed by the packet body. 720 The packet header is of variable length. 721 7224.2. Packet Headers 723 724 The first octet of the packet header is called the "Packet Tag". It 725 determines the format of the header and denotes the packet contents. 726 The remainder of the packet header is the length of the packet. 727 728 729 730Callas, et al Standards Track [Page 13] 731 732RFC 4880 OpenPGP Message Format November 2007 733 734 735 Note that the most significant bit is the leftmost bit, called bit 7. 736 A mask for this bit is 0x80 in hexadecimal. 737 738 +---------------+ 739 PTag |7 6 5 4 3 2 1 0| 740 +---------------+ 741 Bit 7 -- Always one 742 Bit 6 -- New packet format if set 743 744 PGP 2.6.x only uses old format packets. Thus, software that 745 interoperates with those versions of PGP must only use old format 746 packets. If interoperability is not an issue, the new packet format 747 is RECOMMENDED. Note that old format packets have four bits of 748 packet tags, and new format packets have six; some features cannot be 749 used and still be backward-compatible. 750 751 Also note that packets with a tag greater than or equal to 16 MUST 752 use new format packets. The old format packets can only express tags 753 less than or equal to 15. 754 755 Old format packets contain: 756 757 Bits 5-2 -- packet tag 758 Bits 1-0 -- length-type 759 760 New format packets contain: 761 762 Bits 5-0 -- packet tag 763 7644.2.1. Old Format Packet Lengths 765 766 The meaning of the length-type in old format packets is: 767 768 0 - The packet has a one-octet length. The header is 2 octets long. 769 770 1 - The packet has a two-octet length. The header is 3 octets long. 771 772 2 - The packet has a four-octet length. The header is 5 octets long. 773 774 3 - The packet is of indeterminate length. The header is 1 octet 775 long, and the implementation must determine how long the packet 776 is. If the packet is in a file, this means that the packet 777 extends until the end of the file. In general, an implementation 778 SHOULD NOT use indeterminate-length packets except where the end 779 of the data will be clear from the context, and even then it is 780 better to use a definite length, or a new format header. The new 781 format headers described below have a mechanism for precisely 782 encoding data of indeterminate length. 783 784 785 786Callas, et al Standards Track [Page 14] 787 788RFC 4880 OpenPGP Message Format November 2007 789 790 7914.2.2. New Format Packet Lengths 792 793 New format packets have four possible ways of encoding length: 794 795 1. A one-octet Body Length header encodes packet lengths of up to 191 796 octets. 797 798 2. A two-octet Body Length header encodes packet lengths of 192 to 799 8383 octets. 800 801 3. A five-octet Body Length header encodes packet lengths of up to 802 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 803 encodes a four-octet scalar number.) 804 805 4. When the length of the packet body is not known in advance by the 806 issuer, Partial Body Length headers encode a packet of 807 indeterminate length, effectively making it a stream. 808 8094.2.2.1. One-Octet Lengths 810 811 A one-octet Body Length header encodes a length of 0 to 191 octets. 812 This type of length header is recognized because the one octet value 813 is less than 192. The body length is equal to: 814 815 bodyLen = 1st_octet; 816 8174.2.2.2. Two-Octet Lengths 818 819 A two-octet Body Length header encodes a length of 192 to 8383 820 octets. It is recognized because its first octet is in the range 192 821 to 223. The body length is equal to: 822 823 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 824 8254.2.2.3. Five-Octet Lengths 826 827 A five-octet Body Length header consists of a single octet holding 828 the value 255, followed by a four-octet scalar. The body length is 829 equal to: 830 831 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 832 (4th_octet << 8) | 5th_octet 833 834 This basic set of one, two, and five-octet lengths is also used 835 internally to some packets. 836 837 838 839 840 841 842Callas, et al Standards Track [Page 15] 843 844RFC 4880 OpenPGP Message Format November 2007 845 846 8474.2.2.4. Partial Body Lengths 848 849 A Partial Body Length header is one octet long and encodes the length 850 of only part of the data packet. This length is a power of 2, from 1 851 to 1,073,741,824 (2 to the 30th power). It is recognized by its one 852 octet value that is greater than or equal to 224, and less than 255. 853 The Partial Body Length is equal to: 854 855 partialBodyLen = 1 << (1st_octet & 0x1F); 856 857 Each Partial Body Length header is followed by a portion of the 858 packet body data. The Partial Body Length header specifies this 859 portion's length. Another length header (one octet, two-octet, 860 five-octet, or partial) follows that portion. The last length header 861 in the packet MUST NOT be a Partial Body Length header. Partial Body 862 Length headers may only be used for the non-final parts of the 863 packet. 864 865 Note also that the last Body Length header can be a zero-length 866 header. 867 868 An implementation MAY use Partial Body Lengths for data packets, be 869 they literal, compressed, or encrypted. The first partial length 870 MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 871 used for any other packet types. 872 8734.2.3. Packet Length Examples 874 875 These examples show ways that new format packets might encode the 876 packet lengths. 877 878 A packet with length 100 may have its length encoded in one octet: 879 0x64. This is followed by 100 octets of data. 880 881 A packet with length 1723 may have its length encoded in two octets: 882 0xC5, 0xFB. This header is followed by the 1723 octets of data. 883 884 A packet with length 100000 may have its length encoded in five 885 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 886 887 It might also be encoded in the following octet stream: 0xEF, first 888 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 889 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 1693 890 octets of data. This is just one possible encoding, and many 891 variations are possible on the size of the Partial Body Length 892 headers, as long as a regular Body Length header encodes the last 893 portion of the data. 894 895 896 897 898Callas, et al Standards Track [Page 16] 899 900RFC 4880 OpenPGP Message Format November 2007 901 902 903 Please note that in all of these explanations, the total length of 904 the packet is the length of the header(s) plus the length of the 905 body. 906 9074.3. Packet Tags 908 909 The packet tag denotes what type of packet the body holds. Note that 910 old format headers can only have tags less than 16, whereas new 911 format headers can have tags as great as 63. The defined tags (in 912 decimal) are as follows: 913 914 0 -- Reserved - a packet tag MUST NOT have this value 915 1 -- Public-Key Encrypted Session Key Packet 916 2 -- Signature Packet 917 3 -- Symmetric-Key Encrypted Session Key Packet 918 4 -- One-Pass Signature Packet 919 5 -- Secret-Key Packet 920 6 -- Public-Key Packet 921 7 -- Secret-Subkey Packet 922 8 -- Compressed Data Packet 923 9 -- Symmetrically Encrypted Data Packet 924 10 -- Marker Packet 925 11 -- Literal Data Packet 926 12 -- Trust Packet 927 13 -- User ID Packet 928 14 -- Public-Subkey Packet 929 17 -- User Attribute Packet 930 18 -- Sym. Encrypted and Integrity Protected Data Packet 931 19 -- Modification Detection Code Packet 932 60 to 63 -- Private or Experimental Values 933 9345. Packet Types 935 9365.1. Public-Key Encrypted Session Key Packets (Tag 1) 937 938 A Public-Key Encrypted Session Key packet holds the session key used 939 to encrypt a message. Zero or more Public-Key Encrypted Session Key 940 packets and/or Symmetric-Key Encrypted Session Key packets may 941 precede a Symmetrically Encrypted Data Packet, which holds an 942 encrypted message. The message is encrypted with the session key, 943 and the session key is itself encrypted and stored in the Encrypted 944 Session Key packet(s). The Symmetrically Encrypted Data Packet is 945 preceded by one Public-Key Encrypted Session Key packet for each 946 OpenPGP key to which the message is encrypted. The recipient of the 947 message finds a session key that is encrypted to their public key, 948 decrypts the session key, and then uses the session key to decrypt 949 the message. 950 951 952 953 954Callas, et al Standards Track [Page 17] 955 956RFC 4880 OpenPGP Message Format November 2007 957 958 959 The body of this packet consists of: 960 961 - A one-octet number giving the version number of the packet type. 962 The currently defined value for packet version is 3. 963 964 - An eight-octet number that gives the Key ID of the public key to 965 which the session key is encrypted. If the session key is 966 encrypted to a subkey, then the Key ID of this subkey is used 967 here instead of the Key ID of the primary key. 968 969 - A one-octet number giving the public-key algorithm used. 970 971 - A string of octets that is the encrypted session key. This 972 string takes up the remainder of the packet, and its contents are 973 dependent on the public-key algorithm used. 974 975 Algorithm Specific Fields for RSA encryption 976 977 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 978 979 Algorithm Specific Fields for Elgamal encryption: 980 981 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 982 983 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 984 985 The value "m" in the above formulas is derived from the session key 986 as follows. First, the session key is prefixed with a one-octet 987 algorithm identifier that specifies the symmetric encryption 988 algorithm used to encrypt the following Symmetrically Encrypted Data 989 Packet. Then a two-octet checksum is appended, which is equal to the 990 sum of the preceding session key octets, not including the algorithm 991 identifier, modulo 65536. This value is then encoded as described in 992 PKCS#1 block encoding EME-PKCS1-v1_5 in Section 7.2.1 of [RFC3447] to 993 form the "m" value used in the formulas above. See Section 13.1 of 994 this document for notes on OpenPGP's use of PKCS#1. 995 996 Note that when an implementation forms several PKESKs with one 997 session key, forming a message that can be decrypted by several keys, 998 the implementation MUST make a new PKCS#1 encoding for each key. 999 1000 An implementation MAY accept or use a Key ID of zero as a "wild card" 1001 or "speculative" Key ID. In this case, the receiving implementation 1002 would try all available private keys, checking for a valid decrypted 1003 session key. This format helps reduce traffic analysis of messages. 1004 1005 1006 1007 1008 1009 1010Callas, et al Standards Track [Page 18] 1011 1012RFC 4880 OpenPGP Message Format November 2007 1013 1014 10155.2. Signature Packet (Tag 2) 1016 1017 A Signature packet describes a binding between some public key and 1018 some data. The most common signatures are a signature of a file or a 1019 block of text, and a signature that is a certification of a User ID. 1020 1021 Two versions of Signature packets are defined. Version 3 provides 1022 basic signature information, while version 4 provides an expandable 1023 format with subpackets that can specify more information about the 1024 signature. PGP 2.6.x only accepts version 3 signatures. 1025 1026 Implementations SHOULD accept V3 signatures. Implementations SHOULD 1027 generate V4 signatures. 1028 1029 Note that if an implementation is creating an encrypted and signed 1030 message that is encrypted to a V3 key, it is reasonable to create a 1031 V3 signature. 1032 10335.2.1. Signature Types 1034 1035 There are a number of possible meanings for a signature, which are 1036 indicated in a signature type octet in any given signature. Please 1037 note that the vagueness of these meanings is not a flaw, but a 1038 feature of the system. Because OpenPGP places final authority for 1039 validity upon the receiver of a signature, it may be that one 1040 signer's casual act might be more rigorous than some other 1041 authority's positive act. See Section 5.2.4, "Computing Signatures", 1042 for detailed information on how to compute and verify signatures of 1043 each type. 1044 1045 These meanings are as follows: 1046 1047 0x00: Signature of a binary document. 1048 This means the signer owns it, created it, or certifies that it 1049 has not been modified. 1050 1051 0x01: Signature of a canonical text document. 1052 This means the signer owns it, created it, or certifies that it 1053 has not been modified. The signature is calculated over the text 1054 data with its line endings converted to <CR><LF>. 1055 1056 0x02: Standalone signature. 1057 This signature is a signature of only its own subpacket contents. 1058 It is calculated identically to a signature over a zero-length 1059 binary document. Note that it doesn't make sense to have a V3 1060 standalone signature. 1061 1062 1063 1064 1065 1066Callas, et al Standards Track [Page 19] 1067 1068RFC 4880 OpenPGP Message Format November 2007 1069 1070 1071 0x10: Generic certification of a User ID and Public-Key packet. 1072 The issuer of this certification does not make any particular 1073 assertion as to how well the certifier has checked that the owner 1074 of the key is in fact the person described by the User ID. 1075 1076 0x11: Persona certification of a User ID and Public-Key packet. 1077 The issuer of this certification has not done any verification of 1078 the claim that the owner of this key is the User ID specified. 1079 1080 0x12: Casual certification of a User ID and Public-Key packet. 1081 The issuer of this certification has done some casual 1082 verification of the claim of identity. 1083 1084 0x13: Positive certification of a User ID and Public-Key packet. 1085 The issuer of this certification has done substantial 1086 verification of the claim of identity. 1087 1088 Most OpenPGP implementations make their "key signatures" as 0x10 1089 certifications. Some implementations can issue 0x11-0x13 1090 certifications, but few differentiate between the types. 1091 1092 0x18: Subkey Binding Signature 1093 This signature is a statement by the top-level signing key that 1094 indicates that it owns the subkey. This signature is calculated 1095 directly on the primary key and subkey, and not on any User ID or 1096 other packets. A signature that binds a signing subkey MUST have 1097 an Embedded Signature subpacket in this binding signature that 1098 contains a 0x19 signature made by the signing subkey on the 1099 primary key and subkey. 1100 1101 0x19: Primary Key Binding Signature 1102 This signature is a statement by a signing subkey, indicating 1103 that it is owned by the primary key and subkey. This signature 1104 is calculated the same way as a 0x18 signature: directly on the 1105 primary key and subkey, and not on any User ID or other packets. 1106 1107 0x1F: Signature directly on a key 1108 This signature is calculated directly on a key. It binds the 1109 information in the Signature subpackets to the key, and is 1110 appropriate to be used for subpackets that provide information 1111 about the key, such as the Revocation Key subpacket. It is also 1112 appropriate for statements that non-self certifiers want to make 1113 about the key itself, rather than the binding between a key and a 1114 name. 1115 1116 1117 1118 1119 1120 1121 1122Callas, et al Standards Track [Page 20] 1123 1124RFC 4880 OpenPGP Message Format November 2007 1125 1126 1127 0x20: Key revocation signature 1128 The signature is calculated directly on the key being revoked. A 1129 revoked key is not to be used. Only revocation signatures by the 1130 key being revoked, or by an authorized revocation key, should be 1131 considered valid revocation signatures. 1132 1133 0x28: Subkey revocation signature 1134 The signature is calculated directly on the subkey being revoked. 1135 A revoked subkey is not to be used. Only revocation signatures 1136 by the top-level signature key that is bound to this subkey, or 1137 by an authorized revocation key, should be considered valid 1138 revocation signatures. 1139 1140 0x30: Certification revocation signature 1141 This signature revokes an earlier User ID certification signature 1142 (signature class 0x10 through 0x13) or direct-key signature 1143 (0x1F). It should be issued by the same key that issued the 1144 revoked signature or an authorized revocation key. The signature 1145 is computed over the same data as the certificate that it 1146 revokes, and should have a later creation date than that 1147 certificate. 1148 1149 0x40: Timestamp signature. 1150 This signature is only meaningful for the timestamp contained in 1151 it. 1152 1153 0x50: Third-Party Confirmation signature. 1154 This signature is a signature over some other OpenPGP Signature 1155 packet(s). It is analogous to a notary seal on the signed data. 1156 A third-party signature SHOULD include Signature Target 1157 subpacket(s) to give easy identification. Note that we really do 1158 mean SHOULD. There are plausible uses for this (such as a blind 1159 party that only sees the signature, not the key or source 1160 document) that cannot include a target subpacket. 1161 11625.2.2. Version 3 Signature Packet Format 1163 1164 The body of a version 3 Signature Packet contains: 1165 1166 - One-octet version number (3). 1167 1168 - One-octet length of following hashed material. MUST be 5. 1169 1170 - One-octet signature type. 1171 1172 - Four-octet creation time. 1173 1174 - Eight-octet Key ID of signer. 1175 1176 1177 1178Callas, et al Standards Track [Page 21] 1179 1180RFC 4880 OpenPGP Message Format November 2007 1181 1182 1183 - One-octet public-key algorithm. 1184 1185 - One-octet hash algorithm. 1186 1187 - Two-octet field holding left 16 bits of signed hash value. 1188 1189 - One or more multiprecision integers comprising the signature. 1190 This portion is algorithm specific, as described below. 1191 1192 The concatenation of the data to be signed, the signature type, and 1193 creation time from the Signature packet (5 additional octets) is 1194 hashed. The resulting hash value is used in the signature algorithm. 1195 The high 16 bits (first two octets) of the hash are included in the 1196 Signature packet to provide a quick test to reject some invalid 1197 signatures. 1198 1199 Algorithm-Specific Fields for RSA signatures: 1200 1201 - multiprecision integer (MPI) of RSA signature value m**d mod n. 1202 1203 Algorithm-Specific Fields for DSA signatures: 1204 1205 - MPI of DSA value r. 1206 1207 - MPI of DSA value s. 1208 1209 The signature calculation is based on a hash of the signed data, as 1210 described above. The details of the calculation are different for 1211 DSA signatures than for RSA signatures. 1212 1213 With RSA signatures, the hash value is encoded using PKCS#1 encoding 1214 type EMSA-PKCS1-v1_5 as described in Section 9.2 of RFC 3447. This 1215 requires inserting the hash value as an octet string into an ASN.1 1216 structure. The object identifier for the type of hash being used is 1217 included in the structure. The hexadecimal representations for the 1218 currently defined hash algorithms are as follows: 1219 1220 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 1221 1222 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 1223 1224 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 1225 1226 - SHA224: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 1227 1228 - SHA256: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 1229 1230 - SHA384: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 1231 1232 1233 1234Callas, et al Standards Track [Page 22] 1235 1236RFC 4880 OpenPGP Message Format November 2007 1237 1238 1239 - SHA512: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 1240 1241 The ASN.1 Object Identifiers (OIDs) are as follows: 1242 1243 - MD5: 1.2.840.113549.2.5 1244 1245 - RIPEMD-160: 1.3.36.3.2.1 1246 1247 - SHA-1: 1.3.14.3.2.26 1248 1249 - SHA224: 2.16.840.1.101.3.4.2.4 1250 1251 - SHA256: 2.16.840.1.101.3.4.2.1 1252 1253 - SHA384: 2.16.840.1.101.3.4.2.2 1254 1255 - SHA512: 2.16.840.1.101.3.4.2.3 1256 1257 The full hash prefixes for these are as follows: 1258 1259 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 1260 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 1261 0x04, 0x10 1262 1263 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 1264 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 1265 1266 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 1267 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 1268 1269 SHA224: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1270 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 1271 0x00, 0x04, 0x1C 1272 1273 SHA256: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1274 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 1275 0x00, 0x04, 0x20 1276 1277 SHA384: 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1278 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 1279 0x00, 0x04, 0x30 1280 1281 SHA512: 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1282 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 1283 0x00, 0x04, 0x40 1284 1285 DSA signatures MUST use hashes that are equal in size to the number 1286 of bits of q, the group generated by the DSA key's generator value. 1287 1288 1289 1290Callas, et al Standards Track [Page 23] 1291 1292RFC 4880 OpenPGP Message Format November 2007 1293 1294 1295 If the output size of the chosen hash is larger than the number of 1296 bits of q, the hash result is truncated to fit by taking the number 1297 of leftmost bits equal to the number of bits of q. This (possibly 1298 truncated) hash function result is treated as a number and used 1299 directly in the DSA signature algorithm. 1300 13015.2.3. Version 4 Signature Packet Format 1302 1303 The body of a version 4 Signature packet contains: 1304 1305 - One-octet version number (4). 1306 1307 - One-octet signature type. 1308 1309 - One-octet public-key algorithm. 1310 1311 - One-octet hash algorithm. 1312 1313 - Two-octet scalar octet count for following hashed subpacket data. 1314 Note that this is the length in octets of all of the hashed 1315 subpackets; a pointer incremented by this number will skip over 1316 the hashed subpackets. 1317 1318 - Hashed subpacket data set (zero or more subpackets). 1319 1320 - Two-octet scalar octet count for the following unhashed subpacket 1321 data. Note that this is the length in octets of all of the 1322 unhashed subpackets; a pointer incremented by this number will 1323 skip over the unhashed subpackets. 1324 1325 - Unhashed subpacket data set (zero or more subpackets). 1326 1327 - Two-octet field holding the left 16 bits of the signed hash 1328 value. 1329 1330 - One or more multiprecision integers comprising the signature. 1331 This portion is algorithm specific, as described above. 1332 1333 The concatenation of the data being signed and the signature data 1334 from the version number through the hashed subpacket data (inclusive) 1335 is hashed. The resulting hash value is what is signed. The left 16 1336 bits of the hash are included in the Signature packet to provide a 1337 quick test to reject some invalid signatures. 1338 1339 There are two fields consisting of Signature subpackets. The first 1340 field is hashed with the rest of the signature data, while the second 1341 is unhashed. The second set of subpackets is not cryptographically 1342 1343 1344 1345 1346Callas, et al Standards Track [Page 24] 1347 1348RFC 4880 OpenPGP Message Format November 2007 1349 1350 1351 protected by the signature and should include only advisory 1352 information. 1353 1354 The algorithms for converting the hash function result to a signature 1355 are described in a section below. 1356 13575.2.3.1. Signature Subpacket Specification 1358 1359 A subpacket data set consists of zero or more Signature subpackets. 1360 In Signature packets, the subpacket data set is preceded by a two- 1361 octet scalar count of the length in octets of all the subpackets. A 1362 pointer incremented by this number will skip over the subpacket data 1363 set. 1364 1365 Each subpacket consists of a subpacket header and a body. The header 1366 consists of: 1367 1368 - the subpacket length (1, 2, or 5 octets), 1369 1370 - the subpacket type (1 octet), 1371 1372 and is followed by the subpacket-specific data. 1373 1374 The length includes the type octet but not this length. Its format 1375 is similar to the "new" format packet header lengths, but cannot have 1376 Partial Body Lengths. That is: 1377 1378 if the 1st octet < 192, then 1379 lengthOfLength = 1 1380 subpacketLen = 1st_octet 1381 1382 if the 1st octet >= 192 and < 255, then 1383 lengthOfLength = 2 1384 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1385 1386 if the 1st octet = 255, then 1387 lengthOfLength = 5 1388 subpacket length = [four-octet scalar starting at 2nd_octet] 1389 1390 The value of the subpacket type octet may be: 1391 1392 0 = Reserved 1393 1 = Reserved 1394 2 = Signature Creation Time 1395 3 = Signature Expiration Time 1396 4 = Exportable Certification 1397 5 = Trust Signature 1398 6 = Regular Expression 1399 1400 1401 1402Callas, et al Standards Track [Page 25] 1403 1404RFC 4880 OpenPGP Message Format November 2007 1405 1406 1407 7 = Revocable 1408 8 = Reserved 1409 9 = Key Expiration Time 1410 10 = Placeholder for backward compatibility 1411 11 = Preferred Symmetric Algorithms 1412 12 = Revocation Key 1413 13 = Reserved 1414 14 = Reserved 1415 15 = Reserved 1416 16 = Issuer 1417 17 = Reserved 1418 18 = Reserved 1419 19 = Reserved 1420 20 = Notation Data 1421 21 = Preferred Hash Algorithms 1422 22 = Preferred Compression Algorithms 1423 23 = Key Server Preferences 1424 24 = Preferred Key Server 1425 25 = Primary User ID 1426 26 = Policy URI 1427 27 = Key Flags 1428 28 = Signer's User ID 1429 29 = Reason for Revocation 1430 30 = Features 1431 31 = Signature Target 1432 32 = Embedded Signature 1433 100 To 110 = Private or experimental 1434 1435 An implementation SHOULD ignore any subpacket of a type that it does 1436 not recognize. 1437 1438 Bit 7 of the subpacket type is the "critical" bit. If set, it 1439 denotes that the subpacket is one that is critical for the evaluator 1440 of the signature to recognize. If a subpacket is encountered that is 1441 marked critical but is unknown to the evaluating software, the 1442 evaluator SHOULD consider the signature to be in error. 1443 1444 An evaluator may "recognize" a subpacket, but not implement it. The 1445 purpose of the critical bit is to allow the signer to tell an 1446 evaluator that it would prefer a new, unknown feature to generate an 1447 error than be ignored. 1448 1449 Implementations SHOULD implement the three preferred algorithm 1450 subpackets (11, 21, and 22), as well as the "Reason for Revocation" 1451 subpacket. Note, however, that if an implementation chooses not to 1452 implement some of the preferences, it is required to behave in a 1453 polite manner to respect the wishes of those users who do implement 1454 these preferences. 1455 1456 1457 1458Callas, et al Standards Track [Page 26] 1459 1460RFC 4880 OpenPGP Message Format November 2007 1461 1462 14635.2.3.2. Signature Subpacket Types 1464 1465 A number of subpackets are currently defined. Some subpackets apply 1466 to the signature itself and some are attributes of the key. 1467 Subpackets that are found on a self-signature are placed on a 1468 certification made by the key itself. Note that a key may have more 1469 than one User ID, and thus may have more than one self-signature, and 1470 differing subpackets. 1471 1472 A subpacket may be found either in the hashed or unhashed subpacket 1473 sections of a signature. If a subpacket is not hashed, then the 1474 information in it cannot be considered definitive because it is not 1475 part of the signature proper. 1476 14775.2.3.3. Notes on Self-Signatures 1478 1479 A self-signature is a binding signature made by the key to which the 1480 signature refers. There are three types of self-signatures, the 1481 certification signatures (types 0x10-0x13), the direct-key signature 1482 (type 0x1F), and the subkey binding signature (type 0x18). For 1483 certification self-signatures, each User ID may have a self- 1484 signature, and thus different subpackets in those self-signatures. 1485 For subkey binding signatures, each subkey in fact has a self- 1486 signature. Subpackets that appear in a certification self-signature 1487 apply to the user name, and subpackets that appear in the subkey 1488 self-signature apply to the subkey. Lastly, subpackets on the 1489 direct-key signature apply to the entire key. 1490 1491 Implementing software should interpret a self-signature's preference 1492 subpackets as narrowly as possible. For example, suppose a key has 1493 two user names, Alice and Bob. Suppose that Alice prefers the 1494 symmetric algorithm CAST5, and Bob prefers IDEA or TripleDES. If the 1495 software locates this key via Alice's name, then the preferred 1496 algorithm is CAST5; if software locates the key via Bob's name, then 1497 the preferred algorithm is IDEA. If the key is located by Key ID, 1498 the algorithm of the primary User ID of the key provides the 1499 preferred symmetric algorithm. 1500 1501 Revoking a self-signature or allowing it to expire has a semantic 1502 meaning that varies with the signature type. Revoking the self- 1503 signature on a User ID effectively retires that user name. The 1504 self-signature is a statement, "My name X is tied to my signing key 1505 K" and is corroborated by other users' certifications. If another 1506 user revokes their certification, they are effectively saying that 1507 they no longer believe that name and that key are tied together. 1508 Similarly, if the users themselves revoke their self-signature, then 1509 the users no longer go by that name, no longer have that email 1510 address, etc. Revoking a binding signature effectively retires that 1511 1512 1513 1514Callas, et al Standards Track [Page 27] 1515 1516RFC 4880 OpenPGP Message Format November 2007 1517 1518 1519 subkey. Revoking a direct-key signature cancels that signature. 1520 Please see the "Reason for Revocation" subpacket (Section 5.2.3.23) 1521 for more relevant detail. 1522 1523 Since a self-signature contains important information about the key's 1524 use, an implementation SHOULD allow the user to rewrite the self- 1525 signature, and important information in it, such as preferences and 1526 key expiration. 1527 1528 It is good practice to verify that a self-signature imported into an 1529 implementation doesn't advertise features that the implementation 1530 doesn't support, rewriting the signature as appropriate. 1531 1532 An implementation that encounters multiple self-signatures on the 1533 same object may resolve the ambiguity in any way it sees fit, but it 1534 is RECOMMENDED that priority be given to the most recent self- 1535 signature. 1536 15375.2.3.4. Signature Creation Time 1538 1539 (4-octet time field) 1540 1541 The time the signature was made. 1542 1543 MUST be present in the hashed area. 1544 15455.2.3.5. Issuer 1546 1547 (8-octet Key ID) 1548 1549 The OpenPGP Key ID of the key issuing the signature. 1550 15515.2.3.6. Key Expiration Time 1552 1553 (4-octet time field) 1554 1555 The validity period of the key. This is the number of seconds after 1556 the key creation time that the key expires. If this is not present 1557 or has a value of zero, the key never expires. This is found only on 1558 a self-signature. 1559 15605.2.3.7. Preferred Symmetric Algorithms 1561 1562 (array of one-octet values) 1563 1564 Symmetric algorithm numbers that indicate which algorithms the key 1565 holder prefers to use. The subpacket body is an ordered list of 1566 octets with the most preferred listed first. It is assumed that only 1567 1568 1569 1570Callas, et al Standards Track [Page 28] 1571 1572RFC 4880 OpenPGP Message Format November 2007 1573 1574 1575 algorithms listed are supported by the recipient's software. 1576 Algorithm numbers are in Section 9. This is only found on a self- 1577 signature. 1578 15795.2.3.8. Preferred Hash Algorithms 1580 1581 (array of one-octet values) 1582 1583 Message digest algorithm numbers that indicate which algorithms the 1584 key holder prefers to receive. Like the preferred symmetric 1585 algorithms, the list is ordered. Algorithm numbers are in Section 9. 1586 This is only found on a self-signature. 1587 15885.2.3.9. Preferred Compression Algorithms 1589 1590 (array of one-octet values) 1591 1592 Compression algorithm numbers that indicate which algorithms the key 1593 holder prefers to use. Like the preferred symmetric algorithms, the 1594 list is ordered. Algorithm numbers are in Section 9. If this 1595 subpacket is not included, ZIP is preferred. A zero denotes that 1596 uncompressed data is preferred; the key holder's software might have 1597 no compression software in that implementation. This is only found 1598 on a self-signature. 1599 16005.2.3.10. Signature Expiration Time 1601 1602 (4-octet time field) 1603 1604 The validity period of the signature. This is the number of seconds 1605 after the signature creation time that the signature expires. If 1606 this is not present or has a value of zero, it never expires. 1607 16085.2.3.11. Exportable Certification 1609 1610 (1 octet of exportability, 0 for not, 1 for exportable) 1611 1612 This subpacket denotes whether a certification signature is 1613 "exportable", to be used by other users than the signature's issuer. 1614 The packet body contains a Boolean flag indicating whether the 1615 signature is exportable. If this packet is not present, the 1616 certification is exportable; it is equivalent to a flag containing a 1617 1. 1618 1619 Non-exportable, or "local", certifications are signatures made by a 1620 user to mark a key as valid within that user's implementation only. 1621 1622 1623 1624 1625 1626Callas, et al Standards Track [Page 29] 1627 1628RFC 4880 OpenPGP Message Format November 2007 1629 1630 1631 Thus, when an implementation prepares a user's copy of a key for 1632 transport to another user (this is the process of "exporting" the 1633 key), any local certification signatures are deleted from the key. 1634 1635 The receiver of a transported key "imports" it, and likewise trims 1636 any local certifications. In normal operation, there won't be any, 1637 assuming the import is performed on an exported key. However, there 1638 are instances where this can reasonably happen. For example, if an 1639 implementation allows keys to be imported from a key database in 1640 addition to an exported key, then this situation can arise. 1641 1642 Some implementations do not represent the interest of a single user 1643 (for example, a key server). Such implementations always trim local 1644 certifications from any key they handle. 1645 16465.2.3.12. Revocable 1647 1648 (1 octet of revocability, 0 for not, 1 for revocable) 1649 1650 Signature's revocability status. The packet body contains a Boolean 1651 flag indicating whether the signature is revocable. Signatures that 1652 are not revocable have any later revocation signatures ignored. They 1653 represent a commitment by the signer that he cannot revoke his 1654 signature for the life of his key. If this packet is not present, 1655 the signature is revocable. 1656 16575.2.3.13. Trust Signature 1658 1659 (1 octet "level" (depth), 1 octet of trust amount) 1660 1661 Signer asserts that the key is not only valid but also trustworthy at 1662 the specified level. Level 0 has the same meaning as an ordinary 1663 validity signature. Level 1 means that the signed key is asserted to 1664 be a valid trusted introducer, with the 2nd octet of the body 1665 specifying the degree of trust. Level 2 means that the signed key is 1666 asserted to be trusted to issue level 1 trust signatures, i.e., that 1667 it is a "meta introducer". Generally, a level n trust signature 1668 asserts that a key is trusted to issue level n-1 trust signatures. 1669 The trust amount is in a range from 0-255, interpreted such that 1670 values less than 120 indicate partial trust and values of 120 or 1671 greater indicate complete trust. Implementations SHOULD emit values 1672 of 60 for partial trust and 120 for complete trust. 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682Callas, et al Standards Track [Page 30] 1683 1684RFC 4880 OpenPGP Message Format November 2007 1685 1686 16875.2.3.14. Regular Expression 1688 1689 (null-terminated regular expression) 1690 1691 Used in conjunction with trust Signature packets (of level > 0) to 1692 limit the scope of trust that is extended. Only signatures by the 1693 target key on User IDs that match the regular expression in the body 1694 of this packet have trust extended by the trust Signature subpacket. 1695 The regular expression uses the same syntax as the Henry Spencer's 1696 "almost public domain" regular expression [REGEX] package. A 1697 description of the syntax is found in Section 8 below. 1698 16995.2.3.15. Revocation Key 1700 1701 (1 octet of class, 1 octet of public-key algorithm ID, 20 octets of 1702 fingerprint) 1703 1704 Authorizes the specified key to issue revocation signatures for this 1705 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1706 then this means that the revocation information is sensitive. Other 1707 bits are for future expansion to other kinds of authorizations. This 1708 is found on a self-signature. 1709 1710 If the "sensitive" flag is set, the keyholder feels this subpacket 1711 contains private trust information that describes a real-world 1712 sensitive relationship. If this flag is set, implementations SHOULD 1713 NOT export this signature to other users except in cases where the 1714 data needs to be available: when the signature is being sent to the 1715 designated revoker, or when it is accompanied by a revocation 1716 signature from that revoker. Note that it may be appropriate to 1717 isolate this subpacket within a separate signature so that it is not 1718 combined with other subpackets that need to be exported. 1719 17205.2.3.16. Notation Data 1721 1722 (4 octets of flags, 2 octets of name length (M), 1723 2 octets of value length (N), 1724 M octets of name data, 1725 N octets of value data) 1726 1727 This subpacket describes a "notation" on the signature that the 1728 issuer wishes to make. The notation has a name and a value, each of 1729 which are strings of octets. There may be more than one notation in 1730 a signature. Notations can be used for any extension the issuer of 1731 the signature cares to make. The "flags" field holds four octets of 1732 flags. 1733 1734 1735 1736 1737 1738Callas, et al Standards Track [Page 31] 1739 1740RFC 4880 OpenPGP Message Format November 2007 1741 1742 1743 All undefined flags MUST be zero. Defined flags are as follows: 1744 1745 First octet: 0x80 = human-readable. This note value is text. 1746 Other octets: none. 1747 1748 Notation names are arbitrary strings encoded in UTF-8. They reside 1749 in two namespaces: The IETF namespace and the user namespace. 1750 1751 The IETF namespace is registered with IANA. These names MUST NOT 1752 contain the "@" character (0x40). This is a tag for the user 1753 namespace. 1754 1755 Names in the user namespace consist of a UTF-8 string tag followed by 1756 "@" followed by a DNS domain name. Note that the tag MUST NOT 1757 contain an "@" character. For example, the "sample" tag used by 1758 Example Corporation could be "sample@example.com". 1759 1760 Names in a user space are owned and controlled by the owners of that 1761 domain. Obviously, it's bad form to create a new name in a DNS space 1762 that you don't own. 1763 1764 Since the user namespace is in the form of an email address, 1765 implementers MAY wish to arrange for that address to reach a person 1766 who can be consulted about the use of the named tag. Note that due 1767 to UTF-8 encoding, not all valid user space name tags are valid email 1768 addresses. 1769 1770 If there is a critical notation, the criticality applies to that 1771 specific notation and not to notations in general. 1772 17735.2.3.17. Key Server Preferences 1774 1775 (N octets of flags) 1776 1777 This is a list of one-bit flags that indicate preferences that the 1778 key holder has about how the key is handled on a key server. All 1779 undefined flags MUST be zero. 1780 1781 First octet: 0x80 = No-modify 1782 the key holder requests that this key only be modified or updated 1783 by the key holder or an administrator of the key server. 1784 1785 This is found only on a self-signature. 1786 1787 1788 1789 1790 1791 1792 1793 1794Callas, et al Standards Track [Page 32] 1795 1796RFC 4880 OpenPGP Message Format November 2007 1797 1798 17995.2.3.18. Preferred Key Server 1800 1801 (String) 1802 1803 This is a URI of a key server that the key holder prefers be used for 1804 updates. Note that keys with multiple User IDs can have a preferred 1805 key server for each User ID. Note also that since this is a URI, the 1806 key server can actually be a copy of the key retrieved by ftp, http, 1807 finger, etc. 1808 18095.2.3.19. Primary User ID 1810 1811 (1 octet, Boolean) 1812 1813 This is a flag in a User ID's self-signature that states whether this 1814 User ID is the main User ID for this key. It is reasonable for an 1815 implementation to resolve ambiguities in preferences, etc. by 1816 referring to the primary User ID. If this flag is absent, its value 1817 is zero. If more than one User ID in a key is marked as primary, the 1818 implementation may resolve the ambiguity in any way it sees fit, but 1819 it is RECOMMENDED that priority be given to the User ID with the most 1820 recent self-signature. 1821 1822 When appearing on a self-signature on a User ID packet, this 1823 subpacket applies only to User ID packets. When appearing on a 1824 self-signature on a User Attribute packet, this subpacket applies 1825 only to User Attribute packets. That is to say, there are two 1826 different and independent "primaries" -- one for User IDs, and one 1827 for User Attributes. 1828 18295.2.3.20. Policy URI 1830 1831 (String) 1832 1833 This subpacket contains a URI of a document that describes the policy 1834 under which the signature was issued. 1835 18365.2.3.21. Key Flags 1837 1838 (N octets of flags) 1839 1840 This subpacket contains a list of binary flags that hold information 1841 about a key. It is a string of octets, and an implementation MUST 1842 NOT assume a fixed size. This is so it can grow over time. If a 1843 list is shorter than an implementation expects, the unstated flags 1844 are considered to be zero. The defined flags are as follows: 1845 1846 1847 1848 1849 1850Callas, et al Standards Track [Page 33] 1851 1852RFC 4880 OpenPGP Message Format November 2007 1853 1854 1855 First octet: 1856 1857 0x01 - This key may be used to certify other keys. 1858 1859 0x02 - This key may be used to sign data. 1860 1861 0x04 - This key may be used to encrypt communications. 1862 1863 0x08 - This key may be used to encrypt storage. 1864 1865 0x10 - The private component of this key may have been split 1866 by a secret-sharing mechanism. 1867 1868 0x20 - This key may be used for authentication. 1869 1870 0x80 - The private component of this key may be in the 1871 possession of more than one person. 1872 1873 Usage notes: 1874 1875 The flags in this packet may appear in self-signatures or in 1876 certification signatures. They mean different things depending on 1877 who is making the statement -- for example, a certification signature 1878 that has the "sign data" flag is stating that the certification is 1879 for that use. On the other hand, the "communications encryption" 1880 flag in a self-signature is stating a preference that a given key be 1881 used for communications. Note however, that it is a thorny issue to 1882 determine what is "communications" and what is "storage". This 1883 decision is left wholly up to the implementation; the authors of this 1884 document do not claim any special wisdom on the issue and realize 1885 that accepted opinion may change. 1886 1887 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1888 self-signature only; they are meaningless on a certification 1889 signature. They SHOULD be placed only on a direct-key signature 1890 (type 0x1F) or a subkey signature (type 0x18), one that refers to the 1891 key the flag applies to. 1892 18935.2.3.22. Signer's User ID 1894 1895 (String) 1896 1897 This subpacket allows a keyholder to state which User ID is 1898 responsible for the signing. Many keyholders use a single key for 1899 different purposes, such as business communications as well as 1900 personal communications. This subpacket allows such a keyholder to 1901 state which of their roles is making a signature. 1902 1903 1904 1905 1906Callas, et al Standards Track [Page 34] 1907 1908RFC 4880 OpenPGP Message Format November 2007 1909 1910 1911 This subpacket is not appropriate to use to refer to a User Attribute 1912 packet. 1913 19145.2.3.23. Reason for Revocation 1915 1916 (1 octet of revocation code, N octets of reason string) 1917 1918 This subpacket is used only in key revocation and certification 1919 revocation signatures. It describes the reason why the key or 1920 certificate was revoked. 1921 1922 The first octet contains a machine-readable code that denotes the 1923 reason for the revocation: 1924 1925 0 - No reason specified (key revocations or cert revocations) 1926 1 - Key is superseded (key revocations) 1927 2 - Key material has been compromised (key revocations) 1928 3 - Key is retired and no longer used (key revocations) 1929 32 - User ID information is no longer valid (cert revocations) 1930 100-110 - Private Use 1931 1932 Following the revocation code is a string of octets that gives 1933 information about the Reason for Revocation in human-readable form 1934 (UTF-8). The string may be null, that is, of zero length. The 1935 length of the subpacket is the length of the reason string plus one. 1936 An implementation SHOULD implement this subpacket, include it in all 1937 revocation signatures, and interpret revocations appropriately. 1938 There are important semantic differences between the reasons, and 1939 there are thus important reasons for revoking signatures. 1940 1941 If a key has been revoked because of a compromise, all signatures 1942 created by that key are suspect. However, if it was merely 1943 superseded or retired, old signatures are still valid. If the 1944 revoked signature is the self-signature for certifying a User ID, a 1945 revocation denotes that that user name is no longer in use. Such a 1946 revocation SHOULD include a 0x20 code. 1947 1948 Note that any signature may be revoked, including a certification on 1949 some other person's key. There are many good reasons for revoking a 1950 certification signature, such as the case where the keyholder leaves 1951 the employ of a business with an email address. A revoked 1952 certification is no longer a part of validity calculations. 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962Callas, et al Standards Track [Page 35] 1963 1964RFC 4880 OpenPGP Message Format November 2007 1965 1966 19675.2.3.24. Features 1968 1969 (N octets of flags) 1970 1971 The Features subpacket denotes which advanced OpenPGP features a 1972 user's implementation supports. This is so that as features are 1973 added to OpenPGP that cannot be backwards-compatible, a user can 1974 state that they can use that feature. The flags are single bits that 1975 indicate that a given feature is supported. 1976 1977 This subpacket is similar to a preferences subpacket, and only 1978 appears in a self-signature. 1979 1980 An implementation SHOULD NOT use a feature listed when sending to a 1981 user who does not state that they can use it. 1982 1983 Defined features are as follows: 1984 1985 First octet: 1986 1987 0x01 - Modification Detection (packets 18 and 19) 1988 1989 If an implementation implements any of the defined features, it 1990 SHOULD implement the Features subpacket, too. 1991 1992 An implementation may freely infer features from other suitable 1993 implementation-dependent mechanisms. 1994 19955.2.3.25. Signature Target 1996 1997 (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash) 1998 1999 This subpacket identifies a specific target signature to which a 2000 signature refers. For revocation signatures, this subpacket 2001 provides explicit designation of which signature is being revoked. 2002 For a third-party or timestamp signature, this designates what 2003 signature is signed. All arguments are an identifier of that target 2004 signature. 2005 2006 The N octets of hash data MUST be the size of the hash of the 2007 signature. For example, a target signature with a SHA-1 hash MUST 2008 have 20 octets of hash data. 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018Callas, et al Standards Track [Page 36] 2019 2020RFC 4880 OpenPGP Message Format November 2007 2021 2022 20235.2.3.26. Embedded Signature 2024 2025 (1 signature packet body) 2026 2027 This subpacket contains a complete Signature packet body as 2028 specified in Section 5.2 above. It is useful when one signature 2029 needs to refer to, or be incorporated in, another signature. 2030 20315.2.4. Computing Signatures 2032 2033 All signatures are formed by producing a hash over the signature 2034 data, and then using the resulting hash in the signature algorithm. 2035 2036 For binary document signatures (type 0x00), the document data is 2037 hashed directly. For text document signatures (type 0x01), the 2038 document is canonicalized by converting line endings to <CR><LF>, 2039 and the resulting data is hashed. 2040 2041 When a signature is made over a key, the hash data starts with the 2042 octet 0x99, followed by a two-octet length of the key, and then body 2043 of the key packet. (Note that this is an old-style packet header for 2044 a key packet with two-octet length.) A subkey binding signature 2045 (type 0x18) or primary key binding signature (type 0x19) then hashes 2046 the subkey using the same format as the main key (also using 0x99 as 2047 the first octet). Key revocation signatures (types 0x20 and 0x28) 2048 hash only the key being revoked. 2049 2050 A certification signature (type 0x10 through 0x13) hashes the User 2051 ID being bound to the key into the hash context after the above 2052 data. A V3 certification hashes the contents of the User ID or 2053 attribute packet packet, without any header. A V4 certification 2054 hashes the constant 0xB4 for User ID certifications or the constant 2055 0xD1 for User Attribute certifications, followed by a four-octet 2056 number giving the length of the User ID or User Attribute data, and 2057 then the User ID or User Attribute data. 2058 2059 When a signature is made over a Signature packet (type 0x50), the 2060 hash data starts with the octet 0x88, followed by the four-octet 2061 length of the signature, and then the body of the Signature packet. 2062 (Note that this is an old-style packet header for a Signature packet 2063 with the length-of-length set to zero.) The unhashed subpacket data 2064 of the Signature packet being hashed is not included in the hash, and 2065 the unhashed subpacket data length value is set to zero. 2066 2067 Once the data body is hashed, then a trailer is hashed. A V3 2068 signature hashes five octets of the packet body, starting from the 2069 signature type field. This data is the signature type, followed by 2070 the four-octet signature time. A V4 signature hashes the packet body 2071 2072 2073 2074Callas, et al Standards Track [Page 37] 2075 2076RFC 4880 OpenPGP Message Format November 2007 2077 2078 2079 starting from its first field, the version number, through the end 2080 of the hashed subpacket data. Thus, the fields hashed are the 2081 signature version, the signature type, the public-key algorithm, the 2082 hash algorithm, the hashed subpacket length, and the hashed 2083 subpacket body. 2084 2085 V4 signatures also hash in a final trailer of six octets: the 2086 version of the Signature packet, i.e., 0x04; 0xFF; and a four-octet, 2087 big-endian number that is the length of the hashed data from the 2088 Signature packet (note that this number does not include these final 2089 six octets). 2090 2091 After all this has been hashed in a single hash context, the 2092 resulting hash field is used in the signature algorithm and placed 2093 at the end of the Signature packet. 2094 20955.2.4.1. Subpacket Hints 2096 2097 It is certainly possible for a signature to contain conflicting 2098 information in subpackets. For example, a signature may contain 2099 multiple copies of a preference or multiple expiration times. In 2100 most cases, an implementation SHOULD use the last subpacket in the 2101 signature, but MAY use any conflict resolution scheme that makes 2102 more sense. Please note that we are intentionally leaving conflict 2103 resolution to the implementer; most conflicts are simply syntax 2104 errors, and the wishy-washy language here allows a receiver to be 2105 generous in what they accept, while putting pressure on a creator to 2106 be stingy in what they generate. 2107 2108 Some apparent conflicts may actually make sense -- for example, 2109 suppose a keyholder has a V3 key and a V4 key that share the same 2110 RSA key material. Either of these keys can verify a signature 2111 created by the other, and it may be reasonable for a signature to 2112 contain an issuer subpacket for each key, as a way of explicitly 2113 tying those keys to the signature. 2114 21155.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) 2116 2117 The Symmetric-Key Encrypted Session Key packet holds the 2118 symmetric-key encryption of a session key used to encrypt a message. 2119 Zero or more Public-Key Encrypted Session Key packets and/or 2120 Symmetric-Key Encrypted Session Key packets may precede a 2121 Symmetrically Encrypted Data packet that holds an encrypted message. 2122 The message is encrypted with a session key, and the session key is 2123 itself encrypted and stored in the Encrypted Session Key packet or 2124 the Symmetric-Key Encrypted Session Key packet. 2125 2126 2127 2128 2129 2130Callas, et al Standards Track [Page 38] 2131 2132RFC 4880 OpenPGP Message Format November 2007 2133 2134 2135 If the Symmetrically Encrypted Data packet is preceded by one or 2136 more Symmetric-Key Encrypted Session Key packets, each specifies a 2137 passphrase that may be used to decrypt the message. This allows a 2138 message to be encrypted to a number of public keys, and also to one 2139 or more passphrases. This packet type is new and is not generated 2140 by PGP 2.x or PGP 5.0. 2141 2142 The body of this packet consists of: 2143 2144 - A one-octet version number. The only currently defined version 2145 is 4. 2146 2147 - A one-octet number describing the symmetric algorithm used. 2148 2149 - A string-to-key (S2K) specifier, length as defined above. 2150 2151 - Optionally, the encrypted session key itself, which is decrypted 2152 with the string-to-key object. 2153 2154 If the encrypted session key is not present (which can be detected 2155 on the basis of packet length and S2K specifier size), then the S2K 2156 algorithm applied to the passphrase produces the session key for 2157 decrypting the file, using the symmetric cipher algorithm from the 2158 Symmetric-Key Encrypted Session Key packet. 2159 2160 If the encrypted session key is present, the result of applying the 2161 S2K algorithm to the passphrase is used to decrypt just that 2162 encrypted session key field, using CFB mode with an IV of all zeros. 2163 The decryption result consists of a one-octet algorithm identifier 2164 that specifies the symmetric-key encryption algorithm used to 2165 encrypt the following Symmetrically Encrypted Data packet, followed 2166 by the session key octets themselves. 2167 2168 Note: because an all-zero IV is used for this decryption, the S2K 2169 specifier MUST use a salt value, either a Salted S2K or an 2170 Iterated-Salted S2K. The salt value will ensure that the decryption 2171 key is not repeated even if the passphrase is reused. 2172 21735.4. One-Pass Signature Packets (Tag 4) 2174 2175 The One-Pass Signature packet precedes the signed data and contains 2176 enough information to allow the receiver to begin calculating any 2177 hashes needed to verify the signature. It allows the Signature 2178 packet to be placed at the end of the message, so that the signer 2179 can compute the entire signed message in one pass. 2180 2181 A One-Pass Signature does not interoperate with PGP 2.6.x or 2182 earlier. 2183 2184 2185 2186Callas, et al Standards Track [Page 39] 2187 2188RFC 4880 OpenPGP Message Format November 2007 2189 2190 2191 The body of this packet consists of: 2192 2193 - A one-octet version number. The current version is 3. 2194 2195 - A one-octet signature type. Signature types are described in 2196 Section 5.2.1. 2197 2198 - A one-octet number describing the hash algorithm used. 2199 2200 - A one-octet number describing the public-key algorithm used. 2201 2202 - An eight-octet number holding the Key ID of the signing key. 2203 2204 - A one-octet number holding a flag showing whether the signature 2205 is nested. A zero value indicates that the next packet is 2206 another One-Pass Signature packet that describes another 2207 signature to be applied to the same message data. 2208 2209 Note that if a message contains more than one one-pass signature, 2210 then the Signature packets bracket the message; that is, the first 2211 Signature packet after the message corresponds to the last one-pass 2212 packet and the final Signature packet corresponds to the first 2213 one-pass packet. 2214 22155.5. Key Material Packet 2216 2217 A key material packet contains all the information about a public or 2218 private key. There are four variants of this packet type, and two 2219 major versions. Consequently, this section is complex. 2220 22215.5.1. Key Packet Variants 2222 22235.5.1.1. Public-Key Packet (Tag 6) 2224 2225 A Public-Key packet starts a series of packets that forms an OpenPGP 2226 key (sometimes called an OpenPGP certificate). 2227 22285.5.1.2. Public-Subkey Packet (Tag 14) 2229 2230 A Public-Subkey packet (tag 14) has exactly the same format as a 2231 Public-Key packet, but denotes a subkey. One or more subkeys may be 2232 associated with a top-level key. By convention, the top-level key 2233 provides signature services, and the subkeys provide encryption 2234 services. 2235 2236 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 2237 packet. This tag was selected for reuse because no previous version 2238 of PGP ever emitted comment packets but they did properly ignore 2239 2240 2241 2242Callas, et al Standards Track [Page 40] 2243 2244RFC 4880 OpenPGP Message Format November 2007 2245 2246 2247 them. Public-Subkey packets are ignored by PGP 2.6.x and do not 2248 cause it to fail, providing a limited degree of backward 2249 compatibility. 2250 22515.5.1.3. Secret-Key Packet (Tag 5) 2252 2253 A Secret-Key packet contains all the information that is found in a 2254 Public-Key packet, including the public-key material, but also 2255 includes the secret-key material after all the public-key fields. 2256 22575.5.1.4. Secret-Subkey Packet (Tag 7) 2258 2259 A Secret-Subkey packet (tag 7) is the subkey analog of the Secret 2260 Key packet and has exactly the same format. 2261 22625.5.2. Public-Key Packet Formats 2263 2264 There are two versions of key-material packets. Version 3 packets 2265 were first generated by PGP 2.6. Version 4 keys first appeared in 2266 PGP 5.0 and are the preferred key version for OpenPGP. 2267 2268 OpenPGP implementations MUST create keys with version 4 format. V3 2269 keys are deprecated; an implementation MUST NOT generate a V3 key, 2270 but MAY accept it. 2271 2272 A version 3 public key or public-subkey packet contains: 2273 2274 - A one-octet version number (3). 2275 2276 - A four-octet number denoting the time that the key was created. 2277 2278 - A two-octet number denoting the time in days that this key is 2279 valid. If this number is zero, then it does not expire. 2280 2281 - A one-octet number denoting the public-key algorithm of this key. 2282 2283 - A series of multiprecision integers comprising the key material: 2284 2285 - a multiprecision integer (MPI) of RSA public modulus n; 2286 2287 - an MPI of RSA public encryption exponent e. 2288 2289 V3 keys are deprecated. They contain three weaknesses. First, it is 2290 relatively easy to construct a V3 key that has the same Key ID as any 2291 other key because the Key ID is simply the low 64 bits of the public 2292 modulus. Secondly, because the fingerprint of a V3 key hashes the 2293 key material, but not its length, there is an increased opportunity 2294 for fingerprint collisions. Third, there are weaknesses in the MD5 2295 2296 2297 2298Callas, et al Standards Track [Page 41] 2299 2300RFC 4880 OpenPGP Message Format November 2007 2301 2302 2303 hash algorithm that make developers prefer other algorithms. See 2304 below for a fuller discussion of Key IDs and fingerprints. 2305 2306 V2 keys are identical to the deprecated V3 keys except for the 2307 version number. An implementation MUST NOT generate them and MAY 2308 accept or reject them as it sees fit. 2309 2310 The version 4 format is similar to the version 3 format except for 2311 the absence of a validity period. This has been moved to the 2312 Signature packet. In addition, fingerprints of version 4 keys are 2313 calculated differently from version 3 keys, as described in the 2314 section "Enhanced Key Formats". 2315 2316 A version 4 packet contains: 2317 2318 - A one-octet version number (4). 2319 2320 - A four-octet number denoting the time that the key was created. 2321 2322 - A one-octet number denoting the public-key algorithm of this key. 2323 2324 - A series of multiprecision integers comprising the key material. 2325 This algorithm-specific portion is: 2326 2327 Algorithm-Specific Fields for RSA public keys: 2328 2329 - multiprecision integer (MPI) of RSA public modulus n; 2330 2331 - MPI of RSA public encryption exponent e. 2332 2333 Algorithm-Specific Fields for DSA public keys: 2334 2335 - MPI of DSA prime p; 2336 2337 - MPI of DSA group order q (q is a prime divisor of p-1); 2338 2339 - MPI of DSA group generator g; 2340 2341 - MPI of DSA public-key value y (= g**x mod p where x 2342 is secret). 2343 2344 Algorithm-Specific Fields for Elgamal public keys: 2345 2346 - MPI of Elgamal prime p; 2347 2348 - MPI of Elgamal group generator g; 2349 2350 2351 2352 2353 2354Callas, et al Standards Track [Page 42] 2355 2356RFC 4880 OpenPGP Message Format November 2007 2357 2358 2359 - MPI of Elgamal public key value y (= g**x mod p where x 2360 is secret). 2361 23625.5.3. Secret-Key Packet Formats 2363 2364 The Secret-Key and Secret-Subkey packets contain all the data of the 2365 Public-Key and Public-Subkey packets, with additional algorithm- 2366 specific secret-key data appended, usually in encrypted form. 2367 2368 The packet contains: 2369 2370 - A Public-Key or Public-Subkey packet, as described above. 2371 2372 - One octet indicating string-to-key usage conventions. Zero 2373 indicates that the secret-key data is not encrypted. 255 or 254 2374 indicates that a string-to-key specifier is being given. Any 2375 other value is a symmetric-key encryption algorithm identifier. 2376 2377 - [Optional] If string-to-key usage octet was 255 or 254, a one- 2378 octet symmetric encryption algorithm. 2379 2380 - [Optional] If string-to-key usage octet was 255 or 254, a 2381 string-to-key specifier. The length of the string-to-key 2382 specifier is implied by its type, as described above. 2383 2384 - [Optional] If secret data is encrypted (string-to-key usage octet 2385 not zero), an Initial Vector (IV) of the same length as the 2386 cipher's block size. 2387 2388 - Plain or encrypted multiprecision integers comprising the secret 2389 key data. These algorithm-specific fields are as described 2390 below. 2391 2392 - If the string-to-key usage octet is zero or 255, then a two-octet 2393 checksum of the plaintext of the algorithm-specific portion (sum 2394 of all octets, mod 65536). If the string-to-key usage octet was 2395 254, then a 20-octet SHA-1 hash of the plaintext of the 2396 algorithm-specific portion. This checksum or hash is encrypted 2397 together with the algorithm-specific fields (if string-to-key 2398 usage octet is not zero). Note that for all other values, a 2399 two-octet checksum is required. 2400 2401 Algorithm-Specific Fields for RSA secret keys: 2402 2403 - multiprecision integer (MPI) of RSA secret exponent d. 2404 2405 - MPI of RSA secret prime value p. 2406 2407 2408 2409 2410Callas, et al Standards Track [Page 43] 2411 2412RFC 4880 OpenPGP Message Format November 2007 2413 2414 2415 - MPI of RSA secret prime value q (p < q). 2416 2417 - MPI of u, the multiplicative inverse of p, mod q. 2418 2419 Algorithm-Specific Fields for DSA secret keys: 2420 2421 - MPI of DSA secret exponent x. 2422 2423 Algorithm-Specific Fields for Elgamal secret keys: 2424 2425 - MPI of Elgamal secret exponent x. 2426 2427 Secret MPI values can be encrypted using a passphrase. If a string- 2428 to-key specifier is given, that describes the algorithm for 2429 converting the passphrase to a key, else a simple MD5 hash of the 2430 passphrase is used. Implementations MUST use a string-to-key 2431 specifier; the simple hash is for backward compatibility and is 2432 deprecated, though implementations MAY continue to use existing 2433 private keys in the old format. The cipher for encrypting the MPIs 2434 is specified in the Secret-Key packet. 2435 2436 Encryption/decryption of the secret data is done in CFB mode using 2437 the key created from the passphrase and the Initial Vector from the 2438 packet. A different mode is used with V3 keys (which are only RSA) 2439 than with other key formats. With V3 keys, the MPI bit count prefix 2440 (i.e., the first two octets) is not encrypted. Only the MPI non- 2441 prefix data is encrypted. Furthermore, the CFB state is 2442 resynchronized at the beginning of each new MPI value, so that the 2443 CFB block boundary is aligned with the start of the MPI data. 2444 2445 With V4 keys, a simpler method is used. All secret MPI values are 2446 encrypted in CFB mode, including the MPI bitcount prefix. 2447 2448 The two-octet checksum that follows the algorithm-specific portion is 2449 the algebraic sum, mod 65536, of the plaintext of all the algorithm- 2450 specific octets (including MPI prefix and data). With V3 keys, the 2451 checksum is stored in the clear. With V4 keys, the checksum is 2452 encrypted like the algorithm-specific data. This value is used to 2453 check that the passphrase was correct. However, this checksum is 2454 deprecated; an implementation SHOULD NOT use it, but should rather 2455 use the SHA-1 hash denoted with a usage octet of 254. The reason for 2456 this is that there are some attacks that involve undetectably 2457 modifying the secret key. 2458 2459 2460 2461 2462 2463 2464 2465 2466Callas, et al Standards Track [Page 44] 2467 2468RFC 4880 OpenPGP Message Format November 2007 2469 2470 24715.6. Compressed Data Packet (Tag 8) 2472 2473 The Compressed Data packet contains compressed data. Typically, this 2474 packet is found as the contents of an encrypted packet, or following 2475 a Signature or One-Pass Signature packet, and contains a literal data 2476 packet. 2477 2478 The body of this packet consists of: 2479 2480 - One octet that gives the algorithm used to compress the packet. 2481 2482 - Compressed data, which makes up the remainder of the packet. 2483 2484 A Compressed Data Packet's body contains an block that compresses 2485 some set of packets. See section "Packet Composition" for details on 2486 how messages are formed. 2487 2488 ZIP-compressed packets are compressed with raw RFC 1951 [RFC1951] 2489 DEFLATE blocks. Note that PGP V2.6 uses 13 bits of compression. If 2490 an implementation uses more bits of compression, PGP V2.6 cannot 2491 decompress it. 2492 2493 ZLIB-compressed packets are compressed with RFC 1950 [RFC1950] ZLIB- 2494 style blocks. 2495 2496 BZip2-compressed packets are compressed using the BZip2 [BZ2] 2497 algorithm. 2498 24995.7. Symmetrically Encrypted Data Packet (Tag 9) 2500 2501 The Symmetrically Encrypted Data packet contains data encrypted with 2502 a symmetric-key algorithm. When it has been decrypted, it contains 2503 other packets (usually a literal data packet or compressed data 2504 packet, but in theory other Symmetrically Encrypted Data packets or 2505 sequences of packets that form whole OpenPGP messages). 2506 2507 The body of this packet consists of: 2508 2509 - Encrypted data, the output of the selected symmetric-key cipher 2510 operating in OpenPGP's variant of Cipher Feedback (CFB) mode. 2511 2512 The symmetric cipher used may be specified in a Public-Key or 2513 Symmetric-Key Encrypted Session Key packet that precedes the 2514 Symmetrically Encrypted Data packet. In that case, the cipher 2515 algorithm octet is prefixed to the session key before it is 2516 encrypted. If no packets of these types precede the encrypted data, 2517 the IDEA algorithm is used with the session key calculated as the MD5 2518 hash of the passphrase, though this use is deprecated. 2519 2520 2521 2522Callas, et al Standards Track [Page 45] 2523 2524RFC 4880 OpenPGP Message Format November 2007 2525 2526 2527 The data is encrypted in CFB mode, with a CFB shift size equal to the 2528 cipher's block size. The Initial Vector (IV) is specified as all 2529 zeros. Instead of using an IV, OpenPGP prefixes a string of length 2530 equal to the block size of the cipher plus two to the data before it 2531 is encrypted. The first block-size octets (for example, 8 octets for 2532 a 64-bit block length) are random, and the following two octets are 2533 copies of the last two octets of the IV. For example, in an 8-octet 2534 block, octet 9 is a repeat of octet 7, and octet 10 is a repeat of 2535 octet 8. In a cipher of length 16, octet 17 is a repeat of octet 15 2536 and octet 18 is a repeat of octet 16. As a pedantic clarification, 2537 in both these examples, we consider the first octet to be numbered 1. 2538 2539 After encrypting the first block-size-plus-two octets, the CFB state 2540 is resynchronized. The last block-size octets of ciphertext are 2541 passed through the cipher and the block boundary is reset. 2542 2543 The repetition of 16 bits in the random data prefixed to the message 2544 allows the receiver to immediately check whether the session key is 2545 incorrect. See the "Security Considerations" section for hints on 2546 the proper use of this "quick check". 2547 25485.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 2549 2550 An experimental version of PGP used this packet as the Literal 2551 packet, but no released version of PGP generated Literal packets with 2552 this tag. With PGP 5.x, this packet has been reassigned and is 2553 reserved for use as the Marker packet. 2554 2555 The body of this packet consists of: 2556 2557 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 2558 2559 Such a packet MUST be ignored when received. It may be placed at the 2560 beginning of a message that uses features not available in PGP 2.6.x 2561 in order to cause that version to report that newer software is 2562 necessary to process the message. 2563 25645.9. Literal Data Packet (Tag 11) 2565 2566 A Literal Data packet contains the body of a message; data that is 2567 not to be further interpreted. 2568 2569 The body of this packet consists of: 2570 2571 - A one-octet field that describes how the data is formatted. 2572 2573 2574 2575 2576 2577 2578Callas, et al Standards Track [Page 46] 2579 2580RFC 4880 OpenPGP Message Format November 2007 2581 2582 2583 If it is a 'b' (0x62), then the Literal packet contains binary data. 2584 If it is a 't' (0x74), then it contains text data, and thus may need 2585 line ends converted to local form, or other text-mode changes. The 2586 tag 'u' (0x75) means the same as 't', but also indicates that 2587 implementation believes that the literal data contains UTF-8 text. 2588 2589 Early versions of PGP also defined a value of 'l' as a 'local' mode 2590 for machine-local conversions. RFC 1991 [RFC1991] incorrectly stated 2591 this local mode flag as '1' (ASCII numeral one). Both of these local 2592 modes are deprecated. 2593 2594 - File name as a string (one-octet length, followed by a file 2595 name). This may be a zero-length string. Commonly, if the 2596 source of the encrypted data is a file, this will be the name of 2597 the encrypted file. An implementation MAY consider the file name 2598 in the Literal packet to be a more authoritative name than the 2599 actual file name. 2600 2601 If the special name "_CONSOLE" is used, the message is considered to 2602 be "for your eyes only". This advises that the message data is 2603 unusually sensitive, and the receiving program should process it more 2604 carefully, perhaps avoiding storing the received data to disk, for 2605 example. 2606 2607 - A four-octet number that indicates a date associated with the 2608 literal data. Commonly, the date might be the modification date 2609 of a file, or the time the packet was created, or a zero that 2610 indicates no specific time. 2611 2612 - The remainder of the packet is literal data. 2613 2614 Text data is stored with <CR><LF> text endings (i.e., network- 2615 normal line endings). These should be converted to native line 2616 endings by the receiving software. 2617 26185.10. Trust Packet (Tag 12) 2619 2620 The Trust packet is used only within keyrings and is not normally 2621 exported. Trust packets contain data that record the user's 2622 specifications of which key holders are trustworthy introducers, 2623 along with other information that implementing software uses for 2624 trust information. The format of Trust packets is defined by a given 2625 implementation. 2626 2627 Trust packets SHOULD NOT be emitted to output streams that are 2628 transferred to other users, and they SHOULD be ignored on any input 2629 other than local keyring files. 2630 2631 2632 2633 2634Callas, et al Standards Track [Page 47] 2635 2636RFC 4880 OpenPGP Message Format November 2007 2637 2638 26395.11. User ID Packet (Tag 13) 2640 2641 A User ID packet consists of UTF-8 text that is intended to represent 2642 the name and email address of the key holder. By convention, it 2643 includes an RFC 2822 [RFC2822] mail name-addr, but there are no 2644 restrictions on its content. The packet length in the header 2645 specifies the length of the User ID. 2646 26475.12. User Attribute Packet (Tag 17) 2648 2649 The User Attribute packet is a variation of the User ID packet. It 2650 is capable of storing more types of data than the User ID packet, 2651 which is limited to text. Like the User ID packet, a User Attribute 2652 packet may be certified by the key owner ("self-signed") or any other 2653 key owner who cares to certify it. Except as noted, a User Attribute 2654 packet may be used anywhere that a User ID packet may be used. 2655 2656 While User Attribute packets are not a required part of the OpenPGP 2657 standard, implementations SHOULD provide at least enough 2658 compatibility to properly handle a certification signature on the 2659 User Attribute packet. A simple way to do this is by treating the 2660 User Attribute packet as a User ID packet with opaque contents, but 2661 an implementation may use any method desired. 2662 2663 The User Attribute packet is made up of one or more attribute 2664 subpackets. Each subpacket consists of a subpacket header and a 2665 body. The header consists of: 2666 2667 - the subpacket length (1, 2, or 5 octets) 2668 2669 - the subpacket type (1 octet) 2670 2671 and is followed by the subpacket specific data. 2672 2673 The only currently defined subpacket type is 1, signifying an image. 2674 An implementation SHOULD ignore any subpacket of a type that it does 2675 not recognize. Subpacket types 100 through 110 are reserved for 2676 private or experimental use. 2677 26785.12.1. The Image Attribute Subpacket 2679 2680 The Image Attribute subpacket is used to encode an image, presumably 2681 (but not required to be) that of the key owner. 2682 2683 The Image Attribute subpacket begins with an image header. The first 2684 two octets of the image header contain the length of the image 2685 header. Note that unlike other multi-octet numerical values in this 2686 document, due to a historical accident this value is encoded as a 2687 2688 2689 2690Callas, et al Standards Track [Page 48] 2691 2692RFC 4880 OpenPGP Message Format November 2007 2693 2694 2695 little-endian number. The image header length is followed by a 2696 single octet for the image header version. The only currently 2697 defined version of the image header is 1, which is a 16-octet image 2698 header. The first three octets of a version 1 image header are thus 2699 0x10, 0x00, 0x01. 2700 2701 The fourth octet of a version 1 image header designates the encoding 2702 format of the image. The only currently defined encoding format is 2703 the value 1 to indicate JPEG. Image format types 100 through 110 are 2704 reserved for private or experimental use. The rest of the version 1 2705 image header is made up of 12 reserved octets, all of which MUST be 2706 set to 0. 2707 2708 The rest of the image subpacket contains the image itself. As the 2709 only currently defined image type is JPEG, the image is encoded in 2710 the JPEG File Interchange Format (JFIF), a standard file format for 2711 JPEG images [JFIF]. 2712 2713 An implementation MAY try to determine the type of an image by 2714 examination of the image data if it is unable to handle a particular 2715 version of the image header or if a specified encoding format value 2716 is not recognized. 2717 27185.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) 2719 2720 The Symmetrically Encrypted Integrity Protected Data packet is a 2721 variant of the Symmetrically Encrypted Data packet. It is a new 2722 feature created for OpenPGP that addresses the problem of detecting a 2723 modification to encrypted data. It is used in combination with a 2724 Modification Detection Code packet. 2725 2726 There is a corresponding feature in the features Signature subpacket 2727 that denotes that an implementation can properly use this packet 2728 type. An implementation MUST support decrypting these packets and 2729 SHOULD prefer generating them to the older Symmetrically Encrypted 2730 Data packet when possible. Since this data packet protects against 2731 modification attacks, this standard encourages its proliferation. 2732 While blanket adoption of this data packet would create 2733 interoperability problems, rapid adoption is nevertheless important. 2734 An implementation SHOULD specifically denote support for this packet, 2735 but it MAY infer it from other mechanisms. 2736 2737 For example, an implementation might infer from the use of a cipher 2738 such as Advanced Encryption Standard (AES) or Twofish that a user 2739 supports this feature. It might place in the unhashed portion of 2740 another user's key signature a Features subpacket. It might also 2741 present a user with an opportunity to regenerate their own self- 2742 signature with a Features subpacket. 2743 2744 2745 2746Callas, et al Standards Track [Page 49] 2747 2748RFC 4880 OpenPGP Message Format November 2007 2749 2750 2751 This packet contains data encrypted with a symmetric-key algorithm 2752 and protected against modification by the SHA-1 hash algorithm. When 2753 it has been decrypted, it will typically contain other packets (often 2754 a Literal Data packet or Compressed Data packet). The last decrypted 2755 packet in this packet's payload MUST be a Modification Detection Code 2756 packet. 2757 2758 The body of this packet consists of: 2759 2760 - A one-octet version number. The only currently defined value is 2761 1. 2762 2763 - Encrypted data, the output of the selected symmetric-key cipher 2764 operating in Cipher Feedback mode with shift amount equal to the 2765 block size of the cipher (CFB-n where n is the block size). 2766 2767 The symmetric cipher used MUST be specified in a Public-Key or 2768 Symmetric-Key Encrypted Session Key packet that precedes the 2769 Symmetrically Encrypted Data packet. In either case, the cipher 2770 algorithm octet is prefixed to the session key before it is 2771 encrypted. 2772 2773 The data is encrypted in CFB mode, with a CFB shift size equal to the 2774 cipher's block size. The Initial Vector (IV) is specified as all 2775 zeros. Instead of using an IV, OpenPGP prefixes an octet string to 2776 the data before it is encrypted. The length of the octet string 2777 equals the block size of the cipher in octets, plus two. The first 2778 octets in the group, of length equal to the block size of the cipher, 2779 are random; the last two octets are each copies of their 2nd 2780 preceding octet. For example, with a cipher whose block size is 128 2781 bits or 16 octets, the prefix data will contain 16 random octets, 2782 then two more octets, which are copies of the 15th and 16th octets, 2783 respectively. Unlike the Symmetrically Encrypted Data Packet, no 2784 special CFB resynchronization is done after encrypting this prefix 2785 data. See "OpenPGP CFB Mode" below for more details. 2786 2787 The repetition of 16 bits in the random data prefixed to the message 2788 allows the receiver to immediately check whether the session key is 2789 incorrect. 2790 2791 The plaintext of the data to be encrypted is passed through the SHA-1 2792 hash function, and the result of the hash is appended to the 2793 plaintext in a Modification Detection Code packet. The input to the 2794 hash function includes the prefix data described above; it includes 2795 all of the plaintext, and then also includes two octets of values 2796 0xD3, 0x14. These represent the encoding of a Modification Detection 2797 Code packet tag and length field of 20 octets. 2798 2799 2800 2801 2802Callas, et al Standards Track [Page 50] 2803 2804RFC 4880 OpenPGP Message Format November 2007 2805 2806 2807 The resulting hash value is stored in a Modification Detection Code 2808 (MDC) packet, which MUST use the two octet encoding just given to 2809 represent its tag and length field. The body of the MDC packet is 2810 the 20-octet output of the SHA-1 hash. 2811 2812 The Modification Detection Code packet is appended to the plaintext 2813 and encrypted along with the plaintext using the same CFB context. 2814 2815 During decryption, the plaintext data should be hashed with SHA-1, 2816 including the prefix data as well as the packet tag and length field 2817 of the Modification Detection Code packet. The body of the MDC 2818 packet, upon decryption, is compared with the result of the SHA-1 2819 hash. 2820 2821 Any failure of the MDC indicates that the message has been modified 2822 and MUST be treated as a security problem. Failures include a 2823 difference in the hash values, but also the absence of an MDC packet, 2824 or an MDC packet in any position other than the end of the plaintext. 2825 Any failure SHOULD be reported to the user. 2826 2827 Note: future designs of new versions of this packet should consider 2828 rollback attacks since it will be possible for an attacker to change 2829 the version back to 1. 2830 2831 NON-NORMATIVE EXPLANATION 2832 2833 The MDC system, as packets 18 and 19 are called, were created to 2834 provide an integrity mechanism that is less strong than a 2835 signature, yet stronger than bare CFB encryption. 2836 2837 It is a limitation of CFB encryption that damage to the ciphertext 2838 will corrupt the affected cipher blocks and the block following. 2839 Additionally, if data is removed from the end of a CFB-encrypted 2840 block, that removal is undetectable. (Note also that CBC mode has 2841 a similar limitation, but data removed from the front of the block 2842 is undetectable.) 2843 2844 The obvious way to protect or authenticate an encrypted block is 2845 to digitally sign it. However, many people do not wish to 2846 habitually sign data, for a large number of reasons beyond the 2847 scope of this document. Suffice it to say that many people 2848 consider properties such as deniability to be as valuable as 2849 integrity. 2850 2851 OpenPGP addresses this desire to have more security than raw 2852 encryption and yet preserve deniability with the MDC system. An 2853 MDC is intentionally not a MAC. Its name was not selected by 2854 accident. It is analogous to a checksum. 2855 2856 2857 2858Callas, et al Standards Track [Page 51] 2859 2860RFC 4880 OpenPGP Message Format November 2007 2861 2862 2863 Despite the fact that it is a relatively modest system, it has 2864 proved itself in the real world. It is an effective defense to 2865 several attacks that have surfaced since it has been created. It 2866 has met its modest goals admirably. 2867 2868 Consequently, because it is a modest security system, it has 2869 modest requirements on the hash function(s) it employs. It does 2870 not rely on a hash function being collision-free, it relies on a 2871 hash function being one-way. If a forger, Frank, wishes to send 2872 Alice a (digitally) unsigned message that says, "I've always 2873 secretly loved you, signed Bob", it is far easier for him to 2874 construct a new message than it is to modify anything intercepted 2875 from Bob. (Note also that if Bob wishes to communicate secretly 2876 with Alice, but without authentication or identification and with 2877 a threat model that includes forgers, he has a problem that 2878 transcends mere cryptography.) 2879 2880 Note also that unlike nearly every other OpenPGP subsystem, there 2881 are no parameters in the MDC system. It hard-defines SHA-1 as its 2882 hash function. This is not an accident. It is an intentional 2883 choice to avoid downgrade and cross-grade attacks while making a 2884 simple, fast system. (A downgrade attack would be an attack that 2885 replaced SHA-256 with SHA-1, for example. A cross-grade attack 2886 would replace SHA-1 with another 160-bit hash, such as RIPE- 2887 MD/160, for example.) 2888 2889 However, given the present state of hash function cryptanalysis 2890 and cryptography, it may be desirable to upgrade the MDC system to 2891 a new hash function. See Section 13.11 in the "IANA 2892 Considerations" for guidance. 2893 28945.14. Modification Detection Code Packet (Tag 19) 2895 2896 The Modification Detection Code packet contains a SHA-1 hash of 2897 plaintext data, which is used to detect message modification. It is 2898 only used with a Symmetrically Encrypted Integrity Protected Data 2899 packet. The Modification Detection Code packet MUST be the last 2900 packet in the plaintext data that is encrypted in the Symmetrically 2901 Encrypted Integrity Protected Data packet, and MUST appear in no 2902 other place. 2903 2904 A Modification Detection Code packet MUST have a length of 20 octets. 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914Callas, et al Standards Track [Page 52] 2915 2916RFC 4880 OpenPGP Message Format November 2007 2917 2918 2919 The body of this packet consists of: 2920 2921 - A 20-octet SHA-1 hash of the preceding plaintext data of the 2922 Symmetrically Encrypted Integrity Protected Data packet, 2923 including prefix data, the tag octet, and length octet of the 2924 Modification Detection Code packet. 2925 2926 Note that the Modification Detection Code packet MUST always use a 2927 new format encoding of the packet tag, and a one-octet encoding of 2928 the packet length. The reason for this is that the hashing rules for 2929 modification detection include a one-octet tag and one-octet length 2930 in the data hash. While this is a bit restrictive, it reduces 2931 complexity. 2932 29336. Radix-64 Conversions 2934 2935 As stated in the introduction, OpenPGP's underlying native 2936 representation for objects is a stream of arbitrary octets, and some 2937 systems desire these objects to be immune to damage caused by 2938 character set translation, data conversions, etc. 2939 2940 In principle, any printable encoding scheme that met the requirements 2941 of the unsafe channel would suffice, since it would not change the 2942 underlying binary bit streams of the native OpenPGP data structures. 2943 The OpenPGP standard specifies one such printable encoding scheme to 2944 ensure interoperability. 2945 2946 OpenPGP's Radix-64 encoding is composed of two parts: a base64 2947 encoding of the binary data and a checksum. The base64 encoding is 2948 identical to the MIME base64 content-transfer-encoding [RFC2045]. 2949 2950 The checksum is a 24-bit Cyclic Redundancy Check (CRC) converted to 2951 four characters of radix-64 encoding by the same MIME base64 2952 transformation, preceded by an equal sign (=). The CRC is computed 2953 by using the generator 0x864CFB and an initialization of 0xB704CE. 2954 The accumulation is done on the data before it is converted to 2955 radix-64, rather than on the converted data. A sample implementation 2956 of this algorithm is in the next section. 2957 2958 The checksum with its leading equal sign MAY appear on the first line 2959 after the base64 encoded data. 2960 2961 Rationale for CRC-24: The size of 24 bits fits evenly into printable 2962 base64. The nonzero initialization can detect more errors than a 2963 zero initialization. 2964 2965 2966 2967 2968 2969 2970Callas, et al Standards Track [Page 53] 2971 2972RFC 4880 OpenPGP Message Format November 2007 2973 2974 29756.1. An Implementation of the CRC-24 in "C" 2976 2977 #define CRC24_INIT 0xB704CEL 2978 #define CRC24_POLY 0x1864CFBL 2979 2980 typedef long crc24; 2981 crc24 crc_octets(unsigned char *octets, size_t len) 2982 { 2983 crc24 crc = CRC24_INIT; 2984 int i; 2985 while (len--) { 2986 crc ^= (*octets++) << 16; 2987 for (i = 0; i < 8; i++) { 2988 crc <<= 1; 2989 if (crc & 0x1000000) 2990 crc ^= CRC24_POLY; 2991 } 2992 } 2993 return crc & 0xFFFFFFL; 2994 } 2995 29966.2. Forming ASCII Armor 2997 2998 When OpenPGP encodes data into ASCII Armor, it puts specific headers 2999 around the Radix-64 encoded data, so OpenPGP can reconstruct the data 3000 later. An OpenPGP implementation MAY use ASCII armor to protect raw 3001 binary data. OpenPGP informs the user what kind of data is encoded 3002 in the ASCII armor through the use of the headers. 3003 3004 Concatenating the following data creates ASCII Armor: 3005 3006 - An Armor Header Line, appropriate for the type of data 3007 3008 - Armor Headers 3009 3010 - A blank (zero-length, or containing only whitespace) line 3011 3012 - The ASCII-Armored data 3013 3014 - An Armor Checksum 3015 3016 - The Armor Tail, which depends on the Armor Header Line 3017 3018 An Armor Header Line consists of the appropriate header line text 3019 surrounded by five (5) dashes ('-', 0x2D) on either side of the 3020 header line text. The header line text is chosen based upon the type 3021 of data that is being encoded in Armor, and how it is being encoded. 3022 Header line texts include the following strings: 3023 3024 3025 3026Callas, et al Standards Track [Page 54] 3027 3028RFC 4880 OpenPGP Message Format November 2007 3029 3030 3031 BEGIN PGP MESSAGE 3032 Used for signed, encrypted, or compressed files. 3033 3034 BEGIN PGP PUBLIC KEY BLOCK 3035 Used for armoring public keys. 3036 3037 BEGIN PGP PRIVATE KEY BLOCK 3038 Used for armoring private keys. 3039 3040 BEGIN PGP MESSAGE, PART X/Y 3041 Used for multi-part messages, where the armor is split amongst Y 3042 parts, and this is the Xth part out of Y. 3043 3044 BEGIN PGP MESSAGE, PART X 3045 Used for multi-part messages, where this is the Xth part of an 3046 unspecified number of parts. Requires the MESSAGE-ID Armor 3047 Header to be used. 3048 3049 BEGIN PGP SIGNATURE 3050 Used for detached signatures, OpenPGP/MIME signatures, and 3051 cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE 3052 for detached signatures. 3053 3054 Note that all these Armor Header Lines are to consist of a complete 3055 line. That is to say, there is always a line ending preceding the 3056 starting five dashes, and following the ending five dashes. The 3057 header lines, therefore, MUST start at the beginning of a line, and 3058 MUST NOT have text other than whitespace following them on the same 3059 line. These line endings are considered a part of the Armor Header 3060 Line for the purposes of determining the content they delimit. This 3061 is particularly important when computing a cleartext signature (see 3062 below). 3063 3064 The Armor Headers are pairs of strings that can give the user or the 3065 receiving OpenPGP implementation some information about how to decode 3066 or use the message. The Armor Headers are a part of the armor, not a 3067 part of the message, and hence are not protected by any signatures 3068 applied to the message. 3069 3070 The format of an Armor Header is that of a key-value pair. A colon 3071 (':' 0x38) and a single space (0x20) separate the key and value. 3072 OpenPGP should consider improperly formatted Armor Headers to be 3073 corruption of the ASCII Armor. Unknown keys should be reported to 3074 the user, but OpenPGP should continue to process the message. 3075 3076 Note that some transport methods are sensitive to line length. While 3077 there is a limit of 76 characters for the Radix-64 data (Section 3078 6.3), there is no limit to the length of Armor Headers. Care should 3079 3080 3081 3082Callas, et al Standards Track [Page 55] 3083 3084RFC 4880 OpenPGP Message Format November 2007 3085 3086 3087 be taken that the Armor Headers are short enough to survive 3088 transport. One way to do this is to repeat an Armor Header key 3089 multiple times with different values for each so that no one line is 3090 overly long. 3091 3092 Currently defined Armor Header Keys are as follows: 3093 3094 - "Version", which states the OpenPGP implementation and version 3095 used to encode the message. 3096 3097 - "Comment", a user-defined comment. OpenPGP defines all text to 3098 be in UTF-8. A comment may be any UTF-8 string. However, the 3099 whole point of armoring is to provide seven-bit-clean data. 3100 Consequently, if a comment has characters that are outside the 3101 US-ASCII range of UTF, they may very well not survive transport. 3102 3103 - "MessageID", a 32-character string of printable characters. The 3104 string must be the same for all parts of a multi-part message 3105 that uses the "PART X" Armor Header. MessageID strings should be 3106 unique enough that the recipient of the mail can associate all 3107 the parts of a message with each other. A good checksum or 3108 cryptographic hash function is sufficient. 3109 3110 The MessageID SHOULD NOT appear unless it is in a multi-part 3111 message. If it appears at all, it MUST be computed from the 3112 finished (encrypted, signed, etc.) message in a deterministic 3113 fashion, rather than contain a purely random value. This is to 3114 allow the legitimate recipient to determine that the MessageID 3115 cannot serve as a covert means of leaking cryptographic key 3116 information. 3117 3118 - "Hash", a comma-separated list of hash algorithms used in this 3119 message. This is used only in cleartext signed messages. 3120 3121 - "Charset", a description of the character set that the plaintext 3122 is in. Please note that OpenPGP defines text to be in UTF-8. An 3123 implementation will get best results by translating into and out 3124 of UTF-8. However, there are many instances where this is easier 3125 said than done. Also, there are communities of users who have no 3126 need for UTF-8 because they are all happy with a character set 3127 like ISO Latin-5 or a Japanese character set. In such instances, 3128 an implementation MAY override the UTF-8 default by using this 3129 header key. An implementation MAY implement this key and any 3130 translations it cares to; an implementation MAY ignore it and 3131 assume all text is UTF-8. 3132 3133 3134 3135 3136 3137 3138Callas, et al Standards Track [Page 56] 3139 3140RFC 4880 OpenPGP Message Format November 2007 3141 3142 3143 The Armor Tail Line is composed in the same manner as the Armor 3144 Header Line, except the string "BEGIN" is replaced by the string 3145 "END". 3146 31476.3. Encoding Binary in Radix-64 3148 3149 The encoding process represents 24-bit groups of input bits as output 3150 strings of 4 encoded characters. Proceeding from left to right, a 3151 24-bit input group is formed by concatenating three 8-bit input 3152 groups. These 24 bits are then treated as four concatenated 6-bit 3153 groups, each of which is translated into a single digit in the 3154 Radix-64 alphabet. When encoding a bit stream with the Radix-64 3155 encoding, the bit stream must be presumed to be ordered with the most 3156 significant bit first. That is, the first bit in the stream will be 3157 the high-order bit in the first 8-bit octet, and the eighth bit will 3158 be the low-order bit in the first 8-bit octet, and so on. 3159 3160 +--first octet--+-second octet--+--third octet--+ 3161 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 3162 +-----------+---+-------+-------+---+-----------+ 3163 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 3164 +--1.index--+--2.index--+--3.index--+--4.index--+ 3165 3166 Each 6-bit group is used as an index into an array of 64 printable 3167 characters from the table below. The character referenced by the 3168 index is placed in the output string. 3169 3170 Value Encoding Value Encoding Value Encoding Value Encoding 3171 0 A 17 R 34 i 51 z 3172 1 B 18 S 35 j 52 0 3173 2 C 19 T 36 k 53 1 3174 3 D 20 U 37 l 54 2 3175 4 E 21 V 38 m 55 3 3176 5 F 22 W 39 n 56 4 3177 6 G 23 X 40 o 57 5 3178 7 H 24 Y 41 p 58 6 3179 8 I 25 Z 42 q 59 7 3180 9 J 26 a 43 r 60 8 3181 10 K 27 b 44 s 61 9 3182 11 L 28 c 45 t 62 + 3183 12 M 29 d 46 u 63 / 3184 13 N 30 e 47 v 3185 14 O 31 f 48 w (pad) = 3186 15 P 32 g 49 x 3187 16 Q 33 h 50 y 3188 3189 The encoded output stream must be represented in lines of no more 3190 than 76 characters each. 3191 3192 3193 3194Callas, et al Standards Track [Page 57] 3195 3196RFC 4880 OpenPGP Message Format November 2007 3197 3198 3199 Special processing is performed if fewer than 24 bits are available 3200 at the end of the data being encoded. There are three possibilities: 3201 3202 1. The last data group has 24 bits (3 octets). No special processing 3203 is needed. 3204 3205 2. The last data group has 16 bits (2 octets). The first two 6-bit 3206 groups are processed as above. The third (incomplete) data group 3207 has two zero-value bits added to it, and is processed as above. A 3208 pad character (=) is added to the output. 3209 3210 3. The last data group has 8 bits (1 octet). The first 6-bit group 3211 is processed as above. The second (incomplete) data group has 3212 four zero-value bits added to it, and is processed as above. Two 3213 pad characters (=) are added to the output. 3214 32156.4. Decoding Radix-64 3216 3217 In Radix-64 data, characters other than those in the table, line 3218 breaks, and other white space probably indicate a transmission error, 3219 about which a warning message or even a message rejection might be 3220 appropriate under some circumstances. Decoding software must ignore 3221 all white space. 3222 3223 Because it is used only for padding at the end of the data, the 3224 occurrence of any "=" characters may be taken as evidence that the 3225 end of the data has been reached (without truncation in transit). No 3226 such assurance is possible, however, when the number of octets 3227 transmitted was a multiple of three and no "=" characters are 3228 present. 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250Callas, et al Standards Track [Page 58] 3251 3252RFC 4880 OpenPGP Message Format November 2007 3253 3254 32556.5. Examples of Radix-64 3256 3257 Input data: 0x14FB9C03D97E 3258 Hex: 1 4 F B 9 C | 0 3 D 9 7 E 3259 8-bit: 00010100 11111011 10011100 | 00000011 11011001 11111110 3260 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 111110 3261 Decimal: 5 15 46 28 0 61 37 62 3262 Output: F P u c A 9 l + 3263 Input data: 0x14FB9C03D9 3264 Hex: 1 4 F B 9 C | 0 3 D 9 3265 8-bit: 00010100 11111011 10011100 | 00000011 11011001 3266 pad with 00 3267 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 3268 Decimal: 5 15 46 28 0 61 36 3269 pad with = 3270 Output: F P u c A 9 k = 3271 Input data: 0x14FB9C03 3272 Hex: 1 4 F B 9 C | 0 3 3273 8-bit: 00010100 11111011 10011100 | 00000011 3274 pad with 0000 3275 6-bit: 000101 001111 101110 011100 | 000000 110000 3276 Decimal: 5 15 46 28 0 48 3277 pad with = = 3278 Output: F P u c A w = = 3279 32806.6. Example of an ASCII Armored Message 3281 3282 -----BEGIN PGP MESSAGE----- 3283 Version: OpenPrivacy 0.99 3284 3285 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 3286 vBSFjNSiVHsuAA== 3287 =njUN 3288 -----END PGP MESSAGE----- 3289 3290 Note that this example has extra indenting; an actual armored message 3291 would have no leading whitespace. 3292 32937. Cleartext Signature Framework 3294 3295 It is desirable to be able to sign a textual octet stream without 3296 ASCII armoring the stream itself, so the signed text is still 3297 readable without special software. In order to bind a signature to 3298 such a cleartext, this framework is used. (Note that this framework 3299 is not intended to be reversible. RFC 3156 [RFC3156] defines another 3300 way to sign cleartext messages for environments that support MIME.) 3301 3302 3303 3304 3305 3306Callas, et al Standards Track [Page 59] 3307 3308RFC 4880 OpenPGP Message Format November 2007 3309 3310 3311 The cleartext signed message consists of: 3312 3313 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 3314 single line, 3315 3316 - One or more "Hash" Armor Headers, 3317 3318 - Exactly one empty line not included into the message digest, 3319 3320 - The dash-escaped cleartext that is included into the message 3321 digest, 3322 3323 - The ASCII armored signature(s) including the '-----BEGIN PGP 3324 SIGNATURE-----' Armor Header and Armor Tail Lines. 3325 3326 If the "Hash" Armor Header is given, the specified message digest 3327 algorithm(s) are used for the signature. If there are no such 3328 headers, MD5 is used. If MD5 is the only hash used, then an 3329 implementation MAY omit this header for improved V2.x compatibility. 3330 If more than one message digest is used in the signature, the "Hash" 3331 armor header contains a comma-delimited list of used message digests. 3332 3333 Current message digest names are described below with the algorithm 3334 IDs. 3335 3336 An implementation SHOULD add a line break after the cleartext, but 3337 MAY omit it if the cleartext ends with a line break. This is for 3338 visual clarity. 3339 33407.1. Dash-Escaped Text 3341 3342 The cleartext content of the message must also be dash-escaped. 3343 3344 Dash-escaped cleartext is the ordinary cleartext where every line 3345 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 3346 (0x2D) and space ' ' (0x20). This prevents the parser from 3347 recognizing armor headers of the cleartext itself. An implementation 3348 MAY dash-escape any line, SHOULD dash-escape lines commencing "From" 3349 followed by a space, and MUST dash-escape any line commencing in a 3350 dash. The message digest is computed using the cleartext itself, not 3351 the dash-escaped form. 3352 3353 As with binary signatures on text documents, a cleartext signature is 3354 calculated on the text using canonical <CR><LF> line endings. The 3355 line ending (i.e., the <CR><LF>) before the '-----BEGIN PGP 3356 SIGNATURE-----' line that terminates the signed text is not 3357 considered part of the signed text. 3358 3359 3360 3361 3362Callas, et al Standards Track [Page 60] 3363 3364RFC 4880 OpenPGP Message Format November 2007 3365 3366 3367 When reversing dash-escaping, an implementation MUST strip the string 3368 "- " if it occurs at the beginning of a line, and SHOULD warn on "-" 3369 and any character other than a space at the beginning of a line. 3370 3371 Also, any trailing whitespace -- spaces (0x20) and tabs (0x09) -- at 3372 the end of any line is removed when the cleartext signature is 3373 generated. 3374 33758. Regular Expressions 3376 3377 A regular expression is zero or more branches, separated by '|'. It 3378 matches anything that matches one of the branches. 3379 3380 A branch is zero or more pieces, concatenated. It matches a match 3381 for the first, followed by a match for the second, etc. 3382 3383 A piece is an atom possibly followed by '*', '+', or '?'. An atom 3384 followed by '*' matches a sequence of 0 or more matches of the atom. 3385 An atom followed by '+' matches a sequence of 1 or more matches of 3386 the atom. An atom followed by '?' matches a match of the atom, or 3387 the null string. 3388 3389 An atom is a regular expression in parentheses (matching a match for 3390 the regular expression), a range (see below), '.' (matching any 3391 single character), '^' (matching the null string at the beginning of 3392 the input string), '$' (matching the null string at the end of the 3393 input string), a '\' followed by a single character (matching that 3394 character), or a single character with no other significance 3395 (matching that character). 3396 3397 A range is a sequence of characters enclosed in '[]'. It normally 3398 matches any single character from the sequence. If the sequence 3399 begins with '^', it matches any single character not from the rest of 3400 the sequence. If two characters in the sequence are separated 3401 by '-', this is shorthand for the full list of ASCII characters 3402 between them (e.g., '[0-9]' matches any decimal digit). To include a 3403 literal ']' in the sequence, make it the first character (following a 3404 possible '^'). To include a literal '-', make it the first or last 3405 character. 3406 34079. Constants 3408 3409 This section describes the constants used in OpenPGP. 3410 3411 Note that these tables are not exhaustive lists; an implementation 3412 MAY implement an algorithm not on these lists, so long as the 3413 algorithm numbers are chosen from the private or experimental 3414 algorithm range. 3415 3416 3417 3418Callas, et al Standards Track [Page 61] 3419 3420RFC 4880 OpenPGP Message Format November 2007 3421 3422 3423 See the section "Notes on Algorithms" below for more discussion of 3424 the algorithms. 3425 34269.1. Public-Key Algorithms 3427 3428 ID Algorithm 3429 -- --------- 3430 1 - RSA (Encrypt or Sign) [HAC] 3431 2 - RSA Encrypt-Only [HAC] 3432 3 - RSA Sign-Only [HAC] 3433 16 - Elgamal (Encrypt-Only) [ELGAMAL] [HAC] 3434 17 - DSA (Digital Signature Algorithm) [FIPS186] [HAC] 3435 18 - Reserved for Elliptic Curve 3436 19 - Reserved for ECDSA 3437 20 - Reserved (formerly Elgamal Encrypt or Sign) 3438 21 - Reserved for Diffie-Hellman (X9.42, 3439 as defined for IETF-S/MIME) 3440 100 to 110 - Private/Experimental algorithm 3441 3442 Implementations MUST implement DSA for signatures, and Elgamal for 3443 encryption. Implementations SHOULD implement RSA keys (1). RSA 3444 Encrypt-Only (2) and RSA Sign-Only are deprecated and SHOULD NOT be 3445 generated, but may be interpreted. See Section 13.5. See Section 3446 13.8 for notes on Elliptic Curve (18), ECDSA (19), Elgamal Encrypt or 3447 Sign (20), and X9.42 (21). Implementations MAY implement any other 3448 algorithm. 3449 34509.2. Symmetric-Key Algorithms 3451 3452 ID Algorithm 3453 -- --------- 3454 0 - Plaintext or unencrypted data 3455 1 - IDEA [IDEA] 3456 2 - TripleDES (DES-EDE, [SCHNEIER] [HAC] - 3457 168 bit key derived from 192) 3458 3 - CAST5 (128 bit key, as per [RFC2144]) 3459 4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH] 3460 5 - Reserved 3461 6 - Reserved 3462 7 - AES with 128-bit key [AES] 3463 8 - AES with 192-bit key 3464 9 - AES with 256-bit key 3465 10 - Twofish with 256-bit key [TWOFISH] 3466 100 to 110 - Private/Experimental algorithm 3467 3468 Implementations MUST implement TripleDES. Implementations SHOULD 3469 implement AES-128 and CAST5. Implementations that interoperate with 3470 3471 3472 3473 3474Callas, et al Standards Track [Page 62] 3475 3476RFC 4880 OpenPGP Message Format November 2007 3477 3478 3479 PGP 2.6 or earlier need to support IDEA, as that is the only 3480 symmetric cipher those versions use. Implementations MAY implement 3481 any other algorithm. 3482 34839.3. Compression Algorithms 3484 3485 ID Algorithm 3486 -- --------- 3487 0 - Uncompressed 3488 1 - ZIP [RFC1951] 3489 2 - ZLIB [RFC1950] 3490 3 - BZip2 [BZ2] 3491 100 to 110 - Private/Experimental algorithm 3492 3493 Implementations MUST implement uncompressed data. Implementations 3494 SHOULD implement ZIP. Implementations MAY implement any other 3495 algorithm. 3496 34979.4. Hash Algorithms 3498 3499 ID Algorithm Text Name 3500 -- --------- --------- 3501 1 - MD5 [HAC] "MD5" 3502 2 - SHA-1 [FIPS180] "SHA1" 3503 3 - RIPE-MD/160 [HAC] "RIPEMD160" 3504 4 - Reserved 3505 5 - Reserved 3506 6 - Reserved 3507 7 - Reserved 3508 8 - SHA256 [FIPS180] "SHA256" 3509 9 - SHA384 [FIPS180] "SHA384" 3510 10 - SHA512 [FIPS180] "SHA512" 3511 11 - SHA224 [FIPS180] "SHA224" 3512 100 to 110 - Private/Experimental algorithm 3513 3514 Implementations MUST implement SHA-1. Implementations MAY implement 3515 other algorithms. MD5 is deprecated. 3516 351710. IANA Considerations 3518 3519 OpenPGP is highly parameterized, and consequently there are a number 3520 of considerations for allocating parameters for extensions. This 3521 section describes how IANA should look at extensions to the protocol 3522 as described in this document. 3523 3524 3525 3526 3527 3528 3529 3530Callas, et al Standards Track [Page 63] 3531 3532RFC 4880 OpenPGP Message Format November 2007 3533 3534 353510.1. New String-to-Key Specifier Types 3536 3537 OpenPGP S2K specifiers contain a mechanism for new algorithms to turn 3538 a string into a key. This specification creates a registry of S2K 3539 specifier types. The registry includes the S2K type, the name of the 3540 S2K, and a reference to the defining specification. The initial 3541 values for this registry can be found in Section 3.7.1. Adding a new 3542 S2K specifier MUST be done through the IETF CONSENSUS method, as 3543 described in [RFC2434]. 3544 354510.2. New Packets 3546 3547 Major new features of OpenPGP are defined through new packet types. 3548 This specification creates a registry of packet types. The registry 3549 includes the packet type, the name of the packet, and a reference to 3550 the defining specification. The initial values for this registry can 3551 be found in Section 4.3. Adding a new packet type MUST be done 3552 through the IETF CONSENSUS method, as described in [RFC2434]. 3553 355410.2.1. User Attribute Types 3555 3556 The User Attribute packet permits an extensible mechanism for other 3557 types of certificate identification. This specification creates a 3558 registry of User Attribute types. The registry includes the User 3559 Attribute type, the name of the User Attribute, and a reference to 3560 the defining specification. The initial values for this registry can 3561 be found in Section 5.12. Adding a new User Attribute type MUST be 3562 done through the IETF CONSENSUS method, as described in [RFC2434]. 3563 356410.2.1.1. Image Format Subpacket Types 3565 3566 Within User Attribute packets, there is an extensible mechanism for 3567 other types of image-based user attributes. This specification 3568 creates a registry of Image Attribute subpacket types. The registry 3569 includes the Image Attribute subpacket type, the name of the Image 3570 Attribute subpacket, and a reference to the defining specification. 3571 The initial values for this registry can be found in Section 5.12.1. 3572 Adding a new Image Attribute subpacket type MUST be done through the 3573 IETF CONSENSUS method, as described in [RFC2434]. 3574 357510.2.2. New Signature Subpackets 3576 3577 OpenPGP signatures contain a mechanism for signed (or unsigned) data 3578 to be added to them for a variety of purposes in the Signature 3579 subpackets as discussed in Section 5.2.3.1. This specification 3580 creates a registry of Signature subpacket types. The registry 3581 includes the Signature subpacket type, the name of the subpacket, and 3582 a reference to the defining specification. The initial values for 3583 3584 3585 3586Callas, et al Standards Track [Page 64] 3587 3588RFC 4880 OpenPGP Message Format November 2007 3589 3590 3591 this registry can be found in Section 5.2.3.1. Adding a new 3592 Signature subpacket MUST be done through the IETF CONSENSUS method, 3593 as described in [RFC2434]. 3594 359510.2.2.1. Signature Notation Data Subpackets 3596 3597 OpenPGP signatures further contain a mechanism for extensions in 3598 signatures. These are the Notation Data subpackets, which contain a 3599 key/value pair. Notations contain a user space that is completely 3600 unmanaged and an IETF space. 3601 3602 This specification creates a registry of Signature Notation Data 3603 types. The registry includes the Signature Notation Data type, the 3604 name of the Signature Notation Data, its allowed values, and a 3605 reference to the defining specification. The initial values for this 3606 registry can be found in Section 5.2.3.16. Adding a new Signature 3607 Notation Data subpacket MUST be done through the EXPERT REVIEW 3608 method, as described in [RFC2434]. 3609 361010.2.2.2. Key Server Preference Extensions 3611 3612 OpenPGP signatures contain a mechanism for preferences to be 3613 specified about key servers. This specification creates a registry 3614 of key server preferences. The registry includes the key server 3615 preference, the name of the preference, and a reference to the 3616 defining specification. The initial values for this registry can be 3617 found in Section 5.2.3.17. Adding a new key server preference MUST 3618 be done through the IETF CONSENSUS method, as described in [RFC2434]. 3619 362010.2.2.3. Key Flags Extensions 3621 3622 OpenPGP signatures contain a mechanism for flags to be specified 3623 about key usage. This specification creates a registry of key usage 3624 flags. The registry includes the key flags value, the name of the 3625 flag, and a reference to the defining specification. The initial 3626 values for this registry can be found in Section 5.2.3.21. Adding a 3627 new key usage flag MUST be done through the IETF CONSENSUS method, as 3628 described in [RFC2434]. 3629 363010.2.2.4. Reason for Revocation Extensions 3631 3632 OpenPGP signatures contain a mechanism for flags to be specified 3633 about why a key was revoked. This specification creates a registry 3634 of "Reason for Revocation" flags. The registry includes the "Reason 3635 for Revocation" flags value, the name of the flag, and a reference to 3636 the defining specification. The initial values for this registry can 3637 be found in Section 5.2.3.23. Adding a new feature flag MUST be done 3638 through the IETF CONSENSUS method, as described in [RFC2434]. 3639 3640 3641 3642Callas, et al Standards Track [Page 65] 3643 3644RFC 4880 OpenPGP Message Format November 2007 3645 3646 364710.2.2.5. Implementation Features 3648 3649 OpenPGP signatures contain a mechanism for flags to be specified 3650 stating which optional features an implementation supports. This 3651 specification creates a registry of feature-implementation flags. 3652 The registry includes the feature-implementation flags value, the 3653 name of the flag, and a reference to the defining specification. The 3654 initial values for this registry can be found in Section 5.2.3.24. 3655 Adding a new feature-implementation flag MUST be done through the 3656 IETF CONSENSUS method, as described in [RFC2434]. 3657 3658 Also see Section 13.12 for more information about when feature flags 3659 are needed. 3660 366110.2.3. New Packet Versions 3662 3663 The core OpenPGP packets all have version numbers, and can be revised 3664 by introducing a new version of an existing packet. This 3665 specification creates a registry of packet types. The registry 3666 includes the packet type, the number of the version, and a reference 3667 to the defining specification. The initial values for this registry 3668 can be found in Section 5. Adding a new packet version MUST be done 3669 through the IETF CONSENSUS method, as described in [RFC2434]. 3670 367110.3. New Algorithms 3672 3673 Section 9 lists the core algorithms that OpenPGP uses. Adding in a 3674 new algorithm is usually simple. For example, adding in a new 3675 symmetric cipher usually would not need anything more than allocating 3676 a constant for that cipher. If that cipher had other than a 64-bit 3677 or 128-bit block size, there might need to be additional 3678 documentation describing how OpenPGP-CFB mode would be adjusted. 3679 Similarly, when DSA was expanded from a maximum of 1024-bit public 3680 keys to 3072-bit public keys, the revision of FIPS 186 contained 3681 enough information itself to allow implementation. Changes to this 3682 document were made mainly for emphasis. 3683 368410.3.1. Public-Key Algorithms 3685 3686 OpenPGP specifies a number of public-key algorithms. This 3687 specification creates a registry of public-key algorithm identifiers. 3688 The registry includes the algorithm name, its key sizes and 3689 parameters, and a reference to the defining specification. The 3690 initial values for this registry can be found in Section 9. Adding a 3691 new public-key algorithm MUST be done through the IETF CONSENSUS 3692 method, as described in [RFC2434]. 3693 3694 3695 3696 3697 3698Callas, et al Standards Track [Page 66] 3699 3700RFC 4880 OpenPGP Message Format November 2007 3701 3702 370310.3.2. Symmetric-Key Algorithms 3704 3705 OpenPGP specifies a number of symmetric-key algorithms. This 3706 specification creates a registry of symmetric-key algorithm 3707 identifiers. The registry includes the algorithm name, its key sizes 3708 and block size, and a reference to the defining specification. The 3709 initial values for this registry can be found in Section 9. Adding a 3710 new symmetric-key algorithm MUST be done through the IETF CONSENSUS 3711 method, as described in [RFC2434]. 3712 371310.3.3. Hash Algorithms 3714 3715 OpenPGP specifies a number of hash algorithms. This specification 3716 creates a registry of hash algorithm identifiers. The registry 3717 includes the algorithm name, a text representation of that name, its 3718 block size, an OID hash prefix, and a reference to the defining 3719 specification. The initial values for this registry can be found in 3720 Section 9 for the algorithm identifiers and text names, and Section 3721 5.2.2 for the OIDs and expanded signature prefixes. Adding a new 3722 hash algorithm MUST be done through the IETF CONSENSUS method, as 3723 described in [RFC2434]. 3724 372510.3.4. Compression Algorithms 3726 3727 OpenPGP specifies a number of compression algorithms. This 3728 specification creates a registry of compression algorithm 3729 identifiers. The registry includes the algorithm name and a 3730 reference to the defining specification. The initial values for this 3731 registry can be found in Section 9.3. Adding a new compression key 3732 algorithm MUST be done through the IETF CONSENSUS method, as 3733 described in [RFC2434]. 3734 373511. Packet Composition 3736 3737 OpenPGP packets are assembled into sequences in order to create 3738 messages and to transfer keys. Not all possible packet sequences are 3739 meaningful and correct. This section describes the rules for how 3740 packets should be placed into sequences. 3741 374211.1. Transferable Public Keys 3743 3744 OpenPGP users may transfer public keys. The essential elements of a 3745 transferable public key are as follows: 3746 3747 - One Public-Key packet 3748 3749 - Zero or more revocation signatures 3750 3751 3752 3753 3754Callas, et al Standards Track [Page 67] 3755 3756RFC 4880 OpenPGP Message Format November 2007 3757 3758 3759 - One or more User ID packets 3760 3761 - After each User ID packet, zero or more Signature packets 3762 (certifications) 3763 3764 - Zero or more User Attribute packets 3765 3766 - After each User Attribute packet, zero or more Signature packets 3767 (certifications) 3768 3769 - Zero or more Subkey packets 3770 3771 - After each Subkey packet, one Signature packet, plus optionally a 3772 revocation 3773 3774 The Public-Key packet occurs first. Each of the following User ID 3775 packets provides the identity of the owner of this public key. If 3776 there are multiple User ID packets, this corresponds to multiple 3777 means of identifying the same unique individual user; for example, a 3778 user may have more than one email address, and construct a User ID 3779 for each one. 3780 3781 Immediately following each User ID packet, there are zero or more 3782 Signature packets. Each Signature packet is calculated on the 3783 immediately preceding User ID packet and the initial Public-Key 3784 packet. The signature serves to certify the corresponding public key 3785 and User ID. In effect, the signer is testifying to his or her 3786 belief that this public key belongs to the user identified by this 3787 User ID. 3788 3789 Within the same section as the User ID packets, there are zero or 3790 more User Attribute packets. Like the User ID packets, a User 3791 Attribute packet is followed by zero or more Signature packets 3792 calculated on the immediately preceding User Attribute packet and the 3793 initial Public-Key packet. 3794 3795 User Attribute packets and User ID packets may be freely intermixed 3796 in this section, so long as the signatures that follow them are 3797 maintained on the proper User Attribute or User ID packet. 3798 3799 After the User ID packet or Attribute packet, there may be zero or 3800 more Subkey packets. In general, subkeys are provided in cases where 3801 the top-level public key is a signature-only key. However, any V4 3802 key may have subkeys, and the subkeys may be encryption-only keys, 3803 signature-only keys, or general-purpose keys. V3 keys MUST NOT have 3804 subkeys. 3805 3806 3807 3808 3809 3810Callas, et al Standards Track [Page 68] 3811 3812RFC 4880 OpenPGP Message Format November 2007 3813 3814 3815 Each Subkey packet MUST be followed by one Signature packet, which 3816 should be a subkey binding signature issued by the top-level key. 3817 For subkeys that can issue signatures, the subkey binding signature 3818 MUST contain an Embedded Signature subpacket with a primary key 3819 binding signature (0x19) issued by the subkey on the top-level key. 3820 3821 Subkey and Key packets may each be followed by a revocation Signature 3822 packet to indicate that the key is revoked. Revocation signatures 3823 are only accepted if they are issued by the key itself, or by a key 3824 that is authorized to issue revocations via a Revocation Key 3825 subpacket in a self-signature by the top-level key. 3826 3827 Transferable public-key packet sequences may be concatenated to allow 3828 transferring multiple public keys in one operation. 3829 383011.2. Transferable Secret Keys 3831 3832 OpenPGP users may transfer secret keys. The format of a transferable 3833 secret key is the same as a transferable public key except that 3834 secret-key and secret-subkey packets are used instead of the public 3835 key and public-subkey packets. Implementations SHOULD include self- 3836 signatures on any user IDs and subkeys, as this allows for a complete 3837 public key to be automatically extracted from the transferable secret 3838 key. Implementations MAY choose to omit the self-signatures, 3839 especially if a transferable public key accompanies the transferable 3840 secret key. 3841 384211.3. OpenPGP Messages 3843 3844 An OpenPGP message is a packet or sequence of packets that 3845 corresponds to the following grammatical rules (comma represents 3846 sequential composition, and vertical bar separates alternatives): 3847 3848 OpenPGP Message :- Encrypted Message | Signed Message | 3849 Compressed Message | Literal Message. 3850 3851 Compressed Message :- Compressed Data Packet. 3852 3853 Literal Message :- Literal Data Packet. 3854 3855 ESK :- Public-Key Encrypted Session Key Packet | 3856 Symmetric-Key Encrypted Session Key Packet. 3857 3858 ESK Sequence :- ESK | ESK Sequence, ESK. 3859 3860 Encrypted Data :- Symmetrically Encrypted Data Packet | 3861 Symmetrically Encrypted Integrity Protected Data Packet 3862 3863 3864 3865 3866Callas, et al Standards Track [Page 69] 3867 3868RFC 4880 OpenPGP Message Format November 2007 3869 3870 3871 Encrypted Message :- Encrypted Data | ESK Sequence, Encrypted Data. 3872 3873 One-Pass Signed Message :- One-Pass Signature Packet, 3874 OpenPGP Message, Corresponding Signature Packet. 3875 3876 Signed Message :- Signature Packet, OpenPGP Message | 3877 One-Pass Signed Message. 3878 3879 In addition, decrypting a Symmetrically Encrypted Data packet or a 3880 Symmetrically Encrypted Integrity Protected Data packet as well as 3881 decompressing a Compressed Data packet must yield a valid OpenPGP 3882 Message. 3883 388411.4. Detached Signatures 3885 3886 Some OpenPGP applications use so-called "detached signatures". For 3887 example, a program bundle may contain a file, and with it a second 3888 file that is a detached signature of the first file. These detached 3889 signatures are simply a Signature packet stored separately from the 3890 data for which they are a signature. 3891 389212. Enhanced Key Formats 3893 389412.1. Key Structures 3895 3896 The format of an OpenPGP V3 key is as follows. Entries in square 3897 brackets are optional and ellipses indicate repetition. 3898 3899 RSA Public Key 3900 [Revocation Self Signature] 3901 User ID [Signature ...] 3902 [User ID [Signature ...] ...] 3903 3904 Each signature certifies the RSA public key and the preceding User 3905 ID. The RSA public key can have many User IDs and each User ID can 3906 have many signatures. V3 keys are deprecated. Implementations MUST 3907 NOT generate new V3 keys, but MAY continue to use existing ones. 3908 3909 The format of an OpenPGP V4 key that uses multiple public keys is 3910 similar except that the other keys are added to the end as "subkeys" 3911 of the primary key. 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922Callas, et al Standards Track [Page 70] 3923 3924RFC 4880 OpenPGP Message Format November 2007 3925 3926 3927 Primary-Key 3928 [Revocation Self Signature] 3929 [Direct Key Signature...] 3930 User ID [Signature ...] 3931 [User ID [Signature ...] ...] 3932 [User Attribute [Signature ...] ...] 3933 [[Subkey [Binding-Signature-Revocation] 3934 Primary-Key-Binding-Signature] ...] 3935 3936 A subkey always has a single signature after it that is issued using 3937 the primary key to tie the two keys together. This binding signature 3938 may be in either V3 or V4 format, but SHOULD be V4. Subkeys that can 3939 issue signatures MUST have a V4 binding signature due to the REQUIRED 3940 embedded primary key binding signature. 3941 3942 In the above diagram, if the binding signature of a subkey has been 3943 revoked, the revoked key may be removed, leaving only one key. 3944 3945 In a V4 key, the primary key MUST be a key capable of certification. 3946 The subkeys may be keys of any other type. There may be other 3947 constructions of V4 keys, too. For example, there may be a single- 3948 key RSA key in V4 format, a DSA primary key with an RSA encryption 3949 key, or RSA primary key with an Elgamal subkey, etc. 3950 3951 It is also possible to have a signature-only subkey. This permits a 3952 primary key that collects certifications (key signatures), but is 3953 used only for certifying subkeys that are used for encryption and 3954 signatures. 3955 395612.2. Key IDs and Fingerprints 3957 3958 For a V3 key, the eight-octet Key ID consists of the low 64 bits of 3959 the public modulus of the RSA key. 3960 3961 The fingerprint of a V3 key is formed by hashing the body (but not 3962 the two-octet length) of the MPIs that form the key material (public 3963 modulus n, followed by exponent e) with MD5. Note that both V3 keys 3964 and MD5 are deprecated. 3965 3966 A V4 fingerprint is the 160-bit SHA-1 hash of the octet 0x99, 3967 followed by the two-octet packet length, followed by the entire 3968 Public-Key packet starting with the version field. The Key ID is the 3969 low-order 64 bits of the fingerprint. Here are the fields of the 3970 hash material, with the example of a DSA key: 3971 3972 a.1) 0x99 (1 octet) 3973 3974 a.2) high-order length octet of (b)-(e) (1 octet) 3975 3976 3977 3978Callas, et al Standards Track [Page 71] 3979 3980RFC 4880 OpenPGP Message Format November 2007 3981 3982 3983 a.3) low-order length octet of (b)-(e) (1 octet) 3984 3985 b) version number = 4 (1 octet); 3986 3987 c) timestamp of key creation (4 octets); 3988 3989 d) algorithm (1 octet): 17 = DSA (example); 3990 3991 e) Algorithm-specific fields. 3992 3993 Algorithm-Specific Fields for DSA keys (example): 3994 3995 e.1) MPI of DSA prime p; 3996 3997 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 3998 3999 e.3) MPI of DSA group generator g; 4000 4001 e.4) MPI of DSA public-key value y (= g**x mod p where x is secret). 4002 4003 Note that it is possible for there to be collisions of Key IDs -- two 4004 different keys with the same Key ID. Note that there is a much 4005 smaller, but still non-zero, probability that two different keys have 4006 the same fingerprint. 4007 4008 Also note that if V3 and V4 format keys share the same RSA key 4009 material, they will have different Key IDs as well as different 4010 fingerprints. 4011 4012 Finally, the Key ID and fingerprint of a subkey are calculated in the 4013 same way as for a primary key, including the 0x99 as the first octet 4014 (even though this is not a valid packet ID for a public subkey). 4015 401613. Notes on Algorithms 4017 401813.1. PKCS#1 Encoding in OpenPGP 4019 4020 This standard makes use of the PKCS#1 functions EME-PKCS1-v1_5 and 4021 EMSA-PKCS1-v1_5. However, the calling conventions of these functions 4022 has changed in the past. To avoid potential confusion and 4023 interoperability problems, we are including local copies in this 4024 document, adapted from those in PKCS#1 v2.1 [RFC3447]. RFC 3447 4025 should be treated as the ultimate authority on PKCS#1 for OpenPGP. 4026 Nonetheless, we believe that there is value in having a self- 4027 contained document that avoids problems in the future with needed 4028 changes in the conventions. 4029 4030 4031 4032 4033 4034Callas, et al Standards Track [Page 72] 4035 4036RFC 4880 OpenPGP Message Format November 2007 4037 4038 403913.1.1. EME-PKCS1-v1_5-ENCODE 4040 4041 Input: 4042 4043 k = the length in octets of the key modulus 4044 4045 M = message to be encoded, an octet string of length mLen, where 4046 mLen <= k - 11 4047 4048 Output: 4049 4050 EM = encoded message, an octet string of length k 4051 4052 Error: "message too long" 4053 4054 1. Length checking: If mLen > k - 11, output "message too long" and 4055 stop. 4056 4057 2. Generate an octet string PS of length k - mLen - 3 consisting of 4058 pseudo-randomly generated nonzero octets. The length of PS will 4059 be at least eight octets. 4060 4061 3. Concatenate PS, the message M, and other padding to form an 4062 encoded message EM of length k octets as 4063 4064 EM = 0x00 || 0x02 || PS || 0x00 || M. 4065 4066 4. Output EM. 4067 406813.1.2. EME-PKCS1-v1_5-DECODE 4069 4070 Input: 4071 4072 EM = encoded message, an octet string 4073 4074 Output: 4075 4076 M = message, an octet string 4077 4078 Error: "decryption error" 4079 4080 To decode an EME-PKCS1_v1_5 message, separate the encoded message EM 4081 into an octet string PS consisting of nonzero octets and a message M 4082 as follows 4083 4084 EM = 0x00 || 0x02 || PS || 0x00 || M. 4085 4086 4087 4088 4089 4090Callas, et al Standards Track [Page 73] 4091 4092RFC 4880 OpenPGP Message Format November 2007 4093 4094 4095 If the first octet of EM does not have hexadecimal value 0x00, if the 4096 second octet of EM does not have hexadecimal value 0x02, if there is 4097 no octet with hexadecimal value 0x00 to separate PS from M, or if the 4098 length of PS is less than 8 octets, output "decryption error" and 4099 stop. See also the security note in Section 14 regarding differences 4100 in reporting between a decryption error and a padding error. 4101 410213.1.3. EMSA-PKCS1-v1_5 4103 4104 This encoding method is deterministic and only has an encoding 4105 operation. 4106 4107 Option: 4108 4109 Hash - a hash function in which hLen denotes the length in octets of 4110 the hash function output 4111 4112 Input: 4113 4114 M = message to be encoded 4115 4116 mL = intended length in octets of the encoded message, at least tLen 4117 + 11, where tLen is the octet length of the DER encoding T of a 4118 certain value computed during the encoding operation 4119 4120 Output: 4121 4122 EM = encoded message, an octet string of length emLen 4123 4124 Errors: "message too long"; "intended encoded message length too 4125 short" 4126 4127 Steps: 4128 4129 1. Apply the hash function to the message M to produce a hash value 4130 H: 4131 4132 H = Hash(M). 4133 4134 If the hash function outputs "message too long," output "message 4135 too long" and stop. 4136 4137 2. Using the list in Section 5.2.2, produce an ASN.1 DER value for 4138 the hash function used. Let T be the full hash prefix from 4139 Section 5.2.2, and let tLen be the length in octets of T. 4140 4141 3. If emLen < tLen + 11, output "intended encoded message length 4142 too short" and stop. 4143 4144 4145 4146Callas, et al Standards Track [Page 74] 4147 4148RFC 4880 OpenPGP Message Format November 2007 4149 4150 4151 4. Generate an octet string PS consisting of emLen - tLen - 3 4152 octets with hexadecimal value 0xFF. The length of PS will be at 4153 least 8 octets. 4154 4155 5. Concatenate PS, the hash prefix T, and other padding to form the 4156 encoded message EM as 4157 4158 EM = 0x00 || 0x01 || PS || 0x00 || T. 4159 4160 6. Output EM. 4161 416213.2. Symmetric Algorithm Preferences 4163 4164 The symmetric algorithm preference is an ordered list of algorithms 4165 that the keyholder accepts. Since it is found on a self-signature, 4166 it is possible that a keyholder may have multiple, different 4167 preferences. For example, Alice may have TripleDES only specified 4168 for "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 4169 "alice@home.org". Note that it is also possible for preferences to 4170 be in a subkey's binding signature. 4171 4172 Since TripleDES is the MUST-implement algorithm, if it is not 4173 explicitly in the list, it is tacitly at the end. However, it is 4174 good form to place it there explicitly. Note also that if an 4175 implementation does not implement the preference, then it is 4176 implicitly a TripleDES-only implementation. 4177 4178 An implementation MUST NOT use a symmetric algorithm that is not in 4179 the recipient's preference list. When encrypting to more than one 4180 recipient, the implementation finds a suitable algorithm by taking 4181 the intersection of the preferences of the recipients. Note that the 4182 MUST-implement algorithm, TripleDES, ensures that the intersection is 4183 not null. The implementation may use any mechanism to pick an 4184 algorithm in the intersection. 4185 4186 If an implementation can decrypt a message that a keyholder doesn't 4187 have in their preferences, the implementation SHOULD decrypt the 4188 message anyway, but MUST warn the keyholder that the protocol has 4189 been violated. For example, suppose that Alice, above, has software 4190 that implements all algorithms in this specification. Nonetheless, 4191 she prefers subsets for work or home. If she is sent a message 4192 encrypted with IDEA, which is not in her preferences, the software 4193 warns her that someone sent her an IDEA-encrypted message, but it 4194 would ideally decrypt it anyway. 4195 4196 4197 4198 4199 4200 4201 4202Callas, et al Standards Track [Page 75] 4203 4204RFC 4880 OpenPGP Message Format November 2007 4205 4206 420713.3. Other Algorithm Preferences 4208 4209 Other algorithm preferences work similarly to the symmetric algorithm 4210 preference, in that they specify which algorithms the keyholder 4211 accepts. There are two interesting cases that other comments need to 4212 be made about, though, the compression preferences and the hash 4213 preferences. 4214 421513.3.1. Compression Preferences 4216 4217 Compression has been an integral part of PGP since its first days. 4218 OpenPGP and all previous versions of PGP have offered compression. 4219 In this specification, the default is for messages to be compressed, 4220 although an implementation is not required to do so. Consequently, 4221 the compression preference gives a way for a keyholder to request 4222 that messages not be compressed, presumably because they are using a 4223 minimal implementation that does not include compression. 4224 Additionally, this gives a keyholder a way to state that it can 4225 support alternate algorithms. 4226 4227 Like the algorithm preferences, an implementation MUST NOT use an 4228 algorithm that is not in the preference vector. If the preferences 4229 are not present, then they are assumed to be [ZIP(1), 4230 Uncompressed(0)]. 4231 4232 Additionally, an implementation MUST implement this preference to the 4233 degree of recognizing when to send an uncompressed message. A robust 4234 implementation would satisfy this requirement by looking at the 4235 recipient's preference and acting accordingly. A minimal 4236 implementation can satisfy this requirement by never generating a 4237 compressed message, since all implementations can handle messages 4238 that have not been compressed. 4239 424013.3.2. Hash Algorithm Preferences 4241 4242 Typically, the choice of a hash algorithm is something the signer 4243 does, rather than the verifier, because a signer rarely knows who is 4244 going to be verifying the signature. This preference, though, allows 4245 a protocol based upon digital signatures ease in negotiation. 4246 4247 Thus, if Alice is authenticating herself to Bob with a signature, it 4248 makes sense for her to use a hash algorithm that Bob's software uses. 4249 This preference allows Bob to state in his key which algorithms Alice 4250 may use. 4251 4252 Since SHA1 is the MUST-implement hash algorithm, if it is not 4253 explicitly in the list, it is tacitly at the end. However, it is 4254 good form to place it there explicitly. 4255 4256 4257 4258Callas, et al Standards Track [Page 76] 4259 4260RFC 4880 OpenPGP Message Format November 2007 4261 4262 426313.4. Plaintext 4264 4265 Algorithm 0, "plaintext", may only be used to denote secret keys that 4266 are stored in the clear. Implementations MUST NOT use plaintext in 4267 Symmetrically Encrypted Data packets; they must use Literal Data 4268 packets to encode unencrypted or literal data. 4269 427013.5. RSA 4271 4272 There are algorithm types for RSA Sign-Only, and RSA Encrypt-Only 4273 keys. These types are deprecated. The "key flags" subpacket in a 4274 signature is a much better way to express the same idea, and 4275 generalizes it to all algorithms. An implementation SHOULD NOT 4276 create such a key, but MAY interpret it. 4277 4278 An implementation SHOULD NOT implement RSA keys of size less than 4279 1024 bits. 4280 428113.6. DSA 4282 4283 An implementation SHOULD NOT implement DSA keys of size less than 4284 1024 bits. It MUST NOT implement a DSA key with a q size of less 4285 than 160 bits. DSA keys MUST also be a multiple of 64 bits, and the 4286 q size MUST be a multiple of 8 bits. The Digital Signature Standard 4287 (DSS) [FIPS186] specifies that DSA be used in one of the following 4288 ways: 4289 4290 * 1024-bit key, 160-bit q, SHA-1, SHA-224, SHA-256, SHA-384, or 4291 SHA-512 hash 4292 4293 * 2048-bit key, 224-bit q, SHA-224, SHA-256, SHA-384, or SHA-512 4294 hash 4295 4296 * 2048-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash 4297 4298 * 3072-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash 4299 4300 The above key and q size pairs were chosen to best balance the 4301 strength of the key with the strength of the hash. Implementations 4302 SHOULD use one of the above key and q size pairs when generating DSA 4303 keys. If DSS compliance is desired, one of the specified SHA hashes 4304 must be used as well. [FIPS186] is the ultimate authority on DSS, 4305 and should be consulted for all questions of DSS compliance. 4306 4307 Note that earlier versions of this standard only allowed a 160-bit q 4308 with no truncation allowed, so earlier implementations may not be 4309 able to handle signatures with a different q size or a truncated 4310 hash. 4311 4312 4313 4314Callas, et al Standards Track [Page 77] 4315 4316RFC 4880 OpenPGP Message Format November 2007 4317 4318 431913.7. Elgamal 4320 4321 An implementation SHOULD NOT implement Elgamal keys of size less than 4322 1024 bits. 4323 432413.8. Reserved Algorithm Numbers 4325 4326 A number of algorithm IDs have been reserved for algorithms that 4327 would be useful to use in an OpenPGP implementation, yet there are 4328 issues that prevent an implementer from actually implementing the 4329 algorithm. These are marked in Section 9.1, "Public-Key Algorithms", 4330 as "reserved for". 4331 4332 The reserved public-key algorithms, Elliptic Curve (18), ECDSA (19), 4333 and X9.42 (21), do not have the necessary parameters, parameter 4334 order, or semantics defined. 4335 4336 Previous versions of OpenPGP permitted Elgamal [ELGAMAL] signatures 4337 with a public-key identifier of 20. These are no longer permitted. 4338 An implementation MUST NOT generate such keys. An implementation 4339 MUST NOT generate Elgamal signatures. See [BLEICHENBACHER]. 4340 434113.9. OpenPGP CFB Mode 4342 4343 OpenPGP does symmetric encryption using a variant of Cipher Feedback 4344 mode (CFB mode). This section describes the procedure it uses in 4345 detail. This mode is what is used for Symmetrically Encrypted Data 4346 Packets; the mechanism used for encrypting secret-key material is 4347 similar, and is described in the sections above. 4348 4349 In the description below, the value BS is the block size in octets of 4350 the cipher. Most ciphers have a block size of 8 octets. The AES and 4351 Twofish have a block size of 16 octets. Also note that the 4352 description below assumes that the IV and CFB arrays start with an 4353 index of 1 (unlike the C language, which assumes arrays start with a 4354 zero index). 4355 4356 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and 4357 prefixes the plaintext with BS+2 octets of random data, such that 4358 octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB 4359 resynchronization after encrypting those BS+2 octets. 4360 4361 Thus, for an algorithm that has a block size of 8 octets (64 bits), 4362 the IV is 10 octets long and octets 7 and 8 of the IV are the same as 4363 octets 9 and 10. For an algorithm with a block size of 16 octets 4364 (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate 4365 octets 15 and 16. Those extra two octets are an easy check for a 4366 correct key. 4367 4368 4369 4370Callas, et al Standards Track [Page 78] 4371 4372RFC 4880 OpenPGP Message Format November 2007 4373 4374 4375 Step by step, here is the procedure: 4376 4377 1. The feedback register (FR) is set to the IV, which is all zeros. 4378 4379 2. FR is encrypted to produce FRE (FR Encrypted). This is the 4380 encryption of an all-zero value. 4381 4382 3. FRE is xored with the first BS octets of random data prefixed to 4383 the plaintext to produce C[1] through C[BS], the first BS octets 4384 of ciphertext. 4385 4386 4. FR is loaded with C[1] through C[BS]. 4387 4388 5. FR is encrypted to produce FRE, the encryption of the first BS 4389 octets of ciphertext. 4390 4391 6. The left two octets of FRE get xored with the next two octets of 4392 data that were prefixed to the plaintext. This produces C[BS+1] 4393 and C[BS+2], the next two octets of ciphertext. 4394 4395 7. (The resynchronization step) FR is loaded with C[3] through 4396 C[BS+2]. 4397 4398 8. FR is encrypted to produce FRE. 4399 4400 9. FRE is xored with the first BS octets of the given plaintext, now 4401 that we have finished encrypting the BS+2 octets of prefixed 4402 data. This produces C[BS+3] through C[BS+(BS+2)], the next BS 4403 octets of ciphertext. 4404 4405 10. FR is loaded with C[BS+3] to C[BS + (BS+2)] (which is C11-C18 for 4406 an 8-octet block). 4407 4408 11. FR is encrypted to produce FRE. 4409 4410 12. FRE is xored with the next BS octets of plaintext, to produce 4411 the next BS octets of ciphertext. These are loaded into FR, and 4412 the process is repeated until the plaintext is used up. 4413 441413.10. Private or Experimental Parameters 4415 4416 S2K specifiers, Signature subpacket types, user attribute types, 4417 image format types, and algorithms described in Section 9 all reserve 4418 the range 100 to 110 for private and experimental use. Packet types 4419 reserve the range 60 to 63 for private and experimental use. These 4420 are intentionally managed with the PRIVATE USE method, as described 4421 in [RFC2434]. 4422 4423 4424 4425 4426Callas, et al Standards Track [Page 79] 4427 4428RFC 4880 OpenPGP Message Format November 2007 4429 4430 4431 However, implementations need to be careful with these and promote 4432 them to full IANA-managed parameters when they grow beyond the 4433 original, limited system. 4434 443513.11. Extension of the MDC System 4436 4437 As described in the non-normative explanation in Section 5.13, the 4438 MDC system is uniquely unparameterized in OpenPGP. This was an 4439 intentional decision to avoid cross-grade attacks. If the MDC system 4440 is extended to a stronger hash function, care must be taken to avoid 4441 downgrade and cross-grade attacks. 4442 4443 One simple way to do this is to create new packets for a new MDC. 4444 For example, instead of the MDC system using packets 18 and 19, a new 4445 MDC could use 20 and 21. This has obvious drawbacks (it uses two 4446 packet numbers for each new hash function in a space that is limited 4447 to a maximum of 60). 4448 4449 Another simple way to extend the MDC system is to create new versions 4450 of packet 18, and reflect this in packet 19. For example, suppose 4451 that V2 of packet 18 implicitly used SHA-256. This would require 4452 packet 19 to have a length of 32 octets. The change in the version 4453 in packet 18 and the size of packet 19 prevent a downgrade attack. 4454 4455 There are two drawbacks to this latter approach. The first is that 4456 using the version number of a packet to carry algorithm information 4457 is not tidy from a protocol-design standpoint. It is possible that 4458 there might be several versions of the MDC system in common use, but 4459 this untidiness would reflect untidiness in cryptographic consensus 4460 about hash function security. The second is that different versions 4461 of packet 19 would have to have unique sizes. If there were two 4462 versions each with 256-bit hashes, they could not both have 32-octet 4463 packet 19s without admitting the chance of a cross-grade attack. 4464 4465 Yet another, complex approach to extend the MDC system would be a 4466 hybrid of the two above -- create a new pair of MDC packets that are 4467 fully parameterized, and yet protected from downgrade and cross- 4468 grade. 4469 4470 Any change to the MDC system MUST be done through the IETF CONSENSUS 4471 method, as described in [RFC2434]. 4472 447313.12. Meta-Considerations for Expansion 4474 4475 If OpenPGP is extended in a way that is not backwards-compatible, 4476 meaning that old implementations will not gracefully handle their 4477 4478 4479 4480 4481 4482Callas, et al Standards Track [Page 80] 4483 4484RFC 4880 OpenPGP Message Format November 2007 4485 4486 4487 absence of a new feature, the extension proposal can be declared in 4488 the key holder's self-signature as part of the Features signature 4489 subpacket. 4490 4491 We cannot state definitively what extensions will not be upwards- 4492 compatible, but typically new algorithms are upwards-compatible, 4493 whereas new packets are not. 4494 4495 If an extension proposal does not update the Features system, it 4496 SHOULD include an explanation of why this is unnecessary. If the 4497 proposal contains neither an extension to the Features system nor an 4498 explanation of why such an extension is unnecessary, the proposal 4499 SHOULD be rejected. 4500 450114. Security Considerations 4502 4503 * As with any technology involving cryptography, you should check the 4504 current literature to determine if any algorithms used here have 4505 been found to be vulnerable to attack. 4506 4507 * This specification uses Public-Key Cryptography technologies. It 4508 is assumed that the private key portion of a public-private key 4509 pair is controlled and secured by the proper party or parties. 4510 4511 * Certain operations in this specification involve the use of random 4512 numbers. An appropriate entropy source should be used to generate 4513 these numbers (see [RFC4086]). 4514 4515 * The MD5 hash algorithm has been found to have weaknesses, with 4516 collisions found in a number of cases. MD5 is deprecated for use 4517 in OpenPGP. Implementations MUST NOT generate new signatures using 4518 MD5 as a hash function. They MAY continue to consider old 4519 signatures that used MD5 as valid. 4520 4521 * SHA-224 and SHA-384 require the same work as SHA-256 and SHA-512, 4522 respectively. In general, there are few reasons to use them 4523 outside of DSS compatibility. You need a situation where one needs 4524 more security than smaller hashes, but does not want to have the 4525 full 256-bit or 512-bit data length. 4526 4527 * Many security protocol designers think that it is a bad idea to use 4528 a single key for both privacy (encryption) and integrity 4529 (signatures). In fact, this was one of the motivating forces 4530 behind the V4 key format with separate signature and encryption 4531 keys. If you as an implementer promote dual-use keys, you should 4532 at least be aware of this controversy. 4533 4534 4535 4536 4537 4538Callas, et al Standards Track [Page 81] 4539 4540RFC 4880 OpenPGP Message Format November 2007 4541 4542 4543 * The DSA algorithm will work with any hash, but is sensitive to the 4544 quality of the hash algorithm. Verifiers should be aware that even 4545 if the signer used a strong hash, an attacker could have modified 4546 the signature to use a weak one. Only signatures using acceptably 4547 strong hash algorithms should be accepted as valid. 4548 4549 * As OpenPGP combines many different asymmetric, symmetric, and hash 4550 algorithms, each with different measures of strength, care should 4551 be taken that the weakest element of an OpenPGP message is still 4552 sufficiently strong for the purpose at hand. While consensus about 4553 the strength of a given algorithm may evolve, NIST Special 4554 Publication 800-57 [SP800-57] recommends the following list of 4555 equivalent strengths: 4556 4557 Asymmetric | Hash | Symmetric 4558 key size | size | key size 4559 ------------+--------+----------- 4560 1024 160 80 4561 2048 224 112 4562 3072 256 128 4563 7680 384 192 4564 15360 512 256 4565 4566 * There is a somewhat-related potential security problem in 4567 signatures. If an attacker can find a message that hashes to the 4568 same hash with a different algorithm, a bogus signature structure 4569 can be constructed that evaluates correctly. 4570 4571 For example, suppose Alice DSA signs message M using hash algorithm 4572 H. Suppose that Mallet finds a message M' that has the same hash 4573 value as M with H'. Mallet can then construct a signature block 4574 that verifies as Alice's signature of M' with H'. However, this 4575 would also constitute a weakness in either H or H' or both. Should 4576 this ever occur, a revision will have to be made to this document 4577 to revise the allowed hash algorithms. 4578 4579 * If you are building an authentication system, the recipient may 4580 specify a preferred signing algorithm. However, the signer would 4581 be foolish to use a weak algorithm simply because the recipient 4582 requests it. 4583 4584 * Some of the encryption algorithms mentioned in this document have 4585 been analyzed less than others. For example, although CAST5 is 4586 presently considered strong, it has been analyzed less than 4587 TripleDES. Other algorithms may have other controversies 4588 surrounding them. 4589 4590 4591 4592 4593 4594Callas, et al Standards Track [Page 82] 4595 4596RFC 4880 OpenPGP Message Format November 2007 4597 4598 4599 * In late summer 2002, Jallad, Katz, and Schneier published an 4600 interesting attack on the OpenPGP protocol and some of its 4601 implementations [JKS02]. In this attack, the attacker modifies a 4602 message and sends it to a user who then returns the erroneously 4603 decrypted message to the attacker. The attacker is thus using the 4604 user as a random oracle, and can often decrypt the message. 4605 4606 Compressing data can ameliorate this attack. The incorrectly 4607 decrypted data nearly always decompresses in ways that defeat the 4608 attack. However, this is not a rigorous fix, and leaves open some 4609 small vulnerabilities. For example, if an implementation does not 4610 compress a message before encryption (perhaps because it knows it 4611 was already compressed), then that message is vulnerable. Because 4612 of this happenstance -- that modification attacks can be thwarted 4613 by decompression errors -- an implementation SHOULD treat a 4614 decompression error as a security problem, not merely a data 4615 problem. 4616 4617 This attack can be defeated by the use of Modification Detection, 4618 provided that the implementation does not let the user naively 4619 return the data to the attacker. An implementation MUST treat an 4620 MDC failure as a security problem, not merely a data problem. 4621 4622 In either case, the implementation MAY allow the user access to the 4623 erroneous data, but MUST warn the user as to potential security 4624 problems should that data be returned to the sender. 4625 4626 While this attack is somewhat obscure, requiring a special set of 4627 circumstances to create it, it is nonetheless quite serious as it 4628 permits someone to trick a user to decrypt a message. 4629 Consequently, it is important that: 4630 4631 1. Implementers treat MDC errors and decompression failures as 4632 security problems. 4633 4634 2. Implementers implement Modification Detection with all due 4635 speed and encourage its spread. 4636 4637 3. Users migrate to implementations that support Modification 4638 Detection with all due speed. 4639 4640 * PKCS#1 has been found to be vulnerable to attacks in which a system 4641 that reports errors in padding differently from errors in 4642 decryption becomes a random oracle that can leak the private key in 4643 mere millions of queries. Implementations must be aware of this 4644 attack and prevent it from happening. The simplest solution is to 4645 report a single error code for all variants of decryption errors so 4646 as not to leak information to an attacker. 4647 4648 4649 4650Callas, et al Standards Track [Page 83] 4651 4652RFC 4880 OpenPGP Message Format November 2007 4653 4654 4655 * Some technologies mentioned here may be subject to government 4656 control in some countries. 4657 4658 * In winter 2005, Serge Mister and Robert Zuccherato from Entrust 4659 released a paper describing a way that the "quick check" in OpenPGP 4660 CFB mode can be used with a random oracle to decrypt two octets of 4661 every cipher block [MZ05]. They recommend as prevention not using 4662 the quick check at all. 4663 4664 Many implementers have taken this advice to heart for any data that 4665 is symmetrically encrypted and for which the session key is 4666 public-key encrypted. In this case, the quick check is not needed 4667 as the public-key encryption of the session key should guarantee 4668 that it is the right session key. In other cases, the 4669 implementation should use the quick check with care. 4670 4671 On the one hand, there is a danger to using it if there is a random 4672 oracle that can leak information to an attacker. In plainer 4673 language, there is a danger to using the quick check if timing 4674 information about the check can be exposed to an attacker, 4675 particularly via an automated service that allows rapidly repeated 4676 queries. 4677 4678 On the other hand, it is inconvenient to the user to be informed 4679 that they typed in the wrong passphrase only after a petabyte of 4680 data is decrypted. There are many cases in cryptographic 4681 engineering where the implementer must use care and wisdom, and 4682 this is one. 4683 468415. Implementation Nits 4685 4686 This section is a collection of comments to help an implementer, 4687 particularly with an eye to backward compatibility. Previous 4688 implementations of PGP are not OpenPGP compliant. Often the 4689 differences are small, but small differences are frequently more 4690 vexing than large differences. Thus, this is a non-comprehensive 4691 list of potential problems and gotchas for a developer who is trying 4692 to be backward-compatible. 4693 4694 * The IDEA algorithm is patented, and yet it is required for PGP 4695 2.x interoperability. It is also the de-facto preferred 4696 algorithm for a V3 key with a V3 self-signature (or no self- 4697 signature). 4698 4699 * When exporting a private key, PGP 2.x generates the header "BEGIN 4700 PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY BLOCK". 4701 All previous versions ignore the implied data type, and look 4702 directly at the packet data type. 4703 4704 4705 4706Callas, et al Standards Track [Page 84] 4707 4708RFC 4880 OpenPGP Message Format November 2007 4709 4710 4711 * PGP 2.0 through 2.5 generated V2 Public-Key packets. These are 4712 identical to the deprecated V3 keys except for the version 4713 number. An implementation MUST NOT generate them and may accept 4714 or reject them as it sees fit. Some older PGP versions generated 4715 V2 PKESK packets (Tag 1) as well. An implementation may accept 4716 or reject V2 PKESK packets as it sees fit, and MUST NOT generate 4717 them. 4718 4719 * PGP 2.6.x will not accept key-material packets with versions 4720 greater than 3. 4721 4722 * There are many ways possible for two keys to have the same key 4723 material, but different fingerprints (and thus Key IDs). Perhaps 4724 the most interesting is an RSA key that has been "upgraded" to V4 4725 format, but since a V4 fingerprint is constructed by hashing the 4726 key creation time along with other things, two V4 keys created at 4727 different times, yet with the same key material will have 4728 different fingerprints. 4729 4730 * If an implementation is using zlib to interoperate with PGP 2.x, 4731 then the "windowBits" parameter should be set to -13. 4732 4733 * The 0x19 back signatures were not required for signing subkeys 4734 until relatively recently. Consequently, there may be keys in 4735 the wild that do not have these back signatures. Implementing 4736 software may handle these keys as it sees fit. 4737 4738 * OpenPGP does not put limits on the size of public keys. However, 4739 larger keys are not necessarily better keys. Larger keys take 4740 more computation time to use, and this can quickly become 4741 impractical. Different OpenPGP implementations may also use 4742 different upper bounds for public key sizes, and so care should 4743 be taken when choosing sizes to maintain interoperability. As of 4744 2007 most implementations have an upper bound of 4096 bits. 4745 4746 * ASCII armor is an optional feature of OpenPGP. The OpenPGP 4747 working group strives for a minimal set of mandatory-to-implement 4748 features, and since there could be useful implementations that 4749 only use binary object formats, this is not a "MUST" feature for 4750 an implementation. For example, an implementation that is using 4751 OpenPGP as a mechanism for file signatures may find ASCII armor 4752 unnecessary. OpenPGP permits an implementation to declare what 4753 features it does and does not support, but ASCII armor is not one 4754 of these. Since most implementations allow binary and armored 4755 objects to be used indiscriminately, an implementation that does 4756 not implement ASCII armor may find itself with compatibility 4757 issues with general-purpose implementations. Moreover, 4758 implementations of OpenPGP-MIME [RFC3156] already have a 4759 4760 4761 4762Callas, et al Standards Track [Page 85] 4763 4764RFC 4880 OpenPGP Message Format November 2007 4765 4766 4767 requirement for ASCII armor so those implementations will 4768 necessarily have support. 4769 477016. References 4771 477216.1. Normative References 4773 4774 [AES] NIST, FIPS PUB 197, "Advanced Encryption Standard 4775 (AES)," November 2001. 4776 http://csrc.nist.gov/publications/fips/fips197/fips- 4777 197.{ps,pdf} 4778 4779 [BLOWFISH] Schneier, B. "Description of a New Variable-Length 4780 Key, 64-Bit Block Cipher (Blowfish)" Fast Software 4781 Encryption, Cambridge Security Workshop Proceedings 4782 (December 1993), Springer-Verlag, 1994, pp191-204 4783 <http://www.counterpane.com/bfsverlag.html> 4784 4785 [BZ2] J. Seward, jseward@acm.org, "The Bzip2 and libbzip2 4786 home page" <http://www.bzip.org/> 4787 4788 [ELGAMAL] T. Elgamal, "A Public-Key Cryptosystem and a 4789 Signature Scheme Based on Discrete Logarithms," IEEE 4790 Transactions on Information Theory, v. IT-31, n. 4, 4791 1985, pp. 469-472. 4792 4793 [FIPS180] Secure Hash Signature Standard (SHS) (FIPS PUB 180- 4794 2). 4795 <http://csrc.nist.gov/publications/fips/fips180- 4796 2/fips180-2withchangenotice.pdf> 4797 4798 [FIPS186] Digital Signature Standard (DSS) (FIPS PUB 186-2). 4799 <http://csrc.nist.gov/publications/fips/fips186-2/ 4800 fips186-2-change1.pdf> FIPS 186-3 describes keys 4801 greater than 1024 bits. The latest draft is at: 4802 <http://csrc.nist.gov/publications/drafts/ 4803 fips_186-3/Draft-FIPS-186-3%20_March2006.pdf> 4804 4805 [HAC] Alfred Menezes, Paul van Oorschot, and Scott 4806 Vanstone, "Handbook of Applied Cryptography," CRC 4807 Press, 1996. 4808 <http://www.cacr.math.uwaterloo.ca/hac/> 4809 4810 [IDEA] Lai, X, "On the design and security of block 4811 ciphers", ETH Series in Information Processing, J.L. 4812 Massey (editor), Vol. 1, Hartung-Gorre Verlag 4813 Knostanz, Technische Hochschule (Zurich), 1992 4814 4815 4816 4817 4818Callas, et al Standards Track [Page 86] 4819 4820RFC 4880 OpenPGP Message Format November 2007 4821 4822 4823 [ISO10646] ISO/IEC 10646-1:1993. International Standard -- 4824 Information technology -- Universal Multiple-Octet 4825 Coded Character Set (UCS) -- Part 1: Architecture 4826 and Basic Multilingual Plane. 4827 4828 [JFIF] JPEG File Interchange Format (Version 1.02). Eric 4829 Hamilton, C-Cube Microsystems, Milpitas, CA, 4830 September 1, 1992. 4831 4832 [RFC1950] Deutsch, P. and J-L. Gailly, "ZLIB Compressed Data 4833 Format Specification version 3.3", RFC 1950, May 4834 1996. 4835 4836 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format 4837 Specification version 1.3", RFC 1951, May 1996. 4838 4839 [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet 4840 Mail Extensions (MIME) Part One: Format of Internet 4841 Message Bodies", RFC 2045, November 1996 4842 4843 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 4844 Requirement Levels", BCP 14, RFC 2119, March 1997. 4845 4846 [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC 4847 2144, May 1997. 4848 4849 [RFC2434] Narten, T. and H. Alvestrand, "Guidelines for 4850 Writing an IANA Considerations Section in RFCs", BCP 4851 26, RFC 2434, October 1998. 4852 4853 [RFC2822] Resnick, P., "Internet Message Format", RFC 2822, 4854 April 2001. 4855 4856 [RFC3156] Elkins, M., Del Torto, D., Levien, R., and T. 4857 Roessler, "MIME Security with OpenPGP", RFC 3156, 4858 August 2001. 4859 4860 [RFC3447] Jonsson, J. and B. Kaliski, "Public-Key Cryptography 4861 Standards (PKCS) #1: RSA Cryptography Specifications 4862 Version 2.1", RFC 3447, February 2003. 4863 4864 [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 4865 10646", STD 63, RFC 3629, November 2003. 4866 4867 [RFC4086] Eastlake, D., 3rd, Schiller, J., and S. Crocker, 4868 "Randomness Requirements for Security", BCP 106, RFC 4869 4086, June 2005. 4870 4871 4872 4873 4874Callas, et al Standards Track [Page 87] 4875 4876RFC 4880 OpenPGP Message Format November 2007 4877 4878 4879 [SCHNEIER] Schneier, B., "Applied Cryptography Second Edition: 4880 protocols, algorithms, and source code in C", 1996. 4881 4882 [TWOFISH] B. Schneier, J. Kelsey, D. Whiting, D. Wagner, C. 4883 Hall, and N. Ferguson, "The Twofish Encryption 4884 Algorithm", John Wiley & Sons, 1999. 4885 488616.2. Informative References 4887 4888 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating Elgamal 4889 signatures without knowing the secret key," 4890 Eurocrypt 96. Note that the version in the 4891 proceedings has an error. A revised version is 4892 available at the time of writing from 4893 <ftp://ftp.inf.ethz.ch/pub/publications/papers/ti 4894 /isc/ElGamal.ps> 4895 4896 [JKS02] Kahil Jallad, Jonathan Katz, Bruce Schneier 4897 "Implementation of Chosen-Ciphertext Attacks against 4898 PGP and GnuPG" http://www.counterpane.com/pgp- 4899 attack.html 4900 4901 [MAURER] Ueli Maurer, "Modelling a Public-Key 4902 Infrastructure", Proc. 1996 European Symposium on 4903 Research in Computer Security (ESORICS' 96), Lecture 4904 Notes in Computer Science, Springer-Verlag, vol. 4905 1146, pp. 325-350, Sep 1996. 4906 4907 [MZ05] Serge Mister, Robert Zuccherato, "An Attack on CFB 4908 Mode Encryption As Used By OpenPGP," IACR ePrint 4909 Archive: Report 2005/033, 8 Feb 2005 4910 http://eprint.iacr.org/2005/033 4911 4912 [REGEX] Jeffrey Friedl, "Mastering Regular Expressions," 4913 O'Reilly, ISBN 0-596-00289-0. 4914 4915 [RFC1423] Balenson, D., "Privacy Enhancement for Internet 4916 Electronic Mail: Part III: Algorithms, Modes, and 4917 Identifiers", RFC 1423, February 1993. 4918 4919 [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP 4920 Message Exchange Formats", RFC 1991, August 1996. 4921 4922 [RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R. 4923 Thayer, "OpenPGP Message Format", RFC 2440, November 4924 1998. 4925 4926 4927 4928 4929 4930Callas, et al Standards Track [Page 88] 4931 4932RFC 4880 OpenPGP Message Format November 2007 4933 4934 4935 [SP800-57] NIST Special Publication 800-57, Recommendation on 4936 Key Management 4937 <http://csrc.nist.gov/publications/nistpubs/ 800- 4938 57/SP800-57-Part1.pdf> 4939 <http://csrc.nist.gov/publications/nistpubs/ 800- 4940 57/SP800-57-Part2.pdf> 4941 4942Acknowledgements 4943 4944 This memo also draws on much previous work from a number of other 4945 authors, including: Derek Atkins, Charles Breed, Dave Del Torto, Marc 4946 Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Ben Laurie, 4947 Raph Levien, Colin Plumb, Will Price, David Shaw, William Stallings, 4948 Mark Weaver, and Philip R. Zimmermann. 4949 4950Authors' Addresses 4951 4952 The working group can be contacted via the current chair: 4953 4954 Derek Atkins 4955 IHTFP Consulting, Inc. 4956 4 Farragut Ave 4957 Somerville, MA 02144 USA 4958 4959 EMail: derek@ihtfp.com 4960 Tel: +1 617 623 3745 4961 4962 The principal authors of this document are as follows: 4963 4964 Jon Callas 4965 EMail: jon@callas.org 4966 4967 Lutz Donnerhacke 4968 IKS GmbH 4969 Wildenbruchstr. 15 4970 07745 Jena, Germany 4971 EMail: lutz@iks-jena.de 4972 4973 Hal Finney 4974 EMail: hal@finney.org 4975 4976 David Shaw 4977 EMail: dshaw@jabberwocky.com 4978 4979 Rodney Thayer 4980 EMail: rodney@canola-jones.com 4981 4982 4983 4984 4985 4986Callas, et al Standards Track [Page 89] 4987 4988RFC 4880 OpenPGP Message Format November 2007 4989 4990 4991Full Copyright Statement 4992 4993 Copyright (C) The IETF Trust (2007). 4994 4995 This document is subject to the rights, licenses and restrictions 4996 contained in BCP 78, and except as set forth therein, the authors 4997 retain all their rights. 4998 4999 This document and the information contained herein are provided on an 5000 "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS 5001 OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND 5002 THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS 5003 OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF 5004 THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED 5005 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 5006 5007Intellectual Property 5008 5009 The IETF takes no position regarding the validity or scope of any 5010 Intellectual Property Rights or other rights that might be claimed to 5011 pertain to the implementation or use of the technology described in 5012 this document or the extent to which any license under such rights 5013 might or might not be available; nor does it represent that it has 5014 made any independent effort to identify any such rights. Information 5015 on the procedures with respect to rights in RFC documents can be 5016 found in BCP 78 and BCP 79. 5017 5018 Copies of IPR disclosures made to the IETF Secretariat and any 5019 assurances of licenses to be made available, or the result of an 5020 attempt made to obtain a general license or permission for the use of 5021 such proprietary rights by implementers or users of this 5022 specification can be obtained from the IETF on-line IPR repository at 5023 http://www.ietf.org/ipr. 5024 5025 The IETF invites any interested party to bring to its attention any 5026 copyrights, patents or patent applications, or other proprietary 5027 rights that may cover technology that may be required to implement 5028 this standard. Please address the information to the IETF at 5029 ietf-ipr@ietf.org. 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042Callas, et al Standards Track [Page 90] 5043 5044