idnits 2.17.1 draft-ietf-openpgp-rfc2440bis-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 Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The document seems to lack an IANA Considerations section. (See Section 2.2 of https://www.ietf.org/id-info/checklist for how to handle the case when there are no actions for IANA.) ** The document seems to lack an Authors' Addresses Section. ** The document seems to lack separate sections for Informative/Normative References. All references will be assumed normative when checking for downward references. Miscellaneous warnings: ---------------------------------------------------------------------------- == The document seems to lack the recommended RFC 2119 boilerplate, even if it appears to use RFC 2119 keywords. (The document does seem to have the reference to RFC 2119 which the ID-Checklist requires). == Using lowercase 'not' together with uppercase 'MUST', 'SHALL', 'SHOULD', or 'RECOMMENDED' is not an accepted usage according to RFC 2119. Please use uppercase 'NOT' together with RFC 2119 keywords (if that is what you mean). Found 'MUST not' in this paragraph: An implementation MUST not use a symmetric algorithm that is not in the recipient's preference list. When encrypting to more than one recipient, the implementation finds a suitable algorithm by taking the intersection of the preferences of the recipients. Note that the MUST-implement algorithm, TripleDES, ensures that the intersection is not null. The implementation may use any mechanism to pick an algorithm in the intersection. == Unrecognized Status in 'Category: INTERNET-DRAFT', assuming Proposed Standard (Expected one of 'Standards Track', 'Full Standard', 'Draft Standard', 'Proposed Standard', 'Best Current Practice', 'Informational', 'Experimental', 'Informational', 'Historic'.) -- The document seems to lack a disclaimer for pre-RFC5378 work, but may have content which was first submitted before 10 November 2008. If you have contacted all the original authors and they are all willing to grant the BCP78 rights to the IETF Trust, then this is fine, and you can ignore this comment. If not, you may need to add the pre-RFC5378 disclaimer. (See the Legal Provisions document at https://trustee.ietf.org/license-info for more information.) -- Couldn't find a document date in the document -- date freshness check skipped. -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) -- Looks like a reference, but probably isn't: '0' on line 363 -- Looks like a reference, but probably isn't: '1' on line 3019 -- Looks like a reference, but probably isn't: '2' on line 363 -- Looks like a reference, but probably isn't: '3' on line 3028 == Missing Reference: 'Optional' is mentioned on line 1841, but not defined == Missing Reference: 'RFC 2045' is mentioned on line 2159, but not defined == Missing Reference: 'Binding-Signature-Revocation' is mentioned on line 2727, but not defined == Missing Reference: 'BS' is mentioned on line 3019, but not defined == Unused Reference: 'DONNERHACKE' is defined on line 3251, but no explicit reference was found in the text == Unused Reference: 'RFC822' is defined on line 3274, but no explicit reference was found in the text == Unused Reference: 'RFC1423' is defined on line 3278, but no explicit reference was found in the text == Unused Reference: 'RFC1641' is defined on line 3282, but no explicit reference was found in the text == Unused Reference: 'RFC1750' is defined on line 3285, but no explicit reference was found in the text == Unused Reference: 'RFC1951' is defined on line 3289, but no explicit reference was found in the text == Unused Reference: 'RFC1983' is defined on line 3292, but no explicit reference was found in the text == Unused Reference: 'RFC1991' is defined on line 3295, but no explicit reference was found in the text == Unused Reference: 'RFC2015' is defined on line 3298, but no explicit reference was found in the text == Unused Reference: 'RFC2045' is defined on line 3301, but no explicit reference was found in the text == Unused Reference: 'RFC2119' is defined on line 3305, but no explicit reference was found in the text == Unused Reference: 'RFC2144' is defined on line 3308, but no explicit reference was found in the text -- Possible downref: Non-RFC (?) normative reference: ref. 'AES' -- Possible downref: Non-RFC (?) normative reference: ref. 'BLEICHENBACHER' -- Possible downref: Non-RFC (?) normative reference: ref. 'BLOWFISH' -- Possible downref: Non-RFC (?) normative reference: ref. 'DONNERHACKE' -- Possible downref: Non-RFC (?) normative reference: ref. 'ELGAMAL' -- Possible downref: Non-RFC (?) normative reference: ref. 'IDEA' -- Possible downref: Non-RFC (?) normative reference: ref. 'ISO10646' -- Possible downref: Non-RFC (?) normative reference: ref. 'MENEZES' ** Obsolete normative reference: RFC 822 (Obsoleted by RFC 2822) ** Downref: Normative reference to an Historic RFC: RFC 1423 ** Downref: Normative reference to an Experimental RFC: RFC 1641 ** Obsolete normative reference: RFC 1750 (Obsoleted by RFC 4086) ** Downref: Normative reference to an Informational RFC: RFC 1951 ** Downref: Normative reference to an Informational RFC: RFC 1983 ** Obsolete normative reference: RFC 1991 (Obsoleted by RFC 4880) ** Downref: Normative reference to an Informational RFC: RFC 2144 ** Obsolete normative reference: RFC 2279 (Obsoleted by RFC 3629) ** Obsolete normative reference: RFC 2437 (Obsoleted by RFC 3447) -- Possible downref: Non-RFC (?) normative reference: ref. 'SAFER' -- Possible downref: Non-RFC (?) normative reference: ref. 'SCHNEIER' -- Possible downref: Non-RFC (?) normative reference: ref. 'TWOFISH' Summary: 15 errors (**), 0 flaws (~~), 19 warnings (==), 18 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 Counterpane Internet Security 3 draft-ietf-openpgp-rfc2440bis-02.txt 4 Expires Apr 2001 Lutz Donnerhacke 5 October 2000 IN-Root-CA Individual Network e.V. 7 Hal Finney 8 Network Associates 10 Rodney Thayer 12 OpenPGP Message Format 13 draft-ietf-openpgp-rfc2440bis-02.txt 15 Copyright 2000 by The Internet Society. All Rights Reserved. 17 Status of this Memo 19 This document is an Internet-Draft and is in full conformance with 20 all provisions of Section 10 of RFC2026. 22 Internet-Drafts are working documents of the Internet Engineering 23 Task Force (IETF), its areas, and its working groups. Note that 24 other groups may also distribute working documents as 25 Internet-Drafts. 27 Internet-Drafts are draft documents valid for a maximum of six 28 months and may be updated, replaced, or obsoleted by other documents 29 at any time. It is inappropriate to use Internet-Drafts as 30 reference material or to cite them other than as "work in progress." 32 The list of current Internet-Drafts can be accessed at 33 http://www.ietf.org/ietf/1id-abstracts.txt 35 The list of Internet-Draft Shadow Directories can be accessed at 36 http://www.ietf.org/shadow.html. 38 IESG Note 40 This document defines many tag values, yet it doesn't describe a 41 mechanism for adding new tags (for new features). Traditionally the 42 Internet Assigned Numbers Authority (IANA) handles the allocation of 43 new values for future expansion and RFCs usually define the 44 procedure to be used by the IANA. However there are subtle (and not 45 so subtle) interactions that may occur in this protocol between new 46 features and existing features which result in a significant 47 reduction in over all security. Therefore this document does not 48 define an extension procedure. Instead requests to define new tag 49 values (say for new encryption algorithms for example) should be 50 forwarded to the IESG Security Area Directors for consideration or 51 forwarding to the appropriate IETF Working Group for consideration. 53 Abstract 55 This document is maintained in order to publish all necessary 56 information needed to develop interoperable applications based on 57 the OpenPGP format. It is not a step-by-step cookbook for writing an 58 application. It describes only the format and methods needed to 59 read, check, generate, and write conforming packets crossing any 60 network. It does not deal with storage and implementation questions. 61 It does, however, discuss implementation issues necessary to avoid 62 security flaws. 64 Open-PGP software uses a combination of strong public-key and 65 symmetric cryptography to provide security services for electronic 66 communications and data storage. These services include 67 confidentiality, key management, authentication, and digital 68 signatures. This document specifies the message formats used in 69 OpenPGP. 71 Table of Contents 73 Status of this Memo 1 74 IESG Note 1 75 Abstract 2 76 Table of Contents 3 77 1. Introduction 6 78 1.1. Terms 6 79 2. General functions 6 80 2.1. Confidentiality via Encryption 6 81 2.2. Authentication via Digital signature 7 82 2.3. Compression 8 83 2.4. Conversion to Radix-64 8 84 2.5. Signature-Only Applications 8 85 3. Data Element Formats 9 86 3.1. Scalar numbers 9 87 3.2. Multi-Precision Integers 9 88 3.3. Key IDs 9 89 3.4. Text 9 90 3.5. Time fields 10 91 3.6. Keyrings 10 92 3.7. String-to-key (S2K) specifiers 10 93 3.7.1. String-to-key (S2k) specifier types 10 94 3.7.1.1. Simple S2K 10 95 3.7.1.2. Salted S2K 11 96 3.7.1.3. Iterated and Salted S2K 11 97 3.7.2. String-to-key usage 12 98 3.7.2.1. Secret key encryption 12 99 3.7.2.2. Symmetric-key message encryption 12 100 4. Packet Syntax 12 101 4.1. Overview 13 102 4.2. Packet Headers 13 103 4.2.1. Old-Format Packet Lengths 13 104 4.2.2. New-Format Packet Lengths 14 105 4.2.2.1. One-Octet Lengths 14 106 4.2.2.2. Two-Octet Lengths 14 107 4.2.2.3. Five-Octet Lengths 15 108 4.2.2.4. Partial Body Lengths 15 109 4.2.3. Packet Length Examples 15 110 4.3. Packet Tags 16 111 5. Packet Types 16 112 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 16 113 5.2. Signature Packet (Tag 2) 17 114 5.2.1. Signature Types 18 115 5.2.2. Version 3 Signature Packet Format 20 116 5.2.3. Version 4 Signature Packet Format 21 117 5.2.3.1. Signature Subpacket Specification 22 118 5.2.3.2. Signature Subpacket Types 24 119 5.2.3.3. Notes on Self-Signatures 24 120 5.2.3.4. Signature creation time 25 121 5.2.3.5. Issuer 25 122 5.2.3.6. Key expiration time 25 123 5.2.3.7. Preferred symmetric algorithms 25 124 5.2.3.8. Preferred hash algorithms 25 125 5.2.3.9. Preferred compression algorithms 26 126 5.2.3.10.Signature expiration time 26 127 5.2.3.11.Exportable Certification 26 128 5.2.3.12.Revocable 26 129 5.2.3.13.Trust signature 27 130 5.2.3.14.Regular expression 27 131 5.2.3.15.Revocation key 27 132 5.2.3.16.Notation Data 28 133 5.2.3.17.Key server preferences 28 134 5.2.3.18.Preferred key server 29 135 5.2.3.19.Primary user id 29 136 5.2.3.20.Policy URL 29 137 5.2.3.21.Key Flags 29 138 5.2.3.22.Signer's User ID 30 139 5.2.3.23.Reason for Revocation 30 140 5.2.3.24.Features 31 141 5.2.4. Computing Signatures 31 142 5.2.4.1. Subpacket Hints 32 143 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 33 144 5.4. One-Pass Signature Packets (Tag 4) 34 145 5.5. Key Material Packet 34 146 5.5.1. Key Packet Variants 35 147 5.5.1.1. Public Key Packet (Tag 6) 35 148 5.5.1.2. Public Subkey Packet (Tag 14) 35 149 5.5.1.3. Secret Key Packet (Tag 5) 35 150 5.5.1.4. Secret Subkey Packet (Tag 7) 35 151 5.5.2. Public Key Packet Formats 35 152 5.5.3. Secret Key Packet Formats 37 153 5.6. Compressed Data Packet (Tag 8) 38 154 5.7. Symmetrically Encrypted Data Packet (Tag 9) 39 155 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 40 156 5.9. Literal Data Packet (Tag 11) 40 157 5.10. Trust Packet (Tag 12) 41 158 5.11. User ID Packet (Tag 13) 41 159 5.12. Sym. Encrypted Integrity Protected Data Packet (Tag 15) 41 160 5.13. Modification Detection Code Packet (Tag 16) 43 161 6. Radix-64 Conversions 43 162 6.1. An Implementation of the CRC-24 in "C" 44 163 6.2. Forming ASCII Armor 44 164 6.3. Encoding Binary in Radix-64 47 165 6.4. Decoding Radix-64 48 166 6.5. Examples of Radix-64 48 167 6.6. Example of an ASCII Armored Message 49 168 7. Cleartext signature framework 49 169 7.1. Dash-Escaped Text 50 170 8. Regular Expressions 50 171 9. Constants 51 172 9.1. Public Key Algorithms 51 173 9.2. Symmetric Key Algorithms 51 174 9.3. Compression Algorithms 52 175 9.4. Hash Algorithms 52 176 10. Packet Composition 52 177 10.1. Transferable Public Keys 52 178 10.2. OpenPGP Messages 53 179 10.3. Detached Signatures 54 180 11. Enhanced Key Formats 54 181 11.1. Key Structures 54 182 11.2. Key IDs and Fingerprints 55 183 12. Notes on Algorithms 56 184 12.1. Symmetric Algorithm Preferences 56 185 12.2. Other Algorithm Preferences 57 186 12.2.1. Compression Preferences 57 187 12.2.2. Hash Algorithm Preferences 58 188 12.3. Plaintext 58 189 12.4. RSA 58 190 12.5. Elgamal 58 191 12.6. DSA 59 192 12.7. Reserved Algorithm Numbers 59 193 12.8. OpenPGP CFB mode 60 194 13. Security Considerations 61 195 14. Implementation Nits 62 196 15. Authors and Working Group Chair 63 197 16. References 64 198 17. Full Copyright Statement 66 200 1. Introduction 202 This document provides information on the message-exchange packet 203 formats used by OpenPGP to provide encryption, decryption, signing, 204 and key management functions. It is a revision of RFC2440, "OpenPGP 205 Message Format", which itself replaces RFC 1991, "PGP Message 206 Exchange Formats." 208 1.1. Terms 210 * OpenPGP - This is a definition for security software that uses 211 PGP 5.x as a basis, formalized in RFC 2440 and this document. 213 * PGP - Pretty Good Privacy. PGP is a family of software systems 214 developed by Philip R. Zimmermann from which OpenPGP is based. 216 * PGP 2.6.x - This version of PGP has many variants, hence the 217 term PGP 2.6.x. It used only RSA, MD5, and IDEA for its 218 cryptographic transforms. An informational RFC, RFC1991, was 219 written describing this version of PGP. 221 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in 222 the community and also in the predecessor of this document, 223 RFC1991. It has new formats and corrects a number of problems in 224 the PGP 2.6.x design. It is referred to here as PGP 5.x because 225 that software was the first release of the "PGP 3" code base. 227 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of 228 Network Associates, Inc. and are used with permission. 230 This document uses the terms "MUST", "SHOULD", and "MAY" as defined 231 in RFC2119, along with the negated forms of those terms. 233 2. General functions 235 OpenPGP provides data integrity services for messages and data files 236 by using these core technologies: 238 - digital signatures 240 - encryption 242 - compression 244 - radix-64 conversion 246 In addition, OpenPGP provides key management and certificate 247 services, but many of these are beyond the scope of this document. 249 2.1. Confidentiality via Encryption 251 OpenPGP uses two encryption methods to provide confidentiality: 253 symmetric-key encryption and public key encryption. With public-key 254 encryption, the object is encrypted using a symmetric encryption 255 algorithm. Each symmetric key is used only once. A new "session 256 key" is generated as a random number for each message. Since it is 257 used only once, the session key is bound to the message and 258 transmitted with it. To protect the key, it is encrypted with the 259 receiver's public key. The sequence is as follows: 261 1. The sender creates a message. 263 2. The sending OpenPGP generates a random number to be used as a 264 session key for this message only. 266 3. The session key is encrypted using each recipient's public key. 267 These "encrypted session keys" start the message. 269 4. The sending OpenPGP encrypts the message using the session key, 270 which forms the remainder of the message. Note that the message 271 is also usually compressed. 273 5. The receiving OpenPGP decrypts the session key using the 274 recipient's private key. 276 6. The receiving OpenPGP decrypts the message using the session 277 key. If the message was compressed, it will be decompressed. 279 With symmetric-key encryption, an object may be encrypted with a 280 symmetric key derived from a passphrase (or other shared secret), or 281 a two-stage mechanism similar to the public-key method described 282 above in which a session key is itself encrypted with a symmetric 283 algorithm keyed from a shared secret. 285 Both digital signature and confidentiality services may be applied 286 to the same message. First, a signature is generated for the message 287 and attached to the message. Then, the message plus signature is 288 encrypted using a symmetric session key. Finally, the session key is 289 encrypted using public-key encryption and prefixed to the encrypted 290 block. 292 2.2. Authentication via Digital signature 294 The digital signature uses a hash code or message digest algorithm, 295 and a public-key signature algorithm. The sequence is as follows: 297 1. The sender creates a message. 299 2. The sending software generates a hash code of the message. 301 3. The sending software generates a signature from the hash code 302 using the sender's private key. 304 4. The binary signature is attached to the message. 306 5. The receiving software keeps a copy of the message signature. 308 6. The receiving software generates a new hash code for the 309 received message and verifies it using the message's signature. 310 If the verification is successful, the message is accepted as 311 authentic. 313 2.3. Compression 315 OpenPGP implementations SHOULD compress the message after applying 316 the signature but before encryption. 318 Note that while all past implementations of PGP properly handle 319 messages that have not been compressed, they all have compressed 320 messages by default. If an implementation does not implement 321 compression, its authors should be aware that most PGP messages in 322 the world are compressed. Thus, it may even be wise for a 323 space-constrained implementation to implement decompression, but not 324 compression. 326 2.4. Conversion to Radix-64 328 OpenPGP's underlying native representation for encrypted messages, 329 signature certificates, and keys is a stream of arbitrary octets. 330 Some systems only permit the use of blocks consisting of seven-bit, 331 printable text. For transporting OpenPGP's native raw binary octets 332 through channels that are not safe to raw binary data, a printable 333 encoding of these binary octets is needed. OpenPGP provides the 334 service of converting the raw 8-bit binary octet stream to a stream 335 of printable ASCII characters, called Radix-64 encoding or ASCII 336 Armor. 338 Implementations SHOULD provide Radix-64 conversions. 340 Note that many applications, particularly messaging applications, 341 will want more advanced features as described in the OpenPGP-MIME 342 document, RFC2015. An application that implements OpenPGP for 343 messaging SHOULD implement OpenPGP-MIME. 345 2.5. Signature-Only Applications 347 OpenPGP is designed for applications that use both encryption and 348 signatures, but there are a number of problems that are solved by a 349 signature-only implementation. Although this specification requires 350 both encryption and signatures, it is reasonable for there to be 351 subset implementations that are non-comformant only in that they 352 omit encryption. 354 3. Data Element Formats 356 This section describes the data elements used by OpenPGP. 358 3.1. Scalar numbers 360 Scalar numbers are unsigned, and are always stored in big-endian 361 format. Using n[k] to refer to the kth octet being interpreted, the 362 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 363 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 364 n[3]). 366 3.2. Multi-Precision Integers 368 Multi-Precision Integers (also called MPIs) are unsigned integers 369 used to hold large integers such as the ones used in cryptographic 370 calculations. 372 An MPI consists of two pieces: a two-octet scalar that is the length 373 of the MPI in bits followed by a string of octets that contain the 374 actual integer. 376 These octets form a big-endian number; a big-endian number can be 377 made into an MPI by prefixing it with the appropriate length. 379 Examples: 381 (all numbers are in hexadecimal) 383 The string of octets [00 01 01] forms an MPI with the value 1. The 384 string [00 09 01 FF] forms an MPI with the value of 511. 386 Additional rules: 388 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 390 The length field of an MPI describes the length starting from its 391 most significant non-zero bit. Thus, the MPI [00 02 01] is not 392 formed correctly. It should be [00 01 01]. 394 3.3. Key IDs 396 A Key ID is an eight-octet scalar that identifies a key. 397 Implementations SHOULD NOT assume that Key IDs are unique. The 398 section, "Enhanced Key Formats" below describes how Key IDs are 399 formed. 401 3.4. Text 403 The default character set for text is the UTF-8 [RFC2279] encoding 404 of Unicode [ISO10646]. 406 3.5. Time fields 408 A time field is an unsigned four-octet number containing the number 409 of seconds elapsed since midnight, 1 January 1970 UTC. 411 3.6. Keyrings 413 A keyring is a collection of one or more keys in a file or database. 414 Traditionally, a keyring is simply a sequential list of keys, but 415 may be any suitable database. It is beyond the scope of this 416 standard to discuss the details of keyrings or other databases. 418 3.7. String-to-key (S2K) specifiers 420 String-to-key (S2K) specifiers are used to convert passphrase 421 strings into symmetric-key encryption/decryption keys. They are 422 used in two places, currently: to encrypt the secret part of private 423 keys in the private keyring, and to convert passphrases to 424 encryption keys for symmetrically encrypted messages. 426 3.7.1. String-to-key (S2k) specifier types 428 There are three types of S2K specifiers currently supported, as 429 follows: 431 3.7.1.1. Simple S2K 433 This directly hashes the string to produce the key data. See below 434 for how this hashing is done. 436 Octet 0: 0x00 437 Octet 1: hash algorithm 439 Simple S2K hashes the passphrase to produce the session key. The 440 manner in which this is done depends on the size of the session key 441 (which will depend on the cipher used) and the size of the hash 442 algorithm's output. If the hash size is greater than or equal to the 443 session key size, the high-order (leftmost) octets of the hash are 444 used as the key. 446 If the hash size is less than the key size, multiple instances of 447 the hash context are created -- enough to produce the required key 448 data. These instances are preloaded with 0, 1, 2, ... octets of 449 zeros (that is to say, the first instance has no preloading, the 450 second gets preloaded with 1 octet of zero, the third is preloaded 451 with two octets of zeros, and so forth). 453 As the data is hashed, it is given independently to each hash 454 context. Since the contexts have been initialized differently, they 455 will each produce different hash output. Once the passphrase is 456 hashed, the output data from the multiple hashes is concatenated, 457 first hash leftmost, to produce the key data, with any excess octets 458 on the right discarded. 460 3.7.1.2. Salted S2K 462 This includes a "salt" value in the S2K specifier -- some arbitrary 463 data -- that gets hashed along with the passphrase string, to help 464 prevent dictionary attacks. 466 Octet 0: 0x01 467 Octet 1: hash algorithm 468 Octets 2-9: 8-octet salt value 470 Salted S2K is exactly like Simple S2K, except that the input to the 471 hash function(s) consists of the 8 octets of salt from the S2K 472 specifier, followed by the passphrase. 474 3.7.1.3. Iterated and Salted S2K 476 This includes both a salt and an octet count. The salt is combined 477 with the passphrase and the resulting value is hashed repeatedly. 478 This further increases the amount of work an attacker must do to try 479 dictionary attacks. 481 Octet 0: 0x03 482 Octet 1: hash algorithm 483 Octets 2-9: 8-octet salt value 484 Octet 10: count, a one-octet, coded value 486 The count is coded into a one-octet number using the following 487 formula: 489 #define EXPBIAS 6 490 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 492 The above formula is in C, where "Int32" is a type for a 32-bit 493 integer, and the variable "c" is the coded count, Octet 10. 495 Iterated-Salted S2K hashes the passphrase and salt data multiple 496 times. The total number of octets to be hashed is specified in the 497 encoded count in the S2K specifier. Note that the resulting count 498 value is an octet count of how many octets will be hashed, not an 499 iteration count. 501 Initially, one or more hash contexts are set up as with the other 502 S2K algorithms, depending on how many octets of key data are needed. 503 Then the salt, followed by the passphrase data is repeatedly hashed 504 until the number of octets specified by the octet count has been 505 hashed. The one exception is that if the octet count is less than 506 the size of the salt plus passphrase, the full salt plus passphrase 507 will be hashed even though that is greater than the octet count. 508 After the hashing is done the data is unloaded from the hash 509 context(s) as with the other S2K algorithms. 511 3.7.2. String-to-key usage 513 Implementations SHOULD use salted or iterated-and-salted S2K 514 specifiers, as simple S2K specifiers are more vulnerable to 515 dictionary attacks. 517 3.7.2.1. Secret key encryption 519 An S2K specifier can be stored in the secret keyring to specify how 520 to convert the passphrase to a key that unlocks the secret data. 521 Older versions of PGP just stored a cipher algorithm octet preceding 522 the secret data or a zero to indicate that the secret data was 523 unencrypted. The MD5 hash function was always used to convert the 524 passphrase to a key for the specified cipher algorithm. 526 For compatibility, when an S2K specifier is used, the special value 527 255 is stored in the position where the hash algorithm octet would 528 have been in the old data structure. This is then followed 529 immediately by a one-octet algorithm identifier, and then by the S2K 530 specifier as encoded above. 532 Therefore, preceding the secret data there will be one of these 533 possibilities: 535 0: secret data is unencrypted (no pass phrase) 536 255: followed by algorithm octet and S2K specifier 537 Cipher alg: use Simple S2K algorithm using MD5 hash 539 This last possibility, the cipher algorithm number with an implicit 540 use of MD5 and IDEA, is provided for backward compatibility; it MAY 541 be understood, but SHOULD NOT be generated, and is deprecated. 543 These are followed by an Initial Vector of the same length as the 544 block size of the cipher for the decryption of the secret values, if 545 they are encrypted, and then the secret key values themselves. 547 3.7.2.2. Symmetric-key message encryption 549 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) 550 packet at the front of a message. This is used to allow S2K 551 specifiers to be used for the passphrase conversion or to create 552 messages with a mix of symmetric-key ESKs and public-key ESKs. This 553 allows a message to be decrypted either with a passphrase or a 554 public key. 556 PGP 2.X always used IDEA with Simple string-to-key conversion when 557 encrypting a message with a symmetric algorithm. This is deprecated, 558 but MAY be used for backward-compatibility. 560 4. Packet Syntax 562 This section describes the packets used by OpenPGP. 564 4.1. Overview 566 An OpenPGP message is constructed from a number of records that are 567 traditionally called packets. A packet is a chunk of data that has a 568 tag specifying its meaning. An OpenPGP message, keyring, 569 certificate, and so forth consists of a number of packets. Some of 570 those packets may contain other OpenPGP packets (for example, a 571 compressed data packet, when uncompressed, contains OpenPGP 572 packets). 574 Each packet consists of a packet header, followed by the packet 575 body. The packet header is of variable length. 577 4.2. Packet Headers 579 The first octet of the packet header is called the "Packet Tag." It 580 determines the format of the header and denotes the packet contents. 581 The remainder of the packet header is the length of the packet. 583 Note that the most significant bit is the left-most bit, called bit 584 7. A mask for this bit is 0x80 in hexadecimal. 586 +---------------+ 587 PTag |7 6 5 4 3 2 1 0| 588 +---------------+ 589 Bit 7 -- Always one 590 Bit 6 -- New packet format if set 592 PGP 2.6.x only uses old format packets. Thus, software that 593 interoperates with those versions of PGP must only use old format 594 packets. If interoperability is not an issue, either format may be 595 used. Note that old format packets have four bits of content tags, 596 and new format packets have six; some features cannot be used and 597 still be backward-compatible. 599 Also note that packets with a tag greater than or equal to 16 MUST 600 use new format packets. The old format packets can only express tags 601 less than or equal to 15. 603 Old format packets contain: 605 Bits 5-2 -- content tag 606 Bits 1-0 - length-type 608 New format packets contain: 610 Bits 5-0 -- content tag 612 4.2.1. Old-Format Packet Lengths 614 The meaning of the length-type in old-format packets is: 616 0 - The packet has a one-octet length. The header is 2 octets long. 618 1 - The packet has a two-octet length. The header is 3 octets long. 620 2 - The packet has a four-octet length. The header is 5 octets long. 622 3 - The packet is of indeterminate length. The header is 1 octet 623 long, and the implementation must determine how long the packet 624 is. If the packet is in a file, this means that the packet 625 extends until the end of the file. In general, an implementation 626 SHOULD NOT use indeterminate length packets except where the end 627 of the data will be clear from the context, and even then it is 628 better to use a definite length, or a new-format header. The 629 new-format headers described below have a mechanism for 630 precisely encoding data of indeterminate length. 632 4.2.2. New-Format Packet Lengths 634 New format packets have four possible ways of encoding length: 636 1. A one-octet Body Length header encodes packet lengths of up to 637 191 octets. 639 2. A two-octet Body Length header encodes packet lengths of 192 to 640 8383 octets. 642 3. A five-octet Body Length header encodes packet lengths of up to 643 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 644 encodes a four-octet scalar number.) 646 4. When the length of the packet body is not known in advance by 647 the issuer, Partial Body Length headers encode a packet of 648 indeterminate length, effectively making it a stream. 650 4.2.2.1. One-Octet Lengths 652 A one-octet Body Length header encodes a length of from 0 to 191 653 octets. This type of length header is recognized because the one 654 octet value is less than 192. The body length is equal to: 656 bodyLen = 1st_octet; 658 4.2.2.2. Two-Octet Lengths 660 A two-octet Body Length header encodes a length of from 192 to 8383 661 octets. It is recognized because its first octet is in the range 662 192 to 223. The body length is equal to: 664 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 666 4.2.2.3. Five-Octet Lengths 668 A five-octet Body Length header consists of a single octet holding 669 the value 255, followed by a four-octet scalar. The body length is 670 equal to: 672 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 673 (4th_octet << 8) | 5th_octet 675 4.2.2.4. Partial Body Lengths 677 A Partial Body Length header is one octet long and encodes the 678 length of only part of the data packet. This length is a power of 2, 679 from 1 to 1,073,741,824 (2 to the 30th power). It is recognized by 680 its one octet value that is greater than or equal to 224, and less 681 than 255. The partial body length is equal to: 683 partialBodyLen = 1 << (1st_octet & 0x1f); 685 Each Partial Body Length header is followed by a portion of the 686 packet body data. The Partial Body Length header specifies this 687 portion's length. Another length header (of one of the three types 688 -- one octet, two-octet, or partial) follows that portion. The last 689 length header in the packet MUST NOT be a partial Body Length 690 header. Partial Body Length headers may only be used for the 691 non-final parts of the packet. 693 4.2.3. Packet Length Examples 695 These examples show ways that new-format packets might encode the 696 packet lengths. 698 A packet with length 100 may have its length encoded in one octet: 699 0x64. This is followed by 100 octets of data. 701 A packet with length 1723 may have its length coded in two octets: 702 0xC5, 0xFB. This header is followed by the 1723 octets of data. 704 A packet with length 100000 may have its length encoded in five 705 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 707 It might also be encoded in the following octet stream: 0xEF, first 708 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 709 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 710 1693 octets of data. This is just one possible encoding, and many 711 variations are possible on the size of the Partial Body Length 712 headers, as long as a regular Body Length header encodes the last 713 portion of the data. Note also that the last Body Length header can 714 be a zero-length header. 716 An implementation MAY use Partial Body Lengths for data packets, be 717 they literal, compressed, or encrypted. The first partial length 718 MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 719 used for any other packet types. 721 Please note that in all of these explanations, the total length of 722 the packet is the length of the header(s) plus the length of the 723 body. 725 4.3. Packet Tags 727 The packet tag denotes what type of packet the body holds. Note that 728 old format headers can only have tags less than 16, whereas new 729 format headers can have tags as great as 63. The defined tags (in 730 decimal) are: 732 0 -- Reserved - a packet tag must not have this value 733 1 -- Public-Key Encrypted Session Key Packet 734 2 -- Signature Packet 735 3 -- Symmetric-Key Encrypted Session Key Packet 736 4 -- One-Pass Signature Packet 737 5 -- Secret Key Packet 738 6 -- Public Key Packet 739 7 -- Secret Subkey Packet 740 8 -- Compressed Data Packet 741 9 -- Symmetrically Encrypted Data Packet 742 10 -- Marker Packet 743 11 -- Literal Data Packet 744 12 -- Trust Packet 745 13 -- User ID Packet 746 14 -- Public Subkey Packet 747 15 -- Symmetrically Encrypted and Integrity Protected Data 748 Packet 749 16 -- Modification Detection Code Packet 750 60 to 63 -- Private or Experimental Values 752 5. Packet Types 754 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 756 A Public-Key Encrypted Session Key packet holds the session key used 757 to encrypt a message. Zero or more Encrypted Session Key packets 758 (either Public-Key or Symmetric-Key) may precede a Symmetrically 759 Encrypted Data Packet, which holds an encrypted message. The 760 message is encrypted with the session key, and the session key is 761 itself encrypted and stored in the Encrypted Session Key packet(s). 762 The Symmetrically Encrypted Data Packet is preceded by one 763 Public-Key Encrypted Session Key packet for each OpenPGP key to 764 which the message is encrypted. The recipient of the message finds 765 a session key that is encrypted to their public key, decrypts the 766 session key, and then uses the session key to decrypt the message. 768 The body of this packet consists of: 770 - A one-octet number giving the version number of the packet type. 771 The currently defined value for packet version is 3. An 772 implementation should accept, but not generate a version of 2, 773 which is equivalent to V3 in all other respects. 775 - An eight-octet number that gives the key ID of the public key 776 that the session key is encrypted to. 778 - A one-octet number giving the public key algorithm used. 780 - A string of octets that is the encrypted session key. This 781 string takes up the remainder of the packet, and its contents 782 are dependent on the public key algorithm used. 784 Algorithm Specific Fields for RSA encryption 786 - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 788 Algorithm Specific Fields for Elgamal encryption: 790 - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 792 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 794 The value "m" in the above formulas is derived from the session key 795 as follows. First the session key is prefixed with a one-octet 796 algorithm identifier that specifies the symmetric encryption 797 algorithm used to encrypt the following Symmetrically Encrypted Data 798 Packet. Then a two-octet checksum is appended which is equal to the 799 sum of the preceding session key octets, not including the algorithm 800 identifier, modulo 65536. This value is then encoded as described 801 in PKCS-1 block encoding EME-PKCS1-v1_5 [RFC2437] to form the "m" 802 value used in the formulas above. 804 Note that when an implementation forms several PKESKs with one 805 session key, forming a message that can be decrypted by several 806 keys, the implementation MUST make new PKCS-1 encoding for each key. 808 An implementation MAY accept or use a Key ID of zero as a "wild 809 card" or "speculative" Key ID. In this case, the receiving 810 implementation would try all available private keys, checking for a 811 valid decrypted session key. This format helps reduce traffic 812 analysis of messages. 814 5.2. Signature Packet (Tag 2) 816 A signature packet describes a binding between some public key and 817 some data. The most common signatures are a signature of a file or a 818 block of text, and a signature that is a certification of a user ID. 820 Two versions of signature packets are defined. Version 3 provides 821 basic signature information, while version 4 provides an expandable 822 format with subpackets that can specify more information about the 823 signature. PGP 2.6.x only accepts version 3 signatures. 825 Implementations MUST accept V3 signatures. Implementations SHOULD 826 generate V4 signatures. Implementations MAY generate a V3 signature 827 that can be verified by PGP 2.6.x. 829 Note that if an implementation is creating an encrypted and signed 830 message that is encrypted to a V3 key, it is reasonable to create a 831 V3 signature. 833 5.2.1. Signature Types 835 There are a number of possible meanings for a signature, which are 836 specified in a signature type octet in any given signature. These 837 meanings are: 839 0x00: Signature of a binary document. 840 This means the signer owns it, created it, or certifies that it 841 has not been modified. 843 0x01: Signature of a canonical text document. 844 This means the signer owns it, created it, or certifies that it 845 has not been modified. The signature is calculated over the 846 text data with its line endings converted to and 847 trailing blanks removed. 849 0x02: Standalone signature. 850 This signature is a signature of only its own subpacket 851 contents. It is calculated identically to a signature over a 852 zero-length binary document. Note that it doesn't make sense to 853 have a V3 standalone signature. 855 0x10: Generic certification of a User ID and Public Key packet. 856 The issuer of this certification does not make any particular 857 assertion as to how well the certifier has checked that the 858 owner of the key is in fact the person described by the user ID. 859 Note that all PGP "key signatures" are this type of 860 certification. 862 0x11: Persona certification of a User ID and Public Key packet. 863 The issuer of this certification has not done any verification 864 of the claim that the owner of this key is the user ID 865 specified. 867 0x12: Casual certification of a User ID and Public Key packet. 868 The issuer of this certification has done some casual 869 verification of the claim of identity. 871 0x13: Positive certification of a User ID and Public Key packet. 872 The issuer of this certification has done substantial 873 verification of the claim of identity. 875 Please note that the vagueness of these certification claims is 876 not a flaw, but a feature of the system. Because PGP places 877 final authority for validity upon the receiver of a 878 certification, it may be that one authority's casual 879 certification might be more rigorous than some other authority's 880 positive certification. These classifications allow a 881 certification authority to issue fine-grained claims. 883 0x18: Subkey Binding Signature 884 This signature is a statement by the top-level signing key 885 indicates that it owns the subkey. This signature is calculated 886 directly on the subkey itself, not on any User ID or other 887 packets. 889 0x1F: Signature directly on a key 890 This signature is calculated directly on a key. It binds the 891 information in the signature subpackets to the key, and is 892 appropriate to be used for subpackets that provide information 893 about the key, such as the revocation key subpacket. It is also 894 appropriate for statements that non-self certifiers want to make 895 about the key itself, rather than the binding between a key and 896 a name. 898 0x20: Key revocation signature 899 The signature is calculated directly on the key being revoked. 900 A revoked key is not to be used. Only revocation signatures by 901 the key being revoked, or by an authorized revocation key, 902 should be considered valid revocation signatures. 904 0x28: Subkey revocation signature 905 The signature is calculated directly on the subkey being 906 revoked. A revoked subkey is not to be used. Only revocation 907 signatures by the top-level signature key that is bound to this 908 subkey, or by an authorized revocation key, should be considered 909 valid revocation signatures. 911 0x30: Certification revocation signature 912 This signature revokes an earlier user ID certification 913 signature (signature class 0x10 through 0x13). It should be 914 issued by the same key that issued the revoked signature or an 915 authorized revocation key The signature should have a later 916 creation date than the signature it revokes. 918 0x40: Timestamp signature. 919 This signature is only meaningful for the timestamp contained in 920 it. 922 5.2.2. Version 3 Signature Packet Format 924 The body of a version 3 Signature Packet contains: 926 - One-octet version number (3). 928 - One-octet length of following hashed material. MUST be 5. 930 - One-octet signature type. 932 - Four-octet creation time. 934 - Eight-octet key ID of signer. 936 - One-octet public key algorithm. 938 - One-octet hash algorithm. 940 - Two-octet field holding left 16 bits of signed hash value. 942 - One or more multi-precision integers comprising the signature. 943 This portion is algorithm specific, as described below. 945 The data being signed is hashed, and then the signature type and 946 creation time from the signature packet are hashed (5 additional 947 octets). The resulting hash value is used in the signature 948 algorithm. The high 16 bits (first two octets) of the hash are 949 included in the signature packet to provide a quick test to reject 950 some invalid signatures. 952 Algorithm Specific Fields for RSA signatures: 954 - multiprecision integer (MPI) of RSA signature value m**d mod n. 956 Algorithm Specific Fields for DSA signatures: 958 - MPI of DSA value r. 960 - MPI of DSA value s. 962 The signature calculation is based on a hash of the signed data, as 963 described above. The details of the calculation are different for 964 DSA signature than for RSA signatures. 966 With RSA signatures, the hash value is encoded as described in 967 PKCS-1 section 9.2.1 encoded using PKCS-1 encoding type 968 EMSA-PKCS1-v1_5 [RFC2437]. This requires inserting the hash value 969 as an octet string into an ASN.1 structure. The object identifier 970 for the type of hash being used is included in the structure. The 971 hexadecimal representations for the currently defined hash 972 algorithms are: 974 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02 976 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 978 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 980 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 982 The ASN.1 OIDs are: 984 - MD2: 1.2.840.113549.2.2 986 - MD5: 1.2.840.113549.2.5 988 - RIPEMD-160: 1.3.36.3.2.1 990 - SHA-1: 1.3.14.3.2.26 992 The full hash prefixes for these are: 994 MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 995 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00, 996 0x04, 0x10 998 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 999 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 1000 0x04, 0x10 1002 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 1003 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 1005 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 1006 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 1008 DSA signatures MUST use hashes with a size of 160 bits, to match q, 1009 the size of the group generated by the DSA key's generator value. 1010 The hash function result is treated as a 160 bit number and used 1011 directly in the DSA signature algorithm. 1013 5.2.3. Version 4 Signature Packet Format 1015 The body of a version 4 Signature Packet contains: 1017 - One-octet version number (4). 1019 - One-octet signature type. 1021 - One-octet public key algorithm. 1023 - One-octet hash algorithm. 1025 - Two-octet scalar octet count for following hashed subpacket 1026 data. Note that this is the length in octets of all of the 1027 hashed subpackets; a pointer incremented by this number will 1028 skip over the hashed subpackets. 1030 - Hashed subpacket data. (two or more subpackets) 1032 - Two-octet scalar octet count for following unhashed subpacket 1033 data. Note that this is the length in octets of all of the 1034 unhashed subpackets; a pointer incremented by this number will 1035 skip over the unhashed subpackets. 1037 - Unhashed subpacket data. (zero or more subpackets) 1039 - Two-octet field holding left 16 bits of signed hash value. 1041 - One or more multi-precision integers comprising the signature. 1042 This portion is algorithm specific, as described above. 1044 The data being signed is hashed, and then the signature data from 1045 the version number through the hashed subpacket data (inclusive) is 1046 hashed. The resulting hash value is what is signed. The left 16 1047 bits of the hash are included in the signature packet to provide a 1048 quick test to reject some invalid signatures. 1050 There are two fields consisting of signature subpackets. The first 1051 field is hashed with the rest of the signature data, while the 1052 second is unhashed. The second set of subpackets is not 1053 cryptographically protected by the signature and should include only 1054 advisory information. 1056 The algorithms for converting the hash function result to a 1057 signature are described in a section below. 1059 5.2.3.1. Signature Subpacket Specification 1061 The subpacket fields consist of zero or more signature subpackets. 1062 Each set of subpackets is preceded by a two-octet scalar count of 1063 the length of the set of subpackets. 1065 Each subpacket consists of a subpacket header and a body. The 1066 header consists of: 1068 - the subpacket length (1, 2, or 5 octets) 1070 - the subpacket type (1 octet) 1072 and is followed by the subpacket specific data. 1074 The length includes the type octet but not this length. Its format 1075 is similar to the "new" format packet header lengths, but cannot 1076 have partial body lengths. That is: 1078 if the 1st octet < 192, then 1079 lengthOfLength = 1 1080 subpacketLen = 1st_octet 1082 if the 1st octet >= 192 and < 255, then 1083 lengthOfLength = 2 1084 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1086 if the 1st octet = 255, then 1087 lengthOfLength = 5 1088 subpacket length = [four-octet scalar starting at 2nd_octet] 1090 The value of the subpacket type octet may be: 1092 2 = signature creation time 1093 3 = signature expiration time 1094 4 = exportable certification 1095 5 = trust signature 1096 6 = regular expression 1097 7 = revocable 1098 9 = key expiration time 1099 10 = placeholder for backward compatibility 1100 11 = preferred symmetric algorithms 1101 12 = revocation key 1102 16 = issuer key ID 1103 20 = notation data 1104 21 = preferred hash algorithms 1105 22 = preferred compression algorithms 1106 23 = key server preferences 1107 24 = preferred key server 1108 25 = primary user id 1109 26 = policy URL 1110 27 = key flags 1111 28 = signer's user id 1112 29 = reason for revocation 1113 30 = features 1114 100 to 110 = internal or user-defined 1116 An implementation SHOULD ignore any subpacket of a type that it does 1117 not recognize. 1119 Bit 7 of the subpacket type is the "critical" bit. If set, it 1120 denotes that the subpacket is one that is critical for the evaluator 1121 of the signature to recognize. If a subpacket is encountered that 1122 is marked critical but is unknown to the evaluating software, the 1123 evaluator SHOULD consider the signature to be in error. 1125 An evaluator may "recognize" a subpacket, but not implement it. The 1126 purpose of the critical bit is to allow the signer to tell an 1127 evaluator that it would prefer a new, unknown feature to generate an 1128 error than be ignored. 1130 Implementations SHOULD implement "preferences" and the "reason for 1131 revocation" subpackets. Note, however, that if an implementation 1132 chooses not to implement some of the preferences, it is required to 1133 behave in a polite manner to respect the wishes of those users who 1134 do implement these preferences. 1136 5.2.3.2. Signature Subpacket Types 1138 A number of subpackets are currently defined. Some subpackets apply 1139 to the signature itself and some are attributes of the key. 1140 Subpackets that are found on a self-signature are placed on a user 1141 id certification made by the key itself. Note that a key may have 1142 more than one user id, and thus may have more than one 1143 self-signature, and differing subpackets. 1145 A subpacket may be found either in the hashed or unhashed subpacket 1146 sections of a signature. If a subpacket is not hashed, then the 1147 information in it cannot be considered definitive because it is not 1148 part of the signature proper. 1150 5.2.3.3. Notes on Self-Signatures 1152 A self-signature is a binding signature made by the key the 1153 signature refers to. There are three types of self-signatures, the 1154 certification signatures (types 0x10-0x13), the direct-key signature 1155 (type 0x1f), and the subkey binding signature (type 0x18). For 1156 certification self-signatures, each user ID may have a 1157 self-signature, and thus different subpackets in those 1158 self-signatures. For subkey binding signatures, each subkey in fact 1159 has a self-signature. Subpackets that appear in a certification 1160 self-signature apply to the username, and subpackets that appear in 1161 the subkey self-signature apply to the subkey. Lastly, subpackets on 1162 the direct key signature apply to the entire key. 1164 Implementing software should interpret a self-signature's preference 1165 subpackets as narrowly as possible. For example, suppose a key has 1166 two usernames, Alice and Bob. Suppose that Alice prefers the 1167 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If 1168 the software locates this key via Alice's name, then the preferred 1169 algorithm is CAST5, if software locates the key via Bob's name, then 1170 the preferred algorithm is IDEA. If the key is located by key id, 1171 then algorithm of the default user id of the key provides the 1172 default symmetric algorithm. 1174 Revoking a self-signature has defined semantic meanings. Revoking 1175 the self-signature on a certification effectively retires that user 1176 name. The self-signature is a statement, "My name X is tied to my 1177 signing key K" and is corroborated by other users' certifications. 1178 If another user revokes their certification, they are effectively 1179 saying that they no longer believe that name and that key are tied 1180 together. Similarly, if the user themselves revokes their 1181 self-signature, it means the user no longer goes by that name, no 1182 longer has that email address, etc. Revoking a binding signature 1183 effectively retires that subkey. Please see the "Reason for 1184 Revocation" subpacket below for more relevant detail. 1186 Since a self-signatures contain important information about the 1187 key's use, an implementation SHOULD allow the user to rewrite the 1188 self-signature, and important information in it, such as preferences 1189 and key expiration. 1191 5.2.3.4. Signature creation time 1193 (4 octet time field) 1195 The time the signature was made. 1197 MUST be present in the hashed area. 1199 5.2.3.5. Issuer 1201 (8 octet key ID) 1203 The OpenPGP key ID of the key issuing the signature. 1205 5.2.3.6. Key expiration time 1207 (4 octet time field) 1209 The validity period of the key. This is the number of seconds after 1210 the key creation time that the key expires. If this is not present 1211 or has a value of zero, the key never expires. This is found only on 1212 a self-signature. 1214 5.2.3.7. Preferred symmetric algorithms 1216 (sequence of one-octet values) 1218 Symmetric algorithm numbers that indicate which algorithms the key 1219 holder prefers to use. The subpacket body is an ordered list of 1220 octets with the most preferred listed first. It is assumed that only 1221 algorithms listed are supported by the recipient's software. 1222 Algorithm numbers in section 9. This is only found on a 1223 self-signature. 1225 5.2.3.8. Preferred hash algorithms 1227 (array of one-octet values) 1229 Message digest algorithm numbers that indicate which algorithms the 1230 key holder prefers to receive. Like the preferred symmetric 1231 algorithms, the list is ordered. Algorithm numbers are in section 6. 1232 This is only found on a self-signature. 1234 5.2.3.9. Preferred compression algorithms 1236 (array of one-octet values) 1238 Compression algorithm numbers that indicate which algorithms the key 1239 holder prefers to use. Like the preferred symmetric algorithms, the 1240 list is ordered. Algorithm numbers are in section 6. If this 1241 subpacket is not included, ZIP is preferred. A zero denotes that 1242 uncompressed data is preferred; the key holder's software might have 1243 no compression software in that implementation. This is only found 1244 on a self-signature. 1246 5.2.3.10. Signature expiration time 1248 (4 octet time field) 1250 The validity period of the signature. This is the number of seconds 1251 after the signature creation time that the signature expires. If 1252 this is not present or has a value of zero, it never expires. 1254 5.2.3.11. Exportable Certification 1256 (1 octet of exportability, 0 for not, 1 for exportable) 1258 This subpacket denotes whether a certification signature is 1259 "exportable," to be used by other users than the signature's issuer. 1260 The packet body contains a boolean flag indicating whether the 1261 signature is exportable. If this packet is not present, the 1262 certification is exportable; it is equivalent to a flag containing a 1263 1. 1265 Non-exportable, or "local," certifications are signatures made by a 1266 user to mark a key as valid within that user's implementation only. 1267 Thus, when an implementation prepares a user's copy of a key for 1268 transport to another user (this is the process of "exporting" the 1269 key), any local certification signatures are deleted from the key. 1271 The receiver of a transported key "imports" it, and likewise trims 1272 any local certifications. In normal operation, there won't be any, 1273 assuming the import is performed on an exported key. However, there 1274 are instances where this can reasonably happen. For example, if an 1275 implementation allows keys to be imported from a key database in 1276 addition to an exported key, then this situation can arise. 1278 Some implementations do not represent the interest of a single user 1279 (for example, a key server). Such implementations always trim local 1280 certifications from any key they handle. 1282 5.2.3.12. Revocable 1284 (1 octet of revocability, 0 for not, 1 for revocable) 1285 Signature's revocability status. Packet body contains a boolean 1286 flag indicating whether the signature is revocable. Signatures that 1287 are not revocable have any later revocation signatures ignored. 1288 They represent a commitment by the signer that he cannot revoke his 1289 signature for the life of his key. If this packet is not present, 1290 the signature is revocable. 1292 5.2.3.13. Trust signature 1294 (1 octet "level" (depth), 1 octet of trust amount) 1296 Signer asserts that the key is not only valid, but also trustworthy, 1297 at the specified level. Level 0 has the same meaning as an ordinary 1298 validity signature. Level 1 means that the signed key is asserted 1299 to be a valid trusted introducer, with the 2nd octet of the body 1300 specifying the degree of trust. Level 2 means that the signed key is 1301 asserted to be trusted to issue level 1 trust signatures, i.e. that 1302 it is a "meta introducer". Generally, a level n trust signature 1303 asserts that a key is trusted to issue level n-1 trust signatures. 1304 The trust amount is in a range from 0-255, interpreted such that 1305 values less than 120 indicate partial trust and values of 120 or 1306 greater indicate complete trust. Implementations SHOULD emit values 1307 of 60 for partial trust and 120 for complete trust. 1309 5.2.3.14. Regular expression 1311 (null-terminated regular expression) 1313 Used in conjunction with trust signature packets (of level > 0) to 1314 limit the scope of trust that is extended. Only signatures by the 1315 target key on user IDs that match the regular expression in the body 1316 of this packet have trust extended by the trust signature subpacket. 1317 The regular expression uses the same syntax as the Henry Spencer's 1318 "almost public domain" regular expression package. A description of 1319 the syntax is found in a section below. 1321 5.2.3.15. Revocation key 1323 (1 octet of class, 1 octet of algid, 20 octets of fingerprint) 1325 Authorizes the specified key to issue revocation signatures for this 1326 key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1327 then this means that the revocation information is sensitive. Other 1328 bits are for future expansion to other kinds of authorizations. This 1329 is found on a self-signature. 1331 If the "sensitive" flag is set, the keyholder feels this subpacket 1332 contains private trust information that describes a real-world 1333 sensitive relationship. If this flag is set, implementations SHOULD 1334 NOT export this signature to other users except in cases where the 1335 data needs to be available: when the signature is being sent to the 1336 designated revoker, or when it is accompanied by a revocation 1337 signature from that revoker. Note that it may be appropriate to 1338 isolate this subpacket within a separate signature so that it is not 1339 combined with other subpackets that need to be exported. 1341 5.2.3.16. Notation Data 1343 (4 octets of flags, 2 octets of name length (M), 1344 2 octets of value length (N), 1345 M octets of name data, 1346 N octets of value data) 1348 This subpacket describes a "notation" on the signature that the 1349 issuer wishes to make. The notation has a name and a value, each of 1350 which are strings of octets. There may be more than one notation in 1351 a signature. Notations can be used for any extension the issuer of 1352 the signature cares to make. The "flags" field holds four octets of 1353 flags. 1355 All undefined flags MUST be zero. Defined flags are: 1357 First octet: 0x80 = human-readable. This note is text, a note 1358 from one person to another, and has no 1359 meaning to software. 1360 Other octets: none. 1362 Notation names are arbitrary strings encoded in UTF-8. They reside 1363 two name spaces: The IETF name space and the user name space. 1365 The IETF name space is registered with IANA. These names MUST NOT 1366 contain the "@" character (0x40) is this is a tag for the user name 1367 space. 1369 Names in the user name space consist of a UTF-8 string tag followed 1370 by "@" followed by a DNS domain name. Note that the tag MUST NOT 1371 contain an "@" character. For example, the "sample" tag used by 1372 Example Corporation could be "sample@example.com". 1374 Names in a user space are owned and controlled by the owners of that 1375 domain. Obviously, it's of bad form to create a new name in a DNS 1376 space that you don't own. 1378 5.2.3.17. Key server preferences 1380 (N octets of flags) 1382 This is a list of flags that indicate preferences that the key 1383 holder has about how the key is handled on a key server. All 1384 undefined flags MUST be zero. 1386 First octet: 0x80 = No-modify 1387 the key holder requests that this key only be modified or 1388 updated by the key holder or an administrator of the key server. 1390 This is found only on a self-signature. 1392 5.2.3.18. Preferred key server 1394 (String) 1396 This is a URL of a key server that the key holder prefers be used 1397 for updates. Note that keys with multiple user ids can have a 1398 preferred key server for each user id. Note also that since this is 1399 a URL, the key server can actually be a copy of the key retrieved by 1400 ftp, http, finger, etc. 1402 5.2.3.19. Primary user id 1404 (1 octet, boolean) 1406 This is a flag in a user id's self signature that states whether 1407 this user id is the main user id for this key. It is reasonable for 1408 an implementation to resolve ambiguities in preferences, etc. by 1409 referring to the primary user id. If this flag is absent, its value 1410 is zero. If more than one user id in a key is marked as primary, the 1411 implementation may resolve the ambiguity in any way it sees fit. 1413 5.2.3.20. Policy URL 1415 (String) 1417 This subpacket contains a URL of a document that describes the 1418 policy that the signature was issued under. 1420 5.2.3.21. Key Flags 1422 (Octet string) 1424 This subpacket contains a list of binary flags that hold information 1425 about a key. It is a string of octets, and an implementation MUST 1426 NOT assume a fixed size. This is so it can grow over time. If a list 1427 is shorter than an implementation expects, the unstated flags are 1428 considered to be zero. The defined flags are: 1430 First octet: 1432 0x01 - This key may be used to certify other keys. 1434 0x02 - This key may be used to sign data. 1436 0x04 - This key may be used to encrypt communications. 1438 0x08 - This key may be used to encrypt storage. 1440 0x10 - The private component of this key may have been split by 1441 a secret-sharing mechanism. 1443 0x80 - The private component of this key may be in the 1444 possession of more than one person. 1446 Usage notes: 1448 The flags in this packet may appear in self-signatures or in 1449 certification signatures. They mean different things depending on 1450 who is making the statement -- for example, a certification 1451 signature that has the "sign data" flag is stating that the 1452 certification is for that use. On the other hand, the 1453 "communications encryption" flag in a self-signature is stating a 1454 preference that a given key be used for communications. Note 1455 however, that it is a thorny issue to determine what is 1456 "communications" and what is "storage." This decision is left wholly 1457 up to the implementation; the authors of this document do not claim 1458 any special wisdom on the issue, and realize that accepted opinion 1459 may change. 1461 The "split key" (0x10) and "group key" (0x80) flags are placed on a 1462 self-signature only; they are meaningless on a certification 1463 signature. They SHOULD be placed only on a direct-key signature 1464 (type 0x1f) or a subkey signature (type 0x18), one that refers to 1465 the key the flag applies to. 1467 5.2.3.22. Signer's User ID 1469 This subpacket allows a keyholder to state which user id is 1470 responsible for the signing. Many keyholders use a single key for 1471 different purposes, such as business communications as well as 1472 personal communications. This subpacket allows such a keyholder to 1473 state which of their roles is making a signature. 1475 5.2.3.23. Reason for Revocation 1477 (1 octet of revocation code, N octets of reason string) 1479 This subpacket is used only in key revocation and certification 1480 revocation signatures. It describes the reason why the key or 1481 certificate was revoked. 1483 The first octet contains a machine-readable code that denotes the 1484 reason for the revocation: 1486 0x00 - No reason specified (key revocations or cert revocations) 1487 0x01 - Key is superceded (key revocations) 1488 0x02 - Key material has been compromised (key revocations) 1489 0x03 - Key is retired and no longer used (key revocations) 1490 0x20 - User id information is no longer valid (cert revocations) 1492 Following the revocation code is a string of octets which gives 1493 information about the reason for revocation in human-readable form 1494 (UTF-8). The string may be null, that is, of zero length. The length 1495 of the subpacket is the length of the reason string plus one. 1497 An implementation SHOULD implement this subpacket, include it in all 1498 revocation signatures, and interpret revocations appropriately. 1499 There are important semantic differences between the reasons, and 1500 there are thus important reasons for revoking signatures. 1502 If a key has been revoked because of a compromise, all signatures 1503 created by that key are suspect. However, if it was merely 1504 superceded or retired, old signatures are still valid. If the 1505 revoked signature is the self-signature for certifying a user id, a 1506 revocation denotes that that user name is no longer in use. Such a 1507 revocation SHOULD inclide an 0x20 subpacket. 1509 Note that any signature may be revoked, including a certification on 1510 some other person's key. There are many good reasons for revoking a 1511 certification signature, such as the case where the keyholder leaves 1512 the employ of a business with an email address. A revoked 1513 certification no longer is a part of validity calculations. 1515 5.2.3.24. Features 1517 (array of one-octet values) 1519 The features subpacket denotes which advanced OpenPGP features a 1520 user's implementation supports. This is so that as features are 1521 added to OpenPGP that cannot be backwards-compatible, a user can 1522 state that they can use that feature. 1524 This subpacket is similar to a preferences subpacket, and only 1525 appears in a self-signature. 1527 An implementation SHOULD NOT use a feature listed when sending to a 1528 user who does not state that they can use it. 1530 Defined features are: 1532 1 - Modification Detection (packets 15 and 16) 1534 If an implementation implements any of the defined features, it 1535 SHOULD implement the features subpacket, too. 1537 5.2.4. Computing Signatures 1539 All signatures are formed by producing a hash over the signature 1540 data, and then using the resulting hash in the signature algorithm. 1542 The signature data is simple to compute for document signatures 1543 (types 0x00 and 0x01), for which the document itself is the data. 1544 For standalone signatures, this is a null string. 1546 When a signature is made over a key, the hash data starts with the 1547 octet 0x99, followed by a two-octet length of the key, and then body 1548 of the key packet. (Note that this is an old-style packet header for 1549 a key packet with two-octet length.) A subkey signature (type 0x18) 1550 then hashes the subkey, using the same format as the main key. Key 1551 revocation signatures (types 0x20 and 0x28) hash only the key being 1552 revoked. 1554 A certification signature (type 0x10 through 0x13) hashes the user 1555 id being bound to the key into the hash context after the above 1556 data. A V3 certification hashes the contents of the name packet, 1557 without any header. A V4 certification hashes the constant 0xb4 1558 (which is an old-style packet header with the length-of-length set 1559 to zero), a four-octet number giving the length of the username, and 1560 then the username data. 1562 Once the data body is hashed, then a trailer is hashed. A V3 1563 signature hashes five octets of the packet body, starting from the 1564 signature type field. This data is the signature type, followed by 1565 the four-octet signature time. A V4 signature hashes the packet body 1566 starting from its first field, the version number, through the end 1567 of the hashed subpacket data. Thus, the fields hashed are the 1568 signature version, the signature type, the public key algorithm, the 1569 hash algorithm, the hashed subpacket length, and the hashed 1570 subpacket body. 1572 V4 signatures also hash in a final trailer of six octets: the 1573 version of the signature packet, i.e. 0x04; 0xFF; a four-octet, 1574 big-endian number that is the length of the hashed data from the 1575 signature packet (note that this number does not include these final 1576 six octets. 1578 After all this has been hashed, the resulting hash field is used in 1579 the signature algorithm, and placed at the end of the signature 1580 packet. 1582 5.2.4.1. Subpacket Hints 1584 An implementation SHOULD put the two mandatory subpackets, creation 1585 time and issuer, as the first subpackets in the subpacket list, 1586 simply to make it easier for the implementer to find them. 1588 It is certainly possible for a signature to contain conflicting 1589 information in subpackets. For example, a signature may contain 1590 multiple copies of a preference or multiple expiration times. In 1591 most cases, an implementation SHOULD use the last subpacket in the 1592 signature, but MAY use any conflict resolution scheme that makes 1593 more sense. Please note that we are intentionally leaving conflict 1594 resolution to the implementer; most conflicts are simply syntax 1595 errors, and the wishy-washy language here allows a receiver to be 1596 generous in what they accept, while putting pressure on a creator to 1597 be stingy in what they generate. 1599 Some apparent conflicts may actually make sense -- for example, 1600 suppose a keyholder has an V3 key and a V4 key that share the same 1601 RSA key material. Either of these keys can verify a signature 1602 created by the other, and it may be reasonable for a signature to 1603 contain an issuer subpacket for each key, as a way of explicitly 1604 tying those keys to the signature. 1606 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 1608 The Symmetric-Key Encrypted Session Key packet holds the 1609 symmetric-key encryption of a session key used to encrypt a message. 1610 Zero or more Encrypted Session Key packets and/or Symmetric-Key 1611 Encrypted Session Key packets may precede a Symmetrically Encrypted 1612 Data Packet that holds an encrypted message. The message is 1613 encrypted with a session key, and the session key is itself 1614 encrypted and stored in the Encrypted Session Key packet or the 1615 Symmetric-Key Encrypted Session Key packet. 1617 If the Symmetrically Encrypted Data Packet is preceded by one or 1618 more Symmetric-Key Encrypted Session Key packets, each specifies a 1619 passphrase that may be used to decrypt the message. This allows a 1620 message to be encrypted to a number of public keys, and also to one 1621 or more pass phrases. This packet type is new, and is not generated 1622 by PGP 2.x or PGP 5.0. 1624 The body of this packet consists of: 1626 - A one-octet version number. The only currently defined version 1627 is 4. 1629 - A one-octet number describing the symmetric algorithm used. 1631 - A string-to-key (S2K) specifier, length as defined above. 1633 - Optionally, the encrypted session key itself, which is decrypted 1634 with the string-to-key object. 1636 If the encrypted session key is not present (which can be detected 1637 on the basis of packet length and S2K specifier size), then the S2K 1638 algorithm applied to the passphrase produces the session key for 1639 decrypting the file, using the symmetric cipher algorithm from the 1640 Symmetric-Key Encrypted Session Key packet. 1642 If the encrypted session key is present, the result of applying the 1643 S2K algorithm to the passphrase is used to decrypt just that 1644 encrypted session key field, using CFB mode with an IV of all zeros. 1645 The decryption result consists of a one-octet algorithm identifier 1647 that specifies the symmetric-key encryption algorithm used to 1648 encrypt the following Symmetrically Encrypted Data Packet, followed 1649 by the session key octets themselves. 1651 Note: because an all-zero IV is used for this decryption, the S2K 1652 specifier MUST use a salt value, either a Salted S2K or an 1653 Iterated-Salted S2K. The salt value will insure that the decryption 1654 key is not repeated even if the passphrase is reused. 1656 5.4. One-Pass Signature Packets (Tag 4) 1658 The One-Pass Signature packet precedes the signed data and contains 1659 enough information to allow the receiver to begin calculating any 1660 hashes needed to verify the signature. It allows the Signature 1661 Packet to be placed at the end of the message, so that the signer 1662 can compute the entire signed message in one pass. 1664 A One-Pass Signature does not interoperate with PGP 2.6.x or 1665 earlier. 1667 The body of this packet consists of: 1669 - A one-octet version number. The current version is 3. 1671 - A one-octet signature type. Signature types are described in 1672 section 5.2.1. 1674 - A one-octet number describing the hash algorithm used. 1676 - A one-octet number describing the public key algorithm used. 1678 - An eight-octet number holding the key ID of the signing key. 1680 - A one-octet number holding a flag showing whether the signature 1681 is nested. A zero value indicates that the next packet is 1682 another One-Pass Signature packet that describes another 1683 signature to be applied to the same message data. 1685 Note that if a message contains more than one one-pass signature, 1686 then the signature packets bracket the message; that is, the first 1687 signature packet after the message corresponds to the last one-pass 1688 packet and the final signature packet corresponds to the first 1689 one-pass packet. 1691 5.5. Key Material Packet 1693 A key material packet contains all the information about a public or 1694 private key. There are four variants of this packet type, and two 1695 major versions. Consequently, this section is complex. 1697 5.5.1. Key Packet Variants 1699 5.5.1.1. Public Key Packet (Tag 6) 1701 A Public Key packet starts a series of packets that forms an OpenPGP 1702 key (sometimes called an OpenPGP certificate). 1704 5.5.1.2. Public Subkey Packet (Tag 14) 1706 A Public Subkey packet (tag 14) has exactly the same format as a 1707 Public Key packet, but denotes a subkey. One or more subkeys may be 1708 associated with a top-level key. By convention, the top-level key 1709 provides signature services, and the subkeys provide encryption 1710 services. 1712 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 1713 packet. This tag was selected for reuse because no previous version 1714 of PGP ever emitted comment packets but they did properly ignore 1715 them. Public Subkey packets are ignored by PGP 2.6.x and do not 1716 cause it to fail, providing a limited degree of backward 1717 compatibility. 1719 5.5.1.3. Secret Key Packet (Tag 5) 1721 A Secret Key packet contains all the information that is found in a 1722 Public Key packet, including the public key material, but also 1723 includes the secret key material after all the public key fields. 1725 5.5.1.4. Secret Subkey Packet (Tag 7) 1727 A Secret Subkey packet (tag 7) is the subkey analog of the Secret 1728 Key packet, and has exactly the same format. 1730 5.5.2. Public Key Packet Formats 1732 There are two versions of key-material packets. Version 3 packets 1733 were first generated by PGP 2.6. Version 2 packets are identical in 1734 format to Version 3 packets, but are generated by PGP 2.5 or before. 1735 V2 packets are deprecated and they MUST NOT be generated. 1737 PGP 5.0 introduced version 4 packets, with new fields and semantics. 1738 PGP 2.6.x will not accept key-material packets with versions 1739 greater than 3. 1741 OpenPGP implementations SHOULD create keys with version 4 format. An 1742 implementation MAY generate a V3 key to ensure interoperability with 1743 old software; note, however, that V4 keys correct some security 1744 deficiencies in V3 keys. These deficiencies are described below. An 1745 implementation MUST NOT create a V3 key with a public key algorithm 1746 other than RSA. 1748 A version 3 public key or public subkey packet contains: 1750 - A one-octet version number (3). 1752 - A four-octet number denoting the time that the key was created. 1754 - A two-octet number denoting the time in days that this key is 1755 valid. If this number is zero, then it does not expire. 1757 - A one-octet number denoting the public key algorithm of this key 1759 - A series of multi-precision integers comprising the key 1760 material: 1762 - a multiprecision integer (MPI) of RSA public modulus n; 1764 - an MPI of RSA public encryption exponent e. 1766 V3 keys SHOULD only be used for backward compatibility because of 1767 three weaknesses in them. First, it is relatively easy to construct 1768 a V3 key that has the same key ID as any other key because the key 1769 ID is simply the low 64 bits of the public modulus. Secondly, 1770 because the fingerprint of a V3 key hashes the key material, but not 1771 its length, which increases the opportunity for fingerprint 1772 collisions. Third, there are minor weaknesses in the MD5 hash 1773 algorithm that make developers prefer other algorithms. See below 1774 for a fuller discussion of key IDs and fingerprints. 1776 The version 4 format is similar to the version 3 format except for 1777 the absence of a validity period. This has been moved to the 1778 signature packet. In addition, fingerprints of version 4 keys are 1779 calculated differently from version 3 keys, as described in section 1780 "Enhanced Key Formats." 1782 A version 4 packet contains: 1784 - A one-octet version number (4). 1786 - A four-octet number denoting the time that the key was created. 1788 - A one-octet number denoting the public key algorithm of this key 1790 - A series of multi-precision integers comprising the key 1791 material. This algorithm-specific portion is: 1793 Algorithm Specific Fields for RSA public keys: 1795 - multiprecision integer (MPI) of RSA public modulus n; 1797 - MPI of RSA public encryption exponent e. 1799 Algorithm Specific Fields for DSA public keys: 1801 - MPI of DSA prime p; 1803 - MPI of DSA group order q (q is a prime divisor of p-1); 1805 - MPI of DSA group generator g; 1807 - MPI of DSA public key value y (= g**x mod p where x is 1808 secret). 1810 Algorithm Specific Fields for Elgamal public keys: 1812 - MPI of Elgamal prime p; 1814 - MPI of Elgamal group generator g; 1816 - MPI of Elgamal public key value y (= g**x mod p where x is 1817 secret). 1819 5.5.3. Secret Key Packet Formats 1821 The Secret Key and Secret Subkey packets contain all the data of the 1822 Public Key and Public Subkey packets, with additional 1823 algorithm-specific secret key data appended, in encrypted form. 1825 The packet contains: 1827 - A Public Key or Public Subkey packet, as described above 1829 - One octet indicating string-to-key usage conventions. 0 1830 indicates that the secret key data is not encrypted. 255 1831 indicates that a string-to-key specifier is being given. Any 1832 other value is a symmetric-key encryption algorithm specifier. 1834 - [Optional] If string-to-key usage octet was 255, a one-octet 1835 symmetric encryption algorithm. 1837 - [Optional] If string-to-key usage octet was 255, a string-to-key 1838 specifier. The length of the string-to-key specifier is implied 1839 by its type, as described above. 1841 - [Optional] If secret data is encrypted, Initial Vector (IV) of 1842 the same length as the cipher's block size. 1844 - Encrypted multi-precision integers comprising the secret key 1845 data. These algorithm-specific fields are as described below. 1847 - Two-octet checksum of the plaintext of the algorithm-specific 1848 portion (sum of all octets, mod 65536). 1850 Algorithm Specific Fields for RSA secret keys: 1852 - multiprecision integer (MPI) of RSA secret exponent d. 1854 - MPI of RSA secret prime value p. 1856 - MPI of RSA secret prime value q (p < q). 1858 - MPI of u, the multiplicative inverse of p, mod q. 1860 Algorithm Specific Fields for DSA secret keys: 1862 - MPI of DSA secret exponent x. 1864 Algorithm Specific Fields for Elgamal secret keys: 1866 - MPI of Elgamal secret exponent x. 1868 Secret MPI values can be encrypted using a passphrase. If a 1869 string-to-key specifier is given, that describes the algorithm for 1870 converting the passphrase to a key, else a simple MD5 hash of the 1871 passphrase is used. Implementations SHOULD use a string-to-key 1872 specifier; the simple hash is for backward compatibility. The cipher 1873 for encrypting the MPIs is specified in the secret key packet. 1875 Encryption/decryption of the secret data is done in CFB mode using 1876 the key created from the passphrase and the Initial Vector from the 1877 packet. A different mode is used with V3 keys (which are only RSA) 1878 than with other key formats. With V3 keys, the MPI bit count prefix 1879 (i.e., the first two octets) is not encrypted. Only the MPI 1880 non-prefix data is encrypted. Furthermore, the CFB state is 1881 resynchronized at the beginning of each new MPI value, so that the 1882 CFB block boundary is aligned with the start of the MPI data. 1884 With V4 keys, a simpler method is used. All secret MPI values are 1885 encrypted in CFB mode, including the MPI bitcount prefix. 1887 The 16-bit checksum that follows the algorithm-specific portion is 1888 the algebraic sum, mod 65536, of the plaintext of all the 1889 algorithm-specific octets (including MPI prefix and data). With V3 1890 keys, the checksum is stored in the clear. With V4 keys, the 1891 checksum is encrypted like the algorithm-specific data. This value 1892 is used to check that the passphrase was correct. 1894 5.6. Compressed Data Packet (Tag 8) 1896 The Compressed Data packet contains compressed data. Typically, this 1897 packet is found as the contents of an encrypted packet, or following 1898 a Signature or One-Pass Signature packet, and contains literal data 1899 packets. 1901 The body of this packet consists of: 1903 - One octet that gives the algorithm used to compress the packet. 1905 - The remainder of the packet is compressed data. 1907 A Compressed Data Packet's body contains an block that compresses 1908 some set of packets. See section "Packet Composition" for details on 1909 how messages are formed. 1911 ZIP-compressed packets are compressed with raw RFC1951 DEFLATE 1912 blocks. Note that PGP V2.6 uses 13 bits of compression. If an 1913 implementation uses more bits of compression, PGP V2.6 cannot 1914 decompress it. 1916 ZLIB-compressed packets are compressed with RFC1950 ZLIB-style 1917 blocks. 1919 5.7. Symmetrically Encrypted Data Packet (Tag 9) 1921 The Symmetrically Encrypted Data packet contains data encrypted with 1922 a symmetric-key algorithm. When it has been decrypted, it contains 1923 other packets (usually literal data packets or compressed data 1924 packets, but in theory other Symmetrically Encrypted Data Packets or 1925 sequences of packets that form whole OpenPGP messages). 1927 The body of this packet consists of: 1929 - Encrypted data, the output of the selected symmetric-key cipher 1930 operating in PGP's variant of Cipher Feedback (CFB) mode. 1932 The symmetric cipher used may be specified in an Public-Key or 1933 Symmetric-Key Encrypted Session Key packet that precedes the 1934 Symmetrically Encrypted Data Packet. In that case, the cipher 1935 algorithm octet is prefixed to the session key before it is 1936 encrypted. If no packets of these types precede the encrypted data, 1937 the IDEA algorithm is used with the session key calculated as the 1938 MD5 hash of the passphrase. 1940 The data is encrypted in CFB mode, with a CFB shift size equal to 1941 the cipher's block size. The Initial Vector (IV) is specified as 1942 all zeros. Instead of using an IV, OpenPGP prefixes a string of 1943 length equal to the block size of the cipher plus two to the data 1944 before it is encrypted. The first block-length octets (for example, 1945 8 octets for a 64-bit block length) are random, and the following 1946 two octets are copies of the last two octets of the IV. For example, 1947 in an 8 octet block, octet 9 is a repeat of octet 7, and octet 10 is 1948 a repeat of octet 8. In a cipher of length 16, octet 17 is a repeat 1949 of octet 15 and octet 18 is a repeat of octet 16. As a pedantic 1950 clarification, in both these examples, we consider the first octet 1951 to be numbered 1. 1953 After encrypting the first block-size-plus-two octets, the CFB state 1954 is resynchronized. The last block-size octets of ciphertext are 1955 passed through the cipher and the block boundary is reset. 1957 The repetition of 16 bits in the random data prefixed to the message 1958 allows the receiver to immediately check whether the session key is 1959 incorrect. 1961 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 1963 An experimental version of PGP used this packet as the Literal 1964 packet, but no released version of PGP generated Literal packets 1965 with this tag. With PGP 5.x, this packet has been re-assigned and is 1966 reserved for use as the Marker packet. 1968 The body of this packet consists of: 1970 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 1972 Such a packet MUST be ignored when received. It may be placed at 1973 the beginning of a message that uses features not available in PGP 1974 2.6.x in order to cause that version to report that newer software 1975 is necessary to process the message. 1977 5.9. Literal Data Packet (Tag 11) 1979 A Literal Data packet contains the body of a message; data that is 1980 not to be further interpreted. 1982 The body of this packet consists of: 1984 - A one-octet field that describes how the data is formatted. 1986 If it is a 'b' (0x62), then the literal packet contains binary data. 1987 If it is a 't' (0x74), then it contains text data, and thus may need 1988 line ends converted to local form, or other text-mode changes. RFC 1989 1991 also defined a value of 'l' as a 'local' mode for machine-local 1990 conversions. This use is now deprecated. 1992 - File name as a string (one-octet length, followed by file name), 1993 if the encrypted data should be saved as a file. 1995 If the special name "_CONSOLE" is used, the message is considered to 1996 be "for your eyes only". This advises that the message data is 1997 unusually sensitive, and the receiving program should process it 1998 more carefully, perhaps avoiding storing the received data to disk, 1999 for example. 2001 - A four-octet number that indicates the modification date of the 2002 file, or the creation time of the packet, or a zero that 2003 indicates the present time. 2005 - The remainder of the packet is literal data. 2007 Text data is stored with text endings (i.e. network-normal 2008 line endings). These should be converted to native line endings by 2009 the receiving software. 2011 5.10. Trust Packet (Tag 12) 2013 The Trust packet is used only within keyrings and is not normally 2014 exported. Trust packets contain data that record the user's 2015 specifications of which key holders are trustworthy introducers, 2016 along with other information that implementing software uses for 2017 trust information. 2019 Trust packets SHOULD NOT be emitted to output streams that are 2020 transferred to other users, and they SHOULD be ignored on any input 2021 other than local keyring files. 2023 5.11. User ID Packet (Tag 13) 2025 A User ID packet consists of data that is intended to represent the 2026 name and email address of the key holder. By convention, it 2027 includes an RFC822 mail name, but there are no restrictions on its 2028 content. The packet length in the header specifies the length of 2029 the user id. If it is text, it is encoded in UTF-8. 2031 5.12. Sym. Encrypted Integrity Protected Data Packet (Tag 15) 2033 The Symmetrically Encrypted Integrity Protected Data Packet is a 2034 variant of the Symmetrically Encrypted Data Packet. It is a new 2035 feature created for OpenPGP that addresses the problem of detecting 2036 a modification to encrypted data. It is used in combination with a 2037 Modification Detection Code Packet. 2039 There is a corresponding feature in the features signature subpacket 2040 that denotes that an implementation can properly use this packet 2041 type. An implementation SHOULD NOT use this packet when encrypting 2042 to a recipient that does not state it can use this packet, and 2043 SHOULD prefer this to older Symmetrically Encrypted Data Packet when 2044 possible. 2046 This packet contains data encrypted with a symmetric-key algorithm 2047 and protected against modification by the SHA-1 hash algorithm. When 2048 it has been decrypted, it will typically contain other packets 2049 (often literal data packets or compressed data packets). The last 2050 decrypted packet in this packet's payload MUST be a Modification 2051 Detection Code packet. 2053 The body of this packet consists of: 2055 - A one-octet version number. The only currently defined value is 2056 1. 2058 - Encrypted data, the output of the selected symmetric-key cipher 2059 operating in Cipher Feedback mode with shift amount equal to the 2060 block size of the cipher (CFB-n where n is the block size). 2062 The symmetric cipher used MUST be specified in a Public-Key or 2063 Symmetric-Key Encrypted Session Key packet that precedes the 2064 Symmetrically Encrypted Data Packet. In either case, the cipher 2065 algorithm octet is prefixed to the session key before it is 2066 encrypted. 2068 The data is encrypted in CFB mode, with a CFB shift size equal to 2069 the cipher's block size. The Initial Vector (IV) is specified as 2070 all zeros. Instead of using an IV, OpenPGP prefixes an octet string 2071 to the data before it is encrypted. The length of the octet string 2072 equals the block size of the cipher in octets, plus two. The first 2073 octets in the group, of length equal to the block size of the 2074 cipher, are random; the last two octets are each copies of their 2nd 2075 preceding octet. For example, with a cipher whose block size is 128 2076 bits or 16 octets, the prefix data will contain 16 random octets, 2077 then two more octets, which are copies of the 15th and 16th octets, 2078 respectivelly. Unlike the Symmetrically Encrypted Data Packet, no 2079 special CFB resynchronization is done after encrypting this prefix 2080 data. 2082 The repetition of 16 bits in the random data prefixed to the message 2083 allows the receiver to immediately check whether the session key is 2084 incorrect. 2086 The plaintext of the data to be encrypted is passed through the 2087 SHA-1 hash function, and the result of the hash is appended to the 2088 plaintext in a Modification Detection Code packet. Specifically, 2089 the input to the hash function does not include the prefix data 2090 described above; it includes all of the plaintext, and then also 2091 includes two octets of values 0xD0, 0x14. These represent the 2092 encoding of a Modification Detection Code packet tag and length 2093 field of 20 octets. 2095 The resulting hash value is stored in a Modification Detection Code 2096 packet which MUST use the two octet encoding just given to represent 2097 its tag and length field. The body of the MDC packet is the 20 2098 octet output of the SHA-1 hash. 2100 The Modification Detection Code packet is appended to the plaintext 2101 and encrypted along with the plaintext using the same CFB context. 2103 During decryption, the plaintext data should be hashed with SHA-1, 2104 not including the prefix data but including the packet tag and 2105 length field of the Modification Detection Code packet. The body of 2106 the MDC packet, upon decryption, is compared with the result of the 2107 SHA-1 hash. Any difference in hash values is an indication that the 2108 message has been modified and SHOULD be reported to the user. 2109 Likewise, the absence of an MDC packet, or an MDC packet in any 2110 position other than the end of the plaintext, also represent message 2111 modifications and SHOULD also be reported. 2113 Note: future designs of new versions of this packet should consider 2114 rollback attacks since it will be possible for an attacker to change 2115 the version back to 1. 2117 5.13. Modification Detection Code Packet (Tag 16) 2119 The Modification Detection Code packet contains a SHA-1 hash of 2120 plaintext data which is used to detect message modification. It is 2121 only used with a Symmetrically Encrypted Integrity Protected Data 2122 packet. The Modification Detection Code packet MUST be the last 2123 packet in the plaintext data which is encrypted in the Symmetrically 2124 Encrypted Integrity Protected Data packet, and MUST appear in no 2125 other place. 2127 A Modification Detection Code packet MUST have a length of 20 2128 octets. 2130 The body of this packet consists of: 2132 - A 20-octet SHA-1 hash of the preceding plaintext data of the 2133 Symmetrically Encrypted Integrity Protected Data packet, not 2134 including prefix data but including the tag and length byte of 2135 the Modification Detection Code packet. 2137 Note that the Modification Detection Code packet MUST always use a 2138 new-format encoding of the packet tag, and a one-octet encoding of 2139 the packet length. The reason for this is that the hashing rules for 2140 modification detection include a one-octet tag and one-octet length 2141 in the data hash. While this is a bit restrictive, it reduces 2142 complexity. 2144 6. Radix-64 Conversions 2146 As stated in the introduction, OpenPGP's underlying native 2147 representation for objects is a stream of arbitrary octets, and some 2148 systems desire these objects to be immune to damage caused by 2149 character set translation, data conversions, etc. 2151 In principle, any printable encoding scheme that met the 2152 requirements of the unsafe channel would suffice, since it would not 2153 change the underlying binary bit streams of the native OpenPGP data 2154 structures. The OpenPGP standard specifies one such printable 2155 encoding scheme to ensure interoperability. 2157 OpenPGP's Radix-64 encoding is composed of two parts: a base64 2158 encoding of the binary data, and a checksum. The base64 encoding is 2159 identical to the MIME base64 content-transfer-encoding [RFC 2045]. 2160 An OpenPGP implementation MAY use ASCII Armor to protect the raw 2161 binary data. 2163 The checksum is a 24-bit CRC converted to four characters of 2164 radix-64 encoding by the same MIME base64 transformation, preceded 2165 by an equals sign (=). The CRC is computed by using the generator 2166 0x864CFB and an initialization of 0xB704CE. The accumulation is 2167 done on the data before it is converted to radix-64, rather than on 2168 the converted data. A sample implementation of this algorithm is in 2169 the next section. 2171 The checksum with its leading equal sign MAY appear on the first 2172 line after the Base64 encoded data. 2174 Rationale for CRC-24: The size of 24 bits fits evenly into printable 2175 base64. The nonzero initialization can detect more errors than a 2176 zero initialization. 2178 6.1. An Implementation of the CRC-24 in "C" 2180 #define CRC24_INIT 0xb704ceL 2181 #define CRC24_POLY 0x1864cfbL 2183 typedef long crc24; 2184 crc24 crc_octets(unsigned char *octets, size_t len) 2185 { 2186 crc24 crc = CRC24_INIT; 2187 int i; 2189 while (len--) { 2190 crc ^= (*octets++) << 16; 2191 for (i = 0; i < 8; i++) { 2192 crc <<= 1; 2193 if (crc & 0x1000000) 2194 crc ^= CRC24_POLY; 2195 } 2196 } 2197 return crc & 0xffffffL; 2198 } 2200 6.2. Forming ASCII Armor 2202 When OpenPGP encodes data into ASCII Armor, it puts specific headers 2203 around the data, so OpenPGP can reconstruct the data later. OpenPGP 2204 informs the user what kind of data is encoded in the ASCII armor 2205 through the use of the headers. 2207 Concatenating the following data creates ASCII Armor: 2209 - An Armor Header Line, appropriate for the type of data 2211 - Armor Headers 2213 - A blank (zero-length, or containing only whitespace) line 2215 - The ASCII-Armored data 2217 - An Armor Checksum 2219 - The Armor Tail, which depends on the Armor Header Line. 2221 An Armor Header Line consists of the appropriate header line text 2222 surrounded by five (5) dashes ('-', 0x2D) on either side of the 2223 header line text. The header line text is chosen based upon the 2224 type of data that is being encoded in Armor, and how it is being 2225 encoded. Header line texts include the following strings: 2227 BEGIN PGP MESSAGE 2228 Used for signed, encrypted, or compressed files. 2230 BEGIN PGP PUBLIC KEY BLOCK 2231 Used for armoring public keys 2233 BEGIN PGP PRIVATE KEY BLOCK 2234 Used for armoring private keys 2236 BEGIN PGP MESSAGE, PART X/Y 2237 Used for multi-part messages, where the armor is split amongst Y 2238 parts, and this is the Xth part out of Y. 2240 BEGIN PGP MESSAGE, PART X 2241 Used for multi-part messages, where this is the Xth part of an 2242 unspecified number of parts. Requires the MESSAGE-ID Armor 2243 Header to be used. 2245 BEGIN PGP SIGNATURE 2246 Used for detached signatures, OpenPGP/MIME signatures, and 2247 signatures following clearsigned messages. Note that PGP 2.x 2248 uses BEGIN PGP MESSAGE for detached signatures. 2250 Note that all these Armor Header Lines are to consist of a complete 2251 line. That is to say, there is always a line ending preceding the 2252 starting five dashes, and following the ending five dashes. The 2253 header lines, therefore, MUST start at the beginning of a line, and 2254 MUST NOT have text following them on the same line. These line 2255 endings are considered a part of the Armor Header Line for the 2256 purposes of determining the content they delimit. This is 2257 particularly important when computing a cleartext signature (see 2258 below). 2260 The Armor Headers are pairs of strings that can give the user or the 2261 receiving OpenPGP implementation some information about how to 2262 decode or use the message. The Armor Headers are a part of the 2263 armor, not a part of the message, and hence are not protected by any 2264 signatures applied to the message. 2266 The format of an Armor Header is that of a key-value pair. A colon 2267 (':' 0x38) and a single space (0x20) separate the key and value. 2268 OpenPGP should consider improperly formatted Armor Headers to be 2269 corruption of the ASCII Armor. Unknown keys should be reported to 2270 the user, but OpenPGP should continue to process the message. 2272 Currently defined Armor Header Keys are: 2274 - "Version", that states the OpenPGP Version used to encode the 2275 message. 2277 - "Comment", a user-defined comment. 2279 - "MessageID", a 32-character string of printable characters. The 2280 string must be the same for all parts of a multi-part message 2281 that uses the "PART X" Armor Header. MessageID strings should 2282 be unique enough that the recipient of the mail can associate 2283 all the parts of a message with each other. A good checksum or 2284 cryptographic hash function is sufficient. 2286 The MessageID SHOULD NOT appear unless it is in a multi-part 2287 message. If it appears at all, it MUST be computed from the 2288 finished (encrypted, signed, etc.) message in a deterministic 2289 fashion, rather than contain a purely random value. This is to 2290 allow the legitimate recipient to determine that the MessageID 2291 cannot serve as a covert means of leaking cryptographic key 2292 information. 2294 - "Hash", a comma-separated list of hash algorithms used in this 2295 message. This is used only in clear-signed messages. 2297 - "Charset", a description of the character set that the plaintext 2298 is in. Please note that OpenPGP defines text to be in UTF-8 by 2299 default. An implementation will get best results by translating 2300 into and out of UTF-8. However, there are many instances where 2301 this is easier said than done. Also, there are communities of 2302 users who have no need for UTF-8 because they are all happy with 2303 a character set like ISO Latin-5 or a Japanese character set. In 2304 such instances, an implementation MAY override the UTF-8 default 2305 by using this header key. An implementation MAY implement this 2306 key and any translations it cares to; an implementation MAY 2307 ignore it and assume all text is UTF-8. 2309 The Armor Tail Line is composed in the same manner as the Armor 2310 Header Line, except the string "BEGIN" is replaced by the string 2311 "END." 2313 6.3. Encoding Binary in Radix-64 2315 The encoding process represents 24-bit groups of input bits as 2316 output strings of 4 encoded characters. Proceeding from left to 2317 right, a 24-bit input group is formed by concatenating three 8-bit 2318 input groups. These 24 bits are then treated as four concatenated 2319 6-bit groups, each of which is translated into a single digit in the 2320 Radix-64 alphabet. When encoding a bit stream with the Radix-64 2321 encoding, the bit stream must be presumed to be ordered with the 2322 most-significant-bit first. That is, the first bit in the stream 2323 will be the high-order bit in the first 8-bit octet, and the eighth 2324 bit will be the low-order bit in the first 8-bit octet, and so on. 2326 +--first octet--+-second octet--+--third octet--+ 2327 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 2328 +-----------+---+-------+-------+---+-----------+ 2329 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 2330 +--1.index--+--2.index--+--3.index--+--4.index--+ 2332 Each 6-bit group is used as an index into an array of 64 printable 2333 characters from the table below. The character referenced by the 2334 index is placed in the output string. 2336 Value Encoding Value Encoding Value Encoding Value Encoding 2337 0 A 17 R 34 i 51 z 2338 1 B 18 S 35 j 52 0 2339 2 C 19 T 36 k 53 1 2340 3 D 20 U 37 l 54 2 2341 4 E 21 V 38 m 55 3 2342 5 F 22 W 39 n 56 4 2343 6 G 23 X 40 o 57 5 2344 7 H 24 Y 41 p 58 6 2345 8 I 25 Z 42 q 59 7 2346 9 J 26 a 43 r 60 8 2347 10 K 27 b 44 s 61 9 2348 11 L 28 c 45 t 62 + 2349 12 M 29 d 46 u 63 / 2350 13 N 30 e 47 v 2351 14 O 31 f 48 w (pad) = 2352 15 P 32 g 49 x 2353 16 Q 33 h 50 y 2355 The encoded output stream must be represented in lines of no more 2356 than 76 characters each. 2358 Special processing is performed if fewer than 24 bits are available 2359 at the end of the data being encoded. There are three possibilities: 2361 1. The last data group has 24 bits (3 octets). No special 2362 processing is needed. 2364 2. The last data group has 16 bits (2 octets). The first two 6-bit 2365 groups are processed as above. The third (incomplete) data group 2366 has two zero-value bits added to it, and is processed as above. 2367 A pad character (=) is added to the output. 2369 3. The last data group has 8 bits (1 octet). The first 6-bit group 2370 is processed as above. The second (incomplete) data group has 2371 four zero-value bits added to it, and is processed as above. Two 2372 pad characters (=) are added to the output. 2374 6.4. Decoding Radix-64 2376 Any characters outside of the base64 alphabet are ignored in 2377 Radix-64 data. Decoding software must ignore all line breaks or 2378 other characters not found in the table above. 2380 In Radix-64 data, characters other than those in the table, line 2381 breaks, and other white space probably indicate a transmission 2382 error, about which a warning message or even a message rejection 2383 might be appropriate under some circumstances. 2385 Because it is used only for padding at the end of the data, the 2386 occurrence of any "=" characters may be taken as evidence that the 2387 end of the data has been reached (without truncation in transit). No 2388 such assurance is possible, however, when the number of octets 2389 transmitted was a multiple of three and no "=" characters are 2390 present. 2392 6.5. Examples of Radix-64 2394 Input data: 0x14fb9c03d97e 2395 Hex: 1 4 f b 9 c | 0 3 d 9 7 e 2396 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2397 11111110 2398 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 2399 111110 2400 Decimal: 5 15 46 28 0 61 37 62 2401 Output: F P u c A 9 l + 2403 Input data: 0x14fb9c03d9 2404 Hex: 1 4 f b 9 c | 0 3 d 9 2405 8-bit: 00010100 11111011 10011100 | 00000011 11011001 2406 pad with 00 2407 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 2408 Decimal: 5 15 46 28 0 61 36 2409 pad with = 2410 Output: F P u c A 9 k = 2412 Input data: 0x14fb9c03 2413 Hex: 1 4 f b 9 c | 0 3 2414 8-bit: 00010100 11111011 10011100 | 00000011 2415 pad with 0000 2417 6-bit: 000101 001111 101110 011100 | 000000 110000 2418 Decimal: 5 15 46 28 0 48 2419 pad with = = 2420 Output: F P u c A w = = 2422 6.6. Example of an ASCII Armored Message 2424 -----BEGIN PGP MESSAGE----- 2425 Version: OpenPrivacy 0.99 2427 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 2428 vBSFjNSiVHsuAA== 2429 =njUN 2430 -----END PGP MESSAGE----- 2432 Note that this example is indented by two spaces. 2434 7. Cleartext signature framework 2436 It is desirable to sign a textual octet stream without ASCII 2437 armoring the stream itself, so the signed text is still readable 2438 without special software. In order to bind a signature to such a 2439 cleartext, this framework is used. (Note that RFC 2015 defines 2440 another way to clear sign messages for environments that support 2441 MIME.) 2443 The cleartext signed message consists of: 2445 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 2446 single line, 2448 - One or more "Hash" Armor Headers, 2450 - Exactly one empty line not included into the message digest, 2452 - The dash-escaped cleartext that is included into the message 2453 digest, 2455 - The ASCII armored signature(s) including the '-----BEGIN PGP 2456 SIGNATURE-----' Armor Header and Armor Tail Lines. 2458 If the "Hash" armor header is given, the specified message digest 2459 algorithm is used for the signature. If there are no such headers, 2460 MD5 is used, an implementation MAY omit them for V2.x compatibility. 2461 If more than one message digest is used in the signature, the "Hash" 2462 armor header contains a comma-delimited list of used message 2463 digests. 2465 Current message digest names are described below with the algorithm 2466 IDs. 2468 7.1. Dash-Escaped Text 2470 The cleartext content of the message must also be dash-escaped. 2472 Dash escaped cleartext is the ordinary cleartext where every line 2473 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 2474 (0x2D) and space ' ' (0x20). This prevents the parser from 2475 recognizing armor headers of the cleartext itself. The message 2476 digest is computed using the cleartext itself, not the dash escaped 2477 form. 2479 As with binary signatures on text documents, a cleartext signature 2480 is calculated on the text using canonical line endings. 2481 The line ending (i.e. the ) before the '-----BEGIN PGP 2482 SIGNATURE-----' line that terminates the signed text is not 2483 considered part of the signed text. 2485 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of 2486 any line is ignored when the cleartext signature is calculated. 2488 8. Regular Expressions 2490 A regular expression is zero or more branches, separated by '|'. It 2491 matches anything that matches one of the branches. 2493 A branch is zero or more pieces, concatenated. It matches a match 2494 for the first, followed by a match for the second, etc. 2496 A piece is an atom possibly followed by '*', '+', or '?'. An atom 2497 followed by '*' matches a sequence of 0 or more matches of the atom. 2498 An atom followed by '+' matches a sequence of 1 or more matches of 2499 the atom. An atom followed by '?' matches a match of the atom, or 2500 the null string. 2502 An atom is a regular expression in parentheses (matching a match for 2503 the regular expression), a range (see below), '.' (matching any 2504 single character), '^' (matching the null string at the beginning of 2505 the input string), '$' (matching the null string at the end of the 2506 input string), a '\' followed by a single character (matching that 2507 character), or a single character with no other significance 2508 (matching that character). 2510 A range is a sequence of characters enclosed in '[]'. It normally 2511 matches any single character from the sequence. If the sequence 2512 begins with '^', it matches any single character not from the rest 2513 of the sequence. If two characters in the sequence are separated by 2514 '-', this is shorthand for the full list of ASCII characters between 2515 them (e.g. '[0-9]' matches any decimal digit). To include a literal 2516 ']' in the sequence, make it the first character (following a 2517 possible '^'). To include a literal '-', make it the first or last 2518 character. 2520 9. Constants 2522 This section describes the constants used in OpenPGP. 2524 Note that these tables are not exhaustive lists; an implementation 2525 MAY implement an algorithm not on these lists. 2527 See the section "Notes on Algorithms" below for more discussion of 2528 the algorithms. 2530 9.1. Public Key Algorithms 2532 ID Algorithm 2533 -- --------- 2534 1 - RSA (Encrypt or Sign) 2535 2 - RSA Encrypt-Only 2536 3 - RSA Sign-Only 2537 16 - Elgamal (Encrypt-Only), see [ELGAMAL] 2538 17 - DSA (Digital Signature Standard) [SCHNEIER] 2539 18 - Reserved for Elliptic Curve 2540 19 - Reserved for ECDSA 2541 20 - Elgamal (Encrypt or Sign) 2542 21 - Reserved for Diffie-Hellman (X9.42, 2543 as defined for IETF-S/MIME) 2544 100 to 110 - Private/Experimental algorithm. 2546 Implementations MUST implement DSA for signatures, and Elgamal for 2547 encryption. Implementations SHOULD implement RSA keys. 2548 Implementations MAY implement any other algorithm. 2550 9.2. Symmetric Key Algorithms 2552 ID Algorithm 2553 -- --------- 2554 0 - Plaintext or unencrypted data 2555 1 - IDEA [IDEA] 2556 2 - Triple-DES (DES-EDE, [SCHNEIER] - 2557 168 bit key derived from 192) 2558 3 - CAST5 (128 bit key, as per RFC2144) 2559 4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH] 2560 5 - SAFER-SK128 (13 rounds) [SAFER] 2561 6 - Reserved for DES/SK [AES] 2562 7 - AES with 128-bit key 2563 8 - AES with 192-bit key 2564 9 - AES with 256-bit key 2565 10 - Twofish with 256-bit key [TWOFISH] 2566 100 to 110 - Private/Experimental algorithm. 2568 Implementations MUST implement Triple-DES. Implementations SHOULD 2569 implement IDEA and CAST5.Implementations MAY implement any other 2570 algorithm. 2572 9.3. Compression Algorithms 2574 ID Algorithm 2575 -- --------- 2576 0 - Uncompressed 2577 1 - ZIP (RFC1951) 2578 2 - ZLIB (RFC1950) 2579 100 to 110 - Private/Experimental algorithm. 2581 Implementations MUST implement uncompressed data. Implementations 2582 SHOULD implement ZIP. Implementations MAY implement ZLIB. 2584 9.4. Hash Algorithms 2586 ID Algorithm Text Name 2587 -- --------- ---- ---- 2588 1 - MD5 "MD5" 2589 2 - SHA-1 "SHA1" 2590 3 - RIPE-MD/160 "RIPEMD160" 2591 4 - Reserved for double-width SHA (experimental) 2592 5 - MD2 "MD2" 2593 6 - Reserved for TIGER/192 "TIGER192" 2594 7 - Reserved for HAVAL (5 pass, 160-bit) "HAVAL-5-160" 2595 100 to 110 - Private/Experimental algorithm. 2597 Implementations MUST implement SHA-1. Implementations SHOULD 2598 implement MD5. 2600 10. Packet Composition 2602 OpenPGP packets are assembled into sequences in order to create 2603 messages and to transfer keys. Not all possible packet sequences 2604 are meaningful and correct. This describes the rules for how 2605 packets should be placed into sequences. 2607 10.1. Transferable Public Keys 2609 OpenPGP users may transfer public keys. The essential elements of a 2610 transferable public key are: 2612 - One Public Key packet 2614 - Zero or more revocation signatures 2616 - One or more User ID packets 2618 - After each User ID packet, zero or more signature packets 2619 (certifications) 2621 - Zero or more Subkey packets 2622 - After each Subkey packet, one signature packet, optionally a 2623 revocation. 2625 The Public Key packet occurs first. Each of the following User ID 2626 packets provides the identity of the owner of this public key. If 2627 there are multiple User ID packets, this corresponds to multiple 2628 means of identifying the same unique individual user; for example, a 2629 user may have more than one email address, and construct a User ID 2630 for each one. 2632 Immediately following each User ID packet, there are zero or more 2633 signature packets. Each signature packet is calculated on the 2634 immediately preceding User ID packet and the initial Public Key 2635 packet. The signature serves to certify the corresponding public key 2636 and user ID. In effect, the signer is testifying to his or her 2637 belief that this public key belongs to the user identified by this 2638 user ID. 2640 After the User ID packets there may be one or more Subkey packets. 2641 In general, subkeys are provided in cases where the top-level public 2642 key is a signature-only key. However, any V4 key may have subkeys, 2643 and the subkeys may be encryption-only keys, signature-only keys, or 2644 general-purpose keys. 2646 Each Subkey packet must be followed by one Signature packet, which 2647 should be a subkey binding signature issued by the top level key. 2649 Subkey and Key packets may each be followed by a revocation 2650 Signature packet to indicate that the key is revoked. Revocation 2651 signatures are only accepted if they are issued by the key itself, 2652 or by a key that is authorized to issue revocations via a revocation 2653 key subpacket in a self-signature by the top level key. 2655 Transferable public key packet sequences may be concatenated to 2656 allow transferring multiple public keys in one operation. 2658 10.2. OpenPGP Messages 2660 An OpenPGP message is a packet or sequence of packets that 2661 corresponds to the following grammatical rules (comma represents 2662 sequential composition, and vertical bar separates alternatives): 2664 OpenPGP Message :- Encrypted Message | Signed Message | 2665 Compressed Message | Literal Message. 2667 Compressed Message :- Compressed Data Packet. 2669 Literal Message :- Literal Data Packet. 2671 ESK :- Public Key Encrypted Session Key Packet | 2672 Symmetric-Key Encrypted Session Key Packet. 2674 ESK Sequence :- ESK | ESK Sequence, ESK. 2676 Encrypted Data :- Symmetrically Encrypted Data Packet | 2677 Symmetrically Encrypted Integrity Protected Data Packet 2679 Encrypted Message :- Encrypted Data | ESK Sequence, Encrypted Data. 2681 One-Pass Signed Message :- One-Pass Signature Packet, 2682 OpenPGP Message, Corresponding Signature Packet. 2684 Signed Message :- Signature Packet, OpenPGP Message | 2685 One-Pass Signed Message. 2687 In addition, decrypting a Symmetrically Encrypted Data Packet or a 2688 Symmetrically Encrypted Integrity Protected Data Packet as well as 2690 decompressing a Compressed Data packet must yield a valid OpenPGP 2691 Message. 2693 10.3. Detached Signatures 2695 Some OpenPGP applications use so-called "detached signatures." For 2696 example, a program bundle may contain a file, and with it a second 2697 file that is a detached signature of the first file. These detached 2698 signatures are simply a signature packet stored separately from the 2699 data that they are a signature of. 2701 11. Enhanced Key Formats 2703 11.1. Key Structures 2705 The format of an OpenPGP V3 key is as follows. Entries in square 2706 brackets are optional and ellipses indicate repetition. 2708 RSA Public Key 2709 [Revocation Self Signature] 2710 User ID [Signature ...] 2711 [User ID [Signature ...] ...] 2713 Each signature certifies the RSA public key and the preceding user 2714 ID. The RSA public key can have many user IDs and each user ID can 2715 have many signatures. 2717 The format of an OpenPGP V4 key that uses two public keys is similar 2718 except that the other keys are added to the end as 'subkeys' of the 2719 primary key. 2721 Primary-Key 2722 [Revocation Self Signature] 2723 [Direct Key Self Signature...] 2724 User ID [Signature ...] 2725 [User ID [Signature ...] ...] 2727 [[Subkey [Binding-Signature-Revocation] 2728 Primary-Key-Binding-Signature] ...] 2730 A subkey always has a single signature after it that is issued using 2731 the primary key to tie the two keys together. This binding 2732 signature may be in either V3 or V4 format, but V4 is preferred, of 2733 course. 2735 In the above diagram, if the binding signature of a subkey has been 2736 revoked, the revoked binding signature may be removed, leaving only 2737 one signature. 2739 In a key that has a main key and subkeys, the primary key MUST be a 2740 key capable of signing. The subkeys may be keys of any other type. 2741 There may be other constructions of V4 keys, too. For example, there 2742 may be a single-key RSA key in V4 format, a DSA primary key with an 2743 RSA encryption key, or RSA primary key with an Elgamal subkey, etc. 2745 It is also possible to have a signature-only subkey. This permits a 2746 primary key that collects certifications (key signatures) but is 2747 used only used for certifying subkeys that are used for encryption 2748 and signatures. 2750 11.2. Key IDs and Fingerprints 2752 For a V3 key, the eight-octet key ID consists of the low 64 bits of 2753 the public modulus of the RSA key. 2755 The fingerprint of a V3 key is formed by hashing the body (but not 2756 the two-octet length) of the MPIs that form the key material (public 2757 modulus n, followed by exponent e) with MD5. 2759 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet 2760 Tag, followed by the two-octet packet length, followed by the entire 2761 Public Key packet starting with the version field. The key ID is 2762 the low order 64 bits of the fingerprint. Here are the fields of 2763 the hash material, with the example of a DSA key: 2765 a.1) 0x99 (1 octet) 2767 a.2) high order length octet of (b)-(f) (1 octet) 2769 a.3) low order length octet of (b)-(f) (1 octet) 2771 b) version number = 4 (1 octet); 2773 c) time stamp of key creation (4 octets); 2775 d) algorithm (1 octet): 17 = DSA (example); 2776 e) Algorithm specific fields. 2778 Algorithm Specific Fields for DSA keys (example): 2780 e.1) MPI of DSA prime p; 2782 e.2) MPI of DSA group order q (q is a prime divisor of p-1); 2784 e.3) MPI of DSA group generator g; 2786 e.4) MPI of DSA public key value y (= g**x mod p where x is secret). 2788 Note that it is possible for there to be collisions of key IDs -- 2789 two different keys with the same key ID. Note that there is a much 2790 smaller, but still non-zero probability that two different keys have 2791 the same fingerprint. 2793 Also note that if V3 and V4 format keys share the same RSA key 2794 material, they will have different key ids as well as different 2795 fingerprints. 2797 12. Notes on Algorithms 2799 12.1. Symmetric Algorithm Preferences 2801 The symmetric algorithm preference is an ordered list of algorithms 2802 that the keyholder accepts. Since it is found on a self-signature, 2803 it is possible that a keyholder may have different preferences. For 2804 example, Alice may have TripleDES only specified for 2805 "alice@work.com" but CAST5, Blowfish, and TripleDES specified for 2806 "alice@home.org". Note that it is also possible for preferences to 2807 be in a subkey's binding signature. 2809 Since TripleDES is the MUST-implement algorithm, if it is not 2810 explicitly in the list, it is tacitly at the end. However, it is 2811 good form to place it there explicitly. Note also that if an 2812 implementation does not implement the preference, then it is 2813 implicitly a TripleDES-only implementation. 2815 An implementation MUST not use a symmetric algorithm that is not in 2816 the recipient's preference list. When encrypting to more than one 2817 recipient, the implementation finds a suitable algorithm by taking 2818 the intersection of the preferences of the recipients. Note that the 2819 MUST-implement algorithm, TripleDES, ensures that the intersection 2820 is not null. The implementation may use any mechanism to pick an 2821 algorithm in the intersection. 2823 If an implementation can decrypt a message that a keyholder doesn't 2824 have in their preferences, the implementation SHOULD decrypt the 2825 message anyway, but MUST warn the keyholder than protocol has been 2826 violated. (For example, suppose that Alice, above, has software that 2827 implements all algorithms in this specification. Nonetheless, she 2828 prefers subsets for work or home. If she is sent a message encrypted 2829 with IDEA, which is not in her preferences, the software warns her 2830 that someone sent her an IDEA-encrypted message, but it would 2831 ideally decrypt it anyway.) 2833 An implementation that is striving for backward compatibility MAY 2834 consider a V3 key with a V3 self-signature to be an implicit 2835 preference for IDEA, and no ability to do TripleDES. This is 2836 technically non-compliant, but an implementation MAY violate the 2837 above rule in this case only and use IDEA to encrypt the message, 2838 provided that the message creator is warned. Ideally, though, the 2839 implementation would follow the rule by actually generating two 2840 messages, because it is possible that the OpenPGP user's 2841 implementation does not have IDEA, and thus could not read the 2842 message. Consequently, an implementation MAY, but SHOULD NOT use 2843 IDEA in an algorithm conflict with a V3 key. 2845 12.2. Other Algorithm Preferences 2847 Other algorithm preferences work similarly to the symmetric 2848 algorithm preference, in that they specify which algorithms the 2849 keyholder accepts. There are two interesting cases that other 2850 comments need to be made about, though, the compression preferences 2851 and the hash preferences. 2853 12.2.1. Compression Preferences 2855 Compression has been an integral part of PGP since its first days. 2856 OpenPGP and all previous versions of PGP have offered compression. 2857 And in this specification, the default is for messages to be 2858 compressed, although an implementation is not required to do so. 2859 Consequently, the compression preference gives a way for a keyholder 2860 to request that messages not be compressed, presumably because they 2861 are using a minimal implementation that does not include 2862 compression. Additionally, this gives a keyholder a way to state 2863 that it can support alternate algorithms. 2865 Like the algorithm preferences, an implementation MUST NOT use an 2866 algorithm that is not in the preference vector. If the preferences 2867 are not present, then they are assumed to be [ZIP(1), 2868 UNCOMPRESSED(0)]. 2870 Additionally, an implementation MUST implement this preference to 2871 the degree of recognizing when to send an uncompressed message. A 2872 robust implementation would satisfy this requirement by looking at 2873 the recipient's preference and acting accordingly. A minimal 2874 implementation can satisfy this requirement by never generating a 2875 compressed message, since all implementations can handle messages 2876 that have not been compressed. 2878 12.2.2. Hash Algorithm Preferences 2880 Typically, the choice of a hash algorithm is something the signer 2881 does, rather than the verifier, because a signer rarely knows who is 2882 going to be verifying the signature. This preference, though, allows 2883 a protocol based upon digital signatures ease in negotiation. 2885 Thus, if Alice is authenticating herself to Bob with a signature, it 2886 makes sense for her to use a hash algorithm that Bob's software 2887 uses. This preference allows Bob to state in his key which 2888 algorithms Alice may use. 2890 12.3. Plaintext 2892 Algorithm 0, "plaintext," may only be used to denote secret keys 2893 that are stored in the clear. Implementations MUST NOT use plaintext 2894 in Symmetrically Encrypted Data Packets; they must use Literal Data 2895 Packets to encode unencrypted or literal data. 2897 12.4. RSA 2899 There are algorithm types for RSA-signature-only, and 2900 RSA-encrypt-only keys. These types are deprecated. The "key flags" 2901 subpacket in a signature is a much better way to express the same 2902 idea, and generalizes it to all algorithms. An implementation SHOULD 2903 NOT create such a key, but MAY interpret it. 2905 An implementation SHOULD NOT implement RSA keys of size less than 2906 768 bits. 2908 It is permissible for an implementation to support RSA merely for 2909 backward compatibility; for example, such an implementation would 2910 support V3 keys with IDEA symmetric cryptography. Note that this is 2911 an exception to the other MUST-implement rules. An implementation 2912 that supports RSA in V4 keys MUST implement the MUST-implement 2913 features. 2915 12.5. Elgamal 2917 If an Elgamal key is to be used for both signing and encryption, 2918 extra care must be taken in creating the key. 2920 An ElGamal key consists of a generator g, a prime modulus p, a 2921 secret exponent x, and a public value y = g^x mod p. 2923 The generator and prime must be chosen so that solving the discrete 2924 log problem is intractable. The group g should generate the 2925 multiplicative group mod p-1 or a large subgroup of it, and the 2926 order of g should have at least one large prime factor. A good 2927 choice is to use a "strong" Sophie-Germain prime in choosing p, so 2928 that both p and (p-1)/2 are primes. In fact, this choice is so good 2929 that implementers SHOULD do it, as it avoids a small subgroup 2930 attack. 2932 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that 2933 if the generator g has only small prime factors, and if g divides 2934 the order of the group it generates, then signatures can be forged. 2935 In particular, choosing g=2 is a bad choice if the group order may 2936 be even. On the other hand, a generator of 2 is a fine choice for an 2937 encryption-only key, as this will make the encryption faster. 2939 While verifying Elgamal signatures, note that it is important to 2940 test that r and s are less than p. If this test is not done then 2941 signatures can be trivially forged by using large r values of 2942 approximately twice the length of p. This attack is also discussed 2943 in the Bleichenbacher paper. 2945 Details on safe use of Elgamal signatures may be found in [MENEZES], 2946 which discusses all the weaknesses described above. 2948 If an implementation allows Elgamal signatures, then it MUST use the 2949 algorithm identifier 20 for an Elgamal public key that can sign. 2951 An implementation SHOULD NOT implement Elgamal keys of size less 2952 than 768 bits. For long-term security, Elgamal keys should be 1024 2953 bits or longer. 2955 12.6. DSA 2957 An implementation SHOULD NOT implement DSA keys of size less than 2958 768 bits. Note that present DSA is limited to a maximum of 1024 bit 2959 keys, which are recommended for long-term use. Also, DSA keys MUST 2960 be an even multiple of 64 bits long. 2962 12.7. Reserved Algorithm Numbers 2964 A number of algorithm IDs have been reserved for algorithms that 2965 would be useful to use in an OpenPGP implementation, yet there are 2966 issues that prevent an implementer from actually implementing the 2967 algorithm. These are marked in the Public Algorithms section as 2968 "(reserved for)". 2970 The reserved public key algorithms, Elliptic Curve (18), ECDSA (19), 2971 and X9.42 (21) do not have the necessary parameters, parameter 2972 order, or semantics defined. 2974 The reserved symmetric key algorithm, DES/SK (6), does not have 2975 semantics defined. 2977 The reserved hash algorithms, TIGER192 (6), and HAVAL-5-160 (7), do 2978 not have OIDs. The reserved algorithm number 4, reserved for a 2979 double-width variant of SHA1, is not presently defined. 2981 12.8. OpenPGP CFB mode 2983 OpenPGP does symmetric encryption using a variant of Cipher Feedback 2984 Mode (CFB mode). This section describes the procedure it uses in 2985 detail. This mode is what is used for Symmetrically Encrypted Data 2986 Packets; the mechanism used for encrypting secret key material is 2987 similar, but described in those sections above. 2989 In the description below, the value BS is the block size in octets 2990 of the cipher. Most ciphers have a block size of 8 octets. The AES 2991 and Twofish have a blocksize of 16 octets. Also note that the 2992 description below assumes that the IV and CFB arrays start with an 2993 index of 1 (unlike the C language, which assumes arrays start with a 2994 zero index). 2996 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, 2997 and prefixes the plaintext with BS+2 octets of random data, such 2998 that octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB 2999 "resync" after encrypting those BS+2 octets. 3001 Thus, for an algorithm that has a block size of 8 octets (64 bits), 3002 the IV is 10 octets long and octets 7 and 8 of the IV are the same 3003 as octets 9 and 10. For an algorithm with a blocksize of 16 octets 3004 (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate 3005 octets 15 and 16. Those extra two octets are an easy check for a 3006 correct key. 3008 Step by step, here is the procedure: 3010 1. The feedback register (FR) is set to the IV, which is all zeros. 3012 2. FR is encrypted to produce FRE (FR Encrypted). This is the 3013 encryption of an all-zero value. 3015 3. FRE is xored with the first BS octets of random data prefixed to 3016 the plaintext to produce C[1] through C[BS], the first BS octets 3017 of ciphertext. 3019 4. FR is loaded with C[1] through C[BS]. 3021 5. FR is encrypted to produce FRE, the encryption of the first BS 3022 octets of ciphertext. 3024 6. The left two octets of FRE get xored with the next two octets of 3025 data that were prefixed to the plaintext. This produces C[BS+1] 3026 and C[BS+2], the next two octets of ciphertext. 3028 7. (The resync step) FR is loaded with C[3] through C[BS+2]. 3030 8. FR is encrypted to produce FRE. 3032 9. FRE is xored with the first BS octets of the given plaintext, 3033 now that we have finished encrypting the BS+2 octets of prefixed 3034 data. This produces C[BS+3] through C[BS+(BS+2)], the next BS 3035 octets of ciphertext. 3037 10. FR is loaded with C[BS+3] to C[BS + (BS+2)] (which is C11-C18 3038 for an 8-octet block). 3040 11. FR is encrypted to produce FRE. 3042 12. FRE is xored with the next BS octets of plaintext, to produce 3043 the next BS octets of ciphertext. These are loaded into FR and 3044 the process is repeated until the plaintext is used up. 3046 13. Security Considerations 3048 * As with any technology involving cryptography, you should check 3049 the current literature to determine if any algorithms used here 3050 have been found to be vulnerable to attack. 3052 * This specification uses Public Key Cryptography technologies. 3053 Possession of the private key portion of a public-private key 3054 pair is assumed to be controlled by the proper party or parties. 3056 * Certain operations in this specification involve the use of 3057 random numbers. An appropriate entropy source should be used to 3058 generate these numbers. See RFC 1750. 3060 * The MD5 hash algorithm has been found to have weaknesses 3061 (pseudo-collisions in the compress function) that make some 3062 people deprecate its use. They consider the SHA-1 algorithm 3063 better. 3065 * Many security protocol designers think that it is a bad idea to 3066 use a single key for both privacy (encryption) and integrity 3067 (signatures). In fact, this was one of the motivating forces 3068 behind the V4 key format with separate signature and encryption 3069 keys. If you as an implementer promote dual-use keys, you should 3070 at least be aware of this controversy. 3072 * The DSA algorithm will work with any 160-bit hash, but it is 3073 sensitive to the quality of the hash algorithm, if the hash 3074 algorithm is broken, it can leak the secret key. The Digital 3075 Signature Standard (DSS) specifies that DSA be used with SHA-1. 3076 RIPEMD-160 is considered by many cryptographers to be as strong. 3077 An implementation should take care which hash algorithms are 3078 used with DSA, as a weak hash can not only allow a signature to 3079 be forged, but could leak the secret key. These same 3080 considerations about the quality of the hash algorithm apply to 3081 Elgamal signatures. 3083 * There is a somewhat-related potential security problem in 3084 signatures. If an attacker can find a message that hashes to the 3085 same hash with a different algorithm, a bogus signature 3086 structure can be constructed that evaluates correctly. 3088 For example, suppose Alice DSA signs message M using hash 3089 algorithm H. Suppose that Mallet finds a message M' that has the 3090 same hash value as M with H'. Mallet can then construct a 3091 signature block that verifies as Alice's signature of M' with 3092 H'. However, this would also constitute a weakness in either H 3093 or H' or both. Should this ever occur, a revision will have to 3094 be made to this document to revise the allowed hash algorithms. 3096 * If you are building an authentication system, the recipient may 3097 specify a preferred signing algorithm. However, the signer would 3098 be foolish to use a weak algorithm simply because the recipient 3099 requests it. 3101 * Some of the encryption algorithms mentioned in this document 3102 have been analyzed less than others. For example, although 3103 CAST5 is presently considered strong, it has been analyzed less 3104 than Triple-DES. Other algorithms may have other controversies 3105 surrounding them. 3107 * Some technologies mentioned here may be subject to government 3108 control in some countries. 3110 14. Implementation Nits 3112 This section is a collection of comments to help an implementer, 3113 particularly with an eye to backward compatibility. Previous 3114 implementations of PGP are not OpenPGP-compliant. Often the 3115 differences are small, but small differences are frequently more 3116 vexing than large differences. Thus, this is a non-comprehensive 3117 list of potential problems and gotchas for a developer who is trying 3118 to be backward-compatible. 3120 * PGP 5.x does not accept V4 signatures for anything other than 3121 key material. 3123 * PGP 5.x does not recognize the "five-octet" lengths in 3124 new-format headers or in signature subpacket lengths. 3126 * PGP 5.0 rejects an encrypted session key if the keylength 3127 differs from the S2K symmetric algorithm. This is a bug in its 3128 validation function. 3130 * PGP 5.0 does not handle multiple one-pass signature headers and 3131 trailers. Signing one will compress the one-pass signed literal 3132 and prefix a V3 signature instead of doing a nested one-pass 3133 signature. 3135 * When exporting a private key, PGP 2.x generates the header 3136 "BEGIN PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY 3137 BLOCK". All previous versions ignore the implied data type, and 3138 look directly at the packet data type. 3140 * In a clear-signed signature, PGP 5.0 will figure out the correct 3141 hash algorithm if there is no "Hash:" header, but it will reject 3142 a mismatch between the header and the actual algorithm used. The 3143 "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x 3144 rejects the "Hash:" header and assumes MD5. There are a number 3145 of enhanced variants of PGP 2.6.x that have been modified for 3146 SHA-1 signatures. 3148 * PGP 5.0 can read an RSA key in V4 format, but can only recognize 3149 it with a V3 key id, and can properly use only a V3 format RSA 3150 key. 3152 * Neither PGP 5.x nor PGP 6.0 recognize Elgamal Encrypt and Sign 3153 keys. They only handle Elgamal Encrypt-only keys. 3155 * There are many ways possible for two keys to have the same key 3156 material, but different fingerprints (and thus key ids). Perhaps 3157 the most interesting is an RSA key that has been "upgraded" to 3158 V4 format, but since a V4 fingerprint is constructed by hashing 3159 the key creation time along with other things, two V4 keys 3160 created at different times, yet with the same key material will 3161 have different fingerprints. 3163 * If an implementation is using zlib to interoperate with PGP 2.x, 3164 then the "windowBits" parameter should be set to -13. 3166 * PGP 2.6.X and 5.0 do not trim trailing whitespace from a 3167 "canonical text" signature. They only remove it from cleartext 3168 signatures. These signatures are not OpenPGP compliant -- 3169 OpenPGP requires trimming the whitespace. If you wish to 3170 interoperate with PGP 2.6.X or PGP 5, you may wish to accept 3171 these non-compliant signatures. 3173 * PGP 6.0 introduced a photographic user id and represents this id 3174 in packet number 17. The format of this packet is proprietary to 3175 its authors. Strictly speaking, an OpenPGP key that contains 3176 such a packet is not compliant to this document, and that packet 3177 number is reserved by this document for future use. However, if 3178 an implementation wishes to be compatible with such keys, the 3179 packet may be considered to be a user id packet with opaque 3180 contents. 3182 15. Authors and Working Group Chair 3184 The working group can be contacted via the current chair: 3186 John W. Noerenberg, II 3187 Qualcomm, Inc 3188 6455 Lusk Blvd 3189 San Diego, CA 92131 USA 3190 Email: jwn2@qualcomm.com 3191 Tel: +1 (619) 658-3510 3193 The principal authors of this draft are: 3195 Jon Callas 3196 Counterpane Internet Security, Inc. 3197 3031 Tisch Way, suite 100 East Plaza 3198 San Jose, CA 95128, USA 3200 Email: jon@callas.org, jon@counterpane.com 3201 Tel: +1 (408) 556-2445 3203 Lutz Donnerhacke 3204 IKS GmbH 3205 Wildenbruchstr. 15 3206 07745 Jena, Germany 3208 EMail: lutz@iks-jena.de 3209 Tel: +49-3641-675642 3211 Hal Finney 3212 Network Associates, Inc. 3213 3965 Freedom Circle 3214 Santa Clara, CA 95054, USA 3216 Email: hal@pgp.com 3218 Rodney Thayer 3220 Email: rodney@tillerman.to 3222 This memo also draws on much previous work from a number of other 3223 authors who include: Derek Atkins, Charles Breed, Dave Del Torto, 3224 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph 3225 Levien, Colin Plumb, Will Price, William Stallings, Mark Weaver, and 3226 Philip R. Zimmermann. 3228 16. References 3230 [AES] Advanced Encryption Standards Questions and Answers 3231 3234 3237 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal 3238 signatures without knowing the secret key," 3239 Eurocrypt 96. Note that the version in the 3240 proceedings has an error. A revised version is 3241 available at the time of writing from 3242 3245 [BLOWFISH] Schneier, B. "Description of a New Variable-Length 3246 Key, 64-Bit Block Cipher (Blowfish)" Fast Software 3247 Encryption, Cambridge Security Workshop Proceedings 3248 (December 1993), Springer-Verlag, 1994, pp191-204 3249 3251 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved 3252 international version of PGP", ftp://ftp.iks- 3253 jena.de/mitarb/lutz/crypt/software/pgp/ 3255 [ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a 3256 Signature Scheme Based on Discrete Logarithms," 3257 IEEE Transactions on Information Theory, v. IT-31, 3258 n. 4, 1985, pp. 469-472. 3260 [IDEA] Lai, X, "On the design and security of block 3261 ciphers", ETH Series in Information Processing, 3262 J.L. Massey (editor), Vol. 1, Hartung-Gorre Verlag 3263 Knostanz, Technische Hochschule (Zurich), 1992 3265 [ISO10646] ISO/IEC 10646-1:1993. International Standard -- 3266 Information technology -- Universal Multiple-Octet 3267 Coded Character Set (UCS) -- Part 1: Architecture 3268 and Basic Multilingual Plane. 3270 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott 3271 Vanstone, "Handbook of Applied Cryptography," CRC 3272 Press, 1996. 3274 [RFC822] Crocker, D., "Standard for the format of ARPA 3275 Internet text messages", STD 11, RFC 822, August 3276 1982. 3278 [RFC1423] Balenson, D., "Privacy Enhancement for Internet 3279 Electronic Mail: Part III: Algorithms, Modes, and 3280 Identifiers", RFC 1423, October 1993. 3282 [RFC1641] Goldsmith, D. and M. Davis, "Using Unicode with 3283 MIME", RFC 1641, July 1994. 3285 [RFC1750] Eastlake, D., Crocker, S. and J. Schiller, 3286 "Randomness Recommendations for Security", RFC 3287 1750, December 1994. 3289 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format 3290 Specification version 1.3.", RFC 1951, May 1996. 3292 [RFC1983] Malkin, G., "Internet Users' Glossary", FYI 18, RFC 3293 1983, August 1996. 3295 [RFC1991] Atkins, D., Stallings, W. and P. Zimmermann, "PGP 3296 Message Exchange Formats", RFC 1991, August 1996. 3298 [RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy 3299 (PGP)", RFC 2015, October 1996. 3301 [RFC2045] Borenstein, N. and N. Freed, "Multipurpose Internet 3302 Mail Extensions (MIME) Part One: Format of Internet 3303 Message Bodies.", RFC 2045, November 1996. 3305 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 3306 Requirement Level", BCP 14, RFC 2119, March 1997. 3308 [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC 3309 2144, May 1997. 3311 [RFC2279] Yergeau., F., "UTF-8, a transformation format of 3312 Unicode and ISO 10646", RFC 2279, January 1998. 3314 [RFC2437] B. Kaliski and J. Staddon, " PKCS #1: RSA 3315 Cryptography Specifications Version 2.0", 3316 RFC 2437, October 1998. 3318 [SAFER] Massey, J.L. "SAFER K-64: One Year Later", B. 3319 Preneel, editor, Fast Software Encryption, Second 3320 International Workshop (LNCS 1008) pp212-241, 3321 Springer-Verlag 1995 3323 [SCHNEIER] Schneier, B., "Applied Cryptography Second Edition: 3324 protocols, algorithms, and source code in C", 1996. 3326 [TWOFISH] B. Schneier, J. Kelsey, D. Whiting, D. Wagner, C. 3327 Hall, and N. Ferguson, "The Twofish Encryption 3328 Algorithm", John Wiley & Sons, 1999. 3330 17. Full Copyright Statement 3332 Copyright 2000 by The Internet Society. All Rights Reserved. 3334 This document and translations of it may be copied and furnished to 3335 others, and derivative works that comment on or otherwise explain it 3336 or assist in its implementation may be prepared, copied, published 3337 and distributed, in whole or in part, without restriction of any 3338 kind, provided that the above copyright notice and this paragraph 3339 are included on all such copies and derivative works. However, this 3340 document itself may not be modified in any way, such as by removing 3341 the copyright notice or references to the Internet Society or other 3342 Internet organizations, except as needed for the purpose of 3343 developing Internet standards in which case the procedures for 3344 copyrights defined in the Internet Standards process must be 3345 followed, or as required to translate it into languages other than 3346 English. 3348 The limited permissions granted above are perpetual and will not be 3349 revoked by the Internet Society or its successors or assigns.