idnits 2.17.1 draft-ietf-openpgp-formats-03.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 ** Missing expiration date. The document expiration date should appear on the first and last page. ** The document seems to lack a 1id_guidelines paragraph about Internet-Drafts being working documents. ** The document seems to lack a 1id_guidelines paragraph about the list of current Internet-Drafts. ** The document seems to lack a 1id_guidelines paragraph about the list of Shadow Directories. 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). -- The exact meaning of the all-uppercase expression 'MAY NOT' is not defined in RFC 2119. If it is intended as a requirements expression, it should be rewritten using one of the combinations defined in RFC 2119; otherwise it should not be all-uppercase. == The expression 'MAY NOT', while looking like RFC 2119 requirements text, is not defined in RFC 2119, and should not be used. Consider using 'MUST NOT' instead (if that is what you mean). Found 'MAY NOT' in this paragraph: An implementation MAY use Partial Body Lengths for data packets, be they literal, compressed, or encrypted. The first partial length MUST be at least 512 octets long. Partial Body Lengths MAY NOT be used for any other packet types. == Using lowercase 'not' together with uppercase 'MUST', 'SHALL', 'SHOULD', or 'RECOMMENDED' is not an accepted usage according to RFC 2119. Please use uppercase 'NOT' together with RFC 2119 keywords (if that is what you mean). Found 'MUST not' in this paragraph: An implementation MUST not use a symmetric algorithm that is not in the recipent's preference list. When encrypting to more than one recipient, the implementation finds a suitable algorithm by taking the intersection of the preferences of the recipients. Note that the MUST-implement algorithm, TripleDES, ensures that the intersection is not null. The implementation may use any mechanism to pick an algorithm in the intersection. == 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 313 -- Looks like a reference, but probably isn't: '1' on line 313 -- Looks like a reference, but probably isn't: '2' on line 313 -- Looks like a reference, but probably isn't: '3' on line 314 == Missing Reference: 'ISO10646' is mentioned on line 354, but not defined == Missing Reference: 'Optional' is mentioned on line 1642, but not defined == Unused Reference: 'DONNERHACKE' is defined on line 2781, but no explicit reference was found in the text == Unused Reference: 'ISO-10646' is defined on line 2789, but no explicit reference was found in the text == Unused Reference: 'RFC822' is defined on line 2801, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 2804, but no explicit reference was found in the text == Unused Reference: 'RFC1641' is defined on line 2808, but no explicit reference was found in the text == Unused Reference: 'RFC1750' is defined on line 2811, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 2814, but no explicit reference was found in the text == Unused Reference: 'RFC1983' is defined on line 2817, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 2819, but no explicit reference was found in the text == Unused Reference: 'RFC2015' is defined on line 2822, but no explicit reference was found in the text == Unused Reference: 'RFC2045' is defined on line 2828, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 2832, but no explicit reference was found in the text -- Possible downref: Non-RFC (?) normative reference: ref. 'BLEICHENBACHER' -- Possible downref: Non-RFC (?) normative reference: ref. 'DONNERHACKE' -- Possible downref: Non-RFC (?) normative reference: ref. 'ELGAMAL' -- Possible downref: Non-RFC (?) normative reference: ref. 'ISO-10646' -- Possible downref: Non-RFC (?) normative reference: ref. 'MENEZES' -- Possible downref: Non-RFC (?) normative reference: ref. 'PKCS1' ** 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) ** Obsolete normative reference: RFC 2044 (Obsoleted by RFC 2279) Summary: 17 errors (**), 0 flaws (~~), 18 warnings (==), 14 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 Network Associates 3 draft-ietf-openpgp-formats-03.txt 4 Expires Nov 1998 Lutz Donnerhacke 5 May 1998 IN-Root-CA Individual Network e.V. 7 Hal Finney 8 Network Associates 10 Rodney Thayer 11 Sable Technology 13 OpenPGP Message Format 14 draft-ietf-openpgp-formats-03.txt 16 Copyright 1998 by The Internet Society. All Rights Reserved. 18 Status of this Memo 20 This document is an Internet-Draft. Internet-Drafts are working 21 documents of the Internet Engineering Task Force (IETF), its areas, 22 and its working groups. Note that other groups may also distribute 23 working documents as Internet-Drafts. 25 Internet-Drafts are draft documents valid for a maximum of six 26 months and may be updated, replaced, or obsoleted by other documents 27 at any time. It is inappropriate to use Internet-Drafts as 28 reference material or to cite them other than as "work in progress." 30 To view the entire list of current Internet-Drafts, please check the 31 "1id-abstracts.txt" listing contained in the Internet-Drafts Shadow 32 Directories on ftp.is.co.za (Africa), ftp.nordu.net (Northern 33 Europe), ftp.nis.garr.it (Southern Europe), munnari.oz.au (Pacific 34 Rim), ftp.ietf.org (US East Coast), or ftp.isi.edu (US West Coast). 36 Abstract 38 This document is maintained in order to publish all necessary 39 information needed to develop interoperable applications based on 40 the OpenPGP format. It is not a step-by-step cookbook for writing an 41 application. It describes only the format and methods needed to 42 read, check, generate and write conforming packets crossing any 43 network. It does not deal with storage and implementation questions. 44 It does, however, discuss implementation issues necessary to avoid 45 security flaws. 47 Open-PGP software uses a combination of strong public-key and 48 symmetric cryptography to provide security services for electronic 49 communications and data storage. These services include 50 confidentiality, key management, authentication and digital 51 signatures. This document specifies the message formats used in 52 OpenPGP. 54 Table of Contents 56 Status of this Memo 1 57 Abstract 1 58 Table of Contents 2 59 1. Introduction 5 60 1.1. Terms 5 61 2. General functions 5 62 2.1. Confidentiality via Encryption 5 63 2.2. Authentication via Digital signature 6 64 2.3. Compression 7 65 2.4. Conversion to Radix-64 7 66 3. Data Element Formats 7 67 3.1. Scalar numbers 7 68 3.2. Multi-Precision Integers 7 69 3.3. Key IDs 8 70 3.4. Text 8 71 3.5. Time fields 8 72 3.6. String-to-key (S2K) specifiers 8 73 3.6.1. String-to-key (S2k) specifier types 8 74 3.6.1.1. Simple S2K 8 75 3.6.1.2. Salted S2K 9 76 3.6.1.3. Iterated and Salted S2K 9 77 3.6.2. String-to-key usage 10 78 3.6.2.1. Secret key encryption 10 79 3.6.2.2. Symmetric-key message encryption 11 80 4. Packet Syntax 11 81 4.1. Overview 11 82 4.2. Packet Headers 11 83 4.2.1. Old-Format Packet Lengths 12 84 4.2.2. New-Format Packet Lengths 12 85 4.2.2.1. One-Octet Lengths 13 86 4.2.2.2. Two-Octet Lengths 13 87 4.2.2.3. Five-Octet Lengths 13 88 4.2.2.4. Partial Body Lengths 13 89 4.2.3. Packet Length Examples 13 90 4.3. Packet Tags 14 91 5. Packet Types 14 92 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 14 93 5.2. Signature Packet (Tag 2) 16 94 5.2.1. Signature Types 16 95 5.2.2. Version 3 Signature Packet Format 18 96 5.2.3. Version 4 Signature Packet Format 20 97 5.2.3.1. Signature Subpacket Specification 20 98 5.2.3.2. Signature Subpacket Types 22 99 5.2.3.3. Signature creation time 22 100 5.2.3.4. Issuer 23 101 5.2.3.5. Key expiration time 23 102 5.2.3.6. Preferred symmetric algorithms 23 103 5.2.3.7. Preferred hash algorithms 23 104 5.2.3.8. Preferred compression algorithms 23 105 5.2.3.9. Signature expiration time 23 106 5.2.3.10.Exportable 24 107 5.2.3.11.Revocable 24 108 5.2.3.12.Trust signature 24 109 5.2.3.13.Regular expression 24 110 5.2.3.14.Revocation key 25 111 5.2.3.15.Notation Data 25 112 5.2.3.16.Key server preferences 25 113 5.2.3.17.Preferred key server 26 114 5.2.3.18.Primary user id 26 115 5.2.3.19.Policy URL 26 116 5.2.3.20.Key Flags 26 117 5.2.3.21.Signer's User ID 27 118 5.2.4. Computing Signatures 27 119 5.2.4.1. Subpacket Hints 28 120 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 29 121 5.4. One-Pass Signature Packets (Tag 4) 30 122 5.5. Key Material Packet 30 123 5.5.1. Key Packet Variants 30 124 5.5.1.1. Public Key Packet (Tag 6) 30 125 5.5.1.2. Public Subkey Packet (Tag 14) 30 126 5.5.1.3. Secret Key Packet (Tag 5) 31 127 5.5.1.4. Secret Subkey Packet (Tag 7) 31 128 5.5.2. Public Key Packet Formats 31 129 5.5.3. Secret Key Packet Formats 33 130 5.6. Compressed Data Packet (Tag 8) 34 131 5.7. Symmetrically Encrypted Data Packet (Tag 9) 35 132 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 35 133 5.9. Literal Data Packet (Tag 11) 36 134 5.10. Trust Packet (Tag 12) 36 135 5.11. User ID Packet (Tag 13) 37 136 6. Radix-64 Conversions 37 137 6.1. An Implementation of the CRC-24 in "C" 37 138 6.2. Forming ASCII Armor 38 139 6.3. Encoding Binary in Radix-64 39 140 6.4. Decoding Radix-64 41 141 6.5. Examples of Radix-64 41 142 6.6. Example of an ASCII Armored Message 42 143 7. Cleartext signature framework 42 144 7.1. Dash-Escaped Text 42 145 8. Regular Expressions 43 146 9. Constants 43 147 9.1. Public Key Algorithms 44 148 9.2. Symmetric Key Algorithms 44 149 9.3. Compression Algorithms 44 150 9.4. Hash Algorithms 45 151 10. Packet Composition 45 152 10.1. Transferable Public Keys 45 153 10.2. OpenPGP Messages 46 154 11. Enhanced Key Formats 47 155 11.1. Key Structures 47 156 11.2. Key IDs and Fingerprints 48 157 12. Notes on Algorithms 48 158 12.1. Symmetric Algorithm Preferences 48 159 12.2. Other Algorithm Preferences 49 160 12.2.1. Compression Preferences 49 161 12.2.2. Hash Algorithm Preferences 50 162 12.3. Plaintext 50 163 12.4. RSA 50 164 12.5. Elgamal 51 165 12.6. DSA 51 166 12.7. OpenPGP CFB mode 51 167 13. Security Considerations 52 168 14. Implementation Nits 53 169 15. Authors and Working Group Chair 54 170 16. References 55 171 17. Full Copyright Statement 56 173 1. Introduction 175 This document provides information on the message-exchange packet 176 formats used by OpenPGP to provide encryption, decryption, signing, 177 key management and functions. It builds on the foundation provided 178 in RFC 1991 "PGP Message Exchange Formats." 180 1.1. Terms 182 * OpenPGP - This is a definition for security software that uses 183 PGP 5.x as a basis. 185 * PGP - Pretty Good Privacy. PGP is a family of software systems 186 developed by Philip R. Zimmermann from which OpenPGP is based. 188 * PGP 2.6.x - This version of PGP has many variants, hence the 189 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 190 cryptographic transforms. 192 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 193 the community and also in the predecessor of this document, 194 RFC1991. It has new formats and corrects a number of problems in 195 the PGP 2.6.x design. It is referred to here as PGP 5.x because 196 that software was the first release of the "PGP 3" code base. 198 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 199 Network Associates, Inc. 201 2. General functions 203 OpenPGP provides data integrity services for messages and data files 204 by using these core technologies: 206 - digital signatures 208 - encryption 210 - compression 212 - radix-64 conversion 214 In addition, OpenPGP provides key management and certificate 215 services, but many of these are beyond the scope of this document. 217 2.1. Confidentiality via Encryption 219 OpenPGP uses two encryption methods to provide confidentiality: 220 symmetric-key encryption and public key encryption. With public-key 221 encryption, the object is encrypted using a symmetric encryption 222 algorithm. Each symmetric key is used only once. A new "session 223 key" is generated as a random number for each message. Since it is 224 used only once, the session key is bound to the message and 225 transmitted with it. To protect the key, it is encrypted with the 226 receiver's public key. The sequence is as follows: 228 1. The sender creates a message. 230 2. The sending OpenPGP generates a random number to be used as a 231 session key for this message only. 233 3. The session key is encrypted using each recipient's public key. 234 These "encrypted session keys" start the message. 236 4. The sending OpenPGP encrypts the message using the session key, 237 which forms the remainder of the message. Note that the message 238 is also usually compressed. 240 5. The receiving OpenPGP decrypts the session key using the 241 recipient's private key. 243 6. The receiving OpenPGP decrypts the message using the session 244 key. If the message was compressed, it will be decompressed. 246 With symmetric-key encryption, an object may encrypted with a 247 symmetric key derived from a passphrase (or other shared secret), or 248 a two-stage mechanism similar to the public-key method aboved can be 249 used where a session key is itself encrypted with a symmetric 250 algorithm keyed from a shared secret. 252 Both digital signature and confidentiality services may be applied 253 to the same message. First, a signature is generated for the message 254 and attached to the message. Then, the message plus signature is 255 encrypted using a symmetric session key. Finally, the session key is 256 encrypted using public-key encryption and prepended to the encrypted 257 block. 259 2.2. Authentication via Digital signature 261 The digital signature uses a hash code or message digest algorithm, 262 and a public-key signature algorithm. The sequence is as follows: 264 1. The sender creates a message. 266 2. The sending software generates a hash code of the message. 268 3. The sending software generates a signature from the hash code 269 using the sender's private key. 271 4. The binary signature is attached to the message. 273 5. The receiving software keeps a copy of the message signature. 275 6. The receiving software generates a new hash code for the 276 received message and verifies it using the message's signature. 277 If the verification is successful, the message is accepted as 278 authentic. 280 2.3. Compression 282 OpenPGP implementations MAY compress the message after applying the 283 signature but before encryption. 285 2.4. Conversion to Radix-64 287 OpenPGP's underlying native representation for encrypted messages, 288 signature certificates, and keys is a stream of arbitrary octets. 289 Some systems only permit the use of blocks consisting of seven-bit, 290 printable text. For transporting OpenPGP's native raw binary octets 291 through channels that are not safe to raw binary data, a printable 292 encoding of these binary octets is needed. OpenPGP provides the 293 service of converting the raw 8-bit binary octet stream to a stream 294 of printable ASCII characters, called Radix-64 encoding or ASCII 295 Armor. 297 Implementations SHOULD provide Radix-64 conversions. 299 Note that many applications, particularly messaging applications, 300 will want more advanced features as described in the OpenPGP-MIME 301 document, RFC2015. An application that implements OpenPGP for 302 messaging SHOULD implement OpenPGP-MIME. 304 3. Data Element Formats 306 This section describes the data elements used by OpenPGP. 308 3.1. Scalar numbers 310 Scalar numbers are unsigned, and are always stored in big-endian 311 format. Using n[k] to refer to the kth octet being interpreted, the 312 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 313 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 314 n[3]). 316 3.2. Multi-Precision Integers 318 Multi-Precision Integers (also called MPIs) are unsigned integers 319 used to hold large integers such as the ones used in cryptographic 320 calculations. 322 An MPI consists of two pieces: a two-octet scalar that is the length 323 of the MPI in bits followed by a string of octets that contain the 324 actual integer. 326 These octets form a big-endian number; a big-endian number can be 327 made into an MPI by prefixing it with the appropriate length. 329 Examples: 331 (all numbers are in hexadecimal) 333 The string of octets [00 01 01] forms an MPI with the value 1. The 334 string [00 09 01 FF] forms an MPI with the value of 511. 336 Additional rules: 338 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 340 The length field of an MPI describes the length starting from its 341 most significant non-zero bit. Thus, the MPI [00 02 01] is not 342 formed correctly. It should be [00 01 01]. 344 3.3. Key IDs 346 A Key ID is an eight-octet scalar that identifies a key. 347 Implementations SHOULD NOT assume that Key IDs are unique. The 348 section, "Enhanced Key Formats" below describes how Key IDs are 349 formed. 351 3.4. Text 353 The default character set for text is the UTF-8 [RFC2044] encoding 354 of Unicode [ISO10646]. 356 3.5. Time fields 358 A time field is an unsigned four-octet number containing the number 359 of seconds elapsed since midnight, 1 January 1970 UTC. 361 3.6. String-to-key (S2K) specifiers 363 String-to-key (S2K) specifiers are used to convert passphrase 364 strings into symmetric-key encryption/decryption keys. They are 365 used in two places, currently: to encrypt the secret part of private 366 keys in the private keyring, and to convert passphrases to 367 encryption keys for symmetrically encrypted messages. 369 3.6.1. String-to-key (S2k) specifier types 371 There are three types of S2K specifiers currently supported, as 372 follows: 374 3.6.1.1. Simple S2K 376 This directly hashes the string to produce the key data. See below 377 for how this hashing is done. 379 Octet 0: 0x00 380 Octet 1: hash algorithm 382 Simple S2K hashes the passphrase to produce the session key. The 383 manner in which this is done depends on the size of the session key 384 (which will depend on the cipher used) and the size of the hash 385 algorithm's output. If the hash size is greater than or equal to the 386 session key size, the high-order (leftmost) octets of the hash are 387 used as the key. 389 If the hash size is less than the key size, multiple instances of 390 the hash context are created -- enough to produce the required key 391 data. These instances are preloaded with 0, 1, 2, ... octets of 392 zeros (that is to say, the first instance has no preloading, the 393 second gets preloaded with 1 octet of zero, the third is preloaded 394 with two octets of zeros, and so forth). 396 As the data is hashed, it is given independently to each hash 397 context. Since the contexts have been initialized differently, they 398 will each produce different hash output. Once the passphrase is 399 hashed, the output data from the multiple hashes is concatenated, 400 first hash leftmost, to produce the key data, with any excess octets 401 on the right discarded. 403 3.6.1.2. Salted S2K 405 This includes a "salt" value in the S2K specifier -- some arbitrary 406 data -- that gets hashed along with the passphrase string, to help 407 prevent dictionary attacks. 409 Octet 0: 0x01 410 Octet 1: hash algorithm 411 Octets 2-9: 8-octet salt value 413 Salted S2K is exactly like Simple S2K, except that the input to the 414 hash function(s) consists of the 8 octets of salt from the S2K 415 specifier, followed by the passphrase. 417 3.6.1.3. Iterated and Salted S2K 419 This includes both a salt and an octet count. The salt is combined 420 with the passphrase and the resulting value is hashed repeatedly. 421 This further increases the amount of work an attacker must do to try 422 dictionary attacks. 424 Octet 0: 0x03 425 Octet 1: hash algorithm 426 Octets 2-9: 8-octet salt value 427 Octet 10: count, a one-octet, coded value 429 The count is coded into a one-octet number using the following 430 formula: 432 #define EXPBIAS 6 433 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 435 The above formula is in C, where "Int32" is a type for a 32-bit 436 integer, and the variable "c" is the coded count, Octet 10. 438 Iterated-Salted S2K hashes the passphrase and salt data multiple 439 times. The total number of octets to be hashed is specified in the 440 encoded count in the S2K specifier. Note that the resulting count 441 value is an octet count of how many octets will be hashed, not an 442 iteration count. 444 Initially, one or more hash contexts are set up as with the other 445 S2K algorithms, depending on how many octets of key data are needed. 446 Then the salt, followed by the passphrase data is repeatedly hashed 447 until the number of octets specified by the octet count has been 448 hashed. The one exception is that if the octet count is less than 449 the size of the salt plus passphrase, the full salt plus passphrase 450 will be hashed even though that is greater than the octet count. 451 After the hashing is done the data is unloaded from the hash 452 context(s) as with the other S2K algorithms. 454 3.6.2. String-to-key usage 456 Implementations SHOULD use salted or iterated-and-salted S2K 457 specifiers, as simple S2K specifiers are more vulnerable to 458 dictionary attacks. 460 3.6.2.1. Secret key encryption 462 An S2K specifier can be stored in the secret keyring to specify how 463 to convert the passphrase to a key that unlocks the secret data. 464 Older versions of PGP just stored a cipher algorithm octet preceding 465 the secret data or a zero to indicate that the secret data was 466 unencrypted. The MD5 hash function was always used to convert the 467 passphrase to a key for the specified cipher algorithm. 469 For compatibility, when an S2K specifier is used, the special value 470 255 is stored in the position where the hash algorithm octet would 471 have been in the old data structure. This is then followed 472 immediately by a one-octet algorithm identifier, and then by the S2K 473 specifier as encoded above. 475 Therefore, preceding the secret data there will be one of these 476 possibilities: 478 0: secret data is unencrypted (no pass phrase) 479 255: followed by algorithm octet and S2K specifier 480 Cipher alg: use Simple S2K algorithm using MD5 hash 482 This last possibility, the cipher algorithm number with an implicit 483 use of MD5 and IDEA, is provided for backward compatibility; it MAY 484 be understood, but SHOULD NOT be generated, and is deprecated. 486 These are followed by an 8-octet Initial Vector for the decryption 487 of the secret values, if they are encrypted, and then the secret key 488 values themselves. 490 3.6.2.2. Symmetric-key message encryption 492 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 493 packet at the front of a message. This is used to allow S2K 494 specifiers to be used for the passphrase conversion or to create 495 messages with a mix of symmetric-key ESKs and public-key ESKs. This 496 allows a message to be decrypted either with a passphrase or a 497 public key. 499 PGP 2.X always used IDEA with Simple string-to-key conversion when 500 encrypting a message with a symmetric algorithm. This is deprecated, 501 but MAY be used for backwards-compatibility. 503 4. Packet Syntax 505 This section describes the packets used by OpenPGP. 507 4.1. Overview 509 An OpenPGP message is constructed from a number of records that are 510 traditionally called packets. A packet is a chunk of data that has a 511 tag specifying its meaning. An OpenPGP message, keyring, 512 certificate, and so forth consists of a number of packets. Some of 513 those packets may contain other OpenPGP packets (for example, a 514 compressed data packet, when uncompressed, contains OpenPGP 515 packets). 517 Each packet consists of a packet header, followed by the packet 518 body. The packet header is of variable length. 520 4.2. Packet Headers 522 The first octet of the packet header is called the "Packet Tag." It 523 determines the format of the header and denotes the packet contents. 524 The remainder of the packet header is the length of the packet. 526 Note that the most significant bit is the left-most bit, called bit 527 7. A mask for this bit is 0x80 in hexadecimal. 529 +---------------+ 530 PTag |7 6 5 4 3 2 1 0| 531 +---------------+ 532 Bit 7 -- Always one 533 Bit 6 -- New packet format if set 535 PGP 2.6.x only uses old format packets. Thus, software that 536 interoperates with those versions of PGP must only use old format 537 packets. If interoperability is not an issue, either format may be 538 used. Note that old format packets have four bits of content tags, 539 and new format packets have six; some features cannot be used and 540 still be backwards-compatible. 542 Old format packets contain: 544 Bits 5-2 -- content tag 545 Bits 1-0 - length-type 547 New format packets contain: 549 Bits 5-0 -- content tag 551 4.2.1. Old-Format Packet Lengths 553 The meaning of the length-type in old-format packets is: 555 0 - The packet has a one-octet length. The header is 2 octets long. 557 1 - The packet has a two-octet length. The header is 3 octets long. 559 2 - The packet has a four-octet length. The header is 5 octets long. 561 3 - The packet is of indeterminate length. The header is 1 octet 562 long, and the implementation must determine how long the packet 563 is. If the packet is in a file, this means that the packet 564 extends until the end of the file. With a compressed packet, the 565 algorithm implicitly denotes how the end of the packet. In 566 general, an implementation SHOULD NOT use indeterminate length 567 packets except where the end of the data will be clear from the 568 context, and even then it is better to use a definite length, or 569 a new-format header. The new-format headers described below have 570 a mechanism for precisely encoding data of indeterminite length. 572 4.2.2. New-Format Packet Lengths 574 New format packets have four possible ways of encoding length: 576 1. A one-octet Body Length header encodes packet lengths of up to 577 191 octets. 579 2. A two-octet Body Length header encodes packet lengths of 192 to 580 8383 octets. 582 3. A five-octet Body Length header encodes packet lengths of up to 583 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 584 encodes a four-octet scalar number.) 586 4. When the length of the packet body is not known in advance by 587 the issuer, Partial Body Length headers encode a packet of 588 indeterminite length, effectively making it a stream. 590 4.2.2.1. One-Octet Lengths 592 A one-octet Body Length header encodes a length of from 0 to 191 593 octets. This type of length header is recognized because the one 594 octet value is less than 192. The body length is equal to: 596 bodyLen = length_octet; 598 4.2.2.2. Two-Octet Lengths 600 A two-octet Body Length header encodes a length of from 192 to 8383 601 octets. It is recognized because its first octet is in the range 602 192 to 223. The body length is equal to: 604 bodyLen = (1st_octet - 192) * 256 + (2nd_octet) + 192 606 4.2.2.3. Five-Octet Lengths 608 A five-octet Body Length header consists of a single octet holding 609 the value 255, followed by a four-octet scalar. The body length is 610 equal to: 612 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 613 (4th_octet << 8) | 5th_octet 615 4.2.2.4. Partial Body Lengths 617 A Partial Body Length header is one octet long and encodes the 618 length of only part of the data packet. This length is a power of 2, 619 from 1 to 1,073,741,824 (2 to the 30th power). It is recognized by 620 its one octet value that is greater than or equal to 224, and less 621 than 255. The partial body length is equal to: 623 partialBodyLen = 1 << (length_octet & 0x1f); 625 Each Partial Body Length header is followed by a portion of the 626 packet body data. The Partial Body Length header specifies this 627 portion's length. Another length header (of one of the three types 628 -- one octet, two-octet, or partial) follows that portion. The last 629 length header in the packet MUST NOT be a partial Body Length 630 header. Partial Body Length headers may only be used for the 631 non-final parts of the packet. 633 4.2.3. Packet Length Examples 635 A packet with length 100 may have its length encoded in one octet: 636 0x64. This is followed by 100 octets of data. 638 A packet with length 1723 may have its length coded in two octets: 639 0xC5, 0xFB. This header is followed by the 1723 octets of data. 641 A packet with length 100000 may have its length encoded in five 642 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 644 It might also be encoded in the following octet stream: 0xEF, first 645 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 646 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 647 1693 octets of data. This is just one possible encoding, and many 648 variations are possible on the size of the Partial Body Length 649 headers, as long as a regular Body Length header encodes the last 650 portion of the data. Note also that the last Body Length header can 651 be a zero-length header. 653 An implementation MAY use Partial Body Lengths for data packets, be 654 they literal, compressed, or encrypted. The first partial length 655 MUST be at least 512 octets long. Partial Body Lengths MAY NOT be 656 used for any other packet types. 658 Please note that in all of these explanations, the total length of 659 the packet is the length of the header(s) plus the length of the 660 body. 662 4.3. Packet Tags 664 The packet tag denotes what type of packet the body holds. Note that 665 old format headers can only have tags less than 16, whereas new 666 format headers can have tags as great as 63. The defined tags (in 667 decimal) are: 669 0 -- Reserved - a packet tag must not have this value 670 1 -- Public-Key Encrypted Session Key Packet 671 2 -- Signature Packet 672 3 -- Symmetric-Key Encrypted Session Key Packet 673 4 -- One-Pass Signature Packet 674 5 -- Secret Key Packet 675 6 -- Public Key Packet 676 7 -- Secret Subkey Packet 677 8 -- Compressed Data Packet 678 9 -- Symmetrically Encrypted Data Packet 679 10 -- Marker Packet 680 11 -- Literal Data Packet 681 12 -- Trust Packet 682 13 -- User ID Packet 683 14 -- Subkey Packet 684 60 to 63 -- Private or Experimental Values 686 5. Packet Types 688 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 689 A Public-Key Encrypted Session Key packet holds the session key used 690 to encrypt a message. Zero or more Encrypted Session Key packets 691 (either Public-Key or Symmetric-Key) may precede a Symmetrically 692 Encrypted Data Packet, which holds an encrypted message. The 693 message is encrypted with the session key, and the session key is 694 itself encrypted and stored in the Encrypted Session Key packet(s). 695 The Symmetrically Encrypted Data Packet is preceded by one 696 Public-Key Encrypted Session Key packet for each OpenPGP key to 697 which the message is encrypted. The recipient of the message finds 698 a session key that is encrypted to their public key, decrypts the 699 session key, and then uses the session key to decrypt the message. 701 The body of this packet consists of: 703 - A one-octet number giving the version number of the packet type. 704 The currently defined value for packet version is 3. An 705 implementation should accept, but not generate a version of 2, 706 which is equivalent to V3 in all other respects. 708 - An eight-octet number that gives the key ID of the public key 709 that the session key is encrypted to. 711 - A one-octet number giving the public key algorithm used. 713 - A string of octets that is the encrypted session key. This 714 string takes up the remainder of the packet, and its contents 715 are dependent on the public key algorithm used. 717 Algorithm Specific Fields for RSA encryption 719 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 721 Algorithm Specific Fields for Elgamal encryption: 723 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 725 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 727 The value "m" in the above formulas is derived from the session key 728 as follows. First the session key is prefixed with a one-octet 729 algorithm identifier that specifies the symmetric encryption 730 algorithm used to encrypt the following Symmetrically Encrypted Data 731 Packet. Then a two-octet checksum is appended which is equal to the 732 sum of the preceding octets, including the algorithm identifier and 733 session key, modulo 65536. This value is then padded as described 734 in PKCS-1 block type 02 [PKCS1] to form the "m" value used in the 735 formulas above. 737 Note that when an implementation forms several PKESKs with one 738 session key, forming a message that can be decrypted by several 739 keys, the PKCS-1 the implementation MUST make new padding for each 740 key. 742 An implementation MAY accept or use a Key ID of zero as a "wild 743 card" or "speculative" Key ID. In this case, the receiving 744 implementation would try all available private keys, checking for a 745 valid decrypted session key. This format helps reduce traffic 746 analysis of messages. 748 5.2. Signature Packet (Tag 2) 750 A signature packet describes a binding between some public key and 751 some data. The most common signatures are a signature of a file or a 752 block of text, and a signature that is a certification of a user ID. 754 Two versions of signature packets are defined. Version 3 provides 755 basic signature information, while version 4 provides an expandable 756 format with subpackets that can specify more information about the 757 signature. PGP 2.6.x only accepts version 3 signatures. 759 Implementations MUST accept V3 signatures. Implementations SHOULD 760 generate V4 signatures. Implementations MAY generate a V3 signature 761 that can be verified by PGP 2.6.x. 763 Note that if an implementation is creating an encrypted and signed 764 message that is encrypted to a V3 key, it is reasonable to create a 765 V3 signature. 767 5.2.1. Signature Types 769 There are a number of possible meanings for a signature, which are 770 specified in a signature type octet in any given signature. These 771 meanings are: 773 0x00: Signature of a binary document. 774 Typically, this means the signer owns it, created it, or 775 certifies that it has not been modified. 777 0x01: Signature of a canonical text document. 778 Typically, this means the signer owns it, created it, or 779 certifies that it has not been modified. The signature will be 780 calculated over the text data with its line endings converted to 781 and trailing blanks removed. 783 0x02: Standalone signature. 784 This signature is a signature of only its own subpacket 785 contents. It is calculated identically to a signature over a 786 zero-length binary document. Note that it doesn't make sense to 787 have a V3 standalone signature. 789 0x10: Generic certification of a User ID and Public Key packet. 790 The issuer of this certification does not make any particular 791 assertion as to how well the certifier has checked that the 792 owner of the key is in fact the person described by the user ID. 793 Note that all PGP "key signatures" are this type of 794 certification. 796 0x11: Persona certification of a User ID and Public Key packet. 797 The issuer of this certification has not done any verification 798 of the claim that the owner of this key is the user ID 799 specified. 801 0x12: Casual certification of a User ID and Public Key packet. 802 The issuer of this certification has done some casual 803 verification of the claim of identity. 805 0x13: Positive certification of a User ID and Public Key packet. 806 The issuer of this certification has done substantial 807 verification of the claim of identity. 809 Please note that the vagueness of these certification claims is 810 not a flaw, but a feature of the system. Because PGP places 811 final authority for validity upon the receiver of a 812 certification, it may be that one authority's casual 813 certification might be more rigorous than some other authority's 814 positive certification. These classifications allow a 815 certification authority to issue fine-grained claims. 817 0x18: Subkey Binding Signature 818 This signature is a statement by the top-level signing key 819 indicates that it owns the subkey. This signature is calculated 820 directly on the subkey itself, not on any User ID or other 821 packets. 823 0x1F: Signature directly on a key 824 This signature is calculated directly on a key. It binds the 825 information in the signature subpackets to the key, and is 826 appropriate to be used for subpackets which provide information 827 about the key, such as the revocation key subpacket. It is also 828 appropriate for statements that non-self certifiers want to make 829 about the key itself, rather than the binding between a key and 830 a name. 832 0x20: Key revocation signature 833 The signature is calculated directly on the key being revoked. 834 A revoked key is not to be used. Only revocation signatures by 835 the key being revoked, or by an authorized revocation key, 836 should be considered valid revocation signatures. 838 0x28: Subkey revocation signature 839 The signature is calculated directly on the subkey being 840 revoked. A revoked subkey is not to be used. Only revocation 841 signatures by the top-level signature key which is bound to this 842 subkey, or by an authorized revocation key, should be considered 843 valid revocation signatures. 845 0x30: Certification revocation signature 846 This signature revokes an earlier user ID certification 847 signature (signature class 0x10 through 0x13). It should be 848 issued by the same key which issued the revoked signature or an 849 authorized revocation key The signature should have a later 850 creation date than the signature it revokes. 852 0x40: Timestamp signature. 853 This signature is only meaningful for the timestamp contained in 854 it. 856 5.2.2. Version 3 Signature Packet Format 858 The body of a version 3 Signature Packet contains: 860 - One-octet version number (3). 862 - One-octet length of following hashed material. MUST be 5. 864 - One-octet signature type. 866 - Four-octet creation time. 868 - Eight-octet key ID of signer. 870 - One-octet public key algorithm. 872 - One-octet hash algorithm. 874 - Two-octet field holding left 16 bits of signed hash value. 876 - One or more multi-precision integers comprising the signature. 877 This portion is algorithm specific, as described below. 879 The data being signed is hashed, and then the signature type and 880 creation time from the signature packet are hashed (5 additional 881 octets). The resulting hash value is used in the signature 882 algorithm. The high 16 bits (first two octets) of the hash are 883 included in the signature packet to provide a quick test to reject 884 some invalid signatures. 886 Algorithm Specific Fields for RSA signatures: 888 - multiprecision integer (MPI) of RSA signature value m**d. 890 Algorithm Specific Fields for DSA signatures: 892 - MPI of DSA value r. 894 - MPI of DSA value s. 896 The signature calculation is based on a hash of the signed data, as 897 described above. The details of the calculation are different for 898 DSA signature than for RSA signatures. 900 With RSA signatures, the hash value is encoded as described in 901 PKCS-1 section 10.1.2, "Data encoding", producing an ASN.1 value of 902 type DigestInfo, and then padded using PKCS-1 block type 01 [PKCS1]. 903 This requires inserting the hash value as an octet string into an 904 ASN.1 structure. The object identifier for the type of hash being 905 used is included in the structure. The hexadecimal representations 906 for the currently defined hash algorithms are: 908 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02 910 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 912 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 914 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 916 The ASN.1 OIDs are: 918 - MD2: 1.2.840.113549.2.2 920 - MD5: 1.2.840.113549.2.5 922 - RIPEMD-160: 1.3.36.3.2.1 924 - SHA-1: 1.3.14.3.2.26 926 The full hash prefixes for these are: 928 MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 929 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 930 0x04, 0x10 932 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 933 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 934 0x04, 0x10 936 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 937 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 939 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 940 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 942 DSA signatures SHOULD use hashes with a size of 160 bits, to match 943 q, the size of the group generated by the DSA key's generator value. 944 The hash function result is treated as a 160 bit number and used 945 directly in the DSA signature algorithm. 947 5.2.3. Version 4 Signature Packet Format 949 The body of a version 4 Signature Packet contains: 951 - One-octet version number (4). 953 - One-octet signature type. 955 - One-octet public key algorithm. 957 - One-octet hash algorithm. 959 - Two-octet scalar octet count for following hashed subpacket 960 data. 962 - Hashed subpacket data. (zero or more subpackets) 964 - Two-octet scalar octet count for following unhashed subpacket 965 data. 967 - Unhashed subpacket data. (zero or more subpackets) 969 - Two-octet field holding left 16 bits of signed hash value. 971 - One or more multi-precision integers comprising the signature. 972 This portion is algorithm specific, as described above. 974 The data being signed is hashed, and then the signature data from 975 the version number through the hashed subpacket data (inclusive) is 976 hashed. The resulting hash value is what is signed. The left 16 977 bits of the hash are included in the signature packet to provide a 978 quick test to reject some invalid signatures. 980 There are two fields consisting of signature subpackets. The first 981 field is hashed with the rest of the signature data, while the 982 second is unhashed. The second set of subpackets is not 983 cryptographically protected by the signature and should include only 984 advisory information. 986 The algorithms for converting the hash function result to a 987 signature are described in a section below. 989 5.2.3.1. Signature Subpacket Specification 991 The subpacket fields consist of zero or more signature subpackets. 992 Each set of subpackets is preceded by a two-octet scalar count of 993 the length of the set of subpackets. 995 Each subpacket consists of a subpacket header and a body. The 996 header consists of: 998 - the subpacket length (1, 2, or 5 octets) 1000 - the subpacket type (1 octet) 1002 - the subpacket specific data 1004 The length includes the type octet but not this length. Its format 1005 is the same as the "new" format packet header lengths. That is: 1007 if the 1st octet < 192, then length is the octet value 1009 if the 1st octet >= 192 and < 255, then length is 2 octets and 1010 equal to (1st octet - 192) * 256 + (2nd octet) + 192 1012 if the 1st octet = 255, then the subpacket length is a 1013 four-octet scalar found in octets 2 through 5, as per the packet 1014 header length. 1016 The value of the subpacket type octet may be: 1018 2 = signature creation time 1019 3 = signature expiration time 1020 4 = exportable 1021 5 = trust signature 1022 6 = regular expression 1023 7 = revocable 1024 9 = key expiration time 1025 10 = placeholder for backwards compatibility 1026 11 = preferred symmetric algorithms 1027 12 = revocation key 1028 16 = issuer key ID 1029 20 = notation data 1030 21 = preferred hash algorithms 1031 22 = preferred compression algorithms 1032 23 = key server preferences 1033 24 = preferred key server 1034 25 = primary user id 1035 26 = policy URL 1036 27 = key flags 1037 28 = Signer's user id 1038 100 to 110 = internal or user-defined 1040 An implementation SHOULD ignore any subpacket of a type that it does 1041 not recognize. 1043 Bit 7 of the subpacket type is the "critical" bit. If set, it 1044 denotes that the subpacket is one that is critical for the evaluator 1045 of the signature to recognize. If a subpacket is encountered which 1046 is marked critical but is unknown to the evaluating software, the 1047 evaluator SHOULD consider the signature to be in error. 1049 An evaluator may "recognize" a subpacket, but not implement it. The 1050 purpose of the critical bit is to allow the signer to tell an 1051 evaluator that it would prefer a new, unknown feature to generate an 1052 error than be ignored. 1054 Implementations SHOULD implement "preferences". 1056 5.2.3.2. Signature Subpacket Types 1058 A number of subpackets are currently defined. Some subpackets apply 1059 to the signature itself and some are attributes of the key. 1060 Subpackets that are found on a self-signature are placed on a user 1061 id certification made by the key itself. Note that a key may have 1062 more than one user id, and thus may have more than one 1063 self-signature, and differing subpackets. 1065 A self-signature is a binding signature made by the key the 1066 signature refers to. There are three types of self-signatures, the 1067 certification signatures (types 0x10-0x13), the direct-key signature 1068 (type 0x1f), and the subkey binding signature (type 0x18). For 1069 certification self-signatures, each user ID may have a 1070 self-signature, and thus different subpackets in those 1071 self-signatures. For subkey binding signatures, each subkey in fact 1072 has a self-signature. Subpackets that appear in a certification 1073 self-signature apply to the username, and subpackets that appear in 1074 the subkey self-signature apply to the subkey. Lastly, subpackets on 1075 the direct key signature apply to the entire key. 1077 Implementing software should interpret a self-signature's preference 1078 subpackets as narrowly as possible. For example, suppose a key has 1079 two usernames, Alice and Bob. Suppose that Alice prefers the 1080 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If 1081 the software locates this key via Alice's name, then the preferred 1082 algorithm is CAST5, if software locates the key via Bob's name, then 1083 the preferred algorithm is IDEA. If the key is located by key id, 1084 then algorithm of the default user id of the key provides the 1085 default symmetric algorithm. 1087 A subpacket may be found either in the hashed or unhashed subpacket 1088 sections of a signature. If a subpacket is not hashed, then the 1089 information in it cannot be considered definitive because it is not 1090 part of the signature proper. 1092 5.2.3.3. Signature creation time 1094 (4 octet time field) 1096 The time the signature was made. 1098 MUST be present in the hashed area. 1100 5.2.3.4. Issuer 1102 (8 octet key ID) 1104 The OpenPGP key ID of the key issuing the signature. 1106 MUST be present in the hashed area. 1108 5.2.3.5. Key expiration time 1110 (4 octet time field) 1112 The validity period of the key. This is the number of seconds after 1113 the key creation time that the key expires. If this is not present 1114 or has a value of zero, the key never expires. This is found only on 1115 a self-signature. 1117 5.2.3.6. Preferred symmetric algorithms 1119 (sequence of one-octet values) 1121 Symmetric algorithm numbers that indicate which algorithms the key 1122 holder prefers to use. The subpacket body is an ordered list of 1123 octets with the most preferred listed first. It is assumed that only 1124 algorithms listed are supported by the recipient's software. 1125 Algorithm numbers in section 9. This is only found on a 1126 self-signature. 1128 5.2.3.7. Preferred hash algorithms 1130 (array of one-octet values) 1132 Message digest algorithm numbers that indicate which algorithms the 1133 key holder prefers to receive. Like the preferred symmetric 1134 algorithms, the list is ordered. Algorithm numbers are in section 6. 1135 This is only found on a self-signature. 1137 5.2.3.8. Preferred compression algorithms 1139 (array of one-octet values) 1141 Compression algorithm numbers that indicate which algorithms the key 1142 holder prefers to use. Like the preferred symmetric algorithms, the 1143 list is ordered. Algorithm numbers are in section 6. If this 1144 subpacket is not included, ZIP is preferred. A zero denotes that 1145 uncompressed data is preferred; the key holder's software may not 1146 have compression software. This is only found on a self-signature. 1148 5.2.3.9. Signature expiration time 1150 (4 octet time field) 1151 The validity period of the signature. This is the number of seconds 1152 after the signature creation time that the signature expires. If 1153 this is not present or has a value of zero, it never expires. 1155 5.2.3.10. Exportable 1157 (1 octet of exportability, 0 for not, 1 for exportable) 1159 Signature's exportability status. Packet body contains a boolean 1160 flag indicating whether the signature is exportable. Signatures 1161 which are not exportable are ignored during export and import 1162 operations. If this packet is not present the signature is assumed 1163 to be exportable. 1165 5.2.3.11. Revocable 1167 (1 octet of revocability, 0 for not, 1 for revocable) 1169 Signature's revocability status. Packet body contains a boolean 1170 flag indicating whether the signature is revocable. Signatures 1171 which are not revocable have any later revocation signatures 1172 ignored. They represent a commitment by the signer that he cannot 1173 revoke his signature for the life of his key. If this packet is not 1174 present, the signature is revocable. 1176 5.2.3.12. Trust signature 1178 (1 octet "level" (depth), 1 octet of trust amount) 1180 Signer asserts that the key is not only valid, but also trustworthy, 1181 at the specified level. Level 0 has the same meaning as an ordinary 1182 validity signature. Level 1 means that the signed key is asserted 1183 to be a valid trusted introducer, with the 2nd octet of the body 1184 specifying the degree of trust. Level 2 means that the signed key is 1185 asserted to be trusted to issue level 1 trust signatures, i.e. that 1186 it is a "meta introducer". Generally, a level n trust signature 1187 asserts that a key is trusted to issue level n-1 trust signatures. 1188 The trust amount is in a range from 0-255, interpreted such that 1189 values less than 120 indicate partial trust and values of 120 or 1190 greater indicate complete trust. Implementations SHOULD emit values 1191 of 60 for partial trust and 120 for complete trust. 1193 5.2.3.13. Regular expression 1195 (null-terminated regular expression) 1197 Used in conjunction with trust signature packets (of level > 0) to 1198 limit the scope of trust which is extended. Only signatures by the 1199 target key on user IDs which match the regular expression in the 1200 body of this packet have trust extended by the trust packet. The 1201 regular expression uses the same syntax as the Henry Spencer's 1202 "almost public domain" regular expression package. A description of 1203 the syntax is found in a section below. 1205 5.2.3.14. Revocation key 1207 (1 octet of class, 1 octet of algid, 20 octets of fingerprint) 1209 Authorizes the specified key to issue revocation signatures for this 1210 key. Class octet must have bit 0x80 set, other bits are for future 1211 expansion to other kinds of signature authorizations. This is found 1212 on a self-signature. 1214 Authorizes the specified key to issue revocation signatures for this 1215 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1216 then this means that the revocation information is sensitive. Other 1217 bits are for future expansion to other kinds of authorizations. This 1218 is found on a self-signature. 1220 If the "sensitive" flag is set, the keyholder feels this subpacket 1221 contains private trust information that describes a real-world 1222 sensitive relationship. If this flag is set, implementations SHOULD 1223 NOT export this signature to other users except in cases where the 1224 data needs to be available: when the signature is being sent to the 1225 designated revoker, or when it is accompanied by a revocation 1226 signature from that revoker. Note that it may be appropriate to 1227 isolate this subpacket within a separate signature so that it is not 1228 combined with other subpackets which need to be exported. 1230 5.2.3.15. Notation Data 1232 (4 octets of flags, 2 octets of name length (M), 1233 2 octets of value length (N), 1234 M octets of name data, 1235 N octets of value data) 1237 This subpacket describes a "notation" on the signature that the 1238 issuer wishes to make. The notation has a name and a value, each of 1239 which are strings of octets. There may be more than one notation in 1240 a signature. Notations can be used for any extension the issuer of 1241 the signature cares to make. The "flags" field holds four octets of 1242 flags. 1244 All undefined flags MUST be zero. Defined flags are: 1246 First octet: 0x80 = human-readable. This note is text, a note 1247 from one person to another, and has no 1248 meaning to software. 1249 Other octets: none. 1251 5.2.3.16. Key server preferences 1253 (N octets of flags) 1254 This is a list of flags that indicate preferences that the key 1255 holder has about how the key is handled on a key server. All 1256 undefined flags MUST be zero. 1258 First octet: 0x80 = No-modify 1259 the key holder requests that this key only be modified or 1260 updated by the key holder or an administrator of the key server. 1262 This is found only on a self-signature. 1264 5.2.3.17. Preferred key server 1266 (String) 1268 This is a URL of a key server that the key holder prefers be used 1269 for updates. Note that keys with multiple user ids can have a 1270 preferred key server for each user id. Note also that since this is 1271 a URL, the key server can actually be a copy of the key retrieved by 1272 ftp, http, finger, etc. 1274 5.2.3.18. Primary user id 1276 (1 octet, boolean) 1278 This is a flag in a user id's self signature that states whether 1279 this user id is the main user id for this key. It is reasonable for 1280 an implementation to resolve ambiguities in preferences, etc. by 1281 referring to the primary user id. If this flag is absent, its value 1282 is zero. If more than one user id in a key is marked as primary, the 1283 implementation may resolve the ambiguity in any way it sees fit. 1285 5.2.3.19. Policy URL 1287 (String) 1289 This subpacket contains a URL of a document that describes the 1290 policy under which the signature was issued. 1292 5.2.3.20. Key Flags 1294 (Octet string) 1296 This subpacket contains a list of binary flags that hold information 1297 about a key. It is a string of octets, and an implementation MUST 1298 NOT assume a fixed size. This is so it can grow over time. If a list 1299 is shorter than an implementation expects, the unstated flags are 1300 considered to be zero. The defined flags are: 1302 First octet: 1304 0x01 - This key may be used to certify other keys. 1306 0x02 - This key may be used to sign data. 1308 0x04 - This key may be used to encrypt communications. 1310 0x08 - This key may be used to encrypt storage. 1312 0x10 - The private component of this key may have been split by 1313 a secret-sharing mechanism. 1315 0x80 - The private component of this key may be in the 1316 possession of more than one person. 1318 Usage notes: 1320 The flags in this packet may appear in self-signatures or in 1321 certification signatures. They mean different things depending on 1322 who is making the statement -- for example, a certification 1323 signature that has the "sign data" flag is stating that the 1324 certification is for that use. On the other hand, the 1325 "communications encryption" flag in a self-signature is stating a 1326 preference that a given key be used for communications. Note 1327 however, that it is a thorny issue to determine what is 1328 "communications" and what is "storage." This decision is left wholly 1329 up to the implementation; the authors of this document do not claim 1330 any special wisdom on the issue, and realize that accepted opinion 1331 may change. 1333 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1334 self-signature only; they are meaningless on a certification 1335 signature. They SHOULD be placed only on a direct-key signature 1336 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1337 the key the flag applies to. 1339 5.2.3.21. Signer's User ID 1341 This subpacket allows a keyholder to state which user id is 1342 responsible for the signing. Many keyholders use a single key for 1343 different purposes, such as business communications as well as 1344 personal communications. This subpacket allows such a keyholder to 1345 state which of their roles is making a signature. 1347 5.2.4. Computing Signatures 1349 All signatures are formed by producing a hash over the signature 1350 data, and then using the resulting hash in the signature algorithm. 1352 The signature data is simple to compute for document signatures 1353 (types 0x00 and 0x01), for which the document itself is the data. 1354 For standalone signatures, this is a null string. 1356 When a signature is made over a key, the hash data starts with the 1357 octet 0x99, followed by a two-octet length of the key, and then body 1358 of the key packet. (Note that this is an old-style packet header for 1359 a key packet with two-octet length.) A subkey signature (type 0x18) 1360 then hashes the subkey, using the same format as the main key. Key 1361 revocation signatures (types 0x20 and 0x28) hash only the key being 1362 revoked. 1364 A certification signature (type 0x10 through 0x13) hashes the user 1365 id being bound to the key into the hash context after the above 1366 data. A V3 certification hashes the contents of the name packet, 1367 without any header. A V4 certification hashes the constant 0xb4 1368 (which is an old-style packet header with the length-of-length set 1369 to zero), a four-octet number giving the length of the username, and 1370 then the username data. 1372 Once the data body is hashed, then a trailer is hashed. A V3 1373 signature hashes five octets of the packet body, starting from the 1374 signature type field. This data is the signature type, followed by 1375 the four-octet signature time. A V4 signature hashes the packet body 1376 starting from its first field, the version number, through the end 1377 of the hashed subpacket data. Thus, the fields hashed are the 1378 signature version, the signature type, the public key algorithm, the 1379 hash algorithm, the hashed subpacket length, and the hashed 1380 subpacket body. 1382 V4 signatures also hash in a final trailer of six octets: the 1383 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1384 big-endian number that is the length of the hashed data from the 1385 signature packet (note that this number does not include these final 1386 six octets. 1388 After all this has been hashed, the resulting hash field is used in 1389 the signature algorithm, and placed at the end of the signature 1390 packet. 1392 5.2.4.1. Subpacket Hints 1394 An implementation SHOULD put the two mandatory subpackets, creation 1395 time and issuer, as the first subpackets in the subpacket list, 1396 simply to make it easier for the implementor to find them. 1398 It is certainly possible for a signature to contain conflicting 1399 information in subpackets. For example, a signature may contain 1400 multiple copies of a preference or multiple expiration times. In 1401 most cases, an implementation SHOULD use the last subpacket in the 1402 signature, but MAY use any conflict resolution scheme that makes 1403 more sense. Please note that we are intentionally leaving conflict 1404 resolution to the implementor; most conflicts are simply syntax 1405 errors, and the wishy-washy language here allows a receiver to be 1406 generous in what they accept, while putting pressure on a creator to 1407 be stingy in what they generate. 1409 Some apparent conflicts may actually make sense -- for example, 1410 suppose a keyholder has an V3 key and a V4 key that share the same 1411 RSA key material. Either of these keys can verify a signature 1412 created by the other, and it may be reasonable for a signature to 1413 contain an issuer subpacket for each key, as a way of explicitly 1414 tying those keys to the signature. 1416 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 1418 The Symmetric-Key Encrypted Session Key packet holds the 1419 symmetric-key encryption of a session key used to encrypt a message. 1420 Zero or more Encrypted Session Key packets and/or Symmetric-Key 1421 Encrypted Session Key packets may precede a Symmetrically Encrypted 1422 Data Packet that holds an encrypted message. The message is 1423 encrypted with a session key, and the session key is itself 1424 encrypted and stored in the Encrypted Session Key packet or the 1425 Symmetric-Key Encrypted Session Key packet. 1427 If the Symmetrically Encrypted Data Packet is preceded by one or 1428 more Symmetric-Key Encrypted Session Key packets, each specifies a 1429 passphrase which may be used to decrypt the message. This allows a 1430 message to be encrypted to a number of public keys, and also to one 1431 or more pass phrases. This packet type is new, and is not generated 1432 by PGP 2.x or PGP 5.0. 1434 The body of this packet consists of: 1436 - A one-octet version number. The only currently defined version 1437 is 4. 1439 - A one-octet number describing the symmetric algorithm used. 1441 - A string-to-key (S2K) specifier, length as defined above. 1443 - Optionally, the encrypted session key itself, which is decrypted 1444 with the string-to-key object. 1446 If the encrypted session key is not present (which can be detected 1447 on the basis of packet length and S2K specifier size), then the S2K 1448 algorithm applied to the passphrase produces the session key for 1449 decrypting the file, using the symmetric cipher algorithm from the 1450 Symmetric-Key Encrypted Session Key packet. 1452 If the encrypted session key is present, the result of applying the 1453 S2K algorithm to the passphrase is used to decrypt just that 1454 encrypted session key field, using CFB mode with an IV of all zeros. 1455 The decryption result consists of a one-octet algorithm identifier 1456 that specifies the symmetric-key encryption algorithm used to 1457 encrypt the following Symmetrically Encrypted Data Packet, followed 1458 by the session key octets themselves. 1460 Note: because an all-zero IV is used for this decryption, the S2K 1461 specifier MUST use a salt value, either a a Salted S2K or an 1462 Iterated-Salted S2K. The salt value will insure that the decryption 1463 key is not repeated even if the passphrase is reused. 1465 5.4. One-Pass Signature Packets (Tag 4) 1467 The One-Pass Signature packet precedes the signed data and contains 1468 enough information to allow the receiver to begin calculating any 1469 hashes needed to verify the signature. It allows the Signature 1470 Packet to be placed at the end of the message, so that the signer 1471 can compute the entire signed message in one pass. 1473 A One-Pass Signature does not interoperate with PGP 2.6.x or 1474 earlier. 1476 The body of this packet consists of: 1478 - A one-octet version number. The current version is 3. 1480 - A one-octet signature type. Signature types are described in 1481 section 5.2.3. 1483 - A one-octet number describing the hash algorithm used. 1485 - A one-octet number describing the public key algorithm used. 1487 - An eight-octet number holding the key ID of the signing key. 1489 - A one-octet number holding a flag showing whether the signature 1490 is nested. A zero value indicates that the next packet is 1491 another One-Pass Signature packet which describes another 1492 signature to be applied to the same message data. 1494 5.5. Key Material Packet 1496 A key material packet contains all the information about a public or 1497 private key. There are four variants of this packet type, and two 1498 major versions. Consequently, this section is complex. 1500 5.5.1. Key Packet Variants 1502 5.5.1.1. Public Key Packet (Tag 6) 1504 A Public Key packet starts a series of packets that forms an OpenPGP 1505 key (sometimes called an OpenPGP certificate). 1507 5.5.1.2. Public Subkey Packet (Tag 14) 1509 A Public Subkey packet (tag 14) has exactly the same format as a 1510 Public Key packet, but denotes a subkey. One or more subkeys may be 1511 associated with a top-level key. By convention, the top-level key 1512 provides signature services, and the subkeys provide encryption 1513 services. 1515 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1516 packet. This tag was selected for reuse because no previous version 1517 of PGP ever emitted comment packets but they did properly ignore 1518 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1519 cause it to fail, providing a limited degree of backwards 1520 compatibility. 1522 5.5.1.3. Secret Key Packet (Tag 5) 1524 A Secret Key packet contains all the information that is found in a 1525 Public Key packet, including the public key material, but also 1526 includes the secret key material after all the public key fields. 1528 5.5.1.4. Secret Subkey Packet (Tag 7) 1530 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1531 Key packet, and has exactly the same format. 1533 5.5.2. Public Key Packet Formats 1535 There are two versions of key-material packets. Version 3 packets 1536 were first generated by PGP 2.6. Version 2 packets are identical in 1537 format to Version 3 packets, but are generated by PGP 2.5 or before. 1538 V2 packets are deprecated and they MUST NOT be generated. 1540 PGP 5.0 introduced version 4 packets, with new fields and semantics. 1541 PGP 2.6.x will not accept key-material packets with versions 1542 greater than 3. 1544 OpenPGP implementations SHOULD create keys with version 4 format. An 1545 implementation MAY generate a V3 key to ensure interoperability with 1546 old software; note, however, that V4 keys correct some security 1547 deficiencies in V3 keys. These deficiencies are described below. An 1548 implementation MUST NOT create a V3 key with a public key algorithm 1549 other than RSA. 1551 A version 3 public key or public subkey packet contains: 1553 - A one-octet version number (3). 1555 - A four-octet number denoting the time that the key was created. 1557 - A two-octet number denoting the time in days that this key is 1558 valid. If this number is zero, then it does not expire. 1560 - A one-octet number denoting the public key algorithm of this key 1561 - A series of multi-precision integers comprising the key 1562 material: 1564 - a multiprecision integer (MPI) of RSA public modulus n; 1566 - an MPI of RSA public encryption exponent e. 1568 V3 keys SHOULD only be used for backards compatibility because of 1569 three weaknesses in them. First, it is relatively easy to construct 1570 a V3 key that has the same key ID as any other key because the key 1571 ID is simply the low 64 bits of the public modulus. Secondly, 1572 because the fingerprint of a V3 key hashes the key material, but not 1573 its length, which increases the opportunity for fingerprint 1574 collisions. Third, there are minor weaknesses in the MD5 hash 1575 algorithm that make developers prefer other algorithms. See below 1576 for a fuller discussion of key IDs and fingerprints. 1578 The version 4 format is similar to the version 3 format except for 1579 the absence of a validity period. This has been moved to the 1580 signature packet. In addition, fingerprints of version 4 keys are 1581 calculated differently from version 3 keys, as described in section 1582 "Enhanced Key Formats." 1584 A version 4 packet contains: 1586 - A one-octet version number (4). 1588 - A four-octet number denoting the time that the key was created. 1590 - A one-octet number denoting the public key algorithm of this key 1592 - A series of multi-precision integers comprising the key 1593 material. This algorithm-specific portion is: 1595 Algorithm Specific Fields for RSA public keys: 1597 - multiprecision integer (MPI) of RSA public modulus n; 1599 - MPI of RSA public encryption exponent e. 1601 Algorithm Specific Fields for DSA public keys: 1603 - MPI of DSA prime p; 1605 - MPI of DSA group order q (q is a prime divisor of p-1); 1607 - MPI of DSA group generator g; 1609 - MPI of DSA public key value y (= g**x where x is secret). 1611 Algorithm Specific Fields for Elgamal public keys: 1613 - MPI of Elgamal prime p; 1615 - MPI of Elgamal group generator g; 1617 - MPI of Elgamal public key value y (= g**x where x is 1618 secret). 1620 5.5.3. Secret Key Packet Formats 1622 The Secret Key and Secret Subkey packets contain all the data of the 1623 Public Key and Public Subkey packets, with additional 1624 algorithm-specific secret key data appended, in encrypted form. 1626 The packet contains: 1628 - A Public Key or Public Subkey packet, as described above 1630 - One octet indicating string-to-key usage conventions. 0 1631 indicates that the secret key data is not encrypted. 255 1632 indicates that a string-to-key specifier is being given. Any 1633 other value is a symmetric-key encryption algorithm specifier. 1635 - [Optional] If string-to-key usage octet was 255, a one-octet 1636 symmetric encryption algorithm. 1638 - [Optional] If string-to-key usage octet was 255, a string-to-key 1639 specifier. The length of the string-to-key specifier is implied 1640 by its type, as described above. 1642 - [Optional] If secret data is encrypted, eight-octet Initial 1643 Vector (IV). 1645 - Encrypted multi-precision integers comprising the secret key 1646 data. These algorithm-specific fields are as described below. 1648 - Two-octet checksum of the plaintext of the algorithm-specific 1649 portion (sum of all octets, mod 65536). 1651 Algorithm Specific Fields for RSA secret keys: 1653 - multiprecision integer (MPI) of RSA secret exponent d. 1655 - MPI of RSA secret prime value p. 1657 - MPI of RSA secret prime value q (p < q). 1659 - MPI of u, the multiplicative inverse of p, mod q. 1661 Algorithm Specific Fields for DSA secret keys: 1663 - MPI of DSA secret exponent x. 1665 Algorithm Specific Fields for Elgamal secret keys: 1667 - MPI of Elgamal secret exponent x. 1669 Secret MPI values can be encrypted using a passphrase. If a 1670 string-to-key specifier is given, that describes the algorithm for 1671 converting the passphrase to a key, else a simple MD5 hash of the 1672 passphrase is used. Implementations SHOULD use a string-to-key 1673 specifier; the simple hash is for backwards compatibility. The 1674 cipher for encrypting the MPIs is specified in the secret key 1675 packet. 1677 Encryption/decryption of the secret data is done in CFB mode using 1678 the key created from the passphrase and the Initial Vector from the 1679 packet. A different mode is used with V3 keys (which are onlyRSA) 1680 than with other key formats. With V3 keys, the MPI bit count prefix 1681 (i.e., the first two octets) is not encrypted. Only the MPI 1682 non-prefix data is encrypted. Furthermore, the CFB state is 1683 resynchronized at the beginning of each new MPI value, so that the 1684 CFB block boundary is aligned with the start of the MPI data. 1686 With V4 keys, a simpler method is used. All secret MPI values are 1687 encrypted in CFB mode, including the MPI bitcount prefix. 1689 The 16-bit checksum that follows the algorithm-specific portion is 1690 the algebraic sum, mod 65536, of the plaintext of all the 1691 algorithm-specific octets (including MPI prefix and data). With V3 1692 keys, the checksum is stored in the clear. With V4 keys, the 1693 checksum is encrypted like the algorithm-specific data. This value 1694 is used to check that the passphrase was correct. 1696 5.6. Compressed Data Packet (Tag 8) 1698 The Compressed Data packet contains compressed data. Typically, this 1699 packet is found as the contents of an encrypted packet, or following 1700 a Signature or One-Pass Signature packet, and contains literal data 1701 packets. 1703 The body of this packet consists of: 1705 - One octet that gives the algorithm used to compress the packet. 1707 - The remainder of the packet is compressed data. 1709 A Compressed Data Packet's body contains an block that compresses 1710 some set of packets. See section "Packet Composition" for details on 1711 how messages are formed. 1713 ZIP-compressed packets are compressed with raw RFC1951 DEFLATE 1714 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 1715 implementation uses more bits of compression, it cannot be 1716 decompressed by PGP V2.6 1718 ZLIB-compressed packets are compressed with RFC1950 ZLIB-style 1719 blocks. 1721 5.7. Symmetrically Encrypted Data Packet (Tag 9) 1723 The Symmetrically Encrypted Data packet contains data encrypted with 1724 a symmetric-key algorithm. When it has been decrypted, it will 1725 typically contain other packets (often literal data packets or 1726 compressed data packets). 1728 The body of this packet consists of: 1730 - Encrypted data, the output of the selected symmetric-key cipher 1731 operating in PGP's variant of Cipher Feedback (CFB) mode. 1733 The symmetric cipher used may be specified in an Public-Key or 1734 Symmetric-Key Encrypted Session Key packet which precedes the 1735 Symmetrically Encrypted Data Packet. In that case, the cipher 1736 algorithm octet is prefixed to the session key before it is 1737 encrypted. If no packets of these types precede the encrypted data, 1738 the IDEA algorithm is used with the session key calculated as the 1739 MD5 hash of the passphrase. 1741 The data is encrypted in CFB mode, with a CFB shift size equal to 1742 the cipher's block size. The Initial Vector (IV) is specified as 1743 all zeros. Instead of using an IV, OpenPGP prefixes a 10 octet 1744 string to the data before it is encrypted. The first eight octets 1745 are random, and the 9th and 10th octets are copies of the 7th and 1746 8th octets, respectivelly. After encrypting the first 10 octets, the 1747 CFB state is resynchronized if the cipher block size is 8 octets or 1748 less. The last 8 octets of ciphertext are passed through the cipher 1749 and the block boundary is reset. 1751 The repetition of 16 bits in the 80 bits of random data prepended to 1752 the message allows the receiver to immediately check whether the 1753 session key is incorrect. 1755 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 1757 An experimental version of PGP used this packet as the Literal 1758 packet, but no released version of PGP generated Literal packets 1759 with this tag. With PGP 5.x, this packet has been re-assigned and is 1760 reserved for use as the Marker packet. 1762 The body of this packet consists of: 1764 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 1766 Such a packet MUST be ignored when received. It may be placed at 1767 the beginning of a message that uses features not available in PGP 1768 2.6.x in order to cause that version to report that newer software 1769 is necessary to process the message. 1771 5.9. Literal Data Packet (Tag 11) 1773 A Literal Data packet contains the body of a message; data that is 1774 not to be further interpreted. 1776 The body of this packet consists of: 1778 - A one-octet field that describes how the data is formatted. 1780 If it is a 'b' (0x62), then the literal packet contains binary data. 1781 If it is a 't' (0x74), then it contains text data, and thus may need 1782 line ends converted to local form, or other text-mode changes. RFC 1783 1991 also defined a value of 'l' as a 'local' mode for machine-local 1784 conversions. This use is now deprecated. 1786 - File name as a string (one-octet length, followed by file name), 1787 if the encrypted data should be saved as a file. 1789 If the special name "_CONSOLE" is used, the message is considered to 1790 be "for your eyes only". This advises that the message data is 1791 unusually sensitive, and the receiving program should process it 1792 more carefully, perhaps avoiding storing the received data to disk, 1793 for example. 1795 - A four-octet number that indicates the modification date of the 1796 file, or the creation time of the packet, or a zero that 1797 indicates the present time. 1799 - The remainder of the packet is literal data. 1801 Text data is stored with text endings (i.e. network-normal 1802 line endings). These should be converted to native line endings by 1803 the receiving software. 1805 5.10. Trust Packet (Tag 12) 1807 The Trust packet is used only within keyrings and is not normally 1808 exported. Trust packets contain data that record the user's 1809 specifications of which key holders are trustworthy introducers, 1810 along with other information that implementing software uses for 1811 trust information. 1813 Trust packets SHOULD NOT be emitted to output streams that are 1814 transferred to other users, and they SHOULD be ignored on any input 1815 other than local keyring files. 1817 5.11. User ID Packet (Tag 13) 1819 A User ID packet consists of data which is intended to represent the 1820 name and email address of the key holder. By convention, it 1821 includes an RFC822 mail name, but there are no restrictions on its 1822 content. The packet length in the header specifies the length of 1823 the user id. If it is text, it is encoded in UTF-8. 1825 6. Radix-64 Conversions 1827 As stated in the introduction, OpenPGP's underlying native 1828 representation for objects is a stream of arbitrary octets, and some 1829 systems desire these objects to be immune to damage caused by 1830 character set translation, data conversions, etc. 1832 In principle, any printable encoding scheme that met the 1833 requirements of the unsafe channel would suffice, since it would not 1834 change the underlying binary bit streams of the native OpenPGP data 1835 structures. The OpenPGP standard specifies one such printable 1836 encoding scheme to ensure interoperability. 1838 OpenPGP's Radix-64 encoding is composed of two parts: a base64 1839 encoding of the binary data, and a checksum. The base64 encoding is 1840 identical to the MIME base64 content-transfer-encoding [RFC 2045, 1841 Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to 1842 protect the raw binary data. 1844 The checksum is a 24-bit CRC converted to four characters of 1845 radix-64 encoding by the same MIME base64 transformation, preceded 1846 by an equals sign (=). The CRC is computed by using the generator 1847 0x864CFB and an initialization of 0xB704CE. The accumulation is 1848 done on the data before it is converted to radix-64, rather than on 1849 the converted data. A sample implementation of this algorithm is in 1850 the next section. 1852 The checksum with its leading equal sign MAY appear on the first 1853 line after the Base64 encoded data. 1855 Rationale for CRC-24: The size of 24 bits fits evenly into printable 1856 base64. The nonzero initialization can detect more errors than a 1857 zero initialization. 1859 6.1. An Implementation of the CRC-24 in "C" 1861 #define CRC24_INIT 0xb704ce 1862 #define CRC24_POLY 0x1864cfb 1864 typedef long crc24; 1865 crc24 crc_octets(unsigned char *octets, size_t len) 1866 { 1867 crc24 crc = CRC24_INIT; 1868 int i; 1869 while (len--) { 1870 crc ^= *octets++; 1871 for (i = 0; i < 8; i++) { 1872 crc <<= 1; 1873 if (crc & 0x1000000) 1874 crc ^= CRC24_POLY; 1875 } 1876 } 1877 return crc; 1878 } 1880 6.2. Forming ASCII Armor 1882 When OpenPGP encodes data into ASCII Armor, it puts specific headers 1883 around the data, so OpenPGP can reconstruct the data later. OpenPGP 1884 informs the user what kind of data is encoded in the ASCII armor 1885 through the use of the headers. 1887 Concatenating the following data creates ASCII Armor: 1889 - An Armor Header Line, appropriate for the type of data 1891 - Armor Headers 1893 - A blank (zero-length, or containing only whitespace) line 1895 - The ASCII-Armored data 1897 - An Armor Checksum 1899 - The Armor Tail, which depends on the Armor Header Line. 1901 An Armor Header Line consists of the appropriate header line text 1902 surrounded by five (5) dashes ('-', 0x2D) on either side of the 1903 header line text. The header line text is chosen based upon the 1904 type of data that is being encoded in Armor, and how it is being 1905 encoded. Header line texts include the following strings: 1907 BEGIN PGP MESSAGE 1908 Used for signed, encrypted, or compressed files 1910 BEGIN PGP PUBLIC KEY BLOCK 1911 Used for armoring public keys 1913 BEGIN PGP PRIVATE KEY BLOCK 1914 Used for armoring private keys 1916 BEGIN PGP MESSAGE, PART X/Y 1917 Used for multi-part messages, where the armor is split amongst Y 1918 parts, and this is the Xth part out of Y. 1920 BEGIN PGP MESSAGE, PART X 1921 Used for multi-part messages, where this is the Xth part of an 1922 unspecified number of parts. Requires the MESSAGE-ID Armor 1923 Header to be used. 1925 BEGIN PGP SIGNATURE 1926 Used for detached signatures, OpenPGP/MIME signatures, and 1927 signatures following clearsigned messages 1929 The Armor Headers are pairs of strings that can give the user or the 1930 receiving OpenPGP implementation some information about how to 1931 decode or use the message. The Armor Headers are a part of the 1932 armor, not a part of the message, and hence are not protected by any 1933 signatures applied to the message. 1935 The format of an Armor Header is that of a key-value pair. A colon 1936 (':' 0x38) and a single space (0x20) separate the key and value. 1937 OpenPGP should consider improperly formatted Armor Headers to be 1938 corruption of the ASCII Armor. Unknown keys should be reported to 1939 the user, but OpenPGP should continue to process the message. 1941 Currently defined Armor Header Keys are: 1943 - "Version", which states the OpenPGP Version used to encode the 1944 message. 1946 - "Comment", a user-defined comment. 1948 - "MessageID", a 32-character string of printable characters. The 1949 string must be the same for all parts of a multi-part message 1950 that uses the "PART X" Armor Header. MessageID strings should 1951 be unique enough that the recipient of the mail can associate 1952 all the parts of a message with each other. A good checksum or 1953 cryptographic hash function is sufficent. 1955 The MessageID SHOULD NOT appear unless it is in a multi-part 1956 message. If it appears at all, it MUST be computed from the 1957 finished (encrypted, signed, etc.) message in a deterministic 1958 fashion, rather than contain a purely random value. This is to 1959 allow the legitimate recipient to determine that the MessageID 1960 cannot serve as a covert means of leaking cryptographic key 1961 information. 1963 The Armor Tail Line is composed in the same manner as the Armor 1964 Header Line, except the string "BEGIN" is replaced by the string 1965 "END." 1967 6.3. Encoding Binary in Radix-64 1969 The encoding process represents 24-bit groups of input bits as 1970 output strings of 4 encoded characters. Proceeding from left to 1971 right, a 24-bit input group is formed by concatenating three 8-bit 1972 input groups. These 24 bits are then treated as four concatenated 1973 6-bit groups, each of which is translated into a single digit in the 1974 Radix-64 alphabet. When encoding a bit stream with the Radix-64 1975 encoding, the bit stream must be presumed to be ordered with the 1976 most-significant-bit first. That is, the first bit in the stream 1977 will be the high-order bit in the first 8-bit octet, and the eighth 1978 bit will be the low-order bit in the first 8-bit octet, and so on. 1980 +--first octet--+-second octet--+--third octet--+ 1981 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 1982 +-----------+---+-------+-------+---+-----------+ 1983 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 1984 +--1.index--+--2.index--+--3.index--+--4.index--+ 1986 Each 6-bit group is used as an index into an array of 64 printable 1987 characters from the table below. The character referenced by the 1988 index is placed in the output string. 1990 Value Encoding Value Encoding Value Encoding Value Encoding 1991 0 A 17 R 34 i 51 z 1992 1 B 18 S 35 j 52 0 1993 2 C 19 T 36 k 53 1 1994 3 D 20 U 37 l 54 2 1995 4 E 21 V 38 m 55 3 1996 5 F 22 W 39 n 56 4 1997 6 G 23 X 40 o 57 5 1998 7 H 24 Y 41 p 58 6 1999 8 I 25 Z 42 q 59 7 2000 9 J 26 a 43 r 60 8 2001 10 K 27 b 44 s 61 9 2002 11 L 28 c 45 t 62 + 2003 12 M 29 d 46 u 63 / 2004 13 N 30 e 47 v 2005 14 O 31 f 48 w (pad) = 2006 15 P 32 g 49 x 2007 16 Q 33 h 50 y 2009 The encoded output stream must be represented in lines of no more 2010 than 76 characters each. 2012 Special processing is performed if fewer than 24 bits are available 2013 at the end of the data being encoded. There are three possibilities: 2015 1. The last data group has 24 bits (3 octets). No special 2016 processing is needed. 2018 2. The last data group has 16 bits (2 octets). The first two 6-bit 2019 groups are processed as above. The third (incomplete) data group 2020 has two zero-value bits added to it, and is processed as above. 2021 A pad character (=) is added to the output. 2023 3. The last data group has 8 bits (1 octet). The first 6-bit group 2024 is processed as above. The second (incomplete) data group has 2025 four zero-value bits added to it, and is processed as above. Two 2026 pad characters (=) are added to the output. 2028 6.4. Decoding Radix-64 2030 Any characters outside of the base64 alphabet are ignored in 2031 Radix-64 data. Decoding software must ignore all line breaks or 2032 other characters not found in the table above. 2034 In Radix-64 data, characters other than those in the table, line 2035 breaks, and other white space probably indicate a transmission 2036 error, about which a warning message or even a message rejection 2037 might be appropriate under some circumstances. 2039 Because it is used only for padding at the end of the data, the 2040 occurrence of any "=" characters may be taken as evidence that the 2041 end of the data has been reached (without truncation in transit). No 2042 such assurance is possible, however, when the number of octets 2043 transmitted was a multiple of three and no "=" characters are 2044 present. 2046 6.5. Examples of Radix-64 2048 Input data: 0x14fb9c03d97e 2049 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2050 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2051 11111110 2052 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 2053 111110 2054 Decimal: 5 15 46 28 0 61 37 62 2055 Output: F P u c A 9 l + 2057 Input data: 0x14fb9c03d9 2058 Hex: 1 4 f b 9 c | 0 3 d 9 2059 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2060 pad with 00 2061 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2062 Decimal: 5 15 46 28 0 61 36 2063 pad with = 2064 Output: F P u c A 9 k = 2066 Input data: 0x14fb9c03 2067 Hex: 1 4 f b 9 c | 0 3 2068 8-bit: 00010100 11111011 10011100 | 00000011 2069 pad with 0000 2070 6-bit: 000101 001111 101110 011100 | 000000 110000 2071 Decimal: 5 15 46 28 0 48 2072 pad with = = 2073 Output: F P u c A w = = 2075 6.6. Example of an ASCII Armored Message 2077 -----BEGIN PGP MESSAGE----- 2078 Version: OpenPrivacy 0.99 2080 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2081 vBSFjNSiVHsuAA== 2082 =njUN 2083 -----END PGP MESSAGE----- 2085 Note that this example is indented by two spaces. 2087 7. Cleartext signature framework 2089 It is desirable to sign a textual octet stream without ASCII 2090 armoring the stream itself, so the signed text is still readable 2091 without special software. In order to bind a signature to such a 2092 cleartext, this framework is used. (Note that RFC 2015 defines 2093 another way to clear sign messages for environments that support 2094 MIME.) 2096 The cleartext signed message consists of: 2098 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2099 single line, 2101 - Zero or more "Hash" Armor Headers, 2103 - Exactly one empty line not included into the message digest, 2105 - The dash-escaped cleartext that is included into the message 2106 digest, 2108 - The ASCII armored signature(s) including the Armor Header and 2109 Armor Tail Lines. 2111 If the "Hash" armor header is given, the specified message digest 2112 algorithm is used for the signature. If there are no such headers, 2113 SHA-1 is used. If more than one message digest is used in the 2114 signature, the "Hash" armor header contains a comma-delimited list 2115 of used message digests. 2117 Current message digest names are described below with the algorithm 2118 IDs. 2120 7.1. Dash-Escaped Text 2122 The cleartext content of the message must also be dash-escaped. 2124 Dash escaped cleartext is the ordinary cleartext where every line 2125 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2126 (0x2D) and space ' ' (0x20). This prevents the parser from 2127 recognizing armor headers of the cleartext itself. The message 2128 digest is computed using the cleartext itself, not the dash escaped 2129 form. 2131 As with binary signatures on text documents, a cleartext signature 2132 is calculated on the text using canonical line endings. 2133 The line ending (i.e. the ) before the '-----BEGIN PGP 2134 SIGNATURE-----' line that terminates the signed text is not 2135 considered part of the signed text. 2137 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of 2138 any line is ignored when the cleartext signature is calculated. 2140 8. Regular Expressions 2142 A regular expression is zero or more branches, separated by '|'. It 2143 matches anything that matches one of the branches. 2145 A branch is zero or more pieces, concatenated. It matches a match 2146 for the first, followed by a match for the second, etc. 2148 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2149 followed by '*' matches a sequence of 0 or more matches of the atom. 2150 An atom followed by '+' matches a sequence of 1 or more matches of 2151 the atom. An atom followed by '?' matches a match of the atom, or 2152 the null string. 2154 An atom is a regular expression in parentheses (matching a match for 2155 the regular expression), a range (see below), '.' (matching any 2156 single character), '^' (matching the null string at the beginning of 2157 the input string), '$' (matching the null string at the end of the 2158 input string), a '\' followed by a single character (matching that 2159 char- acter), or a single character with no other significance 2160 (matching that character). 2162 A range is a sequence of characters enclosed in '[]'. It normally 2163 matches any single character from the sequence. If the sequence 2164 begins with '^', it matches any single character not from the rest 2165 of the sequence. If two characters in the sequence are separated by 2166 '-', this is shorthand for the full list of ASCII characters between 2167 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2168 ']' in the sequence, make it the first character (following a 2169 possible '^'). To include a literal '-', make it the first or last 2170 character. 2172 9. Constants 2174 This section describes the constants used in OpenPGP. 2176 Note that these tables are not exhaustive lists; an implementation 2177 MAY implement an algorithm not on these lists. 2179 See the section "Notes on Algorithms" below for more discussion of 2180 the algorithms. 2182 9.1. Public Key Algorithms 2184 ID Algorithm 2185 -- --------- 2186 1 - RSA (Encrypt or Sign) 2187 2 - RSA Encrypt-Only 2188 3 - RSA Sign-Only 2189 16 - Elgamal (Encrypt-Only), see [ELGAMAL] 2190 17 - DSA (Digital Signature Standard) 2191 18 - Elliptic Curve 2192 19 - ECDSA 2193 20 - Elgamal (Encrypt or Sign) 2194 21 - Diffie-Hellman (X9.42) 2195 100 to 110 - Private/Experimental algorithm. 2197 Implementations MUST implement DSA for signatures, and Elgamal for 2198 encryption. Implementations SHOULD implement RSA keys. 2199 Implementations MAY implement any other algorithm. 2201 9.2. Symmetric Key Algorithms 2203 ID Algorithm 2204 -- --------- 2205 0 - Plaintext or unencrypted data 2206 1 - IDEA 2207 2 - Triple-DES (DES-EDE, as per spec - 2208 168 bit key derived from 192) 2209 3 - CAST5 (128 bit key) 2210 4 - Blowfish (128 bit key, 16 rounds) 2211 5 - SAFER-SK128 (13 rounds) 2212 6 - DES/SK 2213 100 to 110 - Private/Experimental algorithm. 2215 Implementations MUST implement Triple-DES. Implementations SHOULD 2216 implement IDEA and CAST5.Implementations MAY implement any other 2217 algorithm. 2219 9.3. Compression Algorithms 2221 ID Algorithm 2222 -- --------- 2223 0 - Uncompressed 2224 1 - ZIP (RFC1951) 2225 2 - ZLIB (RFC1950) 2226 100 to 110 - Private/Experimental algorithm. 2228 Implementations MUST implement uncompressed data. Implementations 2229 SHOULD implement ZIP. 2231 9.4. Hash Algorithms 2233 ID Algorithm Text Name 2234 -- --------- ---- ---- 2235 1 - MD5 "MD5" 2236 2 - SHA-1 "SHA1" 2237 3 - RIPE-MD/160 "RIPEMD160" 2238 4 - HAVAL (5 pass, 160-bit) "HAVAL-5-160" 2239 5 - MD2 "MD2" 2240 6 - TIGER/192 "TIGER192" 2241 100 to 110 - Private/Experimental algorithm. 2243 Implementations MUST implement SHA-1. Implementations SHOULD 2244 implement MD5. 2246 10. Packet Composition 2248 OpenPGP packets are assembled into sequences in order to create 2249 messages 2251 and to transfer keys. Not all possible packet sequences are 2252 meaningful and correct. This describes the rules for how packets 2253 should be placed into sequences. 2255 10.1. Transferable Public Keys 2257 OpenPGP users may transfer public keys. The essential elements of a 2258 transferable public key are: 2260 - One Public Key packet 2262 - Zero or more revocation signatures 2264 - One or more User ID packets 2266 - After each User ID packet, zero or more Signature packets 2268 - Zero or more Subkey packets 2270 - After each Subkey packet, one or more Signature packets 2272 The Public Key packet occurs first. Each of the following User ID 2273 packets provides the identity of the owner of this public key. If 2274 there are multiple User ID packets, this corresponds to multiple 2275 means of identifying the same unique individual user; for example, a 2276 user may have more than one email address, and construct a User ID 2277 for each one. 2279 Immediately following each User ID packet, there are zero or more 2280 signature packets. Each signature packet is calculated on the 2281 immediately preceding User ID packet and the initial Public Key 2282 packet. The signature serves to certify the corresponding public key 2283 and user ID. In effect, the signer is testifying to his or her 2284 belief that this public key belongs to the user identified by this 2285 user ID. 2287 After the User ID packets there may be one or more Subkey packets. 2288 In general, subkeys are provided in cases where the top-level public 2289 key is a signature-only key. However, any V4 key may have subkeys, 2290 and the subkeys may be encryption-only keys, signature-only keys, or 2291 general-purpose keys. 2293 Each Subkey packet must be followed by at least one Signature 2294 packet, which should be of the subkey binding signature type, issued 2295 by the top level key. 2297 Subkey and Key packets may each be followed by a revocation 2298 Signature packet to indicate that the key is revoked. Revocation 2299 signatures are only accepted if they are issued by the key itself, 2300 or by a key which is authorized to issue revocations via a 2301 revocation key subpacket in a self-signature by the top level key. 2303 Transferable public key packet sequences may be concatenated to 2304 allow transferring multiple public keys in one operation. 2306 10.2. OpenPGP Messages 2308 An OpenPGP message is a packet or sequence of packets that 2309 corresponds to the following grammatical rules (comma represents 2310 sequential composition, and vertical bar separates alternatives): 2312 OpenPGP Message :- Encrypted Message | Signed Message | 2313 Compressed Message | Literal Message. 2315 Compressed Message :- Compressed Data Packet. 2317 Literal Message :- Literal Data Packet. 2319 ESK :- Pubic Key Encrypted Session Key Packet | 2320 Symmetric-Key Encrypted Session Key Packet. 2322 ESK Sequence :- ESK | ESK Sequence, ESK. 2324 Encrypted Message :- Symmetrically Encrypted Data Packet | 2325 ESK Sequence, Symmetrically Encrypted Data Packet. 2327 One-Pass Signed Message :- One-Pass Signature Packet, 2328 OpenPGP Message, Signature Packet. 2330 Signed Message :- Signature Packet, OpenPGP Message | 2331 One-Pass Signed Message. 2333 In addition, decrypting a Symmetrically Encrypted Data packet and 2335 decompressing a Compressed Data packet must yield a valid OpenPGP 2336 Message. 2338 11. Enhanced Key Formats 2340 11.1. Key Structures 2342 The format of an OpenPGP V3 key is as follows. Entries in square 2343 brackets are optional and ellipses indicate repetition. 2345 RSA Public Key 2346 [Revocation Self Signature] 2347 User ID [Signature ...] 2348 [User ID [Signature ...] ...] 2350 Each signature certifies the RSA public key and the preceding user 2351 ID. The RSA public key can have many user IDs and each user ID can 2352 have many signatures. 2354 The format of an OpenPGP V4 key that uses two public keys is similar 2355 except that the other keys are added to the end as 'subkeys' of the 2356 primary key. 2358 Primary-Key 2359 [Revocation Self Signature] 2360 [Direct Key Self Signature...] 2361 User ID [Signature ...] 2362 [User ID [Signature ...] ...] 2363 [Subkey Primary-Key-Signature ...] 2365 A subkey always has a single signature after it that is issued using 2366 the primary key to tie the two keys together. The new format can 2367 use either the new signature packets or the old signature packets. 2369 In a key that has a main key and subkeys, the primary key MUST be a 2370 key capable of signing. The subkeys may be keys of any other type. 2371 There may be other constructions of V4 keys, too. For example, there 2372 may be a single-key RSA key in V4 format, a DSA primary key with an 2373 RSA encryption key, or RSA primary key with an Elgamal subkey, etc. 2375 It is also possible to have a signature-only subkey. This permits a 2376 primary key that collects certifications (key signatures) but is 2377 used only used for certifying subkeys that are used for encryption 2378 and signatures. 2380 11.2. Key IDs and Fingerprints 2382 For a V3 key, the eight-octet key ID consists of the low 64 bits of 2383 the public modulus of the RSA key. 2385 The fingerprint of a V3 key is formed by hashing the body (but not 2386 the two-octet length) of the MPIs that form the key material (public 2387 modulus n, followed by exponent e) with MD5. 2389 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet 2390 Tag, followed by the two-octet packet length, followed by the entire 2391 Public Key packet starting with the version field. The key ID is 2392 either the low order 64 bits of the fingerprint. Here are the 2393 fields of the hash material, with the example of a DSA key: 2395 a.1) 0x99 (1 octet) 2397 a.2) high order length octet of (b)-(f) (1 octet) 2399 a.3) low order length octet of (b)-(f) (1 octet) 2401 b) version number = 4 (1 octet); 2403 c) time stamp of key creation (4 octets); 2405 d) algorithm (1 octet): 7 = DSA (example); 2407 e) Algorithm specific fields. 2409 Algorithm Specific Fields for DSA keys (example): 2411 e.1) MPI of DSA prime p; 2413 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 2415 e.3) MPI of DSA group generator g; 2417 e.4) MPI of DSA public key value y (= g**x where x is secret). 2419 Note that it is possible for there to be collisions of key IDs -- 2420 two different keys with the same key ID. Note that there is a much 2421 smaller, but still non-zero probability that two different keys have 2422 the same fingerprint. 2424 Also note that if V3 and V4 format keys share the same RSA key 2425 material, they will have different keyids as well as different 2426 fingerprints. 2428 12. Notes on Algorithms 2430 12.1. Symmetric Algorithm Preferences 2431 The symmetric algorithm preference is an ordered list of algorithms 2432 that the keyholder accepts. Since it is found on a self-signature, 2433 it is possible that a keyholder may have different preferences. For 2434 example, Alice may have TripleDES only specified for 2435 "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 2436 "alice@home.org". Note that it is also possible for preferences to 2437 be in a subkey's binding signature. 2439 Since TripleDES is the MUST-implement algorithm, if it is not 2440 explicitly in the the list, it is tacitly at the end. However, it is 2441 good form to place it there explicitly. Note also that if an 2442 implementation does not implement the preference, then it is 2443 implicitly a TripleDES-only implementation. 2445 An implementation MUST not use a symmetric algorithm that is not in 2446 the recipent's preference list. When encrypting to more than one 2447 recipient, the implementation finds a suitable algorithm by taking 2448 the intersection of the preferences of the recipients. Note that the 2449 MUST-implement algorithm, TripleDES, ensures that the intersection 2450 is not null. The implementation may use any mechanism to pick an 2451 algorithm in the intersection. 2453 If an implementation can decrypt a message that a keyholder doesn't 2454 have in their preferences, the implementation SHOULD decrypt the 2455 message anyway, but MUST warn the keyholder than protocol has been 2456 violated. (For example, suppose that Alice, above, has software that 2457 implements all algorithms in this specification. Nonetheless, she 2458 prefers subsets for work or home. If she is sent a message encrypted 2459 with IDEA, which is not in her preferences, the software warns her 2460 that someone sent her an IDEA-encrypted message, but it would 2461 ideally decrypt it anyway.) 2463 An implementation that is striving for backwards compatibility MAY 2464 consider a V3 key with a V3 self-signature to be an implicit 2465 preference for IDEA, and no ability to do TripleDES. This is 2466 technically non-compliant, so if an implementation is forming a 2467 message to be read by a V3 keyholder and a V4 keyholder that does 2468 not speak IDEA, the implementation must somehow break this up into 2469 two messages (which is relatively easy to do for email), or issue an 2470 error message when this is not possible. 2472 12.2. Other Algorithm Preferences 2474 Other algorithm preferences work similarly to the symmetric 2475 algorithm preference, in that they specify which algorithms the 2476 keyholder accepts. There are two interesting cases that other 2477 comments need to be made about, though, the compression preferences 2478 and the hash preferences. 2480 12.2.1. Compression Preferences 2482 Compression has been an integral part of PGP since its first days. 2484 OpenPGP and all previous versions of PGP have offered compression. 2485 And in this specification, the default is for messages to be 2486 compressed, although an implementation is not required to do so. 2487 Consequently, the compression preference gives a way for a keyholder 2488 to request that messages not be compressed, presumably because they 2489 are using a minimal implementation that does not include 2490 compression. Additionally, this gives a keyholder a way to state 2491 that it can support alternate algorithms. 2493 Like the algorithm preferences, an implementation MUST NOT use an 2494 algorithm that is not in the preference vector. If the preferences 2495 are mot present, then they are assumed to be [ZIP(1), 2496 UNCOMPRESSED(0)]. 2498 12.2.2. Hash Algorithm Preferences 2500 Typically, the choice of a hash algorithm is something the signer 2501 does, rather than the verifier, because a signer does not typically 2502 know who is going to be verifying the signature. This preference, 2503 though, allows a protocol based upon digital signatures ease in 2504 negotiation. 2506 Thus, if Alice is authenticating herself to Bob with a signature, it 2507 makes sense for her to use a hash algorithm that Bob's software 2508 uses. This preference allows Bob to state in his key which 2509 algorithms Alice may use. 2511 12.3. Plaintext 2513 Algorithm 0, "plaintext," may only be used to denote secret keys 2514 that are stored in the clear. Implementations must not use plaintext 2515 in Symmetrically Encrypted Data Packets; they must use Literal Data 2516 Packets to encode unencrypted or literal data. 2518 12.4. RSA 2520 There are algorithm types for RSA-signature-only, and 2521 RSA-encrypt-only keys. These types are deprecated. The "key flags" 2522 subpacket in a signature is a much better way to express the same 2523 idea, and generalizes it to all algorithms. An implementation SHOULD 2524 NOT create such a key, but MAY interpret it. 2526 An implementation SHOULD NOT implement RSA keys of size less than 2527 768 bits. 2529 It is permissable for an implementation to support RSA merely for 2530 backwards compatibility; for example, such an implementation would 2531 support V3 keys with IDEA symmetric cryptography. Note that this is 2532 an exception to the other MUST-implement rules. An implementation 2533 that supports RSA in V4 keys MUST implement the MUST-implement 2534 features. 2536 12.5. Elgamal 2538 If an Elgamal key is to be used for both signing and encryption, 2539 extra care must be taken in creating the key. 2541 An ElGamal key consists of a generator g, a prime modulus p, a 2542 secret exponent x, and a public value y = g^x mod p. 2544 The generator and prime must be chosen so that solving the discrete 2545 log problem is intractable. The group g should generate the 2546 multiplicative group mod p-1 or a large subgroup of it, and the 2547 order of g should have at least one large prime factor. A good 2548 choice is to use a "strong" Sophie-Germain prime in choosing p, so 2549 that both p and (p-1)/2 are primes. 2551 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that 2552 if the generator g has only small prime factors, and if g divides 2553 the order of the group it generates, then signatures can be forged. 2554 In particular, choosing g=2 is a bad choice if the group order may 2555 be even. On the other hand, a generator of 2 is a fine choice for an 2556 encryption-only key, as this will make the encryption faster. 2558 While verifying Elgamal signatures, note that it is important to 2559 test that r and s are less than p. If this test is not done then 2560 signatures can be trivially forged by using large r values of 2561 approximately twice the length of p. This attack is also discussed 2562 in the Bleichenbacher paper. 2564 Details on safe use of Elgamal signatures may be found in [MENEZES], 2565 which discusses all the weaknesses described above. 2567 If an implementation allows Elgamal signatures, then it MUST use the 2568 algorithm identifier 20. 2570 An implementation SHOULD NOT implement Elgamal keys of size less 2571 than 768 bits. For long-term security, Elgamal keys should be 1024 2572 bits or longer. 2574 12.6. DSA 2576 An implementation SHOULD NOT implement DSA keys of size less than 2577 768 bits. Note that present DSA is limited to a maximum of 1024 bit 2578 keys, which are recommended for long-term use. 2580 12.7. OpenPGP CFB mode 2582 OpenPGP does symmetric encryption using a variant of Cipher Feedback 2583 Mode (CFB mode). This section describes the procedure it uses in 2584 detail. This mode is what is used for Symmetrically Ecrypted Data 2585 Packets; the mechanism used for encrypting secret key material is 2586 similar, but described in those sections above. 2588 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 2589 and prefixes the plaintext with ten bytes of random data, such that 2590 bytes 9 and 10 match bytes 7 and 8. It does a CFB "resync" after 2591 encrypting those ten bytes. 2593 Note that for an algorithm that has a larger block size than 64 2594 bits, the equivalent function will be done with that entire block. 2596 Step by step, here is the procedure: 2598 1. The feedback register (FR) is set to the IV, which is all zeros. 2600 2. FR is encrypted to produce FRE (FR Encrypted). This is the 2601 encryption of an all-zero value. 2603 3. FRE is xored with the first 8 bytes of random data prefixed to 2604 the plaintext to produce C1-C8, the first 8 bytes of ciphertext. 2606 4. FR is loaded with C1-C8. 2608 5. FR is encrypted to produce FRE, the encryption of the first 8 2609 bytes of ciphertext. 2611 6. The left two bytes of FRE get xored with the next two bytes of 2612 data which were prepended to the plaintext. This produces 2613 C9-C10, the next two bytes of ciphertext. 2615 7. (The resync step) FR is loaded with C3-C10. 2617 8. FR is encrypted to produce FRE. 2619 9. FRE is xored with the first 8 bytes of the given plaintext, now 2620 that we have finished encrypting the 10 bytes of prepended data. 2621 This produces C11-C18, the next 8 bytes of ciphertext. 2623 10. FR is loaded with C11-C18 2625 11. FR is encrypted to produce FRE. 2627 12. FRE is xored with the next 8 bytes of plaintext, to produce the 2628 next 8 bytes of ciphertext. These are loaded into FR and the 2629 process is repeated until the plaintext is used up. 2631 13. Security Considerations 2633 As with any technology involving cryptography, you should check the 2634 current literature to determine if any algorithms used here have 2635 been found to be vulnerable to attack. 2637 This specification uses Public Key Cryptography technologies. 2638 Possession of the private key portion of a public-private key pair 2639 is assumed to be controlled by the proper party or parties. 2641 Certain operations in this specification involve the use of random 2642 numbers. An appropriate entropy source should be used to generate 2643 these numbers. See RFC 1750. 2645 The MD5 hash algorithm has been found to have weaknesses 2646 (pseudo-collisions in the compress function) that make some people 2647 deprecate its use. They consider the SHA-1 algorithm better. 2649 The DSA algorithm will work with any 160-bit hash, but it is 2650 sensitive to the quality of the hash algorithm, if the hash 2651 algorithm is broken, it can leak the secret key. The Digital 2652 Signature Standard (DSS) specifies that DSA be used with SHA-1. 2653 RIPEMD-160 is considered by many cryptographers to be as strong. An 2654 implementation should take care which hash algorithms are used with 2655 DSA, as a weak hash can not only allow a signature to be forged, but 2656 could leak the secret key. 2658 If you are building an authentication system, the recipient may 2659 specify a preferred signing algorithm. However, the signer would be 2660 foolish to use a weak algorithm simply because the recipient 2661 requests it. 2663 Some of the encryption algorithms mentioned in this document have 2664 been analyzed less than others. For example, although CAST5 is 2665 presently considered strong, it has been analyzed less than 2666 Triple-DES. Other algorithms may have other controversies 2667 surrounding them. 2669 Some technologies mentioned here may be subject to government 2670 control in some countries. 2672 14. Implementation Nits 2674 This section is a collection of comments to help an implementor, 2675 particularly with an eye to backwards compatibility. Previous 2676 implementations of PGP are not OpenPGP-compliant. Often the 2677 differences are small, but small differences are frequently more 2678 vexing than large differences. Thus, this list of potential problems 2679 and gotchas for a developer who is trying to be 2680 backwards-compatible. 2682 * PGP 5.x does not accept V4 signatures for anything other than 2683 key material. 2685 * PGP 5.x does not recognize the "five-octet" lengths in 2686 new-format headers or in signature subpacket lengths. 2688 * PGP 5.0 rejects an encrypted session key if the keylength 2689 differs from the the S2K symmetric algorithm. This is a bug in 2690 its validation function. 2692 * PGP 5.0 does not handle multiple one-pass signature headers and 2693 trailers. Signing one will compress the one-pass signed literal 2694 and prefix a V3 signature instead of doing a nested one-pass 2695 signature. 2697 * When exporting a private key, PGP 2.x generates the header 2698 "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY 2699 BLOCK". All previous versions ignore the implied data type, and 2700 look directly at the packet data type. 2702 * In a clear-signed signature, PGP 5.0 will figure out the correct 2703 hash algorithm if there is no "Hash:" header, but it will reject 2704 a mismatch between the header and the actual agorithm used. The 2705 "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x 2706 rejects the "Hash:" header and assumes MD5. There are a number 2707 of enhanced variants of PGP 2.6.x that have been modified for 2708 SHA-1 signatures. 2710 * PGP 5.0 can read an RSA key in V4 format, but will only 2711 recognize it using V3 format. 2713 * There are many ways possible for for two keys to have the same 2714 key material, but different fingerprints (and thus key ids). 2715 Perhaps the most interesting is an RSA key that has been 2716 "upgraded" to V4 format, but since a V4 fingerprint is 2717 constructed by hashing the key creation time along with other 2718 things, two V4 keys created at different times, yet with the 2719 same key material will have different fingerprints. 2721 * PGP 2.6.x and PGP 5.0 sometimes add to the beginning of a file a 2722 zero-length compressed data packet. 2724 * If an implemtation is using zlib to interoperate with PGP 2.x, 2725 then the "windowBits" parameter should be set to -13. 2727 15. Authors and Working Group Chair 2729 The working group can be contacted via the current chair: 2731 John W. Noerenberg, II 2732 Qualcomm, Inc 2733 6455 Lusk Blvd 2734 San Diego, CA 92131 USA 2735 Email: jwn2@qualcomm.com 2736 Tel: +1 619-658-3510 2738 The principal authors of this draft are: 2740 Jon Callas 2741 Network Associates, Inc. 2742 4200 Bohannon Drive 2743 Menlo Park, CA 94025, USA 2744 Email: jon@pgp.com 2745 Tel: +1-650-473-2860 2747 Lutz Donnerhacke 2748 IKS GmbH 2749 Wildenbruchstr. 15 2750 07745 Jena, Germany 2751 EMail: lutz@iks-jena.de 2752 Tel: +49-3641-675642 2754 Hal Finney 2755 Network Associates, Inc. 2756 4200 Bohannon Drive 2757 Menlo Park, CA 94025, USA 2758 Email: hal@pgp.com 2760 Rodney Thayer 2761 Sable Technology Corporation 2762 246 Walnut Street 2763 Newton, MA 02160 USA 2764 Email: rodney@sabletech.com 2765 Tel: +1-617-332-7292 2767 This draft also draws on much previous work from a number of other 2768 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 2769 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph 2770 Levine, Colin Plumb, Will Price, William Stallings, Mark Weaver, and 2771 Philip R. Zimmermann. 2773 16. References 2775 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal 2776 signatures without knowing the secret key," Eurocrypt 96. Note that 2777 the version in the proceedings has an error. A revised version is 2778 available at the time of writing from 2779 2781 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved 2782 international version of PGP", 2783 ftp://ftp.iks-jena.de/mitarb/lutz/crypt/software/pgp/ 2785 [ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a Signature 2786 Scheme Based on Discrete Logarithms," IEEE Transactions on 2787 Information Theory, v. IT-31, n. 4, 1985, pp. 469-472. 2789 [ISO-10646] ISO/IEC 10646-1:1993. International Standard -- 2790 Information technology -- Universal Multiple-Octet Coded Character 2791 Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane. 2792 UTF-8 is described in Annex R, adopted but not yet published. 2793 UTF-16 is described in Annex Q, adopted but not yet published. 2795 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott Vanstone, 2796 "Handbook of Applied Cryptography," CRC Press, 1996. 2798 [PKCS1] RSA Laboratories, "PKCS #1: RSA Encryption Standard," 2799 version 1.5, November 1993 2801 [RFC822] D. Crocker, "Standard for the format of ARPA Internet text 2802 messages", RFC 822, August 1982 2804 [RFC1423] D. Balenson, "Privacy Enhancement for Internet Electronic 2805 Mail: Part III: Algorithms, Modes, and Identifiers", RFC 1423, 2806 October 1993 2808 [RFC1641] Goldsmith, D., and M. Davis, "Using Unicode with MIME", 2809 RFC 1641, Taligent inc., July 1994. 2811 [RFC1750] Eastlake, Crocker, & Schiller., Randomness Recommendations 2812 for Security. December 1994. 2814 [RFC1951] Deutsch, P., DEFLATE Compressed Data Format Specification 2815 version 1.3. May 1996. 2817 [RFC1983] G. Malkin., Internet Users' Glossary. August 1996. 2819 [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP Message 2820 Exchange Formats", RFC 1991, August 1996. 2822 [RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy 2823 (PGP)", RFC 2015, October 1996. 2825 [RFC2044] F. Yergeau., UTF-8, a transformation format of Unicode and 2826 ISO 10646. October 1996. 2828 [RFC2045] Borenstein, N., and Freed, N., "Multipurpose Internet Mail 2829 Extensions (MIME) Part One: Format of Internet Message Bodies.", 2830 November 1996 2832 [RFC2119] Bradner, S., Key words for use in RFCs to Indicate 2833 Requirement Level. March 1997. 2835 17. Full Copyright Statement 2837 Copyright 1998 by The Internet Society. All Rights Reserved. 2839 This document and translations of it may be copied and furnished to 2840 others, and derivative works that comment on or otherwise explain it 2841 or assist in its implementation may be prepared, copied, published 2842 and distributed, in whole or in part, without restriction of any 2843 kind, provided that the above copyright notice and this paragraph 2844 are included on all such copies and derivative works. However, this 2845 document itself may not be modified in any way, such as by removing 2846 the copyright notice or references to the Internet Society or other 2847 Internet organizations, except as needed for the purpose of 2848 developing Internet standards in which case the procedures for 2849 copyrights defined in the Internet Standards process must be 2850 followed, or as required to translate it into languages other than 2851 English. 2853 The limited permissions granted above are perpetual and will not be 2854 revoked by the Internet Society or its successors or assigns.