idnits 2.17.1 draft-ietf-openpgp-formats-05.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 314 -- Looks like a reference, but probably isn't: '1' on line 314 -- Looks like a reference, but probably isn't: '2' on line 314 -- Looks like a reference, but probably isn't: '3' on line 315 == Missing Reference: 'ISO10646' is mentioned on line 355, but not defined == Missing Reference: 'Optional' is mentioned on line 1670, but not defined == Missing Reference: 'Binding-Signature-Revocation' is mentioned on line 2401, but not defined == Unused Reference: 'DONNERHACKE' is defined on line 2831, but no explicit reference was found in the text == Unused Reference: 'ISO-10646' is defined on line 2839, but no explicit reference was found in the text == Unused Reference: 'RFC822' is defined on line 2851, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 2854, but no explicit reference was found in the text == Unused Reference: 'RFC1641' is defined on line 2858, but no explicit reference was found in the text == Unused Reference: 'RFC1750' is defined on line 2861, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 2864, but no explicit reference was found in the text == Unused Reference: 'RFC1983' is defined on line 2867, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 2869, but no explicit reference was found in the text == Unused Reference: 'RFC2015' is defined on line 2872, but no explicit reference was found in the text == Unused Reference: 'RFC2045' is defined on line 2878, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 2882, but no explicit reference was found in the text -- Possible downref: Non-RFC (?) normative reference: ref. 'BLEICHENBACHER' -- Possible downref: Non-RFC (?) normative reference: ref. 'DONNERHACKE' -- Possible downref: Non-RFC (?) normative reference: ref. 'ELGAMAL' -- Possible downref: Non-RFC (?) normative reference: ref. 'ISO-10646' -- Possible downref: Non-RFC (?) normative reference: ref. 'MENEZES' -- Possible downref: Non-RFC (?) normative reference: ref. 'PKCS1' ** Obsolete normative reference: RFC 822 (Obsoleted by RFC 2822) ** Downref: Normative reference to an Historic RFC: RFC 1423 ** Downref: Normative reference to an Experimental RFC: RFC 1641 ** Obsolete normative reference: RFC 1750 (Obsoleted by RFC 4086) ** Downref: Normative reference to an Informational RFC: RFC 1951 ** Downref: Normative reference to an Informational RFC: RFC 1983 ** Obsolete normative reference: RFC 1991 (Obsoleted by RFC 4880) ** Obsolete normative reference: RFC 2044 (Obsoleted by RFC 2279) Summary: 17 errors (**), 0 flaws (~~), 18 warnings (==), 13 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-05.txt 4 Expires Dec 1998 Lutz Donnerhacke 5 June 1998 IN-Root-CA Individual Network e.V. 7 Hal Finney 8 Network Associates 10 Rodney Thayer 11 EIS Corporation 13 OpenPGP Message Format 14 draft-ietf-openpgp-formats-05.txt 16 Copyright 1998 by The Internet Society. All Rights Reserved. 18 Status of this Memo 20 This document is an Internet-Draft. Internet-Drafts are working 21 documents of the Internet Engineering Task Force (IETF), its areas, 22 and its working groups. Note that other groups may also distribute 23 working documents as Internet-Drafts. 25 Internet-Drafts are draft documents valid for a maximum of six 26 months and may be updated, replaced, or obsoleted by other documents 27 at any time. It is inappropriate to use Internet-Drafts as 28 reference material or to cite them other than as "work in progress." 30 To view the entire list of current Internet-Drafts, please check the 31 "1id-abstracts.txt" listing contained in the Internet-Drafts Shadow 32 Directories on ftp.is.co.za (Africa), ftp.nordu.net (Northern 33 Europe), ftp.nis.garr.it (Southern Europe), munnari.oz.au (Pacific 34 Rim), ftp.ietf.org (US East Coast), or ftp.isi.edu (US West Coast). 36 Abstract 38 This document is maintained in order to publish all necessary 39 information needed to develop interoperable applications based on 40 the OpenPGP format. It is not a step-by-step cookbook for writing an 41 application. It describes only the format and methods needed to 42 read, check, generate, and write conforming packets crossing any 43 network. It does not deal with storage and implementation questions. 44 It does, however, discuss implementation issues necessary to avoid 45 security flaws. 47 Open-PGP software uses a combination of strong public-key and 48 symmetric cryptography to provide security services for electronic 49 communications and data storage. These services include 50 confidentiality, key management, authentication, and digital 51 signatures. This document specifies the message formats used in 52 OpenPGP. 54 Table of Contents 56 Status of this Memo 1 57 Abstract 1 58 Table of Contents 2 59 1. Introduction 5 60 1.1. Terms 5 61 2. General functions 5 62 2.1. Confidentiality via Encryption 5 63 2.2. Authentication via Digital signature 6 64 2.3. Compression 7 65 2.4. Conversion to Radix-64 7 66 3. Data Element Formats 7 67 3.1. Scalar numbers 7 68 3.2. Multi-Precision Integers 7 69 3.3. Key IDs 8 70 3.4. Text 8 71 3.5. Time fields 8 72 3.6. String-to-key (S2K) specifiers 8 73 3.6.1. String-to-key (S2k) specifier types 8 74 3.6.1.1. Simple S2K 8 75 3.6.1.2. Salted S2K 9 76 3.6.1.3. Iterated and Salted S2K 9 77 3.6.2. String-to-key usage 10 78 3.6.2.1. Secret key encryption 10 79 3.6.2.2. Symmetric-key message encryption 11 80 4. Packet Syntax 11 81 4.1. Overview 11 82 4.2. Packet Headers 11 83 4.2.1. Old-Format Packet Lengths 12 84 4.2.2. New-Format Packet Lengths 12 85 4.2.2.1. One-Octet Lengths 13 86 4.2.2.2. Two-Octet Lengths 13 87 4.2.2.3. Five-Octet Lengths 13 88 4.2.2.4. Partial Body Lengths 13 89 4.2.3. Packet Length Examples 13 90 4.3. Packet Tags 14 91 5. Packet Types 14 92 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 14 93 5.2. Signature Packet (Tag 2) 16 94 5.2.1. Signature Types 16 95 5.2.2. Version 3 Signature Packet Format 18 96 5.2.3. Version 4 Signature Packet Format 20 97 5.2.3.1. Signature Subpacket Specification 20 98 5.2.3.2. Signature Subpacket Types 22 99 5.2.3.3. Signature creation time 22 100 5.2.3.4. Issuer 23 101 5.2.3.5. Key expiration time 23 102 5.2.3.6. Preferred symmetric algorithms 23 103 5.2.3.7. Preferred hash algorithms 23 104 5.2.3.8. Preferred compression algorithms 23 105 5.2.3.9. Signature expiration time 24 106 5.2.3.10.Exportable 24 107 5.2.3.11.Revocable 24 108 5.2.3.12.Trust signature 24 109 5.2.3.13.Regular expression 24 110 5.2.3.14.Revocation key 25 111 5.2.3.15.Notation Data 25 112 5.2.3.16.Key server preferences 26 113 5.2.3.17.Preferred key server 26 114 5.2.3.18.Primary user id 26 115 5.2.3.19.Policy URL 26 116 5.2.3.20.Key Flags 26 117 5.2.3.21.Signer's User ID 27 118 5.2.3.22.Reason for Revocation 27 119 5.2.4. Computing Signatures 28 120 5.2.4.1. Subpacket Hints 29 121 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 29 122 5.4. One-Pass Signature Packets (Tag 4) 30 123 5.5. Key Material Packet 31 124 5.5.1. Key Packet Variants 31 125 5.5.1.1. Public Key Packet (Tag 6) 31 126 5.5.1.2. Public Subkey Packet (Tag 14) 31 127 5.5.1.3. Secret Key Packet (Tag 5) 31 128 5.5.1.4. Secret Subkey Packet (Tag 7) 31 129 5.5.2. Public Key Packet Formats 31 130 5.5.3. Secret Key Packet Formats 33 131 5.6. Compressed Data Packet (Tag 8) 35 132 5.7. Symmetrically Encrypted Data Packet (Tag 9) 35 133 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 36 134 5.9. Literal Data Packet (Tag 11) 36 135 5.10. Trust Packet (Tag 12) 37 136 5.11. User ID Packet (Tag 13) 37 137 6. Radix-64 Conversions 37 138 6.1. An Implementation of the CRC-24 in "C" 38 139 6.2. Forming ASCII Armor 38 140 6.3. Encoding Binary in Radix-64 40 141 6.4. Decoding Radix-64 41 142 6.5. Examples of Radix-64 42 143 6.6. Example of an ASCII Armored Message 42 144 7. Cleartext signature framework 42 145 7.1. Dash-Escaped Text 43 146 8. Regular Expressions 44 147 9. Constants 44 148 9.1. Public Key Algorithms 44 149 9.2. Symmetric Key Algorithms 45 150 9.3. Compression Algorithms 45 151 9.4. Hash Algorithms 45 152 10. Packet Composition 46 153 10.1. Transferable Public Keys 46 154 10.2. OpenPGP Messages 47 155 11. Enhanced Key Formats 47 156 11.1. Key Structures 47 157 11.2. Key IDs and Fingerprints 48 158 12. Notes on Algorithms 49 159 12.1. Symmetric Algorithm Preferences 49 160 12.2. Other Algorithm Preferences 50 161 12.2.1. Compression Preferences 50 162 12.2.2. Hash Algorithm Preferences 51 163 12.3. Plaintext 51 164 12.4. RSA 51 165 12.5. Elgamal 51 166 12.6. DSA 52 167 12.7. OpenPGP CFB mode 52 168 13. Security Considerations 53 169 14. Implementation Nits 54 170 15. Authors and Working Group Chair 55 171 16. References 56 172 17. Full Copyright Statement 57 174 1. Introduction 176 This document provides information on the message-exchange packet 177 formats used by OpenPGP to provide encryption, decryption, signing, 178 and key management functions. It builds on the foundation provided 179 in RFC 1991 "PGP Message Exchange Formats." 181 1.1. Terms 183 * OpenPGP - This is a definition for security software that uses 184 PGP 5.x as a basis. 186 * PGP - Pretty Good Privacy. PGP is a family of software systems 187 developed by Philip R. Zimmermann from which OpenPGP is based. 189 * PGP 2.6.x - This version of PGP has many variants, hence the 190 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 191 cryptographic transforms. 193 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 194 the community and also in the predecessor of this document, 195 RFC1991. It has new formats and corrects a number of problems in 196 the PGP 2.6.x design. It is referred to here as PGP 5.x because 197 that software was the first release of the "PGP 3" code base. 199 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 200 Network Associates, Inc. 202 2. General functions 204 OpenPGP provides data integrity services for messages and data files 205 by using these core technologies: 207 - digital signatures 209 - encryption 211 - compression 213 - radix-64 conversion 215 In addition, OpenPGP provides key management and certificate 216 services, but many of these are beyond the scope of this document. 218 2.1. Confidentiality via Encryption 220 OpenPGP uses two encryption methods to provide confidentiality: 221 symmetric-key encryption and public key encryption. With public-key 222 encryption, the object is encrypted using a symmetric encryption 223 algorithm. Each symmetric key is used only once. A new "session 224 key" is generated as a random number for each message. Since it is 225 used only once, the session key is bound to the message and 226 transmitted with it. To protect the key, it is encrypted with the 227 receiver's public key. The sequence is as follows: 229 1. The sender creates a message. 231 2. The sending OpenPGP generates a random number to be used as a 232 session key for this message only. 234 3. The session key is encrypted using each recipient's public key. 235 These "encrypted session keys" start the message. 237 4. The sending OpenPGP encrypts the message using the session key, 238 which forms the remainder of the message. Note that the message 239 is also usually compressed. 241 5. The receiving OpenPGP decrypts the session key using the 242 recipient's private key. 244 6. The receiving OpenPGP decrypts the message using the session 245 key. If the message was compressed, it will be decompressed. 247 With symmetric-key encryption, an object may encrypted with a 248 symmetric key derived from a passphrase (or other shared secret), or 249 a two-stage mechanism similar to the public-key method described 250 above in which a session key is itself encrypted with a symmetric 251 algorithm keyed from a shared secret. 253 Both digital signature and confidentiality services may be applied 254 to the same message. First, a signature is generated for the message 255 and attached to the message. Then, the message plus signature is 256 encrypted using a symmetric session key. Finally, the session key is 257 encrypted using public-key encryption and prefixed to the encrypted 258 block. 260 2.2. Authentication via Digital signature 262 The digital signature uses a hash code or message digest algorithm, 263 and a public-key signature algorithm. The sequence is as follows: 265 1. The sender creates a message. 267 2. The sending software generates a hash code of the message. 269 3. The sending software generates a signature from the hash code 270 using the sender's private key. 272 4. The binary signature is attached to the message. 274 5. The receiving software keeps a copy of the message signature. 276 6. The receiving software generates a new hash code for the 277 received message and verifies it using the message's signature. 278 If the verification is successful, the message is accepted as 279 authentic. 281 2.3. Compression 283 OpenPGP implementations MAY compress the message after applying the 284 signature but before encryption. 286 2.4. Conversion to Radix-64 288 OpenPGP's underlying native representation for encrypted messages, 289 signature certificates, and keys is a stream of arbitrary octets. 290 Some systems only permit the use of blocks consisting of seven-bit, 291 printable text. For transporting OpenPGP's native raw binary octets 292 through channels that are not safe to raw binary data, a printable 293 encoding of these binary octets is needed. OpenPGP provides the 294 service of converting the raw 8-bit binary octet stream to a stream 295 of printable ASCII characters, called Radix-64 encoding or ASCII 296 Armor. 298 Implementations SHOULD provide Radix-64 conversions. 300 Note that many applications, particularly messaging applications, 301 will want more advanced features as described in the OpenPGP-MIME 302 document, RFC2015. An application that implements OpenPGP for 303 messaging SHOULD implement OpenPGP-MIME. 305 3. Data Element Formats 307 This section describes the data elements used by OpenPGP. 309 3.1. Scalar numbers 311 Scalar numbers are unsigned, and are always stored in big-endian 312 format. Using n[k] to refer to the kth octet being interpreted, the 313 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 314 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 315 n[3]). 317 3.2. Multi-Precision Integers 319 Multi-Precision Integers (also called MPIs) are unsigned integers 320 used to hold large integers such as the ones used in cryptographic 321 calculations. 323 An MPI consists of two pieces: a two-octet scalar that is the length 324 of the MPI in bits followed by a string of octets that contain the 325 actual integer. 327 These octets form a big-endian number; a big-endian number can be 328 made into an MPI by prefixing it with the appropriate length. 330 Examples: 332 (all numbers are in hexadecimal) 334 The string of octets [00 01 01] forms an MPI with the value 1. The 335 string [00 09 01 FF] forms an MPI with the value of 511. 337 Additional rules: 339 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 341 The length field of an MPI describes the length starting from its 342 most significant non-zero bit. Thus, the MPI [00 02 01] is not 343 formed correctly. It should be [00 01 01]. 345 3.3. Key IDs 347 A Key ID is an eight-octet scalar that identifies a key. 348 Implementations SHOULD NOT assume that Key IDs are unique. The 349 section, "Enhanced Key Formats" below describes how Key IDs are 350 formed. 352 3.4. Text 354 The default character set for text is the UTF-8 [RFC2044] encoding 355 of Unicode [ISO10646]. 357 3.5. Time fields 359 A time field is an unsigned four-octet number containing the number 360 of seconds elapsed since midnight, 1 January 1970 UTC. 362 3.6. String-to-key (S2K) specifiers 364 String-to-key (S2K) specifiers are used to convert passphrase 365 strings into symmetric-key encryption/decryption keys. They are 366 used in two places, currently: to encrypt the secret part of private 367 keys in the private keyring, and to convert passphrases to 368 encryption keys for symmetrically encrypted messages. 370 3.6.1. String-to-key (S2k) specifier types 372 There are three types of S2K specifiers currently supported, as 373 follows: 375 3.6.1.1. Simple S2K 377 This directly hashes the string to produce the key data. See below 378 for how this hashing is done. 380 Octet 0: 0x00 381 Octet 1: hash algorithm 383 Simple S2K hashes the passphrase to produce the session key. The 384 manner in which this is done depends on the size of the session key 385 (which will depend on the cipher used) and the size of the hash 386 algorithm's output. If the hash size is greater than or equal to the 387 session key size, the high-order (leftmost) octets of the hash are 388 used as the key. 390 If the hash size is less than the key size, multiple instances of 391 the hash context are created -- enough to produce the required key 392 data. These instances are preloaded with 0, 1, 2, ... octets of 393 zeros (that is to say, the first instance has no preloading, the 394 second gets preloaded with 1 octet of zero, the third is preloaded 395 with two octets of zeros, and so forth). 397 As the data is hashed, it is given independently to each hash 398 context. Since the contexts have been initialized differently, they 399 will each produce different hash output. Once the passphrase is 400 hashed, the output data from the multiple hashes is concatenated, 401 first hash leftmost, to produce the key data, with any excess octets 402 on the right discarded. 404 3.6.1.2. Salted S2K 406 This includes a "salt" value in the S2K specifier -- some arbitrary 407 data -- that gets hashed along with the passphrase string, to help 408 prevent dictionary attacks. 410 Octet 0: 0x01 411 Octet 1: hash algorithm 412 Octets 2-9: 8-octet salt value 414 Salted S2K is exactly like Simple S2K, except that the input to the 415 hash function(s) consists of the 8 octets of salt from the S2K 416 specifier, followed by the passphrase. 418 3.6.1.3. Iterated and Salted S2K 420 This includes both a salt and an octet count. The salt is combined 421 with the passphrase and the resulting value is hashed repeatedly. 422 This further increases the amount of work an attacker must do to try 423 dictionary attacks. 425 Octet 0: 0x03 426 Octet 1: hash algorithm 427 Octets 2-9: 8-octet salt value 428 Octet 10: count, a one-octet, coded value 430 The count is coded into a one-octet number using the following 431 formula: 433 #define EXPBIAS 6 434 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 436 The above formula is in C, where "Int32" is a type for a 32-bit 437 integer, and the variable "c" is the coded count, Octet 10. 439 Iterated-Salted S2K hashes the passphrase and salt data multiple 440 times. The total number of octets to be hashed is specified in the 441 encoded count in the S2K specifier. Note that the resulting count 442 value is an octet count of how many octets will be hashed, not an 443 iteration count. 445 Initially, one or more hash contexts are set up as with the other 446 S2K algorithms, depending on how many octets of key data are needed. 447 Then the salt, followed by the passphrase data is repeatedly hashed 448 until the number of octets specified by the octet count has been 449 hashed. The one exception is that if the octet count is less than 450 the size of the salt plus passphrase, the full salt plus passphrase 451 will be hashed even though that is greater than the octet count. 452 After the hashing is done the data is unloaded from the hash 453 context(s) as with the other S2K algorithms. 455 3.6.2. String-to-key usage 457 Implementations SHOULD use salted or iterated-and-salted S2K 458 specifiers, as simple S2K specifiers are more vulnerable to 459 dictionary attacks. 461 3.6.2.1. Secret key encryption 463 An S2K specifier can be stored in the secret keyring to specify how 464 to convert the passphrase to a key that unlocks the secret data. 465 Older versions of PGP just stored a cipher algorithm octet preceding 466 the secret data or a zero to indicate that the secret data was 467 unencrypted. The MD5 hash function was always used to convert the 468 passphrase to a key for the specified cipher algorithm. 470 For compatibility, when an S2K specifier is used, the special value 471 255 is stored in the position where the hash algorithm octet would 472 have been in the old data structure. This is then followed 473 immediately by a one-octet algorithm identifier, and then by the S2K 474 specifier as encoded above. 476 Therefore, preceding the secret data there will be one of these 477 possibilities: 479 0: secret data is unencrypted (no pass phrase) 480 255: followed by algorithm octet and S2K specifier 481 Cipher alg: use Simple S2K algorithm using MD5 hash 483 This last possibility, the cipher algorithm number with an implicit 484 use of MD5 and IDEA, is provided for backward compatibility; it MAY 485 be understood, but SHOULD NOT be generated, and is deprecated. 487 These are followed by an 8-octet Initial Vector for the decryption 488 of the secret values, if they are encrypted, and then the secret key 489 values themselves. 491 3.6.2.2. Symmetric-key message encryption 493 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 494 packet at the front of a message. This is used to allow S2K 495 specifiers to be used for the passphrase conversion or to create 496 messages with a mix of symmetric-key ESKs and public-key ESKs. This 497 allows a message to be decrypted either with a passphrase or a 498 public key. 500 PGP 2.X always used IDEA with Simple string-to-key conversion when 501 encrypting a message with a symmetric algorithm. This is deprecated, 502 but MAY be used for backward-compatibility. 504 4. Packet Syntax 506 This section describes the packets used by OpenPGP. 508 4.1. Overview 510 An OpenPGP message is constructed from a number of records that are 511 traditionally called packets. A packet is a chunk of data that has a 512 tag specifying its meaning. An OpenPGP message, keyring, 513 certificate, and so forth consists of a number of packets. Some of 514 those packets may contain other OpenPGP packets (for example, a 515 compressed data packet, when uncompressed, contains OpenPGP 516 packets). 518 Each packet consists of a packet header, followed by the packet 519 body. The packet header is of variable length. 521 4.2. Packet Headers 523 The first octet of the packet header is called the "Packet Tag." It 524 determines the format of the header and denotes the packet contents. 525 The remainder of the packet header is the length of the packet. 527 Note that the most significant bit is the left-most bit, called bit 528 7. A mask for this bit is 0x80 in hexadecimal. 530 +---------------+ 531 PTag |7 6 5 4 3 2 1 0| 532 +---------------+ 533 Bit 7 -- Always one 534 Bit 6 -- New packet format if set 536 PGP 2.6.x only uses old format packets. Thus, software that 537 interoperates with those versions of PGP must only use old format 538 packets. If interoperability is not an issue, either format may be 539 used. Note that old format packets have four bits of content tags, 540 and new format packets have six; some features cannot be used and 541 still be backward-compatible. 543 Old format packets contain: 545 Bits 5-2 -- content tag 546 Bits 1-0 - length-type 548 New format packets contain: 550 Bits 5-0 -- content tag 552 4.2.1. Old-Format Packet Lengths 554 The meaning of the length-type in old-format packets is: 556 0 - The packet has a one-octet length. The header is 2 octets long. 558 1 - The packet has a two-octet length. The header is 3 octets long. 560 2 - The packet has a four-octet length. The header is 5 octets long. 562 3 - The packet is of indeterminate length. The header is 1 octet 563 long, and the implementation must determine how long the packet 564 is. If the packet is in a file, this means that the packet 565 extends until the end of the file. In general, an implementation 566 SHOULD NOT use indeterminate length packets except where the end 567 of the data will be clear from the context, and even then it is 568 better to use a definite length, or a new-format header. The 569 new-format headers described below have a mechanism for 570 precisely encoding data of indeterminate length. 572 4.2.2. New-Format Packet Lengths 574 New format packets have four possible ways of encoding length: 576 1. A one-octet Body Length header encodes packet lengths of up to 577 191 octets. 579 2. A two-octet Body Length header encodes packet lengths of 192 to 580 8383 octets. 582 3. A five-octet Body Length header encodes packet lengths of up to 583 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 584 encodes a four-octet scalar number.) 586 4. When the length of the packet body is not known in advance by 587 the issuer, Partial Body Length headers encode a packet of 588 indeterminite length, effectively making it a stream. 590 4.2.2.1. One-Octet Lengths 592 A one-octet Body Length header encodes a length of from 0 to 191 593 octets. This type of length header is recognized because the one 594 octet value is less than 192. The body length is equal to: 596 bodyLen = 1st_octet; 598 4.2.2.2. Two-Octet Lengths 600 A two-octet Body Length header encodes a length of from 192 to 8383 601 octets. It is recognized because its first octet is in the range 602 192 to 223. The body length is equal to: 604 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 606 4.2.2.3. Five-Octet Lengths 608 A five-octet Body Length header consists of a single octet holding 609 the value 255, followed by a four-octet scalar. The body length is 610 equal to: 612 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 613 (4th_octet << 8) | 5th_octet 615 4.2.2.4. Partial Body Lengths 617 A Partial Body Length header is one octet long and encodes the 618 length of only part of the data packet. This length is a power of 2, 619 from 1 to 1,073,741,824 (2 to the 30th power). It is recognized by 620 its one octet value that is greater than or equal to 224, and less 621 than 255. The partial body length is equal to: 623 partialBodyLen = 1 << (1st_octet & 0x1f); 625 Each Partial Body Length header is followed by a portion of the 626 packet body data. The Partial Body Length header specifies this 627 portion's length. Another length header (of one of the three types 628 -- one octet, two-octet, or partial) follows that portion. The last 629 length header in the packet MUST NOT be a partial Body Length 630 header. Partial Body Length headers may only be used for the 631 non-final parts of the packet. 633 4.2.3. Packet Length Examples 635 A packet with length 100 may have its length encoded in one octet: 636 0x64. This is followed by 100 octets of data. 638 A packet with length 1723 may have its length coded in two octets: 639 0xC5, 0xFB. This header is followed by the 1723 octets of data. 641 A packet with length 100000 may have its length encoded in five 642 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 644 It might also be encoded in the following octet stream: 0xEF, first 645 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 646 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 647 1693 octets of data. This is just one possible encoding, and many 648 variations are possible on the size of the Partial Body Length 649 headers, as long as a regular Body Length header encodes the last 650 portion of the data. Note also that the last Body Length header can 651 be a zero-length header. 653 An implementation MAY use Partial Body Lengths for data packets, be 654 they literal, compressed, or encrypted. The first partial length 655 MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 656 used for any other packet types. 658 Please note that in all of these explanations, the total length of 659 the packet is the length of the header(s) plus the length of the 660 body. 662 4.3. Packet Tags 664 The packet tag denotes what type of packet the body holds. Note that 665 old format headers can only have tags less than 16, whereas new 666 format headers can have tags as great as 63. The defined tags (in 667 decimal) are: 669 0 -- Reserved - a packet tag must not have this value 670 1 -- Public-Key Encrypted Session Key Packet 671 2 -- Signature Packet 672 3 -- Symmetric-Key Encrypted Session Key Packet 673 4 -- One-Pass Signature Packet 674 5 -- Secret Key Packet 675 6 -- Public Key Packet 676 7 -- Secret Subkey Packet 677 8 -- Compressed Data Packet 678 9 -- Symmetrically Encrypted Data Packet 679 10 -- Marker Packet 680 11 -- Literal Data Packet 681 12 -- Trust Packet 682 13 -- User ID Packet 683 14 -- Subkey Packet 684 60 to 63 -- Private or Experimental Values 686 5. Packet Types 688 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 689 A Public-Key Encrypted Session Key packet holds the session key used 690 to encrypt a message. Zero or more Encrypted Session Key packets 691 (either Public-Key or Symmetric-Key) may precede a Symmetrically 692 Encrypted Data Packet, which holds an encrypted message. The 693 message is encrypted with the session key, and the session key is 694 itself encrypted and stored in the Encrypted Session Key packet(s). 695 The Symmetrically Encrypted Data Packet is preceded by one 696 Public-Key Encrypted Session Key packet for each OpenPGP key to 697 which the message is encrypted. The recipient of the message finds 698 a session key that is encrypted to their public key, decrypts the 699 session key, and then uses the session key to decrypt the message. 701 The body of this packet consists of: 703 - A one-octet number giving the version number of the packet type. 704 The currently defined value for packet version is 3. An 705 implementation should accept, but not generate a version of 2, 706 which is equivalent to V3 in all other respects. 708 - An eight-octet number that gives the key ID of the public key 709 that the session key is encrypted to. 711 - A one-octet number giving the public key algorithm used. 713 - A string of octets that is the encrypted session key. This 714 string takes up the remainder of the packet, and its contents 715 are dependent on the public key algorithm used. 717 Algorithm Specific Fields for RSA encryption 719 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 721 Algorithm Specific Fields for Elgamal encryption: 723 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 725 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 727 The value "m" in the above formulas is derived from the session key 728 as follows. First the session key is prefixed with a one-octet 729 algorithm identifier that specifies the symmetric encryption 730 algorithm used to encrypt the following Symmetrically Encrypted Data 731 Packet. Then a two-octet checksum is appended which is equal to the 732 sum of the preceding octets, including the algorithm identifier and 733 session key, modulo 65536. This value is then padded as described 734 in PKCS-1 block type 02 [PKCS1] to form the "m" value used in the 735 formulas above. 737 Note that when an implementation forms several PKESKs with one 738 session key, forming a message that can be decrypted by several 739 keys, the implementation MUST make new PKCS-1 padding for each key. 741 An implementation MAY accept or use a Key ID of zero as a "wild 742 card" or "speculative" Key ID. In this case, the receiving 743 implementation would try all available private keys, checking for a 744 valid decrypted session key. This format helps reduce traffic 745 analysis of messages. 747 5.2. Signature Packet (Tag 2) 749 A signature packet describes a binding between some public key and 750 some data. The most common signatures are a signature of a file or a 751 block of text, and a signature that is a certification of a user ID. 753 Two versions of signature packets are defined. Version 3 provides 754 basic signature information, while version 4 provides an expandable 755 format with subpackets that can specify more information about the 756 signature. PGP 2.6.x only accepts version 3 signatures. 758 Implementations MUST accept V3 signatures. Implementations SHOULD 759 generate V4 signatures. Implementations MAY generate a V3 signature 760 that can be verified by PGP 2.6.x. 762 Note that if an implementation is creating an encrypted and signed 763 message that is encrypted to a V3 key, it is reasonable to create a 764 V3 signature. 766 5.2.1. Signature Types 768 There are a number of possible meanings for a signature, which are 769 specified in a signature type octet in any given signature. These 770 meanings are: 772 0x00: Signature of a binary document. 773 Typically, this means the signer owns it, created it, or 774 certifies that it has not been modified. 776 0x01: Signature of a canonical text document. 777 Typically, this means the signer owns it, created it, or 778 certifies that it has not been modified. The signature is 779 calculated over the text data with its line endings converted to 780 and trailing blanks removed. 782 0x02: Standalone signature. 783 This signature is a signature of only its own subpacket 784 contents. It is calculated identically to a signature over a 785 zero-length binary document. Note that it doesn't make sense to 786 have a V3 standalone signature. 788 0x10: Generic certification of a User ID and Public Key packet. 789 The issuer of this certification does not make any particular 790 assertion as to how well the certifier has checked that the 791 owner of the key is in fact the person described by the user ID. 792 Note that all PGP "key signatures" are this type of 793 certification. 795 0x11: Persona certification of a User ID and Public Key packet. 796 The issuer of this certification has not done any verification 797 of the claim that the owner of this key is the user ID 798 specified. 800 0x12: Casual certification of a User ID and Public Key packet. 801 The issuer of this certification has done some casual 802 verification of the claim of identity. 804 0x13: Positive certification of a User ID and Public Key packet. 805 The issuer of this certification has done substantial 806 verification of the claim of identity. 808 Please note that the vagueness of these certification claims is 809 not a flaw, but a feature of the system. Because PGP places 810 final authority for validity upon the receiver of a 811 certification, it may be that one authority's casual 812 certification might be more rigorous than some other authority's 813 positive certification. These classifications allow a 814 certification authority to issue fine-grained claims. 816 0x18: Subkey Binding Signature 817 This signature is a statement by the top-level signing key 818 indicates that it owns the subkey. This signature is calculated 819 directly on the subkey itself, not on any User ID or other 820 packets. 822 0x1F: Signature directly on a key 823 This signature is calculated directly on a key. It binds the 824 information in the signature subpackets to the key, and is 825 appropriate to be used for subpackets that provide information 826 about the key, such as the revocation key subpacket. It is also 827 appropriate for statements that non-self certifiers want to make 828 about the key itself, rather than the binding between a key and 829 a name. 831 0x20: Key revocation signature 832 The signature is calculated directly on the key being revoked. 833 A revoked key is not to be used. Only revocation signatures by 834 the key being revoked, or by an authorized revocation key, 835 should be considered valid revocation signatures. 837 0x28: Subkey revocation signature 838 The signature is calculated directly on the subkey being 839 revoked. A revoked subkey is not to be used. Only revocation 840 signatures by the top-level signature key that is bound to this 841 subkey, or by an authorized revocation key, should be considered 842 valid revocation signatures. 844 0x30: Certification revocation signature 845 This signature revokes an earlier user ID certification 846 signature (signature class 0x10 through 0x13). It should be 847 issued by the same key that issued the revoked signature or an 848 authorized revocation key The signature should have a later 849 creation date than the signature it revokes. 851 0x40: Timestamp signature. 852 This signature is only meaningful for the timestamp contained in 853 it. 855 5.2.2. Version 3 Signature Packet Format 857 The body of a version 3 Signature Packet contains: 859 - One-octet version number (3). 861 - One-octet length of following hashed material. MUST be 5. 863 - One-octet signature type. 865 - Four-octet creation time. 867 - Eight-octet key ID of signer. 869 - One-octet public key algorithm. 871 - One-octet hash algorithm. 873 - Two-octet field holding left 16 bits of signed hash value. 875 - One or more multi-precision integers comprising the signature. 876 This portion is algorithm specific, as described below. 878 The data being signed is hashed, and then the signature type and 879 creation time from the signature packet are hashed (5 additional 880 octets). The resulting hash value is used in the signature 881 algorithm. The high 16 bits (first two octets) of the hash are 882 included in the signature packet to provide a quick test to reject 883 some invalid signatures. 885 Algorithm Specific Fields for RSA signatures: 887 - multiprecision integer (MPI) of RSA signature value m**d. 889 Algorithm Specific Fields for DSA signatures: 891 - MPI of DSA value r. 893 - MPI of DSA value s. 895 The signature calculation is based on a hash of the signed data, as 896 described above. The details of the calculation are different for 897 DSA signature than for RSA signatures. 899 With RSA signatures, the hash value is encoded as described in 900 PKCS-1 section 10.1.2, "Data encoding", producing an ASN.1 value of 901 type DigestInfo, and then padded using PKCS-1 block type 01 [PKCS1]. 902 This requires inserting the hash value as an octet string into an 903 ASN.1 structure. The object identifier for the type of hash being 904 used is included in the structure. The hexadecimal representations 905 for the currently defined hash algorithms are: 907 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02 909 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 911 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 913 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 915 The ASN.1 OIDs are: 917 - MD2: 1.2.840.113549.2.2 919 - MD5: 1.2.840.113549.2.5 921 - RIPEMD-160: 1.3.36.3.2.1 923 - SHA-1: 1.3.14.3.2.26 925 The full hash prefixes for these are: 927 MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 928 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 929 0x04, 0x10 931 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 932 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 933 0x04, 0x10 935 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 936 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 938 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 939 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 941 DSA signatures SHOULD use hashes with a size of 160 bits, to match 942 q, the size of the group generated by the DSA key's generator value. 943 The hash function result is treated as a 160 bit number and used 944 directly in the DSA signature algorithm. 946 5.2.3. Version 4 Signature Packet Format 948 The body of a version 4 Signature Packet contains: 950 - One-octet version number (4). 952 - One-octet signature type. 954 - One-octet public key algorithm. 956 - One-octet hash algorithm. 958 - Two-octet scalar octet count for following hashed subpacket 959 data. 961 - Hashed subpacket data. (zero or more subpackets) 963 - Two-octet scalar octet count for following unhashed subpacket 964 data. 966 - Unhashed subpacket data. (zero or more subpackets) 968 - Two-octet field holding left 16 bits of signed hash value. 970 - One or more multi-precision integers comprising the signature. 971 This portion is algorithm specific, as described above. 973 The data being signed is hashed, and then the signature data from 974 the version number through the hashed subpacket data (inclusive) is 975 hashed. The resulting hash value is what is signed. The left 16 976 bits of the hash are included in the signature packet to provide a 977 quick test to reject some invalid signatures. 979 There are two fields consisting of signature subpackets. The first 980 field is hashed with the rest of the signature data, while the 981 second is unhashed. The second set of subpackets is not 982 cryptographically protected by the signature and should include only 983 advisory information. 985 The algorithms for converting the hash function result to a 986 signature are described in a section below. 988 5.2.3.1. Signature Subpacket Specification 990 The subpacket fields consist of zero or more signature subpackets. 991 Each set of subpackets is preceded by a two-octet scalar count of 992 the length of the set of subpackets. 994 Each subpacket consists of a subpacket header and a body. The 995 header consists of: 997 - the subpacket length (1, 2, or 5 octets) 999 - the subpacket type (1 octet) 1001 and is followed by the subpacket specific data. 1003 The length includes the type octet but not this length. Its format 1004 is similar to the "new" format packet header lengths, but cannot 1005 have partial body lengths. That is: 1007 if the 1st octet < 192, then 1008 lengthOfLength = 1 1009 subpacketLen = 1st_octet 1011 if the 1st octet >= 192 and < 255, then 1012 lengthOfLength = 2 1013 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1015 if the 1st octet = 255, then 1016 lengthOfLength = 5 1017 subpacket length = [four-octet scalar starting at 2nd_octet] 1019 The value of the subpacket type octet may be: 1021 2 = signature creation time 1022 3 = signature expiration time 1023 4 = exportable 1024 5 = trust signature 1025 6 = regular expression 1026 7 = revocable 1027 9 = key expiration time 1028 10 = placeholder for backward compatibility 1029 11 = preferred symmetric algorithms 1030 12 = revocation key 1031 16 = issuer key ID 1032 20 = notation data 1033 21 = preferred hash algorithms 1034 22 = preferred compression algorithms 1035 23 = key server preferences 1036 24 = preferred key server 1037 25 = primary user id 1038 26 = policy URL 1039 27 = key flags 1040 28 = signer's user id 1041 29 = reason for revocation 1042 100 to 110 = internal or user-defined 1044 An implementation SHOULD ignore any subpacket of a type that it does 1045 not recognize. 1047 Bit 7 of the subpacket type is the "critical" bit. If set, it 1048 denotes that the subpacket is one that is critical for the evaluator 1049 of the signature to recognize. If a subpacket is encountered that 1050 is marked critical but is unknown to the evaluating software, the 1051 evaluator SHOULD consider the signature to be in error. 1053 An evaluator may "recognize" a subpacket, but not implement it. The 1054 purpose of the critical bit is to allow the signer to tell an 1055 evaluator that it would prefer a new, unknown feature to generate an 1056 error than be ignored. 1058 Implementations SHOULD implement "preferences". 1060 5.2.3.2. Signature Subpacket Types 1062 A number of subpackets are currently defined. Some subpackets apply 1063 to the signature itself and some are attributes of the key. 1064 Subpackets that are found on a self-signature are placed on a user 1065 id certification made by the key itself. Note that a key may have 1066 more than one user id, and thus may have more than one 1067 self-signature, and differing subpackets. 1069 A self-signature is a binding signature made by the key the 1070 signature refers to. There are three types of self-signatures, the 1071 certification signatures (types 0x10-0x13), the direct-key signature 1072 (type 0x1f), and the subkey binding signature (type 0x18). For 1073 certification self-signatures, each user ID may have a 1074 self-signature, and thus different subpackets in those 1075 self-signatures. For subkey binding signatures, each subkey in fact 1076 has a self-signature. Subpackets that appear in a certification 1077 self-signature apply to the username, and subpackets that appear in 1078 the subkey self-signature apply to the subkey. Lastly, subpackets on 1079 the direct key signature apply to the entire key. 1081 Implementing software should interpret a self-signature's preference 1082 subpackets as narrowly as possible. For example, suppose a key has 1083 two usernames, Alice and Bob. Suppose that Alice prefers the 1084 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If 1085 the software locates this key via Alice's name, then the preferred 1086 algorithm is CAST5, if software locates the key via Bob's name, then 1087 the preferred algorithm is IDEA. If the key is located by key id, 1088 then algorithm of the default user id of the key provides the 1089 default symmetric algorithm. 1091 A subpacket may be found either in the hashed or unhashed subpacket 1092 sections of a signature. If a subpacket is not hashed, then the 1093 information in it cannot be considered definitive because it is not 1094 part of the signature proper. 1096 5.2.3.3. Signature creation time 1098 (4 octet time field) 1099 The time the signature was made. 1101 MUST be present in the hashed area. 1103 5.2.3.4. Issuer 1105 (8 octet key ID) 1107 The OpenPGP key ID of the key issuing the signature. 1109 MUST be present in the hashed area. 1111 5.2.3.5. Key expiration time 1113 (4 octet time field) 1115 The validity period of the key. This is the number of seconds after 1116 the key creation time that the key expires. If this is not present 1117 or has a value of zero, the key never expires. This is found only on 1118 a self-signature. 1120 5.2.3.6. Preferred symmetric algorithms 1122 (sequence of one-octet values) 1124 Symmetric algorithm numbers that indicate which algorithms the key 1125 holder prefers to use. The subpacket body is an ordered list of 1126 octets with the most preferred listed first. It is assumed that only 1127 algorithms listed are supported by the recipient's software. 1128 Algorithm numbers in section 9. This is only found on a 1129 self-signature. 1131 5.2.3.7. Preferred hash algorithms 1133 (array of one-octet values) 1135 Message digest algorithm numbers that indicate which algorithms the 1136 key holder prefers to receive. Like the preferred symmetric 1137 algorithms, the list is ordered. Algorithm numbers are in section 6. 1138 This is only found on a self-signature. 1140 5.2.3.8. Preferred compression algorithms 1142 (array of one-octet values) 1144 Compression algorithm numbers that indicate which algorithms the key 1145 holder prefers to use. Like the preferred symmetric algorithms, the 1146 list is ordered. Algorithm numbers are in section 6. If this 1147 subpacket is not included, ZIP is preferred. A zero denotes that 1148 uncompressed data is preferred; the key holder's software might have 1149 no compression software in that implementation. This is only found 1150 on a self-signature. 1152 5.2.3.9. Signature expiration time 1154 (4 octet time field) 1156 The validity period of the signature. This is the number of seconds 1157 after the signature creation time that the signature expires. If 1158 this is not present or has a value of zero, it never expires. 1160 5.2.3.10. Exportable 1162 (1 octet of exportability, 0 for not, 1 for exportable) 1164 Signature's exportability status. Packet body contains a boolean 1165 flag indicating whether the signature is exportable. Signatures that 1166 are not exportable are ignored during export and import operations. 1167 If this packet is not present the signature is assumed to be 1168 exportable. 1170 5.2.3.11. Revocable 1172 (1 octet of revocability, 0 for not, 1 for revocable) 1174 Signature's revocability status. Packet body contains a boolean 1175 flag indicating whether the signature is revocable. Signatures that 1176 are not revocable have any later revocation signatures ignored. 1177 They represent a commitment by the signer that he cannot revoke his 1178 signature for the life of his key. If this packet is not present, 1179 the signature is revocable. 1181 5.2.3.12. Trust signature 1183 (1 octet "level" (depth), 1 octet of trust amount) 1185 Signer asserts that the key is not only valid, but also trustworthy, 1186 at the specified level. Level 0 has the same meaning as an ordinary 1187 validity signature. Level 1 means that the signed key is asserted 1188 to be a valid trusted introducer, with the 2nd octet of the body 1189 specifying the degree of trust. Level 2 means that the signed key is 1190 asserted to be trusted to issue level 1 trust signatures, i.e. that 1191 it is a "meta introducer". Generally, a level n trust signature 1192 asserts that a key is trusted to issue level n-1 trust signatures. 1193 The trust amount is in a range from 0-255, interpreted such that 1194 values less than 120 indicate partial trust and values of 120 or 1195 greater indicate complete trust. Implementations SHOULD emit values 1196 of 60 for partial trust and 120 for complete trust. 1198 5.2.3.13. Regular expression 1200 (null-terminated regular expression) 1201 Used in conjunction with trust signature packets (of level > 0) to 1202 limit the scope of trust that is extended. Only signatures by the 1203 target key on user IDs that match the regular expression in the body 1204 of this packet have trust extended by the trust packet. The regular 1205 expression uses the same syntax as the Henry Spencer's "almost 1206 public domain" regular expression package. A description of the 1207 syntax is found in a section below. 1209 5.2.3.14. Revocation key 1211 (1 octet of class, 1 octet of algid, 20 octets of fingerprint) 1213 Authorizes the specified key to issue revocation signatures for this 1214 key. Class octet must have bit 0x80 set, other bits are for future 1215 expansion to other kinds of signature authorizations. This is found 1216 on a self-signature. 1218 Authorizes the specified key to issue revocation signatures for this 1219 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1220 then this means that the revocation information is sensitive. Other 1221 bits are for future expansion to other kinds of authorizations. This 1222 is found on a self-signature. 1224 If the "sensitive" flag is set, the keyholder feels this subpacket 1225 contains private trust information that describes a real-world 1226 sensitive relationship. If this flag is set, implementations SHOULD 1227 NOT export this signature to other users except in cases where the 1228 data needs to be available: when the signature is being sent to the 1229 designated revoker, or when it is accompanied by a revocation 1230 signature from that revoker. Note that it may be appropriate to 1231 isolate this subpacket within a separate signature so that it is not 1232 combined with other subpackets that need to be exported. 1234 5.2.3.15. Notation Data 1236 (4 octets of flags, 2 octets of name length (M), 1237 2 octets of value length (N), 1238 M octets of name data, 1239 N octets of value data) 1241 This subpacket describes a "notation" on the signature that the 1242 issuer wishes to make. The notation has a name and a value, each of 1243 which are strings of octets. There may be more than one notation in 1244 a signature. Notations can be used for any extension the issuer of 1245 the signature cares to make. The "flags" field holds four octets of 1246 flags. 1248 All undefined flags MUST be zero. Defined flags are: 1250 First octet: 0x80 = human-readable. This note is text, a note 1251 from one person to another, and has no 1252 meaning to software. 1254 Other octets: none. 1256 5.2.3.16. Key server preferences 1258 (N octets of flags) 1260 This is a list of flags that indicate preferences that the key 1261 holder has about how the key is handled on a key server. All 1262 undefined flags MUST be zero. 1264 First octet: 0x80 = No-modify 1265 the key holder requests that this key only be modified or 1266 updated by the key holder or an administrator of the key server. 1268 This is found only on a self-signature. 1270 5.2.3.17. Preferred key server 1272 (String) 1274 This is a URL of a key server that the key holder prefers be used 1275 for updates. Note that keys with multiple user ids can have a 1276 preferred key server for each user id. Note also that since this is 1277 a URL, the key server can actually be a copy of the key retrieved by 1278 ftp, http, finger, etc. 1280 5.2.3.18. Primary user id 1282 (1 octet, boolean) 1284 This is a flag in a user id's self signature that states whether 1285 this user id is the main user id for this key. It is reasonable for 1286 an implementation to resolve ambiguities in preferences, etc. by 1287 referring to the primary user id. If this flag is absent, its value 1288 is zero. If more than one user id in a key is marked as primary, the 1289 implementation may resolve the ambiguity in any way it sees fit. 1291 5.2.3.19. Policy URL 1293 (String) 1295 This subpacket contains a URL of a document that describes the 1296 policy that the signature was issued under. 1298 5.2.3.20. Key Flags 1300 (Octet string) 1302 This subpacket contains a list of binary flags that hold information 1303 about a key. It is a string of octets, and an implementation MUST 1304 NOT assume a fixed size. This is so it can grow over time. If a list 1305 is shorter than an implementation expects, the unstated flags are 1306 considered to be zero. The defined flags are: 1308 First octet: 1310 0x01 - This key may be used to certify other keys. 1312 0x02 - This key may be used to sign data. 1314 0x04 - This key may be used to encrypt communications. 1316 0x08 - This key may be used to encrypt storage. 1318 0x10 - The private component of this key may have been split by 1319 a secret-sharing mechanism. 1321 0x80 - The private component of this key may be in the 1322 possession of more than one person. 1324 Usage notes: 1326 The flags in this packet may appear in self-signatures or in 1327 certification signatures. They mean different things depending on 1328 who is making the statement -- for example, a certification 1329 signature that has the "sign data" flag is stating that the 1330 certification is for that use. On the other hand, the 1331 "communications encryption" flag in a self-signature is stating a 1332 preference that a given key be used for communications. Note 1333 however, that it is a thorny issue to determine what is 1334 "communications" and what is "storage." This decision is left wholly 1335 up to the implementation; the authors of this document do not claim 1336 any special wisdom on the issue, and realize that accepted opinion 1337 may change. 1339 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1340 self-signature only; they are meaningless on a certification 1341 signature. They SHOULD be placed only on a direct-key signature 1342 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1343 the key the flag applies to. 1345 5.2.3.21. Signer's User ID 1347 This subpacket allows a keyholder to state which user id is 1348 responsible for the signing. Many keyholders use a single key for 1349 different purposes, such as business communications as well as 1350 personal communications. This subpacket allows such a keyholder to 1351 state which of their roles is making a signature. 1353 5.2.3.22. Reason for Revocation 1355 (1 octet of revocation code, N octets of reason string) 1356 This subpacket is used only in key revocation and certification 1357 revocation signatures. It describes the reason why the key or 1358 certificate was revoked. 1360 The first octet contains a machine-readable code that denotes the 1361 reason for the revocation: 1363 0x00 - No reason specified (key revocations or cert revocations) 1364 0x01 - Key is superceded (key revocations) 1365 0x02 - Key material has been compromised (key revocations) 1366 0x03 - Key is no longer used (key revocations) 1367 0x20 - User id information is no longer valid (cert revocations) 1369 Following the recovation code is a string of octets which gives 1370 information about the reason for revocation in human-readable form 1371 (UTF-8). The string may be null, that is, of zero length. The length 1372 of the subpacket is the length of the reason string plus one. 1374 5.2.4. Computing Signatures 1376 All signatures are formed by producing a hash over the signature 1377 data, and then using the resulting hash in the signature algorithm. 1379 The signature data is simple to compute for document signatures 1380 (types 0x00 and 0x01), for which the document itself is the data. 1381 For standalone signatures, this is a null string. 1383 When a signature is made over a key, the hash data starts with the 1384 octet 0x99, followed by a two-octet length of the key, and then body 1385 of the key packet. (Note that this is an old-style packet header for 1386 a key packet with two-octet length.) A subkey signature (type 0x18) 1387 then hashes the subkey, using the same format as the main key. Key 1388 revocation signatures (types 0x20 and 0x28) hash only the key being 1389 revoked. 1391 A certification signature (type 0x10 through 0x13) hashes the user 1392 id being bound to the key into the hash context after the above 1393 data. A V3 certification hashes the contents of the name packet, 1394 without any header. A V4 certification hashes the constant 0xb4 1395 (which is an old-style packet header with the length-of-length set 1396 to zero), a four-octet number giving the length of the username, and 1397 then the username data. 1399 Once the data body is hashed, then a trailer is hashed. A V3 1400 signature hashes five octets of the packet body, starting from the 1401 signature type field. This data is the signature type, followed by 1402 the four-octet signature time. A V4 signature hashes the packet body 1403 starting from its first field, the version number, through the end 1404 of the hashed subpacket data. Thus, the fields hashed are the 1405 signature version, the signature type, the public key algorithm, the 1406 hash algorithm, the hashed subpacket length, and the hashed 1407 subpacket body. 1409 V4 signatures also hash in a final trailer of six octets: the 1410 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1411 big-endian number that is the length of the hashed data from the 1412 signature packet (note that this number does not include these final 1413 six octets. 1415 After all this has been hashed, the resulting hash field is used in 1416 the signature algorithm, and placed at the end of the signature 1417 packet. 1419 5.2.4.1. Subpacket Hints 1421 An implementation SHOULD put the two mandatory subpackets, creation 1422 time and issuer, as the first subpackets in the subpacket list, 1423 simply to make it easier for the implementer to find them. 1425 It is certainly possible for a signature to contain conflicting 1426 information in subpackets. For example, a signature may contain 1427 multiple copies of a preference or multiple expiration times. In 1428 most cases, an implementation SHOULD use the last subpacket in the 1429 signature, but MAY use any conflict resolution scheme that makes 1430 more sense. Please note that we are intentionally leaving conflict 1431 resolution to the implementer; most conflicts are simply syntax 1432 errors, and the wishy-washy language here allows a receiver to be 1433 generous in what they accept, while putting pressure on a creator to 1434 be stingy in what they generate. 1436 Some apparent conflicts may actually make sense -- for example, 1437 suppose a keyholder has an V3 key and a V4 key that share the same 1438 RSA key material. Either of these keys can verify a signature 1439 created by the other, and it may be reasonable for a signature to 1440 contain an issuer subpacket for each key, as a way of explicitly 1441 tying those keys to the signature. 1443 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 1445 The Symmetric-Key Encrypted Session Key packet holds the 1446 symmetric-key encryption of a session key used to encrypt a message. 1447 Zero or more Encrypted Session Key packets and/or Symmetric-Key 1448 Encrypted Session Key packets may precede a Symmetrically Encrypted 1449 Data Packet that holds an encrypted message. The message is 1450 encrypted with a session key, and the session key is itself 1451 encrypted and stored in the Encrypted Session Key packet or the 1452 Symmetric-Key Encrypted Session Key packet. 1454 If the Symmetrically Encrypted Data Packet is preceded by one or 1455 more Symmetric-Key Encrypted Session Key packets, each specifies a 1456 passphrase that may be used to decrypt the message. This allows a 1457 message to be encrypted to a number of public keys, and also to one 1458 or more pass phrases. This packet type is new, and is not generated 1459 by PGP 2.x or PGP 5.0. 1461 The body of this packet consists of: 1463 - A one-octet version number. The only currently defined version 1464 is 4. 1466 - A one-octet number describing the symmetric algorithm used. 1468 - A string-to-key (S2K) specifier, length as defined above. 1470 - Optionally, the encrypted session key itself, which is decrypted 1471 with the string-to-key object. 1473 If the encrypted session key is not present (which can be detected 1474 on the basis of packet length and S2K specifier size), then the S2K 1475 algorithm applied to the passphrase produces the session key for 1476 decrypting the file, using the symmetric cipher algorithm from the 1477 Symmetric-Key Encrypted Session Key packet. 1479 If the encrypted session key is present, the result of applying the 1480 S2K algorithm to the passphrase is used to decrypt just that 1481 encrypted session key field, using CFB mode with an IV of all zeros. 1482 The decryption result consists of a one-octet algorithm identifier 1483 that specifies the symmetric-key encryption algorithm used to 1484 encrypt the following Symmetrically Encrypted Data Packet, followed 1485 by the session key octets themselves. 1487 Note: because an all-zero IV is used for this decryption, the S2K 1488 specifier MUST use a salt value, either a a Salted S2K or an 1489 Iterated-Salted S2K. The salt value will insure that the decryption 1490 key is not repeated even if the passphrase is reused. 1492 5.4. One-Pass Signature Packets (Tag 4) 1494 The One-Pass Signature packet precedes the signed data and contains 1495 enough information to allow the receiver to begin calculating any 1496 hashes needed to verify the signature. It allows the Signature 1497 Packet to be placed at the end of the message, so that the signer 1498 can compute the entire signed message in one pass. 1500 A One-Pass Signature does not interoperate with PGP 2.6.x or 1501 earlier. 1503 The body of this packet consists of: 1505 - A one-octet version number. The current version is 3. 1507 - A one-octet signature type. Signature types are described in 1508 section 5.2.3. 1510 - A one-octet number describing the hash algorithm used. 1512 - A one-octet number describing the public key algorithm used. 1514 - An eight-octet number holding the key ID of the signing key. 1516 - A one-octet number holding a flag showing whether the signature 1517 is nested. A zero value indicates that the next packet is 1518 another One-Pass Signature packet that describes another 1519 signature to be applied to the same message data. 1521 5.5. Key Material Packet 1523 A key material packet contains all the information about a public or 1524 private key. There are four variants of this packet type, and two 1525 major versions. Consequently, this section is complex. 1527 5.5.1. Key Packet Variants 1529 5.5.1.1. Public Key Packet (Tag 6) 1531 A Public Key packet starts a series of packets that forms an OpenPGP 1532 key (sometimes called an OpenPGP certificate). 1534 5.5.1.2. Public Subkey Packet (Tag 14) 1536 A Public Subkey packet (tag 14) has exactly the same format as a 1537 Public Key packet, but denotes a subkey. One or more subkeys may be 1538 associated with a top-level key. By convention, the top-level key 1539 provides signature services, and the subkeys provide encryption 1540 services. 1542 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1543 packet. This tag was selected for reuse because no previous version 1544 of PGP ever emitted comment packets but they did properly ignore 1545 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1546 cause it to fail, providing a limited degree of backward 1547 compatibility. 1549 5.5.1.3. Secret Key Packet (Tag 5) 1551 A Secret Key packet contains all the information that is found in a 1552 Public Key packet, including the public key material, but also 1553 includes the secret key material after all the public key fields. 1555 5.5.1.4. Secret Subkey Packet (Tag 7) 1557 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1558 Key packet, and has exactly the same format. 1560 5.5.2. Public Key Packet Formats 1562 There are two versions of key-material packets. Version 3 packets 1563 were first generated by PGP 2.6. Version 2 packets are identical in 1564 format to Version 3 packets, but are generated by PGP 2.5 or before. 1565 V2 packets are deprecated and they MUST NOT be generated. 1567 PGP 5.0 introduced version 4 packets, with new fields and semantics. 1568 PGP 2.6.x will not accept key-material packets with versions 1569 greater than 3. 1571 OpenPGP implementations SHOULD create keys with version 4 format. An 1572 implementation MAY generate a V3 key to ensure interoperability with 1573 old software; note, however, that V4 keys correct some security 1574 deficiencies in V3 keys. These deficiencies are described below. An 1575 implementation MUST NOT create a V3 key with a public key algorithm 1576 other than RSA. 1578 A version 3 public key or public subkey packet contains: 1580 - A one-octet version number (3). 1582 - A four-octet number denoting the time that the key was created. 1584 - A two-octet number denoting the time in days that this key is 1585 valid. If this number is zero, then it does not expire. 1587 - A one-octet number denoting the public key algorithm of this key 1589 - A series of multi-precision integers comprising the key 1590 material: 1592 - a multiprecision integer (MPI) of RSA public modulus n; 1594 - an MPI of RSA public encryption exponent e. 1596 V3 keys SHOULD only be used for backward compatibility because of 1597 three weaknesses in them. First, it is relatively easy to construct 1598 a V3 key that has the same key ID as any other key because the key 1599 ID is simply the low 64 bits of the public modulus. Secondly, 1600 because the fingerprint of a V3 key hashes the key material, but not 1601 its length, which increases the opportunity for fingerprint 1602 collisions. Third, there are minor weaknesses in the MD5 hash 1603 algorithm that make developers prefer other algorithms. See below 1604 for a fuller discussion of key IDs and fingerprints. 1606 The version 4 format is similar to the version 3 format except for 1607 the absence of a validity period. This has been moved to the 1608 signature packet. In addition, fingerprints of version 4 keys are 1609 calculated differently from version 3 keys, as described in section 1610 "Enhanced Key Formats." 1612 A version 4 packet contains: 1614 - A one-octet version number (4). 1616 - A four-octet number denoting the time that the key was created. 1618 - A one-octet number denoting the public key algorithm of this key 1620 - A series of multi-precision integers comprising the key 1621 material. This algorithm-specific portion is: 1623 Algorithm Specific Fields for RSA public keys: 1625 - multiprecision integer (MPI) of RSA public modulus n; 1627 - MPI of RSA public encryption exponent e. 1629 Algorithm Specific Fields for DSA public keys: 1631 - MPI of DSA prime p; 1633 - MPI of DSA group order q (q is a prime divisor of p-1); 1635 - MPI of DSA group generator g; 1637 - MPI of DSA public key value y (= g**x where x is secret). 1639 Algorithm Specific Fields for Elgamal public keys: 1641 - MPI of Elgamal prime p; 1643 - MPI of Elgamal group generator g; 1645 - MPI of Elgamal public key value y (= g**x where x is 1646 secret). 1648 5.5.3. Secret Key Packet Formats 1650 The Secret Key and Secret Subkey packets contain all the data of the 1651 Public Key and Public Subkey packets, with additional 1652 algorithm-specific secret key data appended, in encrypted form. 1654 The packet contains: 1656 - A Public Key or Public Subkey packet, as described above 1658 - One octet indicating string-to-key usage conventions. 0 1659 indicates that the secret key data is not encrypted. 255 1660 indicates that a string-to-key specifier is being given. Any 1661 other value is a symmetric-key encryption algorithm specifier. 1663 - [Optional] If string-to-key usage octet was 255, a one-octet 1664 symmetric encryption algorithm. 1666 - [Optional] If string-to-key usage octet was 255, a string-to-key 1667 specifier. The length of the string-to-key specifier is implied 1668 by its type, as described above. 1670 - [Optional] If secret data is encrypted, eight-octet Initial 1671 Vector (IV). 1673 - Encrypted multi-precision integers comprising the secret key 1674 data. These algorithm-specific fields are as described below. 1676 - Two-octet checksum of the plaintext of the algorithm-specific 1677 portion (sum of all octets, mod 65536). 1679 Algorithm Specific Fields for RSA secret keys: 1681 - multiprecision integer (MPI) of RSA secret exponent d. 1683 - MPI of RSA secret prime value p. 1685 - MPI of RSA secret prime value q (p < q). 1687 - MPI of u, the multiplicative inverse of p, mod q. 1689 Algorithm Specific Fields for DSA secret keys: 1691 - MPI of DSA secret exponent x. 1693 Algorithm Specific Fields for Elgamal secret keys: 1695 - MPI of Elgamal secret exponent x. 1697 Secret MPI values can be encrypted using a passphrase. If a 1698 string-to-key specifier is given, that describes the algorithm for 1699 converting the passphrase to a key, else a simple MD5 hash of the 1700 passphrase is used. Implementations SHOULD use a string-to-key 1701 specifier; the simple hash is for backward compatibility. The cipher 1702 for encrypting the MPIs is specified in the secret key packet. 1704 Encryption/decryption of the secret data is done in CFB mode using 1705 the key created from the passphrase and the Initial Vector from the 1706 packet. A different mode is used with V3 keys (which are only RSA) 1707 than with other key formats. With V3 keys, the MPI bit count prefix 1708 (i.e., the first two octets) is not encrypted. Only the MPI 1709 non-prefix data is encrypted. Furthermore, the CFB state is 1710 resynchronized at the beginning of each new MPI value, so that the 1711 CFB block boundary is aligned with the start of the MPI data. 1713 With V4 keys, a simpler method is used. All secret MPI values are 1714 encrypted in CFB mode, including the MPI bitcount prefix. 1716 The 16-bit checksum that follows the algorithm-specific portion is 1717 the algebraic sum, mod 65536, of the plaintext of all the 1718 algorithm-specific octets (including MPI prefix and data). With V3 1719 keys, the checksum is stored in the clear. With V4 keys, the 1720 checksum is encrypted like the algorithm-specific data. This value 1721 is used to check that the passphrase was correct. 1723 5.6. Compressed Data Packet (Tag 8) 1725 The Compressed Data packet contains compressed data. Typically, this 1726 packet is found as the contents of an encrypted packet, or following 1727 a Signature or One-Pass Signature packet, and contains literal data 1728 packets. 1730 The body of this packet consists of: 1732 - One octet that gives the algorithm used to compress the packet. 1734 - The remainder of the packet is compressed data. 1736 A Compressed Data Packet's body contains an block that compresses 1737 some set of packets. See section "Packet Composition" for details on 1738 how messages are formed. 1740 ZIP-compressed packets are compressed with raw RFC1951 DEFLATE 1741 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 1742 implementation uses more bits of compression, PGP V2.6 cannot 1743 decompress it. 1745 ZLIB-compressed packets are compressed with RFC1950 ZLIB-style 1746 blocks. 1748 5.7. Symmetrically Encrypted Data Packet (Tag 9) 1750 The Symmetrically Encrypted Data packet contains data encrypted with 1751 a symmetric-key algorithm. When it has been decrypted, it will 1752 typically contain other packets (often literal data packets or 1753 compressed data packets). 1755 The body of this packet consists of: 1757 - Encrypted data, the output of the selected symmetric-key cipher 1758 operating in PGP's variant of Cipher Feedback (CFB) mode. 1760 The symmetric cipher used may be specified in an Public-Key or 1761 Symmetric-Key Encrypted Session Key packet that precedes the 1762 Symmetrically Encrypted Data Packet. In that case, the cipher 1763 algorithm octet is prefixed to the session key before it is 1764 encrypted. If no packets of these types precede the encrypted data, 1765 the IDEA algorithm is used with the session key calculated as the 1766 MD5 hash of the passphrase. 1768 The data is encrypted in CFB mode, with a CFB shift size equal to 1769 the cipher's block size. The Initial Vector (IV) is specified as 1770 all zeros. Instead of using an IV, OpenPGP prefixes a 10-octet 1771 string to the data before it is encrypted. The first eight octets 1772 are random, and the 9th and 10th octets are copies of the 7th and 1773 8th octets, respectively. After encrypting the first 10 octets, the 1774 CFB state is resynchronized if the cipher block size is 8 octets or 1775 less. The last 8 octets of ciphertext are passed through the cipher 1776 and the block boundary is reset. 1778 The repetition of 16 bits in the 80 bits of random data prefixed to 1779 the message allows the receiver to immediately check whether the 1780 session key is incorrect. 1782 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 1784 An experimental version of PGP used this packet as the Literal 1785 packet, but no released version of PGP generated Literal packets 1786 with this tag. With PGP 5.x, this packet has been re-assigned and is 1787 reserved for use as the Marker packet. 1789 The body of this packet consists of: 1791 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 1793 Such a packet MUST be ignored when received. It may be placed at 1794 the beginning of a message that uses features not available in PGP 1795 2.6.x in order to cause that version to report that newer software 1796 is necessary to process the message. 1798 5.9. Literal Data Packet (Tag 11) 1800 A Literal Data packet contains the body of a message; data that is 1801 not to be further interpreted. 1803 The body of this packet consists of: 1805 - A one-octet field that describes how the data is formatted. 1807 If it is a 'b' (0x62), then the literal packet contains binary data. 1808 If it is a 't' (0x74), then it contains text data, and thus may need 1809 line ends converted to local form, or other text-mode changes. RFC 1810 1991 also defined a value of 'l' as a 'local' mode for machine-local 1811 conversions. This use is now deprecated. 1813 - File name as a string (one-octet length, followed by file name), 1814 if the encrypted data should be saved as a file. 1816 If the special name "_CONSOLE" is used, the message is considered to 1817 be "for your eyes only". This advises that the message data is 1818 unusually sensitive, and the receiving program should process it 1819 more carefully, perhaps avoiding storing the received data to disk, 1820 for example. 1822 - A four-octet number that indicates the modification date of the 1823 file, or the creation time of the packet, or a zero that 1824 indicates the present time. 1826 - The remainder of the packet is literal data. 1828 Text data is stored with text endings (i.e. network-normal 1829 line endings). These should be converted to native line endings by 1830 the receiving software. 1832 5.10. Trust Packet (Tag 12) 1834 The Trust packet is used only within keyrings and is not normally 1835 exported. Trust packets contain data that record the user's 1836 specifications of which key holders are trustworthy introducers, 1837 along with other information that implementing software uses for 1838 trust information. 1840 Trust packets SHOULD NOT be emitted to output streams that are 1841 transferred to other users, and they SHOULD be ignored on any input 1842 other than local keyring files. 1844 5.11. User ID Packet (Tag 13) 1846 A User ID packet consists of data that is intended to represent the 1847 name and email address of the key holder. By convention, it 1848 includes an RFC822 mail name, but there are no restrictions on its 1849 content. The packet length in the header specifies the length of 1850 the user id. If it is text, it is encoded in UTF-8. 1852 6. Radix-64 Conversions 1854 As stated in the introduction, OpenPGP's underlying native 1855 representation for objects is a stream of arbitrary octets, and some 1856 systems desire these objects to be immune to damage caused by 1857 character set translation, data conversions, etc. 1859 In principle, any printable encoding scheme that met the 1860 requirements of the unsafe channel would suffice, since it would not 1861 change the underlying binary bit streams of the native OpenPGP data 1862 structures. The OpenPGP standard specifies one such printable 1863 encoding scheme to ensure interoperability. 1865 OpenPGP's Radix-64 encoding is composed of two parts: a base64 1866 encoding of the binary data, and a checksum. The base64 encoding is 1867 identical to the MIME base64 content-transfer-encoding [RFC 2045, 1868 Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to 1869 protect the raw binary data. 1871 The checksum is a 24-bit CRC converted to four characters of 1872 radix-64 encoding by the same MIME base64 transformation, preceded 1873 by an equals sign (=). The CRC is computed by using the generator 1874 0x864CFB and an initialization of 0xB704CE. The accumulation is 1875 done on the data before it is converted to radix-64, rather than on 1876 the converted data. A sample implementation of this algorithm is in 1877 the next section. 1879 The checksum with its leading equal sign MAY appear on the first 1880 line after the Base64 encoded data. 1882 Rationale for CRC-24: The size of 24 bits fits evenly into printable 1883 base64. The nonzero initialization can detect more errors than a 1884 zero initialization. 1886 6.1. An Implementation of the CRC-24 in "C" 1888 #define CRC24_INIT 0xb704ce 1889 #define CRC24_POLY 0x1864cfb 1891 typedef long crc24; 1892 crc24 crc_octets(unsigned char *octets, size_t len) 1893 { 1894 crc24 crc = CRC24_INIT; 1895 int i; 1897 while (len--) { 1898 crc ^= *octets++; 1899 for (i = 0; i < 8; i++) { 1900 crc <<= 1; 1901 if (crc & 0x1000000) 1902 crc ^= CRC24_POLY; 1903 } 1904 } 1905 return crc; 1906 } 1908 6.2. Forming ASCII Armor 1910 When OpenPGP encodes data into ASCII Armor, it puts specific headers 1911 around the data, so OpenPGP can reconstruct the data later. OpenPGP 1912 informs the user what kind of data is encoded in the ASCII armor 1913 through the use of the headers. 1915 Concatenating the following data creates ASCII Armor: 1917 - An Armor Header Line, appropriate for the type of data 1919 - Armor Headers 1920 - A blank (zero-length, or containing only whitespace) line 1922 - The ASCII-Armored data 1924 - An Armor Checksum 1926 - The Armor Tail, which depends on the Armor Header Line. 1928 An Armor Header Line consists of the appropriate header line text 1929 surrounded by five (5) dashes ('-', 0x2D) on either side of the 1930 header line text. The header line text is chosen based upon the 1931 type of data that is being encoded in Armor, and how it is being 1932 encoded. Header line texts include the following strings: 1934 BEGIN PGP MESSAGE 1935 Used for signed, encrypted, or compressed files 1937 BEGIN PGP PUBLIC KEY BLOCK 1938 Used for armoring public keys 1940 BEGIN PGP PRIVATE KEY BLOCK 1941 Used for armoring private keys 1943 BEGIN PGP MESSAGE, PART X/Y 1944 Used for multi-part messages, where the armor is split amongst Y 1945 parts, and this is the Xth part out of Y. 1947 BEGIN PGP MESSAGE, PART X 1948 Used for multi-part messages, where this is the Xth part of an 1949 unspecified number of parts. Requires the MESSAGE-ID Armor 1950 Header to be used. 1952 BEGIN PGP SIGNATURE 1953 Used for detached signatures, OpenPGP/MIME signatures, and 1954 signatures following clearsigned messages 1956 The Armor Headers are pairs of strings that can give the user or the 1957 receiving OpenPGP implementation some information about how to 1958 decode or use the message. The Armor Headers are a part of the 1959 armor, not a part of the message, and hence are not protected by any 1960 signatures applied to the message. 1962 The format of an Armor Header is that of a key-value pair. A colon 1963 (':' 0x38) and a single space (0x20) separate the key and value. 1964 OpenPGP should consider improperly formatted Armor Headers to be 1965 corruption of the ASCII Armor. Unknown keys should be reported to 1966 the user, but OpenPGP should continue to process the message. 1968 Currently defined Armor Header Keys are: 1970 - "Version", that states the OpenPGP Version used to encode the 1971 message. 1973 - "Comment", a user-defined comment. 1975 - "MessageID", a 32-character string of printable characters. The 1976 string must be the same for all parts of a multi-part message 1977 that uses the "PART X" Armor Header. MessageID strings should 1978 be unique enough that the recipient of the mail can associate 1979 all the parts of a message with each other. A good checksum or 1980 cryptographic hash function is sufficient. 1982 - "Hash", a comma-separated list of hash algorithms used in this 1983 message. This is used only in clear-signed messages. 1985 - "Charset", a description of the character set that the plantext 1986 is in. Please note that OpenPGP defines text to be in UTF-8, so 1987 this Armor Header Key is only useful for backwards 1988 compatibility. An implementation MAY implement it; an 1989 implementation MAY ignore it. 1991 The MessageID SHOULD NOT appear unless it is in a multi-part 1992 message. If it appears at all, it MUST be computed from the 1993 finished (encrypted, signed, etc.) message in a deterministic 1994 fashion, rather than contain a purely random value. This is to 1995 allow the legitimate recipient to determine that the MessageID 1996 cannot serve as a covert means of leaking cryptographic key 1997 information. 1999 The Armor Tail Line is composed in the same manner as the Armor 2000 Header Line, except the string "BEGIN" is replaced by the string 2001 "END." 2003 6.3. Encoding Binary in Radix-64 2005 The encoding process represents 24-bit groups of input bits as 2006 output strings of 4 encoded characters. Proceeding from left to 2007 right, a 24-bit input group is formed by concatenating three 8-bit 2008 input groups. These 24 bits are then treated as four concatenated 2009 6-bit groups, each of which is translated into a single digit in the 2010 Radix-64 alphabet. When encoding a bit stream with the Radix-64 2011 encoding, the bit stream must be presumed to be ordered with the 2012 most-significant-bit first. That is, the first bit in the stream 2013 will be the high-order bit in the first 8-bit octet, and the eighth 2014 bit will be the low-order bit in the first 8-bit octet, and so on. 2016 +--first octet--+-second octet--+--third octet--+ 2017 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 2018 +-----------+---+-------+-------+---+-----------+ 2019 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 2020 +--1.index--+--2.index--+--3.index--+--4.index--+ 2022 Each 6-bit group is used as an index into an array of 64 printable 2023 characters from the table below. The character referenced by the 2024 index is placed in the output string. 2026 Value Encoding Value Encoding Value Encoding Value Encoding 2027 0 A 17 R 34 i 51 z 2028 1 B 18 S 35 j 52 0 2029 2 C 19 T 36 k 53 1 2030 3 D 20 U 37 l 54 2 2031 4 E 21 V 38 m 55 3 2032 5 F 22 W 39 n 56 4 2033 6 G 23 X 40 o 57 5 2034 7 H 24 Y 41 p 58 6 2035 8 I 25 Z 42 q 59 7 2036 9 J 26 a 43 r 60 8 2037 10 K 27 b 44 s 61 9 2038 11 L 28 c 45 t 62 + 2039 12 M 29 d 46 u 63 / 2040 13 N 30 e 47 v 2041 14 O 31 f 48 w (pad) = 2042 15 P 32 g 49 x 2043 16 Q 33 h 50 y 2045 The encoded output stream must be represented in lines of no more 2046 than 76 characters each. 2048 Special processing is performed if fewer than 24 bits are available 2049 at the end of the data being encoded. There are three possibilities: 2051 1. The last data group has 24 bits (3 octets). No special 2052 processing is needed. 2054 2. The last data group has 16 bits (2 octets). The first two 6-bit 2055 groups are processed as above. The third (incomplete) data group 2056 has two zero-value bits added to it, and is processed as above. 2057 A pad character (=) is added to the output. 2059 3. The last data group has 8 bits (1 octet). The first 6-bit group 2060 is processed as above. The second (incomplete) data group has 2061 four zero-value bits added to it, and is processed as above. Two 2062 pad characters (=) are added to the output. 2064 6.4. Decoding Radix-64 2066 Any characters outside of the base64 alphabet are ignored in 2067 Radix-64 data. Decoding software must ignore all line breaks or 2068 other characters not found in the table above. 2070 In Radix-64 data, characters other than those in the table, line 2071 breaks, and other white space probably indicate a transmission 2072 error, about which a warning message or even a message rejection 2073 might be appropriate under some circumstances. 2075 Because it is used only for padding at the end of the data, the 2076 occurrence of any "=" characters may be taken as evidence that the 2077 end of the data has been reached (without truncation in transit). No 2078 such assurance is possible, however, when the number of octets 2079 transmitted was a multiple of three and no "=" characters are 2080 present. 2082 6.5. Examples of Radix-64 2084 Input data: 0x14fb9c03d97e 2085 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2086 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2087 11111110 2088 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 2089 111110 2090 Decimal: 5 15 46 28 0 61 37 62 2091 Output: F P u c A 9 l + 2093 Input data: 0x14fb9c03d9 2094 Hex: 1 4 f b 9 c | 0 3 d 9 2095 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2096 pad with 00 2097 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2098 Decimal: 5 15 46 28 0 61 36 2099 pad with = 2100 Output: F P u c A 9 k = 2102 Input data: 0x14fb9c03 2103 Hex: 1 4 f b 9 c | 0 3 2104 8-bit: 00010100 11111011 10011100 | 00000011 2105 pad with 0000 2106 6-bit: 000101 001111 101110 011100 | 000000 110000 2107 Decimal: 5 15 46 28 0 48 2108 pad with = = 2109 Output: F P u c A w = = 2111 6.6. Example of an ASCII Armored Message 2113 -----BEGIN PGP MESSAGE----- 2114 Version: OpenPrivacy 0.99 2116 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2117 vBSFjNSiVHsuAA== 2118 =njUN 2119 -----END PGP MESSAGE----- 2121 Note that this example is indented by two spaces. 2123 7. Cleartext signature framework 2125 It is desirable to sign a textual octet stream without ASCII 2126 armoring the stream itself, so the signed text is still readable 2127 without special software. In order to bind a signature to such a 2128 cleartext, this framework is used. (Note that RFC 2015 defines 2129 another way to clear sign messages for environments that support 2130 MIME.) 2132 The cleartext signed message consists of: 2134 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2135 single line, 2137 - One or more "Hash" Armor Headers, 2139 - Exactly one empty line not included into the message digest, 2141 - The dash-escaped cleartext that is included into the message 2142 digest, 2144 - The ASCII armored signature(s) including the Armor Header and 2145 Armor Tail Lines. 2147 If the "Hash" armor header is given, the specified message digest 2148 algorithm is used for the signature. If there are no such headers, 2149 MD5 is used, an implementation MAY omit them for V2.x compatibility. 2150 If more than one message digest is used in the signature, the "Hash" 2151 armor header contains a comma-delimited list of used message 2152 digests. 2154 Current message digest names are described below with the algorithm 2155 IDs. 2157 7.1. Dash-Escaped Text 2159 The cleartext content of the message must also be dash-escaped. 2161 Dash escaped cleartext is the ordinary cleartext where every line 2162 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2163 (0x2D) and space ' ' (0x20). This prevents the parser from 2164 recognizing armor headers of the cleartext itself. The message 2165 digest is computed using the cleartext itself, not the dash escaped 2166 form. 2168 As with binary signatures on text documents, a cleartext signature 2169 is calculated on the text using canonical line endings. 2170 The line ending (i.e. the ) before the '-----BEGIN PGP 2171 SIGNATURE-----' line that terminates the signed text is not 2172 considered part of the signed text. 2174 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of 2175 any line is ignored when the cleartext signature is calculated. 2177 8. Regular Expressions 2179 A regular expression is zero or more branches, separated by '|'. It 2180 matches anything that matches one of the branches. 2182 A branch is zero or more pieces, concatenated. It matches a match 2183 for the first, followed by a match for the second, etc. 2185 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2186 followed by '*' matches a sequence of 0 or more matches of the atom. 2187 An atom followed by '+' matches a sequence of 1 or more matches of 2188 the atom. An atom followed by '?' matches a match of the atom, or 2189 the null string. 2191 An atom is a regular expression in parentheses (matching a match for 2192 the regular expression), a range (see below), '.' (matching any 2193 single character), '^' (matching the null string at the beginning of 2194 the input string), '$' (matching the null string at the end of the 2195 input string), a '\' followed by a single character (matching that 2196 character), or a single character with no other significance 2197 (matching that character). 2199 A range is a sequence of characters enclosed in '[]'. It normally 2200 matches any single character from the sequence. If the sequence 2201 begins with '^', it matches any single character not from the rest 2202 of the sequence. If two characters in the sequence are separated by 2203 '-', this is shorthand for the full list of ASCII characters between 2204 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2205 ']' in the sequence, make it the first character (following a 2206 possible '^'). To include a literal '-', make it the first or last 2207 character. 2209 9. Constants 2211 This section describes the constants used in OpenPGP. 2213 Note that these tables are not exhaustive lists; an implementation 2214 MAY implement an algorithm not on these lists. 2216 See the section "Notes on Algorithms" below for more discussion of 2217 the algorithms. 2219 9.1. Public Key Algorithms 2221 ID Algorithm 2222 -- --------- 2223 1 - RSA (Encrypt or Sign) 2224 2 - RSA Encrypt-Only 2225 3 - RSA Sign-Only 2226 16 - Elgamal (Encrypt-Only), see [ELGAMAL] 2227 17 - DSA (Digital Signature Standard) 2228 18 - Elliptic Curve 2229 19 - ECDSA 2230 20 - Elgamal (Encrypt or Sign) 2231 21 - Diffie-Hellman (X9.42) 2232 100 to 110 - Private/Experimental algorithm. 2234 Implementations MUST implement DSA for signatures, and Elgamal for 2235 encryption. Implementations SHOULD implement RSA keys. 2236 Implementations MAY implement any other algorithm. 2238 9.2. Symmetric Key Algorithms 2240 ID Algorithm 2241 -- --------- 2242 0 - Plaintext or unencrypted data 2243 1 - IDEA 2244 2 - Triple-DES (DES-EDE, as per spec - 2245 168 bit key derived from 192) 2246 3 - CAST5 (128 bit key) 2247 4 - Blowfish (128 bit key, 16 rounds) 2248 5 - SAFER-SK128 (13 rounds) 2249 6 - DES/SK 2250 100 to 110 - Private/Experimental algorithm. 2252 Implementations MUST implement Triple-DES. Implementations SHOULD 2253 implement IDEA and CAST5.Implementations MAY implement any other 2254 algorithm. 2256 9.3. Compression Algorithms 2258 ID Algorithm 2259 -- --------- 2260 0 - Uncompressed 2261 1 - ZIP (RFC1951) 2262 2 - ZLIB (RFC1950) 2263 100 to 110 - Private/Experimental algorithm. 2265 Implementations MUST implement uncompressed data. Implementations 2266 SHOULD implement ZIP. 2268 9.4. Hash Algorithms 2270 ID Algorithm Text Name 2271 -- --------- ---- ---- 2272 1 - MD5 "MD5" 2273 2 - SHA-1 "SHA1" 2274 3 - RIPE-MD/160 "RIPEMD160" 2275 4 - HAVAL (5 pass, 160-bit) "HAVAL-5-160" 2276 5 - MD2 "MD2" 2277 6 - TIGER/192 "TIGER192" 2278 100 to 110 - Private/Experimental algorithm. 2280 Implementations MUST implement SHA-1. Implementations SHOULD 2281 implement MD5. 2283 10. Packet Composition 2285 OpenPGP packets are assembled into sequences in order to create 2286 messages 2288 and to transfer keys. Not all possible packet sequences are 2289 meaningful and correct. This describes the rules for how packets 2290 should be placed into sequences. 2292 10.1. Transferable Public Keys 2294 OpenPGP users may transfer public keys. The essential elements of a 2295 transferable public key are: 2297 - One Public Key packet 2299 - Zero or more revocation signatures 2301 - One or more User ID packets 2303 - After each User ID packet, zero or more signature packets 2304 (certifications) 2306 - Zero or more Subkey packets 2308 - After each Subkey packet, one signature packet, optionally a 2309 revocation. 2311 The Public Key packet occurs first. Each of the following User ID 2312 packets provides the identity of the owner of this public key. If 2313 there are multiple User ID packets, this corresponds to multiple 2314 means of identifying the same unique individual user; for example, a 2315 user may have more than one email address, and construct a User ID 2316 for each one. 2318 Immediately following each User ID packet, there are zero or more 2319 signature packets. Each signature packet is calculated on the 2320 immediately preceding User ID packet and the initial Public Key 2321 packet. The signature serves to certify the corresponding public key 2322 and user ID. In effect, the signer is testifying to his or her 2323 belief that this public key belongs to the user identified by this 2324 user ID. 2326 After the User ID packets there may be one or more Subkey packets. 2327 In general, subkeys are provided in cases where the top-level public 2328 key is a signature-only key. However, any V4 key may have subkeys, 2329 and the subkeys may be encryption-only keys, signature-only keys, or 2330 general-purpose keys. 2332 Each Subkey packet must be followed by one Signature packet, which 2333 should be a subkey binding signature issued by the top level key. 2335 Subkey and Key packets may each be followed by a revocation 2336 Signature packet to indicate that the key is revoked. Revocation 2337 signatures are only accepted if they are issued by the key itself, 2338 or by a key that is authorized to issue revocations via a revocation 2339 key subpacket in a self-signature by the top level key. 2341 Transferable public key packet sequences may be concatenated to 2342 allow transferring multiple public keys in one operation. 2344 10.2. OpenPGP Messages 2346 An OpenPGP message is a packet or sequence of packets that 2347 corresponds to the following grammatical rules (comma represents 2348 sequential composition, and vertical bar separates alternatives): 2350 OpenPGP Message :- Encrypted Message | Signed Message | 2351 Compressed Message | Literal Message. 2353 Compressed Message :- Compressed Data Packet. 2355 Literal Message :- Literal Data Packet. 2357 ESK :- Pubic Key Encrypted Session Key Packet | 2358 Symmetric-Key Encrypted Session Key Packet. 2360 ESK Sequence :- ESK | ESK Sequence, ESK. 2362 Encrypted Message :- Symmetrically Encrypted Data Packet | 2363 ESK Sequence, Symmetrically Encrypted Data Packet. 2365 One-Pass Signed Message :- One-Pass Signature Packet, 2366 OpenPGP Message, Signature Packet. 2368 Signed Message :- Signature Packet, OpenPGP Message | 2369 One-Pass Signed Message. 2371 In addition, decrypting a Symmetrically Encrypted Data packet and 2373 decompressing a Compressed Data packet must yield a valid OpenPGP 2374 Message. 2376 11. Enhanced Key Formats 2378 11.1. Key Structures 2380 The format of an OpenPGP V3 key is as follows. Entries in square 2381 brackets are optional and ellipses indicate repetition. 2383 RSA Public Key 2384 [Revocation Self Signature] 2385 User ID [Signature ...] 2386 [User ID [Signature ...] ...] 2388 Each signature certifies the RSA public key and the preceding user 2389 ID. The RSA public key can have many user IDs and each user ID can 2390 have many signatures. 2392 The format of an OpenPGP V4 key that uses two public keys is similar 2393 except that the other keys are added to the end as 'subkeys' of the 2394 primary key. 2396 Primary-Key 2397 [Revocation Self Signature] 2398 [Direct Key Self Signature...] 2399 User ID [Signature ...] 2400 [User ID [Signature ...] ...] 2401 [[Subkey [Binding-Signature-Revocation] 2402 Primary-Key-Binding-Signature] ...] 2404 A subkey always has a single signature after it that is issued using 2405 the primary key to tie the two keys together. This binding 2406 signature may be in either V3 or V4 format, but V4 is prefered, of 2407 course. 2409 In the above diagram, if the binding signature of a subkey has been 2410 revoked, the revoked binding signature may be removed, leaving only 2411 one signature. 2413 In a key that has a main key and subkeys, the primary key MUST be a 2414 key capable of signing. The subkeys may be keys of any other type. 2415 There may be other constructions of V4 keys, too. For example, there 2416 may be a single-key RSA key in V4 format, a DSA primary key with an 2417 RSA encryption key, or RSA primary key with an Elgamal subkey, etc. 2419 It is also possible to have a signature-only subkey. This permits a 2420 primary key that collects certifications (key signatures) but is 2421 used only used for certifying subkeys that are used for encryption 2422 and signatures. 2424 11.2. Key IDs and Fingerprints 2426 For a V3 key, the eight-octet key ID consists of the low 64 bits of 2427 the public modulus of the RSA key. 2429 The fingerprint of a V3 key is formed by hashing the body (but not 2430 the two-octet length) of the MPIs that form the key material (public 2431 modulus n, followed by exponent e) with MD5. 2433 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet 2434 Tag, followed by the two-octet packet length, followed by the entire 2435 Public Key packet starting with the version field. The key ID is 2436 either the low order 64 bits of the fingerprint. Here are the 2437 fields of the hash material, with the example of a DSA key: 2439 a.1) 0x99 (1 octet) 2441 a.2) high order length octet of (b)-(f) (1 octet) 2443 a.3) low order length octet of (b)-(f) (1 octet) 2445 b) version number = 4 (1 octet); 2447 c) time stamp of key creation (4 octets); 2449 d) algorithm (1 octet): 7 = DSA (example); 2451 e) Algorithm specific fields. 2453 Algorithm Specific Fields for DSA keys (example): 2455 e.1) MPI of DSA prime p; 2457 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 2459 e.3) MPI of DSA group generator g; 2461 e.4) MPI of DSA public key value y (= g**x where x is secret). 2463 Note that it is possible for there to be collisions of key IDs -- 2464 two different keys with the same key ID. Note that there is a much 2465 smaller, but still non-zero probability that two different keys have 2466 the same fingerprint. 2468 Also note that if V3 and V4 format keys share the same RSA key 2469 material, they will have different key ids as well as different 2470 fingerprints. 2472 12. Notes on Algorithms 2474 12.1. Symmetric Algorithm Preferences 2476 The symmetric algorithm preference is an ordered list of algorithms 2477 that the keyholder accepts. Since it is found on a self-signature, 2478 it is possible that a keyholder may have different preferences. For 2479 example, Alice may have TripleDES only specified for 2480 "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 2481 "alice@home.org". Note that it is also possible for preferences to 2482 be in a subkey's binding signature. 2484 Since TripleDES is the MUST-implement algorithm, if it is not 2485 explicitly in the list, it is tacitly at the end. However, it is 2486 good form to place it there explicitly. Note also that if an 2487 implementation does not implement the preference, then it is 2488 implicitly a TripleDES-only implementation. 2490 An implementation MUST not use a symmetric algorithm that is not in 2491 the recipient's preference list. When encrypting to more than one 2492 recipient, the implementation finds a suitable algorithm by taking 2493 the intersection of the preferences of the recipients. Note that the 2494 MUST-implement algorithm, TripleDES, ensures that the intersection 2495 is not null. The implementation may use any mechanism to pick an 2496 algorithm in the intersection. 2498 If an implementation can decrypt a message that a keyholder doesn't 2499 have in their preferences, the implementation SHOULD decrypt the 2500 message anyway, but MUST warn the keyholder than protocol has been 2501 violated. (For example, suppose that Alice, above, has software that 2502 implements all algorithms in this specification. Nonetheless, she 2503 prefers subsets for work or home. If she is sent a message encrypted 2504 with IDEA, which is not in her preferences, the software warns her 2505 that someone sent her an IDEA-encrypted message, but it would 2506 ideally decrypt it anyway.) 2508 An implementation that is striving for backward compatibility MAY 2509 consider a V3 key with a V3 self-signature to be an implicit 2510 preference for IDEA, and no ability to do TripleDES. This is 2511 technically non-compliant, but an implementation MAY violate the 2512 above rule in this case only and use IDEA to encrypt the message, 2513 provided that the message creator is warned. Ideally, though, the 2514 implementation would follow the rule by actually generating two 2515 messages, because it is possible that the OpenPGP user's 2516 implementation does not have IDEA, and thus could not read the 2517 message. Consenquently, an implementation MAY, but SHOULD NOT use 2518 IDEA in an algorithm conflict with a V3 key. 2520 12.2. Other Algorithm Preferences 2522 Other algorithm preferences work similarly to the symmetric 2523 algorithm preference, in that they specify which algorithms the 2524 keyholder accepts. There are two interesting cases that other 2525 comments need to be made about, though, the compression preferences 2526 and the hash preferences. 2528 12.2.1. Compression Preferences 2530 Compression has been an integral part of PGP since its first days. 2531 OpenPGP and all previous versions of PGP have offered compression. 2532 And in this specification, the default is for messages to be 2533 compressed, although an implementation is not required to do so. 2534 Consequently, the compression preference gives a way for a keyholder 2535 to request that messages not be compressed, presumably because they 2536 are using a minimal implementation that does not include 2537 compression. Additionally, this gives a keyholder a way to state 2538 that it can support alternate algorithms. 2540 Like the algorithm preferences, an implementation MUST NOT use an 2541 algorithm that is not in the preference vector. If the preferences 2542 are mot present, then they are assumed to be [ZIP(1), 2543 UNCOMPRESSED(0)]. 2545 12.2.2. Hash Algorithm Preferences 2547 Typically, the choice of a hash algorithm is something the signer 2548 does, rather than the verifier, because a signer does not typically 2549 know who is going to be verifying the signature. This preference, 2550 though, allows a protocol based upon digital signatures ease in 2551 negotiation. 2553 Thus, if Alice is authenticating herself to Bob with a signature, it 2554 makes sense for her to use a hash algorithm that Bob's software 2555 uses. This preference allows Bob to state in his key which 2556 algorithms Alice may use. 2558 12.3. Plaintext 2560 Algorithm 0, "plaintext," may only be used to denote secret keys 2561 that are stored in the clear. Implementations must not use plaintext 2562 in Symmetrically Encrypted Data Packets; they must use Literal Data 2563 Packets to encode unencrypted or literal data. 2565 12.4. RSA 2567 There are algorithm types for RSA-signature-only, and 2568 RSA-encrypt-only keys. These types are deprecated. The "key flags" 2569 subpacket in a signature is a much better way to express the same 2570 idea, and generalizes it to all algorithms. An implementation SHOULD 2571 NOT create such a key, but MAY interpret it. 2573 An implementation SHOULD NOT implement RSA keys of size less than 2574 768 bits. 2576 It is permissible for an implementation to support RSA merely for 2577 backward compatibility; for example, such an implementation would 2578 support V3 keys with IDEA symmetric cryptography. Note that this is 2579 an exception to the other MUST-implement rules. An implementation 2580 that supports RSA in V4 keys MUST implement the MUST-implement 2581 features. 2583 12.5. Elgamal 2585 If an Elgamal key is to be used for both signing and encryption, 2586 extra care must be taken in creating the key. 2588 An ElGamal key consists of a generator g, a prime modulus p, a 2589 secret exponent x, and a public value y = g^x mod p. 2591 The generator and prime must be chosen so that solving the discrete 2592 log problem is intractable. The group g should generate the 2593 multiplicative group mod p-1 or a large subgroup of it, and the 2594 order of g should have at least one large prime factor. A good 2595 choice is to use a "strong" Sophie-Germain prime in choosing p, so 2596 that both p and (p-1)/2 are primes. 2598 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that 2599 if the generator g has only small prime factors, and if g divides 2600 the order of the group it generates, then signatures can be forged. 2601 In particular, choosing g=2 is a bad choice if the group order may 2602 be even. On the other hand, a generator of 2 is a fine choice for an 2603 encryption-only key, as this will make the encryption faster. 2605 While verifying Elgamal signatures, note that it is important to 2606 test that r and s are less than p. If this test is not done then 2607 signatures can be trivially forged by using large r values of 2608 approximately twice the length of p. This attack is also discussed 2609 in the Bleichenbacher paper. 2611 Details on safe use of Elgamal signatures may be found in [MENEZES], 2612 which discusses all the weaknesses described above. 2614 If an implementation allows Elgamal signatures, then it MUST use the 2615 algorithm identifier 20 for an Elgamal public key that can sign. 2617 An implementation SHOULD NOT implement Elgamal keys of size less 2618 than 768 bits. For long-term security, Elgamal keys should be 1024 2619 bits or longer. 2621 12.6. DSA 2623 An implementation SHOULD NOT implement DSA keys of size less than 2624 768 bits. Note that present DSA is limited to a maximum of 1024 bit 2625 keys, which are recommended for long-term use. 2627 12.7. OpenPGP CFB mode 2629 OpenPGP does symmetric encryption using a variant of Cipher Feedback 2630 Mode (CFB mode). This section describes the procedure it uses in 2631 detail. This mode is what is used for Symmetrically Encrypted Data 2632 Packets; the mechanism used for encrypting secret key material is 2633 similar, but described in those sections above. 2635 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 2636 and prefixes the plaintext with ten bytes of random data, such that 2637 bytes 9 and 10 match bytes 7 and 8. It does a CFB "resync" after 2638 encrypting those ten bytes. 2640 Note that for an algorithm that has a larger block size than 64 2641 bits, the equivalent function will be done with that entire block. 2643 Step by step, here is the procedure: 2645 1. The feedback register (FR) is set to the IV, which is all zeros. 2647 2. FR is encrypted to produce FRE (FR Encrypted). This is the 2648 encryption of an all-zero value. 2650 3. FRE is xored with the first 8 bytes of random data prefixed to 2651 the plaintext to produce C1-C8, the first 8 bytes of ciphertext. 2653 4. FR is loaded with C1-C8. 2655 5. FR is encrypted to produce FRE, the encryption of the first 8 2656 bytes of ciphertext. 2658 6. The left two bytes of FRE get xored with the next two bytes of 2659 data that were prefixed to the plaintext. This produces C9-C10, 2660 the next two bytes of ciphertext. 2662 7. (The resync step) FR is loaded with C3-C10. 2664 8. FR is encrypted to produce FRE. 2666 9. FRE is xored with the first 8 bytes of the given plaintext, now 2667 that we have finished encrypting the 10 bytes of prefixed data. 2668 This produces C11-C18, the next 8 bytes of ciphertext. 2670 10. FR is loaded with C11-C18 2672 11. FR is encrypted to produce FRE. 2674 12. FRE is xored with the next 8 bytes of plaintext, to produce the 2675 next 8 bytes of ciphertext. These are loaded into FR and the 2676 process is repeated until the plaintext is used up. 2678 13. Security Considerations 2680 As with any technology involving cryptography, you should check the 2681 current literature to determine if any algorithms used here have 2682 been found to be vulnerable to attack. 2684 This specification uses Public Key Cryptography technologies. 2685 Possession of the private key portion of a public-private key pair 2686 is assumed to be controlled by the proper party or parties. 2688 Certain operations in this specification involve the use of random 2689 numbers. An appropriate entropy source should be used to generate 2690 these numbers. See RFC 1750. 2692 The MD5 hash algorithm has been found to have weaknesses 2693 (pseudo-collisions in the compress function) that make some people 2694 deprecate its use. They consider the SHA-1 algorithm better. 2696 Many security protocol designers think that it is a bad idea to use 2697 a single key for both privacy (encryption) and integrity 2698 (signatures). In fact, this was one of the motivating forces behind 2699 the V4 key format with separate signature and encryption keys. If 2700 you as an implementor promote dual-use keys, you should at least be 2701 aware of this controversy. 2703 The DSA algorithm will work with any 160-bit hash, but it is 2704 sensitive to the quality of the hash algorithm, if the hash 2705 algorithm is broken, it can leak the secret key. The Digital 2706 Signature Standard (DSS) specifies that DSA be used with SHA-1. 2707 RIPEMD-160 is considered by many cryptographers to be as strong. An 2708 implementation should take care which hash algorithms are used with 2709 DSA, as a weak hash can not only allow a signature to be forged, but 2710 could leak the secret key. These same considerations about the 2711 quality of the hash algorithm apply to Elgamal signatures. 2713 If you are building an authentication system, the recipient may 2714 specify a preferred signing algorithm. However, the signer would be 2715 foolish to use a weak algorithm simply because the recipient 2716 requests it. 2718 Some of the encryption algorithms mentioned in this document have 2719 been analyzed less than others. For example, although CAST5 is 2720 presently considered strong, it has been analyzed less than 2721 Triple-DES. Other algorithms may have other controversies 2722 surrounding them. 2724 Some technologies mentioned here may be subject to government 2725 control in some countries. 2727 14. Implementation Nits 2729 This section is a collection of comments to help an implementer, 2730 particularly with an eye to backward compatibility. Previous 2731 implementations of PGP are not OpenPGP-compliant. Often the 2732 differences are small, but small differences are frequently more 2733 vexing than large differences. Thus, this list of potential problems 2734 and gotchas for a developer who is trying to be backward-compatible. 2736 * PGP 5.x does not accept V4 signatures for anything other than 2737 key material. 2739 * PGP 5.x does not recognize the "five-octet" lengths in 2740 new-format headers or in signature subpacket lengths. 2742 * PGP 5.0 rejects an encrypted session key if the keylength 2743 differs from the the S2K symmetric algorithm. This is a bug in 2744 its validation function. 2746 * PGP 5.0 does not handle multiple one-pass signature headers and 2747 trailers. Signing one will compress the one-pass signed literal 2748 and prefix a V3 signature instead of doing a nested one-pass 2749 signature. 2751 * When exporting a private key, PGP 2.x generates the header 2752 "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY 2753 BLOCK". All previous versions ignore the implied data type, and 2754 look directly at the packet data type. 2756 * In a clear-signed signature, PGP 5.0 will figure out the correct 2757 hash algorithm if there is no "Hash:" header, but it will reject 2758 a mismatch between the header and the actual agorithm used. The 2759 "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x 2760 rejects the "Hash:" header and assumes MD5. There are a number 2761 of enhanced variants of PGP 2.6.x that have been modified for 2762 SHA-1 signatures. 2764 * PGP 5.0 can read an RSA key in V4 format, but can only recognize 2765 it with a V3 keyid, and can properly use only a V3 format RSA 2766 key. 2768 * There are many ways possible for for two keys to have the same 2769 key material, but different fingerprints (and thus key ids). 2770 Perhaps the most interesting is an RSA key that has been 2771 "upgraded" to V4 format, but since a V4 fingerprint is 2772 constructed by hashing the key creation time along with other 2773 things, two V4 keys created at different times, yet with the 2774 same key material will have different fingerprints. 2776 * If an implemtation is using zlib to interoperate with PGP 2.x, 2777 then the "windowBits" parameter should be set to -13. 2779 15. Authors and Working Group Chair 2781 The working group can be contacted via the current chair: 2783 John W. Noerenberg, II 2784 Qualcomm, Inc 2785 6455 Lusk Blvd 2786 San Diego, CA 92131 USA 2787 Email: jwn2@qualcomm.com 2788 Tel: +1 619-658-3510 2790 The principal authors of this draft are: 2792 Jon Callas 2793 Network Associates, Inc. 2794 4200 Bohannon Drive 2795 Menlo Park, CA 94025, USA 2796 Email: jon@pgp.com 2797 Tel: +1-650-473-2860 2799 Lutz Donnerhacke 2800 IKS GmbH 2801 Wildenbruchstr. 15 2802 07745 Jena, Germany 2803 EMail: lutz@iks-jena.de 2804 Tel: +49-3641-675642 2806 Hal Finney 2807 Network Associates, Inc. 2808 4200 Bohannon Drive 2809 Menlo Park, CA 94025, USA 2810 Email: hal@pgp.com 2812 Rodney Thayer 2813 EIS Corporation 2814 Clearwater, FL 33767, USA 2815 Email: rodney@unitran.com 2817 This draft also draws on much previous work from a number of other 2818 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 2819 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph 2820 Levine, Colin Plumb, Will Price, William Stallings, Mark Weaver, and 2821 Philip R. Zimmermann. 2823 16. References 2825 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal 2826 signatures without knowing the secret key," Eurocrypt 96. Note that 2827 the version in the proceedings has an error. A revised version is 2828 available at the time of writing from 2829 2831 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved 2832 international version of PGP", 2833 ftp://ftp.iks-jena.de/mitarb/lutz/crypt/software/pgp/ 2835 [ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a Signature 2836 Scheme Based on Discrete Logarithms," IEEE Transactions on 2837 Information Theory, v. IT-31, n. 4, 1985, pp. 469-472. 2839 [ISO-10646] ISO/IEC 10646-1:1993. International Standard -- 2840 Information technology -- Universal Multiple-Octet Coded Character 2841 Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane. 2842 UTF-8 is described in Annex R, adopted but not yet published. 2843 UTF-16 is described in Annex Q, adopted but not yet published. 2845 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott Vanstone, 2846 "Handbook of Applied Cryptography," CRC Press, 1996. 2848 [PKCS1] RSA Laboratories, "PKCS #1: RSA Encryption Standard," 2849 version 1.5, November 1993 2851 [RFC822] D. Crocker, "Standard for the format of ARPA Internet text 2852 messages", RFC 822, August 1982 2854 [RFC1423] D. Balenson, "Privacy Enhancement for Internet Electronic 2855 Mail: Part III: Algorithms, Modes, and Identifiers", RFC 1423, 2856 October 1993 2858 [RFC1641] Goldsmith, D., and M. Davis, "Using Unicode with MIME", 2859 RFC 1641, Taligent inc., July 1994. 2861 [RFC1750] Eastlake, Crocker, & Schiller., Randomness Recommendations 2862 for Security. December 1994. 2864 [RFC1951] Deutsch, P., DEFLATE Compressed Data Format Specification 2865 version 1.3. May 1996. 2867 [RFC1983] G. Malkin., Internet Users' Glossary. August 1996. 2869 [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP Message 2870 Exchange Formats", RFC 1991, August 1996. 2872 [RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy 2873 (PGP)", RFC 2015, October 1996. 2875 [RFC2044] F. Yergeau., UTF-8, a transformation format of Unicode and 2876 ISO 10646. October 1996. 2878 [RFC2045] Borenstein, N., and Freed, N., "Multipurpose Internet Mail 2879 Extensions (MIME) Part One: Format of Internet Message Bodies.", 2880 November 1996 2882 [RFC2119] Bradner, S., Key words for use in RFCs to Indicate 2883 Requirement Level. March 1997. 2885 17. Full Copyright Statement 2887 Copyright 1998 by The Internet Society. All Rights Reserved. 2889 This document and translations of it may be copied and furnished to 2890 others, and derivative works that comment on or otherwise explain it 2891 or assist in its implementation may be prepared, copied, published 2892 and distributed, in whole or in part, without restriction of any 2893 kind, provided that the above copyright notice and this paragraph 2894 are included on all such copies and derivative works. However, this 2895 document itself may not be modified in any way, such as by removing 2896 the copyright notice or references to the Internet Society or other 2897 Internet organizations, except as needed for the purpose of 2898 developing Internet standards in which case the procedures for 2899 copyrights defined in the Internet Standards process must be 2900 followed, or as required to translate it into languages other than 2901 English. 2903 The limited permissions granted above are perpetual and will not be 2904 revoked by the Internet Society or its successors or assigns.