idnits 2.17.1 draft-ietf-openpgp-formats-04.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 recipient'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 314 -- Looks like a reference, but probably isn't: '1' on line 314 -- Looks like a reference, but probably isn't: '2' on line 314 -- Looks like a reference, but probably isn't: '3' on line 315 == Missing Reference: 'ISO10646' is mentioned on line 355, but not defined == Missing Reference: 'Optional' is mentioned on line 1669, but not defined == Missing Reference: 'Binding-Signature-Revocation' is mentioned on line 2388, but not defined == Unused Reference: 'DONNERHACKE' is defined on line 2810, but no explicit reference was found in the text == Unused Reference: 'ISO-10646' is defined on line 2818, but no explicit reference was found in the text == Unused Reference: 'RFC822' is defined on line 2830, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 2833, but no explicit reference was found in the text == Unused Reference: 'RFC1641' is defined on line 2837, but no explicit reference was found in the text == Unused Reference: 'RFC1750' is defined on line 2840, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 2843, but no explicit reference was found in the text == Unused Reference: 'RFC1983' is defined on line 2846, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 2848, but no explicit reference was found in the text == Unused Reference: 'RFC2015' is defined on line 2851, but no explicit reference was found in the text == Unused Reference: 'RFC2045' is defined on line 2857, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 2861, 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 (~~), 19 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-04.txt 4 Expires Dec 1998 Lutz Donnerhacke 5 June 1998 IN-Root-CA Individual Network e.V. 7 Hal Finney 8 Network Associates 10 Rodney Thayer 11 EIS Corporation 13 OpenPGP Message Format 14 draft-ietf-openpgp-formats-04.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 24 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 26 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.3.22.Reason for Revocation 27 119 5.2.4. Computing Signatures 28 120 5.2.4.1. Subpacket Hints 29 121 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 29 122 5.4. One-Pass Signature Packets (Tag 4) 30 123 5.5. Key Material Packet 31 124 5.5.1. Key Packet Variants 31 125 5.5.1.1. Public Key Packet (Tag 6) 31 126 5.5.1.2. Public Subkey Packet (Tag 14) 31 127 5.5.1.3. Secret Key Packet (Tag 5) 31 128 5.5.1.4. Secret Subkey Packet (Tag 7) 31 129 5.5.2. Public Key Packet Formats 31 130 5.5.3. Secret Key Packet Formats 33 131 5.6. Compressed Data Packet (Tag 8) 35 132 5.7. Symmetrically Encrypted Data Packet (Tag 9) 35 133 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 36 134 5.9. Literal Data Packet (Tag 11) 36 135 5.10. Trust Packet (Tag 12) 37 136 5.11. User ID Packet (Tag 13) 37 137 6. Radix-64 Conversions 37 138 6.1. An Implementation of the CRC-24 in "C" 38 139 6.2. Forming ASCII Armor 38 140 6.3. Encoding Binary in Radix-64 40 141 6.4. Decoding Radix-64 41 142 6.5. Examples of Radix-64 42 143 6.6. Example of an ASCII Armored Message 42 144 7. Cleartext signature framework 42 145 7.1. Dash-Escaped Text 43 146 8. Regular Expressions 43 147 9. Constants 44 148 9.1. Public Key Algorithms 44 149 9.2. Symmetric Key Algorithms 45 150 9.3. Compression Algorithms 45 151 9.4. Hash Algorithms 45 152 10. Packet Composition 45 153 10.1. Transferable Public Keys 46 154 10.2. OpenPGP Messages 47 155 11. Enhanced Key Formats 47 156 11.1. Key Structures 47 157 11.2. Key IDs and Fingerprints 48 158 12. Notes on Algorithms 49 159 12.1. Symmetric Algorithm Preferences 49 160 12.2. Other Algorithm Preferences 50 161 12.2.1. Compression Preferences 50 162 12.2.2. Hash Algorithm Preferences 51 163 12.3. Plaintext 51 164 12.4. RSA 51 165 12.5. Elgamal 51 166 12.6. DSA 52 167 12.7. OpenPGP CFB mode 52 168 13. Security Considerations 53 169 14. Implementation Nits 54 170 15. Authors and Working Group Chair 55 171 16. References 56 172 17. Full Copyright Statement 57 174 1. Introduction 176 This document provides information on the message-exchange packet 177 formats used by OpenPGP to provide encryption, decryption, signing, 178 and key management functions. It builds on the foundation provided 179 in RFC 1991 "PGP Message Exchange Formats." 181 1.1. Terms 183 * OpenPGP - This is a definition for security software that uses 184 PGP 5.x as a basis. 186 * PGP - Pretty Good Privacy. PGP is a family of software systems 187 developed by Philip R. Zimmermann from which OpenPGP is based. 189 * PGP 2.6.x - This version of PGP has many variants, hence the 190 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 191 cryptographic transforms. 193 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 194 the community and also in the predecessor of this document, 195 RFC1991. It has new formats and corrects a number of problems in 196 the PGP 2.6.x design. It is referred to here as PGP 5.x because 197 that software was the first release of the "PGP 3" code base. 199 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 200 Network Associates, Inc. 202 2. General functions 204 OpenPGP provides data integrity services for messages and data files 205 by using these core technologies: 207 - digital signatures 209 - encryption 211 - compression 213 - radix-64 conversion 215 In addition, OpenPGP provides key management and certificate 216 services, but many of these are beyond the scope of this document. 218 2.1. Confidentiality via Encryption 220 OpenPGP uses two encryption methods to provide confidentiality: 221 symmetric-key encryption and public key encryption. With public-key 222 encryption, the object is encrypted using a symmetric encryption 223 algorithm. Each symmetric key is used only once. A new "session 224 key" is generated as a random number for each message. Since it is 225 used only once, the session key is bound to the message and 226 transmitted with it. To protect the key, it is encrypted with the 227 receiver's public key. The sequence is as follows: 229 1. The sender creates a message. 231 2. The sending OpenPGP generates a random number to be used as a 232 session key for this message only. 234 3. The session key is encrypted using each recipient's public key. 235 These "encrypted session keys" start the message. 237 4. The sending OpenPGP encrypts the message using the session key, 238 which forms the remainder of the message. Note that the message 239 is also usually compressed. 241 5. The receiving OpenPGP decrypts the session key using the 242 recipient's private key. 244 6. The receiving OpenPGP decrypts the message using the session 245 key. If the message was compressed, it will be decompressed. 247 With symmetric-key encryption, an object may encrypted with a 248 symmetric key derived from a passphrase (or other shared secret), or 249 a two-stage mechanism similar to the public-key method described 250 above in which a session key is itself encrypted with a symmetric 251 algorithm keyed from a shared secret. 253 Both digital signature and confidentiality services may be applied 254 to the same message. First, a signature is generated for the message 255 and attached to the message. Then, the message plus signature is 256 encrypted using a symmetric session key. Finally, the session key is 257 encrypted using public-key encryption and prefixed to the encrypted 258 block. 260 2.2. Authentication via Digital signature 262 The digital signature uses a hash code or message digest algorithm, 263 and a public-key signature algorithm. The sequence is as follows: 265 1. The sender creates a message. 267 2. The sending software generates a hash code of the message. 269 3. The sending software generates a signature from the hash code 270 using the sender's private key. 272 4. The binary signature is attached to the message. 274 5. The receiving software keeps a copy of the message signature. 276 6. The receiving software generates a new hash code for the 277 received message and verifies it using the message's signature. 278 If the verification is successful, the message is accepted as 279 authentic. 281 2.3. Compression 283 OpenPGP implementations MAY compress the message after applying the 284 signature but before encryption. 286 2.4. Conversion to Radix-64 288 OpenPGP's underlying native representation for encrypted messages, 289 signature certificates, and keys is a stream of arbitrary octets. 290 Some systems only permit the use of blocks consisting of seven-bit, 291 printable text. For transporting OpenPGP's native raw binary octets 292 through channels that are not safe to raw binary data, a printable 293 encoding of these binary octets is needed. OpenPGP provides the 294 service of converting the raw 8-bit binary octet stream to a stream 295 of printable ASCII characters, called Radix-64 encoding or ASCII 296 Armor. 298 Implementations SHOULD provide Radix-64 conversions. 300 Note that many applications, particularly messaging applications, 301 will want more advanced features as described in the OpenPGP-MIME 302 document, RFC2015. An application that implements OpenPGP for 303 messaging SHOULD implement OpenPGP-MIME. 305 3. Data Element Formats 307 This section describes the data elements used by OpenPGP. 309 3.1. Scalar numbers 311 Scalar numbers are unsigned, and are always stored in big-endian 312 format. Using n[k] to refer to the kth octet being interpreted, the 313 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 314 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 315 n[3]). 317 3.2. Multi-Precision Integers 319 Multi-Precision Integers (also called MPIs) are unsigned integers 320 used to hold large integers such as the ones used in cryptographic 321 calculations. 323 An MPI consists of two pieces: a two-octet scalar that is the length 324 of the MPI in bits followed by a string of octets that contain the 325 actual integer. 327 These octets form a big-endian number; a big-endian number can be 328 made into an MPI by prefixing it with the appropriate length. 330 Examples: 332 (all numbers are in hexadecimal) 334 The string of octets [00 01 01] forms an MPI with the value 1. The 335 string [00 09 01 FF] forms an MPI with the value of 511. 337 Additional rules: 339 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 341 The length field of an MPI describes the length starting from its 342 most significant non-zero bit. Thus, the MPI [00 02 01] is not 343 formed correctly. It should be [00 01 01]. 345 3.3. Key IDs 347 A Key ID is an eight-octet scalar that identifies a key. 348 Implementations SHOULD NOT assume that Key IDs are unique. The 349 section, "Enhanced Key Formats" below describes how Key IDs are 350 formed. 352 3.4. Text 354 The default character set for text is the UTF-8 [RFC2044] encoding 355 of Unicode [ISO10646]. 357 3.5. Time fields 359 A time field is an unsigned four-octet number containing the number 360 of seconds elapsed since midnight, 1 January 1970 UTC. 362 3.6. String-to-key (S2K) specifiers 364 String-to-key (S2K) specifiers are used to convert passphrase 365 strings into symmetric-key encryption/decryption keys. They are 366 used in two places, currently: to encrypt the secret part of private 367 keys in the private keyring, and to convert passphrases to 368 encryption keys for symmetrically encrypted messages. 370 3.6.1. String-to-key (S2k) specifier types 372 There are three types of S2K specifiers currently supported, as 373 follows: 375 3.6.1.1. Simple S2K 377 This directly hashes the string to produce the key data. See below 378 for how this hashing is done. 380 Octet 0: 0x00 381 Octet 1: hash algorithm 383 Simple S2K hashes the passphrase to produce the session key. The 384 manner in which this is done depends on the size of the session key 385 (which will depend on the cipher used) and the size of the hash 386 algorithm's output. If the hash size is greater than or equal to the 387 session key size, the high-order (leftmost) octets of the hash are 388 used as the key. 390 If the hash size is less than the key size, multiple instances of 391 the hash context are created -- enough to produce the required key 392 data. These instances are preloaded with 0, 1, 2, ... octets of 393 zeros (that is to say, the first instance has no preloading, the 394 second gets preloaded with 1 octet of zero, the third is preloaded 395 with two octets of zeros, and so forth). 397 As the data is hashed, it is given independently to each hash 398 context. Since the contexts have been initialized differently, they 399 will each produce different hash output. Once the passphrase is 400 hashed, the output data from the multiple hashes is concatenated, 401 first hash leftmost, to produce the key data, with any excess octets 402 on the right discarded. 404 3.6.1.2. Salted S2K 406 This includes a "salt" value in the S2K specifier -- some arbitrary 407 data -- that gets hashed along with the passphrase string, to help 408 prevent dictionary attacks. 410 Octet 0: 0x01 411 Octet 1: hash algorithm 412 Octets 2-9: 8-octet salt value 414 Salted S2K is exactly like Simple S2K, except that the input to the 415 hash function(s) consists of the 8 octets of salt from the S2K 416 specifier, followed by the passphrase. 418 3.6.1.3. Iterated and Salted S2K 420 This includes both a salt and an octet count. The salt is combined 421 with the passphrase and the resulting value is hashed repeatedly. 422 This further increases the amount of work an attacker must do to try 423 dictionary attacks. 425 Octet 0: 0x03 426 Octet 1: hash algorithm 427 Octets 2-9: 8-octet salt value 428 Octet 10: count, a one-octet, coded value 430 The count is coded into a one-octet number using the following 431 formula: 433 #define EXPBIAS 6 434 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 436 The above formula is in C, where "Int32" is a type for a 32-bit 437 integer, and the variable "c" is the coded count, Octet 10. 439 Iterated-Salted S2K hashes the passphrase and salt data multiple 440 times. The total number of octets to be hashed is specified in the 441 encoded count in the S2K specifier. Note that the resulting count 442 value is an octet count of how many octets will be hashed, not an 443 iteration count. 445 Initially, one or more hash contexts are set up as with the other 446 S2K algorithms, depending on how many octets of key data are needed. 447 Then the salt, followed by the passphrase data is repeatedly hashed 448 until the number of octets specified by the octet count has been 449 hashed. The one exception is that if the octet count is less than 450 the size of the salt plus passphrase, the full salt plus passphrase 451 will be hashed even though that is greater than the octet count. 452 After the hashing is done the data is unloaded from the hash 453 context(s) as with the other S2K algorithms. 455 3.6.2. String-to-key usage 457 Implementations SHOULD use salted or iterated-and-salted S2K 458 specifiers, as simple S2K specifiers are more vulnerable to 459 dictionary attacks. 461 3.6.2.1. Secret key encryption 463 An S2K specifier can be stored in the secret keyring to specify how 464 to convert the passphrase to a key that unlocks the secret data. 465 Older versions of PGP just stored a cipher algorithm octet preceding 466 the secret data or a zero to indicate that the secret data was 467 unencrypted. The MD5 hash function was always used to convert the 468 passphrase to a key for the specified cipher algorithm. 470 For compatibility, when an S2K specifier is used, the special value 471 255 is stored in the position where the hash algorithm octet would 472 have been in the old data structure. This is then followed 473 immediately by a one-octet algorithm identifier, and then by the S2K 474 specifier as encoded above. 476 Therefore, preceding the secret data there will be one of these 477 possibilities: 479 0: secret data is unencrypted (no pass phrase) 480 255: followed by algorithm octet and S2K specifier 481 Cipher alg: use Simple S2K algorithm using MD5 hash 483 This last possibility, the cipher algorithm number with an implicit 484 use of MD5 and IDEA, is provided for backward compatibility; it MAY 485 be understood, but SHOULD NOT be generated, and is deprecated. 487 These are followed by an 8-octet Initial Vector for the decryption 488 of the secret values, if they are encrypted, and then the secret key 489 values themselves. 491 3.6.2.2. Symmetric-key message encryption 493 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 494 packet at the front of a message. This is used to allow S2K 495 specifiers to be used for the passphrase conversion or to create 496 messages with a mix of symmetric-key ESKs and public-key ESKs. This 497 allows a message to be decrypted either with a passphrase or a 498 public key. 500 PGP 2.X always used IDEA with Simple string-to-key conversion when 501 encrypting a message with a symmetric algorithm. This is deprecated, 502 but MAY be used for backward-compatibility. 504 4. Packet Syntax 506 This section describes the packets used by OpenPGP. 508 4.1. Overview 510 An OpenPGP message is constructed from a number of records that are 511 traditionally called packets. A packet is a chunk of data that has a 512 tag specifying its meaning. An OpenPGP message, keyring, 513 certificate, and so forth consists of a number of packets. Some of 514 those packets may contain other OpenPGP packets (for example, a 515 compressed data packet, when uncompressed, contains OpenPGP 516 packets). 518 Each packet consists of a packet header, followed by the packet 519 body. The packet header is of variable length. 521 4.2. Packet Headers 523 The first octet of the packet header is called the "Packet Tag." It 524 determines the format of the header and denotes the packet contents. 525 The remainder of the packet header is the length of the packet. 527 Note that the most significant bit is the left-most bit, called bit 528 7. A mask for this bit is 0x80 in hexadecimal. 530 +---------------+ 531 PTag |7 6 5 4 3 2 1 0| 532 +---------------+ 533 Bit 7 -- Always one 534 Bit 6 -- New packet format if set 536 PGP 2.6.x only uses old format packets. Thus, software that 537 interoperates with those versions of PGP must only use old format 538 packets. If interoperability is not an issue, either format may be 539 used. Note that old format packets have four bits of content tags, 540 and new format packets have six; some features cannot be used and 541 still be backward-compatible. 543 Old format packets contain: 545 Bits 5-2 -- content tag 546 Bits 1-0 - length-type 548 New format packets contain: 550 Bits 5-0 -- content tag 552 4.2.1. Old-Format Packet Lengths 554 The meaning of the length-type in old-format packets is: 556 0 - The packet has a one-octet length. The header is 2 octets long. 558 1 - The packet has a two-octet length. The header is 3 octets long. 560 2 - The packet has a four-octet length. The header is 5 octets long. 562 3 - The packet is of indeterminate length. The header is 1 octet 563 long, and the implementation must determine how long the packet 564 is. If the packet is in a file, this means that the packet 565 extends until the end of the file. In general, an implementation 566 SHOULD NOT use indeterminate length packets except where the end 567 of the data will be clear from the context, and even then it is 568 better to use a definite length, or a new-format header. The 569 new-format headers described below have a mechanism for 570 precisely encoding data of indeterminate 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 = 1st_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) << 8) + (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 << (1st_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 implementation MUST make new PKCS-1 padding for each key. 741 An implementation MAY accept or use a Key ID of zero as a "wild 742 card" or "speculative" Key ID. In this case, the receiving 743 implementation would try all available private keys, checking for a 744 valid decrypted session key. This format helps reduce traffic 745 analysis of messages. 747 5.2. Signature Packet (Tag 2) 749 A signature packet describes a binding between some public key and 750 some data. The most common signatures are a signature of a file or a 751 block of text, and a signature that is a certification of a user ID. 753 Two versions of signature packets are defined. Version 3 provides 754 basic signature information, while version 4 provides an expandable 755 format with subpackets that can specify more information about the 756 signature. PGP 2.6.x only accepts version 3 signatures. 758 Implementations MUST accept V3 signatures. Implementations SHOULD 759 generate V4 signatures. Implementations MAY generate a V3 signature 760 that can be verified by PGP 2.6.x. 762 Note that if an implementation is creating an encrypted and signed 763 message that is encrypted to a V3 key, it is reasonable to create a 764 V3 signature. 766 5.2.1. Signature Types 768 There are a number of possible meanings for a signature, which are 769 specified in a signature type octet in any given signature. These 770 meanings are: 772 0x00: Signature of a binary document. 773 Typically, this means the signer owns it, created it, or 774 certifies that it has not been modified. 776 0x01: Signature of a canonical text document. 777 Typically, this means the signer owns it, created it, or 778 certifies that it has not been modified. The signature is 779 calculated over the text data with its line endings converted to 780 and trailing blanks removed. 782 0x02: Standalone signature. 783 This signature is a signature of only its own subpacket 784 contents. It is calculated identically to a signature over a 785 zero-length binary document. Note that it doesn't make sense to 786 have a V3 standalone signature. 788 0x10: Generic certification of a User ID and Public Key packet. 789 The issuer of this certification does not make any particular 790 assertion as to how well the certifier has checked that the 791 owner of the key is in fact the person described by the user ID. 792 Note that all PGP "key signatures" are this type of 793 certification. 795 0x11: Persona certification of a User ID and Public Key packet. 796 The issuer of this certification has not done any verification 797 of the claim that the owner of this key is the user ID 798 specified. 800 0x12: Casual certification of a User ID and Public Key packet. 801 The issuer of this certification has done some casual 802 verification of the claim of identity. 804 0x13: Positive certification of a User ID and Public Key packet. 805 The issuer of this certification has done substantial 806 verification of the claim of identity. 808 Please note that the vagueness of these certification claims is 809 not a flaw, but a feature of the system. Because PGP places 810 final authority for validity upon the receiver of a 811 certification, it may be that one authority's casual 812 certification might be more rigorous than some other authority's 813 positive certification. These classifications allow a 814 certification authority to issue fine-grained claims. 816 0x18: Subkey Binding Signature 817 This signature is a statement by the top-level signing key 818 indicates that it owns the subkey. This signature is calculated 819 directly on the subkey itself, not on any User ID or other 820 packets. 822 0x1F: Signature directly on a key 823 This signature is calculated directly on a key. It binds the 824 information in the signature subpackets to the key, and is 825 appropriate to be used for subpackets that provide information 826 about the key, such as the revocation key subpacket. It is also 827 appropriate for statements that non-self certifiers want to make 828 about the key itself, rather than the binding between a key and 829 a name. 831 0x20: Key revocation signature 832 The signature is calculated directly on the key being revoked. 833 A revoked key is not to be used. Only revocation signatures by 834 the key being revoked, or by an authorized revocation key, 835 should be considered valid revocation signatures. 837 0x28: Subkey revocation signature 838 The signature is calculated directly on the subkey being 839 revoked. A revoked subkey is not to be used. Only revocation 840 signatures by the top-level signature key that is bound to this 841 subkey, or by an authorized revocation key, should be considered 842 valid revocation signatures. 844 0x30: Certification revocation signature 845 This signature revokes an earlier user ID certification 846 signature (signature class 0x10 through 0x13). It should be 847 issued by the same key that issued the revoked signature or an 848 authorized revocation key The signature should have a later 849 creation date than the signature it revokes. 851 0x40: Timestamp signature. 852 This signature is only meaningful for the timestamp contained in 853 it. 855 5.2.2. Version 3 Signature Packet Format 857 The body of a version 3 Signature Packet contains: 859 - One-octet version number (3). 861 - One-octet length of following hashed material. MUST be 5. 863 - One-octet signature type. 865 - Four-octet creation time. 867 - Eight-octet key ID of signer. 869 - One-octet public key algorithm. 871 - One-octet hash algorithm. 873 - Two-octet field holding left 16 bits of signed hash value. 875 - One or more multi-precision integers comprising the signature. 876 This portion is algorithm specific, as described below. 878 The data being signed is hashed, and then the signature type and 879 creation time from the signature packet are hashed (5 additional 880 octets). The resulting hash value is used in the signature 881 algorithm. The high 16 bits (first two octets) of the hash are 882 included in the signature packet to provide a quick test to reject 883 some invalid signatures. 885 Algorithm Specific Fields for RSA signatures: 887 - multiprecision integer (MPI) of RSA signature value m**d. 889 Algorithm Specific Fields for DSA signatures: 891 - MPI of DSA value r. 893 - MPI of DSA value s. 895 The signature calculation is based on a hash of the signed data, as 896 described above. The details of the calculation are different for 897 DSA signature than for RSA signatures. 899 With RSA signatures, the hash value is encoded as described in 900 PKCS-1 section 10.1.2, "Data encoding", producing an ASN.1 value of 901 type DigestInfo, and then padded using PKCS-1 block type 01 [PKCS1]. 902 This requires inserting the hash value as an octet string into an 903 ASN.1 structure. The object identifier for the type of hash being 904 used is included in the structure. The hexadecimal representations 905 for the currently defined hash algorithms are: 907 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02 909 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 911 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 913 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 915 The ASN.1 OIDs are: 917 - MD2: 1.2.840.113549.2.2 919 - MD5: 1.2.840.113549.2.5 921 - RIPEMD-160: 1.3.36.3.2.1 923 - SHA-1: 1.3.14.3.2.26 925 The full hash prefixes for these are: 927 MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 928 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 929 0x04, 0x10 931 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 932 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 933 0x04, 0x10 935 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 936 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 938 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 939 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 941 DSA signatures SHOULD use hashes with a size of 160 bits, to match 942 q, the size of the group generated by the DSA key's generator value. 943 The hash function result is treated as a 160 bit number and used 944 directly in the DSA signature algorithm. 946 5.2.3. Version 4 Signature Packet Format 948 The body of a version 4 Signature Packet contains: 950 - One-octet version number (4). 952 - One-octet signature type. 954 - One-octet public key algorithm. 956 - One-octet hash algorithm. 958 - Two-octet scalar octet count for following hashed subpacket 959 data. 961 - Hashed subpacket data. (zero or more subpackets) 963 - Two-octet scalar octet count for following unhashed subpacket 964 data. 966 - Unhashed subpacket data. (zero or more subpackets) 968 - Two-octet field holding left 16 bits of signed hash value. 970 - One or more multi-precision integers comprising the signature. 971 This portion is algorithm specific, as described above. 973 The data being signed is hashed, and then the signature data from 974 the version number through the hashed subpacket data (inclusive) is 975 hashed. The resulting hash value is what is signed. The left 16 976 bits of the hash are included in the signature packet to provide a 977 quick test to reject some invalid signatures. 979 There are two fields consisting of signature subpackets. The first 980 field is hashed with the rest of the signature data, while the 981 second is unhashed. The second set of subpackets is not 982 cryptographically protected by the signature and should include only 983 advisory information. 985 The algorithms for converting the hash function result to a 986 signature are described in a section below. 988 5.2.3.1. Signature Subpacket Specification 990 The subpacket fields consist of zero or more signature subpackets. 991 Each set of subpackets is preceded by a two-octet scalar count of 992 the length of the set of subpackets. 994 Each subpacket consists of a subpacket header and a body. The 995 header consists of: 997 - the subpacket length (1, 2, or 5 octets) 999 - the subpacket type (1 octet) 1001 and is followed by the subpacket specific data. 1003 The length includes the type octet but not this length. Its format 1004 is similar to the "new" format packet header lengths, but cannot 1005 have partial body lengths. That is: 1007 if the 1st octet < 192, then 1008 lengthOfLength = 1 1009 subpacketLen = 1st_octet 1011 if the 1st octet >= 192 and < 255, then 1012 lengthOfLength = 2 1013 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1015 if the 1st octet = 255, then 1016 lengthOfLength = 5 1017 subpacket length = [four-octet scalar starting at 2nd_octet] 1019 The value of the subpacket type octet may be: 1021 2 = signature creation time 1022 3 = signature expiration time 1023 4 = exportable 1024 5 = trust signature 1025 6 = regular expression 1026 7 = revocable 1027 9 = key expiration time 1028 10 = placeholder for backward compatibility 1029 11 = preferred symmetric algorithms 1030 12 = revocation key 1031 16 = issuer key ID 1032 20 = notation data 1033 21 = preferred hash algorithms 1034 22 = preferred compression algorithms 1035 23 = key server preferences 1036 24 = preferred key server 1037 25 = primary user id 1038 26 = policy URL 1039 27 = key flags 1040 28 = signer's user id 1041 29 = reason for revocation 1042 100 to 110 = internal or user-defined 1044 An implementation SHOULD ignore any subpacket of a type that it does 1045 not recognize. 1047 Bit 7 of the subpacket type is the "critical" bit. If set, it 1048 denotes that the subpacket is one that is critical for the evaluator 1049 of the signature to recognize. If a subpacket is encountered that 1050 is marked critical but is unknown to the evaluating software, the 1051 evaluator SHOULD consider the signature to be in error. 1053 An evaluator may "recognize" a subpacket, but not implement it. The 1054 purpose of the critical bit is to allow the signer to tell an 1055 evaluator that it would prefer a new, unknown feature to generate an 1056 error than be ignored. 1058 Implementations SHOULD implement "preferences". 1060 5.2.3.2. Signature Subpacket Types 1062 A number of subpackets are currently defined. Some subpackets apply 1063 to the signature itself and some are attributes of the key. 1064 Subpackets that are found on a self-signature are placed on a user 1065 id certification made by the key itself. Note that a key may have 1066 more than one user id, and thus may have more than one 1067 self-signature, and differing subpackets. 1069 A self-signature is a binding signature made by the key the 1070 signature refers to. There are three types of self-signatures, the 1071 certification signatures (types 0x10-0x13), the direct-key signature 1072 (type 0x1f), and the subkey binding signature (type 0x18). For 1073 certification self-signatures, each user ID may have a 1074 self-signature, and thus different subpackets in those 1075 self-signatures. For subkey binding signatures, each subkey in fact 1076 has a self-signature. Subpackets that appear in a certification 1077 self-signature apply to the username, and subpackets that appear in 1078 the subkey self-signature apply to the subkey. Lastly, subpackets on 1079 the direct key signature apply to the entire key. 1081 Implementing software should interpret a self-signature's preference 1082 subpackets as narrowly as possible. For example, suppose a key has 1083 two usernames, Alice and Bob. Suppose that Alice prefers the 1084 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If 1085 the software locates this key via Alice's name, then the preferred 1086 algorithm is CAST5, if software locates the key via Bob's name, then 1087 the preferred algorithm is IDEA. If the key is located by key id, 1088 then algorithm of the default user id of the key provides the 1089 default symmetric algorithm. 1091 A subpacket may be found either in the hashed or unhashed subpacket 1092 sections of a signature. If a subpacket is not hashed, then the 1093 information in it cannot be considered definitive because it is not 1094 part of the signature proper. 1096 5.2.3.3. Signature creation time 1098 (4 octet time field) 1099 The time the signature was made. 1101 MUST be present in the hashed area. 1103 5.2.3.4. Issuer 1105 (8 octet key ID) 1107 The OpenPGP key ID of the key issuing the signature. 1109 MUST be present in the hashed area. 1111 5.2.3.5. Key expiration time 1113 (4 octet time field) 1115 The validity period of the key. This is the number of seconds after 1116 the key creation time that the key expires. If this is not present 1117 or has a value of zero, the key never expires. This is found only on 1118 a self-signature. 1120 5.2.3.6. Preferred symmetric algorithms 1122 (sequence of one-octet values) 1124 Symmetric algorithm numbers that indicate which algorithms the key 1125 holder prefers to use. The subpacket body is an ordered list of 1126 octets with the most preferred listed first. It is assumed that only 1127 algorithms listed are supported by the recipient's software. 1128 Algorithm numbers in section 9. This is only found on a 1129 self-signature. 1131 5.2.3.7. Preferred hash algorithms 1133 (array of one-octet values) 1135 Message digest algorithm numbers that indicate which algorithms the 1136 key holder prefers to receive. Like the preferred symmetric 1137 algorithms, the list is ordered. Algorithm numbers are in section 6. 1138 This is only found on a self-signature. 1140 5.2.3.8. Preferred compression algorithms 1142 (array of one-octet values) 1144 Compression algorithm numbers that indicate which algorithms the key 1145 holder prefers to use. Like the preferred symmetric algorithms, the 1146 list is ordered. Algorithm numbers are in section 6. If this 1147 subpacket is not included, ZIP is preferred. A zero denotes that 1148 uncompressed data is preferred; the key holder's software may not 1149 have compression software. This is only found on a self-signature. 1151 5.2.3.9. Signature expiration time 1153 (4 octet time field) 1155 The validity period of the signature. This is the number of seconds 1156 after the signature creation time that the signature expires. If 1157 this is not present or has a value of zero, it never expires. 1159 5.2.3.10. Exportable 1161 (1 octet of exportability, 0 for not, 1 for exportable) 1163 Signature's exportability status. Packet body contains a boolean 1164 flag indicating whether the signature is exportable. Signatures that 1165 are not exportable are ignored during export and import operations. 1166 If this packet is not present the signature is assumed to be 1167 exportable. 1169 5.2.3.11. Revocable 1171 (1 octet of revocability, 0 for not, 1 for revocable) 1173 Signature's revocability status. Packet body contains a boolean 1174 flag indicating whether the signature is revocable. Signatures that 1175 are not revocable have any later revocation signatures ignored. 1176 They represent a commitment by the signer that he cannot revoke his 1177 signature for the life of his key. If this packet is not present, 1178 the signature is revocable. 1180 5.2.3.12. Trust signature 1182 (1 octet "level" (depth), 1 octet of trust amount) 1184 Signer asserts that the key is not only valid, but also trustworthy, 1185 at the specified level. Level 0 has the same meaning as an ordinary 1186 validity signature. Level 1 means that the signed key is asserted 1187 to be a valid trusted introducer, with the 2nd octet of the body 1188 specifying the degree of trust. Level 2 means that the signed key is 1189 asserted to be trusted to issue level 1 trust signatures, i.e. that 1190 it is a "meta introducer". Generally, a level n trust signature 1191 asserts that a key is trusted to issue level n-1 trust signatures. 1192 The trust amount is in a range from 0-255, interpreted such that 1193 values less than 120 indicate partial trust and values of 120 or 1194 greater indicate complete trust. Implementations SHOULD emit values 1195 of 60 for partial trust and 120 for complete trust. 1197 5.2.3.13. Regular expression 1199 (null-terminated regular expression) 1200 Used in conjunction with trust signature packets (of level > 0) to 1201 limit the scope of trust that is extended. Only signatures by the 1202 target key on user IDs that match the regular expression in the body 1203 of this packet have trust extended by the trust packet. The regular 1204 expression uses the same syntax as the Henry Spencer's "almost 1205 public domain" regular expression package. A description of the 1206 syntax is found in a section below. 1208 5.2.3.14. Revocation key 1210 (1 octet of class, 1 octet of algid, 20 octets of fingerprint) 1212 Authorizes the specified key to issue revocation signatures for this 1213 key. Class octet must have bit 0x80 set, other bits are for future 1214 expansion to other kinds of signature authorizations. This is found 1215 on a self-signature. 1217 Authorizes the specified key to issue revocation signatures for this 1218 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1219 then this means that the revocation information is sensitive. Other 1220 bits are for future expansion to other kinds of authorizations. This 1221 is found on a self-signature. 1223 If the "sensitive" flag is set, the keyholder feels this subpacket 1224 contains private trust information that describes a real-world 1225 sensitive relationship. If this flag is set, implementations SHOULD 1226 NOT export this signature to other users except in cases where the 1227 data needs to be available: when the signature is being sent to the 1228 designated revoker, or when it is accompanied by a revocation 1229 signature from that revoker. Note that it may be appropriate to 1230 isolate this subpacket within a separate signature so that it is not 1231 combined with other subpackets that need to be exported. 1233 5.2.3.15. Notation Data 1235 (4 octets of flags, 2 octets of name length (M), 1236 2 octets of value length (N), 1237 M octets of name data, 1238 N octets of value data) 1240 This subpacket describes a "notation" on the signature that the 1241 issuer wishes to make. The notation has a name and a value, each of 1242 which are strings of octets. There may be more than one notation in 1243 a signature. Notations can be used for any extension the issuer of 1244 the signature cares to make. The "flags" field holds four octets of 1245 flags. 1247 All undefined flags MUST be zero. Defined flags are: 1249 First octet: 0x80 = human-readable. This note is text, a note 1250 from one person to another, and has no 1251 meaning to software. 1253 Other octets: none. 1255 5.2.3.16. Key server preferences 1257 (N octets of flags) 1259 This is a list of flags that indicate preferences that the key 1260 holder has about how the key is handled on a key server. All 1261 undefined flags MUST be zero. 1263 First octet: 0x80 = No-modify 1264 the key holder requests that this key only be modified or 1265 updated by the key holder or an administrator of the key server. 1267 This is found only on a self-signature. 1269 5.2.3.17. Preferred key server 1271 (String) 1273 This is a URL of a key server that the key holder prefers be used 1274 for updates. Note that keys with multiple user ids can have a 1275 preferred key server for each user id. Note also that since this is 1276 a URL, the key server can actually be a copy of the key retrieved by 1277 ftp, http, finger, etc. 1279 5.2.3.18. Primary user id 1281 (1 octet, boolean) 1283 This is a flag in a user id's self signature that states whether 1284 this user id is the main user id for this key. It is reasonable for 1285 an implementation to resolve ambiguities in preferences, etc. by 1286 referring to the primary user id. If this flag is absent, its value 1287 is zero. If more than one user id in a key is marked as primary, the 1288 implementation may resolve the ambiguity in any way it sees fit. 1290 5.2.3.19. Policy URL 1292 (String) 1294 This subpacket contains a URL of a document that describes the 1295 policy that the signature was issued under. 1297 5.2.3.20. Key Flags 1299 (Octet string) 1301 This subpacket contains a list of binary flags that hold information 1302 about a key. It is a string of octets, and an implementation MUST 1303 NOT assume a fixed size. This is so it can grow over time. If a list 1304 is shorter than an implementation expects, the unstated flags are 1305 considered to be zero. The defined flags are: 1307 First octet: 1309 0x01 - This key may be used to certify other keys. 1311 0x02 - This key may be used to sign data. 1313 0x04 - This key may be used to encrypt communications. 1315 0x08 - This key may be used to encrypt storage. 1317 0x10 - The private component of this key may have been split by 1318 a secret-sharing mechanism. 1320 0x80 - The private component of this key may be in the 1321 possession of more than one person. 1323 Usage notes: 1325 The flags in this packet may appear in self-signatures or in 1326 certification signatures. They mean different things depending on 1327 who is making the statement -- for example, a certification 1328 signature that has the "sign data" flag is stating that the 1329 certification is for that use. On the other hand, the 1330 "communications encryption" flag in a self-signature is stating a 1331 preference that a given key be used for communications. Note 1332 however, that it is a thorny issue to determine what is 1333 "communications" and what is "storage." This decision is left wholly 1334 up to the implementation; the authors of this document do not claim 1335 any special wisdom on the issue, and realize that accepted opinion 1336 may change. 1338 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1339 self-signature only; they are meaningless on a certification 1340 signature. They SHOULD be placed only on a direct-key signature 1341 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1342 the key the flag applies to. 1344 5.2.3.21. Signer's User ID 1346 This subpacket allows a keyholder to state which user id is 1347 responsible for the signing. Many keyholders use a single key for 1348 different purposes, such as business communications as well as 1349 personal communications. This subpacket allows such a keyholder to 1350 state which of their roles is making a signature. 1352 5.2.3.22. Reason for Revocation 1354 (1 octet of revocation code, N octets of reason string) 1355 This subpacket is used only in key revocation and certification 1356 revocation signatures. It describes the reason why the key or 1357 certificate was revoked. 1359 The first octet contains a machine-readable code that denotes the 1360 reason for the revocation: 1362 0x00 - No reason specified (key revocations or cert revocations) 1363 0x01 - Key is superceded (key revocations) 1364 0x02 - Key material has been compromised (key revocations) 1365 0x03 - Key is no longer used (key revocations) 1366 0x20 - User id information is no longer valid (cert revocations) 1368 Following the recovation code is a string of octets which gives 1369 information about the reason for revocation in human-readable form 1370 (UTF-8). The string may be null, that is, of zero length. The length 1371 of the subpacket is the length of the reason string plus one. 1373 5.2.4. Computing Signatures 1375 All signatures are formed by producing a hash over the signature 1376 data, and then using the resulting hash in the signature algorithm. 1378 The signature data is simple to compute for document signatures 1379 (types 0x00 and 0x01), for which the document itself is the data. 1380 For standalone signatures, this is a null string. 1382 When a signature is made over a key, the hash data starts with the 1383 octet 0x99, followed by a two-octet length of the key, and then body 1384 of the key packet. (Note that this is an old-style packet header for 1385 a key packet with two-octet length.) A subkey signature (type 0x18) 1386 then hashes the subkey, using the same format as the main key. Key 1387 revocation signatures (types 0x20 and 0x28) hash only the key being 1388 revoked. 1390 A certification signature (type 0x10 through 0x13) hashes the user 1391 id being bound to the key into the hash context after the above 1392 data. A V3 certification hashes the contents of the name packet, 1393 without any header. A V4 certification hashes the constant 0xb4 1394 (which is an old-style packet header with the length-of-length set 1395 to zero), a four-octet number giving the length of the username, and 1396 then the username data. 1398 Once the data body is hashed, then a trailer is hashed. A V3 1399 signature hashes five octets of the packet body, starting from the 1400 signature type field. This data is the signature type, followed by 1401 the four-octet signature time. A V4 signature hashes the packet body 1402 starting from its first field, the version number, through the end 1403 of the hashed subpacket data. Thus, the fields hashed are the 1404 signature version, the signature type, the public key algorithm, the 1405 hash algorithm, the hashed subpacket length, and the hashed 1406 subpacket body. 1408 V4 signatures also hash in a final trailer of six octets: the 1409 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1410 big-endian number that is the length of the hashed data from the 1411 signature packet (note that this number does not include these final 1412 six octets. 1414 After all this has been hashed, the resulting hash field is used in 1415 the signature algorithm, and placed at the end of the signature 1416 packet. 1418 5.2.4.1. Subpacket Hints 1420 An implementation SHOULD put the two mandatory subpackets, creation 1421 time and issuer, as the first subpackets in the subpacket list, 1422 simply to make it easier for the implementer to find them. 1424 It is certainly possible for a signature to contain conflicting 1425 information in subpackets. For example, a signature may contain 1426 multiple copies of a preference or multiple expiration times. In 1427 most cases, an implementation SHOULD use the last subpacket in the 1428 signature, but MAY use any conflict resolution scheme that makes 1429 more sense. Please note that we are intentionally leaving conflict 1430 resolution to the implementer; most conflicts are simply syntax 1431 errors, and the wishy-washy language here allows a receiver to be 1432 generous in what they accept, while putting pressure on a creator to 1433 be stingy in what they generate. 1435 Some apparent conflicts may actually make sense -- for example, 1436 suppose a keyholder has an V3 key and a V4 key that share the same 1437 RSA key material. Either of these keys can verify a signature 1438 created by the other, and it may be reasonable for a signature to 1439 contain an issuer subpacket for each key, as a way of explicitly 1440 tying those keys to the signature. 1442 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 1444 The Symmetric-Key Encrypted Session Key packet holds the 1445 symmetric-key encryption of a session key used to encrypt a message. 1446 Zero or more Encrypted Session Key packets and/or Symmetric-Key 1447 Encrypted Session Key packets may precede a Symmetrically Encrypted 1448 Data Packet that holds an encrypted message. The message is 1449 encrypted with a session key, and the session key is itself 1450 encrypted and stored in the Encrypted Session Key packet or the 1451 Symmetric-Key Encrypted Session Key packet. 1453 If the Symmetrically Encrypted Data Packet is preceded by one or 1454 more Symmetric-Key Encrypted Session Key packets, each specifies a 1455 passphrase that may be used to decrypt the message. This allows a 1456 message to be encrypted to a number of public keys, and also to one 1457 or more pass phrases. This packet type is new, and is not generated 1458 by PGP 2.x or PGP 5.0. 1460 The body of this packet consists of: 1462 - A one-octet version number. The only currently defined version 1463 is 4. 1465 - A one-octet number describing the symmetric algorithm used. 1467 - A string-to-key (S2K) specifier, length as defined above. 1469 - Optionally, the encrypted session key itself, which is decrypted 1470 with the string-to-key object. 1472 If the encrypted session key is not present (which can be detected 1473 on the basis of packet length and S2K specifier size), then the S2K 1474 algorithm applied to the passphrase produces the session key for 1475 decrypting the file, using the symmetric cipher algorithm from the 1476 Symmetric-Key Encrypted Session Key packet. 1478 If the encrypted session key is present, the result of applying the 1479 S2K algorithm to the passphrase is used to decrypt just that 1480 encrypted session key field, using CFB mode with an IV of all zeros. 1481 The decryption result consists of a one-octet algorithm identifier 1482 that specifies the symmetric-key encryption algorithm used to 1483 encrypt the following Symmetrically Encrypted Data Packet, followed 1484 by the session key octets themselves. 1486 Note: because an all-zero IV is used for this decryption, the S2K 1487 specifier MUST use a salt value, either a a Salted S2K or an 1488 Iterated-Salted S2K. The salt value will insure that the decryption 1489 key is not repeated even if the passphrase is reused. 1491 5.4. One-Pass Signature Packets (Tag 4) 1493 The One-Pass Signature packet precedes the signed data and contains 1494 enough information to allow the receiver to begin calculating any 1495 hashes needed to verify the signature. It allows the Signature 1496 Packet to be placed at the end of the message, so that the signer 1497 can compute the entire signed message in one pass. 1499 A One-Pass Signature does not interoperate with PGP 2.6.x or 1500 earlier. 1502 The body of this packet consists of: 1504 - A one-octet version number. The current version is 3. 1506 - A one-octet signature type. Signature types are described in 1507 section 5.2.3. 1509 - A one-octet number describing the hash algorithm used. 1511 - A one-octet number describing the public key algorithm used. 1513 - An eight-octet number holding the key ID of the signing key. 1515 - A one-octet number holding a flag showing whether the signature 1516 is nested. A zero value indicates that the next packet is 1517 another One-Pass Signature packet that describes another 1518 signature to be applied to the same message data. 1520 5.5. Key Material Packet 1522 A key material packet contains all the information about a public or 1523 private key. There are four variants of this packet type, and two 1524 major versions. Consequently, this section is complex. 1526 5.5.1. Key Packet Variants 1528 5.5.1.1. Public Key Packet (Tag 6) 1530 A Public Key packet starts a series of packets that forms an OpenPGP 1531 key (sometimes called an OpenPGP certificate). 1533 5.5.1.2. Public Subkey Packet (Tag 14) 1535 A Public Subkey packet (tag 14) has exactly the same format as a 1536 Public Key packet, but denotes a subkey. One or more subkeys may be 1537 associated with a top-level key. By convention, the top-level key 1538 provides signature services, and the subkeys provide encryption 1539 services. 1541 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1542 packet. This tag was selected for reuse because no previous version 1543 of PGP ever emitted comment packets but they did properly ignore 1544 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1545 cause it to fail, providing a limited degree of backward 1546 compatibility. 1548 5.5.1.3. Secret Key Packet (Tag 5) 1550 A Secret Key packet contains all the information that is found in a 1551 Public Key packet, including the public key material, but also 1552 includes the secret key material after all the public key fields. 1554 5.5.1.4. Secret Subkey Packet (Tag 7) 1556 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1557 Key packet, and has exactly the same format. 1559 5.5.2. Public Key Packet Formats 1561 There are two versions of key-material packets. Version 3 packets 1562 were first generated by PGP 2.6. Version 2 packets are identical in 1563 format to Version 3 packets, but are generated by PGP 2.5 or before. 1564 V2 packets are deprecated and they MUST NOT be generated. 1566 PGP 5.0 introduced version 4 packets, with new fields and semantics. 1567 PGP 2.6.x will not accept key-material packets with versions 1568 greater than 3. 1570 OpenPGP implementations SHOULD create keys with version 4 format. An 1571 implementation MAY generate a V3 key to ensure interoperability with 1572 old software; note, however, that V4 keys correct some security 1573 deficiencies in V3 keys. These deficiencies are described below. An 1574 implementation MUST NOT create a V3 key with a public key algorithm 1575 other than RSA. 1577 A version 3 public key or public subkey packet contains: 1579 - A one-octet version number (3). 1581 - A four-octet number denoting the time that the key was created. 1583 - A two-octet number denoting the time in days that this key is 1584 valid. If this number is zero, then it does not expire. 1586 - A one-octet number denoting the public key algorithm of this key 1588 - A series of multi-precision integers comprising the key 1589 material: 1591 - a multiprecision integer (MPI) of RSA public modulus n; 1593 - an MPI of RSA public encryption exponent e. 1595 V3 keys SHOULD only be used for backward compatibility because of 1596 three weaknesses in them. First, it is relatively easy to construct 1597 a V3 key that has the same key ID as any other key because the key 1598 ID is simply the low 64 bits of the public modulus. Secondly, 1599 because the fingerprint of a V3 key hashes the key material, but not 1600 its length, which increases the opportunity for fingerprint 1601 collisions. Third, there are minor weaknesses in the MD5 hash 1602 algorithm that make developers prefer other algorithms. See below 1603 for a fuller discussion of key IDs and fingerprints. 1605 The version 4 format is similar to the version 3 format except for 1606 the absence of a validity period. This has been moved to the 1607 signature packet. In addition, fingerprints of version 4 keys are 1608 calculated differently from version 3 keys, as described in section 1609 "Enhanced Key Formats." 1611 A version 4 packet contains: 1613 - A one-octet version number (4). 1615 - A four-octet number denoting the time that the key was created. 1617 - A one-octet number denoting the public key algorithm of this key 1619 - A series of multi-precision integers comprising the key 1620 material. This algorithm-specific portion is: 1622 Algorithm Specific Fields for RSA public keys: 1624 - multiprecision integer (MPI) of RSA public modulus n; 1626 - MPI of RSA public encryption exponent e. 1628 Algorithm Specific Fields for DSA public keys: 1630 - MPI of DSA prime p; 1632 - MPI of DSA group order q (q is a prime divisor of p-1); 1634 - MPI of DSA group generator g; 1636 - MPI of DSA public key value y (= g**x where x is secret). 1638 Algorithm Specific Fields for Elgamal public keys: 1640 - MPI of Elgamal prime p; 1642 - MPI of Elgamal group generator g; 1644 - MPI of Elgamal public key value y (= g**x where x is 1645 secret). 1647 5.5.3. Secret Key Packet Formats 1649 The Secret Key and Secret Subkey packets contain all the data of the 1650 Public Key and Public Subkey packets, with additional 1651 algorithm-specific secret key data appended, in encrypted form. 1653 The packet contains: 1655 - A Public Key or Public Subkey packet, as described above 1657 - One octet indicating string-to-key usage conventions. 0 1658 indicates that the secret key data is not encrypted. 255 1659 indicates that a string-to-key specifier is being given. Any 1660 other value is a symmetric-key encryption algorithm specifier. 1662 - [Optional] If string-to-key usage octet was 255, a one-octet 1663 symmetric encryption algorithm. 1665 - [Optional] If string-to-key usage octet was 255, a string-to-key 1666 specifier. The length of the string-to-key specifier is implied 1667 by its type, as described above. 1669 - [Optional] If secret data is encrypted, eight-octet Initial 1670 Vector (IV). 1672 - Encrypted multi-precision integers comprising the secret key 1673 data. These algorithm-specific fields are as described below. 1675 - Two-octet checksum of the plaintext of the algorithm-specific 1676 portion (sum of all octets, mod 65536). 1678 Algorithm Specific Fields for RSA secret keys: 1680 - multiprecision integer (MPI) of RSA secret exponent d. 1682 - MPI of RSA secret prime value p. 1684 - MPI of RSA secret prime value q (p < q). 1686 - MPI of u, the multiplicative inverse of p, mod q. 1688 Algorithm Specific Fields for DSA secret keys: 1690 - MPI of DSA secret exponent x. 1692 Algorithm Specific Fields for Elgamal secret keys: 1694 - MPI of Elgamal secret exponent x. 1696 Secret MPI values can be encrypted using a passphrase. If a 1697 string-to-key specifier is given, that describes the algorithm for 1698 converting the passphrase to a key, else a simple MD5 hash of the 1699 passphrase is used. Implementations SHOULD use a string-to-key 1700 specifier; the simple hash is for backward compatibility. The cipher 1701 for encrypting the MPIs is specified in the secret key packet. 1703 Encryption/decryption of the secret data is done in CFB mode using 1704 the key created from the passphrase and the Initial Vector from the 1705 packet. A different mode is used with V3 keys (which are only RSA) 1706 than with other key formats. With V3 keys, the MPI bit count prefix 1707 (i.e., the first two octets) is not encrypted. Only the MPI 1708 non-prefix data is encrypted. Furthermore, the CFB state is 1709 resynchronized at the beginning of each new MPI value, so that the 1710 CFB block boundary is aligned with the start of the MPI data. 1712 With V4 keys, a simpler method is used. All secret MPI values are 1713 encrypted in CFB mode, including the MPI bitcount prefix. 1715 The 16-bit checksum that follows the algorithm-specific portion is 1716 the algebraic sum, mod 65536, of the plaintext of all the 1717 algorithm-specific octets (including MPI prefix and data). With V3 1718 keys, the checksum is stored in the clear. With V4 keys, the 1719 checksum is encrypted like the algorithm-specific data. This value 1720 is used to check that the passphrase was correct. 1722 5.6. Compressed Data Packet (Tag 8) 1724 The Compressed Data packet contains compressed data. Typically, this 1725 packet is found as the contents of an encrypted packet, or following 1726 a Signature or One-Pass Signature packet, and contains literal data 1727 packets. 1729 The body of this packet consists of: 1731 - One octet that gives the algorithm used to compress the packet. 1733 - The remainder of the packet is compressed data. 1735 A Compressed Data Packet's body contains an block that compresses 1736 some set of packets. See section "Packet Composition" for details on 1737 how messages are formed. 1739 ZIP-compressed packets are compressed with raw RFC1951 DEFLATE 1740 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 1741 implementation uses more bits of compression, If an implementation 1742 uses more bits of compression, PGP V2.6 cannot decompress it. 1744 ZLIB-compressed packets are compressed with RFC1950 ZLIB-style 1745 blocks. 1747 5.7. Symmetrically Encrypted Data Packet (Tag 9) 1749 The Symmetrically Encrypted Data packet contains data encrypted with 1750 a symmetric-key algorithm. When it has been decrypted, it will 1751 typically contain other packets (often literal data packets or 1752 compressed data packets). 1754 The body of this packet consists of: 1756 - Encrypted data, the output of the selected symmetric-key cipher 1757 operating in PGP's variant of Cipher Feedback (CFB) mode. 1759 The symmetric cipher used may be specified in an Public-Key or 1760 Symmetric-Key Encrypted Session Key packet that precedes the 1761 Symmetrically Encrypted Data Packet. In that case, the cipher 1762 algorithm octet is prefixed to the session key before it is 1763 encrypted. If no packets of these types precede the encrypted data, 1764 the IDEA algorithm is used with the session key calculated as the 1765 MD5 hash of the passphrase. 1767 The data is encrypted in CFB mode, with a CFB shift size equal to 1768 the cipher's block size. The Initial Vector (IV) is specified as 1769 all zeros. Instead of using an IV, OpenPGP prefixes a 10-octet 1770 string to the data before it is encrypted. The first eight octets 1771 are random, and the 9th and 10th octets are copies of the 7th and 1772 8th octets, respectively. After encrypting the first 10 octets, the 1773 CFB state is resynchronized if the cipher block size is 8 octets or 1774 less. The last 8 octets of ciphertext are passed through the cipher 1775 and the block boundary is reset. 1777 The repetition of 16 bits in the 80 bits of random data prefixed to 1778 the message allows the receiver to immediately check whether the 1779 session key is incorrect. 1781 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 1783 An experimental version of PGP used this packet as the Literal 1784 packet, but no released version of PGP generated Literal packets 1785 with this tag. With PGP 5.x, this packet has been re-assigned and is 1786 reserved for use as the Marker packet. 1788 The body of this packet consists of: 1790 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 1792 Such a packet MUST be ignored when received. It may be placed at 1793 the beginning of a message that uses features not available in PGP 1794 2.6.x in order to cause that version to report that newer software 1795 is necessary to process the message. 1797 5.9. Literal Data Packet (Tag 11) 1799 A Literal Data packet contains the body of a message; data that is 1800 not to be further interpreted. 1802 The body of this packet consists of: 1804 - A one-octet field that describes how the data is formatted. 1806 If it is a 'b' (0x62), then the literal packet contains binary data. 1807 If it is a 't' (0x74), then it contains text data, and thus may need 1808 line ends converted to local form, or other text-mode changes. RFC 1809 1991 also defined a value of 'l' as a 'local' mode for machine-local 1810 conversions. This use is now deprecated. 1812 - File name as a string (one-octet length, followed by file name), 1813 if the encrypted data should be saved as a file. 1815 If the special name "_CONSOLE" is used, the message is considered to 1816 be "for your eyes only". This advises that the message data is 1817 unusually sensitive, and the receiving program should process it 1818 more carefully, perhaps avoiding storing the received data to disk, 1819 for example. 1821 - A four-octet number that indicates the modification date of the 1822 file, or the creation time of the packet, or a zero that 1823 indicates the present time. 1825 - The remainder of the packet is literal data. 1827 Text data is stored with text endings (i.e. network-normal 1828 line endings). These should be converted to native line endings by 1829 the receiving software. 1831 5.10. Trust Packet (Tag 12) 1833 The Trust packet is used only within keyrings and is not normally 1834 exported. Trust packets contain data that record the user's 1835 specifications of which key holders are trustworthy introducers, 1836 along with other information that implementing software uses for 1837 trust information. 1839 Trust packets SHOULD NOT be emitted to output streams that are 1840 transferred to other users, and they SHOULD be ignored on any input 1841 other than local keyring files. 1843 5.11. User ID Packet (Tag 13) 1845 A User ID packet consists of data that is intended to represent the 1846 name and email address of the key holder. By convention, it 1847 includes an RFC822 mail name, but there are no restrictions on its 1848 content. The packet length in the header specifies the length of 1849 the user id. If it is text, it is encoded in UTF-8. 1851 6. Radix-64 Conversions 1853 As stated in the introduction, OpenPGP's underlying native 1854 representation for objects is a stream of arbitrary octets, and some 1855 systems desire these objects to be immune to damage caused by 1856 character set translation, data conversions, etc. 1858 In principle, any printable encoding scheme that met the 1859 requirements of the unsafe channel would suffice, since it would not 1860 change the underlying binary bit streams of the native OpenPGP data 1861 structures. The OpenPGP standard specifies one such printable 1862 encoding scheme to ensure interoperability. 1864 OpenPGP's Radix-64 encoding is composed of two parts: a base64 1865 encoding of the binary data, and a checksum. The base64 encoding is 1866 identical to the MIME base64 content-transfer-encoding [RFC 2045, 1867 Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to 1868 protect the raw binary data. 1870 The checksum is a 24-bit CRC converted to four characters of 1871 radix-64 encoding by the same MIME base64 transformation, preceded 1872 by an equals sign (=). The CRC is computed by using the generator 1873 0x864CFB and an initialization of 0xB704CE. The accumulation is 1874 done on the data before it is converted to radix-64, rather than on 1875 the converted data. A sample implementation of this algorithm is in 1876 the next section. 1878 The checksum with its leading equal sign MAY appear on the first 1879 line after the Base64 encoded data. 1881 Rationale for CRC-24: The size of 24 bits fits evenly into printable 1882 base64. The nonzero initialization can detect more errors than a 1883 zero initialization. 1885 6.1. An Implementation of the CRC-24 in "C" 1887 #define CRC24_INIT 0xb704ce 1888 #define CRC24_POLY 0x1864cfb 1890 typedef long crc24; 1891 crc24 crc_octets(unsigned char *octets, size_t len) 1892 { 1893 crc24 crc = CRC24_INIT; 1894 int i; 1896 while (len--) { 1897 crc ^= *octets++; 1898 for (i = 0; i < 8; i++) { 1899 crc <<= 1; 1900 if (crc & 0x1000000) 1901 crc ^= CRC24_POLY; 1902 } 1903 } 1904 return crc; 1905 } 1907 6.2. Forming ASCII Armor 1909 When OpenPGP encodes data into ASCII Armor, it puts specific headers 1910 around the data, so OpenPGP can reconstruct the data later. OpenPGP 1911 informs the user what kind of data is encoded in the ASCII armor 1912 through the use of the headers. 1914 Concatenating the following data creates ASCII Armor: 1916 - An Armor Header Line, appropriate for the type of data 1918 - Armor Headers 1919 - A blank (zero-length, or containing only whitespace) line 1921 - The ASCII-Armored data 1923 - An Armor Checksum 1925 - The Armor Tail, which depends on the Armor Header Line. 1927 An Armor Header Line consists of the appropriate header line text 1928 surrounded by five (5) dashes ('-', 0x2D) on either side of the 1929 header line text. The header line text is chosen based upon the 1930 type of data that is being encoded in Armor, and how it is being 1931 encoded. Header line texts include the following strings: 1933 BEGIN PGP MESSAGE 1934 Used for signed, encrypted, or compressed files 1936 BEGIN PGP PUBLIC KEY BLOCK 1937 Used for armoring public keys 1939 BEGIN PGP PRIVATE KEY BLOCK 1940 Used for armoring private keys 1942 BEGIN PGP MESSAGE, PART X/Y 1943 Used for multi-part messages, where the armor is split amongst Y 1944 parts, and this is the Xth part out of Y. 1946 BEGIN PGP MESSAGE, PART X 1947 Used for multi-part messages, where this is the Xth part of an 1948 unspecified number of parts. Requires the MESSAGE-ID Armor 1949 Header to be used. 1951 BEGIN PGP SIGNATURE 1952 Used for detached signatures, OpenPGP/MIME signatures, and 1953 signatures following clearsigned messages 1955 The Armor Headers are pairs of strings that can give the user or the 1956 receiving OpenPGP implementation some information about how to 1957 decode or use the message. The Armor Headers are a part of the 1958 armor, not a part of the message, and hence are not protected by any 1959 signatures applied to the message. 1961 The format of an Armor Header is that of a key-value pair. A colon 1962 (':' 0x38) and a single space (0x20) separate the key and value. 1963 OpenPGP should consider improperly formatted Armor Headers to be 1964 corruption of the ASCII Armor. Unknown keys should be reported to 1965 the user, but OpenPGP should continue to process the message. 1967 Currently defined Armor Header Keys are: 1969 - "Version", that states the OpenPGP Version used to encode the 1970 message. 1972 - "Comment", a user-defined comment. 1974 - "MessageID", a 32-character string of printable characters. The 1975 string must be the same for all parts of a multi-part message 1976 that uses the "PART X" Armor Header. MessageID strings should 1977 be unique enough that the recipient of the mail can associate 1978 all the parts of a message with each other. A good checksum or 1979 cryptographic hash function is sufficient. 1981 The MessageID SHOULD NOT appear unless it is in a multi-part 1982 message. If it appears at all, it MUST be computed from the 1983 finished (encrypted, signed, etc.) message in a deterministic 1984 fashion, rather than contain a purely random value. This is to 1985 allow the legitimate recipient to determine that the MessageID 1986 cannot serve as a covert means of leaking cryptographic key 1987 information. 1989 The Armor Tail Line is composed in the same manner as the Armor 1990 Header Line, except the string "BEGIN" is replaced by the string 1991 "END." 1993 6.3. Encoding Binary in Radix-64 1995 The encoding process represents 24-bit groups of input bits as 1996 output strings of 4 encoded characters. Proceeding from left to 1997 right, a 24-bit input group is formed by concatenating three 8-bit 1998 input groups. These 24 bits are then treated as four concatenated 1999 6-bit groups, each of which is translated into a single digit in the 2000 Radix-64 alphabet. When encoding a bit stream with the Radix-64 2001 encoding, the bit stream must be presumed to be ordered with the 2002 most-significant-bit first. That is, the first bit in the stream 2003 will be the high-order bit in the first 8-bit octet, and the eighth 2004 bit will be the low-order bit in the first 8-bit octet, and so on. 2006 +--first octet--+-second octet--+--third octet--+ 2007 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 2008 +-----------+---+-------+-------+---+-----------+ 2009 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 2010 +--1.index--+--2.index--+--3.index--+--4.index--+ 2012 Each 6-bit group is used as an index into an array of 64 printable 2013 characters from the table below. The character referenced by the 2014 index is placed in the output string. 2016 Value Encoding Value Encoding Value Encoding Value Encoding 2017 0 A 17 R 34 i 51 z 2018 1 B 18 S 35 j 52 0 2019 2 C 19 T 36 k 53 1 2020 3 D 20 U 37 l 54 2 2021 4 E 21 V 38 m 55 3 2022 5 F 22 W 39 n 56 4 2023 6 G 23 X 40 o 57 5 2024 7 H 24 Y 41 p 58 6 2025 8 I 25 Z 42 q 59 7 2026 9 J 26 a 43 r 60 8 2027 10 K 27 b 44 s 61 9 2028 11 L 28 c 45 t 62 + 2029 12 M 29 d 46 u 63 / 2030 13 N 30 e 47 v 2031 14 O 31 f 48 w (pad) = 2032 15 P 32 g 49 x 2033 16 Q 33 h 50 y 2035 The encoded output stream must be represented in lines of no more 2036 than 76 characters each. 2038 Special processing is performed if fewer than 24 bits are available 2039 at the end of the data being encoded. There are three possibilities: 2041 1. The last data group has 24 bits (3 octets). No special 2042 processing is needed. 2044 2. The last data group has 16 bits (2 octets). The first two 6-bit 2045 groups are processed as above. The third (incomplete) data group 2046 has two zero-value bits added to it, and is processed as above. 2047 A pad character (=) is added to the output. 2049 3. The last data group has 8 bits (1 octet). The first 6-bit group 2050 is processed as above. The second (incomplete) data group has 2051 four zero-value bits added to it, and is processed as above. Two 2052 pad characters (=) are added to the output. 2054 6.4. Decoding Radix-64 2056 Any characters outside of the base64 alphabet are ignored in 2057 Radix-64 data. Decoding software must ignore all line breaks or 2058 other characters not found in the table above. 2060 In Radix-64 data, characters other than those in the table, line 2061 breaks, and other white space probably indicate a transmission 2062 error, about which a warning message or even a message rejection 2063 might be appropriate under some circumstances. 2065 Because it is used only for padding at the end of the data, the 2066 occurrence of any "=" characters may be taken as evidence that the 2067 end of the data has been reached (without truncation in transit). No 2068 such assurance is possible, however, when the number of octets 2069 transmitted was a multiple of three and no "=" characters are 2070 present. 2072 6.5. Examples of Radix-64 2074 Input data: 0x14fb9c03d97e 2075 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2076 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2077 11111110 2078 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 2079 111110 2080 Decimal: 5 15 46 28 0 61 37 62 2081 Output: F P u c A 9 l + 2083 Input data: 0x14fb9c03d9 2084 Hex: 1 4 f b 9 c | 0 3 d 9 2085 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2086 pad with 00 2087 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2088 Decimal: 5 15 46 28 0 61 36 2089 pad with = 2090 Output: F P u c A 9 k = 2092 Input data: 0x14fb9c03 2093 Hex: 1 4 f b 9 c | 0 3 2094 8-bit: 00010100 11111011 10011100 | 00000011 2095 pad with 0000 2096 6-bit: 000101 001111 101110 011100 | 000000 110000 2097 Decimal: 5 15 46 28 0 48 2098 pad with = = 2099 Output: F P u c A w = = 2101 6.6. Example of an ASCII Armored Message 2103 -----BEGIN PGP MESSAGE----- 2104 Version: OpenPrivacy 0.99 2106 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2107 vBSFjNSiVHsuAA== 2108 =njUN 2109 -----END PGP MESSAGE----- 2111 Note that this example is indented by two spaces. 2113 7. Cleartext signature framework 2115 It is desirable to sign a textual octet stream without ASCII 2116 armoring the stream itself, so the signed text is still readable 2117 without special software. In order to bind a signature to such a 2118 cleartext, this framework is used. (Note that RFC 2015 defines 2119 another way to clear sign messages for environments that support 2120 MIME.) 2121 The cleartext signed message consists of: 2123 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2124 single line, 2126 - Zero or more "Hash" Armor Headers, 2128 - Exactly one empty line not included into the message digest, 2130 - The dash-escaped cleartext that is included into the message 2131 digest, 2133 - The ASCII armored signature(s) including the Armor Header and 2134 Armor Tail Lines. 2136 If the "Hash" armor header is given, the specified message digest 2137 algorithm is used for the signature. If there are no such headers, 2138 SHA-1 is used. If more than one message digest is used in the 2139 signature, the "Hash" armor header contains a comma-delimited list 2140 of used message digests. 2142 Current message digest names are described below with the algorithm 2143 IDs. 2145 7.1. Dash-Escaped Text 2147 The cleartext content of the message must also be dash-escaped. 2149 Dash escaped cleartext is the ordinary cleartext where every line 2150 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2151 (0x2D) and space ' ' (0x20). This prevents the parser from 2152 recognizing armor headers of the cleartext itself. The message 2153 digest is computed using the cleartext itself, not the dash escaped 2154 form. 2156 As with binary signatures on text documents, a cleartext signature 2157 is calculated on the text using canonical line endings. 2158 The line ending (i.e. the ) before the '-----BEGIN PGP 2159 SIGNATURE-----' line that terminates the signed text is not 2160 considered part of the signed text. 2162 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of 2163 any line is ignored when the cleartext signature is calculated. 2165 8. Regular Expressions 2167 A regular expression is zero or more branches, separated by '|'. It 2168 matches anything that matches one of the branches. 2170 A branch is zero or more pieces, concatenated. It matches a match 2171 for the first, followed by a match for the second, etc. 2173 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2174 followed by '*' matches a sequence of 0 or more matches of the atom. 2175 An atom followed by '+' matches a sequence of 1 or more matches of 2176 the atom. An atom followed by '?' matches a match of the atom, or 2177 the null string. 2179 An atom is a regular expression in parentheses (matching a match for 2180 the regular expression), a range (see below), '.' (matching any 2181 single character), '^' (matching the null string at the beginning of 2182 the input string), '$' (matching the null string at the end of the 2183 input string), a '\' followed by a single character (matching that 2184 character), or a single character with no other significance 2185 (matching that character). 2187 A range is a sequence of characters enclosed in '[]'. It normally 2188 matches any single character from the sequence. If the sequence 2189 begins with '^', it matches any single character not from the rest 2190 of the sequence. If two characters in the sequence are separated by 2191 '-', this is shorthand for the full list of ASCII characters between 2192 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2193 ']' in the sequence, make it the first character (following a 2194 possible '^'). To include a literal '-', make it the first or last 2195 character. 2197 9. Constants 2199 This section describes the constants used in OpenPGP. 2201 Note that these tables are not exhaustive lists; an implementation 2202 MAY implement an algorithm not on these lists. 2204 See the section "Notes on Algorithms" below for more discussion of 2205 the algorithms. 2207 9.1. Public Key Algorithms 2209 ID Algorithm 2210 -- --------- 2211 1 - RSA (Encrypt or Sign) 2212 2 - RSA Encrypt-Only 2213 3 - RSA Sign-Only 2214 16 - Elgamal (Encrypt-Only), see [ELGAMAL] 2215 17 - DSA (Digital Signature Standard) 2216 18 - Elliptic Curve 2217 19 - ECDSA 2218 20 - Elgamal (Encrypt or Sign) 2219 21 - Diffie-Hellman (X9.42) 2220 100 to 110 - Private/Experimental algorithm. 2222 Implementations MUST implement DSA for signatures, and Elgamal for 2223 encryption. Implementations SHOULD implement RSA keys. 2224 Implementations MAY implement any other algorithm. 2226 9.2. Symmetric Key Algorithms 2228 ID Algorithm 2229 -- --------- 2230 0 - Plaintext or unencrypted data 2231 1 - IDEA 2232 2 - Triple-DES (DES-EDE, as per spec - 2233 168 bit key derived from 192) 2234 3 - CAST5 (128 bit key) 2235 4 - Blowfish (128 bit key, 16 rounds) 2236 5 - SAFER-SK128 (13 rounds) 2237 6 - DES/SK 2238 100 to 110 - Private/Experimental algorithm. 2240 Implementations MUST implement Triple-DES. Implementations SHOULD 2241 implement IDEA and CAST5.Implementations MAY implement any other 2242 algorithm. 2244 9.3. Compression Algorithms 2246 ID Algorithm 2247 -- --------- 2248 0 - Uncompressed 2249 1 - ZIP (RFC1951) 2250 2 - ZLIB (RFC1950) 2251 100 to 110 - Private/Experimental algorithm. 2253 Implementations MUST implement uncompressed data. Implementations 2254 SHOULD implement ZIP. 2256 9.4. Hash Algorithms 2258 ID Algorithm Text Name 2259 -- --------- ---- ---- 2260 1 - MD5 "MD5" 2261 2 - SHA-1 "SHA1" 2262 3 - RIPE-MD/160 "RIPEMD160" 2263 4 - HAVAL (5 pass, 160-bit) "HAVAL-5-160" 2264 5 - MD2 "MD2" 2265 6 - TIGER/192 "TIGER192" 2266 100 to 110 - Private/Experimental algorithm. 2268 Implementations MUST implement SHA-1. Implementations SHOULD 2269 implement MD5. 2271 10. Packet Composition 2273 OpenPGP packets are assembled into sequences in order to create 2274 messages 2275 and to transfer keys. Not all possible packet sequences are 2276 meaningful and correct. This describes the rules for how packets 2277 should be placed into sequences. 2279 10.1. Transferable Public Keys 2281 OpenPGP users may transfer public keys. The essential elements of a 2282 transferable public key are: 2284 - One Public Key packet 2286 - Zero or more revocation signatures 2288 - One or more User ID packets 2290 - After each User ID packet, zero or more signature packets 2291 (certifications) 2293 - Zero or more Subkey packets 2295 - After each Subkey packet, one signature packet, optionally a 2296 revocation. 2298 The Public Key packet occurs first. Each of the following User ID 2299 packets provides the identity of the owner of this public key. If 2300 there are multiple User ID packets, this corresponds to multiple 2301 means of identifying the same unique individual user; for example, a 2302 user may have more than one email address, and construct a User ID 2303 for each one. 2305 Immediately following each User ID packet, there are zero or more 2306 signature packets. Each signature packet is calculated on the 2307 immediately preceding User ID packet and the initial Public Key 2308 packet. The signature serves to certify the corresponding public key 2309 and user ID. In effect, the signer is testifying to his or her 2310 belief that this public key belongs to the user identified by this 2311 user ID. 2313 After the User ID packets there may be one or more Subkey packets. 2314 In general, subkeys are provided in cases where the top-level public 2315 key is a signature-only key. However, any V4 key may have subkeys, 2316 and the subkeys may be encryption-only keys, signature-only keys, or 2317 general-purpose keys. 2319 Each Subkey packet must be followed by one Signature packet, which 2320 should be a subkey binding signature issued by the top level key. 2322 Subkey and Key packets may each be followed by a revocation 2323 Signature packet to indicate that the key is revoked. Revocation 2324 signatures are only accepted if they are issued by the key itself, 2325 or by a key that is authorized to issue revocations via a revocation 2326 key subpacket in a self-signature by the top level key. 2328 Transferable public key packet sequences may be concatenated to 2329 allow transferring multiple public keys in one operation. 2331 10.2. OpenPGP Messages 2333 An OpenPGP message is a packet or sequence of packets that 2334 corresponds to the following grammatical rules (comma represents 2335 sequential composition, and vertical bar separates alternatives): 2337 OpenPGP Message :- Encrypted Message | Signed Message | 2338 Compressed Message | Literal Message. 2340 Compressed Message :- Compressed Data Packet. 2342 Literal Message :- Literal Data Packet. 2344 ESK :- Pubic Key Encrypted Session Key Packet | 2345 Symmetric-Key Encrypted Session Key Packet. 2347 ESK Sequence :- ESK | ESK Sequence, ESK. 2349 Encrypted Message :- Symmetrically Encrypted Data Packet | 2350 ESK Sequence, Symmetrically Encrypted Data Packet. 2352 One-Pass Signed Message :- One-Pass Signature Packet, 2353 OpenPGP Message, Signature Packet. 2355 Signed Message :- Signature Packet, OpenPGP Message | 2356 One-Pass Signed Message. 2358 In addition, decrypting a Symmetrically Encrypted Data packet and 2360 decompressing a Compressed Data packet must yield a valid OpenPGP 2361 Message. 2363 11. Enhanced Key Formats 2365 11.1. Key Structures 2367 The format of an OpenPGP V3 key is as follows. Entries in square 2368 brackets are optional and ellipses indicate repetition. 2370 RSA Public Key 2371 [Revocation Self Signature] 2372 User ID [Signature ...] 2373 [User ID [Signature ...] ...] 2375 Each signature certifies the RSA public key and the preceding user 2376 ID. The RSA public key can have many user IDs and each user ID can 2377 have many signatures. 2379 The format of an OpenPGP V4 key that uses two public keys is similar 2380 except that the other keys are added to the end as 'subkeys' of the 2381 primary key. 2383 Primary-Key 2384 [Revocation Self Signature] 2385 [Direct Key Self Signature...] 2386 User ID [Signature ...] 2387 [User ID [Signature ...] ...] 2388 [[Subkey [Binding-Signature-Revocation] 2389 Primary-Key-Binding-Signature] ...] 2391 A subkey always has a single signature after it that is issued using 2392 the primary key to tie the two keys together. This binding 2393 signature may be in either V3 or V4 format, but V4 is prefered, of 2394 course. 2396 In the above diagram, if the binding signature of a subkey has been 2397 revoked, the revoked binding signature may be removed, leaving only 2398 one signature. 2400 In a key that has a main key and subkeys, the primary key MUST be a 2401 key capable of signing. The subkeys may be keys of any other type. 2402 There may be other constructions of V4 keys, too. For example, there 2403 may be a single-key RSA key in V4 format, a DSA primary key with an 2404 RSA encryption key, or RSA primary key with an Elgamal subkey, etc. 2406 It is also possible to have a signature-only subkey. This permits a 2407 primary key that collects certifications (key signatures) but is 2408 used only used for certifying subkeys that are used for encryption 2409 and signatures. 2411 11.2. Key IDs and Fingerprints 2413 For a V3 key, the eight-octet key ID consists of the low 64 bits of 2414 the public modulus of the RSA key. 2416 The fingerprint of a V3 key is formed by hashing the body (but not 2417 the two-octet length) of the MPIs that form the key material (public 2418 modulus n, followed by exponent e) with MD5. 2420 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet 2421 Tag, followed by the two-octet packet length, followed by the entire 2422 Public Key packet starting with the version field. The key ID is 2423 either the low order 64 bits of the fingerprint. Here are the 2424 fields of the hash material, with the example of a DSA key: 2426 a.1) 0x99 (1 octet) 2428 a.2) high order length octet of (b)-(f) (1 octet) 2429 a.3) low order length octet of (b)-(f) (1 octet) 2431 b) version number = 4 (1 octet); 2433 c) time stamp of key creation (4 octets); 2435 d) algorithm (1 octet): 7 = DSA (example); 2437 e) Algorithm specific fields. 2439 Algorithm Specific Fields for DSA keys (example): 2441 e.1) MPI of DSA prime p; 2443 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 2445 e.3) MPI of DSA group generator g; 2447 e.4) MPI of DSA public key value y (= g**x where x is secret). 2449 Note that it is possible for there to be collisions of key IDs -- 2450 two different keys with the same key ID. Note that there is a much 2451 smaller, but still non-zero probability that two different keys have 2452 the same fingerprint. 2454 Also note that if V3 and V4 format keys share the same RSA key 2455 material, they will have different key ids as well as different 2456 fingerprints. 2458 12. Notes on Algorithms 2460 12.1. Symmetric Algorithm Preferences 2462 The symmetric algorithm preference is an ordered list of algorithms 2463 that the keyholder accepts. Since it is found on a self-signature, 2464 it is possible that a keyholder may have different preferences. For 2465 example, Alice may have TripleDES only specified for 2466 "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 2467 "alice@home.org". Note that it is also possible for preferences to 2468 be in a subkey's binding signature. 2470 Since TripleDES is the MUST-implement algorithm, if it is not 2471 explicitly in the list, it is tacitly at the end. However, it is 2472 good form to place it there explicitly. Note also that if an 2473 implementation does not implement the preference, then it is 2474 implicitly a TripleDES-only implementation. 2476 An implementation MUST not use a symmetric algorithm that is not in 2477 the recipient's preference list. When encrypting to more than one 2478 recipient, the implementation finds a suitable algorithm by taking 2479 the intersection of the preferences of the recipients. Note that the 2480 MUST-implement algorithm, TripleDES, ensures that the intersection 2481 is not null. The implementation may use any mechanism to pick an 2482 algorithm in the intersection. 2484 If an implementation can decrypt a message that a keyholder doesn't 2485 have in their preferences, the implementation SHOULD decrypt the 2486 message anyway, but MUST warn the keyholder than protocol has been 2487 violated. (For example, suppose that Alice, above, has software that 2488 implements all algorithms in this specification. Nonetheless, she 2489 prefers subsets for work or home. If she is sent a message encrypted 2490 with IDEA, which is not in her preferences, the software warns her 2491 that someone sent her an IDEA-encrypted message, but it would 2492 ideally decrypt it anyway.) 2494 An implementation that is striving for backward compatibility MAY 2495 consider a V3 key with a V3 self-signature to be an implicit 2496 preference for IDEA, and no ability to do TripleDES. This is 2497 technically non-compliant, but an implementation MAY violate the 2498 above rule in this case only and use IDEA to encrypt the message, 2499 provided that the message creator is warned. Ideally, though, the 2500 implementation would follow the rule by actually generating two 2501 messages, because it is possible that the OpenPGP user's 2502 implementation does not have IDEA, and thus could not read the 2503 message. Consenquently, an implementation MAY, but SHOULD NOT use 2504 IDEA in an algorithm conflict with a V3 key. 2506 12.2. Other Algorithm Preferences 2508 Other algorithm preferences work similarly to the symmetric 2509 algorithm preference, in that they specify which algorithms the 2510 keyholder accepts. There are two interesting cases that other 2511 comments need to be made about, though, the compression preferences 2512 and the hash preferences. 2514 12.2.1. Compression Preferences 2516 Compression has been an integral part of PGP since its first days. 2517 OpenPGP and all previous versions of PGP have offered compression. 2518 And in this specification, the default is for messages to be 2519 compressed, although an implementation is not required to do so. 2520 Consequently, the compression preference gives a way for a keyholder 2521 to request that messages not be compressed, presumably because they 2522 are using a minimal implementation that does not include 2523 compression. Additionally, this gives a keyholder a way to state 2524 that it can support alternate algorithms. 2526 Like the algorithm preferences, an implementation MUST NOT use an 2527 algorithm that is not in the preference vector. If the preferences 2528 are mot present, then they are assumed to be [ZIP(1), 2529 UNCOMPRESSED(0)]. 2531 12.2.2. Hash Algorithm Preferences 2533 Typically, the choice of a hash algorithm is something the signer 2534 does, rather than the verifier, because a signer does not typically 2535 know who is going to be verifying the signature. This preference, 2536 though, allows a protocol based upon digital signatures ease in 2537 negotiation. 2539 Thus, if Alice is authenticating herself to Bob with a signature, it 2540 makes sense for her to use a hash algorithm that Bob's software 2541 uses. This preference allows Bob to state in his key which 2542 algorithms Alice may use. 2544 12.3. Plaintext 2546 Algorithm 0, "plaintext," may only be used to denote secret keys 2547 that are stored in the clear. Implementations must not use plaintext 2548 in Symmetrically Encrypted Data Packets; they must use Literal Data 2549 Packets to encode unencrypted or literal data. 2551 12.4. RSA 2553 There are algorithm types for RSA-signature-only, and 2554 RSA-encrypt-only keys. These types are deprecated. The "key flags" 2555 subpacket in a signature is a much better way to express the same 2556 idea, and generalizes it to all algorithms. An implementation SHOULD 2557 NOT create such a key, but MAY interpret it. 2559 An implementation SHOULD NOT implement RSA keys of size less than 2560 768 bits. 2562 It is permissible for an implementation to support RSA merely for 2563 backward compatibility; for example, such an implementation would 2564 support V3 keys with IDEA symmetric cryptography. Note that this is 2565 an exception to the other MUST-implement rules. An implementation 2566 that supports RSA in V4 keys MUST implement the MUST-implement 2567 features. 2569 12.5. Elgamal 2571 If an Elgamal key is to be used for both signing and encryption, 2572 extra care must be taken in creating the key. 2574 An ElGamal key consists of a generator g, a prime modulus p, a 2575 secret exponent x, and a public value y = g^x mod p. 2577 The generator and prime must be chosen so that solving the discrete 2578 log problem is intractable. The group g should generate the 2579 multiplicative group mod p-1 or a large subgroup of it, and the 2580 order of g should have at least one large prime factor. A good 2581 choice is to use a "strong" Sophie-Germain prime in choosing p, so 2582 that both p and (p-1)/2 are primes. 2584 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that 2585 if the generator g has only small prime factors, and if g divides 2586 the order of the group it generates, then signatures can be forged. 2587 In particular, choosing g=2 is a bad choice if the group order may 2588 be even. On the other hand, a generator of 2 is a fine choice for an 2589 encryption-only key, as this will make the encryption faster. 2591 While verifying Elgamal signatures, note that it is important to 2592 test that r and s are less than p. If this test is not done then 2593 signatures can be trivially forged by using large r values of 2594 approximately twice the length of p. This attack is also discussed 2595 in the Bleichenbacher paper. 2597 Details on safe use of Elgamal signatures may be found in [MENEZES], 2598 which discusses all the weaknesses described above. 2600 If an implementation allows Elgamal signatures, then it MUST use the 2601 algorithm identifier 20. 2603 An implementation SHOULD NOT implement Elgamal keys of size less 2604 than 768 bits. For long-term security, Elgamal keys should be 1024 2605 bits or longer. 2607 12.6. DSA 2609 An implementation SHOULD NOT implement DSA keys of size less than 2610 768 bits. Note that present DSA is limited to a maximum of 1024 bit 2611 keys, which are recommended for long-term use. 2613 12.7. OpenPGP CFB mode 2615 OpenPGP does symmetric encryption using a variant of Cipher Feedback 2616 Mode (CFB mode). This section describes the procedure it uses in 2617 detail. This mode is what is used for Symmetrically Encrypted Data 2618 Packets; the mechanism used for encrypting secret key material is 2619 similar, but described in those sections above. 2621 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 2622 and prefixes the plaintext with ten bytes of random data, such that 2623 bytes 9 and 10 match bytes 7 and 8. It does a CFB "resync" after 2624 encrypting those ten bytes. 2626 Note that for an algorithm that has a larger block size than 64 2627 bits, the equivalent function will be done with that entire block. 2629 Step by step, here is the procedure: 2631 1. The feedback register (FR) is set to the IV, which is all zeros. 2633 2. FR is encrypted to produce FRE (FR Encrypted). This is the 2634 encryption of an all-zero value. 2636 3. FRE is xored with the first 8 bytes of random data prefixed to 2637 the plaintext to produce C1-C8, the first 8 bytes of ciphertext. 2639 4. FR is loaded with C1-C8. 2641 5. FR is encrypted to produce FRE, the encryption of the first 8 2642 bytes of ciphertext. 2644 6. The left two bytes of FRE get xored with the next two bytes of 2645 data that were prefixed to the plaintext. This produces C9-C10, 2646 the next two bytes of ciphertext. 2648 7. (The resync step) FR is loaded with C3-C10. 2650 8. FR is encrypted to produce FRE. 2652 9. FRE is xored with the first 8 bytes of the given plaintext, now 2653 that we have finished encrypting the 10 bytes of prefixed data. 2654 This produces C11-C18, the next 8 bytes of ciphertext. 2656 10. FR is loaded with C11-C18 2658 11. FR is encrypted to produce FRE. 2660 12. FRE is xored with the next 8 bytes of plaintext, to produce the 2661 next 8 bytes of ciphertext. These are loaded into FR and the 2662 process is repeated until the plaintext is used up. 2664 13. Security Considerations 2666 As with any technology involving cryptography, you should check the 2667 current literature to determine if any algorithms used here have 2668 been found to be vulnerable to attack. 2670 This specification uses Public Key Cryptography technologies. 2671 Possession of the private key portion of a public-private key pair 2672 is assumed to be controlled by the proper party or parties. 2674 Certain operations in this specification involve the use of random 2675 numbers. An appropriate entropy source should be used to generate 2676 these numbers. See RFC 1750. 2678 The MD5 hash algorithm has been found to have weaknesses 2679 (pseudo-collisions in the compress function) that make some people 2680 deprecate its use. They consider the SHA-1 algorithm better. 2682 The DSA algorithm will work with any 160-bit hash, but it is 2683 sensitive to the quality of the hash algorithm, if the hash 2684 algorithm is broken, it can leak the secret key. The Digital 2685 Signature Standard (DSS) specifies that DSA be used with SHA-1. 2686 RIPEMD-160 is considered by many cryptographers to be as strong. An 2687 implementation should take care which hash algorithms are used with 2688 DSA, as a weak hash can not only allow a signature to be forged, but 2689 could leak the secret key. 2691 If you are building an authentication system, the recipient may 2692 specify a preferred signing algorithm. However, the signer would be 2693 foolish to use a weak algorithm simply because the recipient 2694 requests it. 2696 Some of the encryption algorithms mentioned in this document have 2697 been analyzed less than others. For example, although CAST5 is 2698 presently considered strong, it has been analyzed less than 2699 Triple-DES. Other algorithms may have other controversies 2700 surrounding them. 2702 Some technologies mentioned here may be subject to government 2703 control in some countries. 2705 14. Implementation Nits 2707 This section is a collection of comments to help an implementer, 2708 particularly with an eye to backward compatibility. Previous 2709 implementations of PGP are not OpenPGP-compliant. Often the 2710 differences are small, but small differences are frequently more 2711 vexing than large differences. Thus, this list of potential problems 2712 and gotchas for a developer who is trying to be backward-compatible. 2714 * PGP 5.x does not accept V4 signatures for anything other than 2715 key material. 2717 * PGP 5.x does not recognize the "five-octet" lengths in 2718 new-format headers or in signature subpacket lengths. 2720 * PGP 5.0 rejects an encrypted session key if the keylength 2721 differs from the the S2K symmetric algorithm. This is a bug in 2722 its validation function. 2724 * PGP 5.0 does not handle multiple one-pass signature headers and 2725 trailers. Signing one will compress the one-pass signed literal 2726 and prefix a V3 signature instead of doing a nested one-pass 2727 signature. 2729 * When exporting a private key, PGP 2.x generates the header 2730 "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY 2731 BLOCK". All previous versions ignore the implied data type, and 2732 look directly at the packet data type. 2734 * In a clear-signed signature, PGP 5.0 will figure out the correct 2735 hash algorithm if there is no "Hash:" header, but it will reject 2736 a mismatch between the header and the actual agorithm used. The 2737 "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x 2738 rejects the "Hash:" header and assumes MD5. There are a number 2739 of enhanced variants of PGP 2.6.x that have been modified for 2740 SHA-1 signatures. 2742 * PGP 5.0 can read an RSA key in V4 format, but will only 2743 recognize it using V3 format. 2745 * There are many ways possible for for two keys to have the same 2746 key material, but different fingerprints (and thus key ids). 2747 Perhaps the most interesting is an RSA key that has been 2748 "upgraded" to V4 format, but since a V4 fingerprint is 2749 constructed by hashing the key creation time along with other 2750 things, two V4 keys created at different times, yet with the 2751 same key material will have different fingerprints. 2753 * PGP 2.6.x and PGP 5.0 sometimes add to the beginning of a file a 2754 zero-length compressed data packet. 2756 * If an implemtation is using zlib to interoperate with PGP 2.x, 2757 then the "windowBits" parameter should be set to -13. 2759 15. Authors and Working Group Chair 2761 The working group can be contacted via the current chair: 2763 John W. Noerenberg, II 2764 Qualcomm, Inc 2765 6455 Lusk Blvd 2766 San Diego, CA 92131 USA 2767 Email: jwn2@qualcomm.com 2768 Tel: +1 619-658-3510 2770 The principal authors of this draft are: 2772 Jon Callas 2773 Network Associates, Inc. 2774 4200 Bohannon Drive 2775 Menlo Park, CA 94025, USA 2776 Email: jon@pgp.com 2777 Tel: +1-650-473-2860 2779 Lutz Donnerhacke 2780 IKS GmbH 2781 Wildenbruchstr. 15 2782 07745 Jena, Germany 2783 EMail: lutz@iks-jena.de 2784 Tel: +49-3641-675642 2786 Hal Finney 2787 Network Associates, Inc. 2788 4200 Bohannon Drive 2789 Menlo Park, CA 94025, USA 2790 Email: hal@pgp.com 2791 Rodney Thayer 2792 EIS Corporation 2793 Clearwater, FL 33767 2794 Email: rodney@unitran.com 2796 This draft also draws on much previous work from a number of other 2797 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 2798 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph 2799 Levine, Colin Plumb, Will Price, William Stallings, Mark Weaver, and 2800 Philip R. Zimmermann. 2802 16. References 2804 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal 2805 signatures without knowing the secret key," Eurocrypt 96. Note that 2806 the version in the proceedings has an error. A revised version is 2807 available at the time of writing from 2808 2810 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved 2811 international version of PGP", 2812 ftp://ftp.iks-jena.de/mitarb/lutz/crypt/software/pgp/ 2814 [ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a Signature 2815 Scheme Based on Discrete Logarithms," IEEE Transactions on 2816 Information Theory, v. IT-31, n. 4, 1985, pp. 469-472. 2818 [ISO-10646] ISO/IEC 10646-1:1993. International Standard -- 2819 Information technology -- Universal Multiple-Octet Coded Character 2820 Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane. 2821 UTF-8 is described in Annex R, adopted but not yet published. 2822 UTF-16 is described in Annex Q, adopted but not yet published. 2824 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott Vanstone, 2825 "Handbook of Applied Cryptography," CRC Press, 1996. 2827 [PKCS1] RSA Laboratories, "PKCS #1: RSA Encryption Standard," 2828 version 1.5, November 1993 2830 [RFC822] D. Crocker, "Standard for the format of ARPA Internet text 2831 messages", RFC 822, August 1982 2833 [RFC1423] D. Balenson, "Privacy Enhancement for Internet Electronic 2834 Mail: Part III: Algorithms, Modes, and Identifiers", RFC 1423, 2835 October 1993 2837 [RFC1641] Goldsmith, D., and M. Davis, "Using Unicode with MIME", 2838 RFC 1641, Taligent inc., July 1994. 2840 [RFC1750] Eastlake, Crocker, & Schiller., Randomness Recommendations 2841 for Security. December 1994. 2843 [RFC1951] Deutsch, P., DEFLATE Compressed Data Format Specification 2844 version 1.3. May 1996. 2846 [RFC1983] G. Malkin., Internet Users' Glossary. August 1996. 2848 [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP Message 2849 Exchange Formats", RFC 1991, August 1996. 2851 [RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy 2852 (PGP)", RFC 2015, October 1996. 2854 [RFC2044] F. Yergeau., UTF-8, a transformation format of Unicode and 2855 ISO 10646. October 1996. 2857 [RFC2045] Borenstein, N., and Freed, N., "Multipurpose Internet Mail 2858 Extensions (MIME) Part One: Format of Internet Message Bodies.", 2859 November 1996 2861 [RFC2119] Bradner, S., Key words for use in RFCs to Indicate 2862 Requirement Level. March 1997. 2864 17. Full Copyright Statement 2866 Copyright 1998 by The Internet Society. All Rights Reserved. 2868 This document and translations of it may be copied and furnished to 2869 others, and derivative works that comment on or otherwise explain it 2870 or assist in its implementation may be prepared, copied, published 2871 and distributed, in whole or in part, without restriction of any 2872 kind, provided that the above copyright notice and this paragraph 2873 are included on all such copies and derivative works. However, this 2874 document itself may not be modified in any way, such as by removing 2875 the copyright notice or references to the Internet Society or other 2876 Internet organizations, except as needed for the purpose of 2877 developing Internet standards in which case the procedures for 2878 copyrights defined in the Internet Standards process must be 2879 followed, or as required to translate it into languages other than 2880 English. 2882 The limited permissions granted above are perpetual and will not be 2883 revoked by the Internet Society or its successors or assigns.