idnits 2.17.1 draft-ietf-openpgp-formats-07.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- ** Looks like you're using RFC 2026 boilerplate. This must be updated to follow RFC 3978/3979, as updated by RFC 4748. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- ** Missing document type: Expected "INTERNET-DRAFT" in the upper left hand corner of the first page ** 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). == 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 329 -- Looks like a reference, but probably isn't: '1' on line 329 -- Looks like a reference, but probably isn't: '2' on line 329 -- Looks like a reference, but probably isn't: '3' on line 330 == Missing Reference: 'ISO10646' is mentioned on line 370, but not defined == Missing Reference: 'Optional' is mentioned on line 1710, but not defined == Missing Reference: 'Binding-Signature-Revocation' is mentioned on line 2450, but not defined == Unused Reference: 'DONNERHACKE' is defined on line 2906, but no explicit reference was found in the text == Unused Reference: 'ISO-10646' is defined on line 2914, but no explicit reference was found in the text == Unused Reference: 'RFC822' is defined on line 2923, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 2926, but no explicit reference was found in the text == Unused Reference: 'RFC1641' is defined on line 2930, but no explicit reference was found in the text == Unused Reference: 'RFC1750' is defined on line 2933, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 2936, but no explicit reference was found in the text == Unused Reference: 'RFC1983' is defined on line 2939, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 2941, but no explicit reference was found in the text == Unused Reference: 'RFC2015' is defined on line 2944, but no explicit reference was found in the text == Unused Reference: 'RFC2231' is defined on line 2947, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 2951, but no explicit reference was found in the text == Unused Reference: 'RFC2144' is defined on line 2954, 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' ** Obsolete normative reference: RFC 822 (Obsoleted by RFC 2822) ** Downref: Normative reference to an Historic RFC: RFC 1423 ** Downref: Normative reference to an Experimental RFC: RFC 1641 ** Obsolete normative reference: RFC 1750 (Obsoleted by RFC 4086) ** Downref: Normative reference to an Informational RFC: RFC 1951 ** Downref: Normative reference to an Informational RFC: RFC 1983 ** Obsolete normative reference: RFC 1991 (Obsoleted by RFC 4880) ** Downref: Normative reference to an Informational RFC: RFC 2144 ** Obsolete normative reference: RFC 2279 (Obsoleted by RFC 3629) ** Obsolete normative reference: RFC 2313 (Obsoleted by RFC 2437) Summary: 19 errors (**), 0 flaws (~~), 19 warnings (==), 12 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-07.txt 4 Expires Feb 1999 Lutz Donnerhacke 5 August 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-07.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 2.5. Signature-Only Applications 7 67 3. Data Element Formats 7 68 3.1. Scalar numbers 7 69 3.2. Multi-Precision Integers 8 70 3.3. Key IDs 8 71 3.4. Text 8 72 3.5. Time fields 8 73 3.6. String-to-key (S2K) specifiers 8 74 3.6.1. String-to-key (S2k) specifier types 9 75 3.6.1.1. Simple S2K 9 76 3.6.1.2. Salted S2K 9 77 3.6.1.3. Iterated and Salted S2K 10 78 3.6.2. String-to-key usage 10 79 3.6.2.1. Secret key encryption 10 80 3.6.2.2. Symmetric-key message encryption 11 81 4. Packet Syntax 11 82 4.1. Overview 11 83 4.2. Packet Headers 12 84 4.2.1. Old-Format Packet Lengths 12 85 4.2.2. New-Format Packet Lengths 13 86 4.2.2.1. One-Octet Lengths 13 87 4.2.2.2. Two-Octet Lengths 13 88 4.2.2.3. Five-Octet Lengths 13 89 4.2.2.4. Partial Body Lengths 13 90 4.2.3. Packet Length Examples 14 91 4.3. Packet Tags 14 92 5. Packet Types 15 93 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 15 94 5.2. Signature Packet (Tag 2) 16 95 5.2.1. Signature Types 16 96 5.2.2. Version 3 Signature Packet Format 18 97 5.2.3. Version 4 Signature Packet Format 20 98 5.2.3.1. Signature Subpacket Specification 21 99 5.2.3.2. Signature Subpacket Types 22 100 5.2.3.3. Signature creation time 23 101 5.2.3.4. Issuer 23 102 5.2.3.5. Key expiration time 23 103 5.2.3.6. Preferred symmetric algorithms 23 104 5.2.3.7. Preferred hash algorithms 24 105 5.2.3.8. Preferred compression algorithms 24 106 5.2.3.9. Signature expiration time 24 107 5.2.3.10.Exportable Certification 24 108 5.2.3.11.Revocable 25 109 5.2.3.12.Trust signature 25 110 5.2.3.13.Regular expression 25 111 5.2.3.14.Revocation key 26 112 5.2.3.15.Notation Data 26 113 5.2.3.16.Key server preferences 26 114 5.2.3.17.Preferred key server 27 115 5.2.3.18.Primary user id 27 116 5.2.3.19.Policy URL 27 117 5.2.3.20.Key Flags 27 118 5.2.3.21.Signer's User ID 28 119 5.2.3.22.Reason for Revocation 28 120 5.2.4. Computing Signatures 29 121 5.2.4.1. Subpacket Hints 30 122 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 30 123 5.4. One-Pass Signature Packets (Tag 4) 31 124 5.5. Key Material Packet 32 125 5.5.1. Key Packet Variants 32 126 5.5.1.1. Public Key Packet (Tag 6) 32 127 5.5.1.2. Public Subkey Packet (Tag 14) 32 128 5.5.1.3. Secret Key Packet (Tag 5) 32 129 5.5.1.4. Secret Subkey Packet (Tag 7) 32 130 5.5.2. Public Key Packet Formats 32 131 5.5.3. Secret Key Packet Formats 34 132 5.6. Compressed Data Packet (Tag 8) 36 133 5.7. Symmetrically Encrypted Data Packet (Tag 9) 36 134 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 37 135 5.9. Literal Data Packet (Tag 11) 37 136 5.10. Trust Packet (Tag 12) 38 137 5.11. User ID Packet (Tag 13) 38 138 6. Radix-64 Conversions 38 139 6.1. An Implementation of the CRC-24 in "C" 39 140 6.2. Forming ASCII Armor 39 141 6.3. Encoding Binary in Radix-64 41 142 6.4. Decoding Radix-64 42 143 6.5. Examples of Radix-64 43 144 6.6. Example of an ASCII Armored Message 43 145 7. Cleartext signature framework 43 146 7.1. Dash-Escaped Text 44 147 8. Regular Expressions 44 148 9. Constants 45 149 9.1. Public Key Algorithms 45 150 9.2. Symmetric Key Algorithms 46 151 9.3. Compression Algorithms 46 152 9.4. Hash Algorithms 46 153 10. Packet Composition 47 154 10.1. Transferable Public Keys 47 155 10.2. OpenPGP Messages 48 156 11. Enhanced Key Formats 48 157 11.1. Key Structures 48 158 11.2. Key IDs and Fingerprints 49 159 12. Notes on Algorithms 50 160 12.1. Symmetric Algorithm Preferences 50 161 12.2. Other Algorithm Preferences 51 162 12.2.1. Compression Preferences 51 163 12.2.2. Hash Algorithm Preferences 52 164 12.3. Plaintext 52 165 12.4. RSA 52 166 12.5. Elgamal 52 167 12.6. DSA 53 168 12.7. Reserved Algorithm Numbers 53 169 12.8. OpenPGP CFB mode 54 170 13. Security Considerations 55 171 14. Implementation Nits 56 172 15. Authors and Working Group Chair 57 173 16. References 58 174 17. Full Copyright Statement 59 176 1. Introduction 178 This document provides information on the message-exchange packet 179 formats used by OpenPGP to provide encryption, decryption, signing, 180 and key management functions. It builds on the foundation provided 181 in RFC1991 "PGP Message Exchange Formats." 183 1.1. Terms 185 * OpenPGP - This is a definition for security software that uses 186 PGP 5.x as a basis. 188 * PGP - Pretty Good Privacy. PGP is a family of software systems 189 developed by Philip R. Zimmermann from which OpenPGP is based. 191 * PGP 2.6.x - This version of PGP has many variants, hence the 192 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 193 cryptographic transforms. An informational RFC, RFC1991, was 194 written describing this version of PGP. 196 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 197 the community and also in the predecessor of this document, 198 RFC1991. It has new formats and corrects a number of problems in 199 the PGP 2.6.x design. It is referred to here as PGP 5.x because 200 that software was the first release of the "PGP 3" code base. 202 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 203 Network Associates, Inc. and are used with permission. 205 This document uses the terms "MUST", "SHOULD", and "MAY" as defined 206 in RFC2119, along with the negated forms of those terms. 208 2. General functions 210 OpenPGP provides data integrity services for messages and data files 211 by using these core technologies: 213 - digital signatures 215 - encryption 217 - compression 219 - radix-64 conversion 221 In addition, OpenPGP provides key management and certificate 222 services, but many of these are beyond the scope of this document. 224 2.1. Confidentiality via Encryption 226 OpenPGP uses two encryption methods to provide confidentiality: 227 symmetric-key encryption and public key encryption. With public-key 228 encryption, the object is encrypted using a symmetric encryption 229 algorithm. Each symmetric key is used only once. A new "session 230 key" is generated as a random number for each message. Since it is 231 used only once, the session key is bound to the message and 232 transmitted with it. To protect the key, it is encrypted with the 233 receiver's public key. The sequence is as follows: 235 1. The sender creates a message. 237 2. The sending OpenPGP generates a random number to be used as a 238 session key for this message only. 240 3. The session key is encrypted using each recipient's public key. 241 These "encrypted session keys" start the message. 243 4. The sending OpenPGP encrypts the message using the session key, 244 which forms the remainder of the message. Note that the message 245 is also usually compressed. 247 5. The receiving OpenPGP decrypts the session key using the 248 recipient's private key. 250 6. The receiving OpenPGP decrypts the message using the session 251 key. If the message was compressed, it will be decompressed. 253 With symmetric-key encryption, an object may be encrypted with a 254 symmetric key derived from a passphrase (or other shared secret), or 255 a two-stage mechanism similar to the public-key method described 256 above in which a session key is itself encrypted with a symmetric 257 algorithm keyed from a shared secret. 259 Both digital signature and confidentiality services may be applied 260 to the same message. First, a signature is generated for the message 261 and attached to the message. Then, the message plus signature is 262 encrypted using a symmetric session key. Finally, the session key is 263 encrypted using public-key encryption and prefixed to the encrypted 264 block. 266 2.2. Authentication via Digital signature 268 The digital signature uses a hash code or message digest algorithm, 269 and a public-key signature algorithm. The sequence is as follows: 271 1. The sender creates a message. 273 2. The sending software generates a hash code of the message. 275 3. The sending software generates a signature from the hash code 276 using the sender's private key. 278 4. The binary signature is attached to the message. 280 5. The receiving software keeps a copy of the message signature. 282 6. The receiving software generates a new hash code for the 283 received message and verifies it using the message's signature. 284 If the verification is successful, the message is accepted as 285 authentic. 287 2.3. Compression 289 OpenPGP implementations MAY compress the message after applying the 290 signature but before encryption. 292 2.4. Conversion to Radix-64 294 OpenPGP's underlying native representation for encrypted messages, 295 signature certificates, and keys is a stream of arbitrary octets. 296 Some systems only permit the use of blocks consisting of seven-bit, 297 printable text. For transporting OpenPGP's native raw binary octets 298 through channels that are not safe to raw binary data, a printable 299 encoding of these binary octets is needed. OpenPGP provides the 300 service of converting the raw 8-bit binary octet stream to a stream 301 of printable ASCII characters, called Radix-64 encoding or ASCII 302 Armor. 304 Implementations SHOULD provide Radix-64 conversions. 306 Note that many applications, particularly messaging applications, 307 will want more advanced features as described in the OpenPGP-MIME 308 document, RFC2015. An application that implements OpenPGP for 309 messaging SHOULD implement OpenPGP-MIME. 311 2.5. Signature-Only Applications 313 OpenPGP is designed for applications that use both encryption and 314 signatures, but there are a number of problems that are solved by a 315 signature-only implementation. Although this specification requires 316 both encryption and signatures, it is reasonable for there to be 317 subset implementations that are non-comformant only in that they 318 omit encryption. 320 3. Data Element Formats 322 This section describes the data elements used by OpenPGP. 324 3.1. Scalar numbers 326 Scalar numbers are unsigned, and are always stored in big-endian 327 format. Using n[k] to refer to the kth octet being interpreted, the 328 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 329 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 330 n[3]). 332 3.2. Multi-Precision Integers 334 Multi-Precision Integers (also called MPIs) are unsigned integers 335 used to hold large integers such as the ones used in cryptographic 336 calculations. 338 An MPI consists of two pieces: a two-octet scalar that is the length 339 of the MPI in bits followed by a string of octets that contain the 340 actual integer. 342 These octets form a big-endian number; a big-endian number can be 343 made into an MPI by prefixing it with the appropriate length. 345 Examples: 347 (all numbers are in hexadecimal) 349 The string of octets [00 01 01] forms an MPI with the value 1. The 350 string [00 09 01 FF] forms an MPI with the value of 511. 352 Additional rules: 354 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 356 The length field of an MPI describes the length starting from its 357 most significant non-zero bit. Thus, the MPI [00 02 01] is not 358 formed correctly. It should be [00 01 01]. 360 3.3. Key IDs 362 A Key ID is an eight-octet scalar that identifies a key. 363 Implementations SHOULD NOT assume that Key IDs are unique. The 364 section, "Enhanced Key Formats" below describes how Key IDs are 365 formed. 367 3.4. Text 369 The default character set for text is the UTF-8 [RFC2279] encoding 370 of Unicode [ISO10646]. 372 3.5. Time fields 374 A time field is an unsigned four-octet number containing the number 375 of seconds elapsed since midnight, 1 January 1970 UTC. 377 3.6. String-to-key (S2K) specifiers 379 String-to-key (S2K) specifiers are used to convert passphrase 380 strings into symmetric-key encryption/decryption keys. They are 381 used in two places, currently: to encrypt the secret part of private 382 keys in the private keyring, and to convert passphrases to 383 encryption keys for symmetrically encrypted messages. 385 3.6.1. String-to-key (S2k) specifier types 387 There are three types of S2K specifiers currently supported, as 388 follows: 390 3.6.1.1. Simple S2K 392 This directly hashes the string to produce the key data. See below 393 for how this hashing is done. 395 Octet 0: 0x00 396 Octet 1: hash algorithm 398 Simple S2K hashes the passphrase to produce the session key. The 399 manner in which this is done depends on the size of the session key 400 (which will depend on the cipher used) and the size of the hash 401 algorithm's output. If the hash size is greater than or equal to the 402 session key size, the high-order (leftmost) octets of the hash are 403 used as the key. 405 If the hash size is less than the key size, multiple instances of 406 the hash context are created -- enough to produce the required key 407 data. These instances are preloaded with 0, 1, 2, ... octets of 408 zeros (that is to say, the first instance has no preloading, the 409 second gets preloaded with 1 octet of zero, the third is preloaded 410 with two octets of zeros, and so forth). 412 As the data is hashed, it is given independently to each hash 413 context. Since the contexts have been initialized differently, they 414 will each produce different hash output. Once the passphrase is 415 hashed, the output data from the multiple hashes is concatenated, 416 first hash leftmost, to produce the key data, with any excess octets 417 on the right discarded. 419 3.6.1.2. Salted S2K 421 This includes a "salt" value in the S2K specifier -- some arbitrary 422 data -- that gets hashed along with the passphrase string, to help 423 prevent dictionary attacks. 425 Octet 0: 0x01 426 Octet 1: hash algorithm 427 Octets 2-9: 8-octet salt value 429 Salted S2K is exactly like Simple S2K, except that the input to the 430 hash function(s) consists of the 8 octets of salt from the S2K 431 specifier, followed by the passphrase. 433 3.6.1.3. Iterated and Salted S2K 435 This includes both a salt and an octet count. The salt is combined 436 with the passphrase and the resulting value is hashed repeatedly. 437 This further increases the amount of work an attacker must do to try 438 dictionary attacks. 440 Octet 0: 0x03 441 Octet 1: hash algorithm 442 Octets 2-9: 8-octet salt value 443 Octet 10: count, a one-octet, coded value 445 The count is coded into a one-octet number using the following 446 formula: 448 #define EXPBIAS 6 449 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 451 The above formula is in C, where "Int32" is a type for a 32-bit 452 integer, and the variable "c" is the coded count, Octet 10. 454 Iterated-Salted S2K hashes the passphrase and salt data multiple 455 times. The total number of octets to be hashed is specified in the 456 encoded count in the S2K specifier. Note that the resulting count 457 value is an octet count of how many octets will be hashed, not an 458 iteration count. 460 Initially, one or more hash contexts are set up as with the other 461 S2K algorithms, depending on how many octets of key data are needed. 462 Then the salt, followed by the passphrase data is repeatedly hashed 463 until the number of octets specified by the octet count has been 464 hashed. The one exception is that if the octet count is less than 465 the size of the salt plus passphrase, the full salt plus passphrase 466 will be hashed even though that is greater than the octet count. 467 After the hashing is done the data is unloaded from the hash 468 context(s) as with the other S2K algorithms. 470 3.6.2. String-to-key usage 472 Implementations SHOULD use salted or iterated-and-salted S2K 473 specifiers, as simple S2K specifiers are more vulnerable to 474 dictionary attacks. 476 3.6.2.1. Secret key encryption 478 An S2K specifier can be stored in the secret keyring to specify how 479 to convert the passphrase to a key that unlocks the secret data. 480 Older versions of PGP just stored a cipher algorithm octet preceding 481 the secret data or a zero to indicate that the secret data was 482 unencrypted. The MD5 hash function was always used to convert the 483 passphrase to a key for the specified cipher algorithm. 485 For compatibility, when an S2K specifier is used, the special value 486 255 is stored in the position where the hash algorithm octet would 487 have been in the old data structure. This is then followed 488 immediately by a one-octet algorithm identifier, and then by the S2K 489 specifier as encoded above. 491 Therefore, preceding the secret data there will be one of these 492 possibilities: 494 0: secret data is unencrypted (no pass phrase) 495 255: followed by algorithm octet and S2K specifier 496 Cipher alg: use Simple S2K algorithm using MD5 hash 498 This last possibility, the cipher algorithm number with an implicit 499 use of MD5 and IDEA, is provided for backward compatibility; it MAY 500 be understood, but SHOULD NOT be generated, and is deprecated. 502 These are followed by an 8-octet Initial Vector for the decryption 503 of the secret values, if they are encrypted, and then the secret key 504 values themselves. 506 3.6.2.2. Symmetric-key message encryption 508 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 509 packet at the front of a message. This is used to allow S2K 510 specifiers to be used for the passphrase conversion or to create 511 messages with a mix of symmetric-key ESKs and public-key ESKs. This 512 allows a message to be decrypted either with a passphrase or a 513 public key. 515 PGP 2.X always used IDEA with Simple string-to-key conversion when 516 encrypting a message with a symmetric algorithm. This is deprecated, 517 but MAY be used for backward-compatibility. 519 4. Packet Syntax 521 This section describes the packets used by OpenPGP. 523 4.1. Overview 525 An OpenPGP message is constructed from a number of records that are 526 traditionally called packets. A packet is a chunk of data that has a 527 tag specifying its meaning. An OpenPGP message, keyring, 528 certificate, and so forth consists of a number of packets. Some of 529 those packets may contain other OpenPGP packets (for example, a 530 compressed data packet, when uncompressed, contains OpenPGP 531 packets). 533 Each packet consists of a packet header, followed by the packet 534 body. The packet header is of variable length. 536 4.2. Packet Headers 538 The first octet of the packet header is called the "Packet Tag." It 539 determines the format of the header and denotes the packet contents. 540 The remainder of the packet header is the length of the packet. 542 Note that the most significant bit is the left-most bit, called bit 543 7. A mask for this bit is 0x80 in hexadecimal. 545 +---------------+ 546 PTag |7 6 5 4 3 2 1 0| 547 +---------------+ 548 Bit 7 -- Always one 549 Bit 6 -- New packet format if set 551 PGP 2.6.x only uses old format packets. Thus, software that 552 interoperates with those versions of PGP must only use old format 553 packets. If interoperability is not an issue, either format may be 554 used. Note that old format packets have four bits of content tags, 555 and new format packets have six; some features cannot be used and 556 still be backward-compatible. 558 Old format packets contain: 560 Bits 5-2 -- content tag 561 Bits 1-0 - length-type 563 New format packets contain: 565 Bits 5-0 -- content tag 567 4.2.1. Old-Format Packet Lengths 569 The meaning of the length-type in old-format packets is: 571 0 - The packet has a one-octet length. The header is 2 octets long. 573 1 - The packet has a two-octet length. The header is 3 octets long. 575 2 - The packet has a four-octet length. The header is 5 octets long. 577 3 - The packet is of indeterminate length. The header is 1 octet 578 long, and the implementation must determine how long the packet 579 is. If the packet is in a file, this means that the packet 580 extends until the end of the file. In general, an implementation 581 SHOULD NOT use indeterminate length packets except where the end 582 of the data will be clear from the context, and even then it is 583 better to use a definite length, or a new-format header. The 584 new-format headers described below have a mechanism for 585 precisely encoding data of indeterminate length. 587 4.2.2. New-Format Packet Lengths 589 New format packets have four possible ways of encoding length: 591 1. A one-octet Body Length header encodes packet lengths of up to 592 191 octets. 594 2. A two-octet Body Length header encodes packet lengths of 192 to 595 8383 octets. 597 3. A five-octet Body Length header encodes packet lengths of up to 598 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 599 encodes a four-octet scalar number.) 601 4. When the length of the packet body is not known in advance by 602 the issuer, Partial Body Length headers encode a packet of 603 indeterminate length, effectively making it a stream. 605 4.2.2.1. One-Octet Lengths 607 A one-octet Body Length header encodes a length of from 0 to 191 608 octets. This type of length header is recognized because the one 609 octet value is less than 192. The body length is equal to: 611 bodyLen = 1st_octet; 613 4.2.2.2. Two-Octet Lengths 615 A two-octet Body Length header encodes a length of from 192 to 8383 616 octets. It is recognized because its first octet is in the range 617 192 to 223. The body length is equal to: 619 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 621 4.2.2.3. Five-Octet Lengths 623 A five-octet Body Length header consists of a single octet holding 624 the value 255, followed by a four-octet scalar. The body length is 625 equal to: 627 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 628 (4th_octet << 8) | 5th_octet 630 4.2.2.4. Partial Body Lengths 632 A Partial Body Length header is one octet long and encodes the 633 length of only part of the data packet. This length is a power of 2, 634 from 1 to 1,073,741,824 (2 to the 30th power). It is recognized by 635 its one octet value that is greater than or equal to 224, and less 636 than 255. The partial body length is equal to: 638 partialBodyLen = 1 << (1st_octet & 0x1f); 640 Each Partial Body Length header is followed by a portion of the 641 packet body data. The Partial Body Length header specifies this 642 portion's length. Another length header (of one of the three types 643 -- one octet, two-octet, or partial) follows that portion. The last 644 length header in the packet MUST NOT be a partial Body Length 645 header. Partial Body Length headers may only be used for the 646 non-final parts of the packet. 648 4.2.3. Packet Length Examples 650 These examples show ways that new-format packets might encode the 651 packet lengths. 653 A packet with length 100 may have its length encoded in one octet: 654 0x64. This is followed by 100 octets of data. 656 A packet with length 1723 may have its length coded in two octets: 657 0xC5, 0xFB. This header is followed by the 1723 octets of data. 659 A packet with length 100000 may have its length encoded in five 660 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 662 It might also be encoded in the following octet stream: 0xEF, first 663 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 664 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 665 1693 octets of data. This is just one possible encoding, and many 666 variations are possible on the size of the Partial Body Length 667 headers, as long as a regular Body Length header encodes the last 668 portion of the data. Note also that the last Body Length header can 669 be a zero-length header. 671 An implementation MAY use Partial Body Lengths for data packets, be 672 they literal, compressed, or encrypted. The first partial length 673 MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 674 used for any other packet types. 676 Please note that in all of these explanations, the total length of 677 the packet is the length of the header(s) plus the length of the 678 body. 680 4.3. Packet Tags 682 The packet tag denotes what type of packet the body holds. Note that 683 old format headers can only have tags less than 16, whereas new 684 format headers can have tags as great as 63. The defined tags (in 685 decimal) are: 687 0 -- Reserved - a packet tag must not have this value 688 1 -- Public-Key Encrypted Session Key Packet 689 2 -- Signature Packet 690 3 -- Symmetric-Key Encrypted Session Key Packet 691 4 -- One-Pass Signature Packet 692 5 -- Secret Key Packet 693 6 -- Public Key Packet 694 7 -- Secret Subkey Packet 695 8 -- Compressed Data Packet 696 9 -- Symmetrically Encrypted Data Packet 697 10 -- Marker Packet 698 11 -- Literal Data Packet 699 12 -- Trust Packet 700 13 -- User ID Packet 701 14 -- Public Subkey Packet 702 60 to 63 -- Private or Experimental Values 704 5. Packet Types 706 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 708 A Public-Key Encrypted Session Key packet holds the session key used 709 to encrypt a message. Zero or more Encrypted Session Key packets 710 (either Public-Key or Symmetric-Key) may precede a Symmetrically 711 Encrypted Data Packet, which holds an encrypted message. The 712 message is encrypted with the session key, and the session key is 713 itself encrypted and stored in the Encrypted Session Key packet(s). 714 The Symmetrically Encrypted Data Packet is preceded by one 715 Public-Key Encrypted Session Key packet for each OpenPGP key to 716 which the message is encrypted. The recipient of the message finds 717 a session key that is encrypted to their public key, decrypts the 718 session key, and then uses the session key to decrypt the message. 720 The body of this packet consists of: 722 - A one-octet number giving the version number of the packet type. 723 The currently defined value for packet version is 3. An 724 implementation should accept, but not generate a version of 2, 725 which is equivalent to V3 in all other respects. 727 - An eight-octet number that gives the key ID of the public key 728 that the session key is encrypted to. 730 - A one-octet number giving the public key algorithm used. 732 - A string of octets that is the encrypted session key. This 733 string takes up the remainder of the packet, and its contents 734 are dependent on the public key algorithm used. 736 Algorithm Specific Fields for RSA encryption 738 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 740 Algorithm Specific Fields for Elgamal encryption: 742 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 744 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 746 The value "m" in the above formulas is derived from the session key 747 as follows. First the session key is prefixed with a one-octet 748 algorithm identifier that specifies the symmetric encryption 749 algorithm used to encrypt the following Symmetrically Encrypted Data 750 Packet. Then a two-octet checksum is appended which is equal to the 751 sum of the preceding octets, including the algorithm identifier and 752 session key, modulo 65536. This value is then padded as described 753 in PKCS-1 block type 02 [RFC2313] to form the "m" value used in the 754 formulas above. 756 Note that when an implementation forms several PKESKs with one 757 session key, forming a message that can be decrypted by several 758 keys, the implementation MUST make new PKCS-1 padding for each key. 760 An implementation MAY accept or use a Key ID of zero as a "wild 761 card" or "speculative" Key ID. In this case, the receiving 762 implementation would try all available private keys, checking for a 763 valid decrypted session key. This format helps reduce traffic 764 analysis of messages. 766 5.2. Signature Packet (Tag 2) 768 A signature packet describes a binding between some public key and 769 some data. The most common signatures are a signature of a file or a 770 block of text, and a signature that is a certification of a user ID. 772 Two versions of signature packets are defined. Version 3 provides 773 basic signature information, while version 4 provides an expandable 774 format with subpackets that can specify more information about the 775 signature. PGP 2.6.x only accepts version 3 signatures. 777 Implementations MUST accept V3 signatures. Implementations SHOULD 778 generate V4 signatures. Implementations MAY generate a V3 signature 779 that can be verified by PGP 2.6.x. 781 Note that if an implementation is creating an encrypted and signed 782 message that is encrypted to a V3 key, it is reasonable to create a 783 V3 signature. 785 5.2.1. Signature Types 787 There are a number of possible meanings for a signature, which are 788 specified in a signature type octet in any given signature. These 789 meanings are: 791 0x00: Signature of a binary document. 792 Typically, this means the signer owns it, created it, or 793 certifies that it has not been modified. 795 0x01: Signature of a canonical text document. 796 Typically, this means the signer owns it, created it, or 797 certifies that it has not been modified. The signature is 798 calculated over the text data with its line endings converted to 799 and trailing blanks removed. 801 0x02: Standalone signature. 802 This signature is a signature of only its own subpacket 803 contents. It is calculated identically to a signature over a 804 zero-length binary document. Note that it doesn't make sense to 805 have a V3 standalone signature. 807 0x10: Generic certification of a User ID and Public Key packet. 808 The issuer of this certification does not make any particular 809 assertion as to how well the certifier has checked that the 810 owner of the key is in fact the person described by the user ID. 811 Note that all PGP "key signatures" are this type of 812 certification. 814 0x11: Persona certification of a User ID and Public Key packet. 815 The issuer of this certification has not done any verification 816 of the claim that the owner of this key is the user ID 817 specified. 819 0x12: Casual certification of a User ID and Public Key packet. 820 The issuer of this certification has done some casual 821 verification of the claim of identity. 823 0x13: Positive certification of a User ID and Public Key packet. 824 The issuer of this certification has done substantial 825 verification of the claim of identity. 827 Please note that the vagueness of these certification claims is 828 not a flaw, but a feature of the system. Because PGP places 829 final authority for validity upon the receiver of a 830 certification, it may be that one authority's casual 831 certification might be more rigorous than some other authority's 832 positive certification. These classifications allow a 833 certification authority to issue fine-grained claims. 835 0x18: Subkey Binding Signature 836 This signature is a statement by the top-level signing key 837 indicates that it owns the subkey. This signature is calculated 838 directly on the subkey itself, not on any User ID or other 839 packets. 841 0x1F: Signature directly on a key 842 This signature is calculated directly on a key. It binds the 843 information in the signature subpackets to the key, and is 844 appropriate to be used for subpackets that provide information 845 about the key, such as the revocation key subpacket. It is also 846 appropriate for statements that non-self certifiers want to make 847 about the key itself, rather than the binding between a key and 848 a name. 850 0x20: Key revocation signature 851 The signature is calculated directly on the key being revoked. 852 A revoked key is not to be used. Only revocation signatures by 853 the key being revoked, or by an authorized revocation key, 854 should be considered valid revocation signatures. 856 0x28: Subkey revocation signature 857 The signature is calculated directly on the subkey being 858 revoked. A revoked subkey is not to be used. Only revocation 859 signatures by the top-level signature key that is bound to this 860 subkey, or by an authorized revocation key, should be considered 861 valid revocation signatures. 863 0x30: Certification revocation signature 864 This signature revokes an earlier user ID certification 865 signature (signature class 0x10 through 0x13). It should be 866 issued by the same key that issued the revoked signature or an 867 authorized revocation key The signature should have a later 868 creation date than the signature it revokes. 870 0x40: Timestamp signature. 871 This signature is only meaningful for the timestamp contained in 872 it. 874 5.2.2. Version 3 Signature Packet Format 876 The body of a version 3 Signature Packet contains: 878 - One-octet version number (3). 880 - One-octet length of following hashed material. MUST be 5. 882 - One-octet signature type. 884 - Four-octet creation time. 886 - Eight-octet key ID of signer. 888 - One-octet public key algorithm. 890 - One-octet hash algorithm. 892 - Two-octet field holding left 16 bits of signed hash value. 894 - One or more multi-precision integers comprising the signature. 895 This portion is algorithm specific, as described below. 897 The data being signed is hashed, and then the signature type and 898 creation time from the signature packet are hashed (5 additional 899 octets). The resulting hash value is used in the signature 900 algorithm. The high 16 bits (first two octets) of the hash are 901 included in the signature packet to provide a quick test to reject 902 some invalid signatures. 904 Algorithm Specific Fields for RSA signatures: 906 - multiprecision integer (MPI) of RSA signature value m**d. 908 Algorithm Specific Fields for DSA signatures: 910 - MPI of DSA value r. 912 - MPI of DSA value s. 914 The signature calculation is based on a hash of the signed data, as 915 described above. The details of the calculation are different for 916 DSA signature than for RSA signatures. 918 With RSA signatures, the hash value is encoded as described in 919 PKCS-1 section 10.1.2, "Data encoding", producing an ASN.1 value of 920 type DigestInfo, and then padded using PKCS-1 block type 01 921 [RFC2313]. This requires inserting the hash value as an octet 922 string into an ASN.1 structure. The object identifier for the type 923 of hash being used is included in the structure. The hexadecimal 924 representations for the currently defined hash algorithms are: 926 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02 928 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 930 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 932 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 934 The ASN.1 OIDs are: 936 - MD2: 1.2.840.113549.2.2 938 - MD5: 1.2.840.113549.2.5 940 - RIPEMD-160: 1.3.36.3.2.1 941 - SHA-1: 1.3.14.3.2.26 943 The full hash prefixes for these are: 945 MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 946 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 947 0x04, 0x10 949 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 950 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 951 0x04, 0x10 953 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 954 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 956 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 957 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 959 DSA signatures MUST use hashes with a size of 160 bits, to match q, 960 the size of the group generated by the DSA key's generator value. 961 The hash function result is treated as a 160 bit number and used 962 directly in the DSA signature algorithm. 964 5.2.3. Version 4 Signature Packet Format 966 The body of a version 4 Signature Packet contains: 968 - One-octet version number (4). 970 - One-octet signature type. 972 - One-octet public key algorithm. 974 - One-octet hash algorithm. 976 - Two-octet scalar octet count for following hashed subpacket 977 data. Note that this is the length in octets of all of the 978 hashed subpackets; a pointer incremented by this number will 979 skip over the hashed subpackets. 981 - Hashed subpacket data. (zero or more subpackets) 983 - Two-octet scalar octet count for following unhashed subpacket 984 data. Note that this is the length in octets of all of the 985 unhashed subpackets; a pointer incremented by this number will 986 skip over the unhashed subpackets. 988 - Unhashed subpacket data. (zero or more subpackets) 990 - Two-octet field holding left 16 bits of signed hash value. 992 - One or more multi-precision integers comprising the signature. 993 This portion is algorithm specific, as described above. 995 The data being signed is hashed, and then the signature data from 996 the version number through the hashed subpacket data (inclusive) is 997 hashed. The resulting hash value is what is signed. The left 16 998 bits of the hash are included in the signature packet to provide a 999 quick test to reject some invalid signatures. 1001 There are two fields consisting of signature subpackets. The first 1002 field is hashed with the rest of the signature data, while the 1003 second is unhashed. The second set of subpackets is not 1004 cryptographically protected by the signature and should include only 1005 advisory information. 1007 The algorithms for converting the hash function result to a 1008 signature are described in a section below. 1010 5.2.3.1. Signature Subpacket Specification 1012 The subpacket fields consist of zero or more signature subpackets. 1013 Each set of subpackets is preceded by a two-octet scalar count of 1014 the length of the set of subpackets. 1016 Each subpacket consists of a subpacket header and a body. The 1017 header consists of: 1019 - the subpacket length (1, 2, or 5 octets) 1021 - the subpacket type (1 octet) 1023 and is followed by the subpacket specific data. 1025 The length includes the type octet but not this length. Its format 1026 is similar to the "new" format packet header lengths, but cannot 1027 have partial body lengths. That is: 1029 if the 1st octet < 192, then 1030 lengthOfLength = 1 1031 subpacketLen = 1st_octet 1033 if the 1st octet >= 192 and < 255, then 1034 lengthOfLength = 2 1035 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1037 if the 1st octet = 255, then 1038 lengthOfLength = 5 1039 subpacket length = [four-octet scalar starting at 2nd_octet] 1041 The value of the subpacket type octet may be: 1043 2 = signature creation time 1044 3 = signature expiration time 1045 4 = exportable certification 1046 5 = trust signature 1047 6 = regular expression 1048 7 = revocable 1049 9 = key expiration time 1050 10 = placeholder for backward compatibility 1051 11 = preferred symmetric algorithms 1052 12 = revocation key 1053 16 = issuer key ID 1054 20 = notation data 1055 21 = preferred hash algorithms 1056 22 = preferred compression algorithms 1057 23 = key server preferences 1058 24 = preferred key server 1059 25 = primary user id 1060 26 = policy URL 1061 27 = key flags 1062 28 = signer's user id 1063 29 = reason for revocation 1064 100 to 110 = internal or user-defined 1066 An implementation SHOULD ignore any subpacket of a type that it does 1067 not recognize. 1069 Bit 7 of the subpacket type is the "critical" bit. If set, it 1070 denotes that the subpacket is one that is critical for the evaluator 1071 of the signature to recognize. If a subpacket is encountered that 1072 is marked critical but is unknown to the evaluating software, the 1073 evaluator SHOULD consider the signature to be in error. 1075 An evaluator may "recognize" a subpacket, but not implement it. The 1076 purpose of the critical bit is to allow the signer to tell an 1077 evaluator that it would prefer a new, unknown feature to generate an 1078 error than be ignored. 1080 Implementations SHOULD implement "preferences". 1082 5.2.3.2. Signature Subpacket Types 1084 A number of subpackets are currently defined. Some subpackets apply 1085 to the signature itself and some are attributes of the key. 1086 Subpackets that are found on a self-signature are placed on a user 1087 id certification made by the key itself. Note that a key may have 1088 more than one user id, and thus may have more than one 1089 self-signature, and differing subpackets. 1091 A self-signature is a binding signature made by the key the 1092 signature refers to. There are three types of self-signatures, the 1093 certification signatures (types 0x10-0x13), the direct-key signature 1094 (type 0x1f), and the subkey binding signature (type 0x18). For 1095 certification self-signatures, each user ID may have a 1096 self-signature, and thus different subpackets in those 1097 self-signatures. For subkey binding signatures, each subkey in fact 1098 has a self-signature. Subpackets that appear in a certification 1099 self-signature apply to the username, and subpackets that appear in 1100 the subkey self-signature apply to the subkey. Lastly, subpackets on 1101 the direct key signature apply to the entire key. 1103 Implementing software should interpret a self-signature's preference 1104 subpackets as narrowly as possible. For example, suppose a key has 1105 two usernames, Alice and Bob. Suppose that Alice prefers the 1106 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If 1107 the software locates this key via Alice's name, then the preferred 1108 algorithm is CAST5, if software locates the key via Bob's name, then 1109 the preferred algorithm is IDEA. If the key is located by key id, 1110 then algorithm of the default user id of the key provides the 1111 default symmetric algorithm. 1113 A subpacket may be found either in the hashed or unhashed subpacket 1114 sections of a signature. If a subpacket is not hashed, then the 1115 information in it cannot be considered definitive because it is not 1116 part of the signature proper. 1118 5.2.3.3. Signature creation time 1120 (4 octet time field) 1122 The time the signature was made. 1124 MUST be present in the hashed area. 1126 5.2.3.4. Issuer 1128 (8 octet key ID) 1130 The OpenPGP key ID of the key issuing the signature. 1132 5.2.3.5. Key expiration time 1134 (4 octet time field) 1136 The validity period of the key. This is the number of seconds after 1137 the key creation time that the key expires. If this is not present 1138 or has a value of zero, the key never expires. This is found only on 1139 a self-signature. 1141 5.2.3.6. Preferred symmetric algorithms 1143 (sequence of one-octet values) 1144 Symmetric algorithm numbers that indicate which algorithms the key 1145 holder prefers to use. The subpacket body is an ordered list of 1146 octets with the most preferred listed first. It is assumed that only 1147 algorithms listed are supported by the recipient's software. 1148 Algorithm numbers in section 9. This is only found on a 1149 self-signature. 1151 5.2.3.7. Preferred hash algorithms 1153 (array of one-octet values) 1155 Message digest algorithm numbers that indicate which algorithms the 1156 key holder prefers to receive. Like the preferred symmetric 1157 algorithms, the list is ordered. Algorithm numbers are in section 6. 1158 This is only found on a self-signature. 1160 5.2.3.8. Preferred compression algorithms 1162 (array of one-octet values) 1164 Compression algorithm numbers that indicate which algorithms the key 1165 holder prefers to use. Like the preferred symmetric algorithms, the 1166 list is ordered. Algorithm numbers are in section 6. If this 1167 subpacket is not included, ZIP is preferred. A zero denotes that 1168 uncompressed data is preferred; the key holder's software might have 1169 no compression software in that implementation. This is only found 1170 on a self-signature. 1172 5.2.3.9. Signature expiration time 1174 (4 octet time field) 1176 The validity period of the signature. This is the number of seconds 1177 after the signature creation time that the signature expires. If 1178 this is not present or has a value of zero, it never expires. 1180 5.2.3.10. Exportable Certification 1182 (1 octet of exportability, 0 for not, 1 for exportable) 1184 This subpacket denotes whether a certification signature is 1185 "exportable," to be used by other users than the signature's issuer. 1186 The packet body contains a boolean flag indicating whether the 1187 signature is exportable. If this packet is not present, the 1188 certification is exportable; it is equivalent to a flag containing a 1189 1. 1191 Non-exportable, or "local," certifications are signatures made by a 1192 user to mark a key as valid within that user's implementation only. 1193 Thus, when an implementation prepares a user's copy of a key for 1194 transport to another user (this is the process of "exporting" the 1195 key), any local certification signatures are deleted from the key. 1197 The receiver of a transported key "imports" it, and likewise trims 1198 any local certifications. In normal operation, there won't be any, 1199 assuming the import is performed on an exported key. However, there 1200 are instances where this can reasonably happen. For example, if an 1201 implementation allows keys to be imported from a key database in 1202 addition to an exported key, then this situation can arise. 1204 Some implementations do not represent the interest of a single user 1205 (for example, a key server). Such implementations always trim local 1206 certifications from any key they handle. 1208 5.2.3.11. Revocable 1210 (1 octet of revocability, 0 for not, 1 for revocable) 1212 Signature's revocability status. Packet body contains a boolean 1213 flag indicating whether the signature is revocable. Signatures that 1214 are not revocable have any later revocation signatures ignored. 1215 They represent a commitment by the signer that he cannot revoke his 1216 signature for the life of his key. If this packet is not present, 1217 the signature is revocable. 1219 5.2.3.12. Trust signature 1221 (1 octet "level" (depth), 1 octet of trust amount) 1223 Signer asserts that the key is not only valid, but also trustworthy, 1224 at the specified level. Level 0 has the same meaning as an ordinary 1225 validity signature. Level 1 means that the signed key is asserted 1226 to be a valid trusted introducer, with the 2nd octet of the body 1227 specifying the degree of trust. Level 2 means that the signed key is 1228 asserted to be trusted to issue level 1 trust signatures, i.e. that 1229 it is a "meta introducer". Generally, a level n trust signature 1230 asserts that a key is trusted to issue level n-1 trust signatures. 1231 The trust amount is in a range from 0-255, interpreted such that 1232 values less than 120 indicate partial trust and values of 120 or 1233 greater indicate complete trust. Implementations SHOULD emit values 1234 of 60 for partial trust and 120 for complete trust. 1236 5.2.3.13. Regular expression 1238 (null-terminated regular expression) 1240 Used in conjunction with trust signature packets (of level > 0) to 1241 limit the scope of trust that is extended. Only signatures by the 1242 target key on user IDs that match the regular expression in the body 1243 of this packet have trust extended by the trust signature subpacket. 1244 The regular expression uses the same syntax as the Henry Spencer's 1245 "almost public domain" regular expression package. A description of 1246 the syntax is found in a section below. 1248 5.2.3.14. Revocation key 1250 (1 octet of class, 1 octet of algid, 20 octets of fingerprint) 1252 Authorizes the specified key to issue revocation signatures for this 1253 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1254 then this means that the revocation information is sensitive. Other 1255 bits are for future expansion to other kinds of authorizations. This 1256 is found on a self-signature. 1258 If the "sensitive" flag is set, the keyholder feels this subpacket 1259 contains private trust information that describes a real-world 1260 sensitive relationship. If this flag is set, implementations SHOULD 1261 NOT export this signature to other users except in cases where the 1262 data needs to be available: when the signature is being sent to the 1263 designated revoker, or when it is accompanied by a revocation 1264 signature from that revoker. Note that it may be appropriate to 1265 isolate this subpacket within a separate signature so that it is not 1266 combined with other subpackets that need to be exported. 1268 5.2.3.15. Notation Data 1270 (4 octets of flags, 2 octets of name length (M), 1271 2 octets of value length (N), 1272 M octets of name data, 1273 N octets of value data) 1275 This subpacket describes a "notation" on the signature that the 1276 issuer wishes to make. The notation has a name and a value, each of 1277 which are strings of octets. There may be more than one notation in 1278 a signature. Notations can be used for any extension the issuer of 1279 the signature cares to make. The "flags" field holds four octets of 1280 flags. 1282 All undefined flags MUST be zero. Defined flags are: 1284 First octet: 0x80 = human-readable. This note is text, a note 1285 from one person to another, and has no 1286 meaning to software. 1287 Other octets: none. 1289 5.2.3.16. Key server preferences 1291 (N octets of flags) 1293 This is a list of flags that indicate preferences that the key 1294 holder has about how the key is handled on a key server. All 1295 undefined flags MUST be zero. 1297 First octet: 0x80 = No-modify 1298 the key holder requests that this key only be modified or 1299 updated by the key holder or an administrator of the key server. 1301 This is found only on a self-signature. 1303 5.2.3.17. Preferred key server 1305 (String) 1307 This is a URL of a key server that the key holder prefers be used 1308 for updates. Note that keys with multiple user ids can have a 1309 preferred key server for each user id. Note also that since this is 1310 a URL, the key server can actually be a copy of the key retrieved by 1311 ftp, http, finger, etc. 1313 5.2.3.18. Primary user id 1315 (1 octet, boolean) 1317 This is a flag in a user id's self signature that states whether 1318 this user id is the main user id for this key. It is reasonable for 1319 an implementation to resolve ambiguities in preferences, etc. by 1320 referring to the primary user id. If this flag is absent, its value 1321 is zero. If more than one user id in a key is marked as primary, the 1322 implementation may resolve the ambiguity in any way it sees fit. 1324 5.2.3.19. Policy URL 1326 (String) 1328 This subpacket contains a URL of a document that describes the 1329 policy that the signature was issued under. 1331 5.2.3.20. Key Flags 1333 (Octet string) 1335 This subpacket contains a list of binary flags that hold information 1336 about a key. It is a string of octets, and an implementation MUST 1337 NOT assume a fixed size. This is so it can grow over time. If a list 1338 is shorter than an implementation expects, the unstated flags are 1339 considered to be zero. The defined flags are: 1341 First octet: 1343 0x01 - This key may be used to certify other keys. 1345 0x02 - This key may be used to sign data. 1347 0x04 - This key may be used to encrypt communications. 1349 0x08 - This key may be used to encrypt storage. 1351 0x10 - The private component of this key may have been split by 1352 a secret-sharing mechanism. 1354 0x80 - The private component of this key may be in the 1355 possession of more than one person. 1357 Usage notes: 1359 The flags in this packet may appear in self-signatures or in 1360 certification signatures. They mean different things depending on 1361 who is making the statement -- for example, a certification 1362 signature that has the "sign data" flag is stating that the 1363 certification is for that use. On the other hand, the 1364 "communications encryption" flag in a self-signature is stating a 1365 preference that a given key be used for communications. Note 1366 however, that it is a thorny issue to determine what is 1367 "communications" and what is "storage." This decision is left wholly 1368 up to the implementation; the authors of this document do not claim 1369 any special wisdom on the issue, and realize that accepted opinion 1370 may change. 1372 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1373 self-signature only; they are meaningless on a certification 1374 signature. They SHOULD be placed only on a direct-key signature 1375 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1376 the key the flag applies to. 1378 5.2.3.21. Signer's User ID 1380 This subpacket allows a keyholder to state which user id is 1381 responsible for the signing. Many keyholders use a single key for 1382 different purposes, such as business communications as well as 1383 personal communications. This subpacket allows such a keyholder to 1384 state which of their roles is making a signature. 1386 5.2.3.22. Reason for Revocation 1388 (1 octet of revocation code, N octets of reason string) 1390 This subpacket is used only in key revocation and certification 1391 revocation signatures. It describes the reason why the key or 1392 certificate was revoked. 1394 The first octet contains a machine-readable code that denotes the 1395 reason for the revocation: 1397 0x00 - No reason specified (key revocations or cert revocations) 1398 0x01 - Key is superceded (key revocations) 1399 0x02 - Key material has been compromised (key revocations) 1400 0x03 - Key is no longer used (key revocations) 1401 0x20 - User id information is no longer valid (cert revocations) 1403 Following the revocation code is a string of octets which gives 1404 information about the reason for revocation in human-readable form 1405 (UTF-8). The string may be null, that is, of zero length. The length 1406 of the subpacket is the length of the reason string plus one. 1408 5.2.4. Computing Signatures 1410 All signatures are formed by producing a hash over the signature 1411 data, and then using the resulting hash in the signature algorithm. 1413 The signature data is simple to compute for document signatures 1414 (types 0x00 and 0x01), for which the document itself is the data. 1415 For standalone signatures, this is a null string. 1417 When a signature is made over a key, the hash data starts with the 1418 octet 0x99, followed by a two-octet length of the key, and then body 1419 of the key packet. (Note that this is an old-style packet header for 1420 a key packet with two-octet length.) A subkey signature (type 0x18) 1421 then hashes the subkey, using the same format as the main key. Key 1422 revocation signatures (types 0x20 and 0x28) hash only the key being 1423 revoked. 1425 A certification signature (type 0x10 through 0x13) hashes the user 1426 id being bound to the key into the hash context after the above 1427 data. A V3 certification hashes the contents of the name packet, 1428 without any header. A V4 certification hashes the constant 0xb4 1429 (which is an old-style packet header with the length-of-length set 1430 to zero), a four-octet number giving the length of the username, and 1431 then the username data. 1433 Once the data body is hashed, then a trailer is hashed. A V3 1434 signature hashes five octets of the packet body, starting from the 1435 signature type field. This data is the signature type, followed by 1436 the four-octet signature time. A V4 signature hashes the packet body 1437 starting from its first field, the version number, through the end 1438 of the hashed subpacket data. Thus, the fields hashed are the 1439 signature version, the signature type, the public key algorithm, the 1440 hash algorithm, the hashed subpacket length, and the hashed 1441 subpacket body. 1443 V4 signatures also hash in a final trailer of six octets: the 1444 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1445 big-endian number that is the length of the hashed data from the 1446 signature packet (note that this number does not include these final 1447 six octets. 1449 After all this has been hashed, the resulting hash field is used in 1450 the signature algorithm, and placed at the end of the signature 1451 packet. 1453 5.2.4.1. Subpacket Hints 1455 An implementation SHOULD put the two mandatory subpackets, creation 1456 time and issuer, as the first subpackets in the subpacket list, 1457 simply to make it easier for the implementer to find them. 1459 It is certainly possible for a signature to contain conflicting 1460 information in subpackets. For example, a signature may contain 1461 multiple copies of a preference or multiple expiration times. In 1462 most cases, an implementation SHOULD use the last subpacket in the 1463 signature, but MAY use any conflict resolution scheme that makes 1464 more sense. Please note that we are intentionally leaving conflict 1465 resolution to the implementer; most conflicts are simply syntax 1466 errors, and the wishy-washy language here allows a receiver to be 1467 generous in what they accept, while putting pressure on a creator to 1468 be stingy in what they generate. 1470 Some apparent conflicts may actually make sense -- for example, 1471 suppose a keyholder has an V3 key and a V4 key that share the same 1472 RSA key material. Either of these keys can verify a signature 1473 created by the other, and it may be reasonable for a signature to 1474 contain an issuer subpacket for each key, as a way of explicitly 1475 tying those keys to the signature. 1477 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 1479 The Symmetric-Key Encrypted Session Key packet holds the 1480 symmetric-key encryption of a session key used to encrypt a message. 1481 Zero or more Encrypted Session Key packets and/or Symmetric-Key 1482 Encrypted Session Key packets may precede a Symmetrically Encrypted 1483 Data Packet that holds an encrypted message. The message is 1484 encrypted with a session key, and the session key is itself 1485 encrypted and stored in the Encrypted Session Key packet or the 1486 Symmetric-Key Encrypted Session Key packet. 1488 If the Symmetrically Encrypted Data Packet is preceded by one or 1489 more Symmetric-Key Encrypted Session Key packets, each specifies a 1490 passphrase that may be used to decrypt the message. This allows a 1491 message to be encrypted to a number of public keys, and also to one 1492 or more pass phrases. This packet type is new, and is not generated 1493 by PGP 2.x or PGP 5.0. 1495 The body of this packet consists of: 1497 - A one-octet version number. The only currently defined version 1498 is 4. 1500 - A one-octet number describing the symmetric algorithm used. 1502 - A string-to-key (S2K) specifier, length as defined above. 1504 - Optionally, the encrypted session key itself, which is decrypted 1505 with the string-to-key object. 1507 If the encrypted session key is not present (which can be detected 1508 on the basis of packet length and S2K specifier size), then the S2K 1509 algorithm applied to the passphrase produces the session key for 1510 decrypting the file, using the symmetric cipher algorithm from the 1511 Symmetric-Key Encrypted Session Key packet. 1513 If the encrypted session key is present, the result of applying the 1514 S2K algorithm to the passphrase is used to decrypt just that 1515 encrypted session key field, using CFB mode with an IV of all zeros. 1516 The decryption result consists of a one-octet algorithm identifier 1517 that specifies the symmetric-key encryption algorithm used to 1518 encrypt the following Symmetrically Encrypted Data Packet, followed 1519 by the session key octets themselves. 1521 Note: because an all-zero IV is used for this decryption, the S2K 1522 specifier MUST use a salt value, either a Salted S2K or an 1523 Iterated-Salted S2K. The salt value will insure that the decryption 1524 key is not repeated even if the passphrase is reused. 1526 5.4. One-Pass Signature Packets (Tag 4) 1528 The One-Pass Signature packet precedes the signed data and contains 1529 enough information to allow the receiver to begin calculating any 1530 hashes needed to verify the signature. It allows the Signature 1531 Packet to be placed at the end of the message, so that the signer 1532 can compute the entire signed message in one pass. 1534 A One-Pass Signature does not interoperate with PGP 2.6.x or 1535 earlier. 1537 The body of this packet consists of: 1539 - A one-octet version number. The current version is 3. 1541 - A one-octet signature type. Signature types are described in 1542 section 5.2.1. 1544 - A one-octet number describing the hash algorithm used. 1546 - A one-octet number describing the public key algorithm used. 1548 - An eight-octet number holding the key ID of the signing key. 1550 - A one-octet number holding a flag showing whether the signature 1551 is nested. A zero value indicates that the next packet is 1552 another One-Pass Signature packet that describes another 1553 signature to be applied to the same message data. 1555 Note that if a message contains more than one one-pass signature, 1556 then the signature packets bracket the message; that is, the first 1557 signature packet after the message corresponds to the last one-pass 1558 packet and the final signature packet corresponds to the first 1559 one-pass packet. 1561 5.5. Key Material Packet 1563 A key material packet contains all the information about a public or 1564 private key. There are four variants of this packet type, and two 1565 major versions. Consequently, this section is complex. 1567 5.5.1. Key Packet Variants 1569 5.5.1.1. Public Key Packet (Tag 6) 1571 A Public Key packet starts a series of packets that forms an OpenPGP 1572 key (sometimes called an OpenPGP certificate). 1574 5.5.1.2. Public Subkey Packet (Tag 14) 1576 A Public Subkey packet (tag 14) has exactly the same format as a 1577 Public Key packet, but denotes a subkey. One or more subkeys may be 1578 associated with a top-level key. By convention, the top-level key 1579 provides signature services, and the subkeys provide encryption 1580 services. 1582 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1583 packet. This tag was selected for reuse because no previous version 1584 of PGP ever emitted comment packets but they did properly ignore 1585 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1586 cause it to fail, providing a limited degree of backward 1587 compatibility. 1589 5.5.1.3. Secret Key Packet (Tag 5) 1591 A Secret Key packet contains all the information that is found in a 1592 Public Key packet, including the public key material, but also 1593 includes the secret key material after all the public key fields. 1595 5.5.1.4. Secret Subkey Packet (Tag 7) 1597 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1598 Key packet, and has exactly the same format. 1600 5.5.2. Public Key Packet Formats 1602 There are two versions of key-material packets. Version 3 packets 1603 were first generated by PGP 2.6. Version 2 packets are identical in 1604 format to Version 3 packets, but are generated by PGP 2.5 or before. 1605 V2 packets are deprecated and they MUST NOT be generated. 1607 PGP 5.0 introduced version 4 packets, with new fields and semantics. 1608 PGP 2.6.x will not accept key-material packets with versions 1609 greater than 3. 1611 OpenPGP implementations SHOULD create keys with version 4 format. An 1612 implementation MAY generate a V3 key to ensure interoperability with 1613 old software; note, however, that V4 keys correct some security 1614 deficiencies in V3 keys. These deficiencies are described below. An 1615 implementation MUST NOT create a V3 key with a public key algorithm 1616 other than RSA. 1618 A version 3 public key or public subkey packet contains: 1620 - A one-octet version number (3). 1622 - A four-octet number denoting the time that the key was created. 1624 - A two-octet number denoting the time in days that this key is 1625 valid. If this number is zero, then it does not expire. 1627 - A one-octet number denoting the public key algorithm of this key 1629 - A series of multi-precision integers comprising the key 1630 material: 1632 - a multiprecision integer (MPI) of RSA public modulus n; 1634 - an MPI of RSA public encryption exponent e. 1636 V3 keys SHOULD only be used for backward compatibility because of 1637 three weaknesses in them. First, it is relatively easy to construct 1638 a V3 key that has the same key ID as any other key because the key 1639 ID is simply the low 64 bits of the public modulus. Secondly, 1640 because the fingerprint of a V3 key hashes the key material, but not 1641 its length, which increases the opportunity for fingerprint 1642 collisions. Third, there are minor weaknesses in the MD5 hash 1643 algorithm that make developers prefer other algorithms. See below 1644 for a fuller discussion of key IDs and fingerprints. 1646 The version 4 format is similar to the version 3 format except for 1647 the absence of a validity period. This has been moved to the 1648 signature packet. In addition, fingerprints of version 4 keys are 1649 calculated differently from version 3 keys, as described in section 1650 "Enhanced Key Formats." 1652 A version 4 packet contains: 1654 - A one-octet version number (4). 1656 - A four-octet number denoting the time that the key was created. 1658 - A one-octet number denoting the public key algorithm of this key 1660 - A series of multi-precision integers comprising the key 1661 material. This algorithm-specific portion is: 1663 Algorithm Specific Fields for RSA public keys: 1665 - multiprecision integer (MPI) of RSA public modulus n; 1667 - MPI of RSA public encryption exponent e. 1669 Algorithm Specific Fields for DSA public keys: 1671 - MPI of DSA prime p; 1673 - MPI of DSA group order q (q is a prime divisor of p-1); 1675 - MPI of DSA group generator g; 1677 - MPI of DSA public key value y (= g**x where x is secret). 1679 Algorithm Specific Fields for Elgamal public keys: 1681 - MPI of Elgamal prime p; 1683 - MPI of Elgamal group generator g; 1685 - MPI of Elgamal public key value y (= g**x where x is 1686 secret). 1688 5.5.3. Secret Key Packet Formats 1690 The Secret Key and Secret Subkey packets contain all the data of the 1691 Public Key and Public Subkey packets, with additional 1692 algorithm-specific secret key data appended, in encrypted form. 1694 The packet contains: 1696 - A Public Key or Public Subkey packet, as described above 1698 - One octet indicating string-to-key usage conventions. 0 1699 indicates that the secret key data is not encrypted. 255 1700 indicates that a string-to-key specifier is being given. Any 1701 other value is a symmetric-key encryption algorithm specifier. 1703 - [Optional] If string-to-key usage octet was 255, a one-octet 1704 symmetric encryption algorithm. 1706 - [Optional] If string-to-key usage octet was 255, a string-to-key 1707 specifier. The length of the string-to-key specifier is implied 1708 by its type, as described above. 1710 - [Optional] If secret data is encrypted, eight-octet Initial 1711 Vector (IV). 1713 - Encrypted multi-precision integers comprising the secret key 1714 data. These algorithm-specific fields are as described below. 1716 - Two-octet checksum of the plaintext of the algorithm-specific 1717 portion (sum of all octets, mod 65536). 1719 Algorithm Specific Fields for RSA secret keys: 1721 - multiprecision integer (MPI) of RSA secret exponent d. 1723 - MPI of RSA secret prime value p. 1725 - MPI of RSA secret prime value q (p < q). 1727 - MPI of u, the multiplicative inverse of p, mod q. 1729 Algorithm Specific Fields for DSA secret keys: 1731 - MPI of DSA secret exponent x. 1733 Algorithm Specific Fields for Elgamal secret keys: 1735 - MPI of Elgamal secret exponent x. 1737 Secret MPI values can be encrypted using a passphrase. If a 1738 string-to-key specifier is given, that describes the algorithm for 1739 converting the passphrase to a key, else a simple MD5 hash of the 1740 passphrase is used. Implementations SHOULD use a string-to-key 1741 specifier; the simple hash is for backward compatibility. The cipher 1742 for encrypting the MPIs is specified in the secret key packet. 1744 Encryption/decryption of the secret data is done in CFB mode using 1745 the key created from the passphrase and the Initial Vector from the 1746 packet. A different mode is used with V3 keys (which are only RSA) 1747 than with other key formats. With V3 keys, the MPI bit count prefix 1748 (i.e., the first two octets) is not encrypted. Only the MPI 1749 non-prefix data is encrypted. Furthermore, the CFB state is 1750 resynchronized at the beginning of each new MPI value, so that the 1751 CFB block boundary is aligned with the start of the MPI data. 1753 With V4 keys, a simpler method is used. All secret MPI values are 1754 encrypted in CFB mode, including the MPI bitcount prefix. 1756 The 16-bit checksum that follows the algorithm-specific portion is 1757 the algebraic sum, mod 65536, of the plaintext of all the 1758 algorithm-specific octets (including MPI prefix and data). With V3 1759 keys, the checksum is stored in the clear. With V4 keys, the 1760 checksum is encrypted like the algorithm-specific data. This value 1761 is used to check that the passphrase was correct. 1763 5.6. Compressed Data Packet (Tag 8) 1765 The Compressed Data packet contains compressed data. Typically, this 1766 packet is found as the contents of an encrypted packet, or following 1767 a Signature or One-Pass Signature packet, and contains literal data 1768 packets. 1770 The body of this packet consists of: 1772 - One octet that gives the algorithm used to compress the packet. 1774 - The remainder of the packet is compressed data. 1776 A Compressed Data Packet's body contains an block that compresses 1777 some set of packets. See section "Packet Composition" for details on 1778 how messages are formed. 1780 ZIP-compressed packets are compressed with raw RFC1951 DEFLATE 1781 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 1782 implementation uses more bits of compression, PGP V2.6 cannot 1783 decompress it. 1785 ZLIB-compressed packets are compressed with RFC1950 ZLIB-style 1786 blocks. 1788 5.7. Symmetrically Encrypted Data Packet (Tag 9) 1790 The Symmetrically Encrypted Data packet contains data encrypted with 1791 a symmetric-key algorithm. When it has been decrypted, it will 1792 typically contain other packets (often literal data packets or 1793 compressed data packets). 1795 The body of this packet consists of: 1797 - Encrypted data, the output of the selected symmetric-key cipher 1798 operating in PGP's variant of Cipher Feedback (CFB) mode. 1800 The symmetric cipher used may be specified in an Public-Key or 1801 Symmetric-Key Encrypted Session Key packet that precedes the 1802 Symmetrically Encrypted Data Packet. In that case, the cipher 1803 algorithm octet is prefixed to the session key before it is 1804 encrypted. If no packets of these types precede the encrypted data, 1805 the IDEA algorithm is used with the session key calculated as the 1806 MD5 hash of the passphrase. 1808 The data is encrypted in CFB mode, with a CFB shift size equal to 1809 the cipher's block size. The Initial Vector (IV) is specified as 1810 all zeros. Instead of using an IV, OpenPGP prefixes a 10-octet 1811 string to the data before it is encrypted. The first eight octets 1812 are random, and the 9th and 10th octets are copies of the 7th and 1813 8th octets, respectively. After encrypting the first 10 octets, the 1814 CFB state is resynchronized if the cipher block size is 8 octets or 1815 less. The last 8 octets of ciphertext are passed through the cipher 1816 and the block boundary is reset. 1818 The repetition of 16 bits in the 80 bits of random data prefixed to 1819 the message allows the receiver to immediately check whether the 1820 session key is incorrect. 1822 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 1824 An experimental version of PGP used this packet as the Literal 1825 packet, but no released version of PGP generated Literal packets 1826 with this tag. With PGP 5.x, this packet has been re-assigned and is 1827 reserved for use as the Marker packet. 1829 The body of this packet consists of: 1831 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 1833 Such a packet MUST be ignored when received. It may be placed at 1834 the beginning of a message that uses features not available in PGP 1835 2.6.x in order to cause that version to report that newer software 1836 is necessary to process the message. 1838 5.9. Literal Data Packet (Tag 11) 1840 A Literal Data packet contains the body of a message; data that is 1841 not to be further interpreted. 1843 The body of this packet consists of: 1845 - A one-octet field that describes how the data is formatted. 1847 If it is a 'b' (0x62), then the literal packet contains binary data. 1848 If it is a 't' (0x74), then it contains text data, and thus may need 1849 line ends converted to local form, or other text-mode changes. RFC 1850 1991 also defined a value of 'l' as a 'local' mode for machine-local 1851 conversions. This use is now deprecated. 1853 - File name as a string (one-octet length, followed by file name), 1854 if the encrypted data should be saved as a file. 1856 If the special name "_CONSOLE" is used, the message is considered to 1857 be "for your eyes only". This advises that the message data is 1858 unusually sensitive, and the receiving program should process it 1859 more carefully, perhaps avoiding storing the received data to disk, 1860 for example. 1862 - A four-octet number that indicates the modification date of the 1863 file, or the creation time of the packet, or a zero that 1864 indicates the present time. 1866 - The remainder of the packet is literal data. 1868 Text data is stored with text endings (i.e. network-normal 1869 line endings). These should be converted to native line endings by 1870 the receiving software. 1872 5.10. Trust Packet (Tag 12) 1874 The Trust packet is used only within keyrings and is not normally 1875 exported. Trust packets contain data that record the user's 1876 specifications of which key holders are trustworthy introducers, 1877 along with other information that implementing software uses for 1878 trust information. 1880 Trust packets SHOULD NOT be emitted to output streams that are 1881 transferred to other users, and they SHOULD be ignored on any input 1882 other than local keyring files. 1884 5.11. User ID Packet (Tag 13) 1886 A User ID packet consists of data that is intended to represent the 1887 name and email address of the key holder. By convention, it 1888 includes an RFC822 mail name, but there are no restrictions on its 1889 content. The packet length in the header specifies the length of 1890 the user id. If it is text, it is encoded in UTF-8. 1892 6. Radix-64 Conversions 1894 As stated in the introduction, OpenPGP's underlying native 1895 representation for objects is a stream of arbitrary octets, and some 1896 systems desire these objects to be immune to damage caused by 1897 character set translation, data conversions, etc. 1899 In principle, any printable encoding scheme that met the 1900 requirements of the unsafe channel would suffice, since it would not 1901 change the underlying binary bit streams of the native OpenPGP data 1902 structures. The OpenPGP standard specifies one such printable 1903 encoding scheme to ensure interoperability. 1905 OpenPGP's Radix-64 encoding is composed of two parts: a base64 1906 encoding of the binary data, and a checksum. The base64 encoding is 1907 identical to the MIME base64 content-transfer-encoding [RFC 2231, 1908 Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to 1909 protect the raw binary data. 1911 The checksum is a 24-bit CRC converted to four characters of 1912 radix-64 encoding by the same MIME base64 transformation, preceded 1913 by an equals sign (=). The CRC is computed by using the generator 1914 0x864CFB and an initialization of 0xB704CE. The accumulation is 1915 done on the data before it is converted to radix-64, rather than on 1916 the converted data. A sample implementation of this algorithm is in 1917 the next section. 1919 The checksum with its leading equal sign MAY appear on the first 1920 line after the Base64 encoded data. 1922 Rationale for CRC-24: The size of 24 bits fits evenly into printable 1923 base64. The nonzero initialization can detect more errors than a 1924 zero initialization. 1926 6.1. An Implementation of the CRC-24 in "C" 1928 #define CRC24_INIT 0xb704ce 1929 #define CRC24_POLY 0x1864cfb 1931 typedef long crc24; 1932 crc24 crc_octets(unsigned char *octets, size_t len) 1933 { 1934 crc24 crc = CRC24_INIT; 1935 int i; 1937 while (len--) { 1938 crc ^= (*octets++) << 16; 1939 for (i = 0; i < 8; i++) { 1940 crc <<= 1; 1941 if (crc & 0x1000000) 1942 crc ^= CRC24_POLY; 1943 } 1944 } 1945 return crc & 0xffffff; 1946 } 1948 6.2. Forming ASCII Armor 1950 When OpenPGP encodes data into ASCII Armor, it puts specific headers 1951 around the data, so OpenPGP can reconstruct the data later. OpenPGP 1952 informs the user what kind of data is encoded in the ASCII armor 1953 through the use of the headers. 1955 Concatenating the following data creates ASCII Armor: 1957 - An Armor Header Line, appropriate for the type of data 1959 - Armor Headers 1961 - A blank (zero-length, or containing only whitespace) line 1963 - The ASCII-Armored data 1965 - An Armor Checksum 1967 - The Armor Tail, which depends on the Armor Header Line. 1969 An Armor Header Line consists of the appropriate header line text 1970 surrounded by five (5) dashes ('-', 0x2D) on either side of the 1971 header line text. The header line text is chosen based upon the 1972 type of data that is being encoded in Armor, and how it is being 1973 encoded. Header line texts include the following strings: 1975 BEGIN PGP MESSAGE 1976 Used for signed, encrypted, or compressed files. 1978 BEGIN PGP PUBLIC KEY BLOCK 1979 Used for armoring public keys 1981 BEGIN PGP PRIVATE KEY BLOCK 1982 Used for armoring private keys 1984 BEGIN PGP MESSAGE, PART X/Y 1985 Used for multi-part messages, where the armor is split amongst Y 1986 parts, and this is the Xth part out of Y. 1988 BEGIN PGP MESSAGE, PART X 1989 Used for multi-part messages, where this is the Xth part of an 1990 unspecified number of parts. Requires the MESSAGE-ID Armor 1991 Header to be used. 1993 BEGIN PGP SIGNATURE 1994 Used for detached signatures, OpenPGP/MIME signatures, and 1995 signatures following clearsigned messages. Note that PGP 2.x 1996 uses BEGIN PGP MESSAGE for detached signatures. 1998 The Armor Headers are pairs of strings that can give the user or the 1999 receiving OpenPGP implementation some information about how to 2000 decode or use the message. The Armor Headers are a part of the 2001 armor, not a part of the message, and hence are not protected by any 2002 signatures applied to the message. 2004 The format of an Armor Header is that of a key-value pair. A colon 2005 (':' 0x38) and a single space (0x20) separate the key and value. 2006 OpenPGP should consider improperly formatted Armor Headers to be 2007 corruption of the ASCII Armor. Unknown keys should be reported to 2008 the user, but OpenPGP should continue to process the message. 2010 Currently defined Armor Header Keys are: 2012 - "Version", that states the OpenPGP Version used to encode the 2013 message. 2015 - "Comment", a user-defined comment. 2017 - "MessageID", a 32-character string of printable characters. The 2018 string must be the same for all parts of a multi-part message 2019 that uses the "PART X" Armor Header. MessageID strings should 2020 be unique enough that the recipient of the mail can associate 2021 all the parts of a message with each other. A good checksum or 2022 cryptographic hash function is sufficient. 2024 - "Hash", a comma-separated list of hash algorithms used in this 2025 message. This is used only in clear-signed messages. 2027 - "Charset", a description of the character set that the plaintext 2028 is in. Please note that OpenPGP defines text to be in UTF-8 by 2029 default. An implementation will get best results by translating 2030 into and out of UTF-8. However, there are many instances where 2031 this is easier said than done. Also, there are communities of 2032 users who have no need for UTF-8 because they are all happy with 2033 a character set like ISO Latin-5 or a Japanese character set. In 2034 such instances, an implementation MAY override the UTF-8 default 2035 by using this header key. An implementation MAY implement this 2036 key and any translations it cares to; an implementation MAY 2037 ignore it and assume all text is UTF-8. 2039 The MessageID SHOULD NOT appear unless it is in a multi-part 2040 message. If it appears at all, it MUST be computed from the 2041 finished (encrypted, signed, etc.) message in a deterministic 2042 fashion, rather than contain a purely random value. This is to 2043 allow the legitimate recipient to determine that the MessageID 2044 cannot serve as a covert means of leaking cryptographic key 2045 information. 2047 The Armor Tail Line is composed in the same manner as the Armor 2048 Header Line, except the string "BEGIN" is replaced by the string 2049 "END." 2051 6.3. Encoding Binary in Radix-64 2053 The encoding process represents 24-bit groups of input bits as 2054 output strings of 4 encoded characters. Proceeding from left to 2055 right, a 24-bit input group is formed by concatenating three 8-bit 2056 input groups. These 24 bits are then treated as four concatenated 2057 6-bit groups, each of which is translated into a single digit in the 2058 Radix-64 alphabet. When encoding a bit stream with the Radix-64 2059 encoding, the bit stream must be presumed to be ordered with the 2060 most-significant-bit first. That is, the first bit in the stream 2061 will be the high-order bit in the first 8-bit octet, and the eighth 2062 bit will be the low-order bit in the first 8-bit octet, and so on. 2064 +--first octet--+-second octet--+--third octet--+ 2065 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 2066 +-----------+---+-------+-------+---+-----------+ 2067 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 2068 +--1.index--+--2.index--+--3.index--+--4.index--+ 2070 Each 6-bit group is used as an index into an array of 64 printable 2071 characters from the table below. The character referenced by the 2072 index is placed in the output string. 2074 Value Encoding Value Encoding Value Encoding Value Encoding 2075 0 A 17 R 34 i 51 z 2076 1 B 18 S 35 j 52 0 2077 2 C 19 T 36 k 53 1 2078 3 D 20 U 37 l 54 2 2079 4 E 21 V 38 m 55 3 2080 5 F 22 W 39 n 56 4 2081 6 G 23 X 40 o 57 5 2082 7 H 24 Y 41 p 58 6 2083 8 I 25 Z 42 q 59 7 2084 9 J 26 a 43 r 60 8 2085 10 K 27 b 44 s 61 9 2086 11 L 28 c 45 t 62 + 2087 12 M 29 d 46 u 63 / 2088 13 N 30 e 47 v 2089 14 O 31 f 48 w (pad) = 2090 15 P 32 g 49 x 2091 16 Q 33 h 50 y 2093 The encoded output stream must be represented in lines of no more 2094 than 76 characters each. 2096 Special processing is performed if fewer than 24 bits are available 2097 at the end of the data being encoded. There are three possibilities: 2099 1. The last data group has 24 bits (3 octets). No special 2100 processing is needed. 2102 2. The last data group has 16 bits (2 octets). The first two 6-bit 2103 groups are processed as above. The third (incomplete) data group 2104 has two zero-value bits added to it, and is processed as above. 2105 A pad character (=) is added to the output. 2107 3. The last data group has 8 bits (1 octet). The first 6-bit group 2108 is processed as above. The second (incomplete) data group has 2109 four zero-value bits added to it, and is processed as above. Two 2110 pad characters (=) are added to the output. 2112 6.4. Decoding Radix-64 2114 Any characters outside of the base64 alphabet are ignored in 2115 Radix-64 data. Decoding software must ignore all line breaks or 2116 other characters not found in the table above. 2118 In Radix-64 data, characters other than those in the table, line 2119 breaks, and other white space probably indicate a transmission 2120 error, about which a warning message or even a message rejection 2121 might be appropriate under some circumstances. 2123 Because it is used only for padding at the end of the data, the 2124 occurrence of any "=" characters may be taken as evidence that the 2125 end of the data has been reached (without truncation in transit). No 2126 such assurance is possible, however, when the number of octets 2127 transmitted was a multiple of three and no "=" characters are 2128 present. 2130 6.5. Examples of Radix-64 2132 Input data: 0x14fb9c03d97e 2133 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2134 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2135 11111110 2136 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 2137 111110 2138 Decimal: 5 15 46 28 0 61 37 62 2139 Output: F P u c A 9 l + 2141 Input data: 0x14fb9c03d9 2142 Hex: 1 4 f b 9 c | 0 3 d 9 2143 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2144 pad with 00 2145 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2146 Decimal: 5 15 46 28 0 61 36 2147 pad with = 2148 Output: F P u c A 9 k = 2150 Input data: 0x14fb9c03 2151 Hex: 1 4 f b 9 c | 0 3 2152 8-bit: 00010100 11111011 10011100 | 00000011 2153 pad with 0000 2154 6-bit: 000101 001111 101110 011100 | 000000 110000 2155 Decimal: 5 15 46 28 0 48 2156 pad with = = 2157 Output: F P u c A w = = 2159 6.6. Example of an ASCII Armored Message 2161 -----BEGIN PGP MESSAGE----- 2162 Version: OpenPrivacy 0.99 2164 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2165 vBSFjNSiVHsuAA== 2166 =njUN 2167 -----END PGP MESSAGE----- 2169 Note that this example is indented by two spaces. 2171 7. Cleartext signature framework 2173 It is desirable to sign a textual octet stream without ASCII 2174 armoring the stream itself, so the signed text is still readable 2175 without special software. In order to bind a signature to such a 2176 cleartext, this framework is used. (Note that RFC 2015 defines 2177 another way to clear sign messages for environments that support 2178 MIME.) 2180 The cleartext signed message consists of: 2182 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2183 single line, 2185 - One or more "Hash" Armor Headers, 2187 - Exactly one empty line not included into the message digest, 2189 - The dash-escaped cleartext that is included into the message 2190 digest, 2192 - The ASCII armored signature(s) including the '-----BEGIN PGP 2193 SIGNATURE-----' Armor Header and Armor Tail Lines. 2195 If the "Hash" armor header is given, the specified message digest 2196 algorithm is used for the signature. If there are no such headers, 2197 MD5 is used, an implementation MAY omit them for V2.x compatibility. 2198 If more than one message digest is used in the signature, the "Hash" 2199 armor header contains a comma-delimited list of used message 2200 digests. 2202 Current message digest names are described below with the algorithm 2203 IDs. 2205 7.1. Dash-Escaped Text 2207 The cleartext content of the message must also be dash-escaped. 2209 Dash escaped cleartext is the ordinary cleartext where every line 2210 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2211 (0x2D) and space ' ' (0x20). This prevents the parser from 2212 recognizing armor headers of the cleartext itself. The message 2213 digest is computed using the cleartext itself, not the dash escaped 2214 form. 2216 As with binary signatures on text documents, a cleartext signature 2217 is calculated on the text using canonical line endings. 2218 The line ending (i.e. the ) before the '-----BEGIN PGP 2219 SIGNATURE-----' line that terminates the signed text is not 2220 considered part of the signed text. 2222 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of 2223 any line is ignored when the cleartext signature is calculated. 2225 8. Regular Expressions 2227 A regular expression is zero or more branches, separated by '|'. It 2228 matches anything that matches one of the branches. 2230 A branch is zero or more pieces, concatenated. It matches a match 2231 for the first, followed by a match for the second, etc. 2233 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2234 followed by '*' matches a sequence of 0 or more matches of the atom. 2235 An atom followed by '+' matches a sequence of 1 or more matches of 2236 the atom. An atom followed by '?' matches a match of the atom, or 2237 the null string. 2239 An atom is a regular expression in parentheses (matching a match for 2240 the regular expression), a range (see below), '.' (matching any 2241 single character), '^' (matching the null string at the beginning of 2242 the input string), '$' (matching the null string at the end of the 2243 input string), a '\' followed by a single character (matching that 2244 character), or a single character with no other significance 2245 (matching that character). 2247 A range is a sequence of characters enclosed in '[]'. It normally 2248 matches any single character from the sequence. If the sequence 2249 begins with '^', it matches any single character not from the rest 2250 of the sequence. If two characters in the sequence are separated by 2251 '-', this is shorthand for the full list of ASCII characters between 2252 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2253 ']' in the sequence, make it the first character (following a 2254 possible '^'). To include a literal '-', make it the first or last 2255 character. 2257 9. Constants 2259 This section describes the constants used in OpenPGP. 2261 Note that these tables are not exhaustive lists; an implementation 2262 MAY implement an algorithm not on these lists. 2264 See the section "Notes on Algorithms" below for more discussion of 2265 the algorithms. 2267 9.1. Public Key Algorithms 2269 ID Algorithm 2270 -- --------- 2271 1 - RSA (Encrypt or Sign) 2272 2 - RSA Encrypt-Only 2273 3 - RSA Sign-Only 2274 16 - Elgamal (Encrypt-Only), see [ELGAMAL] 2275 17 - DSA (Digital Signature Standard) 2276 18 - Reserved for Elliptic Curve 2277 19 - Reserved for ECDSA 2278 20 - Elgamal (Encrypt or Sign) 2279 21 - Reserved for Diffie-Hellman (X9.42, 2280 as defined for IETF-S/MIME) 2281 100 to 110 - Private/Experimental algorithm. 2283 Implementations MUST implement DSA for signatures, and Elgamal for 2284 encryption. Implementations SHOULD implement RSA keys. 2285 Implementations MAY implement any other algorithm. 2287 9.2. Symmetric Key Algorithms 2289 ID Algorithm 2290 -- --------- 2291 0 - Plaintext or unencrypted data 2292 1 - IDEA 2293 2 - Triple-DES (DES-EDE, as per spec - 2294 168 bit key derived from 192) 2295 3 - CAST5 (128 bit key, as per RFC2144) 2296 4 - Blowfish (128 bit key, 16 rounds) 2297 5 - SAFER-SK128 (13 rounds) 2298 6 - Reserved for DES/SK 2299 100 to 110 - Private/Experimental algorithm. 2301 Implementations MUST implement Triple-DES. Implementations SHOULD 2302 implement IDEA and CAST5.Implementations MAY implement any other 2303 algorithm. 2305 9.3. Compression Algorithms 2307 ID Algorithm 2308 -- --------- 2309 0 - Uncompressed 2310 1 - ZIP (RFC1951) 2311 2 - ZLIB (RFC1950) 2312 100 to 110 - Private/Experimental algorithm. 2314 Implementations MUST implement uncompressed data. Implementations 2315 SHOULD implement ZIP. Implementations MAY implement ZLIB. 2317 9.4. Hash Algorithms 2319 ID Algorithm Text Name 2320 -- --------- ---- ---- 2321 1 - MD5 "MD5" 2322 2 - SHA-1 "SHA1" 2323 3 - RIPE-MD/160 "RIPEMD160" 2324 4 - Reserved for double-width SHA (experimental) 2325 5 - MD2 "MD2" 2326 6 - Reserved for TIGER/192 "TIGER192" 2327 7 - Reserved for HAVAL (5 pass, 160-bit) 2328 "HAVAL-5-160" 2329 100 to 110 - Private/Experimental algorithm. 2331 Implementations MUST implement SHA-1. Implementations SHOULD 2332 implement MD5. 2334 10. Packet Composition 2336 OpenPGP packets are assembled into sequences in order to create 2337 messages and to transfer keys. Not all possible packet sequences 2338 are meaningful and correct. This describes the rules for how 2339 packets should be placed into sequences. 2341 10.1. Transferable Public Keys 2343 OpenPGP users may transfer public keys. The essential elements of a 2344 transferable public key are: 2346 - One Public Key packet 2348 - Zero or more revocation signatures 2350 - One or more User ID packets 2352 - After each User ID packet, zero or more signature packets 2353 (certifications) 2355 - Zero or more Subkey packets 2357 - After each Subkey packet, one signature packet, optionally a 2358 revocation. 2360 The Public Key packet occurs first. Each of the following User ID 2361 packets provides the identity of the owner of this public key. If 2362 there are multiple User ID packets, this corresponds to multiple 2363 means of identifying the same unique individual user; for example, a 2364 user may have more than one email address, and construct a User ID 2365 for each one. 2367 Immediately following each User ID packet, there are zero or more 2368 signature packets. Each signature packet is calculated on the 2369 immediately preceding User ID packet and the initial Public Key 2370 packet. The signature serves to certify the corresponding public key 2371 and user ID. In effect, the signer is testifying to his or her 2372 belief that this public key belongs to the user identified by this 2373 user ID. 2375 After the User ID packets there may be one or more Subkey packets. 2376 In general, subkeys are provided in cases where the top-level public 2377 key is a signature-only key. However, any V4 key may have subkeys, 2378 and the subkeys may be encryption-only keys, signature-only keys, or 2379 general-purpose keys. 2381 Each Subkey packet must be followed by one Signature packet, which 2382 should be a subkey binding signature issued by the top level key. 2384 Subkey and Key packets may each be followed by a revocation 2385 Signature packet to indicate that the key is revoked. Revocation 2386 signatures are only accepted if they are issued by the key itself, 2387 or by a key that is authorized to issue revocations via a revocation 2388 key subpacket in a self-signature by the top level key. 2390 Transferable public key packet sequences may be concatenated to 2391 allow transferring multiple public keys in one operation. 2393 10.2. OpenPGP Messages 2395 An OpenPGP message is a packet or sequence of packets that 2396 corresponds to the following grammatical rules (comma represents 2397 sequential composition, and vertical bar separates alternatives): 2399 OpenPGP Message :- Encrypted Message | Signed Message | 2400 Compressed Message | Literal Message. 2402 Compressed Message :- Compressed Data Packet. 2404 Literal Message :- Literal Data Packet. 2406 ESK :- Public Key Encrypted Session Key Packet | 2407 Symmetric-Key Encrypted Session Key Packet. 2409 ESK Sequence :- ESK | ESK Sequence, ESK. 2411 Encrypted Message :- Symmetrically Encrypted Data Packet | 2412 ESK Sequence, Symmetrically Encrypted Data Packet. 2414 One-Pass Signed Message :- One-Pass Signature Packet, 2415 OpenPGP Message, Corresponding Signature Packet. 2417 Signed Message :- Signature Packet, OpenPGP Message | 2418 One-Pass Signed Message. 2420 In addition, decrypting a Symmetrically Encrypted Data packet and 2422 decompressing a Compressed Data packet must yield a valid OpenPGP 2423 Message. 2425 11. Enhanced Key Formats 2427 11.1. Key Structures 2429 The format of an OpenPGP V3 key is as follows. Entries in square 2430 brackets are optional and ellipses indicate repetition. 2432 RSA Public Key 2433 [Revocation Self Signature] 2434 User ID [Signature ...] 2435 [User ID [Signature ...] ...] 2437 Each signature certifies the RSA public key and the preceding user 2438 ID. The RSA public key can have many user IDs and each user ID can 2439 have many signatures. 2441 The format of an OpenPGP V4 key that uses two public keys is similar 2442 except that the other keys are added to the end as 'subkeys' of the 2443 primary key. 2445 Primary-Key 2446 [Revocation Self Signature] 2447 [Direct Key Self Signature...] 2448 User ID [Signature ...] 2449 [User ID [Signature ...] ...] 2450 [[Subkey [Binding-Signature-Revocation] 2451 Primary-Key-Binding-Signature] ...] 2453 A subkey always has a single signature after it that is issued using 2454 the primary key to tie the two keys together. This binding 2455 signature may be in either V3 or V4 format, but V4 is preferred, of 2456 course. 2458 In the above diagram, if the binding signature of a subkey has been 2459 revoked, the revoked binding signature may be removed, leaving only 2460 one signature. 2462 In a key that has a main key and subkeys, the primary key MUST be a 2463 key capable of signing. The subkeys may be keys of any other type. 2464 There may be other constructions of V4 keys, too. For example, there 2465 may be a single-key RSA key in V4 format, a DSA primary key with an 2466 RSA encryption key, or RSA primary key with an Elgamal subkey, etc. 2468 It is also possible to have a signature-only subkey. This permits a 2469 primary key that collects certifications (key signatures) but is 2470 used only used for certifying subkeys that are used for encryption 2471 and signatures. 2473 11.2. Key IDs and Fingerprints 2475 For a V3 key, the eight-octet key ID consists of the low 64 bits of 2476 the public modulus of the RSA key. 2478 The fingerprint of a V3 key is formed by hashing the body (but not 2479 the two-octet length) of the MPIs that form the key material (public 2480 modulus n, followed by exponent e) with MD5. 2482 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet 2483 Tag, followed by the two-octet packet length, followed by the entire 2484 Public Key packet starting with the version field. The key ID is 2485 the low order 64 bits of the fingerprint. Here are the fields of 2486 the hash material, with the example of a DSA key: 2488 a.1) 0x99 (1 octet) 2490 a.2) high order length octet of (b)-(f) (1 octet) 2492 a.3) low order length octet of (b)-(f) (1 octet) 2494 b) version number = 4 (1 octet); 2496 c) time stamp of key creation (4 octets); 2498 d) algorithm (1 octet): 17 = DSA (example); 2500 e) Algorithm specific fields. 2502 Algorithm Specific Fields for DSA keys (example): 2504 e.1) MPI of DSA prime p; 2506 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 2508 e.3) MPI of DSA group generator g; 2510 e.4) MPI of DSA public key value y (= g**x where x is secret). 2512 Note that it is possible for there to be collisions of key IDs -- 2513 two different keys with the same key ID. Note that there is a much 2514 smaller, but still non-zero probability that two different keys have 2515 the same fingerprint. 2517 Also note that if V3 and V4 format keys share the same RSA key 2518 material, they will have different key ids as well as different 2519 fingerprints. 2521 12. Notes on Algorithms 2523 12.1. Symmetric Algorithm Preferences 2525 The symmetric algorithm preference is an ordered list of algorithms 2526 that the keyholder accepts. Since it is found on a self-signature, 2527 it is possible that a keyholder may have different preferences. For 2528 example, Alice may have TripleDES only specified for 2529 "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 2530 "alice@home.org". Note that it is also possible for preferences to 2531 be in a subkey's binding signature. 2533 Since TripleDES is the MUST-implement algorithm, if it is not 2534 explicitly in the list, it is tacitly at the end. However, it is 2535 good form to place it there explicitly. Note also that if an 2536 implementation does not implement the preference, then it is 2537 implicitly a TripleDES-only implementation. 2539 An implementation MUST not use a symmetric algorithm that is not in 2540 the recipient's preference list. When encrypting to more than one 2541 recipient, the implementation finds a suitable algorithm by taking 2542 the intersection of the preferences of the recipients. Note that the 2543 MUST-implement algorithm, TripleDES, ensures that the intersection 2544 is not null. The implementation may use any mechanism to pick an 2545 algorithm in the intersection. 2547 If an implementation can decrypt a message that a keyholder doesn't 2548 have in their preferences, the implementation SHOULD decrypt the 2549 message anyway, but MUST warn the keyholder than protocol has been 2550 violated. (For example, suppose that Alice, above, has software that 2551 implements all algorithms in this specification. Nonetheless, she 2552 prefers subsets for work or home. If she is sent a message encrypted 2553 with IDEA, which is not in her preferences, the software warns her 2554 that someone sent her an IDEA-encrypted message, but it would 2555 ideally decrypt it anyway.) 2557 An implementation that is striving for backward compatibility MAY 2558 consider a V3 key with a V3 self-signature to be an implicit 2559 preference for IDEA, and no ability to do TripleDES. This is 2560 technically non-compliant, but an implementation MAY violate the 2561 above rule in this case only and use IDEA to encrypt the message, 2562 provided that the message creator is warned. Ideally, though, the 2563 implementation would follow the rule by actually generating two 2564 messages, because it is possible that the OpenPGP user's 2565 implementation does not have IDEA, and thus could not read the 2566 message. Consequently, an implementation MAY, but SHOULD NOT use 2567 IDEA in an algorithm conflict with a V3 key. 2569 12.2. Other Algorithm Preferences 2571 Other algorithm preferences work similarly to the symmetric 2572 algorithm preference, in that they specify which algorithms the 2573 keyholder accepts. There are two interesting cases that other 2574 comments need to be made about, though, the compression preferences 2575 and the hash preferences. 2577 12.2.1. Compression Preferences 2579 Compression has been an integral part of PGP since its first days. 2580 OpenPGP and all previous versions of PGP have offered compression. 2581 And in this specification, the default is for messages to be 2582 compressed, although an implementation is not required to do so. 2583 Consequently, the compression preference gives a way for a keyholder 2584 to request that messages not be compressed, presumably because they 2585 are using a minimal implementation that does not include 2586 compression. Additionally, this gives a keyholder a way to state 2587 that it can support alternate algorithms. 2589 Like the algorithm preferences, an implementation MUST NOT use an 2590 algorithm that is not in the preference vector. If the preferences 2591 are not present, then they are assumed to be [ZIP(1), 2592 UNCOMPRESSED(0)]. 2594 12.2.2. Hash Algorithm Preferences 2596 Typically, the choice of a hash algorithm is something the signer 2597 does, rather than the verifier, because a signer does not typically 2598 know who is going to be verifying the signature. This preference, 2599 though, allows a protocol based upon digital signatures ease in 2600 negotiation. 2602 Thus, if Alice is authenticating herself to Bob with a signature, it 2603 makes sense for her to use a hash algorithm that Bob's software 2604 uses. This preference allows Bob to state in his key which 2605 algorithms Alice may use. 2607 12.3. Plaintext 2609 Algorithm 0, "plaintext," may only be used to denote secret keys 2610 that are stored in the clear. Implementations must not use plaintext 2611 in Symmetrically Encrypted Data Packets; they must use Literal Data 2612 Packets to encode unencrypted or literal data. 2614 12.4. RSA 2616 There are algorithm types for RSA-signature-only, and 2617 RSA-encrypt-only keys. These types are deprecated. The "key flags" 2618 subpacket in a signature is a much better way to express the same 2619 idea, and generalizes it to all algorithms. An implementation SHOULD 2620 NOT create such a key, but MAY interpret it. 2622 An implementation SHOULD NOT implement RSA keys of size less than 2623 768 bits. 2625 It is permissible for an implementation to support RSA merely for 2626 backward compatibility; for example, such an implementation would 2627 support V3 keys with IDEA symmetric cryptography. Note that this is 2628 an exception to the other MUST-implement rules. An implementation 2629 that supports RSA in V4 keys MUST implement the MUST-implement 2630 features. 2632 12.5. Elgamal 2634 If an Elgamal key is to be used for both signing and encryption, 2635 extra care must be taken in creating the key. 2637 An ElGamal key consists of a generator g, a prime modulus p, a 2638 secret exponent x, and a public value y = g^x mod p. 2640 The generator and prime must be chosen so that solving the discrete 2641 log problem is intractable. The group g should generate the 2642 multiplicative group mod p-1 or a large subgroup of it, and the 2643 order of g should have at least one large prime factor. A good 2644 choice is to use a "strong" Sophie-Germain prime in choosing p, so 2645 that both p and (p-1)/2 are primes. 2647 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that 2648 if the generator g has only small prime factors, and if g divides 2649 the order of the group it generates, then signatures can be forged. 2650 In particular, choosing g=2 is a bad choice if the group order may 2651 be even. On the other hand, a generator of 2 is a fine choice for an 2652 encryption-only key, as this will make the encryption faster. 2654 While verifying Elgamal signatures, note that it is important to 2655 test that r and s are less than p. If this test is not done then 2656 signatures can be trivially forged by using large r values of 2657 approximately twice the length of p. This attack is also discussed 2658 in the Bleichenbacher paper. 2660 Details on safe use of Elgamal signatures may be found in [MENEZES], 2661 which discusses all the weaknesses described above. 2663 If an implementation allows Elgamal signatures, then it MUST use the 2664 algorithm identifier 20 for an Elgamal public key that can sign. 2666 An implementation SHOULD NOT implement Elgamal keys of size less 2667 than 768 bits. For long-term security, Elgamal keys should be 1024 2668 bits or longer. 2670 12.6. DSA 2672 An implementation SHOULD NOT implement DSA keys of size less than 2673 768 bits. Note that present DSA is limited to a maximum of 1024 bit 2674 keys, which are recommended for long-term use. 2676 12.7. Reserved Algorithm Numbers 2678 A number of algorithm IDs have been reserved for algorithms that 2679 would be useful to use in an OpenPGP implementation, yet there are 2680 issues that prevent an implementor from actually implementing the 2681 algorithm. These are marked in the Public Algorithms section as 2682 "(reserved for)". 2684 The reserved public key algorithms, Elliptic Curve (18), ECDSA (19), 2685 and X9.42 (21) do not have the necessary parameters, parameter 2686 order, or semantics defined. 2688 The reserved symmetric key algorithm, DES/SK (6), does not have 2689 semantics defined. 2691 The reserved hash algorithms, TIGER192 (6), and HAVAL-5-160 (7), do 2692 not have OIDs. The reserved algorithm number 4, reserved for a 2693 double-width variant of SHA1, is not presently defined. 2695 12.8. OpenPGP CFB mode 2697 OpenPGP does symmetric encryption using a variant of Cipher Feedback 2698 Mode (CFB mode). This section describes the procedure it uses in 2699 detail. This mode is what is used for Symmetrically Encrypted Data 2700 Packets; the mechanism used for encrypting secret key material is 2701 similar, but described in those sections above. 2703 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 2704 and prefixes the plaintext with ten octets of random data, such that 2705 octets 9 and 10 match octets 7 and 8. It does a CFB "resync" after 2706 encrypting those ten octets. 2708 Note that for an algorithm that has a larger block size than 64 2709 bits, the equivalent function will be done with that entire block. 2710 For example, a 16-octet block algorithm would operate on 16 octets, 2711 and then produce two octets of check, and then work on 16-octet 2712 blocks. 2714 Step by step, here is the procedure: 2716 1. The feedback register (FR) is set to the IV, which is all zeros. 2718 2. FR is encrypted to produce FRE (FR Encrypted). This is the 2719 encryption of an all-zero value. 2721 3. FRE is xored with the first 8 octets of random data prefixed to 2722 the plaintext to produce C1-C8, the first 8 octets of 2723 ciphertext. 2725 4. FR is loaded with C1-C8. 2727 5. FR is encrypted to produce FRE, the encryption of the first 8 2728 octets of ciphertext. 2730 6. The left two octets of FRE get xored with the next two octets of 2731 data that were prefixed to the plaintext. This produces C9-C10, 2732 the next two octets of ciphertext. 2734 7. (The resync step) FR is loaded with C3-C10. 2736 8. FR is encrypted to produce FRE. 2738 9. FRE is xored with the first 8 octets of the given plaintext, now 2739 that we have finished encrypting the 10 octets of prefixed data. 2740 This produces C11-C18, the next 8 octets of ciphertext. 2742 10. FR is loaded with C11-C18 2744 11. FR is encrypted to produce FRE. 2746 12. FRE is xored with the next 8 octets of plaintext, to produce the 2747 next 8 octets of ciphertext. These are loaded into FR and the 2748 process is repeated until the plaintext is used up. 2750 13. Security Considerations 2752 As with any technology involving cryptography, you should check the 2753 current literature to determine if any algorithms used here have 2754 been found to be vulnerable to attack. 2756 This specification uses Public Key Cryptography technologies. 2757 Possession of the private key portion of a public-private key pair 2758 is assumed to be controlled by the proper party or parties. 2760 Certain operations in this specification involve the use of random 2761 numbers. An appropriate entropy source should be used to generate 2762 these numbers. See RFC 1750. 2764 The MD5 hash algorithm has been found to have weaknesses 2765 (pseudo-collisions in the compress function) that make some people 2766 deprecate its use. They consider the SHA-1 algorithm better. 2768 Many security protocol designers think that it is a bad idea to use 2769 a single key for both privacy (encryption) and integrity 2770 (signatures). In fact, this was one of the motivating forces behind 2771 the V4 key format with separate signature and encryption keys. If 2772 you as an implementor promote dual-use keys, you should at least be 2773 aware of this controversy. 2775 The DSA algorithm will work with any 160-bit hash, but it is 2776 sensitive to the quality of the hash algorithm, if the hash 2777 algorithm is broken, it can leak the secret key. The Digital 2778 Signature Standard (DSS) specifies that DSA be used with SHA-1. 2779 RIPEMD-160 is considered by many cryptographers to be as strong. An 2780 implementation should take care which hash algorithms are used with 2781 DSA, as a weak hash can not only allow a signature to be forged, but 2782 could leak the secret key. These same considerations about the 2783 quality of the hash algorithm apply to Elgamal signatures. 2785 If you are building an authentication system, the recipient may 2786 specify a preferred signing algorithm. However, the signer would be 2787 foolish to use a weak algorithm simply because the recipient 2788 requests it. 2790 Some of the encryption algorithms mentioned in this document have 2791 been analyzed less than others. For example, although CAST5 is 2792 presently considered strong, it has been analyzed less than 2793 Triple-DES. Other algorithms may have other controversies 2794 surrounding them. 2796 Some technologies mentioned here may be subject to government 2797 control in some countries. 2799 14. Implementation Nits 2801 This section is a collection of comments to help an implementer, 2802 particularly with an eye to backward compatibility. Previous 2803 implementations of PGP are not OpenPGP-compliant. Often the 2804 differences are small, but small differences are frequently more 2805 vexing than large differences. Thus, this list of potential problems 2806 and gotchas for a developer who is trying to be backward-compatible. 2808 * PGP 5.x does not accept V4 signatures for anything other than 2809 key material. 2811 * PGP 5.x does not recognize the "five-octet" lengths in 2812 new-format headers or in signature subpacket lengths. 2814 * PGP 5.0 rejects an encrypted session key if the keylength 2815 differs from the S2K symmetric algorithm. This is a bug in its 2816 validation function. 2818 * PGP 5.0 does not handle multiple one-pass signature headers and 2819 trailers. Signing one will compress the one-pass signed literal 2820 and prefix a V3 signature instead of doing a nested one-pass 2821 signature. 2823 * When exporting a private key, PGP 2.x generates the header 2824 "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY 2825 BLOCK". All previous versions ignore the implied data type, and 2826 look directly at the packet data type. 2828 * In a clear-signed signature, PGP 5.0 will figure out the correct 2829 hash algorithm if there is no "Hash:" header, but it will reject 2830 a mismatch between the header and the actual algorithm used. The 2831 "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x 2832 rejects the "Hash:" header and assumes MD5. There are a number 2833 of enhanced variants of PGP 2.6.x that have been modified for 2834 SHA-1 signatures. 2836 * PGP 5.0 can read an RSA key in V4 format, but can only recognize 2837 it with a V3 keyid, and can properly use only a V3 format RSA 2838 key. 2840 * Neither PGP 5.x nor PGP 6.0 recognize Elgamal Encrypt and Sign 2841 keys. They only handle Elgamal Encrypt-only keys. 2843 * There are many ways possible for two keys to have the same key 2844 material, but different fingerprints (and thus key ids). Perhaps 2845 the most interesting is an RSA key that has been "upgraded" to 2846 V4 format, but since a V4 fingerprint is constructed by hashing 2847 the key creation time along with other things, two V4 keys 2848 created at different times, yet with the same key material will 2849 have different fingerprints. 2851 * If an implementation is using zlib to interoperate with PGP 2.x, 2852 then the "windowBits" parameter should be set to -13. 2854 15. Authors and Working Group Chair 2856 The working group can be contacted via the current chair: 2858 John W. Noerenberg, II 2859 Qualcomm, Inc 2860 6455 Lusk Blvd 2861 San Diego, CA 92131 USA 2862 Email: jwn2@qualcomm.com 2863 Tel: +1 619-658-3510 2865 The principal authors of this draft are: 2867 Jon Callas 2868 Network Associates, Inc. 2869 3965 Freedom Circle 2870 Santa Clara, CA 95054, USA 2871 Email: jon@pgp.com, jcallas@nai.com 2872 Tel: +1-408-346-5860 2874 Lutz Donnerhacke 2875 IKS GmbH 2876 Wildenbruchstr. 15 2877 07745 Jena, Germany 2878 EMail: lutz@iks-jena.de 2879 Tel: +49-3641-675642 2881 Hal Finney 2882 Network Associates, Inc. 2883 3965 Freedom Circle 2884 Santa Clara, CA 95054, USA 2885 Email: hal@pgp.com 2887 Rodney Thayer 2888 EIS Corporation 2889 Clearwater, FL 33767, USA 2890 Email: rodney@unitran.com 2892 This draft also draws on much previous work from a number of other 2893 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 2894 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph 2895 Levien, Colin Plumb, Will Price, William Stallings, Mark Weaver, and 2896 Philip R. Zimmermann. 2898 16. References 2900 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal 2901 signatures without knowing the secret key," Eurocrypt 96. Note that 2902 the version in the proceedings has an error. A revised version is 2903 available at the time of writing from 2904 2906 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved 2907 international version of PGP", 2908 ftp://ftp.iks-jena.de/mitarb/lutz/crypt/software/pgp/ 2910 [ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a Signature 2911 Scheme Based on Discrete Logarithms," IEEE Transactions on 2912 Information Theory, v. IT-31, n. 4, 1985, pp. 469-472. 2914 [ISO-10646] ISO/IEC 10646-1:1993. International Standard -- 2915 Information technology -- Universal Multiple-Octet Coded Character 2916 Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane. 2917 UTF-8 is described in Annex R, adopted but not yet published. 2918 UTF-16 is described in Annex Q, adopted but not yet published. 2920 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott Vanstone, 2921 "Handbook of Applied Cryptography," CRC Press, 1996. 2923 [RFC822] D. Crocker, "Standard for the format of ARPA Internet text 2924 messages", RFC 822, August 1982 2926 [RFC1423] D. Balenson, "Privacy Enhancement for Internet Electronic 2927 Mail: Part III: Algorithms, Modes, and Identifiers", RFC 1423, 2928 October 1993 2930 [RFC1641] Goldsmith, D., and M. Davis, "Using Unicode with MIME", 2931 RFC 1641, Taligent inc., July 1994. 2933 [RFC1750] Eastlake, Crocker, & Schiller., Randomness Recommendations 2934 for Security. December 1994. 2936 [RFC1951] Deutsch, P., DEFLATE Compressed Data Format Specification 2937 version 1.3. May 1996. 2939 [RFC1983] G. Malkin., Internet Users' Glossary. August 1996. 2941 [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP Message 2942 Exchange Formats", RFC 1991, August 1996. 2944 [RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy 2945 (PGP)", RFC 2015, October 1996. 2947 [RFC2231] Borenstein, N., and Freed, N., "Multipurpose Internet Mail 2948 Extensions (MIME) Part One: Format of Internet Message Bodies.", 2949 November 1996 2951 [RFC2119] Bradner, S., Key words for use in RFCs to Indicate 2952 Requirement Level. March 1997. 2954 [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", May 1997 2956 [RFC2279] F. Yergeau., UTF-8, a transformation format of Unicode and 2957 ISO 10646. October 1996. 2959 [RFC2313] RSA Laboratories, "PKCS #1: RSA Encryption Standard," 2960 version 1.5, November 1993 2962 17. Full Copyright Statement 2964 Copyright 1998 by The Internet Society. All Rights Reserved. 2966 This document and translations of it may be copied and furnished to 2967 others, and derivative works that comment on or otherwise explain it 2968 or assist in its implementation may be prepared, copied, published 2969 and distributed, in whole or in part, without restriction of any 2970 kind, provided that the above copyright notice and this paragraph 2971 are included on all such copies and derivative works. However, this 2972 document itself may not be modified in any way, such as by removing 2973 the copyright notice or references to the Internet Society or other 2974 Internet organizations, except as needed for the purpose of 2975 developing Internet standards in which case the procedures for 2976 copyrights defined in the Internet Standards process must be 2977 followed, or as required to translate it into languages other than 2978 English. 2980 The limited permissions granted above are perpetual and will not be 2981 revoked by the Internet Society or its successors or assigns.