idnits 2.17.1 draft-ietf-openpgp-rfc2440bis-07.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Looks like you're using RFC 2026 boilerplate. This must be updated to follow RFC 3978/3979, as updated by RFC 4748. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing document type: Expected "INTERNET-DRAFT" in the upper left hand corner of the first page Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack an Authors' Addresses Section. ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. Miscellaneous warnings: ---------------------------------------------------------------------------- == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). == Unrecognized Status in 'Category: INTERNET-DRAFT', assuming Proposed Standard (Expected one of 'Standards Track', 'Full Standard', 'Draft Standard', 'Proposed Standard', 'Best Current Practice', 'Informational', 'Experimental', 'Informational', 'Historic'.) -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- Couldn't find a document date in the document -- date freshness check skipped. -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '0' on line 370 -- Looks like a reference, but probably isn't: '1' on line 3250 -- Looks like a reference, but probably isn't: '2' on line 370 -- Looks like a reference, but probably isn't: '3' on line 3259 == Missing Reference: 'Optional' is mentioned on line 1952, but not defined == Missing Reference: 'RFC 2045' is mentioned on line 2354, but not defined == Missing Reference: 'Binding-Signature-Revocation' is mentioned on line 2946, but not defined == Missing Reference: 'BS' is mentioned on line 3250, but not defined == Unused Reference: 'DONNERHACKE' is defined on line 3512, but no explicit reference was found in the text == Unused Reference: 'RFC822' is defined on line 3544, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 3548, but no explicit reference was found in the text == Unused Reference: 'RFC1641' is defined on line 3552, but no explicit reference was found in the text == Unused Reference: 'RFC1750' is defined on line 3555, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 3559, but no explicit reference was found in the text == Unused Reference: 'RFC1983' is defined on line 3562, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 3565, but no explicit reference was found in the text == Unused Reference: 'RFC2045' is defined on line 3568, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 3572, but no explicit reference was found in the text == Unused Reference: 'RFC2144' is defined on line 3575, but no explicit reference was found in the text == Unused Reference: 'RFC3156' is defined on line 3585, but no explicit reference was found in the text -- Possible downref: Non-RFC (?) normative reference: ref. 'AES' -- Possible downref: Non-RFC (?) normative reference: ref. 'BLEICHENBACHER' -- Possible downref: Non-RFC (?) normative reference: ref. 'BLOWFISH' -- Possible downref: Non-RFC (?) normative reference: ref. 'DONNERHACKE' -- Possible downref: Non-RFC (?) normative reference: ref. 'ELGAMAL' -- Possible downref: Non-RFC (?) normative reference: ref. 'IDEA' -- Possible downref: Non-RFC (?) normative reference: ref. 'ISO10646' -- Possible downref: Non-RFC (?) normative reference: ref. 'JFIF' -- Possible downref: Non-RFC (?) normative reference: ref. 'JKS02' -- Possible downref: Non-RFC (?) normative reference: ref. 'MENEZES' ** Obsolete normative reference: RFC 822 (Obsoleted by RFC 2822) ** Downref: Normative reference to an Historic RFC: RFC 1423 ** Downref: Normative reference to an Experimental RFC: RFC 1641 ** Obsolete normative reference: RFC 1750 (Obsoleted by RFC 4086) ** Downref: Normative reference to an Informational RFC: RFC 1951 ** Downref: Normative reference to an Informational RFC: RFC 1983 ** Obsolete normative reference: RFC 1991 (Obsoleted by RFC 4880) ** Downref: Normative reference to an Informational RFC: RFC 2144 ** Obsolete normative reference: RFC 2279 (Obsoleted by RFC 3629) ** Obsolete normative reference: RFC 2437 (Obsoleted by RFC 3447) -- Possible downref: Non-RFC (?) normative reference: ref. 'SAFER' -- Possible downref: Non-RFC (?) normative reference: ref. 'SCHNEIER' -- Possible downref: Non-RFC (?) normative reference: ref. 'TWOFISH' Summary: 15 errors (**), 0 flaws (~~), 18 warnings (==), 20 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 1 Network Working Group Jon Callas 2 Category: INTERNET-DRAFT PGP Corporation 3 draft-ietf-openpgp-rfc2440bis-07.txt 4 Expires Sep 2003 Lutz Donnerhacke 5 March 2003 IN-Root-CA Individual Network e.V. 7 Hal Finney 8 Network Associates 10 Rodney Thayer 12 OpenPGP Message Format 13 draft-ietf-openpgp-rfc2440bis-07.txt 15 Copyright 2003 by The Internet Society. All Rights Reserved. 17 Status of this Memo 19 This document is an Internet-Draft and is in full conformance with 20 all provisions of Section 10 of RFC2026. 22 Internet-Drafts are working documents of the Internet Engineering 23 Task Force (IETF), its areas, and its working groups. Note that 24 other groups may also distribute working documents as 25 Internet-Drafts. 27 Internet-Drafts are draft documents valid for a maximum of six 28 months and may be updated, replaced, or obsoleted by other documents 29 at any time. It is inappropriate to use Internet-Drafts as 30 reference material or to cite them other than as "work in progress." 32 The list of current Internet-Drafts can be accessed at 33 http://www.ietf.org/ietf/1id-abstracts.txt 35 The list of Internet-Draft Shadow Directories can be accessed at 36 http://www.ietf.org/shadow.html. 38 IESG Note 40 This document defines many tag values, yet it doesn't describe a 41 mechanism for adding new tags (for new features). Traditionally the 42 Internet Assigned Numbers Authority (IANA) handles the allocation of 43 new values for future expansion and RFCs usually define the 44 procedure to be used by the IANA. However there are subtle (and not 45 so subtle) interactions that may occur in this protocol between new 46 features and existing features which result in a significant 47 reduction in over all security. Therefore this document does not 48 define an extension procedure. Instead requests to define new tag 49 values (say for new encryption algorithms for example) should be 50 forwarded to the IESG Security Area Directors for consideration or 51 forwarding to the appropriate IETF Working Group for consideration. 53 Abstract 55 This document is maintained in order to publish all necessary 56 information needed to develop interoperable applications based on 57 the OpenPGP format. It is not a step-by-step cookbook for writing an 58 application. It describes only the format and methods needed to 59 read, check, generate, and write conforming packets crossing any 60 network. It does not deal with storage and implementation questions. 61 It does, however, discuss implementation issues necessary to avoid 62 security flaws. 64 OpenPGP software uses a combination of strong public-key and 65 symmetric cryptography to provide security services for electronic 66 communications and data storage. These services include 67 confidentiality, key management, authentication, and digital 68 signatures. This document specifies the message formats used in 69 OpenPGP. 71 Table of Contents 73 Status of this Memo 1 74 IESG Note 1 75 Abstract 2 76 Table of Contents 3 77 1. Introduction 6 78 1.1. Terms 6 79 2. General functions 6 80 2.1. Confidentiality via Encryption 7 81 2.2. Authentication via Digital signature 7 82 2.3. Compression 8 83 2.4. Conversion to Radix-64 8 84 2.5. Signature-Only Applications 8 85 3. Data Element Formats 9 86 3.1. Scalar numbers 9 87 3.2. Multi-Precision Integers 9 88 3.3. Key IDs 9 89 3.4. Text 10 90 3.5. Time fields 10 91 3.6. Keyrings 10 92 3.7. String-to-key (S2K) specifiers 10 93 3.7.1. String-to-key (S2K) specifier types 10 94 3.7.1.1. Simple S2K 10 95 3.7.1.2. Salted S2K 11 96 3.7.1.3. Iterated and Salted S2K 11 97 3.7.2. String-to-key usage 12 98 3.7.2.1. Secret key encryption 12 99 3.7.2.2. Symmetric-key message encryption 13 100 4. Packet Syntax 13 101 4.1. Overview 13 102 4.2. Packet Headers 13 103 4.2.1. Old-Format Packet Lengths 14 104 4.2.2. New-Format Packet Lengths 14 105 4.2.2.1. One-Octet Lengths 15 106 4.2.2.2. Two-Octet Lengths 15 107 4.2.2.3. Five-Octet Lengths 15 108 4.2.2.4. Partial Body Lengths 15 109 4.2.3. Packet Length Examples 16 110 4.3. Packet Tags 16 111 5. Packet Types 17 112 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 17 113 5.2. Signature Packet (Tag 2) 18 114 5.2.1. Signature Types 18 115 5.2.2. Version 3 Signature Packet Format 20 116 5.2.3. Version 4 Signature Packet Format 23 117 5.2.3.1. Signature Subpacket Specification 24 118 5.2.3.2. Signature Subpacket Types 25 119 5.2.3.3. Notes on Self-Signatures 25 120 5.2.3.4. Signature creation time 26 121 5.2.3.5. Issuer 26 122 5.2.3.6. Key expiration time 27 123 5.2.3.7. Preferred symmetric algorithms 27 124 5.2.3.8. Preferred hash algorithms 27 125 5.2.3.9. Preferred compression algorithms 27 126 5.2.3.10.Signature expiration time 27 127 5.2.3.11.Exportable Certification 27 128 5.2.3.12.Revocable 28 129 5.2.3.13.Trust signature 28 130 5.2.3.14.Regular expression 29 131 5.2.3.15.Revocation key 29 132 5.2.3.16.Notation Data 29 133 5.2.3.17.Key server preferences 30 134 5.2.3.18.Preferred key server 30 135 5.2.3.19.Primary user id 30 136 5.2.3.20.Policy URL 31 137 5.2.3.21.Key Flags 31 138 5.2.3.22.Signer's User ID 32 139 5.2.3.23.Reason for Revocation 32 140 5.2.3.24.Features 33 141 5.2.3.25.Signature Target 33 142 5.2.4. Computing Signatures 34 143 5.2.4.1. Subpacket Hints 35 144 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) 35 145 5.4. One-Pass Signature Packets (Tag 4) 36 146 5.5. Key Material Packet 37 147 5.5.1. Key Packet Variants 37 148 5.5.1.1. Public Key Packet (Tag 6) 37 149 5.5.1.2. Public Subkey Packet (Tag 14) 37 150 5.5.1.3. Secret Key Packet (Tag 5) 37 151 5.5.1.4. Secret Subkey Packet (Tag 7) 37 152 5.5.2. Public Key Packet Formats 38 153 5.5.3. Secret Key Packet Formats 39 154 5.6. Compressed Data Packet (Tag 8) 41 155 5.7. Symmetrically Encrypted Data Packet (Tag 9) 41 156 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 42 157 5.9. Literal Data Packet (Tag 11) 43 158 5.10. Trust Packet (Tag 12) 43 159 5.11. User ID Packet (Tag 13) 43 160 5.12. User Attribute Packet (Tag 17) 44 161 5.12.1. The Image Attribute Subpacket 44 162 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) 45 163 5.14. Modification Detection Code Packet (Tag 19) 47 164 6. Radix-64 Conversions 47 165 6.1. An Implementation of the CRC-24 in "C" 48 166 6.2. Forming ASCII Armor 48 167 6.3. Encoding Binary in Radix-64 51 168 6.4. Decoding Radix-64 52 169 6.5. Examples of Radix-64 52 170 6.6. Example of an ASCII Armored Message 53 171 7. Cleartext signature framework 53 172 7.1. Dash-Escaped Text 54 173 8. Regular Expressions 54 174 9. Constants 55 175 9.1. Public Key Algorithms 55 176 9.2. Symmetric Key Algorithms 55 177 9.3. Compression Algorithms 56 178 9.4. Hash Algorithms 56 179 10. Packet Composition 56 180 10.1. Transferable Public Keys 56 181 10.2. OpenPGP Messages 58 182 10.3. Detached Signatures 58 183 11. Enhanced Key Formats 59 184 11.1. Key Structures 59 185 11.2. Key IDs and Fingerprints 60 186 12. Notes on Algorithms 61 187 12.1. Symmetric Algorithm Preferences 61 188 12.2. Other Algorithm Preferences 61 189 12.2.1. Compression Preferences 62 190 12.2.2. Hash Algorithm Preferences 62 191 12.3. Plaintext 62 192 12.4. RSA 63 193 12.5. Elgamal 63 194 12.6. DSA 64 195 12.7. Reserved Algorithm Numbers 64 196 12.8. OpenPGP CFB mode 64 197 13. Security Considerations 65 198 14. Implementation Nits 67 199 15. Authors and Working Group Chair 69 200 16. References 70 201 17. Full Copyright Statement 72 203 1. Introduction 205 This document provides information on the message-exchange packet 206 formats used by OpenPGP to provide encryption, decryption, signing, 207 and key management functions. It is a revision of RFC2440, "OpenPGP 208 Message Format", which itself replaces RFC 1991, "PGP Message 209 Exchange Formats." 211 1.1. Terms 213 * OpenPGP - This is a definition for security software that uses 214 PGP 5.x as a basis, formalized in RFC 2440 and this document. 216 * PGP - Pretty Good Privacy. PGP is a family of software systems 217 developed by Philip R. Zimmermann from which OpenPGP is based. 219 * PGP 2.6.x - This version of PGP has many variants, hence the 220 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 221 cryptographic transforms. An informational RFC, RFC1991, was 222 written describing this version of PGP. 224 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 225 the community and also in the predecessor of this document, 226 RFC1991. It has new formats and corrects a number of problems in 227 the PGP 2.6.x design. It is referred to here as PGP 5.x because 228 that software was the first release of the "PGP 3" code base. 230 * GPG - GNU Privacy Guard, also called GNUpg. GPG is an OpenPGP 231 implementation that avoids all encumbered algorithms. 232 Consequently, early versions of GPG did not include RSA public 233 keys. GPG may or may not have (depending on version) support for 234 IDEA or other encumbered algorithms. 236 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 237 PGP Corporation and are used with permission. 239 This document uses the terms "MUST", "SHOULD", and "MAY" as defined 240 in RFC2119, along with the negated forms of those terms. 242 2. General functions 244 OpenPGP provides data integrity services for messages and data files 245 by using these core technologies: 247 - digital signatures 249 - encryption 251 - compression 252 - radix-64 conversion 254 In addition, OpenPGP provides key management and certificate 255 services, but many of these are beyond the scope of this document. 257 2.1. Confidentiality via Encryption 259 OpenPGP combines symmetric-key encryption and public key encryption 260 to provide confidentiality. When made confidential, first the object 261 is encrypted using a symmetric encryption algorithm. Each symmetric 262 key is used only once, for a single object. A new "session key" is 263 generated as a random number for each object (sometimes referred to 264 as a session). Since it is used only once, the session key is bound 265 to the message and transmitted with it. To protect the key, it is 266 encrypted with the receiver's public key. The sequence is as 267 follows: 269 1. The sender creates a message. 271 2. The sending OpenPGP generates a random number to be used as a 272 session key for this message only. 274 3. The session key is encrypted using each recipient's public key. 275 These "encrypted session keys" start the message. 277 4. The sending OpenPGP encrypts the message using the session key, 278 which forms the remainder of the message. Note that the message 279 is also usually compressed. 281 5. The receiving OpenPGP decrypts the session key using the 282 recipient's private key. 284 6. The receiving OpenPGP decrypts the message using the session 285 key. If the message was compressed, it will be decompressed. 287 With symmetric-key encryption, an object may be encrypted with a 288 symmetric key derived from a passphrase (or other shared secret), or 289 a two-stage mechanism similar to the public-key method described 290 above in which a session key is itself encrypted with a symmetric 291 algorithm keyed from a shared secret. 293 Both digital signature and confidentiality services may be applied 294 to the same message. First, a signature is generated for the message 295 and attached to the message. Then, the message plus signature is 296 encrypted using a symmetric session key. Finally, the session key is 297 encrypted using public-key encryption and prefixed to the encrypted 298 block. 300 2.2. Authentication via Digital signature 302 The digital signature uses a hash code or message digest algorithm, 303 and a public-key signature algorithm. The sequence is as follows: 305 1. The sender creates a message. 307 2. The sending software generates a hash code of the message. 309 3. The sending software generates a signature from the hash code 310 using the sender's private key. 312 4. The binary signature is attached to the message. 314 5. The receiving software keeps a copy of the message signature. 316 6. The receiving software generates a new hash code for the 317 received message and verifies it using the message's signature. 318 If the verification is successful, the message is accepted as 319 authentic. 321 2.3. Compression 323 OpenPGP implementations SHOULD compress the message after applying 324 the signature but before encryption. 326 If an implementation does not implement compression, its authors 327 should be aware that most PGP messages in the world are compressed. 328 Thus, it may even be wise for a space-constrained implementation to 329 implement decompression, but not compression. 331 Furthermore, compression has the added side-effect that some types 332 of attacks can be thwarted by the fact that slightly altered, 333 compressed data rarely uncompresses without severe errors. This is 334 hardly rigorous, but it is operationally useful. These attacks can 335 be rigorously prevented by implementing and using Modification 336 Detection Codes as described in sections following. 338 2.4. Conversion to Radix-64 340 OpenPGP's underlying native representation for encrypted messages, 341 signature certificates, and keys is a stream of arbitrary octets. 342 Some systems only permit the use of blocks consisting of seven-bit, 343 printable text. For transporting OpenPGP's native raw binary octets 344 through channels that are not safe to raw binary data, a printable 345 encoding of these binary octets is needed. OpenPGP provides the 346 service of converting the raw 8-bit binary octet stream to a stream 347 of printable ASCII characters, called Radix-64 encoding or ASCII 348 Armor. 350 Implementations SHOULD provide Radix-64 conversions. 352 2.5. Signature-Only Applications 354 OpenPGP is designed for applications that use both encryption and 355 signatures, but there are a number of problems that are solved by a 356 signature-only implementation. Although this specification requires 357 both encryption and signatures, it is reasonable for there to be 358 subset implementations that are non-comformant only in that they 359 omit encryption. 361 3. Data Element Formats 363 This section describes the data elements used by OpenPGP. 365 3.1. Scalar numbers 367 Scalar numbers are unsigned, and are always stored in big-endian 368 format. Using n[k] to refer to the kth octet being interpreted, the 369 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 370 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 371 n[3]). 373 3.2. Multi-Precision Integers 375 Multi-Precision Integers (also called MPIs) are unsigned integers 376 used to hold large integers such as the ones used in cryptographic 377 calculations. 379 An MPI consists of two pieces: a two-octet scalar that is the length 380 of the MPI in bits followed by a string of octets that contain the 381 actual integer. 383 These octets form a big-endian number; a big-endian number can be 384 made into an MPI by prefixing it with the appropriate length. 386 Examples: 388 (all numbers are in hexadecimal) 390 The string of octets [00 01 01] forms an MPI with the value 1. The 391 string [00 09 01 FF] forms an MPI with the value of 511. 393 Additional rules: 395 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 397 The length field of an MPI describes the length starting from its 398 most significant non-zero bit. Thus, the MPI [00 02 01] is not 399 formed correctly. It should be [00 01 01]. 401 Also note that when an MPI is encrypted, the length refers to the 402 plaintext MPI. It may be ill-formed in its ciphertext. 404 3.3. Key IDs 406 A Key ID is an eight-octet scalar that identifies a key. 407 Implementations SHOULD NOT assume that Key IDs are unique. The 408 section, "Enhanced Key Formats" below describes how Key IDs are 409 formed. 411 3.4. Text 413 Unless otherwise specified, the character set for text is the UTF-8 414 [RFC2279] encoding of Unicode [ISO10646]. 416 3.5. Time fields 418 A time field is an unsigned four-octet number containing the number 419 of seconds elapsed since midnight, 1 January 1970 UTC. 421 3.6. Keyrings 423 A keyring is a collection of one or more keys in a file or database. 424 Traditionally, a keyring is simply a sequential list of keys, but 425 may be any suitable database. It is beyond the scope of this 426 standard to discuss the details of keyrings or other databases. 428 3.7. String-to-key (S2K) specifiers 430 String-to-key (S2K) specifiers are used to convert passphrase 431 strings into symmetric-key encryption/decryption keys. They are 432 used in two places, currently: to encrypt the secret part of private 433 keys in the private keyring, and to convert passphrases to 434 encryption keys for symmetrically encrypted messages. 436 3.7.1. String-to-key (S2K) specifier types 438 There are three types of S2K specifiers currently supported, and 439 some reserved values: 441 ID S2K Type 442 -- --- ---- 443 0 Simple S2K 444 1 Salted S2K 445 2 Illegal value 446 3 Iterated and Salted S2K 447 100 to 110 Private/Experimental S2K 449 These are described as follows: 451 3.7.1.1. Simple S2K 453 This directly hashes the string to produce the key data. See below 454 for how this hashing is done. 456 Octet 0: 0x00 457 Octet 1: hash algorithm 459 Simple S2K hashes the passphrase to produce the session key. The 460 manner in which this is done depends on the size of the session key 461 (which will depend on the cipher used) and the size of the hash 462 algorithm's output. If the hash size is greater than the session key 463 size, the high-order (leftmost) octets of the hash are used as the 464 key. 466 If the hash size is less than the key size, multiple instances of 467 the hash context are created -- enough to produce the required key 468 data. These instances are preloaded with 0, 1, 2, ... octets of 469 zeros (that is to say, the first instance has no preloading, the 470 second gets preloaded with 1 octet of zero, the third is preloaded 471 with two octets of zeros, and so forth). 473 As the data is hashed, it is given independently to each hash 474 context. Since the contexts have been initialized differently, they 475 will each produce different hash output. Once the passphrase is 476 hashed, the output data from the multiple hashes is concatenated, 477 first hash leftmost, to produce the key data, with any excess octets 478 on the right discarded. 480 3.7.1.2. Salted S2K 482 This includes a "salt" value in the S2K specifier -- some arbitrary 483 data -- that gets hashed along with the passphrase string, to help 484 prevent dictionary attacks. 486 Octet 0: 0x01 487 Octet 1: hash algorithm 488 Octets 2-9: 8-octet salt value 490 Salted S2K is exactly like Simple S2K, except that the input to the 491 hash function(s) consists of the 8 octets of salt from the S2K 492 specifier, followed by the passphrase. 494 3.7.1.3. Iterated and Salted S2K 496 This includes both a salt and an octet count. The salt is combined 497 with the passphrase and the resulting value is hashed repeatedly. 498 This further increases the amount of work an attacker must do to try 499 dictionary attacks. 501 Octet 0: 0x03 502 Octet 1: hash algorithm 503 Octets 2-9: 8-octet salt value 504 Octet 10: count, a one-octet, coded value 506 The count is coded into a one-octet number using the following 507 formula: 509 #define EXPBIAS 6 510 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 512 The above formula is in C, where "Int32" is a type for a 32-bit 513 integer, and the variable "c" is the coded count, Octet 10. 515 Iterated-Salted S2K hashes the passphrase and salt data multiple 516 times. The total number of octets to be hashed is specified in the 517 encoded count in the S2K specifier. Note that the resulting count 518 value is an octet count of how many octets will be hashed, not an 519 iteration count. 521 Initially, one or more hash contexts are set up as with the other 522 S2K algorithms, depending on how many octets of key data are needed. 523 Then the salt, followed by the passphrase data is repeatedly hashed 524 until the number of octets specified by the octet count has been 525 hashed. The one exception is that if the octet count is less than 526 the size of the salt plus passphrase, the full salt plus passphrase 527 will be hashed even though that is greater than the octet count. 528 After the hashing is done the data is unloaded from the hash 529 context(s) as with the other S2K algorithms. 531 3.7.2. String-to-key usage 533 Implementations SHOULD use salted or iterated-and-salted S2K 534 specifiers, as simple S2K specifiers are more vulnerable to 535 dictionary attacks. 537 3.7.2.1. Secret key encryption 539 An S2K specifier can be stored in the secret keyring to specify how 540 to convert the passphrase to a key that unlocks the secret data. 541 Older versions of PGP just stored a cipher algorithm octet preceding 542 the secret data or a zero to indicate that the secret data was 543 unencrypted. The MD5 hash function was always used to convert the 544 passphrase to a key for the specified cipher algorithm. 546 For compatibility, when an S2K specifier is used, the special value 547 255 is stored in the position where the hash algorithm octet would 548 have been in the old data structure. This is then followed 549 immediately by a one-octet algorithm identifier, and then by the S2K 550 specifier as encoded above. 552 Therefore, preceding the secret data there will be one of these 553 possibilities: 555 0: secret data is unencrypted (no pass phrase) 556 255 or 254: followed by algorithm octet and S2K specifier 557 Cipher alg: use Simple S2K algorithm using MD5 hash 559 This last possibility, the cipher algorithm number with an implicit 560 use of MD5 and IDEA, is provided for backward compatibility; it MAY 561 be understood, but SHOULD NOT be generated, and is deprecated. 563 These are followed by an Initial Vector of the same length as the 564 block size of the cipher for the decryption of the secret values, if 565 they are encrypted, and then the secret key values themselves. 567 3.7.2.2. Symmetric-key message encryption 569 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 570 packet at the front of a message. This is used to allow S2K 571 specifiers to be used for the passphrase conversion or to create 572 messages with a mix of symmetric-key ESKs and public-key ESKs. This 573 allows a message to be decrypted either with a passphrase or a 574 public key. 576 PGP 2.X always used IDEA with Simple string-to-key conversion when 577 encrypting a message with a symmetric algorithm. This is deprecated, 578 but MAY be used for backward-compatibility. 580 4. Packet Syntax 582 This section describes the packets used by OpenPGP. 584 4.1. Overview 586 An OpenPGP message is constructed from a number of records that are 587 traditionally called packets. A packet is a chunk of data that has a 588 tag specifying its meaning. An OpenPGP message, keyring, 589 certificate, and so forth consists of a number of packets. Some of 590 those packets may contain other OpenPGP packets (for example, a 591 compressed data packet, when uncompressed, contains OpenPGP 592 packets). 594 Each packet consists of a packet header, followed by the packet 595 body. The packet header is of variable length. 597 4.2. Packet Headers 599 The first octet of the packet header is called the "Packet Tag." It 600 determines the format of the header and denotes the packet contents. 601 The remainder of the packet header is the length of the packet. 603 Note that the most significant bit is the left-most bit, called bit 604 7. A mask for this bit is 0x80 in hexadecimal. 606 +---------------+ 607 PTag |7 6 5 4 3 2 1 0| 608 +---------------+ 609 Bit 7 -- Always one 610 Bit 6 -- New packet format if set 612 PGP 2.6.x only uses old format packets. Thus, software that 613 interoperates with those versions of PGP must only use old format 614 packets. If interoperability is not an issue, either format may be 615 used. Note that old format packets have four bits of content tags, 616 and new format packets have six; some features cannot be used and 617 still be backward-compatible. 619 Also note that packets with a tag greater than or equal to 16 MUST 620 use new format packets. The old format packets can only express tags 621 less than or equal to 15. 623 Old format packets contain: 625 Bits 5-2 -- content tag 626 Bits 1-0 - length-type 628 New format packets contain: 630 Bits 5-0 -- content tag 632 4.2.1. Old-Format Packet Lengths 634 The meaning of the length-type in old-format packets is: 636 0 - The packet has a one-octet length. The header is 2 octets long. 638 1 - The packet has a two-octet length. The header is 3 octets long. 640 2 - The packet has a four-octet length. The header is 5 octets long. 642 3 - The packet is of indeterminate length. The header is 1 octet 643 long, and the implementation must determine how long the packet 644 is. If the packet is in a file, this means that the packet 645 extends until the end of the file. In general, an implementation 646 SHOULD NOT use indeterminate length packets except where the end 647 of the data will be clear from the context, and even then it is 648 better to use a definite length, or a new-format header. The 649 new-format headers described below have a mechanism for 650 precisely encoding data of indeterminate length. 652 4.2.2. New-Format Packet Lengths 654 New format packets have four possible ways of encoding length: 656 1. A one-octet Body Length header encodes packet lengths of up to 657 191 octets. 659 2. A two-octet Body Length header encodes packet lengths of 192 to 660 8383 octets. 662 3. A five-octet Body Length header encodes packet lengths of up to 663 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 664 encodes a four-octet scalar number.) 666 4. When the length of the packet body is not known in advance by 667 the issuer, Partial Body Length headers encode a packet of 668 indeterminate length, effectively making it a stream. 670 4.2.2.1. One-Octet Lengths 672 A one-octet Body Length header encodes a length of from 0 to 191 673 octets. This type of length header is recognized because the one 674 octet value is less than 192. The body length is equal to: 676 bodyLen = 1st_octet; 678 4.2.2.2. Two-Octet Lengths 680 A two-octet Body Length header encodes a length of from 192 to 8383 681 octets. It is recognized because its first octet is in the range 682 192 to 223. The body length is equal to: 684 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 686 4.2.2.3. Five-Octet Lengths 688 A five-octet Body Length header consists of a single octet holding 689 the value 255, followed by a four-octet scalar. The body length is 690 equal to: 692 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 693 (4th_octet << 8) | 5th_octet 695 This basic set of one, two, and five-octet lengths is also used 696 internally to some packets. 698 4.2.2.4. Partial Body Lengths 700 A Partial Body Length header is one octet long and encodes the 701 length of only part of the data packet. This length is a power of 2, 702 from 1 to 1,073,741,824 (2 to the 30th power). It is recognized by 703 its one octet value that is greater than or equal to 224, and less 704 than 255. The partial body length is equal to: 706 partialBodyLen = 1 << (1st_octet & 0x1f); 708 Each Partial Body Length header is followed by a portion of the 709 packet body data. The Partial Body Length header specifies this 710 portion's length. Another length header (of one of the three types 711 -- one octet, two-octet, or partial) follows that portion. The last 712 length header in the packet MUST NOT be a partial Body Length 713 header. Partial Body Length headers may only be used for the 714 non-final parts of the packet. 716 4.2.3. Packet Length Examples 718 These examples show ways that new-format packets might encode the 719 packet lengths. 721 A packet with length 100 may have its length encoded in one octet: 722 0x64. This is followed by 100 octets of data. 724 A packet with length 1723 may have its length coded in two octets: 725 0xC5, 0xFB. This header is followed by the 1723 octets of data. 727 A packet with length 100000 may have its length encoded in five 728 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 730 It might also be encoded in the following octet stream: 0xEF, first 731 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 732 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 733 1693 octets of data. This is just one possible encoding, and many 734 variations are possible on the size of the Partial Body Length 735 headers, as long as a regular Body Length header encodes the last 736 portion of the data. Note also that the last Body Length header can 737 be a zero-length header. 739 An implementation MAY use Partial Body Lengths for data packets, be 740 they literal, compressed, or encrypted. The first partial length 741 MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 742 used for any other packet types. 744 Please note that in all of these explanations, the total length of 745 the packet is the length of the header(s) plus the length of the 746 body. 748 4.3. Packet Tags 750 The packet tag denotes what type of packet the body holds. Note that 751 old format headers can only have tags less than 16, whereas new 752 format headers can have tags as great as 63. The defined tags (in 753 decimal) are: 755 0 -- Reserved - a packet tag must not have this value 756 1 -- Public-Key Encrypted Session Key Packet 757 2 -- Signature Packet 758 3 -- Symmetric-Key Encrypted Session Key Packet 759 4 -- One-Pass Signature Packet 760 5 -- Secret Key Packet 761 6 -- Public Key Packet 762 7 -- Secret Subkey Packet 763 8 -- Compressed Data Packet 764 9 -- Symmetrically Encrypted Data Packet 765 10 -- Marker Packet 766 11 -- Literal Data Packet 767 12 -- Trust Packet 768 13 -- User ID Packet 769 14 -- Public Subkey Packet 770 17 -- User Attribute Packet 771 18 -- Sym. Encrypted and Integrity Protected Data Packet 772 19 -- Modification Detection Code Packet 773 60 to 63 -- Private or Experimental Values 775 5. Packet Types 777 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 779 A Public-Key Encrypted Session Key packet holds the session key used 780 to encrypt a message. Zero or more Encrypted Session Key packets 781 (either Public-Key or Symmetric-Key) may precede a Symmetrically 782 Encrypted Data Packet, which holds an encrypted message. The 783 message is encrypted with the session key, and the session key is 784 itself encrypted and stored in the Encrypted Session Key packet(s). 785 The Symmetrically Encrypted Data Packet is preceded by one 786 Public-Key Encrypted Session Key packet for each OpenPGP key to 787 which the message is encrypted. The recipient of the message finds 788 a session key that is encrypted to their public key, decrypts the 789 session key, and then uses the session key to decrypt the message. 791 The body of this packet consists of: 793 - A one-octet number giving the version number of the packet type. 794 The currently defined value for packet version is 3. An 795 implementation should accept, but not generate a version of 2, 796 which is equivalent to V3 in all other respects. 798 - An eight-octet number that gives the key ID of the public key 799 that the session key is encrypted to. If the session key is 800 encrypted to a subkey then the key ID of this subkey is used 801 here instead of the key ID of the primary key. 803 - A one-octet number giving the public key algorithm used. 805 - A string of octets that is the encrypted session key. This 806 string takes up the remainder of the packet, and its contents 807 are dependent on the public key algorithm used. 809 Algorithm Specific Fields for RSA encryption 811 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 813 Algorithm Specific Fields for Elgamal encryption: 815 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 817 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 819 The value "m" in the above formulas is derived from the session key 820 as follows. First the session key is prefixed with a one-octet 821 algorithm identifier that specifies the symmetric encryption 822 algorithm used to encrypt the following Symmetrically Encrypted Data 823 Packet. Then a two-octet checksum is appended which is equal to the 824 sum of the preceding session key octets, not including the algorithm 825 identifier, modulo 65536. This value is then encoded as described 826 in PKCS-1 block encoding EME-PKCS1-v1_5 [RFC2437] to form the "m" 827 value used in the formulas above. 829 Note that when an implementation forms several PKESKs with one 830 session key, forming a message that can be decrypted by several 831 keys, the implementation MUST make new PKCS-1 encoding for each key. 833 An implementation MAY accept or use a Key ID of zero as a "wild 834 card" or "speculative" Key ID. In this case, the receiving 835 implementation would try all available private keys, checking for a 836 valid decrypted session key. This format helps reduce traffic 837 analysis of messages. 839 5.2. Signature Packet (Tag 2) 841 A signature packet describes a binding between some public key and 842 some data. The most common signatures are a signature of a file or a 843 block of text, and a signature that is a certification of a user ID. 845 Two versions of signature packets are defined. Version 3 provides 846 basic signature information, while version 4 provides an expandable 847 format with subpackets that can specify more information about the 848 signature. PGP 2.6.x only accepts version 3 signatures. 850 Implementations MUST accept V3 signatures. Implementations SHOULD 851 generate V4 signatures. Implementations MAY generate a V3 signature 852 that can be verified by PGP 2.6.x. 854 Note that if an implementation is creating an encrypted and signed 855 message that is encrypted to a V3 key, it is reasonable to create a 856 V3 signature. 858 5.2.1. Signature Types 860 There are a number of possible meanings for a signature, which are 861 specified in a signature type octet in any given signature. These 862 meanings are: 864 0x00: Signature of a binary document. 865 This means the signer owns it, created it, or certifies that it 866 has not been modified. 868 0x01: Signature of a canonical text document. 869 This means the signer owns it, created it, or certifies that it 870 has not been modified. The signature is calculated over the 871 text data with its line endings converted to and 872 trailing blanks removed. 874 0x02: Standalone signature. 875 This signature is a signature of only its own subpacket 876 contents. It is calculated identically to a signature over a 877 zero-length binary document. Note that it doesn't make sense to 878 have a V3 standalone signature. 880 0x10: Generic certification of a User ID and Public Key packet. 881 The issuer of this certification does not make any particular 882 assertion as to how well the certifier has checked that the 883 owner of the key is in fact the person described by the user ID. 884 Note that all PGP "key signatures" are this type of 885 certification. 887 0x11: Persona certification of a User ID and Public Key packet. 888 The issuer of this certification has not done any verification 889 of the claim that the owner of this key is the user ID 890 specified. 892 0x12: Casual certification of a User ID and Public Key packet. 893 The issuer of this certification has done some casual 894 verification of the claim of identity. 896 0x13: Positive certification of a User ID and Public Key packet. 897 The issuer of this certification has done substantial 898 verification of the claim of identity. 900 Please note that the vagueness of these certification claims is 901 not a flaw, but a feature of the system. Because PGP places 902 final authority for validity upon the receiver of a 903 certification, it may be that one authority's casual 904 certification might be more rigorous than some other authority's 905 positive certification. These classifications allow a 906 certification authority to issue fine-grained claims. 908 0x18: Subkey Binding Signature 909 This signature is a statement by the top-level signing key 910 indicates that it owns the subkey. This signature is calculated 911 directly on the subkey itself, not on any User ID or other 912 packets. 914 0x1F: Signature directly on a key 915 This signature is calculated directly on a key. It binds the 916 information in the signature subpackets to the key, and is 917 appropriate to be used for subpackets that provide information 918 about the key, such as the revocation key subpacket. It is also 919 appropriate for statements that non-self certifiers want to make 920 about the key itself, rather than the binding between a key and 921 a name. 923 0x20: Key revocation signature 924 The signature is calculated directly on the key being revoked. 925 A revoked key is not to be used. Only revocation signatures by 926 the key being revoked, or by an authorized revocation key, 927 should be considered valid revocation signatures. 929 0x28: Subkey revocation signature 930 The signature is calculated directly on the subkey being 931 revoked. A revoked subkey is not to be used. Only revocation 932 signatures by the top-level signature key that is bound to this 933 subkey, or by an authorized revocation key, should be considered 934 valid revocation signatures. 936 0x30: Certification revocation signature 937 This signature revokes an earlier user ID certification 938 signature (signature class 0x10 through 0x13) or direct-key 939 signature (0x1F). It should be issued by the same key that 940 issued the revoked signature or an authorized revocation key. 941 The signature should have a later creation date than the 942 signature it revokes. 944 0x40: Timestamp signature. 945 This signature is only meaningful for the timestamp contained in 946 it. 948 0x50: Notary signature. 949 This signature is a signature over some other OpenPGP signature 950 packet. It is a notary seal on the signed data. Note that a 951 notary signature SHOULD include a Signature Target subpacket to 952 give easy identification. 954 5.2.2. Version 3 Signature Packet Format 956 The body of a version 3 Signature Packet contains: 958 - One-octet version number (3). 960 - One-octet length of following hashed material. MUST be 5. 962 - One-octet signature type. 964 - Four-octet creation time. 966 - Eight-octet key ID of signer. 968 - One-octet public key algorithm. 970 - One-octet hash algorithm. 972 - Two-octet field holding left 16 bits of signed hash value. 974 - One or more multi-precision integers comprising the signature. 975 This portion is algorithm specific, as described below. 977 The data being signed is hashed, and then the signature type and 978 creation time from the signature packet are hashed (5 additional 979 octets). The resulting hash value is used in the signature 980 algorithm. The high 16 bits (first two octets) of the hash are 981 included in the signature packet to provide a quick test to reject 982 some invalid signatures. 984 Algorithm Specific Fields for RSA signatures: 986 - multiprecision integer (MPI) of RSA signature value m**d mod n. 988 Algorithm Specific Fields for DSA signatures: 990 - MPI of DSA value r. 992 - MPI of DSA value s. 994 The signature calculation is based on a hash of the signed data, as 995 described above. The details of the calculation are different for 996 DSA signature than for RSA signatures. 998 Algorithm Specific Fields for Elgamal signatures: 1000 - MPI of Elgamal value a = g**k mod p. 1002 - MPI of Elgamal value b = (h-a*x)/k mod p-1. 1004 The hash h is PKCS-1 padded exactly the same way as for the above 1005 described RSA signatures. 1007 With RSA signatures, the hash value is encoded as described in 1008 PKCS-1 section 9.2.1 encoded using PKCS-1 encoding type 1009 EMSA-PKCS1-v1_5 [RFC2437]. This requires inserting the hash value 1010 as an octet string into an ASN.1 structure. The object identifier 1011 for the type of hash being used is included in the structure. The 1012 hexadecimal representations for the currently defined hash 1013 algorithms are: 1015 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02 1017 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 1019 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 1020 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 1022 - SHA256: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 1024 - SHA384: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 1026 - SHA512: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 1028 The ASN.1 OIDs are: 1030 - MD2: 1.2.840.113549.2.2 1032 - MD5: 1.2.840.113549.2.5 1034 - RIPEMD-160: 1.3.36.3.2.1 1036 - SHA-1: 1.3.14.3.2.26 1038 - SHA256: 2.16.840.1.101.3.4.2.1 1040 - SHA384: 2.16.840.1.101.3.4.2.2 1042 - SHA512: 2.16.840.1.101.3.4.2.3 1044 The full hash prefixes for these are: 1046 MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 1047 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 1048 0x04, 0x10 1050 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 1051 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 1052 0x04, 0x10 1054 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 1055 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 1057 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 1058 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 1060 SHA256: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1061 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 1062 0x00, 0x04, 0x20 1064 SHA384: 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1065 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 1066 0x00, 0x04, 0x30 1068 SHA512: 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1069 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 1070 0x00, 0x04, 0x40 1072 DSA signatures MUST use hashes with a size of 160 bits, to match q, 1073 the size of the group generated by the DSA key's generator value. 1074 The hash function result is treated as a 160 bit number and used 1075 directly in the DSA signature algorithm. 1077 5.2.3. Version 4 Signature Packet Format 1079 The body of a version 4 Signature Packet contains: 1081 - One-octet version number (4). 1083 - One-octet signature type. 1085 - One-octet public key algorithm. 1087 - One-octet hash algorithm. 1089 - Two-octet scalar octet count for following hashed subpacket 1090 data. Note that this is the length in octets of all of the 1091 hashed subpackets; a pointer incremented by this number will 1092 skip over the hashed subpackets. 1094 - Hashed subpacket data. (zero or more subpackets) 1096 - Two-octet scalar octet count for following unhashed subpacket 1097 data. Note that this is the length in octets of all of the 1098 unhashed subpackets; a pointer incremented by this number will 1099 skip over the unhashed subpackets. 1101 - Unhashed subpacket data. (zero or more subpackets) 1103 - Two-octet field holding left 16 bits of signed hash value. 1105 - One or more multi-precision integers comprising the signature. 1106 This portion is algorithm specific, as described above. 1108 The data being signed is hashed, and then the signature data from 1109 the version number through the hashed subpacket data (inclusive) is 1110 hashed. The resulting hash value is what is signed. The left 16 1111 bits of the hash are included in the signature packet to provide a 1112 quick test to reject some invalid signatures. 1114 There are two fields consisting of signature subpackets. The first 1115 field is hashed with the rest of the signature data, while the 1116 second is unhashed. The second set of subpackets is not 1117 cryptographically protected by the signature and should include only 1118 advisory information. 1120 The algorithms for converting the hash function result to a 1121 signature are described in a section below. 1123 5.2.3.1. Signature Subpacket Specification 1125 The subpacket fields consist of zero or more signature subpackets. 1126 Each set of subpackets is preceded by a two-octet scalar count of 1127 the length of the set of subpackets. 1129 Each subpacket consists of a subpacket header and a body. The 1130 header consists of: 1132 - the subpacket length (1, 2, or 5 octets) 1134 - the subpacket type (1 octet) 1136 and is followed by the subpacket specific data. 1138 The length includes the type octet but not this length. Its format 1139 is similar to the "new" format packet header lengths, but cannot 1140 have partial body lengths. That is: 1142 if the 1st octet < 192, then 1143 lengthOfLength = 1 1144 subpacketLen = 1st_octet 1146 if the 1st octet >= 192 and < 255, then 1147 lengthOfLength = 2 1148 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1150 if the 1st octet = 255, then 1151 lengthOfLength = 5 1152 subpacket length = [four-octet scalar starting at 2nd_octet] 1154 The value of the subpacket type octet may be: 1156 2 = signature creation time 1157 3 = signature expiration time 1158 4 = exportable certification 1159 5 = trust signature 1160 6 = regular expression 1161 7 = revocable 1162 9 = key expiration time 1163 10 = placeholder for backward compatibility 1164 11 = preferred symmetric algorithms 1165 12 = revocation key 1166 16 = issuer key ID 1167 20 = notation data 1168 21 = preferred hash algorithms 1169 22 = preferred compression algorithms 1170 23 = key server preferences 1171 24 = preferred key server 1172 25 = primary user id 1173 26 = policy URL 1174 27 = key flags 1175 28 = signer's user id 1176 29 = reason for revocation 1177 30 = features 1178 31 = signature target 1180 100 to 110 = internal or user-defined 1182 An implementation SHOULD ignore any subpacket of a type that it does 1183 not recognize. 1185 Bit 7 of the subpacket type is the "critical" bit. If set, it 1186 denotes that the subpacket is one that is critical for the evaluator 1187 of the signature to recognize. If a subpacket is encountered that 1188 is marked critical but is unknown to the evaluating software, the 1189 evaluator SHOULD consider the signature to be in error. 1191 An evaluator may "recognize" a subpacket, but not implement it. The 1192 purpose of the critical bit is to allow the signer to tell an 1193 evaluator that it would prefer a new, unknown feature to generate an 1194 error than be ignored. 1196 Implementations SHOULD implement "preferences" and the "reason for 1197 revocation" subpackets. Note, however, that if an implementation 1198 chooses not to implement some of the preferences, it is required to 1199 behave in a polite manner to respect the wishes of those users who 1200 do implement these preferences. 1202 5.2.3.2. Signature Subpacket Types 1204 A number of subpackets are currently defined. Some subpackets apply 1205 to the signature itself and some are attributes of the key. 1206 Subpackets that are found on a self-signature are placed on a user 1207 id certification made by the key itself. Note that a key may have 1208 more than one user id, and thus may have more than one 1209 self-signature, and differing subpackets. 1211 A subpacket may be found either in the hashed or unhashed subpacket 1212 sections of a signature. If a subpacket is not hashed, then the 1213 information in it cannot be considered definitive because it is not 1214 part of the signature proper. 1216 5.2.3.3. Notes on Self-Signatures 1218 A self-signature is a binding signature made by the key the 1219 signature refers to. There are three types of self-signatures, the 1220 certification signatures (types 0x10-0x13), the direct-key signature 1221 (type 0x1f), and the subkey binding signature (type 0x18). For 1222 certification self-signatures, each user ID may have a 1223 self-signature, and thus different subpackets in those 1224 self-signatures. For subkey binding signatures, each subkey in fact 1225 has a self-signature. Subpackets that appear in a certification 1226 self-signature apply to the username, and subpackets that appear in 1227 the subkey self-signature apply to the subkey. Lastly, subpackets on 1228 the direct-key signature apply to the entire key. 1230 Implementing software should interpret a self-signature's preference 1231 subpackets as narrowly as possible. For example, suppose a key has 1232 two usernames, Alice and Bob. Suppose that Alice prefers the 1233 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If 1234 the software locates this key via Alice's name, then the preferred 1235 algorithm is CAST5, if software locates the key via Bob's name, then 1236 the preferred algorithm is IDEA. If the key is located by key id, 1237 then algorithm of the default user id of the key provides the 1238 default symmetric algorithm. 1240 Revoking a self-signature or allowing it to expire has a semantic 1241 meaning that varies with the signature type. Revoking the 1242 self-signature on a user ID effectively retires that user name. The 1243 self-signature is a statement, "My name X is tied to my signing key 1244 K" and is corroborated by other users' certifications. If another 1245 user revokes their certification, they are effectively saying that 1246 they no longer believe that name and that key are tied together. 1247 Similarly, if the user themselves revokes their self-signature, it 1248 means the user no longer goes by that name, no longer has that email 1249 address, etc. Revoking a binding signature effectively retires that 1250 subkey. Revoking a direct-key signature cancels that signature. 1251 Please see the "Reason for Revocation" subpacket below for more 1252 relevant detail. 1254 Since a self-signature contains important information about the 1255 key's use, an implementation SHOULD allow the user to rewrite the 1256 self-signature, and important information in it, such as preferences 1257 and key expiration. 1259 An implementation that encounters multiple self-signatures on the 1260 same object may resolve the ambiguity in any way it sees fit, but it 1261 is RECOMMENDED that priority be given to the most recent 1262 self-signature. 1264 5.2.3.4. Signature creation time 1266 (4 octet time field) 1268 The time the signature was made. 1270 MUST be present in the hashed area. 1272 5.2.3.5. Issuer 1274 (8 octet key ID) 1276 The OpenPGP key ID of the key issuing the signature. 1278 5.2.3.6. Key expiration time 1280 (4 octet time field) 1282 The validity period of the key. This is the number of seconds after 1283 the key creation time that the key expires. If this is not present 1284 or has a value of zero, the key never expires. This is found only on 1285 a self-signature. 1287 5.2.3.7. Preferred symmetric algorithms 1289 (sequence of one-octet values) 1291 Symmetric algorithm numbers that indicate which algorithms the key 1292 holder prefers to use. The subpacket body is an ordered list of 1293 octets with the most preferred listed first. It is assumed that only 1294 algorithms listed are supported by the recipient's software. 1295 Algorithm numbers in section 9. This is only found on a 1296 self-signature. 1298 5.2.3.8. Preferred hash algorithms 1300 (array of one-octet values) 1302 Message digest algorithm numbers that indicate which algorithms the 1303 key holder prefers to receive. Like the preferred symmetric 1304 algorithms, the list is ordered. Algorithm numbers are in section 6. 1305 This is only found on a self-signature. 1307 5.2.3.9. Preferred compression algorithms 1309 (array of one-octet values) 1311 Compression algorithm numbers that indicate which algorithms the key 1312 holder prefers to use. Like the preferred symmetric algorithms, the 1313 list is ordered. Algorithm numbers are in section 6. If this 1314 subpacket is not included, ZIP is preferred. A zero denotes that 1315 uncompressed data is preferred; the key holder's software might have 1316 no compression software in that implementation. This is only found 1317 on a self-signature. 1319 5.2.3.10. Signature expiration time 1321 (4 octet time field) 1323 The validity period of the signature. This is the number of seconds 1324 after the signature creation time that the signature expires. If 1325 this is not present or has a value of zero, it never expires. 1327 5.2.3.11. Exportable Certification 1329 (1 octet of exportability, 0 for not, 1 for exportable) 1330 This subpacket denotes whether a certification signature is 1331 "exportable," to be used by other users than the signature's issuer. 1332 The packet body contains a Boolean flag indicating whether the 1333 signature is exportable. If this packet is not present, the 1334 certification is exportable; it is equivalent to a flag containing a 1335 1. 1337 Non-exportable, or "local," certifications are signatures made by a 1338 user to mark a key as valid within that user's implementation only. 1339 Thus, when an implementation prepares a user's copy of a key for 1340 transport to another user (this is the process of "exporting" the 1341 key), any local certification signatures are deleted from the key. 1343 The receiver of a transported key "imports" it, and likewise trims 1344 any local certifications. In normal operation, there won't be any, 1345 assuming the import is performed on an exported key. However, there 1346 are instances where this can reasonably happen. For example, if an 1347 implementation allows keys to be imported from a key database in 1348 addition to an exported key, then this situation can arise. 1350 Some implementations do not represent the interest of a single user 1351 (for example, a key server). Such implementations always trim local 1352 certifications from any key they handle. 1354 5.2.3.12. Revocable 1356 (1 octet of revocability, 0 for not, 1 for revocable) 1358 Signature's revocability status. Packet body contains a Boolean 1359 flag indicating whether the signature is revocable. Signatures that 1360 are not revocable have any later revocation signatures ignored. 1361 They represent a commitment by the signer that he cannot revoke his 1362 signature for the life of his key. If this packet is not present, 1363 the signature is revocable. 1365 5.2.3.13. Trust signature 1367 (1 octet "level" (depth), 1 octet of trust amount) 1369 Signer asserts that the key is not only valid, but also trustworthy, 1370 at the specified level. Level 0 has the same meaning as an ordinary 1371 validity signature. Level 1 means that the signed key is asserted 1372 to be a valid trusted introducer, with the 2nd octet of the body 1373 specifying the degree of trust. Level 2 means that the signed key is 1374 asserted to be trusted to issue level 1 trust signatures, i.e. that 1375 it is a "meta introducer". Generally, a level n trust signature 1376 asserts that a key is trusted to issue level n-1 trust signatures. 1377 The trust amount is in a range from 0-255, interpreted such that 1378 values less than 120 indicate partial trust and values of 120 or 1379 greater indicate complete trust. Implementations SHOULD emit values 1380 of 60 for partial trust and 120 for complete trust. 1382 5.2.3.14. Regular expression 1384 (null-terminated regular expression) 1386 Used in conjunction with trust signature packets (of level > 0) to 1387 limit the scope of trust that is extended. Only signatures by the 1388 target key on user IDs that match the regular expression in the body 1389 of this packet have trust extended by the trust signature subpacket. 1390 The regular expression uses the same syntax as the Henry Spencer's 1391 "almost public domain" regular expression package. A description of 1392 the syntax is found in a section below. 1394 5.2.3.15. Revocation key 1396 (1 octet of class, 1 octet of algid, 20 octets of fingerprint) 1398 Authorizes the specified key to issue revocation signatures for this 1399 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1400 then this means that the revocation information is sensitive. Other 1401 bits are for future expansion to other kinds of authorizations. This 1402 is found on a self-signature. 1404 If the "sensitive" flag is set, the keyholder feels this subpacket 1405 contains private trust information that describes a real-world 1406 sensitive relationship. If this flag is set, implementations SHOULD 1407 NOT export this signature to other users except in cases where the 1408 data needs to be available: when the signature is being sent to the 1409 designated revoker, or when it is accompanied by a revocation 1410 signature from that revoker. Note that it may be appropriate to 1411 isolate this subpacket within a separate signature so that it is not 1412 combined with other subpackets that need to be exported. 1414 5.2.3.16. Notation Data 1416 (4 octets of flags, 2 octets of name length (M), 1417 2 octets of value length (N), 1418 M octets of name data, 1419 N octets of value data) 1421 This subpacket describes a "notation" on the signature that the 1422 issuer wishes to make. The notation has a name and a value, each of 1423 which are strings of octets. There may be more than one notation in 1424 a signature. Notations can be used for any extension the issuer of 1425 the signature cares to make. The "flags" field holds four octets of 1426 flags. 1428 All undefined flags MUST be zero. Defined flags are: 1430 First octet: 0x80 = human-readable. This note value is text, a 1431 note from one person to another, and need 1432 not have meaning to software. 1433 Other octets: none. 1435 Notation names are arbitrary strings encoded in UTF-8. They reside 1436 two name spaces: The IETF name space and the user name space. 1438 The IETF name space is registered with IANA. These names MUST NOT 1439 contain the "@" character (0x40) is this is a tag for the user name 1440 space. 1442 Names in the user name space consist of a UTF-8 string tag followed 1443 by "@" followed by a DNS domain name. Note that the tag MUST NOT 1444 contain an "@" character. For example, the "sample" tag used by 1445 Example Corporation could be "sample@example.com". 1447 Names in a user space are owned and controlled by the owners of that 1448 domain. Obviously, it's of bad form to create a new name in a DNS 1449 space that you don't own. 1451 Since the user name space is in the form of an email address, 1452 implementers MAY wish to arrange for that address to reach a person 1453 who can be consulted about the use of the named tag. Note that due 1454 to UTF-8 encoding, not all valid user space name tags are valid 1455 email addresses. 1457 5.2.3.17. Key server preferences 1459 (N octets of flags) 1461 This is a list of flags that indicate preferences that the key 1462 holder has about how the key is handled on a key server. All 1463 undefined flags MUST be zero. 1465 First octet: 0x80 = No-modify 1466 the key holder requests that this key only be modified or 1467 updated by the key holder or an administrator of the key server. 1469 This is found only on a self-signature. 1471 5.2.3.18. Preferred key server 1473 (String) 1475 This is a URL of a key server that the key holder prefers be used 1476 for updates. Note that keys with multiple user ids can have a 1477 preferred key server for each user id. Note also that since this is 1478 a URL, the key server can actually be a copy of the key retrieved by 1479 ftp, http, finger, etc. 1481 5.2.3.19. Primary user id 1483 (1 octet, Boolean) 1484 This is a flag in a user id's self signature that states whether 1485 this user id is the main user id for this key. It is reasonable for 1486 an implementation to resolve ambiguities in preferences, etc. by 1487 referring to the primary user id. If this flag is absent, its value 1488 is zero. If more than one user id in a key is marked as primary, the 1489 implementation may resolve the ambiguity in any way it sees fit, but 1490 it is RECOMMENDED that priority be given to the user ID with the 1491 most recent self-signature. 1493 When appearing on a self-signature on a User ID packet, this 1494 subpacket applies only to User ID packets. When appearing on a 1495 self-signature on a User Attribute packet, this subpacket applies 1496 only to User Attribute packets. That is to say, there are two 1497 different and independent "primaries" - one for User IDs, and one 1498 for User Attributes. 1500 5.2.3.20. Policy URL 1502 (String) 1504 This subpacket contains a URL of a document that describes the 1505 policy that the signature was issued under. 1507 5.2.3.21. Key Flags 1509 (N octets of flags) 1511 This subpacket contains a list of binary flags that hold information 1512 about a key. It is a string of octets, and an implementation MUST 1513 NOT assume a fixed size. This is so it can grow over time. If a list 1514 is shorter than an implementation expects, the unstated flags are 1515 considered to be zero. The defined flags are: 1517 First octet: 1519 0x01 - This key may be used to certify other keys. 1521 0x02 - This key may be used to sign data. 1523 0x04 - This key may be used to encrypt communications. 1525 0x08 - This key may be used to encrypt storage. 1527 0x10 - The private component of this key may have been split by 1528 a secret-sharing mechanism. 1530 0x80 - The private component of this key may be in the 1531 possession of more than one person. 1533 Usage notes: 1535 The flags in this packet may appear in self-signatures or in 1536 certification signatures. They mean different things depending on 1537 who is making the statement -- for example, a certification 1538 signature that has the "sign data" flag is stating that the 1539 certification is for that use. On the other hand, the 1540 "communications encryption" flag in a self-signature is stating a 1541 preference that a given key be used for communications. Note 1542 however, that it is a thorny issue to determine what is 1543 "communications" and what is "storage." This decision is left wholly 1544 up to the implementation; the authors of this document do not claim 1545 any special wisdom on the issue, and realize that accepted opinion 1546 may change. 1548 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1549 self-signature only; they are meaningless on a certification 1550 signature. They SHOULD be placed only on a direct-key signature 1551 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1552 the key the flag applies to. 1554 5.2.3.22. Signer's User ID 1556 (String) 1558 This subpacket allows a keyholder to state which user id is 1559 responsible for the signing. Many keyholders use a single key for 1560 different purposes, such as business communications as well as 1561 personal communications. This subpacket allows such a keyholder to 1562 state which of their roles is making a signature. 1564 This subpacket is not appropriate to use to refer to a User 1565 Attribute packet. 1567 5.2.3.23. Reason for Revocation 1569 (1 octet of revocation code, N octets of reason string) 1571 This subpacket is used only in key revocation and certification 1572 revocation signatures. It describes the reason why the key or 1573 certificate was revoked. 1575 The first octet contains a machine-readable code that denotes the 1576 reason for the revocation: 1578 0x00 - No reason specified (key revocations or cert revocations) 1579 0x01 - Key is superceded (key revocations) 1580 0x02 - Key material has been compromised (key revocations) 1581 0x03 - Key is retired and no longer used (key revocations) 1582 0x20 - User id information is no longer valid (cert revocations) 1584 Following the revocation code is a string of octets which gives 1585 information about the reason for revocation in human-readable form 1586 (UTF-8). The string may be null, that is, of zero length. The length 1587 of the subpacket is the length of the reason string plus one. 1589 An implementation SHOULD implement this subpacket, include it in all 1590 revocation signatures, and interpret revocations appropriately. 1591 There are important semantic differences between the reasons, and 1592 there are thus important reasons for revoking signatures. 1594 If a key has been revoked because of a compromise, all signatures 1595 created by that key are suspect. However, if it was merely 1596 superceded or retired, old signatures are still valid. If the 1597 revoked signature is the self-signature for certifying a user id, a 1598 revocation denotes that that user name is no longer in use. Such a 1599 revocation SHOULD include an 0x20 subpacket. 1601 Note that any signature may be revoked, including a certification on 1602 some other person's key. There are many good reasons for revoking a 1603 certification signature, such as the case where the keyholder leaves 1604 the employ of a business with an email address. A revoked 1605 certification no longer is a part of validity calculations. 1607 5.2.3.24. Features 1609 (N octets of flags) 1611 The features subpacket denotes which advanced OpenPGP features a 1612 user's implementation supports. This is so that as features are 1613 added to OpenPGP that cannot be backwards-compatible, a user can 1614 state that they can use that feature. 1616 This subpacket is similar to a preferences subpacket, and only 1617 appears in a self-signature. 1619 An implementation SHOULD NOT use a feature listed when sending to a 1620 user who does not state that they can use it. 1622 Defined features are: 1624 First octet: 1626 0x01 - Modification Detection (packets 18 and 19) 1628 If an implementation implements any of the defined features, it 1629 SHOULD implement the features subpacket, too. 1631 In the case of Modification Detection, an implementation may freely 1632 infer this feature from other suitable implementation-dependent 1633 mechanisms. 1635 5.2.3.25. Signature Target 1637 (1 octet PK algorithm, 1 octet hash algorithm, N octets hash) 1638 This subpacket identifies a specific target signature that a 1639 signature refers to. For revocation signatures, this subpacket 1640 provides explicit designation of which signature is being revoked. 1641 For a notary or timestamp signature, this designates what signature 1642 is signed. All arguments are an identifier of that target signature. 1644 The N octets of hash data MUST be the size of the hash of the 1645 signature. For example, a target signature with a SHA-1 hash MUST 1646 have 20 octets of hash data. 1648 5.2.4. Computing Signatures 1650 All signatures are formed by producing a hash over the signature 1651 data, and then using the resulting hash in the signature algorithm. 1653 The signature data is simple to compute for document signatures 1654 (types 0x00 and 0x01), for which the document itself is the data. 1655 For standalone signatures, this is a null string. 1657 When a signature is made over a key, the hash data starts with the 1658 octet 0x99, followed by a two-octet length of the key, and then body 1659 of the key packet. (Note that this is an old-style packet header for 1660 a key packet with two-octet length.) A subkey signature (type 0x18) 1661 then hashes the subkey, using the same format as the main key (also 1662 using 0x99 as the first octet). Key revocation signatures (types 1663 0x20 and 0x28) hash only the key being revoked. 1665 A certification signature (type 0x10 through 0x13) hashes the user 1666 id being bound to the key into the hash context after the above 1667 data. A V3 certification hashes the contents of the name packet, 1668 without any header. A V4 certification hashes the constant 0xb4 for 1669 user ID certifications or the constant 0xd1 for User Attribute 1670 certifications (which are old-style packet headers with the 1671 length-of-length set to zero), followed by a four-octet number 1672 giving the length of the user ID or User Attribute data, and then 1673 the User ID or User Attribute data. 1675 Once the data body is hashed, then a trailer is hashed. A V3 1676 signature hashes five octets of the packet body, starting from the 1677 signature type field. This data is the signature type, followed by 1678 the four-octet signature time. A V4 signature hashes the packet body 1679 starting from its first field, the version number, through the end 1680 of the hashed subpacket data. Thus, the fields hashed are the 1681 signature version, the signature type, the public key algorithm, the 1682 hash algorithm, the hashed subpacket length, and the hashed 1683 subpacket body. 1685 V4 signatures also hash in a final trailer of six octets: the 1686 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1687 big-endian number that is the length of the hashed data from the 1688 signature packet (note that this number does not include these final 1689 six octets. 1691 After all this has been hashed, the resulting hash field is used in 1692 the signature algorithm, and placed at the end of the signature 1693 packet. 1695 5.2.4.1. Subpacket Hints 1697 An implementation SHOULD put the two mandatory subpackets, creation 1698 time and issuer, as the first subpackets in the subpacket list, 1699 simply to make it easier for the implementer to find them. 1701 It is certainly possible for a signature to contain conflicting 1702 information in subpackets. For example, a signature may contain 1703 multiple copies of a preference or multiple expiration times. In 1704 most cases, an implementation SHOULD use the last subpacket in the 1705 signature, but MAY use any conflict resolution scheme that makes 1706 more sense. Please note that we are intentionally leaving conflict 1707 resolution to the implementer; most conflicts are simply syntax 1708 errors, and the wishy-washy language here allows a receiver to be 1709 generous in what they accept, while putting pressure on a creator to 1710 be stingy in what they generate. 1712 Some apparent conflicts may actually make sense -- for example, 1713 suppose a keyholder has an V3 key and a V4 key that share the same 1714 RSA key material. Either of these keys can verify a signature 1715 created by the other, and it may be reasonable for a signature to 1716 contain an issuer subpacket for each key, as a way of explicitly 1717 tying those keys to the signature. 1719 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) 1721 The Symmetric-Key Encrypted Session Key packet holds the 1722 symmetric-key encryption of a session key used to encrypt a message. 1723 Zero or more Encrypted Session Key packets and/or Symmetric-Key 1724 Encrypted Session Key packets may precede a Symmetrically Encrypted 1725 Data Packet that holds an encrypted message. The message is 1726 encrypted with a session key, and the session key is itself 1727 encrypted and stored in the Encrypted Session Key packet or the 1728 Symmetric-Key Encrypted Session Key packet. 1730 If the Symmetrically Encrypted Data Packet is preceded by one or 1731 more Symmetric-Key Encrypted Session Key packets, each specifies a 1732 passphrase that may be used to decrypt the message. This allows a 1733 message to be encrypted to a number of public keys, and also to one 1734 or more pass phrases. This packet type is new, and is not generated 1735 by PGP 2.x or PGP 5.0. 1737 The body of this packet consists of: 1739 - A one-octet version number. The only currently defined version 1740 is 4. 1742 - A one-octet number describing the symmetric algorithm used. 1744 - A string-to-key (S2K) specifier, length as defined above. 1746 - Optionally, the encrypted session key itself, which is decrypted 1747 with the string-to-key object. 1749 If the encrypted session key is not present (which can be detected 1750 on the basis of packet length and S2K specifier size), then the S2K 1751 algorithm applied to the passphrase produces the session key for 1752 decrypting the file, using the symmetric cipher algorithm from the 1753 Symmetric-Key Encrypted Session Key packet. 1755 If the encrypted session key is present, the result of applying the 1756 S2K algorithm to the passphrase is used to decrypt just that 1757 encrypted session key field, using CFB mode with an IV of all zeros. 1758 The decryption result consists of a one-octet algorithm identifier 1759 that specifies the symmetric-key encryption algorithm used to 1760 encrypt the following Symmetrically Encrypted Data Packet, followed 1761 by the session key octets themselves. 1763 Note: because an all-zero IV is used for this decryption, the S2K 1764 specifier MUST use a salt value, either a Salted S2K or an 1765 Iterated-Salted S2K. The salt value will insure that the decryption 1766 key is not repeated even if the passphrase is reused. 1768 5.4. One-Pass Signature Packets (Tag 4) 1770 The One-Pass Signature packet precedes the signed data and contains 1771 enough information to allow the receiver to begin calculating any 1772 hashes needed to verify the signature. It allows the Signature 1773 Packet to be placed at the end of the message, so that the signer 1774 can compute the entire signed message in one pass. 1776 A One-Pass Signature does not interoperate with PGP 2.6.x or 1777 earlier. 1779 The body of this packet consists of: 1781 - A one-octet version number. The current version is 3. 1783 - A one-octet signature type. Signature types are described in 1784 section 5.2.1. 1786 - A one-octet number describing the hash algorithm used. 1788 - A one-octet number describing the public key algorithm used. 1790 - An eight-octet number holding the key ID of the signing key. 1792 - A one-octet number holding a flag showing whether the signature 1793 is nested. A zero value indicates that the next packet is 1794 another One-Pass Signature packet that describes another 1795 signature to be applied to the same message data. 1797 Note that if a message contains more than one one-pass signature, 1798 then the signature packets bracket the message; that is, the first 1799 signature packet after the message corresponds to the last one-pass 1800 packet and the final signature packet corresponds to the first 1801 one-pass packet. 1803 5.5. Key Material Packet 1805 A key material packet contains all the information about a public or 1806 private key. There are four variants of this packet type, and two 1807 major versions. Consequently, this section is complex. 1809 5.5.1. Key Packet Variants 1811 5.5.1.1. Public Key Packet (Tag 6) 1813 A Public Key packet starts a series of packets that forms an OpenPGP 1814 key (sometimes called an OpenPGP certificate). 1816 5.5.1.2. Public Subkey Packet (Tag 14) 1818 A Public Subkey packet (tag 14) has exactly the same format as a 1819 Public Key packet, but denotes a subkey. One or more subkeys may be 1820 associated with a top-level key. By convention, the top-level key 1821 provides signature services, and the subkeys provide encryption 1822 services. 1824 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1825 packet. This tag was selected for reuse because no previous version 1826 of PGP ever emitted comment packets but they did properly ignore 1827 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1828 cause it to fail, providing a limited degree of backward 1829 compatibility. 1831 5.5.1.3. Secret Key Packet (Tag 5) 1833 A Secret Key packet contains all the information that is found in a 1834 Public Key packet, including the public key material, but also 1835 includes the secret key material after all the public key fields. 1837 5.5.1.4. Secret Subkey Packet (Tag 7) 1839 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1840 Key packet, and has exactly the same format. 1842 5.5.2. Public Key Packet Formats 1844 There are two versions of key-material packets. Version 3 packets 1845 were first generated by PGP 2.6. Version 2 packets are identical in 1846 format to Version 3 packets, but are generated by PGP 2.5 or before. 1847 V2 packets are deprecated and they MUST NOT be generated. 1849 PGP 5.0 introduced version 4 packets, with new fields and semantics. 1850 PGP 2.6.x will not accept key-material packets with versions 1851 greater than 3. 1853 OpenPGP implementations SHOULD create keys with version 4 format. An 1854 implementation MAY generate a V3 key to ensure interoperability with 1855 old software; note, however, that V4 keys correct some security 1856 deficiencies in V3 keys. These deficiencies are described below. An 1857 implementation MUST NOT create a V3 key with a public key algorithm 1858 other than RSA. 1860 A version 3 public key or public subkey packet contains: 1862 - A one-octet version number (3). 1864 - A four-octet number denoting the time that the key was created. 1866 - A two-octet number denoting the time in days that this key is 1867 valid. If this number is zero, then it does not expire. 1869 - A one-octet number denoting the public key algorithm of this key 1871 - A series of multi-precision integers comprising the key 1872 material: 1874 - a multiprecision integer (MPI) of RSA public modulus n; 1876 - an MPI of RSA public encryption exponent e. 1878 V3 keys SHOULD only be used for backward compatibility because of 1879 three weaknesses in them. First, it is relatively easy to construct 1880 a V3 key that has the same key ID as any other key because the key 1881 ID is simply the low 64 bits of the public modulus. Secondly, 1882 because the fingerprint of a V3 key hashes the key material, but not 1883 its length, which increases the opportunity for fingerprint 1884 collisions. Third, there are minor weaknesses in the MD5 hash 1885 algorithm that make developers prefer other algorithms. See below 1886 for a fuller discussion of key IDs and fingerprints. 1888 The version 4 format is similar to the version 3 format except for 1889 the absence of a validity period. This has been moved to the 1890 signature packet. In addition, fingerprints of version 4 keys are 1891 calculated differently from version 3 keys, as described in section 1892 "Enhanced Key Formats." 1893 A version 4 packet contains: 1895 - A one-octet version number (4). 1897 - A four-octet number denoting the time that the key was created. 1899 - A one-octet number denoting the public key algorithm of this key 1901 - A series of multi-precision integers comprising the key 1902 material. This algorithm-specific portion is: 1904 Algorithm Specific Fields for RSA public keys: 1906 - multiprecision integer (MPI) of RSA public modulus n; 1908 - MPI of RSA public encryption exponent e. 1910 Algorithm Specific Fields for DSA public keys: 1912 - MPI of DSA prime p; 1914 - MPI of DSA group order q (q is a prime divisor of p-1); 1916 - MPI of DSA group generator g; 1918 - MPI of DSA public key value y (= g**x mod p where x is 1919 secret). 1921 Algorithm Specific Fields for Elgamal public keys: 1923 - MPI of Elgamal prime p; 1925 - MPI of Elgamal group generator g; 1927 - MPI of Elgamal public key value y (= g**x mod p where x is 1928 secret). 1930 5.5.3. Secret Key Packet Formats 1932 The Secret Key and Secret Subkey packets contain all the data of the 1933 Public Key and Public Subkey packets, with additional 1934 algorithm-specific secret key data appended, in encrypted form. 1936 The packet contains: 1938 - A Public Key or Public Subkey packet, as described above 1940 - One octet indicating string-to-key usage conventions. 0 1941 indicates that the secret key data is not encrypted. 255 or 254 1942 indicates that a string-to-key specifier is being given. Any 1943 other value is a symmetric-key encryption algorithm identifier. 1945 - [Optional] If string-to-key usage octet was 255 or 254, a 1946 one-octet symmetric encryption algorithm. 1948 - [Optional] If string-to-key usage octet was 255 or 254, a 1949 string-to-key specifier. The length of the string-to-key 1950 specifier is implied by its type, as described above. 1952 - [Optional] If secret data is encrypted, Initial Vector (IV) of 1953 the same length as the cipher's block size. 1955 - Encrypted multi-precision integers comprising the secret key 1956 data. These algorithm-specific fields are as described below. 1958 - If the string-to-key usage octet was 255, then a two-octet 1959 checksum of the plaintext of the algorithm-specific portion (sum 1960 of all octets, mod 65536). If the string-to-key usage octet was 1961 254, then a 20-octet SHA-1 hash of the plaintext of the 1962 algorithm-specific portion. This checksum or hash is encrypted 1963 together with the algorithm-specific fields. 1965 Algorithm Specific Fields for RSA secret keys: 1967 - multiprecision integer (MPI) of RSA secret exponent d. 1969 - MPI of RSA secret prime value p. 1971 - MPI of RSA secret prime value q (p < q). 1973 - MPI of u, the multiplicative inverse of p, mod q. 1975 Algorithm Specific Fields for DSA secret keys: 1977 - MPI of DSA secret exponent x. 1979 Algorithm Specific Fields for Elgamal secret keys: 1981 - MPI of Elgamal secret exponent x. 1983 Secret MPI values can be encrypted using a passphrase. If a 1984 string-to-key specifier is given, that describes the algorithm for 1985 converting the passphrase to a key, else a simple MD5 hash of the 1986 passphrase is used. Implementations SHOULD use a string-to-key 1987 specifier; the simple hash is for backward compatibility. The cipher 1988 for encrypting the MPIs is specified in the secret key packet. 1990 Encryption/decryption of the secret data is done in CFB mode using 1991 the key created from the passphrase and the Initial Vector from the 1992 packet. A different mode is used with V3 keys (which are only RSA) 1993 than with other key formats. With V3 keys, the MPI bit count prefix 1994 (i.e., the first two octets) is not encrypted. Only the MPI 1995 non-prefix data is encrypted. Furthermore, the CFB state is 1996 resynchronized at the beginning of each new MPI value, so that the 1997 CFB block boundary is aligned with the start of the MPI data. 1999 With V4 keys, a simpler method is used. All secret MPI values are 2000 encrypted in CFB mode, including the MPI bitcount prefix. 2002 The 16-bit checksum that follows the algorithm-specific portion is 2003 the algebraic sum, mod 65536, of the plaintext of all the 2004 algorithm-specific octets (including MPI prefix and data). With V3 2005 keys, the checksum is stored in the clear. With V4 keys, the 2006 checksum is encrypted like the algorithm-specific data. This value 2007 is used to check that the passphrase was correct. However, this 2008 checksum is deprecated; an implementation SHOULD NOT use it, but 2009 should rather use the SHA-1 hash denoted with a usage octet of 254. 2010 The reason for this is that there are some attacks on the private 2011 key that can undetectably modify the secret key. Using a SHA-1 hash 2012 prevents this. 2014 5.6. Compressed Data Packet (Tag 8) 2016 The Compressed Data packet contains compressed data. Typically, this 2017 packet is found as the contents of an encrypted packet, or following 2018 a Signature or One-Pass Signature packet, and contains literal data 2019 packets. 2021 The body of this packet consists of: 2023 - One octet that gives the algorithm used to compress the packet. 2025 - The remainder of the packet is compressed data. 2027 A Compressed Data Packet's body contains an block that compresses 2028 some set of packets. See section "Packet Composition" for details on 2029 how messages are formed. 2031 ZIP-compressed packets are compressed with raw RFC1951 DEFLATE 2032 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 2033 implementation uses more bits of compression, PGP V2.6 cannot 2034 decompress it. 2036 ZLIB-compressed packets are compressed with RFC1950 ZLIB-style 2037 blocks. 2039 5.7. Symmetrically Encrypted Data Packet (Tag 9) 2041 The Symmetrically Encrypted Data packet contains data encrypted with 2042 a symmetric-key algorithm. When it has been decrypted, it contains 2043 other packets (usually literal data packets or compressed data 2044 packets, but in theory other Symmetrically Encrypted Data Packets or 2045 sequences of packets that form whole OpenPGP messages). 2047 The body of this packet consists of: 2049 - Encrypted data, the output of the selected symmetric-key cipher 2050 operating in PGP's variant of Cipher Feedback (CFB) mode. 2052 The symmetric cipher used may be specified in an Public-Key or 2053 Symmetric-Key Encrypted Session Key packet that precedes the 2054 Symmetrically Encrypted Data Packet. In that case, the cipher 2055 algorithm octet is prefixed to the session key before it is 2056 encrypted. If no packets of these types precede the encrypted data, 2057 the IDEA algorithm is used with the session key calculated as the 2058 MD5 hash of the passphrase. 2060 The data is encrypted in CFB mode, with a CFB shift size equal to 2061 the cipher's block size. The Initial Vector (IV) is specified as 2062 all zeros. Instead of using an IV, OpenPGP prefixes a string of 2063 length equal to the block size of the cipher plus two to the data 2064 before it is encrypted. The first block-size octets (for example, 8 2065 octets for a 64-bit block length) are random, and the following two 2066 octets are copies of the last two octets of the IV. For example, in 2067 an 8 octet block, octet 9 is a repeat of octet 7, and octet 10 is a 2068 repeat of octet 8. In a cipher of length 16, octet 17 is a repeat of 2069 octet 15 and octet 18 is a repeat of octet 16. As a pedantic 2070 clarification, in both these examples, we consider the first octet 2071 to be numbered 1. 2073 After encrypting the first block-size-plus-two octets, the CFB state 2074 is resynchronized. The last block-size octets of ciphertext are 2075 passed through the cipher and the block boundary is reset. 2077 The repetition of 16 bits in the random data prefixed to the message 2078 allows the receiver to immediately check whether the session key is 2079 incorrect. 2081 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 2083 An experimental version of PGP used this packet as the Literal 2084 packet, but no released version of PGP generated Literal packets 2085 with this tag. With PGP 5.x, this packet has been re-assigned and is 2086 reserved for use as the Marker packet. 2088 The body of this packet consists of: 2090 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 2092 Such a packet MUST be ignored when received. It may be placed at 2093 the beginning of a message that uses features not available in PGP 2094 2.6.x in order to cause that version to report that newer software 2095 is necessary to process the message. 2097 5.9. Literal Data Packet (Tag 11) 2099 A Literal Data packet contains the body of a message; data that is 2100 not to be further interpreted. 2102 The body of this packet consists of: 2104 - A one-octet field that describes how the data is formatted. 2106 If it is a 'b' (0x62), then the literal packet contains binary data. 2107 If it is a 't' (0x74), then it contains text data, and thus may need 2108 line ends converted to local form, or other text-mode changes. 2110 Early versions of PGP also defined a value of 'l' as a 'local' mode 2111 for machine-local conversions. RFC 1991 incorrectly stated this 2112 local mode flag as '1' (ASCII numeral one). Both of these local 2113 modes are deprecated. 2115 - File name as a string (one-octet length, followed by file name), 2116 if the encrypted data should be saved as a file. 2118 If the special name "_CONSOLE" is used, the message is considered to 2119 be "for your eyes only". This advises that the message data is 2120 unusually sensitive, and the receiving program should process it 2121 more carefully, perhaps avoiding storing the received data to disk, 2122 for example. 2124 - A four-octet number that indicates the modification date of the 2125 file, or the creation time of the packet, or a zero that 2126 indicates the present time. 2128 - The remainder of the packet is literal data. 2130 Text data is stored with text endings (i.e. network-normal 2131 line endings). These should be converted to native line endings by 2132 the receiving software. 2134 5.10. Trust Packet (Tag 12) 2136 The Trust packet is used only within keyrings and is not normally 2137 exported. Trust packets contain data that record the user's 2138 specifications of which key holders are trustworthy introducers, 2139 along with other information that implementing software uses for 2140 trust information. 2142 Trust packets SHOULD NOT be emitted to output streams that are 2143 transferred to other users, and they SHOULD be ignored on any input 2144 other than local keyring files. 2146 5.11. User ID Packet (Tag 13) 2148 A User ID packet consists of data that is intended to represent the 2149 name and email address of the key holder. By convention, it 2150 includes an RFC822 mail name, but there are no restrictions on its 2151 content. The packet length in the header specifies the length of 2152 the user id. If it is text, it is encoded in UTF-8. 2154 5.12. User Attribute Packet (Tag 17) 2156 The User Attribute packet is a variation of the User ID packet. It 2157 is capable of storing more types of data than the User ID packet 2158 which is (by convention) limited to text. Like the User ID packet, 2159 a User Attribute packet may be certified by the key owner 2160 ("self-signed") or any other key owner who cares to certify it. 2161 Except as noted, a User Attribute packet may be used anywhere that a 2162 User ID packet may be used. 2164 While User Attribute packets are not a required part of the OpenPGP 2165 standard, implementations SHOULD provide at least enough 2166 compatibility to properly handle a certification signature on the 2167 User Attribute packet. A simple way to do this is by treating the 2168 User Attribute packet as a User ID packet with opaque contents, but 2169 an implementation may use any method desired. 2171 The User Attribute packet is made up of one or more attribute 2172 subpackets. Each subpacket consists of a subpacket header and a 2173 body. The header consists of: 2175 - the subpacket length (1, 2, or 5 octets) 2177 - the subpacket type (1 octet) 2179 and is followed by the subpacket specific data. 2181 The only currently defined subpacket type is 1, signifying an image. 2182 An implementation SHOULD ignore any subpacket of a type that it does 2183 not recognize. Subpacket types 100 through 110 are reserved for 2184 private or experimental use. 2186 5.12.1. The Image Attribute Subpacket 2188 The image attribute subpacket is used to encode an image, presumably 2189 (but not required to be) that of the key owner. 2191 The image attribute subpacket begins with an image header. The 2192 first two octets of the image header contain the length of the image 2193 header. Note that unlike other multi-byte numerical values in this 2194 document, due to an historical accident this value is encoded as a 2195 little-endian number. The image header length is followed by a 2196 single octet for the image header version. The only currently 2197 defined version of the image header is 1, which is a 16 octet image 2198 header. The first three octets of a version 1 image header are thus 2199 0x10 0x00 0x01. Also note that this is the same encoding used for 2200 signature subpackets 2201 The fourth octet of a version 1 image header designates the encoding 2202 format of the image. The only currently defined encoding format is 2203 the value 1 to indicate JPEG. Image format types 100 through 110 2204 are reserved for private or experimental use. The rest of the 2205 version 1 image header is made up of 12 reserved octets, all of 2206 which MUST be set to 0. 2208 The rest of the image subpacket contains the image itself. As the 2209 only currently defined image type is JPEG, the image is encoded in 2210 the JPEG File Interchange Format (JFIF), a standard file format for 2211 JPEG images. [JFIF] 2213 An implementation MAY try and determine the type of an image by 2214 examination of the image data if it is unable to handle a particular 2215 version of the image header or if a specified encoding format value 2216 is not recognized. 2218 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) 2220 The Symmetrically Encrypted Integrity Protected Data Packet is a 2221 variant of the Symmetrically Encrypted Data Packet. It is a new 2222 feature created for OpenPGP that addresses the problem of detecting 2223 a modification to encrypted data. It is used in combination with a 2224 Modification Detection Code Packet. 2226 There is a corresponding feature in the features signature subpacket 2227 that denotes that an implementation can properly use this packet 2228 type. An implementation SHOULD prefer this to the older 2229 Symmetrically Encrypted Data Packet when possible. Since this data 2230 packet protects against modification attacks, this standard 2231 encourages its proliferation. While blanket adoption of this data 2232 packet would create interoperability problems, rapid adoption is 2233 nevertheless important. An implementation SHOULD specifically denote 2234 support for this packet, but it MAY infer it from other mechanisms. 2236 For example, an implementation might infer from the use of a cipher 2237 such as AES or Twofish that a user supports this feature. It might 2238 place in the unhashed portion of another user's key signature a 2239 features subpacket. It might also present a user with an opportunity 2240 to regenerate their own self-signature with a features subpacket. 2242 This packet contains data encrypted with a symmetric-key algorithm 2243 and protected against modification by the SHA-1 hash algorithm. When 2244 it has been decrypted, it will typically contain other packets 2245 (often literal data packets or compressed data packets). The last 2246 decrypted packet in this packet's payload MUST be a Modification 2247 Detection Code packet. 2249 The body of this packet consists of: 2251 - A one-octet version number. The only currently defined value is 2252 1. 2254 - Encrypted data, the output of the selected symmetric-key cipher 2255 operating in Cipher Feedback mode with shift amount equal to the 2256 block size of the cipher (CFB-n where n is the block size). 2258 The symmetric cipher used MUST be specified in a Public-Key or 2259 Symmetric-Key Encrypted Session Key packet that precedes the 2260 Symmetrically Encrypted Data Packet. In either case, the cipher 2261 algorithm octet is prefixed to the session key before it is 2262 encrypted. 2264 The data is encrypted in CFB mode, with a CFB shift size equal to 2265 the cipher's block size. The Initial Vector (IV) is specified as 2266 all zeros. Instead of using an IV, OpenPGP prefixes an octet string 2267 to the data before it is encrypted. The length of the octet string 2268 equals the block size of the cipher in octets, plus two. The first 2269 octets in the group, of length equal to the block size of the 2270 cipher, are random; the last two octets are each copies of their 2nd 2271 preceding octet. For example, with a cipher whose block size is 128 2272 bits or 16 octets, the prefix data will contain 16 random octets, 2273 then two more octets, which are copies of the 15th and 16th octets, 2274 respectively. Unlike the Symmetrically Encrypted Data Packet, no 2275 special CFB resynchronization is done after encrypting this prefix 2276 data. 2278 The repetition of 16 bits in the random data prefixed to the message 2279 allows the receiver to immediately check whether the session key is 2280 incorrect. 2282 The plaintext of the data to be encrypted is passed through the 2283 SHA-1 hash function, and the result of the hash is appended to the 2284 plaintext in a Modification Detection Code packet. The input to the 2285 hash function includes the prefix data described above; it includes 2286 all of the plaintext, and then also includes two octets of values 2287 0xD3, 0x14. These represent the encoding of a Modification 2288 Detection Code packet tag and length field of 20 octets. 2290 The resulting hash value is stored in a Modification Detection Code 2291 packet which MUST use the two octet encoding just given to represent 2292 its tag and length field. The body of the MDC packet is the 20 2293 octet output of the SHA-1 hash. 2295 The Modification Detection Code packet is appended to the plaintext 2296 and encrypted along with the plaintext using the same CFB context. 2298 During decryption, the plaintext data should be hashed with SHA-1, 2299 including the prefix data as well as the packet tag and length field 2300 of the Modification Detection Code packet. The body of the MDC 2301 packet, upon decryption, is compared with the result of the SHA-1 2302 hash. Any difference in hash values is an indication that the 2303 message has been modified and SHOULD be reported to the user. 2304 Likewise, the absence of an MDC packet, or an MDC packet in any 2305 position other than the end of the plaintext, also represent message 2306 modifications and SHOULD also be reported. 2308 Note: future designs of new versions of this packet should consider 2309 rollback attacks since it will be possible for an attacker to change 2310 the version back to 1. 2312 5.14. Modification Detection Code Packet (Tag 19) 2314 The Modification Detection Code packet contains a SHA-1 hash of 2315 plaintext data which is used to detect message modification. It is 2316 only used with a Symmetrically Encrypted Integrity Protected Data 2317 packet. The Modification Detection Code packet MUST be the last 2318 packet in the plaintext data which is encrypted in the Symmetrically 2319 Encrypted Integrity Protected Data packet, and MUST appear in no 2320 other place. 2322 A Modification Detection Code packet MUST have a length of 20 2323 octets. 2325 The body of this packet consists of: 2327 - A 20-octet SHA-1 hash of the preceding plaintext data of the 2328 Symmetrically Encrypted Integrity Protected Data packet, not 2329 including prefix data but including the tag and length byte of 2330 the Modification Detection Code packet. 2332 Note that the Modification Detection Code packet MUST always use a 2333 new-format encoding of the packet tag, and a one-octet encoding of 2334 the packet length. The reason for this is that the hashing rules for 2335 modification detection include a one-octet tag and one-octet length 2336 in the data hash. While this is a bit restrictive, it reduces 2337 complexity. 2339 6. Radix-64 Conversions 2341 As stated in the introduction, OpenPGP's underlying native 2342 representation for objects is a stream of arbitrary octets, and some 2343 systems desire these objects to be immune to damage caused by 2344 character set translation, data conversions, etc. 2346 In principle, any printable encoding scheme that met the 2347 requirements of the unsafe channel would suffice, since it would not 2348 change the underlying binary bit streams of the native OpenPGP data 2349 structures. The OpenPGP standard specifies one such printable 2350 encoding scheme to ensure interoperability. 2352 OpenPGP's Radix-64 encoding is composed of two parts: a base64 2353 encoding of the binary data, and a checksum. The base64 encoding is 2354 identical to the MIME base64 content-transfer-encoding [RFC 2045]. 2356 An OpenPGP implementation MAY use ASCII Armor to protect the raw 2357 binary data. 2359 The checksum is a 24-bit CRC converted to four characters of 2360 radix-64 encoding by the same MIME base64 transformation, preceded 2361 by an equals sign (=). The CRC is computed by using the generator 2362 0x864CFB and an initialization of 0xB704CE. The accumulation is 2363 done on the data before it is converted to radix-64, rather than on 2364 the converted data. A sample implementation of this algorithm is in 2365 the next section. 2367 The checksum with its leading equal sign MAY appear on the first 2368 line after the Base64 encoded data. 2370 Rationale for CRC-24: The size of 24 bits fits evenly into printable 2371 base64. The nonzero initialization can detect more errors than a 2372 zero initialization. 2374 6.1. An Implementation of the CRC-24 in "C" 2376 #define CRC24_INIT 0xb704ceL 2377 #define CRC24_POLY 0x1864cfbL 2379 typedef long crc24; 2380 crc24 crc_octets(unsigned char *octets, size_t len) 2381 { 2382 crc24 crc = CRC24_INIT; 2383 int i; 2385 while (len--) { 2386 crc ^= (*octets++) << 16; 2387 for (i = 0; i < 8; i++) { 2388 crc <<= 1; 2389 if (crc & 0x1000000) 2390 crc ^= CRC24_POLY; 2391 } 2392 } 2393 return crc & 0xffffffL; 2394 } 2396 6.2. Forming ASCII Armor 2398 When OpenPGP encodes data into ASCII Armor, it puts specific headers 2399 around the data, so OpenPGP can reconstruct the data later. OpenPGP 2400 informs the user what kind of data is encoded in the ASCII armor 2401 through the use of the headers. 2403 Concatenating the following data creates ASCII Armor: 2405 - An Armor Header Line, appropriate for the type of data 2406 - Armor Headers 2408 - A blank (zero-length, or containing only whitespace) line 2410 - The ASCII-Armored data 2412 - An Armor Checksum 2414 - The Armor Tail, which depends on the Armor Header Line. 2416 An Armor Header Line consists of the appropriate header line text 2417 surrounded by five (5) dashes ('-', 0x2D) on either side of the 2418 header line text. The header line text is chosen based upon the 2419 type of data that is being encoded in Armor, and how it is being 2420 encoded. Header line texts include the following strings: 2422 BEGIN PGP MESSAGE 2423 Used for signed, encrypted, or compressed files. 2425 BEGIN PGP PUBLIC KEY BLOCK 2426 Used for armoring public keys 2428 BEGIN PGP PRIVATE KEY BLOCK 2429 Used for armoring private keys 2431 BEGIN PGP MESSAGE, PART X/Y 2432 Used for multi-part messages, where the armor is split amongst Y 2433 parts, and this is the Xth part out of Y. 2435 BEGIN PGP MESSAGE, PART X 2436 Used for multi-part messages, where this is the Xth part of an 2437 unspecified number of parts. Requires the MESSAGE-ID Armor 2438 Header to be used. 2440 BEGIN PGP SIGNATURE 2441 Used for detached signatures, OpenPGP/MIME signatures, and 2442 signatures following clearsigned messages. Note that PGP 2.x 2443 uses BEGIN PGP MESSAGE for detached signatures. 2445 Note that all these Armor Header Lines are to consist of a complete 2446 line. That is to say, there is always a line ending preceding the 2447 starting five dashes, and following the ending five dashes. The 2448 header lines, therefore, MUST start at the beginning of a line, and 2449 MUST NOT have text following them on the same line. These line 2450 endings are considered a part of the Armor Header Line for the 2451 purposes of determining the content they delimit. This is 2452 particularly important when computing a cleartext signature (see 2453 below). 2455 The Armor Headers are pairs of strings that can give the user or the 2456 receiving OpenPGP implementation some information about how to 2457 decode or use the message. The Armor Headers are a part of the 2458 armor, not a part of the message, and hence are not protected by any 2459 signatures applied to the message. 2461 The format of an Armor Header is that of a key-value pair. A colon 2462 (':' 0x38) and a single space (0x20) separate the key and value. 2463 OpenPGP should consider improperly formatted Armor Headers to be 2464 corruption of the ASCII Armor. Unknown keys should be reported to 2465 the user, but OpenPGP should continue to process the message. 2467 Currently defined Armor Header Keys are: 2469 - "Version", that states the OpenPGP Version used to encode the 2470 message. 2472 - "Comment", a user-defined comment. OpenPGP defines all text to 2473 be in UTF-8. A comment may be any UTF-8 string. However, the 2474 whole point of armoring is to provide seven-bit-clean data. 2475 Consequently, if a comment has characters that are outside the 2476 US-ASCII range of UTF, they may very well not survive transport. 2478 - "MessageID", a 32-character string of printable characters. The 2479 string must be the same for all parts of a multi-part message 2480 that uses the "PART X" Armor Header. MessageID strings should 2481 be unique enough that the recipient of the mail can associate 2482 all the parts of a message with each other. A good checksum or 2483 cryptographic hash function is sufficient. 2485 The MessageID SHOULD NOT appear unless it is in a multi-part 2486 message. If it appears at all, it MUST be computed from the 2487 finished (encrypted, signed, etc.) message in a deterministic 2488 fashion, rather than contain a purely random value. This is to 2489 allow the legitimate recipient to determine that the MessageID 2490 cannot serve as a covert means of leaking cryptographic key 2491 information. 2493 - "Hash", a comma-separated list of hash algorithms used in this 2494 message. This is used only in clear-signed messages. 2496 - "Charset", a description of the character set that the plaintext 2497 is in. Please note that OpenPGP defines text to be in UTF-8. An 2498 implementation will get best results by translating into and out 2499 of UTF-8. However, there are many instances where this is easier 2500 said than done. Also, there are communities of users who have no 2501 need for UTF-8 because they are all happy with a character set 2502 like ISO Latin-5 or a Japanese character set. In such instances, 2503 an implementation MAY override the UTF-8 default by using this 2504 header key. An implementation MAY implement this key and any 2505 translations it cares to; an implementation MAY ignore it and 2506 assume all text is UTF-8. 2508 The Armor Tail Line is composed in the same manner as the Armor 2509 Header Line, except the string "BEGIN" is replaced by the string 2510 "END." 2512 6.3. Encoding Binary in Radix-64 2514 The encoding process represents 24-bit groups of input bits as 2515 output strings of 4 encoded characters. Proceeding from left to 2516 right, a 24-bit input group is formed by concatenating three 8-bit 2517 input groups. These 24 bits are then treated as four concatenated 2518 6-bit groups, each of which is translated into a single digit in the 2519 Radix-64 alphabet. When encoding a bit stream with the Radix-64 2520 encoding, the bit stream must be presumed to be ordered with the 2521 most-significant-bit first. That is, the first bit in the stream 2522 will be the high-order bit in the first 8-bit octet, and the eighth 2523 bit will be the low-order bit in the first 8-bit octet, and so on. 2525 +--first octet--+-second octet--+--third octet--+ 2526 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 2527 +-----------+---+-------+-------+---+-----------+ 2528 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 2529 +--1.index--+--2.index--+--3.index--+--4.index--+ 2531 Each 6-bit group is used as an index into an array of 64 printable 2532 characters from the table below. The character referenced by the 2533 index is placed in the output string. 2535 Value Encoding Value Encoding Value Encoding Value Encoding 2536 0 A 17 R 34 i 51 z 2537 1 B 18 S 35 j 52 0 2538 2 C 19 T 36 k 53 1 2539 3 D 20 U 37 l 54 2 2540 4 E 21 V 38 m 55 3 2541 5 F 22 W 39 n 56 4 2542 6 G 23 X 40 o 57 5 2543 7 H 24 Y 41 p 58 6 2544 8 I 25 Z 42 q 59 7 2545 9 J 26 a 43 r 60 8 2546 10 K 27 b 44 s 61 9 2547 11 L 28 c 45 t 62 + 2548 12 M 29 d 46 u 63 / 2549 13 N 30 e 47 v 2550 14 O 31 f 48 w (pad) = 2551 15 P 32 g 49 x 2552 16 Q 33 h 50 y 2554 The encoded output stream must be represented in lines of no more 2555 than 76 characters each. 2557 Special processing is performed if fewer than 24 bits are available 2558 at the end of the data being encoded. There are three possibilities: 2560 1. The last data group has 24 bits (3 octets). No special 2561 processing is needed. 2563 2. The last data group has 16 bits (2 octets). The first two 6-bit 2564 groups are processed as above. The third (incomplete) data group 2565 has two zero-value bits added to it, and is processed as above. 2566 A pad character (=) is added to the output. 2568 3. The last data group has 8 bits (1 octet). The first 6-bit group 2569 is processed as above. The second (incomplete) data group has 2570 four zero-value bits added to it, and is processed as above. Two 2571 pad characters (=) are added to the output. 2573 6.4. Decoding Radix-64 2575 Any characters outside of the base64 alphabet are ignored in 2576 Radix-64 data. Decoding software must ignore all line breaks or 2577 other characters not found in the table above. 2579 In Radix-64 data, characters other than those in the table, line 2580 breaks, and other white space probably indicate a transmission 2581 error, about which a warning message or even a message rejection 2582 might be appropriate under some circumstances. 2584 Because it is used only for padding at the end of the data, the 2585 occurrence of any "=" characters may be taken as evidence that the 2586 end of the data has been reached (without truncation in transit). No 2587 such assurance is possible, however, when the number of octets 2588 transmitted was a multiple of three and no "=" characters are 2589 present. 2591 6.5. Examples of Radix-64 2593 Input data: 0x14fb9c03d97e 2594 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2595 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2596 11111110 2597 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 2598 111110 2599 Decimal: 5 15 46 28 0 61 37 62 2600 Output: F P u c A 9 l + 2602 Input data: 0x14fb9c03d9 2603 Hex: 1 4 f b 9 c | 0 3 d 9 2604 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2605 pad with 00 2606 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2607 Decimal: 5 15 46 28 0 61 36 2608 pad with = 2609 Output: F P u c A 9 k = 2610 Input data: 0x14fb9c03 2611 Hex: 1 4 f b 9 c | 0 3 2612 8-bit: 00010100 11111011 10011100 | 00000011 2613 pad with 0000 2614 6-bit: 000101 001111 101110 011100 | 000000 110000 2615 Decimal: 5 15 46 28 0 48 2616 pad with = = 2617 Output: F P u c A w = = 2619 6.6. Example of an ASCII Armored Message 2621 -----BEGIN PGP MESSAGE----- 2622 Version: OpenPrivacy 0.99 2624 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2625 vBSFjNSiVHsuAA== 2626 =njUN 2627 -----END PGP MESSAGE----- 2629 Note that this example is indented by two spaces. 2631 7. Cleartext signature framework 2633 It is desirable to sign a textual octet stream without ASCII 2634 armoring the stream itself, so the signed text is still readable 2635 without special software. In order to bind a signature to such a 2636 cleartext, this framework is used. (Note that RFC 3156 defines 2637 another way to clear sign messages for environments that support 2638 MIME.) 2640 The cleartext signed message consists of: 2642 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2643 single line, 2645 - One or more "Hash" Armor Headers, 2647 - Exactly one empty line not included into the message digest, 2649 - The dash-escaped cleartext that is included into the message 2650 digest, 2652 - The ASCII armored signature(s) including the '-----BEGIN PGP 2653 SIGNATURE-----' Armor Header and Armor Tail Lines. 2655 If the "Hash" armor header is given, the specified message digest 2656 algorithm is used for the signature. If there are no such headers, 2657 MD5 is used. If MD5 is the only hash used, then an implementation 2658 MAY omit this header for improved V2.x compatibility. If more than 2659 one message digest is used in the signature, the "Hash" armor header 2660 contains a comma-delimited list of used message digests. 2662 Current message digest names are described below with the algorithm 2663 IDs. 2665 7.1. Dash-Escaped Text 2667 The cleartext content of the message must also be dash-escaped. 2669 Dash escaped cleartext is the ordinary cleartext where every line 2670 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2671 (0x2D) and space ' ' (0x20). This prevents the parser from 2672 recognizing armor headers of the cleartext itself. The message 2673 digest is computed using the cleartext itself, not the dash escaped 2674 form. 2676 As with binary signatures on text documents, a cleartext signature 2677 is calculated on the text using canonical line endings. 2678 The line ending (i.e. the ) before the '-----BEGIN PGP 2679 SIGNATURE-----' line that terminates the signed text is not 2680 considered part of the signed text. 2682 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of 2683 any line is ignored when the cleartext signature is calculated. 2685 8. Regular Expressions 2687 A regular expression is zero or more branches, separated by '|'. It 2688 matches anything that matches one of the branches. 2690 A branch is zero or more pieces, concatenated. It matches a match 2691 for the first, followed by a match for the second, etc. 2693 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2694 followed by '*' matches a sequence of 0 or more matches of the atom. 2695 An atom followed by '+' matches a sequence of 1 or more matches of 2696 the atom. An atom followed by '?' matches a match of the atom, or 2697 the null string. 2699 An atom is a regular expression in parentheses (matching a match for 2700 the regular expression), a range (see below), '.' (matching any 2701 single character), '^' (matching the null string at the beginning of 2702 the input string), '$' (matching the null string at the end of the 2703 input string), a '\' followed by a single character (matching that 2704 character), or a single character with no other significance 2705 (matching that character). 2707 A range is a sequence of characters enclosed in '[]'. It normally 2708 matches any single character from the sequence. If the sequence 2709 begins with '^', it matches any single character not from the rest 2710 of the sequence. If two characters in the sequence are separated by 2711 '-', this is shorthand for the full list of ASCII characters between 2712 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2713 ']' in the sequence, make it the first character (following a 2714 possible '^'). To include a literal '-', make it the first or last 2715 character. 2717 9. Constants 2719 This section describes the constants used in OpenPGP. 2721 Note that these tables are not exhaustive lists; an implementation 2722 MAY implement an algorithm not on these lists. 2724 See the section "Notes on Algorithms" below for more discussion of 2725 the algorithms. 2727 9.1. Public Key Algorithms 2729 ID Algorithm 2730 -- --------- 2731 1 - RSA (Encrypt or Sign) 2732 2 - RSA Encrypt-Only 2733 3 - RSA Sign-Only 2734 16 - Elgamal (Encrypt-Only), see [ELGAMAL] 2735 17 - DSA (Digital Signature Algorithm) [SCHNEIER] 2736 18 - Reserved for Elliptic Curve 2737 19 - Reserved for ECDSA 2738 20 - Elgamal (Encrypt or Sign) 2739 21 - Reserved for Diffie-Hellman (X9.42, 2740 as defined for IETF-S/MIME) 2741 100 to 110 - Private/Experimental algorithm. 2743 Implementations MUST implement DSA for signatures, and Elgamal for 2744 encryption. Implementations SHOULD implement RSA keys. 2745 Implementations MAY implement any other algorithm. 2747 9.2. Symmetric Key Algorithms 2749 ID Algorithm 2750 -- --------- 2751 0 - Plaintext or unencrypted data 2752 1 - IDEA [IDEA] 2753 2 - Triple-DES (DES-EDE, [SCHNEIER] - 2754 168 bit key derived from 192) 2755 3 - CAST5 (128 bit key, as per RFC2144) 2756 4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH] 2757 5 - SAFER-SK128 (13 rounds) [SAFER] 2758 6 - Reserved for DES/SK 2759 7 - AES with 128-bit key [AES] 2760 8 - AES with 192-bit key 2761 9 - AES with 256-bit key 2762 10 - Twofish with 256-bit key [TWOFISH] 2763 100 to 110 - Private/Experimental algorithm. 2765 Implementations MUST implement Triple-DES. Implementations SHOULD 2766 implement AES-128 and CAST5. Implementations that interoperate with 2767 PGP 2.6 or earlier need to support IDEA, as that is the only 2768 symmetric cipher those versions use. Implementations MAY implement 2769 any other algorithm. 2771 9.3. Compression Algorithms 2773 ID Algorithm 2774 -- --------- 2775 0 - Uncompressed 2776 1 - ZIP (RFC1951) 2777 2 - ZLIB (RFC1950) 2778 100 to 110 - Private/Experimental algorithm. 2780 Implementations MUST implement uncompressed data. Implementations 2781 SHOULD implement ZIP. Implementations MAY implement ZLIB. 2783 9.4. Hash Algorithms 2785 ID Algorithm Text Name 2786 -- --------- ---- ---- 2787 1 - MD5 "MD5" 2788 2 - SHA-1 "SHA1" 2789 3 - RIPE-MD/160 "RIPEMD160" 2790 4 - Reserved for double-width SHA (experimental, 2791 obviated) 2792 5 - MD2 "MD2" 2793 6 - Reserved for TIGER/192 "TIGER192" 2794 7 - Reserved for HAVAL (5 pass, 160-bit) "HAVAL-5-160" 2795 8 - SHA256 "SHA256" 2796 9 - SHA384 "SHA384" 2797 10 - SHA512 "SHA512" 2798 100 to 110 - Private/Experimental algorithm. 2800 Implementations MUST implement SHA-1. Implementations SHOULD 2801 implement MD5. 2803 10. Packet Composition 2805 OpenPGP packets are assembled into sequences in order to create 2806 messages and to transfer keys. Not all possible packet sequences 2807 are meaningful and correct. This section describes the rules for 2808 how packets should be placed into sequences. 2810 10.1. Transferable Public Keys 2812 OpenPGP users may transfer public keys. The essential elements of a 2813 transferable public key are: 2815 - One Public Key packet 2817 - Zero or more revocation signatures 2819 - One or more User ID packets 2821 - After each User ID packet, zero or more signature packets 2822 (certifications) 2824 - Zero or more User Attribute packets 2826 - After each User Attribute packet, zero or more signature packets 2827 (certifications) 2829 - Zero or more Subkey packets 2831 - After each Subkey packet, one signature packet, optionally a 2832 revocation. 2834 The Public Key packet occurs first. Each of the following User ID 2835 packets provides the identity of the owner of this public key. If 2836 there are multiple User ID packets, this corresponds to multiple 2837 means of identifying the same unique individual user; for example, a 2838 user may have more than one email address, and construct a User ID 2839 for each one. 2841 Immediately following each User ID packet, there are zero or more 2842 signature packets. Each signature packet is calculated on the 2843 immediately preceding User ID packet and the initial Public Key 2844 packet. The signature serves to certify the corresponding public key 2845 and user ID. In effect, the signer is testifying to his or her 2846 belief that this public key belongs to the user identified by this 2847 user ID. 2849 Within the same section as the User ID packets, there are zero or 2850 more User Attribute packets. Like the User ID packets, a User 2851 Attribute packet is followed by zero or more signature packets 2852 calculated on the immediately preceding User Attribute packet and 2853 the initial Public Key packet. 2855 User Attribute packets and User ID packets may be freely intermixed 2856 in this section, so long as the signatures that follow them are 2857 maintained on the proper User Attribute or User ID packet. 2859 After the User ID packets there may be one or more Subkey packets. 2860 In general, subkeys are provided in cases where the top-level public 2861 key is a signature-only key. However, any V4 key may have subkeys, 2862 and the subkeys may be encryption-only keys, signature-only keys, or 2863 general-purpose keys. V3 keys MUST NOT have subkeys. 2865 Each Subkey packet must be followed by one Signature packet, which 2866 should be a subkey binding signature issued by the top level key. 2868 Subkey and Key packets may each be followed by a revocation 2869 Signature packet to indicate that the key is revoked. Revocation 2870 signatures are only accepted if they are issued by the key itself, 2871 or by a key that is authorized to issue revocations via a revocation 2872 key subpacket in a self-signature by the top level key. 2874 Transferable public key packet sequences may be concatenated to 2875 allow transferring multiple public keys in one operation. 2877 10.2. OpenPGP Messages 2879 An OpenPGP message is a packet or sequence of packets that 2880 corresponds to the following grammatical rules (comma represents 2881 sequential composition, and vertical bar separates alternatives): 2883 OpenPGP Message :- Encrypted Message | Signed Message | 2884 Compressed Message | Literal Message. 2886 Compressed Message :- Compressed Data Packet. 2888 Literal Message :- Literal Data Packet. 2890 ESK :- Public Key Encrypted Session Key Packet | 2891 Symmetric-Key Encrypted Session Key Packet. 2893 ESK Sequence :- ESK | ESK Sequence, ESK. 2895 Encrypted Data :- Symmetrically Encrypted Data Packet | 2896 Symmetrically Encrypted Integrity Protected Data Packet 2898 Encrypted Message :- Encrypted Data | ESK Sequence, Encrypted Data. 2900 One-Pass Signed Message :- One-Pass Signature Packet, 2901 OpenPGP Message, Corresponding Signature Packet. 2903 Signed Message :- Signature Packet, OpenPGP Message | 2904 One-Pass Signed Message. 2906 In addition, decrypting a Symmetrically Encrypted Data Packet or a 2907 Symmetrically Encrypted Integrity Protected Data Packet as well as 2909 decompressing a Compressed Data packet must yield a valid OpenPGP 2910 Message. 2912 10.3. Detached Signatures 2914 Some OpenPGP applications use so-called "detached signatures." For 2915 example, a program bundle may contain a file, and with it a second 2916 file that is a detached signature of the first file. These detached 2917 signatures are simply a signature packet stored separately from the 2918 data that they are a signature of. 2920 11. Enhanced Key Formats 2922 11.1. Key Structures 2924 The format of an OpenPGP V3 key is as follows. Entries in square 2925 brackets are optional and ellipses indicate repetition. 2927 RSA Public Key 2928 [Revocation Self Signature] 2929 User ID [Signature ...] 2930 [User ID [Signature ...] ...] 2932 Each signature certifies the RSA public key and the preceding user 2933 ID. The RSA public key can have many user IDs and each user ID can 2934 have many signatures. 2936 The format of an OpenPGP V4 key that uses two public keys is similar 2937 except that the other keys are added to the end as 'subkeys' of the 2938 primary key. 2940 Primary-Key 2941 [Revocation Self Signature] 2942 [Direct Key Self Signature...] 2943 User ID [Signature ...] 2944 [User ID [Signature ...] ...] 2945 [User Attribute [Signature ...] ...] 2946 [[Subkey [Binding-Signature-Revocation] 2947 Primary-Key-Binding-Signature] ...] 2949 A subkey always has a single signature after it that is issued using 2950 the primary key to tie the two keys together. This binding 2951 signature may be in either V3 or V4 format, but V4 is preferred, of 2952 course. 2954 In the above diagram, if the binding signature of a subkey has been 2955 revoked, the revoked key may be removed, leaving only one key. 2957 In a key that has a main key and subkeys, the primary key MUST be a 2958 key capable of certification. The subkeys may be keys of any other 2959 type. There may be other constructions of V4 keys, too. For example, 2960 there may be a single-key RSA key in V4 format, a DSA primary key 2961 with an RSA encryption key, or RSA primary key with an Elgamal 2962 subkey, etc. 2964 It is also possible to have a signature-only subkey. This permits a 2965 primary key that collects certifications (key signatures) but is 2966 used only used for certifying subkeys that are used for encryption 2967 and signatures. 2969 11.2. Key IDs and Fingerprints 2971 For a V3 key, the eight-octet key ID consists of the low 64 bits of 2972 the public modulus of the RSA key. 2974 The fingerprint of a V3 key is formed by hashing the body (but not 2975 the two-octet length) of the MPIs that form the key material (public 2976 modulus n, followed by exponent e) with MD5. 2978 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet 2979 Tag, followed by the two-octet packet length, followed by the entire 2980 Public Key packet starting with the version field. The key ID is 2981 the low order 64 bits of the fingerprint. Here are the fields of 2982 the hash material, with the example of a DSA key: 2984 a.1) 0x99 (1 octet) 2986 a.2) high order length octet of (b)-(f) (1 octet) 2988 a.3) low order length octet of (b)-(f) (1 octet) 2990 b) version number = 4 (1 octet); 2992 c) time stamp of key creation (4 octets); 2994 d) algorithm (1 octet): 17 = DSA (example); 2996 e) Algorithm specific fields. 2998 Algorithm Specific Fields for DSA keys (example): 3000 e.1) MPI of DSA prime p; 3002 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 3004 e.3) MPI of DSA group generator g; 3006 e.4) MPI of DSA public key value y (= g**x mod p where x is secret). 3008 Note that it is possible for there to be collisions of key IDs -- 3009 two different keys with the same key ID. Note that there is a much 3010 smaller, but still non-zero probability that two different keys have 3011 the same fingerprint. 3013 Also note that if V3 and V4 format keys share the same RSA key 3014 material, they will have different key ids as well as different 3015 fingerprints. 3017 Finally, the key ID and fingerprint of a subkey are calculated in 3018 the same way as for a primary key, including the 0x99 as the first 3019 byte (even though this is not a valid packet ID for a public 3020 subkey). 3022 12. Notes on Algorithms 3024 12.1. Symmetric Algorithm Preferences 3026 The symmetric algorithm preference is an ordered list of algorithms 3027 that the keyholder accepts. Since it is found on a self-signature, 3028 it is possible that a keyholder may have different preferences. For 3029 example, Alice may have TripleDES only specified for 3030 "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 3031 "alice@home.org". Note that it is also possible for preferences to 3032 be in a subkey's binding signature. 3034 Since TripleDES is the MUST-implement algorithm, if it is not 3035 explicitly in the list, it is tacitly at the end. However, it is 3036 good form to place it there explicitly. Note also that if an 3037 implementation does not implement the preference, then it is 3038 implicitly a TripleDES-only implementation. 3040 An implementation MUST NOT use a symmetric algorithm that is not in 3041 the recipient's preference list. When encrypting to more than one 3042 recipient, the implementation finds a suitable algorithm by taking 3043 the intersection of the preferences of the recipients. Note that the 3044 MUST-implement algorithm, TripleDES, ensures that the intersection 3045 is not null. The implementation may use any mechanism to pick an 3046 algorithm in the intersection. 3048 If an implementation can decrypt a message that a keyholder doesn't 3049 have in their preferences, the implementation SHOULD decrypt the 3050 message anyway, but MUST warn the keyholder that the protocol has 3051 been violated. (For example, suppose that Alice, above, has software 3052 that implements all algorithms in this specification. Nonetheless, 3053 she prefers subsets for work or home. If she is sent a message 3054 encrypted with IDEA, which is not in her preferences, the software 3055 warns her that someone sent her an IDEA-encrypted message, but it 3056 would ideally decrypt it anyway.) 3058 An implementation that is striving for backward compatibility MAY 3059 consider a V3 key with a V3 self-signature to be an implicit 3060 preference for IDEA, and no ability to do TripleDES. This is 3061 technically non-compliant, but an implementation MAY violate the 3062 above rule in this case only and use IDEA to encrypt the message, 3063 provided that the message creator is warned. Ideally, though, the 3064 implementation would follow the rule by actually generating two 3065 messages, because it is possible that the OpenPGP user's 3066 implementation does not have IDEA, and thus could not read the 3067 message. Consequently, an implementation MAY, but SHOULD NOT use 3068 IDEA in an algorithm conflict with a V3 key. 3070 12.2. Other Algorithm Preferences 3072 Other algorithm preferences work similarly to the symmetric 3073 algorithm preference, in that they specify which algorithms the 3074 keyholder accepts. There are two interesting cases that other 3075 comments need to be made about, though, the compression preferences 3076 and the hash preferences. 3078 12.2.1. Compression Preferences 3080 Compression has been an integral part of PGP since its first days. 3081 OpenPGP and all previous versions of PGP have offered compression. 3082 In this specification, the default is for messages to be compressed, 3083 although an implementation is not required to do so. Consequently, 3084 the compression preference gives a way for a keyholder to request 3085 that messages not be compressed, presumably because they are using a 3086 minimal implementation that does not include compression. 3087 Additionally, this gives a keyholder a way to state that it can 3088 support alternate algorithms. 3090 Like the algorithm preferences, an implementation MUST NOT use an 3091 algorithm that is not in the preference vector. If the preferences 3092 are not present, then they are assumed to be [ZIP(1), 3093 UNCOMPRESSED(0)]. 3095 Additionally, an implementation MUST implement this preference to 3096 the degree of recognizing when to send an uncompressed message. A 3097 robust implementation would satisfy this requirement by looking at 3098 the recipient's preference and acting accordingly. A minimal 3099 implementation can satisfy this requirement by never generating a 3100 compressed message, since all implementations can handle messages 3101 that have not been compressed. 3103 12.2.2. Hash Algorithm Preferences 3105 Typically, the choice of a hash algorithm is something the signer 3106 does, rather than the verifier, because a signer rarely knows who is 3107 going to be verifying the signature. This preference, though, allows 3108 a protocol based upon digital signatures ease in negotiation. 3110 Thus, if Alice is authenticating herself to Bob with a signature, it 3111 makes sense for her to use a hash algorithm that Bob's software 3112 uses. This preference allows Bob to state in his key which 3113 algorithms Alice may use. 3115 Since SHA1 is the MUST-implement hash algorithm, if it is not 3116 explicitly in the list, it is tacitly at the end. However, it is 3117 good form to place it there explicitly. 3119 12.3. Plaintext 3121 Algorithm 0, "plaintext," may only be used to denote secret keys 3122 that are stored in the clear. Implementations MUST NOT use plaintext 3123 in Symmetrically Encrypted Data Packets; they must use Literal Data 3124 Packets to encode unencrypted or literal data. 3126 12.4. RSA 3128 There are algorithm types for RSA-signature-only, and 3129 RSA-encrypt-only keys. These types are deprecated. The "key flags" 3130 subpacket in a signature is a much better way to express the same 3131 idea, and generalizes it to all algorithms. An implementation SHOULD 3132 NOT create such a key, but MAY interpret it. 3134 An implementation SHOULD NOT implement RSA keys of size less than 3135 768 bits. 3137 It is permissible for an implementation to support RSA merely for 3138 backward compatibility; for example, such an implementation would 3139 support V3 keys with IDEA symmetric cryptography. Note that this is 3140 an exception to the other MUST-implement rules. An implementation 3141 that supports RSA in V4 keys MUST implement the MUST-implement 3142 features. 3144 12.5. Elgamal 3146 If an Elgamal key [ELGAMAL] is to be used for both signing and 3147 encryption, extra care must be taken in creating the key. 3149 An Elgamal key consists of a generator g, a prime modulus p, a 3150 secret exponent x, and a public value y = g^x mod p. 3152 The generator and prime must be chosen so that solving the discrete 3153 log problem is intractable. The group g should generate the 3154 multiplicative group mod p-1 or a large subgroup of it, and the 3155 order of g should have at least one large prime factor. A good 3156 choice is to use a "strong" Sophie-Germain prime in choosing p, so 3157 that both p and (p-1)/2 are primes. In fact, this choice is so good 3158 that implementers SHOULD do it, as it avoids a small subgroup 3159 attack. 3161 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that 3162 if the generator g has only small prime factors, and if g divides 3163 the order of the group it generates, then signatures can be forged. 3164 In particular, choosing g=2 is a bad choice if the group order may 3165 be even. On the other hand, a generator of 2 is a fine choice for an 3166 encryption-only key, as this will make the encryption faster. 3168 While verifying Elgamal signatures, note that it is important to 3169 test that r and s are less than p. If this test is not done then 3170 signatures can be trivially forged by using large r values of 3171 approximately twice the length of p. This attack is also discussed 3172 in the Bleichenbacher paper. 3174 Details on safe use of Elgamal signatures may be found in [MENEZES], 3175 which discusses all the weaknesses described above. Please note that 3176 Elgamal signatures are controversial; because of the care that must 3177 be taken with Elgamal keys, many implementations forego them. 3179 If an implementation allows Elgamal signatures, then it MUST use the 3180 algorithm identifier 20 for an Elgamal public key that can sign. 3182 An implementation SHOULD NOT implement Elgamal keys of size less 3183 than 768 bits. For long-term security, Elgamal keys should be 1024 3184 bits or longer. 3186 12.6. DSA 3188 An implementation SHOULD NOT implement DSA keys of size less than 3189 768 bits. Note that present DSA is limited to a maximum of 1024 bit 3190 keys, which are recommended for long-term use. Also, DSA keys MUST 3191 be an even multiple of 64 bits long. 3193 12.7. Reserved Algorithm Numbers 3195 A number of algorithm IDs have been reserved for algorithms that 3196 would be useful to use in an OpenPGP implementation, yet there are 3197 issues that prevent an implementer from actually implementing the 3198 algorithm. These are marked in the Public Algorithms section as 3199 "(reserved for)". 3201 The reserved public key algorithms, Elliptic Curve (18), ECDSA (19), 3202 and X9.42 (21) do not have the necessary parameters, parameter 3203 order, or semantics defined. 3205 The reserved symmetric key algorithm, DES/SK (6), does not have 3206 semantics defined. 3208 The reserved hash algorithms, TIGER192 (6), and HAVAL-5-160 (7), do 3209 not have OIDs. The reserved algorithm number 4, reserved for a 3210 double-width variant of SHA1, is not presently defined. 3212 12.8. OpenPGP CFB mode 3214 OpenPGP does symmetric encryption using a variant of Cipher Feedback 3215 Mode (CFB mode). This section describes the procedure it uses in 3216 detail. This mode is what is used for Symmetrically Encrypted Data 3217 Packets; the mechanism used for encrypting secret key material is 3218 similar, but described in those sections above. 3220 In the description below, the value BS is the block size in octets 3221 of the cipher. Most ciphers have a block size of 8 octets. The AES 3222 and Twofish have a block size of 16 octets. Also note that the 3223 description below assumes that the IV and CFB arrays start with an 3224 index of 1 (unlike the C language, which assumes arrays start with a 3225 zero index). 3227 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 3228 and prefixes the plaintext with BS+2 octets of random data, such 3229 that octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB 3230 "resync" after encrypting those BS+2 octets. 3232 Thus, for an algorithm that has a block size of 8 octets (64 bits), 3233 the IV is 10 octets long and octets 7 and 8 of the IV are the same 3234 as octets 9 and 10. For an algorithm with a block size of 16 octets 3235 (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate 3236 octets 15 and 16. Those extra two octets are an easy check for a 3237 correct key. 3239 Step by step, here is the procedure: 3241 1. The feedback register (FR) is set to the IV, which is all zeros. 3243 2. FR is encrypted to produce FRE (FR Encrypted). This is the 3244 encryption of an all-zero value. 3246 3. FRE is xored with the first BS octets of random data prefixed to 3247 the plaintext to produce C[1] through C[BS], the first BS octets 3248 of ciphertext. 3250 4. FR is loaded with C[1] through C[BS]. 3252 5. FR is encrypted to produce FRE, the encryption of the first BS 3253 octets of ciphertext. 3255 6. The left two octets of FRE get xored with the next two octets of 3256 data that were prefixed to the plaintext. This produces C[BS+1] 3257 and C[BS+2], the next two octets of ciphertext. 3259 7. (The resync step) FR is loaded with C[3] through C[BS+2]. 3261 8. FR is encrypted to produce FRE. 3263 9. FRE is xored with the first BS octets of the given plaintext, 3264 now that we have finished encrypting the BS+2 octets of prefixed 3265 data. This produces C[BS+3] through C[BS+(BS+2)], the next BS 3266 octets of ciphertext. 3268 10. FR is loaded with C[BS+3] to C[BS + (BS+2)] (which is C11-C18 3269 for an 8-octet block). 3271 11. FR is encrypted to produce FRE. 3273 12. FRE is xored with the next BS octets of plaintext, to produce 3274 the next BS octets of ciphertext. These are loaded into FR and 3275 the process is repeated until the plaintext is used up. 3277 13. Security Considerations 3279 * As with any technology involving cryptography, you should check 3280 the current literature to determine if any algorithms used here 3281 have been found to be vulnerable to attack. 3283 * This specification uses Public Key Cryptography technologies. 3284 Possession of the private key portion of a public-private key 3285 pair is assumed to be controlled by the proper party or parties. 3287 * Certain operations in this specification involve the use of 3288 random numbers. An appropriate entropy source should be used to 3289 generate these numbers. See RFC 1750. 3291 * The MD5 hash algorithm has been found to have weaknesses 3292 (pseudo-collisions in the compress function) that make some 3293 people deprecate its use. They consider the SHA-1 algorithm 3294 better. 3296 * Many security protocol designers think that it is a bad idea to 3297 use a single key for both privacy (encryption) and integrity 3298 (signatures). In fact, this was one of the motivating forces 3299 behind the V4 key format with separate signature and encryption 3300 keys. If you as an implementer promote dual-use keys, you should 3301 at least be aware of this controversy. 3303 * The DSA algorithm will work with any 160-bit hash, but it is 3304 sensitive to the quality of the hash algorithm, if the hash 3305 algorithm is broken, it can leak the secret key. The Digital 3306 Signature Standard (DSS) specifies that DSA be used with SHA-1. 3307 RIPEMD-160 is considered by many cryptographers to be as strong. 3308 An implementation should take care which hash algorithms are 3309 used with DSA, as a weak hash can not only allow a signature to 3310 be forged, but could leak the secret key. These same 3311 considerations about the quality of the hash algorithm apply to 3312 Elgamal signatures. 3314 * There is a somewhat-related potential security problem in 3315 signatures. If an attacker can find a message that hashes to the 3316 same hash with a different algorithm, a bogus signature 3317 structure can be constructed that evaluates correctly. 3319 For example, suppose Alice DSA signs message M using hash 3320 algorithm H. Suppose that Mallet finds a message M' that has the 3321 same hash value as M with H'. Mallet can then construct a 3322 signature block that verifies as Alice's signature of M' with 3323 H'. However, this would also constitute a weakness in either H 3324 or H' or both. Should this ever occur, a revision will have to 3325 be made to this document to revise the allowed hash algorithms. 3327 * If you are building an authentication system, the recipient may 3328 specify a preferred signing algorithm. However, the signer would 3329 be foolish to use a weak algorithm simply because the recipient 3330 requests it. 3332 * Some of the encryption algorithms mentioned in this document 3333 have been analyzed less than others. For example, although 3334 CAST5 is presently considered strong, it has been analyzed less 3335 than Triple-DES. Other algorithms may have other controversies 3336 surrounding them. 3338 * In late summer 2002, Jallad, Katz, and Schneier published an 3339 interesting attack on the OpenPGP protocol and some of its 3340 implementations [JKS02]. In this attack, the attacker modifies a 3341 message and sends it to a user who then returns the erroneously 3342 decrypted message to the attacker. The attacker is thus using 3343 the user as a random oracle, and can often decrypt the message. 3345 Compressing data can ameliorate this attack. The incorrectly 3346 decrypted data nearly always decompresses in ways that defeats 3347 the attack. However, this is not a rigorous fix, and leaves open 3348 some small vulnerabilities. For example, if an implementation 3349 does not compress a message before encryption (perhaps because 3350 it knows it was already compressed), then that message is 3351 vulnerable. Because of this happenstance -- that modification 3352 attacks can be thwarted by decompression errors, an 3353 implementation SHOULD treat a decompression error as a security 3354 problem, not merely a data problem. 3356 This attack can be defeated by the use of Modification 3357 Detection, provided that the implementation does not let the 3358 user naively return the data to the attacker. An implementation 3359 MUST treat an MDC failure as a security problem, not merely a 3360 data problem. 3362 In either case, the implementation MAY allow the user access to 3363 the erroneous data, but MUST warn the user as to potential 3364 security problems should that data be returned to the sender. 3366 While this attack is somewhat obscure, requiring a special set 3367 of circumstances to create it, it is nonetheless quite serious 3368 as it permits someone to trick a user to decrypt a message. 3369 Consequently, it is important that: 3371 1. Implementers treat MDC errors and decompression failures as 3372 security problems. 3374 2. Implementers implement Modification Detection with all due 3375 speed and encourage its spread. 3377 3. Users migrate to implementations that support Modification 3378 Detection with all due speed. 3380 * Some technologies mentioned here may be subject to government 3381 control in some countries. 3383 14. Implementation Nits 3385 This section is a collection of comments to help an implementer, 3386 particularly with an eye to backward compatibility. Previous 3387 implementations of PGP are not OpenPGP-compliant. Often the 3388 differences are small, but small differences are frequently more 3389 vexing than large differences. Thus, this is a non-comprehensive 3390 list of potential problems and gotchas for a developer who is trying 3391 to be backward-compatible. 3393 * PGP 5.x does not accept V4 signatures for anything other than 3394 key material. 3396 * PGP 5.x does not recognize the "five-octet" lengths in 3397 new-format headers or in signature subpacket lengths. 3399 * PGP 5.0 rejects an encrypted session key if the key size differs 3400 from the S2K symmetric algorithm. This is a bug in its 3401 validation function. 3403 * PGP 5.0 does not handle multiple one-pass signature headers and 3404 trailers. Signing one will compress the one-pass signed literal 3405 and prefix a V3 signature instead of doing a nested one-pass 3406 signature. 3408 * When exporting a private key, PGP 2.x generates the header 3409 "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY 3410 BLOCK". All previous versions ignore the implied data type, and 3411 look directly at the packet data type. 3413 * In a clear-signed signature, PGP 5.0 will figure out the correct 3414 hash algorithm if there is no "Hash:" header, but it will reject 3415 a mismatch between the header and the actual algorithm used. The 3416 "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x 3417 rejects the "Hash:" header and assumes MD5. There are a number 3418 of enhanced variants of PGP 2.6.x that have been modified for 3419 SHA-1 signatures. 3421 * PGP 5.0 can read an RSA key in V4 format, but can only recognize 3422 it with a V3 key id, and can properly use only a V3 format RSA 3423 key. 3425 * Neither PGP 5.x nor PGP 6.0 recognize Elgamal Encrypt and Sign 3426 keys. They only handle Elgamal Encrypt-only keys. 3428 * There are many ways possible for two keys to have the same key 3429 material, but different fingerprints (and thus key ids). Perhaps 3430 the most interesting is an RSA key that has been "upgraded" to 3431 V4 format, but since a V4 fingerprint is constructed by hashing 3432 the key creation time along with other things, two V4 keys 3433 created at different times, yet with the same key material will 3434 have different fingerprints. 3436 * If an implementation is using zlib to interoperate with PGP 2.x, 3437 then the "windowBits" parameter should be set to -13. 3439 * PGP 2.6.X and 5.0 do not trim trailing whitespace from a 3440 "canonical text" signature. They only remove it from cleartext 3441 signatures. These signatures are not OpenPGP compliant -- 3442 OpenPGP requires trimming the whitespace. If you wish to 3443 interoperate with PGP 2.6.X or PGP 5, you may wish to accept 3444 these non-compliant signatures. 3446 15. Authors and Working Group Chair 3448 The working group can be contacted via the current chair: 3450 John W. Noerenberg, II 3451 Qualcomm, Inc 3452 6455 Lusk Blvd 3453 San Diego, CA 92131 USA 3454 Email: jwn2@qualcomm.com 3455 Tel: +1 (619) 658-3510 3457 The principal authors of this draft are: 3459 Jon Callas 3461 Email: jon@callas.org 3462 Tel: +1 (408) 448-6801 3464 Lutz Donnerhacke 3465 IKS GmbH 3466 Wildenbruchstr. 15 3467 07745 Jena, Germany 3469 EMail: lutz@iks-jena.de 3470 Tel: +49-3641-675642 3472 Hal Finney 3473 Network Associates, Inc. 3474 3965 Freedom Circle 3475 Santa Clara, CA 95054, USA 3477 Email: hal@pgp.com 3479 Rodney Thayer 3481 Email: rodney@tillerman.to 3483 This memo also draws on much previous work from a number of other 3484 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 3485 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph 3486 Levien, Colin Plumb, Will Price, David Shaw, William Stallings, Mark 3487 Weaver, and Philip R. Zimmermann. 3489 16. References 3491 [AES] Advanced Encryption Standards Questions and Answers 3492 3495 3498 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating Elgamal 3499 signatures without knowing the secret key," 3500 Eurocrypt 96. Note that the version in the 3501 proceedings has an error. A revised version is 3502 available at the time of writing from 3503 3506 [BLOWFISH] Schneier, B. "Description of a New Variable-Length 3507 Key, 64-Bit Block Cipher (Blowfish)" Fast Software 3508 Encryption, Cambridge Security Workshop Proceedings 3509 (December 1993), Springer-Verlag, 1994, pp191-204 3510 3512 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved 3513 international version of PGP", ftp://ftp.iks- 3514 jena.de/mitarb/lutz/crypt/software/pgp/ 3516 [ELGAMAL] T. Elgamal, "A Public-Key Cryptosystem and a 3517 Signature Scheme Based on Discrete Logarithms," 3518 IEEE Transactions on Information Theory, v. IT-31, 3519 n. 4, 1985, pp. 469-472. 3521 [IDEA] Lai, X, "On the design and security of block 3522 ciphers", ETH Series in Information Processing, 3523 J.L. Massey (editor), Vol. 1, Hartung-Gorre Verlag 3524 Knostanz, Technische Hochschule (Zurich), 1992 3526 [ISO10646] ISO/IEC 10646-1:1993. International Standard -- 3527 Information technology -- Universal Multiple-Octet 3528 Coded Character Set (UCS) -- Part 1: Architecture 3529 and Basic Multilingual Plane. 3531 [JFIF] JPEG File Interchange Format (Version 1.02). 3532 Eric Hamilton, C-Cube Microsystems, Milpitas, CA, 3533 September 1, 1992. 3535 [JKS02] Kahil Jallad, Jonathan Katz, Bruce Schneier 3536 "Implementation of Chosen-Ciphertext Attacks 3537 against PGP and GnuPG" 3538 http://www.counterpane.com/pgp-attack.html 3540 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott 3541 Vanstone, "Handbook of Applied Cryptography," CRC 3542 Press, 1996. 3544 [RFC822] Crocker, D., "Standard for the format of ARPA 3545 Internet text messages", STD 11, RFC 822, August 3546 1982. 3548 [RFC1423] Balenson, D., "Privacy Enhancement for Internet 3549 Electronic Mail: Part III: Algorithms, Modes, and 3550 Identifiers", RFC 1423, October 1993. 3552 [RFC1641] Goldsmith, D. and M. Davis, "Using Unicode with 3553 MIME", RFC 1641, July 1994. 3555 [RFC1750] Eastlake, D., Crocker, S. and J. Schiller, 3556 "Randomness Recommendations for Security", RFC 3557 1750, December 1994. 3559 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format 3560 Specification version 1.3.", RFC 1951, May 1996. 3562 [RFC1983] Malkin, G., "Internet Users' Glossary", FYI 18, RFC 3563 1983, August 1996. 3565 [RFC1991] Atkins, D., Stallings, W. and P. Zimmermann, "PGP 3566 Message Exchange Formats", RFC 1991, August 1996. 3568 [RFC2045] Borenstein, N. and N. Freed, "Multipurpose Internet 3569 Mail Extensions (MIME) Part One: Format of Internet 3570 Message Bodies.", RFC 2045, November 1996. 3572 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 3573 Requirement Level", BCP 14, RFC 2119, March 1997. 3575 [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC 3576 2144, May 1997. 3578 [RFC2279] Yergeau., F., "UTF-8, a transformation format of 3579 Unicode and ISO 10646", RFC 2279, January 1998. 3581 [RFC2437] B. Kaliski and J. Staddon, " PKCS #1: RSA 3582 Cryptography Specifications Version 2.0", 3583 RFC 2437, October 1998. 3585 [RFC3156] M. Elkins, D. Del Torto, R. Levien, T. Roessler, 3586 "MIME Security with OpenPGP", RFC 3156, 3587 August 2001. 3589 [SAFER] Massey, J.L. "SAFER K-64: One Year Later", B. 3590 Preneel, editor, Fast Software Encryption, Second 3591 International Workshop (LNCS 1008) pp212-241, 3592 Springer-Verlag 1995 3594 [SCHNEIER] Schneier, B., "Applied Cryptography Second Edition: 3595 protocols, algorithms, and source code in C", 1996. 3597 [TWOFISH] B. Schneier, J. Kelsey, D. Whiting, D. Wagner, C. 3598 Hall, and N. Ferguson, "The Twofish Encryption 3599 Algorithm", John Wiley & Sons, 1999. 3601 17. Full Copyright Statement 3603 Copyright 2003 by The Internet Society. All Rights Reserved. 3605 This document and translations of it may be copied and furnished to 3606 others, and derivative works that comment on or otherwise explain it 3607 or assist in its implementation may be prepared, copied, published 3608 and distributed, in whole or in part, without restriction of any 3609 kind, provided that the above copyright notice and this paragraph 3610 are included on all such copies and derivative works. However, this 3611 document itself may not be modified in any way, such as by removing 3612 the copyright notice or references to the Internet Society or other 3613 Internet organizations, except as needed for the purpose of 3614 developing Internet standards in which case the procedures for 3615 copyrights defined in the Internet Standards process must be 3616 followed, or as required to translate it into languages other than 3617 English. 3619 The limited permissions granted above are perpetual and will not be 3620 revoked by the Internet Society or its successors or assigns.