idnits 2.17.1 draft-ietf-openpgp-formats-02.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 recipent's preference list. When encrypting to more than one recipient, the implementation finds a suitable algorithm by taking the intersection of the preferences of the recipients. Note that the MUST-implement algorithm, TripleDES, ensures that the intersection is not null. The implementation may use any mechanism to pick an algorithm in the intersection. == Unrecognized Status in 'Category: INTERNET-DRAFT', assuming Proposed Standard (Expected one of 'Standards Track', 'Full Standard', 'Draft Standard', 'Proposed Standard', 'Best Current Practice', 'Informational', 'Experimental', 'Informational', 'Historic'.) -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- Couldn't find a document date in the document -- date freshness check skipped. -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '0' on line 311 -- Looks like a reference, but probably isn't: '1' on line 311 -- Looks like a reference, but probably isn't: '2' on line 311 -- Looks like a reference, but probably isn't: '3' on line 312 == Missing Reference: 'ISO10646' is mentioned on line 352, but not defined == Missing Reference: 'Optional' is mentioned on line 1597, but not defined == Unused Reference: 'DONNERHACKE' is defined on line 2666, but no explicit reference was found in the text == Unused Reference: 'ISO-10646' is defined on line 2674, but no explicit reference was found in the text == Unused Reference: 'RFC822' is defined on line 2686, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 2689, but no explicit reference was found in the text == Unused Reference: 'RFC1641' is defined on line 2693, but no explicit reference was found in the text == Unused Reference: 'RFC1750' is defined on line 2696, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 2699, but no explicit reference was found in the text == Unused Reference: 'RFC1983' is defined on line 2702, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 2704, but no explicit reference was found in the text == Unused Reference: 'RFC2015' is defined on line 2707, but no explicit reference was found in the text == Unused Reference: 'RFC2045' is defined on line 2713, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 2717, 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 (~~), 17 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-02.txt 4 Expires Oct 1998 Lutz Donnerhacke 5 April 1997 IN-Root-CA Individual Network e.V. 7 Hal Finney 8 Network Associates 10 Rodney Thayer 11 Sable Technology 13 OpenPGP Message Format 14 draft-ietf-openpgp-formats-02.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 19 97 5.2.3.1. Signature Subpacket Specification 20 98 5.2.3.2. Signature Subpacket Types 21 99 5.2.3.3. Signature creation time 22 100 5.2.3.4. Issuer 22 101 5.2.3.5. Key expiration time 22 102 5.2.3.6. Preferred symmetric algorithms 22 103 5.2.3.7. Preferred hash algorithms 23 104 5.2.3.8. Preferred compression algorithms 23 105 5.2.3.9. Signature expiration time 23 106 5.2.3.10.Exportable 23 107 5.2.3.11.Revocable 23 108 5.2.3.12.Trust signature 24 109 5.2.3.13.Regular expression 24 110 5.2.3.14.Revocation key 24 111 5.2.3.15.Notation Data 25 112 5.2.3.16.Key server preferences 25 113 5.2.3.17.Preferred key server 25 114 5.2.3.18.Primary user id 26 115 5.2.3.19.Policy URL 26 116 5.2.3.20.Key Flags 26 117 5.2.3.21.Signer's User ID 27 118 5.2.4. Computing Signatures 27 119 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 28 120 5.4. One-Pass Signature Packets (Tag 4) 29 121 5.5. Key Material Packet 29 122 5.5.1. Key Packet Variants 29 123 5.5.1.1. Public Key Packet (Tag 6) 29 124 5.5.1.2. Public Subkey Packet (Tag 14) 30 125 5.5.1.3. Secret Key Packet (Tag 5) 30 126 5.5.1.4. Secret Subkey Packet (Tag 7) 30 127 5.5.2. Public Key Packet Formats 30 128 5.5.3. Secret Key Packet Formats 32 129 5.6. Compressed Data Packet (Tag 8) 33 130 5.7. Symmetrically Encrypted Data Packet (Tag 9) 34 131 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 34 132 5.9. Literal Data Packet (Tag 11) 35 133 5.10. Trust Packet (Tag 12) 35 134 5.11. User ID Packet (Tag 13) 36 135 6. Radix-64 Conversions 36 136 6.1. An Implementation of the CRC-24 in "C" 36 137 6.2. Forming ASCII Armor 37 138 6.3. Encoding Binary in Radix-64 39 139 6.4. Decoding Radix-64 40 140 6.5. Examples of Radix-64 40 141 6.6. Example of an ASCII Armored Message 41 142 7. Cleartext signature framework 41 143 7.1. Dash-Escaped Text 42 144 8. Regular Expressions 42 145 9. Constants 43 146 9.1. Public Key Algorithms 43 147 9.2. Symmetric Key Algorithms 43 148 9.3. Compression Algorithms 44 149 9.4. Hash Algorithms 44 150 10. Packet Composition 44 151 10.1. Transferable Public Keys 44 152 10.2. OpenPGP Messages 45 153 11. Enhanced Key Formats 46 154 11.1. Key Structures 46 155 11.2. Key IDs and Fingerprints 47 156 12. Notes on Algorithms 48 157 12.1. Symmetric Algorithm Preferences 48 158 12.2. Other Algorithm Preferences 48 159 12.2.1. Compression Preferences 49 160 12.2.2. Hash Algorithm Preferences 49 161 12.3. Plaintext 49 162 12.4. RSA 49 163 12.5. Elgamal 49 164 12.6. DSA 50 165 12.7. OpenPGP CFB mode 50 166 13. Security Considerations 51 167 14. Authors and Working Group Chair 52 168 15. References 53 169 16. Full Copyright Statement 54 171 1. Introduction 173 This document provides information on the message-exchange packet 174 formats used by OpenPGP to provide encryption, decryption, signing, 175 key management and functions. It builds on the foundation provided 176 in RFC 1991 "PGP Message Exchange Formats." 178 1.1. Terms 180 * OpenPGP - This is a definition for security software that uses 181 PGP 5.x as a basis. 183 * PGP - Pretty Good Privacy. PGP is a family of software systems 184 developed by Philip R. Zimmermann from which OpenPGP is based. 186 * PGP 2.6.x - This version of PGP has many variants, hence the 187 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 188 cryptographic transforms. 190 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 191 the community and also in the predecessor of this document, 192 RFC1991. It has new formats and corrects a number of problems in 193 the PGP 2.6.x design. It is referred to here as PGP 5.x because 194 that software was the first release of the "PGP 3" code base. 196 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 197 Network Associates, Inc. 199 2. General functions 201 OpenPGP provides data integrity services for messages and data files 202 by using these core technologies: 204 - digital signatures 206 - encryption 208 - compression 210 - radix-64 conversion 212 In addition, OpenPGP provides key management and certificate 213 services, but many of these are beyond the scope of this document. 215 2.1. Confidentiality via Encryption 217 OpenPGP uses two encryption methods to provide confidentiality: 218 symmetric-key encryption and public key encryption. With public-key 219 encryption, the object is encrypted using a symmetric encryption 220 algorithm. Each symmetric key is used only once. A new "session 221 key" is generated as a random number for each message. Since it is 222 used only once, the session key is bound to the message and 223 transmitted with it. To protect the key, it is encrypted with the 224 receiver's public key. The sequence is as follows: 226 1. The sender creates a message. 228 2. The sending OpenPGP generates a random number to be used as a 229 session key for this message only. 231 3. The session key is encrypted using each recipient's public key. 232 These "encrypted session keys" start the message. 234 4. The sending OpenPGP encrypts the message using the session key, 235 which forms the remainder of the message. Note that the message 236 is also usually compressed. 238 5. The receiving OpenPGP decrypts the session key using the 239 recipient's private key. 241 6. The receiving OpenPGP decrypts the message using the session 242 key. If the message was compressed, it will be decompressed. 244 With symmetric-key encryption, an object may encrypted with a 245 symmetric key derived from a passphrase (or other shared secret), or 246 a two-stage mechanism similar to the public-key method aboved can be 247 used where a session key is itself encrypted with a symmetric 248 algorithm keyed from a shared secret. 250 Both digital signature and confidentiality services may be applied 251 to the same message. First, a signature is generated for the message 252 and attached to the message. Then, the message plus signature is 253 encrypted using a symmetric session key. Finally, the session key is 254 encrypted using public-key encryption and prepended to the encrypted 255 block. 257 2.2. Authentication via Digital signature 259 The digital signature uses a hash code or message digest algorithm, 260 and a public-key signature algorithm. The sequence is as follows: 262 1. The sender creates a message. 264 2. The sending software generates a hash code of the message. 266 3. The sending software generates a signature from the hash code 267 using the sender's private key. 269 4. The binary signature is attached to the message. 271 5. The receiving software keeps a copy of the message signature. 273 6. The receiving software generates a new hash code for the 274 received message and verifies it using the message's signature. 275 If the verification is successful, the message is accepted as 276 authentic. 278 2.3. Compression 280 OpenPGP implementations MAY compress the message after applying the 281 signature but before encryption. 283 2.4. Conversion to Radix-64 285 OpenPGP's underlying native representation for encrypted messages, 286 signature certificates, and keys is a stream of arbitrary octets. 287 Some systems only permit the use of blocks consisting of seven-bit, 288 printable text. For transporting OpenPGP's native raw binary octets 289 through channels that are not safe to raw binary data, a printable 290 encoding of these binary octets is needed. OpenPGP provides the 291 service of converting the raw 8-bit binary octet stream to a stream 292 of printable ASCII characters, called Radix-64 encoding or ASCII 293 Armor. 295 Implementations SHOULD provide Radix-64 conversions. 297 Note that many applications, particularly messaging applications, 298 will want more advanced features as described in the OpenPGP-MIME 299 document, RFC2015. An application that implements OpenPGP for 300 messaging SHOULD implement OpenPGP-MIME. 302 3. Data Element Formats 304 This section describes the data elements used by OpenPGP. 306 3.1. Scalar numbers 308 Scalar numbers are unsigned, and are always stored in big-endian 309 format. Using n[k] to refer to the kth octet being interpreted, the 310 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 311 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 312 n[3]). 314 3.2. Multi-Precision Integers 316 Multi-Precision Integers (also called MPIs) are unsigned integers 317 used to hold large integers such as the ones used in cryptographic 318 calculations. 320 An MPI consists of two pieces: a two-octet scalar that is the length 321 of the MPI in bits followed by a string of octets that contain the 322 actual integer. 324 These octets form a big-endian number; a big-endian number can be 325 made into an MPI by prefixing it with the appropriate length. 327 Examples: 329 (all numbers are in hexadecimal) 331 The string of octets [00 01 01] forms an MPI with the value 1. The 332 string [00 09 01 FF] forms an MPI with the value of 511. 334 Additional rules: 336 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 338 The length field of an MPI describes the length starting from its 339 most significant non-zero bit. Thus, the MPI [00 02 01] is not 340 formed correctly. It should be [00 01 01]. 342 3.3. Key IDs 344 A Key ID is an eight-octet scalar that identifies a key. 345 Implementations SHOULD NOT assume that Key IDs are unique. The 346 section, "Enhanced Key Formats" below describes how Key IDs are 347 formed. 349 3.4. Text 351 The default character set for text is the UTF-8 [RFC2044] encoding 352 of Unicode [ISO10646]. 354 3.5. Time fields 356 A time field is an unsigned four-octet number containing the number 357 of seconds elapsed since midnight, 1 January 1970 UTC. 359 3.6. String-to-key (S2K) specifiers 361 String-to-key (S2K) specifiers are used to convert passphrase 362 strings into symmetric-key encryption/decryption keys. They are 363 used in two places, currently: to encrypt the secret part of private 364 keys in the private keyring, and to convert passphrases to 365 encryption keys for symmetrically encrypted messages. 367 3.6.1. String-to-key (S2k) specifier types 369 There are three types of S2K specifiers currently supported, as 370 follows: 372 3.6.1.1. Simple S2K 374 This directly hashes the string to produce the key data. See below 375 for how this hashing is done. 377 Octet 0: 0x00 378 Octet 1: hash algorithm 380 Simple S2K hashes the passphrase to produce the session key. The 381 manner in which this is done depends on the size of the session key 382 (which will depend on the cipher used) and the size of the hash 383 algorithm's output. If the hash size is greater than or equal to the 384 session key size, the high-order (leftmost) octets of the hash are 385 used as the key. 387 If the hash size is less than the key size, multiple instances of 388 the hash context are created -- enough to produce the required key 389 data. These instances are preloaded with 0, 1, 2, ... octets of 390 zeros (that is to say, the first instance has no preloading, the 391 second gets preloaded with 1 octet of zero, the third is preloaded 392 with two octets of zeros, and so forth). 394 As the data is hashed, it is given independently to each hash 395 context. Since the contexts have been initialized differently, they 396 will each produce different hash output. Once the passphrase is 397 hashed, the output data from the multiple hashes is concatenated, 398 first hash leftmost, to produce the key data, with any excess octets 399 on the right discarded. 401 3.6.1.2. Salted S2K 403 This includes a "salt" value in the S2K specifier -- some arbitrary 404 data -- that gets hashed along with the passphrase string, to help 405 prevent dictionary attacks. 407 Octet 0: 0x01 408 Octet 1: hash algorithm 409 Octets 2-9: 8-octet salt value 411 Salted S2K is exactly like Simple S2K, except that the input to the 412 hash function(s) consists of the 8 octets of salt from the S2K 413 specifier, followed by the passphrase. 415 3.6.1.3. Iterated and Salted S2K 417 This includes both a salt and an octet count. The salt is combined 418 with the passphrase and the resulting value is hashed repeatedly. 419 This further increases the amount of work an attacker must do to try 420 dictionary attacks. 422 Octet 0: 0x03 423 Octet 1: hash algorithm 424 Octets 2-9: 8-octet salt value 425 Octet 10: count, a one-octet, coded value 427 The count is coded into a one-octet number using the following 428 formula: 430 #define EXPBIAS 6 431 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 433 The above formula is in C, where "Int32" is a type for a 32-bit 434 integer, and the variable "c" is the coded count, Octet 10. 436 Iterated-Salted S2K hashes the passphrase and salt data multiple 437 times. The total number of octets to be hashed is specified in the 438 encoded count in the S2K specifier. Note that the resulting count 439 value is an octet count of how many octets will be hashed, not an 440 iteration count. 442 Initially, one or more hash contexts are set up as with the other 443 S2K algorithms, depending on how many octets of key data are needed. 444 Then the salt, followed by the passphrase data is repeatedly hashed 445 until the number of octets specified by the octet count has been 446 hashed. The one exception is that if the octet count is less than 447 the size of the salt plus passphrase, the full salt plus passphrase 448 will be hashed even though that is greater than the octet count. 449 After the hashing is done the data is unloaded from the hash 450 context(s) as with the other S2K algorithms. 452 3.6.2. String-to-key usage 454 Implementations SHOULD use salted or iterated-and-salted S2K 455 specifiers, as simple S2K specifiers are more vulnerable to 456 dictionary attacks. 458 3.6.2.1. Secret key encryption 460 An S2K specifier can be stored in the secret keyring to specify how 461 to convert the passphrase to a key that unlocks the secret data. 462 Older versions of PGP just stored a cipher algorithm octet preceding 463 the secret data or a zero to indicate that the secret data was 464 unencrypted. The MD5 hash function was always used to convert the 465 passphrase to a key for the specified cipher algorithm. 467 For compatibility, when an S2K specifier is used, the special value 468 255 is stored in the position where the hash algorithm octet would 469 have been in the old data structure. This is then followed 470 immediately by a one-octet algorithm identifier, and then by the S2K 471 specifier as encoded above. 473 Therefore, preceding the secret data there will be one of these 474 possibilities: 476 0: secret data is unencrypted (no pass phrase) 477 255: followed by algorithm octet and S2K specifier 478 Cipher alg: use Simple S2K algorithm using MD5 hash 480 This last possibility, the cipher algorithm number with an implicit 481 use of MD5 and IDEA, is provided for backward compatibility; it MAY 482 be understood, but SHOULD NOT be generated, and is deprecated. 484 These are followed by an 8-octet Initial Vector for the decryption 485 of the secret values, if they are encrypted, and then the secret key 486 values themselves. 488 3.6.2.2. Symmetric-key message encryption 490 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 491 packet at the front of a message. This is used to allow S2K 492 specifiers to be used for the passphrase conversion or to create 493 messages with a mix of symmetric-key ESKs and public-key ESKs. This 494 allows a message to be decrypted either with a passphrase or a 495 public key. 497 PGP 2.X always used IDEA with Simple string-to-key conversion when 498 encrypting a message with a symmetric algorithm. This is deprecated, 499 but MAY be used for backwards-compatibility. 501 4. Packet Syntax 503 This section describes the packets used by OpenPGP. 505 4.1. Overview 507 An OpenPGP message is constructed from a number of records that are 508 traditionally called packets. A packet is a chunk of data that has a 509 tag specifying its meaning. An OpenPGP message, keyring, 510 certificate, and so forth consists of a number of packets. Some of 511 those packets may contain other OpenPGP packets (for example, a 512 compressed data packet, when uncompressed, contains OpenPGP 513 packets). 515 Each packet consists of a packet header, followed by the packet 516 body. The packet header is of variable length. 518 4.2. Packet Headers 520 The first octet of the packet header is called the "Packet Tag." It 521 determines the format of the header and denotes the packet contents. 522 The remainder of the packet header is the length of the packet. 524 Note that the most significant bit is the left-most bit, called bit 525 7. A mask for this bit is 0x80 in hexadecimal. 527 +---------------+ 528 PTag |7 6 5 4 3 2 1 0| 529 +---------------+ 530 Bit 7 -- Always one 531 Bit 6 -- New packet format if set 533 PGP 2.6.x only uses old format packets. Thus, software that 534 interoperates with those versions of PGP must only use old format 535 packets. If interoperability is not an issue, either format may be 536 used. Note that old format packets have four bits of content tags, 537 and new format packets have six; some features cannot be used and 538 still be backwards-compatible. 540 Old format packets contain: 542 Bits 5-2 -- content tag 543 Bits 1-0 - length-type 545 New format packets contain: 547 Bits 5-0 -- content tag 549 4.2.1. Old-Format Packet Lengths 551 The meaning of the length-type in old-format packets is: 553 0 - The packet has a one-octet length. The header is 2 octets long. 555 1 - The packet has a two-octet length. The header is 3 octets long. 557 2 - The packet has a four-octet length. The header is 5 octets long. 559 3 - The packet is of indeterminate length. The header is 1 octet 560 long, and the implementation must determine how long the packet 561 is. If the packet is in a file, this means that the packet 562 extends until the end of the file. In general, an implementation 563 should not use indeterminate length packets except where the end 564 of the data will be clear from the context. The new format 565 headers described below have a mechanism for precisely encoding 566 data of indeterminite length. 568 4.2.2. New-Format Packet Lengths 570 New format packets have four possible ways of encoding length: 572 1. A one-octet Body Length header encodes packet lengths of up to 573 191 octets. 575 2. A two-octet Body Length header encodes packet lengths of 192 to 576 8383 octets. 578 3. A five-octet Body Length header encodes packet lengths of up to 579 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 580 encodes a four-octet scalar number.) 582 4. When the length of the packet body is not known in advance by 583 the issuer, Partial Body Length headers encode a packet of 584 indeterminite length, effectively making it a stream. 586 4.2.2.1. One-Octet Lengths 588 A one-octet Body Length header encodes a length of from 0 to 191 589 octets. This type of length header is recognized because the one 590 octet value is less than 192. The body length is equal to: 592 bodyLen = length_octet; 594 4.2.2.2. Two-Octet Lengths 596 A two-octet Body Length header encodes a length of from 192 to 8383 597 octets. It is recognized because its first octet is in the range 598 192 to 223. The body length is equal to: 600 bodyLen = (1st_octet - 192) * 256 + (2nd_octet) + 192 602 4.2.2.3. Five-Octet Lengths 604 A five-octet Body Length header consists of a single octet holding 605 the value 255, followed by a four-octet scalar. The body length is 606 equal to: 608 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 609 (4th_octet << 8) | 5th_octet 611 4.2.2.4. Partial Body Lengths 613 A Partial Body Length header is one octet long and encodes the 614 length of only part of the data packet. This length is a power of 2, 615 from 1 to 1,073,741,824 (2 to the 30th power). It is recognized by 616 its one octet value that is greater than or equal to 224, and less 617 than 255. The partial body length is equal to: 619 partialBodyLen = 1 << (length_octet & 0x1f); 621 Each Partial Body Length header is followed by a portion of the 622 packet body data. The Partial Body Length header specifies this 623 portion's length. Another length header (of one of the three types) 624 follows that portion. The last length header in the packet must not 625 be a partial Body Length header. Partial Body Length headers may 626 only be used for the non-final parts of the packet. 628 4.2.3. Packet Length Examples 630 A packet with length 100 may have its length encoded in one octet: 631 0x64. This is followed by 100 octets of data. 633 A packet with length 1723 may have its length coded in two octets: 634 0xC5, 0xFB. This header is followed by the 1723 octets of data. 636 A packet with length 100000 may have its length encoded in five 637 octets: 0xFF, 0x01, 0x86, 0xA0. 639 It might also be encoded in the following octet stream: 0xE1, first 640 two octets of data, 0xE0, next one octet of data, 0xEF, next 32768 641 octets of data, 0xF0, next 65536 octets of data, 0xC5, 0xDD, last 642 1693 octets of data. This is just one possible encoding, and many 643 variations are possible on the size of the Partial Body Length 644 headers, as long as a regular Body Length header encodes the last 645 portion of the data. Note also that the last Body Length header can 646 be a zero-length header. 648 An implementation MUST only use Partial Body Lengths for data 649 packets, be they literal, compressed, or encrypted. The first 650 partial length MUST be at least 512 octets long. 652 Please note that in all of these explanations, the total length of 653 the packet is the length of the header(s) plus the length of the 654 body. 656 4.3. Packet Tags 658 The packet tag denotes what type of packet the body holds. Note that 659 old format headers can only have tags less than 16, whereas new 660 format headers can have tags as great as 63. The defined tags (in 661 decimal) are: 663 0 -- Reserved - a packet tag must not have this value 664 1 -- Public-Key Encrypted Session Key Packet 665 2 -- Signature Packet 666 3 -- Symmetric-Key Encrypted Session Key Packet 667 4 -- One-Pass Signature Packet 668 5 -- Secret Key Packet 669 6 -- Public Key Packet 670 7 -- Secret Subkey Packet 671 8 -- Compressed Data Packet 672 9 -- Symmetrically Encrypted Data Packet 673 10 -- Marker Packet 674 11 -- Literal Data Packet 675 12 -- Trust Packet 676 13 -- User ID Packet 677 14 -- Subkey Packet 678 60 to 63 -- Private or Experimental Values 680 5. Packet Types 682 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 684 A Public-Key Encrypted Session Key packet holds the session key used 685 to encrypt a message. Zero or more Encrypted Session Key packets 686 (either Public-Key or Symmetric-Key) may precede a Symmetrically 687 Encrypted Data Packet, which holds an encrypted message. The 688 message is encrypted with the session key, and the session key is 689 itself encrypted and stored in the Encrypted Session Key packet(s). 690 The Symmetrically Encrypted Data Packet is preceded by one 691 Public-Key Encrypted Session Key packet for each OpenPGP key to 692 which the message is encrypted. The recipient of the message finds 693 a session key that is encrypted to their public key, decrypts the 694 session key, and then uses the session key to decrypt the message. 696 The body of this packet consists of: 698 - A one-octet number giving the version number of the packet type. 699 The currently defined value for packet version is 3. An 700 implementation should accept, but not generate a version of 2, 701 which is equivalent to V3 in all other respects. 703 - An eight-octet number that gives the key ID of the public key 704 that the session key is encrypted to. 706 - A one-octet number giving the public key algorithm used. 708 - A string of octets that is the encrypted session key. This 709 string takes up the remainder of the packet, and its contents 710 are dependent on the public key algorithm used. 712 Algorithm Specific Fields for RSA encryption 714 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 716 Algorithm Specific Fields for Elgamal encryption: 718 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 720 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 722 The value "m" in the above formulas is derived from the session key 723 as follows. First the session key is prefixed with a one-octet 724 algorithm identifier that specifies the symmetric encryption 725 algorithm used to encrypt the following Symmetrically Encrypted Data 726 Packet. Then a two-octet checksum is appended which is equal to the 727 sum of the preceding octets, including the algorithm identifier and 728 session key, modulo 65536. This value is then padded as described 729 in PKCS-1 block type 02 [PKCS1] to form the "m" value used in the 730 formulas above. 732 Note that when an implementation forms several PKESKs with one 733 session key, forming a message that can be decrypted by several 734 keys, the PKCS-1 the implementation MUST make new padding for each 735 key. 737 An implementation MAY accept or use a Key ID of zero as a "wild 738 card" or "speculative" Key ID. In this case, the receiving 739 implementation would try all available private keys, checking for a 740 valid decrypted session key. This format helps reduce traffic 741 analysis of messages. 743 5.2. Signature Packet (Tag 2) 745 A signature packet describes a binding between some public key and 746 some data. The most common signatures are a signature of a file or a 747 block of text, and a signature that is a certification of a user ID. 749 Two versions of signature packets are defined. Version 3 provides 750 basic signature information, while version 4 provides an expandable 751 format with subpackets that can specify more information about the 752 signature. PGP 2.6.x only accepts version 3 signatures. 754 Implementations MUST accept V3 signatures. Implementations SHOULD 755 generate V4 signatures. Implementations MAY generate a V3 signature 756 that can be verified by PGP 2.6.x. 758 Note that if an implementation is creating an encrypted and signed 759 message that is encrypted to a V3 key, it is reasonable to create a 760 V3 signature. 762 5.2.1. Signature Types 764 There are a number of possible meanings for a signature, which are 765 specified in a signature type octet in any given signature. These 766 meanings are: 768 0x00: Signature of a binary document. 769 Typically, this means the signer owns it, created it, or 770 certifies that it has not been modified. 772 0x01: Signature of a canonical text document. 773 Typically, this means the signer owns it, created it, or 774 certifies that it has not been modified. The signature will be 775 calculated over the text data with its line endings converted to 776 and trailing blanks removed. 778 0x02: Standalone signature. 779 This signature is a signature of only its own subpacket 780 contents. It is calculated identically to a signature over a 781 zero-length binary document. Note that it doesn't make sense to 782 have a V3 standalone signature. 784 0x10: Generic certification of a User ID and Public Key packet. 785 The issuer of this certification does not make any particular 786 assertion as to how well the certifier has checked that the 787 owner of the key is in fact the person described by the user ID. 788 Note that all PGP "key signatures" are this type of 789 certification. 791 0x11: Persona certification of a User ID and Public Key packet. 792 The issuer of this certification has not done any verification 793 of the claim that the owner of this key is the user ID 794 specified. 796 0x12: Casual certification of a User ID and Public Key packet. 797 The issuer of this certification has done some casual 798 verification of the claim of identity. 800 0x13: Positive certification of a User ID and Public Key packet. 801 The issuer of this certification has done substantial 802 verification of the claim of identity. 804 Please note that the vagueness of these certification claims is 805 not a flaw, but a feature of the system. Because PGP places 806 final authority for validity upon the receiver of a 807 certification, it may be that one authority's casual 808 certification might be more rigorous than some other authority's 809 positive certification. These classifications allow a 810 certification authority to issue fine-grained claims. 812 0x18: Subkey Binding Signature 813 This signature is a statement by the top-level signing key 814 indicates that it owns the subkey. This signature is calculated 815 directly on the subkey itself, not on any User ID or other 816 packets. 818 0x1F: Signature directly on a key 819 This signature is calculated directly on a key. It binds the 820 information in the signature subpackets to the key, and is 821 appropriate to be used for subpackets which provide information 822 about the key, such as the revocation key subpacket. It is also 823 appropriate for statements that non-self certifiers want to make 824 about the key itself, rather than the binding between a key and 825 a name. 827 0x20: Key revocation signature 828 The signature is calculated directly on the key being revoked. 829 A revoked key is not to be used. Only revocation signatures by 830 the key being revoked, or by an authorized revocation key, 831 should be considered valid revocation signatures. 833 0x28: Subkey revocation signature 834 The signature is calculated directly on the subkey being 835 revoked. A revoked subkey is not to be used. Only revocation 836 signatures by the top-level signature key which is bound to this 837 subkey, or by an authorized revocation key, should be considered 838 valid revocation signatures. 840 0x30: Certification revocation signature 841 This signature revokes an earlier user ID certification 842 signature (signature class 0x10 through 0x13). It should be 843 issued by the same key which issued the revoked signature or an 844 authorized revocation key The signature should have a later 845 creation date than the signature it revokes. 847 0x40: Timestamp signature. 848 This signature is only meaningful for the timestamp contained in 849 it. 851 5.2.2. Version 3 Signature Packet Format 853 The body of a version 3 Signature Packet contains: 855 - One-octet version number (3). 857 - One-octet length of following hashed material. MUST be 5. 859 - One-octet signature type. 861 - Four-octet creation time. 863 - Eight-octet key ID of signer. 865 - One-octet public key algorithm. 867 - One-octet hash algorithm. 869 - Two-octet field holding left 16 bits of signed hash value. 871 - One or more multi-precision integers comprising the signature. 872 This portion is algorithm specific, as described below. 874 The data being signed is hashed, and then the signature type and 875 creation time from the signature packet are hashed (5 additional 876 octets). The resulting hash value is used in the signature 877 algorithm. The high 16 bits (first two octets) of the hash are 878 included in the signature packet to provide a quick test to reject 879 some invalid signatures. 881 Algorithm Specific Fields for RSA signatures: 883 - multiprecision integer (MPI) of RSA signature value m**d. 885 Algorithm Specific Fields for DSA signatures: 887 - MPI of DSA value r. 889 - MPI of DSA value s. 891 The signature calculation is based on a hash of the signed data, as 892 described above. The details of the calculation are different for 893 DSA signature than for RSA signatures. 895 With RSA signatures, the hash value is encoded as described in 896 PKCS-1 section 10.1.2, "Data encoding", producing an ASN.1 value of 897 type DigestInfo, and then padded using PKCS-1 block type 01 [PKCS1]. 898 This requires inserting the hash value as an octet string into an 899 ASN.1 structure. The object identifier for the type of hash being 900 used is included in the structure. The hexadecimal representations 901 for the currently defined hash algorithms are: 903 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02 905 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 907 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 909 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 911 The ASN.1 OIDs are: 913 - MD5: 1.2.840.113549.2.2 915 - MD5: 1.2.840.113549.2.5 917 - RIPEMD160: 1.3.36.3.2.1 919 - SHA-1: 1.3.14.3.2.26 921 DSA signatures SHOULD use hashes with a size of 160 bits, to match 922 q, the size of the group generated by the DSA key's generator value. 923 The hash function result is treated as a 160 bit number and used 924 directly in the DSA signature algorithm. 926 5.2.3. Version 4 Signature Packet Format 928 The body of a version 4 Signature Packet contains: 930 - One-octet version number (4). 932 - One-octet signature type. 934 - One-octet public key algorithm. 936 - One-octet hash algorithm. 938 - Two-octet scalar octet count for following hashed subpacket 939 data. 941 - Hashed subpacket data. (zero or more subpackets) 943 - Two-octet scalar octet count for following unhashed subpacket 944 data. 946 - Unhashed subpacket data. (zero or more subpackets) 948 - Two-octet field holding left 16 bits of signed hash value. 950 - One or more multi-precision integers comprising the signature. 951 This portion is algorithm specific, as described above. 953 The data being signed is hashed, and then the signature data from 954 the version number through the hashed subpacket data (inclusive) is 955 hashed. The resulting hash value is what is signed. The left 16 956 bits of the hash are included in the signature packet to provide a 957 quick test to reject some invalid signatures. 959 There are two fields consisting of signature subpackets. The first 960 field is hashed with the rest of the signature data, while the 961 second is unhashed. The second set of subpackets is not 962 cryptographically protected by the signature and should include only 963 advisory information. 965 The algorithms for converting the hash function result to a 966 signature are described in a section below. 968 5.2.3.1. Signature Subpacket Specification 970 The subpacket fields consist of zero or more signature subpackets. 971 Each set of subpackets is preceded by a two-octet scalar count of 972 the length of the set of subpackets. 974 Each subpacket consists of a subpacket header and a body. The 975 header consists of: 977 - the subpacket length (1, 2, or 5 octets) 979 - the subpacket type (1 octet) 981 - the subpacket specific data 983 The length includes the type octet but not this length. Its format 984 is the same as the "new" format packet header lengths. That is: 986 if the 1st octet < 192, then length is the octet value 988 if the 1st octet >= 192 and < 255, then length is 2 octets and 989 equal to (1st octet - 192) * 256 + (2nd octet) + 192 991 if the 1st octet = 255, then the subpacket length is a 992 four-octet scalar found in octets 2 through 5, as per the packet 993 header length. 995 The value of the subpacket type octet may be: 997 2 = signature creation time 998 3 = signature expiration time 999 4 = exportable 1000 5 = trust signature 1001 6 = regular expression 1002 7 = revocable 1003 9 = key expiration time 1004 10 = placeholder for backwards compatibility 1005 11 = preferred symmetric algorithms 1006 12 = revocation key 1007 16 = issuer key ID 1008 20 = notation data 1009 21 = preferred hash algorithms 1010 22 = preferred compression algorithms 1011 23 = key server preferences 1012 24 = preferred key server 1013 25 = primary user id 1014 26 = policy URL 1015 27 = key flags 1016 28 = Signer's user id 1017 100 to 110 = internal or user-defined 1019 An implementation SHOULD ignore any subpacket of a type that it does 1020 not recognize. 1022 Bit 7 of the subpacket type is the "critical" bit. If set, it 1023 denotes that the subpacket is one that is critical for the evaluator 1024 of the signature to recognize. If a subpacket is encountered which 1025 is marked critical but is unknown to the evaluating software, the 1026 evaluator SHOULD consider the signature to be in error. 1028 An evaluator may "recognize" a subpacket, but not implement it. The 1029 purpose of the critical bit is to allow the signer to tell an 1030 evaluator that it would prefer a new, unknown feature to generate an 1031 error than be ignored. 1033 Implementations SHOULD implement "preferences". 1035 5.2.3.2. Signature Subpacket Types 1037 A number of subpackets are currently defined. Some subpackets apply 1038 to the signature itself and some are attributes of the key. 1039 Subpackets that are found on a self-signature are placed on a user 1040 id certification made by the key itself. Note that a key may have 1041 more than one user id, and thus may have more than one 1042 self-signature, and differing subpackets. 1044 A self-signature is a binding signature made by the key the 1045 signature refers to. There are three types of self-signatures, the 1046 certification signatures (types 0x10-0x13), the direct-key signature 1047 (type 0x1f), and the subkey binding signature (type 0x18). For 1048 certification self-signatures, each user ID may have a 1049 self-signature, and thus different subpackets in those 1050 self-signatures. For subkey binding signatures, each subkey in fact 1051 has a self-signature. Subpackets that appear in a certification 1052 self-signature apply to the username, and subpackets that appear in 1053 the subkey self-signature apply to the subkey. Lastly, subpackets on 1054 the direct key signature apply to the entire key. 1056 Implementing software should interpret a self-signature's preference 1057 subpackets as narrowly as possible. For example, suppose a key has 1058 two usernames, Alice and Bob. Suppose that Alice prefers the 1059 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If 1060 the software locates this key via Alice's name, then the preferred 1061 algorithm is CAST5, if software locates the key via Bob's name, then 1062 the preferred algorithm is IDEA. If the key is located by key id, 1063 then algorithm of the default user id of the key provides the 1064 default symmetric algorithm. 1066 A subpacket may be found either in the hashed or unhashed subpacket 1067 sections of a signature. If a subpacket is not hashed, then the 1068 information in it cannot be considered definitive because it is not 1069 part of the signature proper. 1071 5.2.3.3. Signature creation time 1073 (4 octet time field) 1075 The time the signature was made. 1077 MUST be present in the hashed area. 1079 5.2.3.4. Issuer 1081 (8 octet key ID) 1083 The OpenPGP key ID of the key issuing the signature. 1085 MUST be present in the hashed area. 1087 5.2.3.5. Key expiration time 1089 (4 octet time field) 1091 The validity period of the key. This is the number of seconds after 1092 the key creation time that the key expires. If this is not present 1093 or has a value of zero, the key never expires. This is found only on 1094 a self-signature. 1096 5.2.3.6. Preferred symmetric algorithms 1098 (sequence of one-octet values) 1099 Symmetric algorithm numbers that indicate which algorithms the key 1100 holder prefers to use. The subpacket body is an ordered list of 1101 octets with the most preferred listed first. It is assumed that only 1102 algorithms listed are supported by the recipient's software. 1103 Algorithm numbers in section 9. This is only found on a 1104 self-signature. 1106 5.2.3.7. Preferred hash algorithms 1108 (array of one-octet values) 1110 Message digest algorithm numbers that indicate which algorithms the 1111 key holder prefers to receive. Like the preferred symmetric 1112 algorithms, the list is ordered. Algorithm numbers are in section 6. 1113 This is only found on a self-signature. 1115 5.2.3.8. Preferred compression algorithms 1117 (array of one-octet values) 1119 Compression algorithm numbers that indicate which algorithms the key 1120 holder prefers to use. Like the preferred symmetric algorithms, the 1121 list is ordered. Algorithm numbers are in section 6. If this 1122 subpacket is not included, ZIP is preferred. A zero denotes that 1123 uncompressed data is preferred; the key holder's software may not 1124 have compression software. This is only found on a self-signature. 1126 5.2.3.9. Signature expiration time 1128 (4 octet time field) 1130 The validity period of the signature. This is the number of seconds 1131 after the signature creation time that the signature expires. If 1132 this is not present or has a value of zero, it never expires. 1134 5.2.3.10. Exportable 1136 (1 octet of exportability, 0 for not, 1 for exportable) 1138 Signature's exportability status. Packet body contains a boolean 1139 flag indicating whether the signature is exportable. Signatures 1140 which are not exportable are ignored during export and import 1141 operations. If this packet is not present the signature is assumed 1142 to be exportable. 1144 5.2.3.11. Revocable 1146 (1 octet of revocability, 0 for not, 1 for revocable) 1148 Signature's revocability status. Packet body contains a boolean 1149 flag indicating whether the signature is revocable. Signatures 1150 which are not revocable have any later revocation signatures 1151 ignored. They represent a commitment by the signer that he cannot 1152 revoke his signature for the life of his key. If this packet is not 1153 present, the signature is revocable. 1155 5.2.3.12. Trust signature 1157 (1 octet "level" (depth), 1 octet of trust amount) 1159 Signer asserts that the key is not only valid, but also trustworthy, 1160 at the specified level. Level 0 has the same meaning as an ordinary 1161 validity signature. Level 1 means that the signed key is asserted 1162 to be a valid trusted introducer, with the 2nd octet of the body 1163 specifying the degree of trust. Level 2 means that the signed key is 1164 asserted to be trusted to issue level 1 trust signatures, i.e. that 1165 it is a "meta introducer". Generally, a level n trust signature 1166 asserts that a key is trusted to issue level n-1 trust signatures. 1167 The trust amount is in a range from 0-255, interpreted such that 1168 values less than 120 indicate partial trust and values of 120 or 1169 greater indicate complete trust. Implementations SHOULD emit values 1170 of 60 for partial trust and 120 for complete trust. 1172 5.2.3.13. Regular expression 1174 (null-terminated regular expression) 1176 Used in conjunction with trust signature packets (of level > 0) to 1177 limit the scope of trust which is extended. Only signatures by the 1178 target key on user IDs which match the regular expression in the 1179 body of this packet have trust extended by the trust packet. The 1180 regular expression uses the same syntax as the Henry Spencer's 1181 "almost public domain" regular expression package. A description of 1182 the syntax is found in a section below. 1184 5.2.3.14. Revocation key 1186 (1 octet of class, 1 octet of algid, 20 octets of fingerprint) 1188 Authorizes the specified key to issue revocation signatures for this 1189 key. Class octet must have bit 0x80 set, other bits are for future 1190 expansion to other kinds of signature authorizations. This is found 1191 on a self-signature. 1193 Authorizes the specified key to issue revocation signatures for this 1194 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1195 then this means that the revocation information is sensitive. Other 1196 bits are for future expansion to other kinds of authorizations. This 1197 is found on a self-signature. 1199 If the "sensitive" flag is set, the keyholder feels this subpacket 1200 contains private trust information that describes a real-world 1201 sensitive relationship. If this flag is set, implementations SHOULD 1202 NOT export this signature to other users except in cases where the 1203 data needs to be available: when the signature is being sent to the 1204 designated revoker, or when it is accompanied by a revocation 1205 signature from that revoker. Note that it may be appropriate to 1206 isolate this subpacket within a separate signature so that it is not 1207 combined with other subpackets which need to be exported. 1209 5.2.3.15. Notation Data 1211 (4 octets of flags, 2 octets of name length (M), 1212 2 octets of value length (N), 1213 M octets of name data, 1214 N octets of value data) 1216 This subpacket describes a "notation" on the signature that the 1217 issuer wishes to make. The notation has a name and a value, each of 1218 which are strings of octets. There may be more than one notation in 1219 a signature. Notations can be used for any extension the issuer of 1220 the signature cares to make. The "flags" field holds four octets of 1221 flags. 1223 All undefined flags MUST be zero. Defined flags are: 1225 First octet: 0x80 = human-readable. This note is text, a note 1226 from one person to another, and has no 1227 meaning to software. 1228 Other octets: none. 1230 5.2.3.16. Key server preferences 1232 (N octets of flags) 1234 This is a list of flags that indicate preferences that the key 1235 holder has about how the key is handled on a key server. All 1236 undefined flags MUST be zero. 1238 First octet: 0x80 = No-modify 1239 the key holder requests that this key only be modified or 1240 updated by the key holder or an administrator of the key server. 1242 This is found only on a self-signature. 1244 5.2.3.17. Preferred key server 1246 (String) 1248 This is a URL of a key server that the key holder prefers be used 1249 for updates. Note that keys with multiple user ids can have a 1250 preferred key server for each user id. Note also that since this is 1251 a URL, the key server can actually be a copy of the key retrieved by 1252 ftp, http, finger, etc. 1254 5.2.3.18. Primary user id 1256 (1 octet, boolean) 1258 This is a flag in a user id's self signature that states whether 1259 this user id is the main user id for this key. It is reasonable for 1260 an implementation to resolve ambiguities in preferences, etc. by 1261 referring to the primary user id. If this flag is absent, its value 1262 is zero. If more than one user id in a key is marked as primary, the 1263 implementation may resolve the ambiguity in any way it sees fit. 1265 5.2.3.19. Policy URL 1267 (String) 1269 This subpacket contains a URL of a document that describes the 1270 policy under which the signature was issued. 1272 5.2.3.20. Key Flags 1274 (Octet string) 1276 This subpacket contains a list of binary flags that hold information 1277 about a key. It is a string of octets, and an implementation MUST 1278 NOT assume a fixed size. This is so it can grow over time. If a list 1279 is shorter than an implementation expects, the unstated flags are 1280 considered to be zero. The defined flags are: 1282 First octet: 1284 0x01 - This key may be used to certify other keys. 1286 0x02 - This key may be used to sign data. 1288 0x04 - This key may be used to encrypt communications. 1290 0x08 - This key may be used to encrypt storage. 1292 0x10 - The private component of this key may have been split by 1293 a secret-sharing mechanism. 1295 0x80 - The private component of this key may be in the 1296 possession of more than one person. 1298 Usage notes: 1300 The flags in this packet may appear in self-signatures or in 1301 certification signatures. They mean different things depending on 1302 who is making the statement -- for example, a certification 1303 signature that has the "sign data" flag is stating that the 1304 certification is for that use. On the other hand, the 1305 "communications encryption" flag in a self-signature is stating a 1306 preference that a given key be used for communications. Note 1307 however, that it is a thorny issue to determine what is 1308 "communications" and what is "storage." This decision is left wholly 1309 up to the implementation; the authors of this document do not claim 1310 any special wisdom on the issue, and realize that accepted opinion 1311 may change. 1313 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1314 self-signature only; they are meaningless on a certification 1315 signature. They SHOULD be placed only on a direct-key signature 1316 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1317 the key the flag applies to. 1319 5.2.3.21. Signer's User ID 1321 This subpacket allows a keyholder to state which user id is 1322 responsible for the signing. Many keyholders use a single key for 1323 different purposes, such as business communications as well as 1324 personal communications. This subpacket allows such a keyholder to 1325 state which of their roles is making a signature. 1327 5.2.4. Computing Signatures 1329 All signatures are formed by producing a hash over the signature 1330 data, and then using the resulting hash in the signature algorithm. 1332 The signature data is simple to compute for document signatures 1333 (types 0x00 and 0x01), for which the document itself is the data. 1334 For standalone signatures, this is a null string. 1336 When a signature is made over a key, the hash data starts with the 1337 octet 0x99, followed by a two-octet length of the key, and then body 1338 of the key packet. (Note that this is an old-style packet header for 1339 a key packet with two-octet length.) A subkey signature (type 0x18) 1340 then hashes the subkey, using the same format as the main key. Key 1341 revocation signatures (types 0x20 and 0x28) hash only the key being 1342 revoked. 1344 A certification signature (type 0x10 through 0x13) hashes the user 1345 id being bound to the key into the hash context after the above 1346 data. A V3 certification hashes the contents of the name packet, 1347 without any header. A V4 certification hashes the constant 0xd4 1348 (which is an old-style packet header with the length-of-length set 1349 to zero), a four-octet number giving the length of the username, and 1350 then the username data. 1352 Once the data body is hashed, then a trailer is hashed. A V3 1353 signature hashes five octets of the packet body, starting from the 1354 signature type field. This data is the signature type, followed by 1355 the four-octet signature time. A V4 signature hashes the packet body 1356 starting from its first field, the version number, through the end 1357 of the hashed subpacket data. Thus, the fields hashed are the 1358 signature version, the signature type, the public key algorithm, the 1359 hash algorithm, the hashed subpacket length, and the hashed 1360 subpacket body. 1362 V4 signatures also hash in a final trailer of six octets: the 1363 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1364 big-endian number that is the length of the hashed data from the 1365 signature packet (note that this number does not include these final 1366 six octets. 1368 After all this has been hashed, the resulting hash field is used in 1369 the signature algorithm, and placed at the end of the signature 1370 packet. 1372 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 1374 The Symmetric-Key Encrypted Session Key packet holds the 1375 symmetric-key encryption of a session key used to encrypt a message. 1376 Zero or more Encrypted Session Key packets and/or Symmetric-Key 1377 Encrypted Session Key packets may precede a Symmetrically Encrypted 1378 Data Packet that holds an encrypted message. The message is 1379 encrypted with a session key, and the session key is itself 1380 encrypted and stored in the Encrypted Session Key packet or the 1381 Symmetric-Key Encrypted Session Key packet. 1383 If the Symmetrically Encrypted Data Packet is preceded by one or 1384 more Symmetric-Key Encrypted Session Key packets, each specifies a 1385 passphrase which may be used to decrypt the message. This allows a 1386 message to be encrypted to a number of public keys, and also to one 1387 or more pass phrases. This packet type is new, and is not generated 1388 by PGP 2.x or PGP 5.0. 1390 The body of this packet consists of: 1392 - A one-octet version number. The only currently defined version 1393 is 4. 1395 - A one-octet number describing the symmetric algorithm used. 1397 - A string-to-key (S2K) specifier, length as defined above. 1399 - Optionally, the encrypted session key itself, which is decrypted 1400 with the string-to-key object. 1402 If the encrypted session key is not present (which can be detected 1403 on the basis of packet length and S2K specifier size), then the S2K 1404 algorithm applied to the passphrase produces the session key for 1405 decrypting the file, using the symmetric cipher algorithm from the 1406 Symmetric-Key Encrypted Session Key packet. 1408 If the encrypted session key is present, the result of applying the 1409 S2K algorithm to the passphrase is used to decrypt just that 1410 encrypted session key field, using CFB mode with an IV of all zeros. 1411 The decryption result consists of a one-octet algorithm identifier 1412 that specifies the symmetric-key encryption algorithm used to 1413 encrypt the following Symmetrically Encrypted Data Packet, followed 1414 by the session key octets themselves. 1416 Note: because an all-zero IV is used for this decryption, the S2K 1417 specifier MUST use a salt value, either a a Salted S2K or an 1418 Iterated-Salted S2K. The salt value will insure that the decryption 1419 key is not repeated even if the passphrase is reused. 1421 5.4. One-Pass Signature Packets (Tag 4) 1423 The One-Pass Signature packet precedes the signed data and contains 1424 enough information to allow the receiver to begin calculating any 1425 hashes needed to verify the signature. It allows the Signature 1426 Packet to be placed at the end of the message, so that the signer 1427 can compute the entire signed message in one pass. 1429 A One-Pass Signature does not interoperate with PGP 2.6.x or 1430 earlier. 1432 The body of this packet consists of: 1434 - A one-octet version number. The current version is 3. 1436 - A one-octet signature type. Signature types are described in 1437 section 5.2.3. 1439 - A one-octet number describing the hash algorithm used. 1441 - A one-octet number describing the public key algorithm used. 1443 - An eight-octet number holding the key ID of the signing key. 1445 - A one-octet number holding a flag showing whether the signature 1446 is nested. A zero value indicates that the next packet is 1447 another One-Pass Signature packet which describes another 1448 signature to be applied to the same message data. 1450 5.5. Key Material Packet 1452 A key material packet contains all the information about a public or 1453 private key. There are four variants of this packet type, and two 1454 major versions. Consequently, this section is complex. 1456 5.5.1. Key Packet Variants 1458 5.5.1.1. Public Key Packet (Tag 6) 1459 A Public Key packet starts a series of packets that forms an OpenPGP 1460 key (sometimes called an OpenPGP certificate). 1462 5.5.1.2. Public Subkey Packet (Tag 14) 1464 A Public Subkey packet (tag 14) has exactly the same format as a 1465 Public Key packet, but denotes a subkey. One or more subkeys may be 1466 associated with a top-level key. By convention, the top-level key 1467 provides signature services, and the subkeys provide encryption 1468 services. 1470 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1471 packet. This tag was selected for reuse because no previous version 1472 of PGP ever emitted comment packets but they did properly ignore 1473 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1474 cause it to fail, providing a limited degree of backwards 1475 compatibility. 1477 5.5.1.3. Secret Key Packet (Tag 5) 1479 A Secret Key packet contains all the information that is found in a 1480 Public Key packet, including the public key material, but also 1481 includes the secret key material after all the public key fields. 1483 5.5.1.4. Secret Subkey Packet (Tag 7) 1485 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1486 Key packet, and has exactly the same format. 1488 5.5.2. Public Key Packet Formats 1490 There are two versions of key-material packets. Version 3 packets 1491 were first generated by PGP 2.6. Version 2 packets are identical in 1492 format to Version 3 packets, but are generated by PGP 2.5 or before. 1493 V2 packets are deprecated and they MUST NOT be generated. 1495 PGP 5.0 introduced version 4 packets, with new fields and semantics. 1496 PGP 2.6.x will not accept key-material packets with versions 1497 greater than 3. 1499 OpenPGP implementations SHOULD create keys with version 4 format. An 1500 implementation MAY generate a V3 key to ensure interoperability with 1501 old software; note, however, that V4 keys correct some security 1502 deficiencies in V3 keys. These deficiencies are described below. An 1503 implementation MUST NOT create a V3 key with a public key algorithm 1504 other than RSA. 1506 A version 3 public key or public subkey packet contains: 1508 - A one-octet version number (3). 1510 - A four-octet number denoting the time that the key was created. 1512 - A two-octet number denoting the time in days that this key is 1513 valid. If this number is zero, then it does not expire. 1515 - A one-octet number denoting the public key algorithm of this key 1517 - A series of multi-precision integers comprising the key 1518 material: 1520 - a multiprecision integer (MPI) of RSA public modulus n; 1522 - an MPI of RSA public encryption exponent e. 1524 V3 keys SHOULD only be used for backards compatibility because of 1525 three weaknesses in them. First, it is relatively easy to construct 1526 a V3 key that has the same key ID as any other key because the key 1527 ID is simply the low 64 bits of the public modulus. Secondly, 1528 because the fingerprint of a V3 key hashes the key material, but not 1529 its length, which increases the opportunity for fingerprint 1530 collisions. Third, there are minor weaknesses in the MD5 hash 1531 algorithm that make developers prefer other algorithms. See below 1532 for a fuller discussion of key IDs and fingerprints. 1534 The version 4 format is similar to the version 3 format except for 1535 the absence of a validity period. This has been moved to the 1536 signature packet. In addition, fingerprints of version 4 keys are 1537 calculated differently from version 3 keys, as described in section 1538 "Enhanced Key Formats." 1540 A version 4 packet contains: 1542 - A one-octet version number (4). 1544 - A four-octet number denoting the time that the key was created. 1546 - A one-octet number denoting the public key algorithm of this key 1548 - A series of multi-precision integers comprising the key 1549 material. This algorithm-specific portion is: 1551 Algorithm Specific Fields for RSA public keys: 1553 - multiprecision integer (MPI) of RSA public modulus n; 1555 - MPI of RSA public encryption exponent e. 1557 Algorithm Specific Fields for DSA public keys: 1559 - MPI of DSA prime p; 1560 - MPI of DSA group order q (q is a prime divisor of p-1); 1562 - MPI of DSA group generator g; 1564 - MPI of DSA public key value y (= g**x where x is secret). 1566 Algorithm Specific Fields for Elgamal public keys: 1568 - MPI of Elgamal prime p; 1570 - MPI of Elgamal group generator g; 1572 - MPI of Elgamal public key value y (= g**x where x is 1573 secret). 1575 5.5.3. Secret Key Packet Formats 1577 The Secret Key and Secret Subkey packets contain all the data of the 1578 Public Key and Public Subkey packets, with additional 1579 algorithm-specific secret key data appended, in encrypted form. 1581 The packet contains: 1583 - A Public Key or Public Subkey packet, as described above 1585 - One octet indicating string-to-key usage conventions. 0 1586 indicates that the secret key data is not encrypted. 255 1587 indicates that a string-to-key specifier is being given. Any 1588 other value is a symmetric-key encryption algorithm specifier. 1590 - [Optional] If string-to-key usage octet was 255, a one-octet 1591 symmetric encryption algorithm. 1593 - [Optional] If string-to-key usage octet was 255, a string-to-key 1594 specifier. The length of the string-to-key specifier is implied 1595 by its type, as described above. 1597 - [Optional] If secret data is encrypted, eight-octet Initial 1598 Vector (IV). 1600 - Encrypted multi-precision integers comprising the secret key 1601 data. These algorithm-specific fields are as described below. 1603 - Two-octet checksum of the plaintext of the algorithm-specific 1604 portion (sum of all octets, mod 65536). 1606 Algorithm Specific Fields for RSA secret keys: 1608 - multiprecision integer (MPI) of RSA secret exponent d. 1610 - MPI of RSA secret prime value p. 1612 - MPI of RSA secret prime value q (p < q). 1614 - MPI of u, the multiplicative inverse of p, mod q. 1616 Algorithm Specific Fields for DSA secret keys: 1618 - MPI of DSA secret exponent x. 1620 Algorithm Specific Fields for Elgamal secret keys: 1622 - MPI of Elgamal secret exponent x. 1624 Secret MPI values can be encrypted using a passphrase. If a 1625 string-to-key specifier is given, that describes the algorithm for 1626 converting the passphrase to a key, else a simple MD5 hash of the 1627 passphrase is used. Implementations SHOULD use a string-to-key 1628 specifier; the simple hash is for backwards compatibility. The 1629 cipher for encrypting the MPIs is specified in the secret key 1630 packet. 1632 Encryption/decryption of the secret data is done in CFB mode using 1633 the key created from the passphrase and the Initial Vector from the 1634 packet. A different mode is used with V3 keys (which are onlyRSA) 1635 than with other key formats. With V3 keys, the MPI bit count prefix 1636 (i.e., the first two octets) is not encrypted. Only the MPI 1637 non-prefix data is encrypted. Furthermore, the CFB state is 1638 resynchronized at the beginning of each new MPI value, so that the 1639 CFB block boundary is aligned with the start of the MPI data. 1641 With V4 keys, a simpler method is used. All secret MPI values are 1642 encrypted in CFB mode, including the MPI bitcount prefix. 1644 The 16-bit checksum that follows the algorithm-specific portion is 1645 the algebraic sum, mod 65536, of the plaintext of all the 1646 algorithm-specific octets (including MPI prefix and data). With V3 1647 keys, the checksum is stored in the clear. With V4 keys, the 1648 checksum is encrypted like the algorithm-specific data. This value 1649 is used to check that the passphrase was correct. 1651 5.6. Compressed Data Packet (Tag 8) 1653 The Compressed Data packet contains compressed data. Typically, this 1654 packet is found as the contents of an encrypted packet, or following 1655 a Signature or One-Pass Signature packet, and contains literal data 1656 packets. 1658 The body of this packet consists of: 1660 - One octet that gives the algorithm used to compress the packet. 1662 - The remainder of the packet is compressed data. 1664 A Compressed Data Packet's body contains an block that compresses 1665 some set of packets. See section "Packet Composition" for details on 1666 how messages are formed. 1668 ZIP-compressed packets are compressed with raw RFC1951 DEFLATE 1669 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 1670 implementation uses more bits of compression, it cannot be 1671 decompressed by PGP V2.6 1673 5.7. Symmetrically Encrypted Data Packet (Tag 9) 1675 The Symmetrically Encrypted Data packet contains data encrypted with 1676 a symmetric-key algorithm. When it has been decrypted, it will 1677 typically contain other packets (often literal data packets or 1678 compressed data packets). 1680 The body of this packet consists of: 1682 - Encrypted data, the output of the selected symmetric-key cipher 1683 operating in PGP's variant of Cipher Feedback (CFB) mode. 1685 The symmetric cipher used may be specified in an Public-Key or 1686 Symmetric-Key Encrypted Session Key packet which precedes the 1687 Symmetrically Encrypted Data Packet. In that case, the cipher 1688 algorithm octet is prefixed to the session key before it is 1689 encrypted. If no packets of these types precede the encrypted data, 1690 the IDEA algorithm is used with the session key calculated as the 1691 MD5 hash of the passphrase. 1693 The data is encrypted in CFB mode, with a CFB shift size equal to 1694 the cipher's block size. The Initial Vector (IV) is specified as 1695 all zeros. Instead of using an IV, OpenPGP prefixes a 10 octet 1696 string to the data before it is encrypted. The first eight octets 1697 are random, and the 9th and 10th octets are copies of the 7th and 1698 8th octets, respectivelly. After encrypting the first 10 octets, the 1699 CFB state is resynchronized if the cipher block size is 8 octets or 1700 less. The last 8 octets of ciphertext are passed through the cipher 1701 and the block boundary is reset. 1703 The repetition of 16 bits in the 80 bits of random data prepended to 1704 the message allows the receiver to immediately check whether the 1705 session key is incorrect. 1707 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 1709 An experimental version of PGP used this packet as the Literal 1710 packet, but no released version of PGP generated Literal packets 1711 with this tag. With PGP 5.x, this packet has been re-assigned and is 1712 reserved for use as the Marker packet. 1714 The body of this packet consists of: 1716 - The three octets 0x60, 0x47, 0x60 (which spell "PGP" in UTF-8). 1718 Such a packet MUST be ignored when received. It may be placed at 1719 the beginning of a message that uses features not available in PGP 1720 2.6.x in order to cause that version to report that newer software 1721 is necessary to process the message. 1723 5.9. Literal Data Packet (Tag 11) 1725 A Literal Data packet contains the body of a message; data that is 1726 not to be further interpreted. 1728 The body of this packet consists of: 1730 - A one-octet field that describes how the data is formatted. 1732 If it is a 'b' (0x62), then the literal packet contains binary data. 1733 If it is a 't' (0x74), then it contains text data, and thus may need 1734 line ends converted to local form, or other text-mode changes. RFC 1735 1991 also defined a value of 'l' as a 'local' mode for machine-local 1736 conversions. This use is now deprecated. 1738 - File name as a string (one-octet length, followed by file name), 1739 if the encrypted data should be saved as a file. 1741 If the special name "_CONSOLE" is used, the message is considered to 1742 be "for your eyes only". This advises that the message data is 1743 unusually sensitive, and the receiving program should process it 1744 more carefully, perhaps avoiding storing the received data to disk, 1745 for example. 1747 - A four-octet number that indicates the modification date of the 1748 file, or the creation time of the packet, or a zero that 1749 indicates the present time. 1751 - The remainder of the packet is literal data. 1753 Text data is stored with text endings (i.e. network-normal 1754 line endings). These should be converted to native line endings by 1755 the receiving software. 1757 5.10. Trust Packet (Tag 12) 1759 The Trust packet is used only within keyrings and is not normally 1760 exported. Trust packets contain data that record the user's 1761 specifications of which key holders are trustworthy introducers, 1762 along with other information that implementing software uses for 1763 trust information. 1765 Trust packets SHOULD NOT be emitted to output streams that are 1766 transferred to other users, and they SHOULD be ignored on any input 1767 other than local keyring files. 1769 5.11. User ID Packet (Tag 13) 1771 A User ID packet consists of data which is intended to represent the 1772 name and email address of the key holder. By convention, it 1773 includes an RFC822 mail name, but there are no restrictions on its 1774 content. The packet length in the header specifies the length of 1775 the user id. If it is text, it is encoded in UTF-8. 1777 6. Radix-64 Conversions 1779 As stated in the introduction, OpenPGP's underlying native 1780 representation for objects is a stream of arbitrary octets, and some 1781 systems desire these objects to be immune to damage caused by 1782 character set translation, data conversions, etc. 1784 In principle, any printable encoding scheme that met the 1785 requirements of the unsafe channel would suffice, since it would not 1786 change the underlying binary bit streams of the native OpenPGP data 1787 structures. The OpenPGP standard specifies one such printable 1788 encoding scheme to ensure interoperability. 1790 OpenPGP's Radix-64 encoding is composed of two parts: a base64 1791 encoding of the binary data, and a checksum. The base64 encoding is 1792 identical to the MIME base64 content-transfer-encoding [RFC 2045, 1793 Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to 1794 protect the raw binary data. 1796 The checksum is a 24-bit CRC converted to four characters of 1797 radix-64 encoding by the same MIME base64 transformation, preceded 1798 by an equals sign (=). The CRC is computed by using the generator 1799 0x864CFB and an initialization of 0xB704CE. The accumulation is 1800 done on the data before it is converted to radix-64, rather than on 1801 the converted data. A sample implementation of this algorithm is in 1802 the next section. 1804 The checksum with its leading equal sign MAY appear on the first 1805 line after the Base64 encoded data. 1807 Rationale for CRC-24: The size of 24 bits fits evenly into printable 1808 base64. The nonzero initialization can detect more errors than a 1809 zero initialization. 1811 6.1. An Implementation of the CRC-24 in "C" 1813 #define CRC24_INIT 0xb704ce 1814 #define CRC24_POLY 0x1864cfb 1815 typedef long crc24; 1816 crc24 crc_octets(unsigned char *octets, size_t len) 1817 { 1818 crc24 crc = CRC24_INIT; 1819 int i; 1821 while (len--) { 1822 crc ^= *octets++; 1823 for (i = 0; i < 8; i++) { 1824 crc <<= 1; 1825 if (crc & 0x1000000) 1826 crc ^= CRC24_POLY; 1827 } 1828 } 1829 return crc; 1830 } 1832 6.2. Forming ASCII Armor 1834 When OpenPGP encodes data into ASCII Armor, it puts specific headers 1835 around the data, so OpenPGP can reconstruct the data later. OpenPGP 1836 informs the user what kind of data is encoded in the ASCII armor 1837 through the use of the headers. 1839 Concatenating the following data creates ASCII Armor: 1841 - An Armor Header Line, appropriate for the type of data 1843 - Armor Headers 1845 - A blank (zero-length, or containing only whitespace) line 1847 - The ASCII-Armored data 1849 - An Armor Checksum 1851 - The Armor Tail, which depends on the Armor Header Line. 1853 An Armor Header Line consists of the appropriate header line text 1854 surrounded by five (5) dashes ('-', 0x2D) on either side of the 1855 header line text. The header line text is chosen based upon the 1856 type of data that is being encoded in Armor, and how it is being 1857 encoded. Header line texts include the following strings: 1859 BEGIN PGP MESSAGE 1860 Used for signed, encrypted, or compressed files 1862 BEGIN PGP PUBLIC KEY BLOCK 1863 Used for armoring public keys 1865 BEGIN PGP PRIVATE KEY BLOCK 1866 Used for armoring private keys 1868 BEGIN PGP MESSAGE, PART X/Y 1869 Used for multi-part messages, where the armor is split amongst Y 1870 parts, and this is the Xth part out of Y. 1872 BEGIN PGP MESSAGE, PART X 1873 Used for multi-part messages, where this is the Xth part of an 1874 unspecified number of parts. Requires the MESSAGE-ID Armor 1875 Header to be used. 1877 BEGIN PGP SIGNATURE 1878 Used for detached signatures, OpenPGP/MIME signatures, and 1879 signatures following clearsigned messages 1881 The Armor Headers are pairs of strings that can give the user or the 1882 receiving OpenPGP implementation some information about how to 1883 decode or use the message. The Armor Headers are a part of the 1884 armor, not a part of the message, and hence are not protected by any 1885 signatures applied to the message. 1887 The format of an Armor Header is that of a key-value pair. A colon 1888 (':' 0x38) and a single space (0x20) separate the key and value. 1889 OpenPGP should consider improperly formatted Armor Headers to be 1890 corruption of the ASCII Armor. Unknown keys should be reported to 1891 the user, but OpenPGP should continue to process the message. 1893 Currently defined Armor Header Keys are: 1895 - "Version", which states the OpenPGP Version used to encode the 1896 message. 1898 - "Comment", a user-defined comment. 1900 - "MessageID", a 32-character string of printable characters. The 1901 string must be the same for all parts of a multi-part message 1902 that uses the "PART X" Armor Header. MessageID strings should 1903 be unique enough that the recipient of the mail can associate 1904 all the parts of a message with each other. A good checksum or 1905 cryptographic hash function is sufficent. 1907 The MessageID SHOULD NOT appear unless it is in a multi-part 1908 message. If it appears at all, it MUST be computed from the 1909 finished (encrypted, signed, etc.) message in a deterministic 1910 fashion, rather than contain a purely random value. This is to 1911 allow the legitimate recipient to determine that the MessageID 1912 cannot serve as a covert means of leaking cryptographic key 1913 information. 1915 The Armor Tail Line is composed in the same manner as the Armor 1916 Header Line, except the string "BEGIN" is replaced by the string 1917 "END." 1919 6.3. Encoding Binary in Radix-64 1921 The encoding process represents 24-bit groups of input bits as 1922 output strings of 4 encoded characters. Proceeding from left to 1923 right, a 24-bit input group is formed by concatenating three 8-bit 1924 input groups. These 24 bits are then treated as four concatenated 1925 6-bit groups, each of which is translated into a single digit in the 1926 Radix-64 alphabet. When encoding a bit stream with the Radix-64 1927 encoding, the bit stream must be presumed to be ordered with the 1928 most-significant-bit first. That is, the first bit in the stream 1929 will be the high-order bit in the first 8-bit octet, and the eighth 1930 bit will be the low-order bit in the first 8-bit octet, and so on. 1932 +--first octet--+-second octet--+--third octet--+ 1933 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 1934 +-----------+---+-------+-------+---+-----------+ 1935 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 1936 +--1.index--+--2.index--+--3.index--+--4.index--+ 1938 Each 6-bit group is used as an index into an array of 64 printable 1939 characters from the table below. The character referenced by the 1940 index is placed in the output string. 1942 Value Encoding Value Encoding Value Encoding Value Encoding 1943 0 A 17 R 34 i 51 z 1944 1 B 18 S 35 j 52 0 1945 2 C 19 T 36 k 53 1 1946 3 D 20 U 37 l 54 2 1947 4 E 21 V 38 m 55 3 1948 5 F 22 W 39 n 56 4 1949 6 G 23 X 40 o 57 5 1950 7 H 24 Y 41 p 58 6 1951 8 I 25 Z 42 q 59 7 1952 9 J 26 a 43 r 60 8 1953 10 K 27 b 44 s 61 9 1954 11 L 28 c 45 t 62 + 1955 12 M 29 d 46 u 63 / 1956 13 N 30 e 47 v 1957 14 O 31 f 48 w (pad) = 1958 15 P 32 g 49 x 1959 16 Q 33 h 50 y 1961 The encoded output stream must be represented in lines of no more 1962 than 76 characters each. 1964 Special processing is performed if fewer than 24 bits are available 1965 at the end of the data being encoded. There are three possibilities: 1967 1. The last data group has 24 bits (3 octets). No special 1968 processing is needed. 1970 2. The last data group has 16 bits (2 octets). The first two 6-bit 1971 groups are processed as above. The third (incomplete) data group 1972 has two zero-value bits added to it, and is processed as above. 1973 A pad character (=) is added to the output. 1975 3. The last data group has 8 bits (1 octet). The first 6-bit group 1976 is processed as above. The second (incomplete) data group has 1977 four zero-value bits added to it, and is processed as above. Two 1978 pad characters (=) are added to the output. 1980 6.4. Decoding Radix-64 1982 Any characters outside of the base64 alphabet are ignored in 1983 Radix-64 data. Decoding software must ignore all line breaks or 1984 other characters not found in the table above. 1986 In Radix-64 data, characters other than those in the table, line 1987 breaks, and other white space probably indicate a transmission 1988 error, about which a warning message or even a message rejection 1989 might be appropriate under some circumstances. 1991 Because it is used only for padding at the end of the data, the 1992 occurrence of any "=" characters may be taken as evidence that the 1993 end of the data has been reached (without truncation in transit). No 1994 such assurance is possible, however, when the number of octets 1995 transmitted was a multiple of three and no "=" characters are 1996 present. 1998 6.5. Examples of Radix-64 2000 Input data: 0x14fb9c03d97e 2001 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2002 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2003 11111110 2004 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 2005 111110 2006 Decimal: 5 15 46 28 0 61 37 62 2007 Output: F P u c A 9 l + 2009 Input data: 0x14fb9c03d9 2010 Hex: 1 4 f b 9 c | 0 3 d 9 2011 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2012 pad with 00 2013 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2014 Decimal: 5 15 46 28 0 61 36 2015 pad with = 2016 Output: F P u c A 9 k = 2017 Input data: 0x14fb9c03 2018 Hex: 1 4 f b 9 c | 0 3 2019 8-bit: 00010100 11111011 10011100 | 00000011 2020 pad with 0000 2021 6-bit: 000101 001111 101110 011100 | 000000 110000 2022 Decimal: 5 15 46 28 0 48 2023 pad with = = 2024 Output: F P u c A w = = 2026 6.6. Example of an ASCII Armored Message 2028 -----BEGIN PGP MESSAGE----- 2029 Version: OpenPGP 1.0 2031 yCoBc07MUy9RSMyrzM9LVchOTS1QSFQoTk0uSgUKFuWX5qUoZKQWpdpzAQA= 2032 =jYsF 2033 -----END PGP MESSAGE----- 2035 Note that this example is indented by two spaces. 2037 7. Cleartext signature framework 2039 It is desirable to sign a textual octet stream without ASCII 2040 armoring the stream itself, so the signed text is still readable 2041 without special software. In order to bind a signature to such a 2042 cleartext, this framework is used. (Note that RFC 2015 defines 2043 another way to clear sign messages for environments that support 2044 MIME.) 2046 The cleartext signed message consists of: 2048 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2049 single line, 2051 - Zero or more "Hash" Armor Headers, 2053 - Exactly one empty line not included into the message digest, 2055 - The dash-escaped cleartext that is included into the message 2056 digest, 2058 - The ASCII armored signature(s) including the Armor Header and 2059 Armor Tail Lines. 2061 If the "Hash" armor header is given, the specified message digest 2062 algorithm is used for the signature. If there are no such headers, 2063 SHA-1 is used. If more than one message digest is used in the 2064 signature, the "Hash" armor header contains a comma-delimited list 2065 of used message digests. 2067 Current message digest names are described below with the algorithm 2068 IDs. 2070 7.1. Dash-Escaped Text 2072 The cleartext content of the message must also be dash-escaped. 2074 Dash escaped cleartext is the ordinary cleartext where every line 2075 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2076 (0x2D) and space ' ' (0x20). This prevents the parser from 2077 recognizing armor headers of the cleartext itself. The message 2078 digest is computed using the cleartext itself, not the dash escaped 2079 form. 2081 As with binary signatures on text documents, a cleartext signature 2082 is calculated on the text using canonical line endings. 2083 The line ending (i.e. the ) before the '-----BEGIN PGP 2084 SIGNATURE-----' line that terminates the signed text is not 2085 considered part of the signed text. 2087 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of 2088 any line is ignored when the cleartext signature is calculated. 2090 8. Regular Expressions 2092 A regular expression is zero or more branches, separated by '|'. It 2093 matches anything that matches one of the branches. 2095 A branch is zero or more pieces, concatenated. It matches a match 2096 for the first, followed by a match for the second, etc. 2098 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2099 followed by '*' matches a sequence of 0 or more matches of the atom. 2100 An atom followed by '+' matches a sequence of 1 or more matches of 2101 the atom. An atom followed by '?' matches a match of the atom, or 2102 the null string. 2104 An atom is a regular expression in parentheses (matching a match for 2105 the regular expression), a range (see below), '.' (matching any 2106 single character), '^' (matching the null string at the beginning of 2107 the input string), '$' (matching the null string at the end of the 2108 input string), a '\' followed by a single character (matching that 2109 char- acter), or a single character with no other significance 2110 (matching that character). 2112 A range is a sequence of characters enclosed in '[]'. It normally 2113 matches any single character from the sequence. If the sequence 2114 begins with '^', it matches any single character not from the rest 2115 of the sequence. If two characters in the sequence are separated by 2116 '-', this is shorthand for the full list of ASCII characters between 2117 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2118 ']' in the sequence, make it the first character (following a 2119 possible '^'). To include a literal '-', make it the first or last 2120 character. 2122 9. Constants 2124 This section describes the constants used in OpenPGP. 2126 Note that these tables are not exhaustive lists; an implementation 2127 MAY implement an algorithm not on these lists. 2129 See the section "Notes on Algorithms" below for more discussion of 2130 the algorithms. 2132 9.1. Public Key Algorithms 2134 ID Algorithm 2135 -- --------- 2136 1 - RSA (Encrypt or Sign) 2137 2 - RSA Encrypt-Only 2138 3 - RSA Sign-Only 2139 16 - Elgamal (Encrypt-Only), see [ELGAMAL] 2140 17 - DSA (Digital Signature Standard) 2141 18 - Elliptic Curve 2142 19 - ECDSA 2143 20 - Elgamal (Encrypt or Sign) 2144 21 - Diffie-Hellman (X9.42) 2145 100 to 110 - Private/Experimental algorithm. 2147 Implementations MUST implement DSA for signatures, and Elgamal for 2148 encryption. Implementations SHOULD implement RSA keys. 2149 Implementations MAY implement any other algorithm. 2151 9.2. Symmetric Key Algorithms 2153 ID Algorithm 2154 -- --------- 2155 0 - Plaintext or unencrypted data 2156 1 - IDEA 2157 2 - Triple-DES (DES-EDE, as per spec - 2158 168 bit key derived from 192) 2159 3 - CAST5 (128 bit key) 2160 4 - Blowfish (128 bit key, 16 rounds) 2161 5 - SAFER-SK128 (13 rounds) 2162 6 - DES/SK 2163 100 to 110 - Private/Experimental algorithm. 2165 Implementations MUST implement Triple-DES. Implementations SHOULD 2166 implement IDEA and CAST5.Implementations MAY implement any other 2167 algorithm. 2169 9.3. Compression Algorithms 2171 ID Algorithm 2172 -- --------- 2173 0 - Uncompressed 2174 1 - ZIP 2175 100 to 110 - Private/Experimental algorithm. 2177 Implementations MUST implement uncompressed data. Implementations 2178 SHOULD implement ZIP. 2180 9.4. Hash Algorithms 2182 ID Algorithm Text Name 2183 -- --------- ---- ---- 2184 1 - MD5 "MD5" 2185 2 - SHA-1 "SHA1" 2186 3 - RIPE-MD/160 "RIPEMD160" 2187 4 - HAVAL (5 pass, 160-bit) "HAVAL-5-160" 2188 5 - MD2 "MD2" 2189 100 to 110 - Private/Experimental algorithm. 2191 Implementations MUST implement SHA-1. Implementations SHOULD 2192 implement MD5. 2194 10. Packet Composition 2196 OpenPGP packets are assembled into sequences in order to create 2197 messages 2199 and to transfer keys. Not all possible packet sequences are 2200 meaningful and correct. This describes the rules for how packets 2201 should be placed into sequences. 2203 10.1. Transferable Public Keys 2205 OpenPGP users may transfer public keys. The essential elements of a 2206 transferable public key are: 2208 - One Public Key packet 2210 - Zero or more revocation signatures 2212 - One or more User ID packets 2214 - After each User ID packet, zero or more Signature packets 2216 - Zero or more Subkey packets 2218 - After each Subkey packet, one or more Signature packets 2220 The Public Key packet occurs first. Each of the following User ID 2221 packets provides the identity of the owner of this public key. If 2222 there are multiple User ID packets, this corresponds to multiple 2223 means of identifying the same unique individual user; for example, a 2224 user may have more than one email address, and construct a User ID 2225 for each one. 2227 Immediately following each User ID packet, there are zero or more 2228 signature packets. Each signature packet is calculated on the 2229 immediately preceding User ID packet and the initial Public Key 2230 packet. The signature serves to certify the corresponding public key 2231 and user ID. In effect, the signer is testifying to his or her 2232 belief that this public key belongs to the user identified by this 2233 user ID. 2235 After the User ID packets there may be one or more Subkey packets. 2236 In general, subkeys are provided in cases where the top-level public 2237 key is a signature-only key. However, any V4 key may have subkeys, 2238 and the subkeys may be encryption-only keys, signature-only keys, or 2239 general-purpose keys. 2241 Each Subkey packet must be followed by at least one Signature 2242 packet, which should be of the subkey binding signature type, issued 2243 by the top level key. 2245 Subkey and Key packets may each be followed by a revocation 2246 Signature packet to indicate that the key is revoked. Revocation 2247 signatures are only accepted if they are issued by the key itself, 2248 or by a key which is authorized to issue revocations via a 2249 revocation key subpacket in a self-signature by the top level key. 2251 Transferable public key packet sequences may be concatenated to 2252 allow transferring multiple public keys in one operation. 2254 10.2. OpenPGP Messages 2256 An OpenPGP message is a packet or sequence of packets that 2257 corresponds to the following grammatical rules (comma represents 2258 sequential composition, and vertical bar separates alternatives): 2260 OpenPGP Message :- Encrypted Message | Signed Message | 2261 Compressed Message | Literal Message. 2263 Compressed Message :- Compressed Data Packet. 2265 Literal Message :- Literal Data Packet. 2267 ESK :- Pubic Key Encrypted Session Key Packet | 2268 Symmetric-Key Encrypted Session Key Packet. 2270 ESK Sequence :- ESK | ESK Sequence, ESK. 2272 Encrypted Message :- Symmetrically Encrypted Data Packet | 2273 ESK Sequence, Symmetrically Encrypted Data Packet. 2275 One-Pass Signed Message :- One-Pass Signature Packet, 2276 OpenPGP Message, Signature Packet. 2278 Signed Message :- Signature Packet, OpenPGP Message | 2279 One-Pass Signed Message. 2281 In addition, decrypting a Symmetrically Encrypted Data packet and 2283 decompressing a Compressed Data packet must yield a valid OpenPGP 2284 Message. 2286 11. Enhanced Key Formats 2288 11.1. Key Structures 2290 The format of an OpenPGP V3 key is as follows. Entries in square 2291 brackets are optional and ellipses indicate repetition. 2293 RSA Public Key 2294 [Revocation Self Signature] 2295 User ID [Signature ...] 2296 [User ID [Signature ...] ...] 2298 Each signature certifies the RSA public key and the preceding user 2299 ID. The RSA public key can have many user IDs and each user ID can 2300 have many signatures. 2302 The format of an OpenPGP V4 key that uses two public keys is similar 2303 except that the other keys are added to the end as 'subkeys' of the 2304 primary key. 2306 Primary-Key 2307 [Revocation Self Signature] 2308 [Direct Key Self Signature...] 2309 User ID [Signature ...] 2310 [User ID [Signature ...] ...] 2311 [Subkey Primary-Key-Signature ...] 2313 A subkey always has a single signature after it that is issued using 2314 the primary key to tie the two keys together. The new format can 2315 use either the new signature packets or the old signature packets. 2317 In a key that has a main key and subkeys, the primary key MUST be a 2318 key capable of signing. The subkeys may be keys of any other type. 2319 There may be other constructions of V4 keys, too. For example, there 2320 may be a single-key RSA key in V4 format, a DSA primary key with an 2321 RSA encryption key, or RSA primary key with an Elgamal subkey, etc. 2323 It is also possible to have a signature-only subkey. This permits a 2324 primary key that collects certifications (key signatures) but is 2325 used only used for certifying subkeys that are used for encryption 2326 and signatures. 2328 11.2. Key IDs and Fingerprints 2330 For a V3 key, the eight-octet key ID consists of the low 64 bits of 2331 the public modulus of the RSA key. 2333 The fingerprint of a V3 key is formed by hashing the body (but not 2334 the two-octet length) of the MPIs that form the key material (public 2335 modulus n, followed by exponent e) with MD5. 2337 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet 2338 Tag, followed by the two-octet packet length, followed by the entire 2339 Public Key packet starting with the version field. The key ID is 2340 either the low order 64 bits of the fingerprint. Here are the 2341 fields of the hash material, with the example of a DSA key: 2343 a.1) 0x99 (1 octet) 2345 a.2) high order length octet of (b)-(f) (1 octet) 2347 a.3) low order length octet of (b)-(f) (1 octet) 2349 b) version number = 4 (1 octet); 2351 c) time stamp of key creation (4 octets); 2353 d) algorithm (1 octet): 7 = DSA (example); 2355 e) Algorithm specific fields. 2357 Algorithm Specific Fields for DSA keys (example): 2359 e.1) MPI of DSA prime p; 2361 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 2363 e.3) MPI of DSA group generator g; 2365 e.4) MPI of DSA public key value y (= g**x where x is secret). 2367 Note that it is possible for there to be collisions of key IDs -- 2368 two different keys with the same key ID. Note that there is a much 2369 smaller, but still non-zero probability that two different keys have 2370 the same fingerprint. 2372 Also note that if V3 and V4 format keys share the same RSA key 2373 material, they will have different keyids as well as different 2374 fingerprints. 2376 12. Notes on Algorithms 2378 12.1. Symmetric Algorithm Preferences 2380 The symmetric algorithm preference is an ordered list of algorithms 2381 that the keyholder accepts. Since it is found on a self-signature, 2382 it is possible that a keyholder may have different preferences. For 2383 example, Alice may have TripleDES only specified for 2384 "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 2385 "alice@home.org". Note that it is also possible for preferences to 2386 be in a subkey's binding signature. 2388 Since TripleDES is the MUST-implement algorithm, if it is not 2389 explicitly in the the list, it is tacitly at the end. However, it is 2390 good form to place it there explicitly. Note also that if an 2391 implementation does not implement the preference, then it is 2392 implicitly a TripleDES-only implementation. 2394 An implementation MUST not use a symmetric algorithm that is not in 2395 the recipent's preference list. When encrypting to more than one 2396 recipient, the implementation finds a suitable algorithm by taking 2397 the intersection of the preferences of the recipients. Note that the 2398 MUST-implement algorithm, TripleDES, ensures that the intersection 2399 is not null. The implementation may use any mechanism to pick an 2400 algorithm in the intersection. 2402 If an implementation can decrypt a message that a keyholder doesn't 2403 have in their preferences, the implementation SHOULD decrypt the 2404 message anyway, but MUST warn the keyholder than protocol has been 2405 violated. (For example, suppose that Alice, above, has software that 2406 implements all algorithms in this specification. Nonetheless, she 2407 prefers subsets for work or home. If she is sent a message encrypted 2408 with IDEA, which is not in her preferences, the software warns her 2409 that someone sent her an IDEA-encrypted message, but it would 2410 ideally decrypt it anyway.) 2412 An implementation that is striving for backwards compatibility MAY 2413 consider a V3 key with a V3 self-signature to be an implicit 2414 preference for IDEA, and no ability to do TripleDES. This is 2415 technically non-compliant, so if an implementation is forming a 2416 message to be read by a V3 keyholder and a V4 keyholder that does 2417 not speak IDEA, the implementation must somehow break this up into 2418 two messages (which is relatively easy to do for email), or issue an 2419 error message when this is not possible. 2421 12.2. Other Algorithm Preferences 2423 Other algorithm preferences work similarly to the symmetric 2424 algorithm preference, in that they specify which algorithms the 2425 keyholder accepts. There are two interesting cases that other 2426 comments need to be made about, though, the compression preferences 2427 and the hash preferences. 2429 12.2.1. Compression Preferences 2431 Compression has been an integral part of PGP since its first days. 2432 OpenPGP and all previous versions of PGP have offered compression. 2433 And in this specification, the default is for messages to be 2434 compressed, although an implementation is not required to do so. 2435 Consequently, the compression preference gives a way for a keyholder 2436 to request that messages not be compressed, presumably because they 2437 are using a minimal implementation that does not include 2438 compression. 2440 12.2.2. Hash Algorithm Preferences 2442 Typically, the choice of a hash algorithm is something the signer 2443 does, rather than the verifier, because a signer does not typically 2444 know who is going to be verifying the signature. This preference, 2445 though, allows a protocol based upon digital signatures ease in 2446 negotiation. 2448 Thus, if Alice is authenticating herself to Bob with a signature, it 2449 makes sense for her to use a hash algorithm that Bob's software 2450 uses. This preference allows Bob to state in his key which 2451 algorithms Alice may use. 2453 12.3. Plaintext 2455 Algorithm 0, "plaintext," may only be used to denote secret keys 2456 that are stored in the clear. Implementations must not use plaintext 2457 in Symmetrically Encrypted Data Packets; they must use Literal Data 2458 Packets to encode unencrypted or literal data. 2460 12.4. RSA 2462 There are algorithm types for RSA-signature-only, and 2463 RSA-encrypt-only keys. These types are deprecated. The "key flags" 2464 subpacket in a signature is a much better way to express the same 2465 idea, and generalizes it to all algorithms. An implementation SHOULD 2466 NOT create such a key, but MAY interpret it. 2468 An implementation SHOULD NOT implement RSA keys of size less than 2469 768 bits. 2471 It is permissable for an implementation to support RSA merely for 2472 backwards compatibility; for example, such an implementation would 2473 support V3 keys with IDEA symmetric cryptography. Note that this is 2474 an exception to the other MUST-implement rules. An implementation 2475 that supports RSA in V4 keys MUST implement the MUST-implement 2476 features. 2478 12.5. Elgamal 2480 If an Elgamal key is to be used for both signing and encryption, 2481 extra care must be taken in creating the key. 2483 An ElGamal key consists of a generator g, a prime modulus p, a 2484 secret exponent x, and a public value y = g^x mod p. 2486 The generator and prime must be chosen so that solving the discrete 2487 log problem is intractable. The group g should generate the 2488 multiplicative group mod p-1 or a large subgroup of it, and the 2489 order of g should have at least one large prime factor. A good 2490 choice is to use a "strong" Sophie-Germain prime in choosing p, so 2491 that both p and (p-1)/2 are primes. 2493 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that 2494 if the generator g has only small prime factors, and if g divides 2495 the order of the group it generates, then signatures can be forged. 2496 In particular, choosing g=2 is a bad choice if the group order may 2497 be even. On the other hand, a generator of 2 is a fine choice for an 2498 encryption-only key, as this will make the encryption faster. 2500 While verifying Elgamal signatures, note that it is important to 2501 test that r and s are less than p. If this test is not done then 2502 signatures can be trivially forged by using large r values of 2503 approximately twice the length of p. This attack is also discussed 2504 in the Bleichenbacher paper. 2506 Details on safe use of Elgamal signatures may be found in [MENEZES], 2507 which discusses all the weaknesses described above. 2509 If an implementation allows Elgamal signatures, then it MUST use the 2510 algorithm identifier 20. 2512 An implementation SHOULD NOT implement Elgamal keys of size less 2513 than 768 bits. For long-term security, Elgamal keys should be 1024 2514 bits or longer. 2516 12.6. DSA 2518 An implementation SHOULD NOT implement DSA keys of size less than 2519 768 bits. Note that present DSA is limited to a maximum of 1024 bit 2520 keys, which are recommended for long-term use. 2522 12.7. OpenPGP CFB mode 2524 OpenPGP does symmetric encryption using a variant of Cipher Feedback 2525 Mode (CFB mode). This section describes the procedure it uses in 2526 detail. 2528 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 2529 and prefixes the plaintext with ten bytes of random data, such that 2530 bytes 9 and 10 match bytes 7 and 8. It does a CFB "resync" after 2531 encrypting those ten bytes. 2533 Note that for an algorithm that has a larger block size than 64 2534 bits, the equivalent function will be done with that entire block. 2536 Step by step, here is the procedure: 2538 1. The feedback register (FR) is set to the IV, which is all zeros. 2540 2. FR is encrypted to produce FRE (FR Encrypted). This is the 2541 encryption of an all-zero value. 2543 3. FRE is xored with the first 8 bytes of random data prefixed to 2544 the plaintext to produce C1-C8, the first 8 bytes of ciphertext. 2546 4. FR is loaded with C1-C8. 2548 5. FR is encrypted to produce FRE, the encryption of the first 8 2549 bytes of ciphertext. 2551 6. The left two bytes of FRE get xored with the next two bytes of 2552 data which were prepended to the plaintext. This produces 2553 C9-C10, the next two bytes of ciphertext. 2555 7. (The resync step) FR is loaded with C3-C10. 2557 8. FR is encrypted to produce FRE. 2559 9. FRE is xored with the first 8 bytes of the given plaintext, now 2560 that we have finished encrypting the 10 bytes of prepended data. 2561 This produces C11-C18, the next 8 bytes of ciphertext. 2563 10. FR is loaded with C11-C18 2565 11. FR is encrypted to produce FRE. 2567 12. FRE is xored with the next 8 bytes of plaintext, to produce the 2568 next 8 bytes of ciphertext. These are loaded into FR and the 2569 process is repeated until the plaintext is used up. 2571 13. Security Considerations 2573 As with any technology involving cryptography, you should check the 2574 current literature to determine if any algorithms used here have 2575 been found to be vulnerable to attack. 2577 This specification uses Public Key Cryptography technologies. 2578 Possession of the private key portion of a public-private key pair 2579 is assumed to be controlled by the proper party or parties. 2581 Certain operations in this specification involve the use of random 2582 numbers. An appropriate entropy source should be used to generate 2583 these numbers. See RFC 1750. 2585 The MD5 hash algorithm has been found to have weaknesses 2586 (pseudo-collisions in the compress function) that make some people 2587 deprecate its use. They consider the SHA-1 algorithm better. 2589 The DSA algorithm will work with any 160-bit hash, but it is 2590 sensitive to the quality of the hash algorithm, if the hash 2591 algorithm is broken, it can leak the secret key. The Digital 2592 Signature Standard (DSS) specifies that DSA be used with SHA-1. 2593 RIPEMD-160 is considered by many cryptographers to be as strong. An 2594 implementation should take care which hash algorithms are used with 2595 DSA, as a weak hash can not only allow a signature to be forged, but 2596 could leak the secret key. 2598 If you are building an authentication system, the recipient may 2599 specify a preferred signing algorithm. However, the signer would be 2600 foolish to use a weak algorithm simply because the recipient 2601 requests it. 2603 Some of the encryption algorithms mentioned in this document have 2604 been analyzed less than others. For example, although CAST5 is 2605 presently considered strong, it has been analyzed less than 2606 Triple-DES. Other algorithms may have other controversies 2607 surrounding them. 2609 Some technologies mentioned here may be subject to government 2610 control in some countries. 2612 14. Authors and Working Group Chair 2614 The working group can be contacted via the current chair: 2616 John W. Noerenberg, II 2617 Qualcomm, Inc 2618 6455 Lusk Blvd 2619 San Diego, CA 92131 USA 2620 Email: jwn2@qualcomm.com 2621 Tel: +1 619-658-3510 2623 The principal authors of this draft are: 2625 Jon Callas 2626 Network Associates, Inc. 2627 4200 Bohannon Drive 2628 Menlo Park, CA 94025, USA 2629 Email: jon@pgp.com 2630 Tel: +1-650-473-2860 2632 Lutz Donnerhacke 2633 IKS GmbH 2634 Wildenbruchstr. 15 2635 07745 Jena, Germany 2636 EMail: lutz@iks-jena.de 2637 Tel: +49-3641-675642 2639 Hal Finney 2640 Network Associates, Inc. 2641 4200 Bohannon Drive 2642 Menlo Park, CA 94025, USA 2643 Email: hal@pgp.com 2645 Rodney Thayer 2646 Sable Technology Corporation 2647 246 Walnut Street 2648 Newton, MA 02160 USA 2649 Email: rodney@sabletech.com 2650 Tel: +1-617-332-7292 2652 This draft also draws on much previous work from a number of other 2653 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 2654 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph 2655 Levine, Colin Plumb, Will Price, William Stallings, Mark Weaver, and 2656 Philip R. Zimmermann. 2658 15. References 2660 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal 2661 signatures without knowing the secret key," Eurocrypt 96. Note that 2662 the version in the proceedings has an error. A revised version is 2663 available at the time of writing from 2664 2666 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved 2667 international version of PGP", 2668 ftp://ftp.iks-jena.de/mitarb/lutz/crypt/software/pgp/ 2670 [ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a Signature 2671 Scheme Based on Discrete Logarithms," IEEE Transactions on 2672 Information Theory, v. IT-31, n. 4, 1985, pp. 469-472. 2674 [ISO-10646] ISO/IEC 10646-1:1993. International Standard -- 2675 Information technology -- Universal Multiple-Octet Coded Character 2676 Set (UCS) -- Part 1: Architecture and Basic Multilingual Plane. 2677 UTF-8 is described in Annex R, adopted but not yet published. 2678 UTF-16 is described in Annex Q, adopted but not yet published. 2680 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott Vanstone, 2681 "Handbook of Applied Cryptography," CRC Press, 1996. 2683 [PKCS1] RSA Laboratories, "PKCS #1: RSA Encryption Standard," 2684 version 1.5, November 1993 2686 [RFC822] D. Crocker, "Standard for the format of ARPA Internet text 2687 messages", RFC 822, August 1982 2689 [RFC1423] D. Balenson, "Privacy Enhancement for Internet Electronic 2690 Mail: Part III: Algorithms, Modes, and Identifiers", RFC 1423, 2691 October 1993 2693 [RFC1641] Goldsmith, D., and M. Davis, "Using Unicode with MIME", 2694 RFC 1641, Taligent inc., July 1994. 2696 [RFC1750] Eastlake, Crocker, & Schiller., Randomness Recommendations 2697 for Security. December 1994. 2699 [RFC1951] Deutsch, P., DEFLATE Compressed Data Format Specification 2700 version 1.3. May 1996. 2702 [RFC1983] G. Malkin., Internet Users' Glossary. August 1996. 2704 [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP Message 2705 Exchange Formats", RFC 1991, August 1996. 2707 [RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy 2708 (PGP)", RFC 2015, October 1996. 2710 [RFC2044] F. Yergeau., UTF-8, a transformation format of Unicode and 2711 ISO 10646. October 1996. 2713 [RFC2045] Borenstein, N., and Freed, N., "Multipurpose Internet Mail 2714 Extensions (MIME) Part One: Format of Internet Message Bodies.", 2715 November 1996 2717 [RFC2119] Bradner, S., Key words for use in RFCs to Indicate 2718 Requirement Level. March 1997. 2720 16. Full Copyright Statement 2722 Copyright 1998 by The Internet Society. All Rights Reserved. 2724 This document and translations of it may be copied and furnished to 2725 others, and derivative works that comment on or otherwise explain it 2726 or assist in its implementation may be prepared, copied, published 2727 and distributed, in whole or in part, without restriction of any 2728 kind, provided that the above copyright notice and this paragraph 2729 are included on all such copies and derivative works. However, this 2730 document itself may not be modified in any way, such as by removing 2731 the copyright notice or references to the Internet Society or other 2732 Internet organizations, except as needed for the purpose of 2733 developing Internet standards in which case the procedures for 2734 copyrights defined in the Internet Standards process must be 2735 followed, or as required to translate it into languages other than 2736 English. 2738 The limited permissions granted above are perpetual and will not be 2739 revoked by the Internet Society or its successors or assigns.