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