1 1.1 agc 2 1.1 agc 3 1.1 agc 4 1.1 agc 5 1.1 agc 6 1.1 agc 7 1.1 agc Network Working Group J. Callas 8 1.1 agc Request for Comments: 4880 PGP Corporation 9 1.1 agc Obsoletes: 1991, 2440 L. Donnerhacke 10 1.1 agc Category: Standards Track IKS GmbH 11 1.1 agc H. Finney 12 1.1 agc PGP Corporation 13 1.1 agc D. Shaw 14 1.1 agc R. Thayer 15 1.1 agc November 2007 16 1.1 agc 17 1.1 agc 18 1.1 agc OpenPGP Message Format 19 1.1 agc 20 1.1 agc Status of This Memo 21 1.1 agc 22 1.1 agc This document specifies an Internet standards track protocol for the 23 1.1 agc Internet community, and requests discussion and suggestions for 24 1.1 agc improvements. Please refer to the current edition of the "Internet 25 1.1 agc Official Protocol Standards" (STD 1) for the standardization state 26 1.1 agc and status of this protocol. Distribution of this memo is unlimited. 27 1.1 agc 28 1.1 agc Abstract 29 1.1 agc 30 1.1 agc This document is maintained in order to publish all necessary 31 1.1 agc information needed to develop interoperable applications based on the 32 1.1 agc OpenPGP format. It is not a step-by-step cookbook for writing an 33 1.1 agc application. It describes only the format and methods needed to 34 1.1 agc read, check, generate, and write conforming packets crossing any 35 1.1 agc network. It does not deal with storage and implementation questions. 36 1.1 agc It does, however, discuss implementation issues necessary to avoid 37 1.1 agc security flaws. 38 1.1 agc 39 1.1 agc OpenPGP software uses a combination of strong public-key and 40 1.1 agc symmetric cryptography to provide security services for electronic 41 1.1 agc communications and data storage. These services include 42 1.1 agc confidentiality, key management, authentication, and digital 43 1.1 agc signatures. This document specifies the message formats used in 44 1.1 agc OpenPGP. 45 1.1 agc 46 1.1 agc 47 1.1 agc 48 1.1 agc 49 1.1 agc 50 1.1 agc 51 1.1 agc 52 1.1 agc 53 1.1 agc 54 1.1 agc 55 1.1 agc 56 1.1 agc 57 1.1 agc 58 1.1 agc Callas, et al Standards Track [Page 1] 59 1.1 agc 61 1.1 agc RFC 4880 OpenPGP Message Format November 2007 62 1.1 agc 63 1.1 agc 64 1.1 agc Table of Contents 65 1.1 agc 66 1.1 agc 1. Introduction ....................................................5 67 1.1 agc 1.1. Terms ......................................................5 68 1.1 agc 2. General functions ...............................................6 69 1.1 agc 2.1. Confidentiality via Encryption .............................6 70 1.1 agc 2.2. Authentication via Digital Signature .......................7 71 1.1 agc 2.3. Compression ................................................7 72 1.1 agc 2.4. Conversion to Radix-64 .....................................8 73 1.1 agc 2.5. Signature-Only Applications ................................8 74 1.1 agc 3. Data Element Formats ............................................8 75 1.1 agc 3.1. Scalar Numbers .............................................8 76 1.1 agc 3.2. Multiprecision Integers ....................................9 77 1.1 agc 3.3. Key IDs ....................................................9 78 1.1 agc 3.4. Text .......................................................9 79 1.1 agc 3.5. Time Fields ...............................................10 80 1.1 agc 3.6. Keyrings ..................................................10 81 1.1 agc 3.7. String-to-Key (S2K) Specifiers ............................10 82 1.1 agc 3.7.1. String-to-Key (S2K) Specifier Types ................10 83 1.1 agc 3.7.1.1. Simple S2K ................................10 84 1.1 agc 3.7.1.2. Salted S2K ................................11 85 1.1 agc 3.7.1.3. Iterated and Salted S2K ...................11 86 1.1 agc 3.7.2. String-to-Key Usage ................................12 87 1.1 agc 3.7.2.1. Secret-Key Encryption .....................12 88 1.1 agc 3.7.2.2. Symmetric-Key Message Encryption ..........13 89 1.1 agc 4. Packet Syntax ..................................................13 90 1.1 agc 4.1. Overview ..................................................13 91 1.1 agc 4.2. Packet Headers ............................................13 92 1.1 agc 4.2.1. Old Format Packet Lengths ..........................14 93 1.1 agc 4.2.2. New Format Packet Lengths ..........................15 94 1.1 agc 4.2.2.1. One-Octet Lengths .........................15 95 1.1 agc 4.2.2.2. Two-Octet Lengths .........................15 96 1.1 agc 4.2.2.3. Five-Octet Lengths ........................15 97 1.1 agc 4.2.2.4. Partial Body Lengths ......................16 98 1.1 agc 4.2.3. Packet Length Examples .............................16 99 1.1 agc 4.3. Packet Tags ...............................................17 100 1.1 agc 5. Packet Types ...................................................17 101 1.1 agc 5.1. Public-Key Encrypted Session Key Packets (Tag 1) ..........17 102 1.1 agc 5.2. Signature Packet (Tag 2) ..................................19 103 1.1 agc 5.2.1. Signature Types ....................................19 104 1.1 agc 5.2.2. Version 3 Signature Packet Format ..................21 105 1.1 agc 5.2.3. Version 4 Signature Packet Format ..................24 106 1.1 agc 5.2.3.1. Signature Subpacket Specification .........25 107 1.1 agc 5.2.3.2. Signature Subpacket Types .................27 108 1.1 agc 5.2.3.3. Notes on Self-Signatures ..................27 109 1.1 agc 5.2.3.4. Signature Creation Time ...................28 110 1.1 agc 5.2.3.5. Issuer ....................................28 111 1.1 agc 5.2.3.6. Key Expiration Time .......................28 112 1.1 agc 113 1.1 agc 114 1.1 agc 115 1.1 agc Callas, et al Standards Track [Page 2] 116 1.1 agc 118 1.1 agc RFC 4880 OpenPGP Message Format November 2007 119 1.1 agc 120 1.1 agc 121 1.1 agc 5.2.3.7. Preferred Symmetric Algorithms ............28 122 1.1 agc 5.2.3.8. Preferred Hash Algorithms .................29 123 1.1 agc 5.2.3.9. Preferred Compression Algorithms ..........29 124 1.1 agc 5.2.3.10. Signature Expiration Time ................29 125 1.1 agc 5.2.3.11. Exportable Certification .................29 126 1.1 agc 5.2.3.12. Revocable ................................30 127 1.1 agc 5.2.3.13. Trust Signature ..........................30 128 1.1 agc 5.2.3.14. Regular Expression .......................31 129 1.1 agc 5.2.3.15. Revocation Key ...........................31 130 1.1 agc 5.2.3.16. Notation Data ............................31 131 1.1 agc 5.2.3.17. Key Server Preferences ...................32 132 1.1 agc 5.2.3.18. Preferred Key Server .....................33 133 1.1 agc 5.2.3.19. Primary User ID ..........................33 134 1.1 agc 5.2.3.20. Policy URI ...............................33 135 1.1 agc 5.2.3.21. Key Flags ................................33 136 1.1 agc 5.2.3.22. Signer's User ID .........................34 137 1.1 agc 5.2.3.23. Reason for Revocation ....................35 138 1.1 agc 5.2.3.24. Features .................................36 139 1.1 agc 5.2.3.25. Signature Target .........................36 140 1.1 agc 5.2.3.26. Embedded Signature .......................37 141 1.1 agc 5.2.4. Computing Signatures ...............................37 142 1.1 agc 5.2.4.1. Subpacket Hints ...........................38 143 1.1 agc 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) .......38 144 1.1 agc 5.4. One-Pass Signature Packets (Tag 4) ........................39 145 1.1 agc 5.5. Key Material Packet .......................................40 146 1.1 agc 5.5.1. Key Packet Variants ................................40 147 1.1 agc 5.5.1.1. Public-Key Packet (Tag 6) .................40 148 1.1 agc 5.5.1.2. Public-Subkey Packet (Tag 14) .............40 149 1.1 agc 5.5.1.3. Secret-Key Packet (Tag 5) .................41 150 1.1 agc 5.5.1.4. Secret-Subkey Packet (Tag 7) ..............41 151 1.1 agc 5.5.2. Public-Key Packet Formats ..........................41 152 1.1 agc 5.5.3. Secret-Key Packet Formats ..........................43 153 1.1 agc 5.6. Compressed Data Packet (Tag 8) ............................45 154 1.1 agc 5.7. Symmetrically Encrypted Data Packet (Tag 9) ...............45 155 1.1 agc 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) ..........46 156 1.1 agc 5.9. Literal Data Packet (Tag 11) ..............................46 157 1.1 agc 5.10. Trust Packet (Tag 12) ....................................47 158 1.1 agc 5.11. User ID Packet (Tag 13) ..................................48 159 1.1 agc 5.12. User Attribute Packet (Tag 17) ...........................48 160 1.1 agc 5.12.1. The Image Attribute Subpacket .....................48 161 1.1 agc 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) ..49 162 1.1 agc 5.14. Modification Detection Code Packet (Tag 19) ..............52 163 1.1 agc 6. Radix-64 Conversions ...........................................53 164 1.1 agc 6.1. An Implementation of the CRC-24 in "C" ....................54 165 1.1 agc 6.2. Forming ASCII Armor .......................................54 166 1.1 agc 6.3. Encoding Binary in Radix-64 ...............................57 167 1.1 agc 6.4. Decoding Radix-64 .........................................58 168 1.1 agc 6.5. Examples of Radix-64 ......................................59 169 1.1 agc 170 1.1 agc 171 1.1 agc 172 1.1 agc Callas, et al Standards Track [Page 3] 173 1.1 agc 175 1.1 agc RFC 4880 OpenPGP Message Format November 2007 176 1.1 agc 177 1.1 agc 178 1.1 agc 6.6. Example of an ASCII Armored Message .......................59 179 1.1 agc 7. Cleartext Signature Framework ..................................59 180 1.1 agc 7.1. Dash-Escaped Text .........................................60 181 1.1 agc 8. Regular Expressions ............................................61 182 1.1 agc 9. Constants ......................................................61 183 1.1 agc 9.1. Public-Key Algorithms .....................................62 184 1.1 agc 9.2. Symmetric-Key Algorithms ..................................62 185 1.1 agc 9.3. Compression Algorithms ....................................63 186 1.1 agc 9.4. Hash Algorithms ...........................................63 187 1.1 agc 10. IANA Considerations ...........................................63 188 1.1 agc 10.1. New String-to-Key Specifier Types ........................64 189 1.1 agc 10.2. New Packets ..............................................64 190 1.1 agc 10.2.1. User Attribute Types ..............................64 191 1.1 agc 10.2.1.1. Image Format Subpacket Types .............64 192 1.1 agc 10.2.2. New Signature Subpackets ..........................64 193 1.1 agc 10.2.2.1. Signature Notation Data Subpackets .......65 194 1.1 agc 10.2.2.2. Key Server Preference Extensions .........65 195 1.1 agc 10.2.2.3. Key Flags Extensions .....................65 196 1.1 agc 10.2.2.4. Reason For Revocation Extensions .........65 197 1.1 agc 10.2.2.5. Implementation Features ..................66 198 1.1 agc 10.2.3. New Packet Versions ...............................66 199 1.1 agc 10.3. New Algorithms ...........................................66 200 1.1 agc 10.3.1. Public-Key Algorithms .............................66 201 1.1 agc 10.3.2. Symmetric-Key Algorithms ..........................67 202 1.1 agc 10.3.3. Hash Algorithms ...................................67 203 1.1 agc 10.3.4. Compression Algorithms ............................67 204 1.1 agc 11. Packet Composition ............................................67 205 1.1 agc 11.1. Transferable Public Keys .................................67 206 1.1 agc 11.2. Transferable Secret Keys .................................69 207 1.1 agc 11.3. OpenPGP Messages .........................................69 208 1.1 agc 11.4. Detached Signatures ......................................70 209 1.1 agc 12. Enhanced Key Formats ..........................................70 210 1.1 agc 12.1. Key Structures ...........................................70 211 1.1 agc 12.2. Key IDs and Fingerprints .................................71 212 1.1 agc 13. Notes on Algorithms ...........................................72 213 1.1 agc 13.1. PKCS#1 Encoding in OpenPGP ...............................72 214 1.1 agc 13.1.1. EME-PKCS1-v1_5-ENCODE .............................73 215 1.1 agc 13.1.2. EME-PKCS1-v1_5-DECODE .............................73 216 1.1 agc 13.1.3. EMSA-PKCS1-v1_5 ...................................74 217 1.1 agc 13.2. Symmetric Algorithm Preferences ..........................75 218 1.1 agc 13.3. Other Algorithm Preferences ..............................76 219 1.1 agc 13.3.1. Compression Preferences ...........................76 220 1.1 agc 13.3.2. Hash Algorithm Preferences ........................76 221 1.1 agc 13.4. Plaintext ................................................77 222 1.1 agc 13.5. RSA ......................................................77 223 1.1 agc 13.6. DSA ......................................................77 224 1.1 agc 13.7. Elgamal ..................................................78 225 1.1 agc 13.8. Reserved Algorithm Numbers ...............................78 226 1.1 agc 227 1.1 agc 228 1.1 agc 229 1.1 agc Callas, et al Standards Track [Page 4] 230 1.1 agc 232 1.1 agc RFC 4880 OpenPGP Message Format November 2007 233 1.1 agc 234 1.1 agc 235 1.1 agc 13.9. OpenPGP CFB Mode .........................................78 236 1.1 agc 13.10. Private or Experimental Parameters ......................79 237 1.1 agc 13.11. Extension of the MDC System .............................80 238 1.1 agc 13.12. Meta-Considerations for Expansion .......................80 239 1.1 agc 14. Security Considerations .......................................81 240 1.1 agc 15. Implementation Nits ...........................................84 241 1.1 agc 16. References ....................................................86 242 1.1 agc 16.1. Normative References .....................................86 243 1.1 agc 16.2. Informative References ...................................88 244 1.1 agc 245 1.1 agc 1. Introduction 246 1.1 agc 247 1.1 agc This document provides information on the message-exchange packet 248 1.1 agc formats used by OpenPGP to provide encryption, decryption, signing, 249 1.1 agc and key management functions. It is a revision of RFC 2440, "OpenPGP 250 1.1 agc Message Format", which itself replaces RFC 1991, "PGP Message 251 1.1 agc Exchange Formats" [RFC1991] [RFC2440]. 252 1.1 agc 253 1.1 agc 1.1. Terms 254 1.1 agc 255 1.1 agc * OpenPGP - This is a term for security software that uses PGP 5.x 256 1.1 agc as a basis, formalized in RFC 2440 and this document. 257 1.1 agc 258 1.1 agc * PGP - Pretty Good Privacy. PGP is a family of software systems 259 1.1 agc developed by Philip R. Zimmermann from which OpenPGP is based. 260 1.1 agc 261 1.1 agc * PGP 2.6.x - This version of PGP has many variants, hence the term 262 1.1 agc PGP 2.6.x. It used only RSA, MD5, and IDEA for its cryptographic 263 1.1 agc transforms. An informational RFC, RFC 1991, was written 264 1.1 agc describing this version of PGP. 265 1.1 agc 266 1.1 agc * PGP 5.x - This version of PGP is formerly known as "PGP 3" in the 267 1.1 agc community and also in the predecessor of this document, RFC 1991. 268 1.1 agc It has new formats and corrects a number of problems in the PGP 269 1.1 agc 2.6.x design. It is referred to here as PGP 5.x because that 270 1.1 agc software was the first release of the "PGP 3" code base. 271 1.1 agc 272 1.1 agc * GnuPG - GNU Privacy Guard, also called GPG. GnuPG is an OpenPGP 273 1.1 agc implementation that avoids all encumbered algorithms. 274 1.1 agc Consequently, early versions of GnuPG did not include RSA public 275 1.1 agc keys. GnuPG may or may not have (depending on version) support 276 1.1 agc for IDEA or other encumbered algorithms. 277 1.1 agc 278 1.1 agc "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of PGP 279 1.1 agc Corporation and are used with permission. The term "OpenPGP" refers 280 1.1 agc to the protocol described in this and related documents. 281 1.1 agc 282 1.1 agc 283 1.1 agc 284 1.1 agc 285 1.1 agc 286 1.1 agc Callas, et al Standards Track [Page 5] 287 1.1 agc 289 1.1 agc RFC 4880 OpenPGP Message Format November 2007 290 1.1 agc 291 1.1 agc 292 1.1 agc The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 293 1.1 agc "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this 294 1.1 agc document are to be interpreted as described in [RFC2119]. 295 1.1 agc 296 1.1 agc The key words "PRIVATE USE", "HIERARCHICAL ALLOCATION", "FIRST COME 297 1.1 agc FIRST SERVED", "EXPERT REVIEW", "SPECIFICATION REQUIRED", "IESG 298 1.1 agc APPROVAL", "IETF CONSENSUS", and "STANDARDS ACTION" that appear in 299 1.1 agc this document when used to describe namespace allocation are to be 300 1.1 agc interpreted as described in [RFC2434]. 301 1.1 agc 302 1.1 agc 2. General functions 303 1.1 agc 304 1.1 agc OpenPGP provides data integrity services for messages and data files 305 1.1 agc by using these core technologies: 306 1.1 agc 307 1.1 agc - digital signatures 308 1.1 agc 309 1.1 agc - encryption 310 1.1 agc 311 1.1 agc - compression 312 1.1 agc 313 1.1 agc - Radix-64 conversion 314 1.1 agc 315 1.1 agc In addition, OpenPGP provides key management and certificate 316 1.1 agc services, but many of these are beyond the scope of this document. 317 1.1 agc 318 1.1 agc 2.1. Confidentiality via Encryption 319 1.1 agc 320 1.1 agc OpenPGP combines symmetric-key encryption and public-key encryption 321 1.1 agc to provide confidentiality. When made confidential, first the object 322 1.1 agc is encrypted using a symmetric encryption algorithm. Each symmetric 323 1.1 agc key is used only once, for a single object. A new "session key" is 324 1.1 agc generated as a random number for each object (sometimes referred to 325 1.1 agc as a session). Since it is used only once, the session key is bound 326 1.1 agc to the message and transmitted with it. To protect the key, it is 327 1.1 agc encrypted with the receiver's public key. The sequence is as 328 1.1 agc follows: 329 1.1 agc 330 1.1 agc 1. The sender creates a message. 331 1.1 agc 332 1.1 agc 2. The sending OpenPGP generates a random number to be used as a 333 1.1 agc session key for this message only. 334 1.1 agc 335 1.1 agc 3. The session key is encrypted using each recipient's public key. 336 1.1 agc These "encrypted session keys" start the message. 337 1.1 agc 338 1.1 agc 339 1.1 agc 340 1.1 agc 341 1.1 agc 342 1.1 agc 343 1.1 agc Callas, et al Standards Track [Page 6] 344 1.1 agc 346 1.1 agc RFC 4880 OpenPGP Message Format November 2007 347 1.1 agc 348 1.1 agc 349 1.1 agc 4. The sending OpenPGP encrypts the message using the session key, 350 1.1 agc which forms the remainder of the message. Note that the message 351 1.1 agc is also usually compressed. 352 1.1 agc 353 1.1 agc 5. The receiving OpenPGP decrypts the session key using the 354 1.1 agc recipient's private key. 355 1.1 agc 356 1.1 agc 6. The receiving OpenPGP decrypts the message using the session key. 357 1.1 agc If the message was compressed, it will be decompressed. 358 1.1 agc 359 1.1 agc With symmetric-key encryption, an object may be encrypted with a 360 1.1 agc symmetric key derived from a passphrase (or other shared secret), or 361 1.1 agc a two-stage mechanism similar to the public-key method described 362 1.1 agc above in which a session key is itself encrypted with a symmetric 363 1.1 agc algorithm keyed from a shared secret. 364 1.1 agc 365 1.1 agc Both digital signature and confidentiality services may be applied to 366 1.1 agc the same message. First, a signature is generated for the message 367 1.1 agc and attached to the message. Then the message plus signature is 368 1.1 agc encrypted using a symmetric session key. Finally, the session key is 369 1.1 agc encrypted using public-key encryption and prefixed to the encrypted 370 1.1 agc block. 371 1.1 agc 372 1.1 agc 2.2. Authentication via Digital Signature 373 1.1 agc 374 1.1 agc The digital signature uses a hash code or message digest algorithm, 375 1.1 agc and a public-key signature algorithm. The sequence is as follows: 376 1.1 agc 377 1.1 agc 1. The sender creates a message. 378 1.1 agc 379 1.1 agc 2. The sending software generates a hash code of the message. 380 1.1 agc 381 1.1 agc 3. The sending software generates a signature from the hash code 382 1.1 agc using the sender's private key. 383 1.1 agc 384 1.1 agc 4. The binary signature is attached to the message. 385 1.1 agc 386 1.1 agc 5. The receiving software keeps a copy of the message signature. 387 1.1 agc 388 1.1 agc 6. The receiving software generates a new hash code for the received 389 1.1 agc message and verifies it using the message's signature. If the 390 1.1 agc verification is successful, the message is accepted as authentic. 391 1.1 agc 392 1.1 agc 2.3. Compression 393 1.1 agc 394 1.1 agc OpenPGP implementations SHOULD compress the message after applying 395 1.1 agc the signature but before encryption. 396 1.1 agc 397 1.1 agc 398 1.1 agc 399 1.1 agc 400 1.1 agc Callas, et al Standards Track [Page 7] 401 1.1 agc 403 1.1 agc RFC 4880 OpenPGP Message Format November 2007 404 1.1 agc 405 1.1 agc 406 1.1 agc If an implementation does not implement compression, its authors 407 1.1 agc should be aware that most OpenPGP messages in the world are 408 1.1 agc compressed. Thus, it may even be wise for a space-constrained 409 1.1 agc implementation to implement decompression, but not compression. 410 1.1 agc 411 1.1 agc Furthermore, compression has the added side effect that some types of 412 1.1 agc attacks can be thwarted by the fact that slightly altered, compressed 413 1.1 agc data rarely uncompresses without severe errors. This is hardly 414 1.1 agc rigorous, but it is operationally useful. These attacks can be 415 1.1 agc rigorously prevented by implementing and using Modification Detection 416 1.1 agc Codes as described in sections following. 417 1.1 agc 418 1.1 agc 2.4. Conversion to Radix-64 419 1.1 agc 420 1.1 agc OpenPGP's underlying native representation for encrypted messages, 421 1.1 agc signature certificates, and keys is a stream of arbitrary octets. 422 1.1 agc Some systems only permit the use of blocks consisting of seven-bit, 423 1.1 agc printable text. For transporting OpenPGP's native raw binary octets 424 1.1 agc through channels that are not safe to raw binary data, a printable 425 1.1 agc encoding of these binary octets is needed. OpenPGP provides the 426 1.1 agc service of converting the raw 8-bit binary octet stream to a stream 427 1.1 agc of printable ASCII characters, called Radix-64 encoding or ASCII 428 1.1 agc Armor. 429 1.1 agc 430 1.1 agc Implementations SHOULD provide Radix-64 conversions. 431 1.1 agc 432 1.1 agc 2.5. Signature-Only Applications 433 1.1 agc 434 1.1 agc OpenPGP is designed for applications that use both encryption and 435 1.1 agc signatures, but there are a number of problems that are solved by a 436 1.1 agc signature-only implementation. Although this specification requires 437 1.1 agc both encryption and signatures, it is reasonable for there to be 438 1.1 agc subset implementations that are non-conformant only in that they omit 439 1.1 agc encryption. 440 1.1 agc 441 1.1 agc 3. Data Element Formats 442 1.1 agc 443 1.1 agc This section describes the data elements used by OpenPGP. 444 1.1 agc 445 1.1 agc 3.1. Scalar Numbers 446 1.1 agc 447 1.1 agc Scalar numbers are unsigned and are always stored in big-endian 448 1.1 agc format. Using n[k] to refer to the kth octet being interpreted, the 449 1.1 agc value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a 450 1.1 agc four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) + 451 1.1 agc n[3]). 452 1.1 agc 453 1.1 agc 454 1.1 agc 455 1.1 agc 456 1.1 agc 457 1.1 agc Callas, et al Standards Track [Page 8] 458 1.1 agc 460 1.1 agc RFC 4880 OpenPGP Message Format November 2007 461 1.1 agc 462 1.1 agc 463 1.1 agc 3.2. Multiprecision Integers 464 1.1 agc 465 1.1 agc Multiprecision integers (also called MPIs) are unsigned integers used 466 1.1 agc to hold large integers such as the ones used in cryptographic 467 1.1 agc calculations. 468 1.1 agc 469 1.1 agc An MPI consists of two pieces: a two-octet scalar that is the length 470 1.1 agc of the MPI in bits followed by a string of octets that contain the 471 1.1 agc actual integer. 472 1.1 agc 473 1.1 agc These octets form a big-endian number; a big-endian number can be 474 1.1 agc made into an MPI by prefixing it with the appropriate length. 475 1.1 agc 476 1.1 agc Examples: 477 1.1 agc 478 1.1 agc (all numbers are in hexadecimal) 479 1.1 agc 480 1.1 agc The string of octets [00 01 01] forms an MPI with the value 1. The 481 1.1 agc string [00 09 01 FF] forms an MPI with the value of 511. 482 1.1 agc 483 1.1 agc Additional rules: 484 1.1 agc 485 1.1 agc The size of an MPI is ((MPI.length + 7) / 8) + 2 octets. 486 1.1 agc 487 1.1 agc The length field of an MPI describes the length starting from its 488 1.1 agc most significant non-zero bit. Thus, the MPI [00 02 01] is not 489 1.1 agc formed correctly. It should be [00 01 01]. 490 1.1 agc 491 1.1 agc Unused bits of an MPI MUST be zero. 492 1.1 agc 493 1.1 agc Also note that when an MPI is encrypted, the length refers to the 494 1.1 agc plaintext MPI. It may be ill-formed in its ciphertext. 495 1.1 agc 496 1.1 agc 3.3. Key IDs 497 1.1 agc 498 1.1 agc A Key ID is an eight-octet scalar that identifies a key. 499 1.1 agc Implementations SHOULD NOT assume that Key IDs are unique. The 500 1.1 agc section "Enhanced Key Formats" below describes how Key IDs are 501 1.1 agc formed. 502 1.1 agc 503 1.1 agc 3.4. Text 504 1.1 agc 505 1.1 agc Unless otherwise specified, the character set for text is the UTF-8 506 1.1 agc [RFC3629] encoding of Unicode [ISO10646]. 507 1.1 agc 508 1.1 agc 509 1.1 agc 510 1.1 agc 511 1.1 agc 512 1.1 agc 513 1.1 agc 514 1.1 agc Callas, et al Standards Track [Page 9] 515 1.1 agc 517 1.1 agc RFC 4880 OpenPGP Message Format November 2007 518 1.1 agc 519 1.1 agc 520 1.1 agc 3.5. Time Fields 521 1.1 agc 522 1.1 agc A time field is an unsigned four-octet number containing the number 523 1.1 agc of seconds elapsed since midnight, 1 January 1970 UTC. 524 1.1 agc 525 1.1 agc 3.6. Keyrings 526 1.1 agc 527 1.1 agc A keyring is a collection of one or more keys in a file or database. 528 1.1 agc Traditionally, a keyring is simply a sequential list of keys, but may 529 1.1 agc be any suitable database. It is beyond the scope of this standard to 530 1.1 agc discuss the details of keyrings or other databases. 531 1.1 agc 532 1.1 agc 3.7. String-to-Key (S2K) Specifiers 533 1.1 agc 534 1.1 agc String-to-key (S2K) specifiers are used to convert passphrase strings 535 1.1 agc into symmetric-key encryption/decryption keys. They are used in two 536 1.1 agc places, currently: to encrypt the secret part of private keys in the 537 1.1 agc private keyring, and to convert passphrases to encryption keys for 538 1.1 agc symmetrically encrypted messages. 539 1.1 agc 540 1.1 agc 3.7.1. String-to-Key (S2K) Specifier Types 541 1.1 agc 542 1.1 agc There are three types of S2K specifiers currently supported, and 543 1.1 agc some reserved values: 544 1.1 agc 545 1.1 agc ID S2K Type 546 1.1 agc -- -------- 547 1.1 agc 0 Simple S2K 548 1.1 agc 1 Salted S2K 549 1.1 agc 2 Reserved value 550 1.1 agc 3 Iterated and Salted S2K 551 1.1 agc 100 to 110 Private/Experimental S2K 552 1.1 agc 553 1.1 agc These are described in Sections 3.7.1.1 - 3.7.1.3. 554 1.1 agc 555 1.1 agc 3.7.1.1. Simple S2K 556 1.1 agc 557 1.1 agc This directly hashes the string to produce the key data. See below 558 1.1 agc for how this hashing is done. 559 1.1 agc 560 1.1 agc Octet 0: 0x00 561 1.1 agc Octet 1: hash algorithm 562 1.1 agc 563 1.1 agc Simple S2K hashes the passphrase to produce the session key. The 564 1.1 agc manner in which this is done depends on the size of the session key 565 1.1 agc (which will depend on the cipher used) and the size of the hash 566 1.1 agc 567 1.1 agc 568 1.1 agc 569 1.1 agc 570 1.1 agc 571 1.1 agc Callas, et al Standards Track [Page 10] 572 1.1 agc 574 1.1 agc RFC 4880 OpenPGP Message Format November 2007 575 1.1 agc 576 1.1 agc 577 1.1 agc algorithm's output. If the hash size is greater than the session key 578 1.1 agc size, the high-order (leftmost) octets of the hash are used as the 579 1.1 agc key. 580 1.1 agc 581 1.1 agc If the hash size is less than the key size, multiple instances of the 582 1.1 agc hash context are created -- enough to produce the required key data. 583 1.1 agc These instances are preloaded with 0, 1, 2, ... octets of zeros (that 584 1.1 agc is to say, the first instance has no preloading, the second gets 585 1.1 agc preloaded with 1 octet of zero, the third is preloaded with two 586 1.1 agc octets of zeros, and so forth). 587 1.1 agc 588 1.1 agc As the data is hashed, it is given independently to each hash 589 1.1 agc context. Since the contexts have been initialized differently, they 590 1.1 agc will each produce different hash output. Once the passphrase is 591 1.1 agc hashed, the output data from the multiple hashes is concatenated, 592 1.1 agc first hash leftmost, to produce the key data, with any excess octets 593 1.1 agc on the right discarded. 594 1.1 agc 595 1.1 agc 3.7.1.2. Salted S2K 596 1.1 agc 597 1.1 agc This includes a "salt" value in the S2K specifier -- some arbitrary 598 1.1 agc data -- that gets hashed along with the passphrase string, to help 599 1.1 agc prevent dictionary attacks. 600 1.1 agc 601 1.1 agc Octet 0: 0x01 602 1.1 agc Octet 1: hash algorithm 603 1.1 agc Octets 2-9: 8-octet salt value 604 1.1 agc 605 1.1 agc Salted S2K is exactly like Simple S2K, except that the input to the 606 1.1 agc hash function(s) consists of the 8 octets of salt from the S2K 607 1.1 agc specifier, followed by the passphrase. 608 1.1 agc 609 1.1 agc 3.7.1.3. Iterated and Salted S2K 610 1.1 agc 611 1.1 agc This includes both a salt and an octet count. The salt is combined 612 1.1 agc with the passphrase and the resulting value is hashed repeatedly. 613 1.1 agc This further increases the amount of work an attacker must do to try 614 1.1 agc dictionary attacks. 615 1.1 agc 616 1.1 agc Octet 0: 0x03 617 1.1 agc Octet 1: hash algorithm 618 1.1 agc Octets 2-9: 8-octet salt value 619 1.1 agc Octet 10: count, a one-octet, coded value 620 1.1 agc 621 1.1 agc 622 1.1 agc 623 1.1 agc 624 1.1 agc 625 1.1 agc 626 1.1 agc 627 1.1 agc 628 1.1 agc Callas, et al Standards Track [Page 11] 629 1.1 agc 631 1.1 agc RFC 4880 OpenPGP Message Format November 2007 632 1.1 agc 633 1.1 agc 634 1.1 agc The count is coded into a one-octet number using the following 635 1.1 agc formula: 636 1.1 agc 637 1.1 agc #define EXPBIAS 6 638 1.1 agc count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS); 639 1.1 agc 640 1.1 agc The above formula is in C, where "Int32" is a type for a 32-bit 641 1.1 agc integer, and the variable "c" is the coded count, Octet 10. 642 1.1 agc 643 1.1 agc Iterated-Salted S2K hashes the passphrase and salt data multiple 644 1.1 agc times. The total number of octets to be hashed is specified in the 645 1.1 agc encoded count in the S2K specifier. Note that the resulting count 646 1.1 agc value is an octet count of how many octets will be hashed, not an 647 1.1 agc iteration count. 648 1.1 agc 649 1.1 agc Initially, one or more hash contexts are set up as with the other S2K 650 1.1 agc algorithms, depending on how many octets of key data are needed. 651 1.1 agc Then the salt, followed by the passphrase data, is repeatedly hashed 652 1.1 agc until the number of octets specified by the octet count has been 653 1.1 agc hashed. The one exception is that if the octet count is less than 654 1.1 agc the size of the salt plus passphrase, the full salt plus passphrase 655 1.1 agc will be hashed even though that is greater than the octet count. 656 1.1 agc After the hashing is done, the data is unloaded from the hash 657 1.1 agc context(s) as with the other S2K algorithms. 658 1.1 agc 659 1.1 agc 3.7.2. String-to-Key Usage 660 1.1 agc 661 1.1 agc Implementations SHOULD use salted or iterated-and-salted S2K 662 1.1 agc specifiers, as simple S2K specifiers are more vulnerable to 663 1.1 agc dictionary attacks. 664 1.1 agc 665 1.1 agc 3.7.2.1. Secret-Key Encryption 666 1.1 agc 667 1.1 agc An S2K specifier can be stored in the secret keyring to specify how 668 1.1 agc to convert the passphrase to a key that unlocks the secret data. 669 1.1 agc Older versions of PGP just stored a cipher algorithm octet preceding 670 1.1 agc the secret data or a zero to indicate that the secret data was 671 1.1 agc unencrypted. The MD5 hash function was always used to convert the 672 1.1 agc passphrase to a key for the specified cipher algorithm. 673 1.1 agc 674 1.1 agc For compatibility, when an S2K specifier is used, the special value 675 1.1 agc 254 or 255 is stored in the position where the hash algorithm octet 676 1.1 agc would have been in the old data structure. This is then followed 677 1.1 agc immediately by a one-octet algorithm identifier, and then by the S2K 678 1.1 agc specifier as encoded above. 679 1.1 agc 680 1.1 agc 681 1.1 agc 682 1.1 agc 683 1.1 agc 684 1.1 agc 685 1.1 agc Callas, et al Standards Track [Page 12] 686 1.1 agc 688 1.1 agc RFC 4880 OpenPGP Message Format November 2007 689 1.1 agc 690 1.1 agc 691 1.1 agc Therefore, preceding the secret data there will be one of these 692 1.1 agc possibilities: 693 1.1 agc 694 1.1 agc 0: secret data is unencrypted (no passphrase) 695 1.1 agc 255 or 254: followed by algorithm octet and S2K specifier 696 1.1 agc Cipher alg: use Simple S2K algorithm using MD5 hash 697 1.1 agc 698 1.1 agc This last possibility, the cipher algorithm number with an implicit 699 1.1 agc use of MD5 and IDEA, is provided for backward compatibility; it MAY 700 1.1 agc be understood, but SHOULD NOT be generated, and is deprecated. 701 1.1 agc 702 1.1 agc These are followed by an Initial Vector of the same length as the 703 1.1 agc block size of the cipher for the decryption of the secret values, if 704 1.1 agc they are encrypted, and then the secret-key values themselves. 705 1.1 agc 706 1.1 agc 3.7.2.2. Symmetric-Key Message Encryption 707 1.1 agc 708 1.1 agc OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) packet 709 1.1 agc at the front of a message. This is used to allow S2K specifiers to 710 1.1 agc be used for the passphrase conversion or to create messages with a 711 1.1 agc mix of symmetric-key ESKs and public-key ESKs. This allows a message 712 1.1 agc to be decrypted either with a passphrase or a public-key pair. 713 1.1 agc 714 1.1 agc PGP 2.X always used IDEA with Simple string-to-key conversion when 715 1.1 agc encrypting a message with a symmetric algorithm. This is deprecated, 716 1.1 agc but MAY be used for backward-compatibility. 717 1.1 agc 718 1.1 agc 4. Packet Syntax 719 1.1 agc 720 1.1 agc This section describes the packets used by OpenPGP. 721 1.1 agc 722 1.1 agc 4.1. Overview 723 1.1 agc 724 1.1 agc An OpenPGP message is constructed from a number of records that are 725 1.1 agc traditionally called packets. A packet is a chunk of data that has a 726 1.1 agc tag specifying its meaning. An OpenPGP message, keyring, 727 1.1 agc certificate, and so forth consists of a number of packets. Some of 728 1.1 agc those packets may contain other OpenPGP packets (for example, a 729 1.1 agc compressed data packet, when uncompressed, contains OpenPGP packets). 730 1.1 agc 731 1.1 agc Each packet consists of a packet header, followed by the packet body. 732 1.1 agc The packet header is of variable length. 733 1.1 agc 734 1.1 agc 4.2. Packet Headers 735 1.1 agc 736 1.1 agc The first octet of the packet header is called the "Packet Tag". It 737 1.1 agc determines the format of the header and denotes the packet contents. 738 1.1 agc The remainder of the packet header is the length of the packet. 739 1.1 agc 740 1.1 agc 741 1.1 agc 742 1.1 agc Callas, et al Standards Track [Page 13] 743 1.1 agc 745 1.1 agc RFC 4880 OpenPGP Message Format November 2007 746 1.1 agc 747 1.1 agc 748 1.1 agc Note that the most significant bit is the leftmost bit, called bit 7. 749 1.1 agc A mask for this bit is 0x80 in hexadecimal. 750 1.1 agc 751 1.1 agc +---------------+ 752 1.1 agc PTag |7 6 5 4 3 2 1 0| 753 1.1 agc +---------------+ 754 1.1 agc Bit 7 -- Always one 755 1.1 agc Bit 6 -- New packet format if set 756 1.1 agc 757 1.1 agc PGP 2.6.x only uses old format packets. Thus, software that 758 1.1 agc interoperates with those versions of PGP must only use old format 759 1.1 agc packets. If interoperability is not an issue, the new packet format 760 1.1 agc is RECOMMENDED. Note that old format packets have four bits of 761 1.1 agc packet tags, and new format packets have six; some features cannot be 762 1.1 agc used and still be backward-compatible. 763 1.1 agc 764 1.1 agc Also note that packets with a tag greater than or equal to 16 MUST 765 1.1 agc use new format packets. The old format packets can only express tags 766 1.1 agc less than or equal to 15. 767 1.1 agc 768 1.1 agc Old format packets contain: 769 1.1 agc 770 1.1 agc Bits 5-2 -- packet tag 771 1.1 agc Bits 1-0 -- length-type 772 1.1 agc 773 1.1 agc New format packets contain: 774 1.1 agc 775 1.1 agc Bits 5-0 -- packet tag 776 1.1 agc 777 1.1 agc 4.2.1. Old Format Packet Lengths 778 1.1 agc 779 1.1 agc The meaning of the length-type in old format packets is: 780 1.1 agc 781 1.1 agc 0 - The packet has a one-octet length. The header is 2 octets long. 782 1.1 agc 783 1.1 agc 1 - The packet has a two-octet length. The header is 3 octets long. 784 1.1 agc 785 1.1 agc 2 - The packet has a four-octet length. The header is 5 octets long. 786 1.1 agc 787 1.1 agc 3 - The packet is of indeterminate length. The header is 1 octet 788 1.1 agc long, and the implementation must determine how long the packet 789 1.1 agc is. If the packet is in a file, this means that the packet 790 1.1 agc extends until the end of the file. In general, an implementation 791 1.1 agc SHOULD NOT use indeterminate-length packets except where the end 792 1.1 agc of the data will be clear from the context, and even then it is 793 1.1 agc better to use a definite length, or a new format header. The new 794 1.1 agc format headers described below have a mechanism for precisely 795 1.1 agc encoding data of indeterminate length. 796 1.1 agc 797 1.1 agc 798 1.1 agc 799 1.1 agc Callas, et al Standards Track [Page 14] 800 1.1 agc 802 1.1 agc RFC 4880 OpenPGP Message Format November 2007 803 1.1 agc 804 1.1 agc 805 1.1 agc 4.2.2. New Format Packet Lengths 806 1.1 agc 807 1.1 agc New format packets have four possible ways of encoding length: 808 1.1 agc 809 1.1 agc 1. A one-octet Body Length header encodes packet lengths of up to 191 810 1.1 agc octets. 811 1.1 agc 812 1.1 agc 2. A two-octet Body Length header encodes packet lengths of 192 to 813 1.1 agc 8383 octets. 814 1.1 agc 815 1.1 agc 3. A five-octet Body Length header encodes packet lengths of up to 816 1.1 agc 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually 817 1.1 agc encodes a four-octet scalar number.) 818 1.1 agc 819 1.1 agc 4. When the length of the packet body is not known in advance by the 820 1.1 agc issuer, Partial Body Length headers encode a packet of 821 1.1 agc indeterminate length, effectively making it a stream. 822 1.1 agc 823 1.1 agc 4.2.2.1. One-Octet Lengths 824 1.1 agc 825 1.1 agc A one-octet Body Length header encodes a length of 0 to 191 octets. 826 1.1 agc This type of length header is recognized because the one octet value 827 1.1 agc is less than 192. The body length is equal to: 828 1.1 agc 829 1.1 agc bodyLen = 1st_octet; 830 1.1 agc 831 1.1 agc 4.2.2.2. Two-Octet Lengths 832 1.1 agc 833 1.1 agc A two-octet Body Length header encodes a length of 192 to 8383 834 1.1 agc octets. It is recognized because its first octet is in the range 192 835 1.1 agc to 223. The body length is equal to: 836 1.1 agc 837 1.1 agc bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 838 1.1 agc 839 1.1 agc 4.2.2.3. Five-Octet Lengths 840 1.1 agc 841 1.1 agc A five-octet Body Length header consists of a single octet holding 842 1.1 agc the value 255, followed by a four-octet scalar. The body length is 843 1.1 agc equal to: 844 1.1 agc 845 1.1 agc bodyLen = (2nd_octet << 24) | (3rd_octet << 16) | 846 1.1 agc (4th_octet << 8) | 5th_octet 847 1.1 agc 848 1.1 agc This basic set of one, two, and five-octet lengths is also used 849 1.1 agc internally to some packets. 850 1.1 agc 851 1.1 agc 852 1.1 agc 853 1.1 agc 854 1.1 agc 855 1.1 agc 856 1.1 agc Callas, et al Standards Track [Page 15] 857 1.1 agc 859 1.1 agc RFC 4880 OpenPGP Message Format November 2007 860 1.1 agc 861 1.1 agc 862 1.1 agc 4.2.2.4. Partial Body Lengths 863 1.1 agc 864 1.1 agc A Partial Body Length header is one octet long and encodes the length 865 1.1 agc of only part of the data packet. This length is a power of 2, from 1 866 1.1 agc to 1,073,741,824 (2 to the 30th power). It is recognized by its one 867 1.1 agc octet value that is greater than or equal to 224, and less than 255. 868 1.1 agc The Partial Body Length is equal to: 869 1.1 agc 870 1.1 agc partialBodyLen = 1 << (1st_octet & 0x1F); 871 1.1 agc 872 1.1 agc Each Partial Body Length header is followed by a portion of the 873 1.1 agc packet body data. The Partial Body Length header specifies this 874 1.1 agc portion's length. Another length header (one octet, two-octet, 875 1.1 agc five-octet, or partial) follows that portion. The last length header 876 1.1 agc in the packet MUST NOT be a Partial Body Length header. Partial Body 877 1.1 agc Length headers may only be used for the non-final parts of the 878 1.1 agc packet. 879 1.1 agc 880 1.1 agc Note also that the last Body Length header can be a zero-length 881 1.1 agc header. 882 1.1 agc 883 1.1 agc An implementation MAY use Partial Body Lengths for data packets, be 884 1.1 agc they literal, compressed, or encrypted. The first partial length 885 1.1 agc MUST be at least 512 octets long. Partial Body Lengths MUST NOT be 886 1.1 agc used for any other packet types. 887 1.1 agc 888 1.1 agc 4.2.3. Packet Length Examples 889 1.1 agc 890 1.1 agc These examples show ways that new format packets might encode the 891 1.1 agc packet lengths. 892 1.1 agc 893 1.1 agc A packet with length 100 may have its length encoded in one octet: 894 1.1 agc 0x64. This is followed by 100 octets of data. 895 1.1 agc 896 1.1 agc A packet with length 1723 may have its length encoded in two octets: 897 1.1 agc 0xC5, 0xFB. This header is followed by the 1723 octets of data. 898 1.1 agc 899 1.1 agc A packet with length 100000 may have its length encoded in five 900 1.1 agc octets: 0xFF, 0x00, 0x01, 0x86, 0xA0. 901 1.1 agc 902 1.1 agc It might also be encoded in the following octet stream: 0xEF, first 903 1.1 agc 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one 904 1.1 agc octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 1693 905 1.1 agc octets of data. This is just one possible encoding, and many 906 1.1 agc variations are possible on the size of the Partial Body Length 907 1.1 agc headers, as long as a regular Body Length header encodes the last 908 1.1 agc portion of the data. 909 1.1 agc 910 1.1 agc 911 1.1 agc 912 1.1 agc 913 1.1 agc Callas, et al Standards Track [Page 16] 914 1.1 agc 916 1.1 agc RFC 4880 OpenPGP Message Format November 2007 917 1.1 agc 918 1.1 agc 919 1.1 agc Please note that in all of these explanations, the total length of 920 1.1 agc the packet is the length of the header(s) plus the length of the 921 1.1 agc body. 922 1.1 agc 923 1.1 agc 4.3. Packet Tags 924 1.1 agc 925 1.1 agc The packet tag denotes what type of packet the body holds. Note that 926 1.1 agc old format headers can only have tags less than 16, whereas new 927 1.1 agc format headers can have tags as great as 63. The defined tags (in 928 1.1 agc decimal) are as follows: 929 1.1 agc 930 1.1 agc 0 -- Reserved - a packet tag MUST NOT have this value 931 1.1 agc 1 -- Public-Key Encrypted Session Key Packet 932 1.1 agc 2 -- Signature Packet 933 1.1 agc 3 -- Symmetric-Key Encrypted Session Key Packet 934 1.1 agc 4 -- One-Pass Signature Packet 935 1.1 agc 5 -- Secret-Key Packet 936 1.1 agc 6 -- Public-Key Packet 937 1.1 agc 7 -- Secret-Subkey Packet 938 1.1 agc 8 -- Compressed Data Packet 939 1.1 agc 9 -- Symmetrically Encrypted Data Packet 940 1.1 agc 10 -- Marker Packet 941 1.1 agc 11 -- Literal Data Packet 942 1.1 agc 12 -- Trust Packet 943 1.1 agc 13 -- User ID Packet 944 1.1 agc 14 -- Public-Subkey Packet 945 1.1 agc 17 -- User Attribute Packet 946 1.1 agc 18 -- Sym. Encrypted and Integrity Protected Data Packet 947 1.1 agc 19 -- Modification Detection Code Packet 948 1.1 agc 60 to 63 -- Private or Experimental Values 949 1.1 agc 950 1.1 agc 5. Packet Types 951 1.1 agc 952 1.1 agc 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 953 1.1 agc 954 1.1 agc A Public-Key Encrypted Session Key packet holds the session key used 955 1.1 agc to encrypt a message. Zero or more Public-Key Encrypted Session Key 956 1.1 agc packets and/or Symmetric-Key Encrypted Session Key packets may 957 1.1 agc precede a Symmetrically Encrypted Data Packet, which holds an 958 1.1 agc encrypted message. The message is encrypted with the session key, 959 1.1 agc and the session key is itself encrypted and stored in the Encrypted 960 1.1 agc Session Key packet(s). The Symmetrically Encrypted Data Packet is 961 1.1 agc preceded by one Public-Key Encrypted Session Key packet for each 962 1.1 agc OpenPGP key to which the message is encrypted. The recipient of the 963 1.1 agc message finds a session key that is encrypted to their public key, 964 1.1 agc decrypts the session key, and then uses the session key to decrypt 965 1.1 agc the message. 966 1.1 agc 967 1.1 agc 968 1.1 agc 969 1.1 agc 970 1.1 agc Callas, et al Standards Track [Page 17] 971 1.1 agc 973 1.1 agc RFC 4880 OpenPGP Message Format November 2007 974 1.1 agc 975 1.1 agc 976 1.1 agc The body of this packet consists of: 977 1.1 agc 978 1.1 agc - A one-octet number giving the version number of the packet type. 979 1.1 agc The currently defined value for packet version is 3. 980 1.1 agc 981 1.1 agc - An eight-octet number that gives the Key ID of the public key to 982 1.1 agc which the session key is encrypted. If the session key is 983 1.1 agc encrypted to a subkey, then the Key ID of this subkey is used 984 1.1 agc here instead of the Key ID of the primary key. 985 1.1 agc 986 1.1 agc - A one-octet number giving the public-key algorithm used. 987 1.1 agc 988 1.1 agc - A string of octets that is the encrypted session key. This 989 1.1 agc string takes up the remainder of the packet, and its contents are 990 1.1 agc dependent on the public-key algorithm used. 991 1.1 agc 992 1.1 agc Algorithm Specific Fields for RSA encryption 993 1.1 agc 994 1.1 agc - multiprecision integer (MPI) of RSA encrypted value m**e mod n. 995 1.1 agc 996 1.1 agc Algorithm Specific Fields for Elgamal encryption: 997 1.1 agc 998 1.1 agc - MPI of Elgamal (Diffie-Hellman) value g**k mod p. 999 1.1 agc 1000 1.1 agc - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p. 1001 1.1 agc 1002 1.1 agc The value "m" in the above formulas is derived from the session key 1003 1.1 agc as follows. First, the session key is prefixed with a one-octet 1004 1.1 agc algorithm identifier that specifies the symmetric encryption 1005 1.1 agc algorithm used to encrypt the following Symmetrically Encrypted Data 1006 1.1 agc Packet. Then a two-octet checksum is appended, which is equal to the 1007 1.1 agc sum of the preceding session key octets, not including the algorithm 1008 1.1 agc identifier, modulo 65536. This value is then encoded as described in 1009 1.1 agc PKCS#1 block encoding EME-PKCS1-v1_5 in Section 7.2.1 of [RFC3447] to 1010 1.1 agc form the "m" value used in the formulas above. See Section 13.1 of 1011 1.1 agc this document for notes on OpenPGP's use of PKCS#1. 1012 1.1 agc 1013 1.1 agc Note that when an implementation forms several PKESKs with one 1014 1.1 agc session key, forming a message that can be decrypted by several keys, 1015 1.1 agc the implementation MUST make a new PKCS#1 encoding for each key. 1016 1.1 agc 1017 1.1 agc An implementation MAY accept or use a Key ID of zero as a "wild card" 1018 1.1 agc or "speculative" Key ID. In this case, the receiving implementation 1019 1.1 agc would try all available private keys, checking for a valid decrypted 1020 1.1 agc session key. This format helps reduce traffic analysis of messages. 1021 1.1 agc 1022 1.1 agc 1023 1.1 agc 1024 1.1 agc 1025 1.1 agc 1026 1.1 agc 1027 1.1 agc Callas, et al Standards Track [Page 18] 1028 1.1 agc 1030 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1031 1.1 agc 1032 1.1 agc 1033 1.1 agc 5.2. Signature Packet (Tag 2) 1034 1.1 agc 1035 1.1 agc A Signature packet describes a binding between some public key and 1036 1.1 agc some data. The most common signatures are a signature of a file or a 1037 1.1 agc block of text, and a signature that is a certification of a User ID. 1038 1.1 agc 1039 1.1 agc Two versions of Signature packets are defined. Version 3 provides 1040 1.1 agc basic signature information, while version 4 provides an expandable 1041 1.1 agc format with subpackets that can specify more information about the 1042 1.1 agc signature. PGP 2.6.x only accepts version 3 signatures. 1043 1.1 agc 1044 1.1 agc Implementations SHOULD accept V3 signatures. Implementations SHOULD 1045 1.1 agc generate V4 signatures. 1046 1.1 agc 1047 1.1 agc Note that if an implementation is creating an encrypted and signed 1048 1.1 agc message that is encrypted to a V3 key, it is reasonable to create a 1049 1.1 agc V3 signature. 1050 1.1 agc 1051 1.1 agc 5.2.1. Signature Types 1052 1.1 agc 1053 1.1 agc There are a number of possible meanings for a signature, which are 1054 1.1 agc indicated in a signature type octet in any given signature. Please 1055 1.1 agc note that the vagueness of these meanings is not a flaw, but a 1056 1.1 agc feature of the system. Because OpenPGP places final authority for 1057 1.1 agc validity upon the receiver of a signature, it may be that one 1058 1.1 agc signer's casual act might be more rigorous than some other 1059 1.1 agc authority's positive act. See Section 5.2.4, "Computing Signatures", 1060 1.1 agc for detailed information on how to compute and verify signatures of 1061 1.1 agc each type. 1062 1.1 agc 1063 1.1 agc These meanings are as follows: 1064 1.1 agc 1065 1.1 agc 0x00: Signature of a binary document. 1066 1.1 agc This means the signer owns it, created it, or certifies that it 1067 1.1 agc has not been modified. 1068 1.1 agc 1069 1.1 agc 0x01: Signature of a canonical text document. 1070 1.1 agc This means the signer owns it, created it, or certifies that it 1071 1.1 agc has not been modified. The signature is calculated over the text 1072 1.1 agc data with its line endings converted to <CR><LF>. 1073 1.1 agc 1074 1.1 agc 0x02: Standalone signature. 1075 1.1 agc This signature is a signature of only its own subpacket contents. 1076 1.1 agc It is calculated identically to a signature over a zero-length 1077 1.1 agc binary document. Note that it doesn't make sense to have a V3 1078 1.1 agc standalone signature. 1079 1.1 agc 1080 1.1 agc 1081 1.1 agc 1082 1.1 agc 1083 1.1 agc 1084 1.1 agc Callas, et al Standards Track [Page 19] 1085 1.1 agc 1087 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1088 1.1 agc 1089 1.1 agc 1090 1.1 agc 0x10: Generic certification of a User ID and Public-Key packet. 1091 1.1 agc The issuer of this certification does not make any particular 1092 1.1 agc assertion as to how well the certifier has checked that the owner 1093 1.1 agc of the key is in fact the person described by the User ID. 1094 1.1 agc 1095 1.1 agc 0x11: Persona certification of a User ID and Public-Key packet. 1096 1.1 agc The issuer of this certification has not done any verification of 1097 1.1 agc the claim that the owner of this key is the User ID specified. 1098 1.1 agc 1099 1.1 agc 0x12: Casual certification of a User ID and Public-Key packet. 1100 1.1 agc The issuer of this certification has done some casual 1101 1.1 agc verification of the claim of identity. 1102 1.1 agc 1103 1.1 agc 0x13: Positive certification of a User ID and Public-Key packet. 1104 1.1 agc The issuer of this certification has done substantial 1105 1.1 agc verification of the claim of identity. 1106 1.1 agc 1107 1.1 agc Most OpenPGP implementations make their "key signatures" as 0x10 1108 1.1 agc certifications. Some implementations can issue 0x11-0x13 1109 1.1 agc certifications, but few differentiate between the types. 1110 1.1 agc 1111 1.1 agc 0x18: Subkey Binding Signature 1112 1.1 agc This signature is a statement by the top-level signing key that 1113 1.1 agc indicates that it owns the subkey. This signature is calculated 1114 1.1 agc directly on the primary key and subkey, and not on any User ID or 1115 1.1 agc other packets. A signature that binds a signing subkey MUST have 1116 1.1 agc an Embedded Signature subpacket in this binding signature that 1117 1.1 agc contains a 0x19 signature made by the signing subkey on the 1118 1.1 agc primary key and subkey. 1119 1.1 agc 1120 1.1 agc 0x19: Primary Key Binding Signature 1121 1.1 agc This signature is a statement by a signing subkey, indicating 1122 1.1 agc that it is owned by the primary key and subkey. This signature 1123 1.1 agc is calculated the same way as a 0x18 signature: directly on the 1124 1.1 agc primary key and subkey, and not on any User ID or other packets. 1125 1.1 agc 1126 1.1 agc 0x1F: Signature directly on a key 1127 1.1 agc This signature is calculated directly on a key. It binds the 1128 1.1 agc information in the Signature subpackets to the key, and is 1129 1.1 agc appropriate to be used for subpackets that provide information 1130 1.1 agc about the key, such as the Revocation Key subpacket. It is also 1131 1.1 agc appropriate for statements that non-self certifiers want to make 1132 1.1 agc about the key itself, rather than the binding between a key and a 1133 1.1 agc name. 1134 1.1 agc 1135 1.1 agc 1136 1.1 agc 1137 1.1 agc 1138 1.1 agc 1139 1.1 agc 1140 1.1 agc 1141 1.1 agc Callas, et al Standards Track [Page 20] 1142 1.1 agc 1144 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1145 1.1 agc 1146 1.1 agc 1147 1.1 agc 0x20: Key revocation signature 1148 1.1 agc The signature is calculated directly on the key being revoked. A 1149 1.1 agc revoked key is not to be used. Only revocation signatures by the 1150 1.1 agc key being revoked, or by an authorized revocation key, should be 1151 1.1 agc considered valid revocation signatures. 1152 1.1 agc 1153 1.1 agc 0x28: Subkey revocation signature 1154 1.1 agc The signature is calculated directly on the subkey being revoked. 1155 1.1 agc A revoked subkey is not to be used. Only revocation signatures 1156 1.1 agc by the top-level signature key that is bound to this subkey, or 1157 1.1 agc by an authorized revocation key, should be considered valid 1158 1.1 agc revocation signatures. 1159 1.1 agc 1160 1.1 agc 0x30: Certification revocation signature 1161 1.1 agc This signature revokes an earlier User ID certification signature 1162 1.1 agc (signature class 0x10 through 0x13) or direct-key signature 1163 1.1 agc (0x1F). It should be issued by the same key that issued the 1164 1.1 agc revoked signature or an authorized revocation key. The signature 1165 1.1 agc is computed over the same data as the certificate that it 1166 1.1 agc revokes, and should have a later creation date than that 1167 1.1 agc certificate. 1168 1.1 agc 1169 1.1 agc 0x40: Timestamp signature. 1170 1.1 agc This signature is only meaningful for the timestamp contained in 1171 1.1 agc it. 1172 1.1 agc 1173 1.1 agc 0x50: Third-Party Confirmation signature. 1174 1.1 agc This signature is a signature over some other OpenPGP Signature 1175 1.1 agc packet(s). It is analogous to a notary seal on the signed data. 1176 1.1 agc A third-party signature SHOULD include Signature Target 1177 1.1 agc subpacket(s) to give easy identification. Note that we really do 1178 1.1 agc mean SHOULD. There are plausible uses for this (such as a blind 1179 1.1 agc party that only sees the signature, not the key or source 1180 1.1 agc document) that cannot include a target subpacket. 1181 1.1 agc 1182 1.1 agc 5.2.2. Version 3 Signature Packet Format 1183 1.1 agc 1184 1.1 agc The body of a version 3 Signature Packet contains: 1185 1.1 agc 1186 1.1 agc - One-octet version number (3). 1187 1.1 agc 1188 1.1 agc - One-octet length of following hashed material. MUST be 5. 1189 1.1 agc 1190 1.1 agc - One-octet signature type. 1191 1.1 agc 1192 1.1 agc - Four-octet creation time. 1193 1.1 agc 1194 1.1 agc - Eight-octet Key ID of signer. 1195 1.1 agc 1196 1.1 agc 1197 1.1 agc 1198 1.1 agc Callas, et al Standards Track [Page 21] 1199 1.1 agc 1201 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1202 1.1 agc 1203 1.1 agc 1204 1.1 agc - One-octet public-key algorithm. 1205 1.1 agc 1206 1.1 agc - One-octet hash algorithm. 1207 1.1 agc 1208 1.1 agc - Two-octet field holding left 16 bits of signed hash value. 1209 1.1 agc 1210 1.1 agc - One or more multiprecision integers comprising the signature. 1211 1.1 agc This portion is algorithm specific, as described below. 1212 1.1 agc 1213 1.1 agc The concatenation of the data to be signed, the signature type, and 1214 1.1 agc creation time from the Signature packet (5 additional octets) is 1215 1.1 agc hashed. The resulting hash value is used in the signature algorithm. 1216 1.1 agc The high 16 bits (first two octets) of the hash are included in the 1217 1.1 agc Signature packet to provide a quick test to reject some invalid 1218 1.1 agc signatures. 1219 1.1 agc 1220 1.1 agc Algorithm-Specific Fields for RSA signatures: 1221 1.1 agc 1222 1.1 agc - multiprecision integer (MPI) of RSA signature value m**d mod n. 1223 1.1 agc 1224 1.1 agc Algorithm-Specific Fields for DSA signatures: 1225 1.1 agc 1226 1.1 agc - MPI of DSA value r. 1227 1.1 agc 1228 1.1 agc - MPI of DSA value s. 1229 1.1 agc 1230 1.1 agc The signature calculation is based on a hash of the signed data, as 1231 1.1 agc described above. The details of the calculation are different for 1232 1.1 agc DSA signatures than for RSA signatures. 1233 1.1 agc 1234 1.1 agc With RSA signatures, the hash value is encoded using PKCS#1 encoding 1235 1.1 agc type EMSA-PKCS1-v1_5 as described in Section 9.2 of RFC 3447. This 1236 1.1 agc requires inserting the hash value as an octet string into an ASN.1 1237 1.1 agc structure. The object identifier for the type of hash being used is 1238 1.1 agc included in the structure. The hexadecimal representations for the 1239 1.1 agc currently defined hash algorithms are as follows: 1240 1.1 agc 1241 1.1 agc - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05 1242 1.1 agc 1243 1.1 agc - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01 1244 1.1 agc 1245 1.1 agc - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A 1246 1.1 agc 1247 1.1 agc - SHA224: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04 1248 1.1 agc 1249 1.1 agc - SHA256: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01 1250 1.1 agc 1251 1.1 agc - SHA384: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02 1252 1.1 agc 1253 1.1 agc 1254 1.1 agc 1255 1.1 agc Callas, et al Standards Track [Page 22] 1256 1.1 agc 1258 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1259 1.1 agc 1260 1.1 agc 1261 1.1 agc - SHA512: 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03 1262 1.1 agc 1263 1.1 agc The ASN.1 Object Identifiers (OIDs) are as follows: 1264 1.1 agc 1265 1.1 agc - MD5: 1.2.840.113549.2.5 1266 1.1 agc 1267 1.1 agc - RIPEMD-160: 1.3.36.3.2.1 1268 1.1 agc 1269 1.1 agc - SHA-1: 1.3.14.3.2.26 1270 1.1 agc 1271 1.1 agc - SHA224: 2.16.840.1.101.3.4.2.4 1272 1.1 agc 1273 1.1 agc - SHA256: 2.16.840.1.101.3.4.2.1 1274 1.1 agc 1275 1.1 agc - SHA384: 2.16.840.1.101.3.4.2.2 1276 1.1 agc 1277 1.1 agc - SHA512: 2.16.840.1.101.3.4.2.3 1278 1.1 agc 1279 1.1 agc The full hash prefixes for these are as follows: 1280 1.1 agc 1281 1.1 agc MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86, 1282 1.1 agc 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00, 1283 1.1 agc 0x04, 0x10 1284 1.1 agc 1285 1.1 agc RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24, 1286 1.1 agc 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14 1287 1.1 agc 1288 1.1 agc SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E, 1289 1.1 agc 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14 1290 1.1 agc 1291 1.1 agc SHA224: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1292 1.1 agc 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 0x05, 1293 1.1 agc 0x00, 0x04, 0x1C 1294 1.1 agc 1295 1.1 agc SHA256: 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1296 1.1 agc 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 0x05, 1297 1.1 agc 0x00, 0x04, 0x20 1298 1.1 agc 1299 1.1 agc SHA384: 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1300 1.1 agc 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 0x05, 1301 1.1 agc 0x00, 0x04, 0x30 1302 1.1 agc 1303 1.1 agc SHA512: 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 0x60, 0x86, 1304 1.1 agc 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 0x05, 1305 1.1 agc 0x00, 0x04, 0x40 1306 1.1 agc 1307 1.1 agc DSA signatures MUST use hashes that are equal in size to the number 1308 1.1 agc of bits of q, the group generated by the DSA key's generator value. 1309 1.1 agc 1310 1.1 agc 1311 1.1 agc 1312 1.1 agc Callas, et al Standards Track [Page 23] 1313 1.1 agc 1315 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1316 1.1 agc 1317 1.1 agc 1318 1.1 agc If the output size of the chosen hash is larger than the number of 1319 1.1 agc bits of q, the hash result is truncated to fit by taking the number 1320 1.1 agc of leftmost bits equal to the number of bits of q. This (possibly 1321 1.1 agc truncated) hash function result is treated as a number and used 1322 1.1 agc directly in the DSA signature algorithm. 1323 1.1 agc 1324 1.1 agc 5.2.3. Version 4 Signature Packet Format 1325 1.1 agc 1326 1.1 agc The body of a version 4 Signature packet contains: 1327 1.1 agc 1328 1.1 agc - One-octet version number (4). 1329 1.1 agc 1330 1.1 agc - One-octet signature type. 1331 1.1 agc 1332 1.1 agc - One-octet public-key algorithm. 1333 1.1 agc 1334 1.1 agc - One-octet hash algorithm. 1335 1.1 agc 1336 1.1 agc - Two-octet scalar octet count for following hashed subpacket data. 1337 1.1 agc Note that this is the length in octets of all of the hashed 1338 1.1 agc subpackets; a pointer incremented by this number will skip over 1339 1.1 agc the hashed subpackets. 1340 1.1 agc 1341 1.1 agc - Hashed subpacket data set (zero or more subpackets). 1342 1.1 agc 1343 1.1 agc - Two-octet scalar octet count for the following unhashed subpacket 1344 1.1 agc data. Note that this is the length in octets of all of the 1345 1.1 agc unhashed subpackets; a pointer incremented by this number will 1346 1.1 agc skip over the unhashed subpackets. 1347 1.1 agc 1348 1.1 agc - Unhashed subpacket data set (zero or more subpackets). 1349 1.1 agc 1350 1.1 agc - Two-octet field holding the left 16 bits of the signed hash 1351 1.1 agc value. 1352 1.1 agc 1353 1.1 agc - One or more multiprecision integers comprising the signature. 1354 1.1 agc This portion is algorithm specific, as described above. 1355 1.1 agc 1356 1.1 agc The concatenation of the data being signed and the signature data 1357 1.1 agc from the version number through the hashed subpacket data (inclusive) 1358 1.1 agc is hashed. The resulting hash value is what is signed. The left 16 1359 1.1 agc bits of the hash are included in the Signature packet to provide a 1360 1.1 agc quick test to reject some invalid signatures. 1361 1.1 agc 1362 1.1 agc There are two fields consisting of Signature subpackets. The first 1363 1.1 agc field is hashed with the rest of the signature data, while the second 1364 1.1 agc is unhashed. The second set of subpackets is not cryptographically 1365 1.1 agc 1366 1.1 agc 1367 1.1 agc 1368 1.1 agc 1369 1.1 agc Callas, et al Standards Track [Page 24] 1370 1.1 agc 1372 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1373 1.1 agc 1374 1.1 agc 1375 1.1 agc protected by the signature and should include only advisory 1376 1.1 agc information. 1377 1.1 agc 1378 1.1 agc The algorithms for converting the hash function result to a signature 1379 1.1 agc are described in a section below. 1380 1.1 agc 1381 1.1 agc 5.2.3.1. Signature Subpacket Specification 1382 1.1 agc 1383 1.1 agc A subpacket data set consists of zero or more Signature subpackets. 1384 1.1 agc In Signature packets, the subpacket data set is preceded by a two- 1385 1.1 agc octet scalar count of the length in octets of all the subpackets. A 1386 1.1 agc pointer incremented by this number will skip over the subpacket data 1387 1.1 agc set. 1388 1.1 agc 1389 1.1 agc Each subpacket consists of a subpacket header and a body. The header 1390 1.1 agc consists of: 1391 1.1 agc 1392 1.1 agc - the subpacket length (1, 2, or 5 octets), 1393 1.1 agc 1394 1.1 agc - the subpacket type (1 octet), 1395 1.1 agc 1396 1.1 agc and is followed by the subpacket-specific data. 1397 1.1 agc 1398 1.1 agc The length includes the type octet but not this length. Its format 1399 1.1 agc is similar to the "new" format packet header lengths, but cannot have 1400 1.1 agc Partial Body Lengths. That is: 1401 1.1 agc 1402 1.1 agc if the 1st octet < 192, then 1403 1.1 agc lengthOfLength = 1 1404 1.1 agc subpacketLen = 1st_octet 1405 1.1 agc 1406 1.1 agc if the 1st octet >= 192 and < 255, then 1407 1.1 agc lengthOfLength = 2 1408 1.1 agc subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192 1409 1.1 agc 1410 1.1 agc if the 1st octet = 255, then 1411 1.1 agc lengthOfLength = 5 1412 1.1 agc subpacket length = [four-octet scalar starting at 2nd_octet] 1413 1.1 agc 1414 1.1 agc The value of the subpacket type octet may be: 1415 1.1 agc 1416 1.1 agc 0 = Reserved 1417 1.1 agc 1 = Reserved 1418 1.1 agc 2 = Signature Creation Time 1419 1.1 agc 3 = Signature Expiration Time 1420 1.1 agc 4 = Exportable Certification 1421 1.1 agc 5 = Trust Signature 1422 1.1 agc 6 = Regular Expression 1423 1.1 agc 1424 1.1 agc 1425 1.1 agc 1426 1.1 agc Callas, et al Standards Track [Page 25] 1427 1.1 agc 1429 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1430 1.1 agc 1431 1.1 agc 1432 1.1 agc 7 = Revocable 1433 1.1 agc 8 = Reserved 1434 1.1 agc 9 = Key Expiration Time 1435 1.1 agc 10 = Placeholder for backward compatibility 1436 1.1 agc 11 = Preferred Symmetric Algorithms 1437 1.1 agc 12 = Revocation Key 1438 1.1 agc 13 = Reserved 1439 1.1 agc 14 = Reserved 1440 1.1 agc 15 = Reserved 1441 1.1 agc 16 = Issuer 1442 1.1 agc 17 = Reserved 1443 1.1 agc 18 = Reserved 1444 1.1 agc 19 = Reserved 1445 1.1 agc 20 = Notation Data 1446 1.1 agc 21 = Preferred Hash Algorithms 1447 1.1 agc 22 = Preferred Compression Algorithms 1448 1.1 agc 23 = Key Server Preferences 1449 1.1 agc 24 = Preferred Key Server 1450 1.1 agc 25 = Primary User ID 1451 1.1 agc 26 = Policy URI 1452 1.1 agc 27 = Key Flags 1453 1.1 agc 28 = Signer's User ID 1454 1.1 agc 29 = Reason for Revocation 1455 1.1 agc 30 = Features 1456 1.1 agc 31 = Signature Target 1457 1.1 agc 32 = Embedded Signature 1458 1.1 agc 100 To 110 = Private or experimental 1459 1.1 agc 1460 1.1 agc An implementation SHOULD ignore any subpacket of a type that it does 1461 1.1 agc not recognize. 1462 1.1 agc 1463 1.1 agc Bit 7 of the subpacket type is the "critical" bit. If set, it 1464 1.1 agc denotes that the subpacket is one that is critical for the evaluator 1465 1.1 agc of the signature to recognize. If a subpacket is encountered that is 1466 1.1 agc marked critical but is unknown to the evaluating software, the 1467 1.1 agc evaluator SHOULD consider the signature to be in error. 1468 1.1 agc 1469 1.1 agc An evaluator may "recognize" a subpacket, but not implement it. The 1470 1.1 agc purpose of the critical bit is to allow the signer to tell an 1471 1.1 agc evaluator that it would prefer a new, unknown feature to generate an 1472 1.1 agc error than be ignored. 1473 1.1 agc 1474 1.1 agc Implementations SHOULD implement the three preferred algorithm 1475 1.1 agc subpackets (11, 21, and 22), as well as the "Reason for Revocation" 1476 1.1 agc subpacket. Note, however, that if an implementation chooses not to 1477 1.1 agc implement some of the preferences, it is required to behave in a 1478 1.1 agc polite manner to respect the wishes of those users who do implement 1479 1.1 agc these preferences. 1480 1.1 agc 1481 1.1 agc 1482 1.1 agc 1483 1.1 agc Callas, et al Standards Track [Page 26] 1484 1.1 agc 1486 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1487 1.1 agc 1488 1.1 agc 1489 1.1 agc 5.2.3.2. Signature Subpacket Types 1490 1.1 agc 1491 1.1 agc A number of subpackets are currently defined. Some subpackets apply 1492 1.1 agc to the signature itself and some are attributes of the key. 1493 1.1 agc Subpackets that are found on a self-signature are placed on a 1494 1.1 agc certification made by the key itself. Note that a key may have more 1495 1.1 agc than one User ID, and thus may have more than one self-signature, and 1496 1.1 agc differing subpackets. 1497 1.1 agc 1498 1.1 agc A subpacket may be found either in the hashed or unhashed subpacket 1499 1.1 agc sections of a signature. If a subpacket is not hashed, then the 1500 1.1 agc information in it cannot be considered definitive because it is not 1501 1.1 agc part of the signature proper. 1502 1.1 agc 1503 1.1 agc 5.2.3.3. Notes on Self-Signatures 1504 1.1 agc 1505 1.1 agc A self-signature is a binding signature made by the key to which the 1506 1.1 agc signature refers. There are three types of self-signatures, the 1507 1.1 agc certification signatures (types 0x10-0x13), the direct-key signature 1508 1.1 agc (type 0x1F), and the subkey binding signature (type 0x18). For 1509 1.1 agc certification self-signatures, each User ID may have a self- 1510 1.1 agc signature, and thus different subpackets in those self-signatures. 1511 1.1 agc For subkey binding signatures, each subkey in fact has a self- 1512 1.1 agc signature. Subpackets that appear in a certification self-signature 1513 1.1 agc apply to the user name, and subpackets that appear in the subkey 1514 1.1 agc self-signature apply to the subkey. Lastly, subpackets on the 1515 1.1 agc direct-key signature apply to the entire key. 1516 1.1 agc 1517 1.1 agc Implementing software should interpret a self-signature's preference 1518 1.1 agc subpackets as narrowly as possible. For example, suppose a key has 1519 1.1 agc two user names, Alice and Bob. Suppose that Alice prefers the 1520 1.1 agc symmetric algorithm CAST5, and Bob prefers IDEA or TripleDES. If the 1521 1.1 agc software locates this key via Alice's name, then the preferred 1522 1.1 agc algorithm is CAST5; if software locates the key via Bob's name, then 1523 1.1 agc the preferred algorithm is IDEA. If the key is located by Key ID, 1524 1.1 agc the algorithm of the primary User ID of the key provides the 1525 1.1 agc preferred symmetric algorithm. 1526 1.1 agc 1527 1.1 agc Revoking a self-signature or allowing it to expire has a semantic 1528 1.1 agc meaning that varies with the signature type. Revoking the self- 1529 1.1 agc signature on a User ID effectively retires that user name. The 1530 1.1 agc self-signature is a statement, "My name X is tied to my signing key 1531 1.1 agc K" and is corroborated by other users' certifications. If another 1532 1.1 agc user revokes their certification, they are effectively saying that 1533 1.1 agc they no longer believe that name and that key are tied together. 1534 1.1 agc Similarly, if the users themselves revoke their self-signature, then 1535 1.1 agc the users no longer go by that name, no longer have that email 1536 1.1 agc address, etc. Revoking a binding signature effectively retires that 1537 1.1 agc 1538 1.1 agc 1539 1.1 agc 1540 1.1 agc Callas, et al Standards Track [Page 27] 1541 1.1 agc 1543 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1544 1.1 agc 1545 1.1 agc 1546 1.1 agc subkey. Revoking a direct-key signature cancels that signature. 1547 1.1 agc Please see the "Reason for Revocation" subpacket (Section 5.2.3.23) 1548 1.1 agc for more relevant detail. 1549 1.1 agc 1550 1.1 agc Since a self-signature contains important information about the key's 1551 1.1 agc use, an implementation SHOULD allow the user to rewrite the self- 1552 1.1 agc signature, and important information in it, such as preferences and 1553 1.1 agc key expiration. 1554 1.1 agc 1555 1.1 agc It is good practice to verify that a self-signature imported into an 1556 1.1 agc implementation doesn't advertise features that the implementation 1557 1.1 agc doesn't support, rewriting the signature as appropriate. 1558 1.1 agc 1559 1.1 agc An implementation that encounters multiple self-signatures on the 1560 1.1 agc same object may resolve the ambiguity in any way it sees fit, but it 1561 1.1 agc is RECOMMENDED that priority be given to the most recent self- 1562 1.1 agc signature. 1563 1.1 agc 1564 1.1 agc 5.2.3.4. Signature Creation Time 1565 1.1 agc 1566 1.1 agc (4-octet time field) 1567 1.1 agc 1568 1.1 agc The time the signature was made. 1569 1.1 agc 1570 1.1 agc MUST be present in the hashed area. 1571 1.1 agc 1572 1.1 agc 5.2.3.5. Issuer 1573 1.1 agc 1574 1.1 agc (8-octet Key ID) 1575 1.1 agc 1576 1.1 agc The OpenPGP Key ID of the key issuing the signature. 1577 1.1 agc 1578 1.1 agc 5.2.3.6. Key Expiration Time 1579 1.1 agc 1580 1.1 agc (4-octet time field) 1581 1.1 agc 1582 1.1 agc The validity period of the key. This is the number of seconds after 1583 1.1 agc the key creation time that the key expires. If this is not present 1584 1.1 agc or has a value of zero, the key never expires. This is found only on 1585 1.1 agc a self-signature. 1586 1.1 agc 1587 1.1 agc 5.2.3.7. Preferred Symmetric Algorithms 1588 1.1 agc 1589 1.1 agc (array of one-octet values) 1590 1.1 agc 1591 1.1 agc Symmetric algorithm numbers that indicate which algorithms the key 1592 1.1 agc holder prefers to use. The subpacket body is an ordered list of 1593 1.1 agc octets with the most preferred listed first. It is assumed that only 1594 1.1 agc 1595 1.1 agc 1596 1.1 agc 1597 1.1 agc Callas, et al Standards Track [Page 28] 1598 1.1 agc 1600 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1601 1.1 agc 1602 1.1 agc 1603 1.1 agc algorithms listed are supported by the recipient's software. 1604 1.1 agc Algorithm numbers are in Section 9. This is only found on a self- 1605 1.1 agc signature. 1606 1.1 agc 1607 1.1 agc 5.2.3.8. Preferred Hash Algorithms 1608 1.1 agc 1609 1.1 agc (array of one-octet values) 1610 1.1 agc 1611 1.1 agc Message digest algorithm numbers that indicate which algorithms the 1612 1.1 agc key holder prefers to receive. Like the preferred symmetric 1613 1.1 agc algorithms, the list is ordered. Algorithm numbers are in Section 9. 1614 1.1 agc This is only found on a self-signature. 1615 1.1 agc 1616 1.1 agc 5.2.3.9. Preferred Compression Algorithms 1617 1.1 agc 1618 1.1 agc (array of one-octet values) 1619 1.1 agc 1620 1.1 agc Compression algorithm numbers that indicate which algorithms the key 1621 1.1 agc holder prefers to use. Like the preferred symmetric algorithms, the 1622 1.1 agc list is ordered. Algorithm numbers are in Section 9. If this 1623 1.1 agc subpacket is not included, ZIP is preferred. A zero denotes that 1624 1.1 agc uncompressed data is preferred; the key holder's software might have 1625 1.1 agc no compression software in that implementation. This is only found 1626 1.1 agc on a self-signature. 1627 1.1 agc 1628 1.1 agc 5.2.3.10. Signature Expiration Time 1629 1.1 agc 1630 1.1 agc (4-octet time field) 1631 1.1 agc 1632 1.1 agc The validity period of the signature. This is the number of seconds 1633 1.1 agc after the signature creation time that the signature expires. If 1634 1.1 agc this is not present or has a value of zero, it never expires. 1635 1.1 agc 1636 1.1 agc 5.2.3.11. Exportable Certification 1637 1.1 agc 1638 1.1 agc (1 octet of exportability, 0 for not, 1 for exportable) 1639 1.1 agc 1640 1.1 agc This subpacket denotes whether a certification signature is 1641 1.1 agc "exportable", to be used by other users than the signature's issuer. 1642 1.1 agc The packet body contains a Boolean flag indicating whether the 1643 1.1 agc signature is exportable. If this packet is not present, the 1644 1.1 agc certification is exportable; it is equivalent to a flag containing a 1645 1.1 agc 1. 1646 1.1 agc 1647 1.1 agc Non-exportable, or "local", certifications are signatures made by a 1648 1.1 agc user to mark a key as valid within that user's implementation only. 1649 1.1 agc 1650 1.1 agc 1651 1.1 agc 1652 1.1 agc 1653 1.1 agc 1654 1.1 agc Callas, et al Standards Track [Page 29] 1655 1.1 agc 1657 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1658 1.1 agc 1659 1.1 agc 1660 1.1 agc Thus, when an implementation prepares a user's copy of a key for 1661 1.1 agc transport to another user (this is the process of "exporting" the 1662 1.1 agc key), any local certification signatures are deleted from the key. 1663 1.1 agc 1664 1.1 agc The receiver of a transported key "imports" it, and likewise trims 1665 1.1 agc any local certifications. In normal operation, there won't be any, 1666 1.1 agc assuming the import is performed on an exported key. However, there 1667 1.1 agc are instances where this can reasonably happen. For example, if an 1668 1.1 agc implementation allows keys to be imported from a key database in 1669 1.1 agc addition to an exported key, then this situation can arise. 1670 1.1 agc 1671 1.1 agc Some implementations do not represent the interest of a single user 1672 1.1 agc (for example, a key server). Such implementations always trim local 1673 1.1 agc certifications from any key they handle. 1674 1.1 agc 1675 1.1 agc 5.2.3.12. Revocable 1676 1.1 agc 1677 1.1 agc (1 octet of revocability, 0 for not, 1 for revocable) 1678 1.1 agc 1679 1.1 agc Signature's revocability status. The packet body contains a Boolean 1680 1.1 agc flag indicating whether the signature is revocable. Signatures that 1681 1.1 agc are not revocable have any later revocation signatures ignored. They 1682 1.1 agc represent a commitment by the signer that he cannot revoke his 1683 1.1 agc signature for the life of his key. If this packet is not present, 1684 1.1 agc the signature is revocable. 1685 1.1 agc 1686 1.1 agc 5.2.3.13. Trust Signature 1687 1.1 agc 1688 1.1 agc (1 octet "level" (depth), 1 octet of trust amount) 1689 1.1 agc 1690 1.1 agc Signer asserts that the key is not only valid but also trustworthy at 1691 1.1 agc the specified level. Level 0 has the same meaning as an ordinary 1692 1.1 agc validity signature. Level 1 means that the signed key is asserted to 1693 1.1 agc be a valid trusted introducer, with the 2nd octet of the body 1694 1.1 agc specifying the degree of trust. Level 2 means that the signed key is 1695 1.1 agc asserted to be trusted to issue level 1 trust signatures, i.e., that 1696 1.1 agc it is a "meta introducer". Generally, a level n trust signature 1697 1.1 agc asserts that a key is trusted to issue level n-1 trust signatures. 1698 1.1 agc The trust amount is in a range from 0-255, interpreted such that 1699 1.1 agc values less than 120 indicate partial trust and values of 120 or 1700 1.1 agc greater indicate complete trust. Implementations SHOULD emit values 1701 1.1 agc of 60 for partial trust and 120 for complete trust. 1702 1.1 agc 1703 1.1 agc 1704 1.1 agc 1705 1.1 agc 1706 1.1 agc 1707 1.1 agc 1708 1.1 agc 1709 1.1 agc 1710 1.1 agc 1711 1.1 agc Callas, et al Standards Track [Page 30] 1712 1.1 agc 1714 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1715 1.1 agc 1716 1.1 agc 1717 1.1 agc 5.2.3.14. Regular Expression 1718 1.1 agc 1719 1.1 agc (null-terminated regular expression) 1720 1.1 agc 1721 1.1 agc Used in conjunction with trust Signature packets (of level > 0) to 1722 1.1 agc limit the scope of trust that is extended. Only signatures by the 1723 1.1 agc target key on User IDs that match the regular expression in the body 1724 1.1 agc of this packet have trust extended by the trust Signature subpacket. 1725 1.1 agc The regular expression uses the same syntax as the Henry Spencer's 1726 1.1 agc "almost public domain" regular expression [REGEX] package. A 1727 1.1 agc description of the syntax is found in Section 8 below. 1728 1.1 agc 1729 1.1 agc 5.2.3.15. Revocation Key 1730 1.1 agc 1731 1.1 agc (1 octet of class, 1 octet of public-key algorithm ID, 20 octets of 1732 1.1 agc fingerprint) 1733 1.1 agc 1734 1.1 agc Authorizes the specified key to issue revocation signatures for this 1735 1.1 agc key. Class octet must have bit 0x80 set. If the bit 0x40 is set, 1736 1.1 agc then this means that the revocation information is sensitive. Other 1737 1.1 agc bits are for future expansion to other kinds of authorizations. This 1738 1.1 agc is found on a self-signature. 1739 1.1 agc 1740 1.1 agc If the "sensitive" flag is set, the keyholder feels this subpacket 1741 1.1 agc contains private trust information that describes a real-world 1742 1.1 agc sensitive relationship. If this flag is set, implementations SHOULD 1743 1.1 agc NOT export this signature to other users except in cases where the 1744 1.1 agc data needs to be available: when the signature is being sent to the 1745 1.1 agc designated revoker, or when it is accompanied by a revocation 1746 1.1 agc signature from that revoker. Note that it may be appropriate to 1747 1.1 agc isolate this subpacket within a separate signature so that it is not 1748 1.1 agc combined with other subpackets that need to be exported. 1749 1.1 agc 1750 1.1 agc 5.2.3.16. Notation Data 1751 1.1 agc 1752 1.1 agc (4 octets of flags, 2 octets of name length (M), 1753 1.1 agc 2 octets of value length (N), 1754 1.1 agc M octets of name data, 1755 1.1 agc N octets of value data) 1756 1.1 agc 1757 1.1 agc This subpacket describes a "notation" on the signature that the 1758 1.1 agc issuer wishes to make. The notation has a name and a value, each of 1759 1.1 agc which are strings of octets. There may be more than one notation in 1760 1.1 agc a signature. Notations can be used for any extension the issuer of 1761 1.1 agc the signature cares to make. The "flags" field holds four octets of 1762 1.1 agc flags. 1763 1.1 agc 1764 1.1 agc 1765 1.1 agc 1766 1.1 agc 1767 1.1 agc 1768 1.1 agc Callas, et al Standards Track [Page 31] 1769 1.1 agc 1771 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1772 1.1 agc 1773 1.1 agc 1774 1.1 agc All undefined flags MUST be zero. Defined flags are as follows: 1775 1.1 agc 1776 1.1 agc First octet: 0x80 = human-readable. This note value is text. 1777 1.1 agc Other octets: none. 1778 1.1 agc 1779 1.1 agc Notation names are arbitrary strings encoded in UTF-8. They reside 1780 1.1 agc in two namespaces: The IETF namespace and the user namespace. 1781 1.1 agc 1782 1.1 agc The IETF namespace is registered with IANA. These names MUST NOT 1783 1.1 agc contain the "@" character (0x40). This is a tag for the user 1784 1.1 agc namespace. 1785 1.1 agc 1786 1.1 agc Names in the user namespace consist of a UTF-8 string tag followed by 1787 1.1 agc "@" followed by a DNS domain name. Note that the tag MUST NOT 1788 1.1 agc contain an "@" character. For example, the "sample" tag used by 1789 1.1 agc Example Corporation could be "sample (a] example.com". 1790 1.1 agc 1791 1.1 agc Names in a user space are owned and controlled by the owners of that 1792 1.1 agc domain. Obviously, it's bad form to create a new name in a DNS space 1793 1.1 agc that you don't own. 1794 1.1 agc 1795 1.1 agc Since the user namespace is in the form of an email address, 1796 1.1 agc implementers MAY wish to arrange for that address to reach a person 1797 1.1 agc who can be consulted about the use of the named tag. Note that due 1798 1.1 agc to UTF-8 encoding, not all valid user space name tags are valid email 1799 1.1 agc addresses. 1800 1.1 agc 1801 1.1 agc If there is a critical notation, the criticality applies to that 1802 1.1 agc specific notation and not to notations in general. 1803 1.1 agc 1804 1.1 agc 5.2.3.17. Key Server Preferences 1805 1.1 agc 1806 1.1 agc (N octets of flags) 1807 1.1 agc 1808 1.1 agc This is a list of one-bit flags that indicate preferences that the 1809 1.1 agc key holder has about how the key is handled on a key server. All 1810 1.1 agc undefined flags MUST be zero. 1811 1.1 agc 1812 1.1 agc First octet: 0x80 = No-modify 1813 1.1 agc the key holder requests that this key only be modified or updated 1814 1.1 agc by the key holder or an administrator of the key server. 1815 1.1 agc 1816 1.1 agc This is found only on a self-signature. 1817 1.1 agc 1818 1.1 agc 1819 1.1 agc 1820 1.1 agc 1821 1.1 agc 1822 1.1 agc 1823 1.1 agc 1824 1.1 agc 1825 1.1 agc Callas, et al Standards Track [Page 32] 1826 1.1 agc 1828 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1829 1.1 agc 1830 1.1 agc 1831 1.1 agc 5.2.3.18. Preferred Key Server 1832 1.1 agc 1833 1.1 agc (String) 1834 1.1 agc 1835 1.1 agc This is a URI of a key server that the key holder prefers be used for 1836 1.1 agc updates. Note that keys with multiple User IDs can have a preferred 1837 1.1 agc key server for each User ID. Note also that since this is a URI, the 1838 1.1 agc key server can actually be a copy of the key retrieved by ftp, http, 1839 1.1 agc finger, etc. 1840 1.1 agc 1841 1.1 agc 5.2.3.19. Primary User ID 1842 1.1 agc 1843 1.1 agc (1 octet, Boolean) 1844 1.1 agc 1845 1.1 agc This is a flag in a User ID's self-signature that states whether this 1846 1.1 agc User ID is the main User ID for this key. It is reasonable for an 1847 1.1 agc implementation to resolve ambiguities in preferences, etc. by 1848 1.1 agc referring to the primary User ID. If this flag is absent, its value 1849 1.1 agc is zero. If more than one User ID in a key is marked as primary, the 1850 1.1 agc implementation may resolve the ambiguity in any way it sees fit, but 1851 1.1 agc it is RECOMMENDED that priority be given to the User ID with the most 1852 1.1 agc recent self-signature. 1853 1.1 agc 1854 1.1 agc When appearing on a self-signature on a User ID packet, this 1855 1.1 agc subpacket applies only to User ID packets. When appearing on a 1856 1.1 agc self-signature on a User Attribute packet, this subpacket applies 1857 1.1 agc only to User Attribute packets. That is to say, there are two 1858 1.1 agc different and independent "primaries" -- one for User IDs, and one 1859 1.1 agc for User Attributes. 1860 1.1 agc 1861 1.1 agc 5.2.3.20. Policy URI 1862 1.1 agc 1863 1.1 agc (String) 1864 1.1 agc 1865 1.1 agc This subpacket contains a URI of a document that describes the policy 1866 1.1 agc under which the signature was issued. 1867 1.1 agc 1868 1.1 agc 5.2.3.21. Key Flags 1869 1.1 agc 1870 1.1 agc (N octets of flags) 1871 1.1 agc 1872 1.1 agc This subpacket contains a list of binary flags that hold information 1873 1.1 agc about a key. It is a string of octets, and an implementation MUST 1874 1.1 agc NOT assume a fixed size. This is so it can grow over time. If a 1875 1.1 agc list is shorter than an implementation expects, the unstated flags 1876 1.1 agc are considered to be zero. The defined flags are as follows: 1877 1.1 agc 1878 1.1 agc 1879 1.1 agc 1880 1.1 agc 1881 1.1 agc 1882 1.1 agc Callas, et al Standards Track [Page 33] 1883 1.1 agc 1885 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1886 1.1 agc 1887 1.1 agc 1888 1.1 agc First octet: 1889 1.1 agc 1890 1.1 agc 0x01 - This key may be used to certify other keys. 1891 1.1 agc 1892 1.1 agc 0x02 - This key may be used to sign data. 1893 1.1 agc 1894 1.1 agc 0x04 - This key may be used to encrypt communications. 1895 1.1 agc 1896 1.1 agc 0x08 - This key may be used to encrypt storage. 1897 1.1 agc 1898 1.1 agc 0x10 - The private component of this key may have been split 1899 1.1 agc by a secret-sharing mechanism. 1900 1.1 agc 1901 1.1 agc 0x20 - This key may be used for authentication. 1902 1.1 agc 1903 1.1 agc 0x80 - The private component of this key may be in the 1904 1.1 agc possession of more than one person. 1905 1.1 agc 1906 1.1 agc Usage notes: 1907 1.1 agc 1908 1.1 agc The flags in this packet may appear in self-signatures or in 1909 1.1 agc certification signatures. They mean different things depending on 1910 1.1 agc who is making the statement -- for example, a certification signature 1911 1.1 agc that has the "sign data" flag is stating that the certification is 1912 1.1 agc for that use. On the other hand, the "communications encryption" 1913 1.1 agc flag in a self-signature is stating a preference that a given key be 1914 1.1 agc used for communications. Note however, that it is a thorny issue to 1915 1.1 agc determine what is "communications" and what is "storage". This 1916 1.1 agc decision is left wholly up to the implementation; the authors of this 1917 1.1 agc document do not claim any special wisdom on the issue and realize 1918 1.1 agc that accepted opinion may change. 1919 1.1 agc 1920 1.1 agc The "split key" (0x10) and "group key" (0x80) flags are placed on a 1921 1.1 agc self-signature only; they are meaningless on a certification 1922 1.1 agc signature. They SHOULD be placed only on a direct-key signature 1923 1.1 agc (type 0x1F) or a subkey signature (type 0x18), one that refers to the 1924 1.1 agc key the flag applies to. 1925 1.1 agc 1926 1.1 agc 5.2.3.22. Signer's User ID 1927 1.1 agc 1928 1.1 agc (String) 1929 1.1 agc 1930 1.1 agc This subpacket allows a keyholder to state which User ID is 1931 1.1 agc responsible for the signing. Many keyholders use a single key for 1932 1.1 agc different purposes, such as business communications as well as 1933 1.1 agc personal communications. This subpacket allows such a keyholder to 1934 1.1 agc state which of their roles is making a signature. 1935 1.1 agc 1936 1.1 agc 1937 1.1 agc 1938 1.1 agc 1939 1.1 agc Callas, et al Standards Track [Page 34] 1940 1.1 agc 1942 1.1 agc RFC 4880 OpenPGP Message Format November 2007 1943 1.1 agc 1944 1.1 agc 1945 1.1 agc This subpacket is not appropriate to use to refer to a User Attribute 1946 1.1 agc packet. 1947 1.1 agc 1948 1.1 agc 5.2.3.23. Reason for Revocation 1949 1.1 agc 1950 1.1 agc (1 octet of revocation code, N octets of reason string) 1951 1.1 agc 1952 1.1 agc This subpacket is used only in key revocation and certification 1953 1.1 agc revocation signatures. It describes the reason why the key or 1954 1.1 agc certificate was revoked. 1955 1.1 agc 1956 1.1 agc The first octet contains a machine-readable code that denotes the 1957 1.1 agc reason for the revocation: 1958 1.1 agc 1959 1.1 agc 0 - No reason specified (key revocations or cert revocations) 1960 1.1 agc 1 - Key is superseded (key revocations) 1961 1.1 agc 2 - Key material has been compromised (key revocations) 1962 1.1 agc 3 - Key is retired and no longer used (key revocations) 1963 1.1 agc 32 - User ID information is no longer valid (cert revocations) 1964 1.1 agc 100-110 - Private Use 1965 1.1 agc 1966 1.1 agc Following the revocation code is a string of octets that gives 1967 1.1 agc information about the Reason for Revocation in human-readable form 1968 1.1 agc (UTF-8). The string may be null, that is, of zero length. The 1969 1.1 agc length of the subpacket is the length of the reason string plus one. 1970 1.1 agc An implementation SHOULD implement this subpacket, include it in all 1971 1.1 agc revocation signatures, and interpret revocations appropriately. 1972 1.1 agc There are important semantic differences between the reasons, and 1973 1.1 agc there are thus important reasons for revoking signatures. 1974 1.1 agc 1975 1.1 agc If a key has been revoked because of a compromise, all signatures 1976 1.1 agc created by that key are suspect. However, if it was merely 1977 1.1 agc superseded or retired, old signatures are still valid. If the 1978 1.1 agc revoked signature is the self-signature for certifying a User ID, a 1979 1.1 agc revocation denotes that that user name is no longer in use. Such a 1980 1.1 agc revocation SHOULD include a 0x20 code. 1981 1.1 agc 1982 1.1 agc Note that any signature may be revoked, including a certification on 1983 1.1 agc some other person's key. There are many good reasons for revoking a 1984 1.1 agc certification signature, such as the case where the keyholder leaves 1985 1.1 agc the employ of a business with an email address. A revoked 1986 1.1 agc certification is no longer a part of validity calculations. 1987 1.1 agc 1988 1.1 agc 1989 1.1 agc 1990 1.1 agc 1991 1.1 agc 1992 1.1 agc 1993 1.1 agc 1994 1.1 agc 1995 1.1 agc 1996 1.1 agc Callas, et al Standards Track [Page 35] 1997 1.1 agc 1999 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2000 1.1 agc 2001 1.1 agc 2002 1.1 agc 5.2.3.24. Features 2003 1.1 agc 2004 1.1 agc (N octets of flags) 2005 1.1 agc 2006 1.1 agc The Features subpacket denotes which advanced OpenPGP features a 2007 1.1 agc user's implementation supports. This is so that as features are 2008 1.1 agc added to OpenPGP that cannot be backwards-compatible, a user can 2009 1.1 agc state that they can use that feature. The flags are single bits that 2010 1.1 agc indicate that a given feature is supported. 2011 1.1 agc 2012 1.1 agc This subpacket is similar to a preferences subpacket, and only 2013 1.1 agc appears in a self-signature. 2014 1.1 agc 2015 1.1 agc An implementation SHOULD NOT use a feature listed when sending to a 2016 1.1 agc user who does not state that they can use it. 2017 1.1 agc 2018 1.1 agc Defined features are as follows: 2019 1.1 agc 2020 1.1 agc First octet: 2021 1.1 agc 2022 1.1 agc 0x01 - Modification Detection (packets 18 and 19) 2023 1.1 agc 2024 1.1 agc If an implementation implements any of the defined features, it 2025 1.1 agc SHOULD implement the Features subpacket, too. 2026 1.1 agc 2027 1.1 agc An implementation may freely infer features from other suitable 2028 1.1 agc implementation-dependent mechanisms. 2029 1.1 agc 2030 1.1 agc 5.2.3.25. Signature Target 2031 1.1 agc 2032 1.1 agc (1 octet public-key algorithm, 1 octet hash algorithm, N octets hash) 2033 1.1 agc 2034 1.1 agc This subpacket identifies a specific target signature to which a 2035 1.1 agc signature refers. For revocation signatures, this subpacket 2036 1.1 agc provides explicit designation of which signature is being revoked. 2037 1.1 agc For a third-party or timestamp signature, this designates what 2038 1.1 agc signature is signed. All arguments are an identifier of that target 2039 1.1 agc signature. 2040 1.1 agc 2041 1.1 agc The N octets of hash data MUST be the size of the hash of the 2042 1.1 agc signature. For example, a target signature with a SHA-1 hash MUST 2043 1.1 agc have 20 octets of hash data. 2044 1.1 agc 2045 1.1 agc 2046 1.1 agc 2047 1.1 agc 2048 1.1 agc 2049 1.1 agc 2050 1.1 agc 2051 1.1 agc 2052 1.1 agc 2053 1.1 agc Callas, et al Standards Track [Page 36] 2054 1.1 agc 2056 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2057 1.1 agc 2058 1.1 agc 2059 1.1 agc 5.2.3.26. Embedded Signature 2060 1.1 agc 2061 1.1 agc (1 signature packet body) 2062 1.1 agc 2063 1.1 agc This subpacket contains a complete Signature packet body as 2064 1.1 agc specified in Section 5.2 above. It is useful when one signature 2065 1.1 agc needs to refer to, or be incorporated in, another signature. 2066 1.1 agc 2067 1.1 agc 5.2.4. Computing Signatures 2068 1.1 agc 2069 1.1 agc All signatures are formed by producing a hash over the signature 2070 1.1 agc data, and then using the resulting hash in the signature algorithm. 2071 1.1 agc 2072 1.1 agc For binary document signatures (type 0x00), the document data is 2073 1.1 agc hashed directly. For text document signatures (type 0x01), the 2074 1.1 agc document is canonicalized by converting line endings to <CR><LF>, 2075 1.1 agc and the resulting data is hashed. 2076 1.1 agc 2077 1.1 agc When a signature is made over a key, the hash data starts with the 2078 1.1 agc octet 0x99, followed by a two-octet length of the key, and then body 2079 1.1 agc of the key packet. (Note that this is an old-style packet header for 2080 1.1 agc a key packet with two-octet length.) A subkey binding signature 2081 1.1 agc (type 0x18) or primary key binding signature (type 0x19) then hashes 2082 1.1 agc the subkey using the same format as the main key (also using 0x99 as 2083 1.1 agc the first octet). Key revocation signatures (types 0x20 and 0x28) 2084 1.1 agc hash only the key being revoked. 2085 1.1 agc 2086 1.1 agc A certification signature (type 0x10 through 0x13) hashes the User 2087 1.1 agc ID being bound to the key into the hash context after the above 2088 1.1 agc data. A V3 certification hashes the contents of the User ID or 2089 1.1 agc attribute packet packet, without any header. A V4 certification 2090 1.1 agc hashes the constant 0xB4 for User ID certifications or the constant 2091 1.1 agc 0xD1 for User Attribute certifications, followed by a four-octet 2092 1.1 agc number giving the length of the User ID or User Attribute data, and 2093 1.1 agc then the User ID or User Attribute data. 2094 1.1 agc 2095 1.1 agc When a signature is made over a Signature packet (type 0x50), the 2096 1.1 agc hash data starts with the octet 0x88, followed by the four-octet 2097 1.1 agc length of the signature, and then the body of the Signature packet. 2098 1.1 agc (Note that this is an old-style packet header for a Signature packet 2099 1.1 agc with the length-of-length set to zero.) The unhashed subpacket data 2100 1.1 agc of the Signature packet being hashed is not included in the hash, and 2101 1.1 agc the unhashed subpacket data length value is set to zero. 2102 1.1 agc 2103 1.1 agc Once the data body is hashed, then a trailer is hashed. A V3 2104 1.1 agc signature hashes five octets of the packet body, starting from the 2105 1.1 agc signature type field. This data is the signature type, followed by 2106 1.1 agc the four-octet signature time. A V4 signature hashes the packet body 2107 1.1 agc 2108 1.1 agc 2109 1.1 agc 2110 1.1 agc Callas, et al Standards Track [Page 37] 2111 1.1 agc 2113 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2114 1.1 agc 2115 1.1 agc 2116 1.1 agc starting from its first field, the version number, through the end 2117 1.1 agc of the hashed subpacket data. Thus, the fields hashed are the 2118 1.1 agc signature version, the signature type, the public-key algorithm, the 2119 1.1 agc hash algorithm, the hashed subpacket length, and the hashed 2120 1.1 agc subpacket body. 2121 1.1 agc 2122 1.1 agc V4 signatures also hash in a final trailer of six octets: the 2123 1.1 agc version of the Signature packet, i.e., 0x04; 0xFF; and a four-octet, 2124 1.1 agc big-endian number that is the length of the hashed data from the 2125 1.1 agc Signature packet (note that this number does not include these final 2126 1.1 agc six octets). 2127 1.1 agc 2128 1.1 agc After all this has been hashed in a single hash context, the 2129 1.1 agc resulting hash field is used in the signature algorithm and placed 2130 1.1 agc at the end of the Signature packet. 2131 1.1 agc 2132 1.1 agc 5.2.4.1. Subpacket Hints 2133 1.1 agc 2134 1.1 agc It is certainly possible for a signature to contain conflicting 2135 1.1 agc information in subpackets. For example, a signature may contain 2136 1.1 agc multiple copies of a preference or multiple expiration times. In 2137 1.1 agc most cases, an implementation SHOULD use the last subpacket in the 2138 1.1 agc signature, but MAY use any conflict resolution scheme that makes 2139 1.1 agc more sense. Please note that we are intentionally leaving conflict 2140 1.1 agc resolution to the implementer; most conflicts are simply syntax 2141 1.1 agc errors, and the wishy-washy language here allows a receiver to be 2142 1.1 agc generous in what they accept, while putting pressure on a creator to 2143 1.1 agc be stingy in what they generate. 2144 1.1 agc 2145 1.1 agc Some apparent conflicts may actually make sense -- for example, 2146 1.1 agc suppose a keyholder has a V3 key and a V4 key that share the same 2147 1.1 agc RSA key material. Either of these keys can verify a signature 2148 1.1 agc created by the other, and it may be reasonable for a signature to 2149 1.1 agc contain an issuer subpacket for each key, as a way of explicitly 2150 1.1 agc tying those keys to the signature. 2151 1.1 agc 2152 1.1 agc 5.3. Symmetric-Key Encrypted Session Key Packets (Tag 3) 2153 1.1 agc 2154 1.1 agc The Symmetric-Key Encrypted Session Key packet holds the 2155 1.1 agc symmetric-key encryption of a session key used to encrypt a message. 2156 1.1 agc Zero or more Public-Key Encrypted Session Key packets and/or 2157 1.1 agc Symmetric-Key Encrypted Session Key packets may precede a 2158 1.1 agc Symmetrically Encrypted Data packet that holds an encrypted message. 2159 1.1 agc The message is encrypted with a session key, and the session key is 2160 1.1 agc itself encrypted and stored in the Encrypted Session Key packet or 2161 1.1 agc the Symmetric-Key Encrypted Session Key packet. 2162 1.1 agc 2163 1.1 agc 2164 1.1 agc 2165 1.1 agc 2166 1.1 agc 2167 1.1 agc Callas, et al Standards Track [Page 38] 2168 1.1 agc 2170 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2171 1.1 agc 2172 1.1 agc 2173 1.1 agc If the Symmetrically Encrypted Data packet is preceded by one or 2174 1.1 agc more Symmetric-Key Encrypted Session Key packets, each specifies a 2175 1.1 agc passphrase that may be used to decrypt the message. This allows a 2176 1.1 agc message to be encrypted to a number of public keys, and also to one 2177 1.1 agc or more passphrases. This packet type is new and is not generated 2178 1.1 agc by PGP 2.x or PGP 5.0. 2179 1.1 agc 2180 1.1 agc The body of this packet consists of: 2181 1.1 agc 2182 1.1 agc - A one-octet version number. The only currently defined version 2183 1.1 agc is 4. 2184 1.1 agc 2185 1.1 agc - A one-octet number describing the symmetric algorithm used. 2186 1.1 agc 2187 1.1 agc - A string-to-key (S2K) specifier, length as defined above. 2188 1.1 agc 2189 1.1 agc - Optionally, the encrypted session key itself, which is decrypted 2190 1.1 agc with the string-to-key object. 2191 1.1 agc 2192 1.1 agc If the encrypted session key is not present (which can be detected 2193 1.1 agc on the basis of packet length and S2K specifier size), then the S2K 2194 1.1 agc algorithm applied to the passphrase produces the session key for 2195 1.1 agc decrypting the file, using the symmetric cipher algorithm from the 2196 1.1 agc Symmetric-Key Encrypted Session Key packet. 2197 1.1 agc 2198 1.1 agc If the encrypted session key is present, the result of applying the 2199 1.1 agc S2K algorithm to the passphrase is used to decrypt just that 2200 1.1 agc encrypted session key field, using CFB mode with an IV of all zeros. 2201 1.1 agc The decryption result consists of a one-octet algorithm identifier 2202 1.1 agc that specifies the symmetric-key encryption algorithm used to 2203 1.1 agc encrypt the following Symmetrically Encrypted Data packet, followed 2204 1.1 agc by the session key octets themselves. 2205 1.1 agc 2206 1.1 agc Note: because an all-zero IV is used for this decryption, the S2K 2207 1.1 agc specifier MUST use a salt value, either a Salted S2K or an 2208 1.1 agc Iterated-Salted S2K. The salt value will ensure that the decryption 2209 1.1 agc key is not repeated even if the passphrase is reused. 2210 1.1 agc 2211 1.1 agc 5.4. One-Pass Signature Packets (Tag 4) 2212 1.1 agc 2213 1.1 agc The One-Pass Signature packet precedes the signed data and contains 2214 1.1 agc enough information to allow the receiver to begin calculating any 2215 1.1 agc hashes needed to verify the signature. It allows the Signature 2216 1.1 agc packet to be placed at the end of the message, so that the signer 2217 1.1 agc can compute the entire signed message in one pass. 2218 1.1 agc 2219 1.1 agc A One-Pass Signature does not interoperate with PGP 2.6.x or 2220 1.1 agc earlier. 2221 1.1 agc 2222 1.1 agc 2223 1.1 agc 2224 1.1 agc Callas, et al Standards Track [Page 39] 2225 1.1 agc 2227 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2228 1.1 agc 2229 1.1 agc 2230 1.1 agc The body of this packet consists of: 2231 1.1 agc 2232 1.1 agc - A one-octet version number. The current version is 3. 2233 1.1 agc 2234 1.1 agc - A one-octet signature type. Signature types are described in 2235 1.1 agc Section 5.2.1. 2236 1.1 agc 2237 1.1 agc - A one-octet number describing the hash algorithm used. 2238 1.1 agc 2239 1.1 agc - A one-octet number describing the public-key algorithm used. 2240 1.1 agc 2241 1.1 agc - An eight-octet number holding the Key ID of the signing key. 2242 1.1 agc 2243 1.1 agc - A one-octet number holding a flag showing whether the signature 2244 1.1 agc is nested. A zero value indicates that the next packet is 2245 1.1 agc another One-Pass Signature packet that describes another 2246 1.1 agc signature to be applied to the same message data. 2247 1.1 agc 2248 1.1 agc Note that if a message contains more than one one-pass signature, 2249 1.1 agc then the Signature packets bracket the message; that is, the first 2250 1.1 agc Signature packet after the message corresponds to the last one-pass 2251 1.1 agc packet and the final Signature packet corresponds to the first 2252 1.1 agc one-pass packet. 2253 1.1 agc 2254 1.1 agc 5.5. Key Material Packet 2255 1.1 agc 2256 1.1 agc A key material packet contains all the information about a public or 2257 1.1 agc private key. There are four variants of this packet type, and two 2258 1.1 agc major versions. Consequently, this section is complex. 2259 1.1 agc 2260 1.1 agc 5.5.1. Key Packet Variants 2261 1.1 agc 2262 1.1 agc 5.5.1.1. Public-Key Packet (Tag 6) 2263 1.1 agc 2264 1.1 agc A Public-Key packet starts a series of packets that forms an OpenPGP 2265 1.1 agc key (sometimes called an OpenPGP certificate). 2266 1.1 agc 2267 1.1 agc 5.5.1.2. Public-Subkey Packet (Tag 14) 2268 1.1 agc 2269 1.1 agc A Public-Subkey packet (tag 14) has exactly the same format as a 2270 1.1 agc Public-Key packet, but denotes a subkey. One or more subkeys may be 2271 1.1 agc associated with a top-level key. By convention, the top-level key 2272 1.1 agc provides signature services, and the subkeys provide encryption 2273 1.1 agc services. 2274 1.1 agc 2275 1.1 agc Note: in PGP 2.6.x, tag 14 was intended to indicate a comment 2276 1.1 agc packet. This tag was selected for reuse because no previous version 2277 1.1 agc of PGP ever emitted comment packets but they did properly ignore 2278 1.1 agc 2279 1.1 agc 2280 1.1 agc 2281 1.1 agc Callas, et al Standards Track [Page 40] 2282 1.1 agc 2284 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2285 1.1 agc 2286 1.1 agc 2287 1.1 agc them. Public-Subkey packets are ignored by PGP 2.6.x and do not 2288 1.1 agc cause it to fail, providing a limited degree of backward 2289 1.1 agc compatibility. 2290 1.1 agc 2291 1.1 agc 5.5.1.3. Secret-Key Packet (Tag 5) 2292 1.1 agc 2293 1.1 agc A Secret-Key packet contains all the information that is found in a 2294 1.1 agc Public-Key packet, including the public-key material, but also 2295 1.1 agc includes the secret-key material after all the public-key fields. 2296 1.1 agc 2297 1.1 agc 5.5.1.4. Secret-Subkey Packet (Tag 7) 2298 1.1 agc 2299 1.1 agc A Secret-Subkey packet (tag 7) is the subkey analog of the Secret 2300 1.1 agc Key packet and has exactly the same format. 2301 1.1 agc 2302 1.1 agc 5.5.2. Public-Key Packet Formats 2303 1.1 agc 2304 1.1 agc There are two versions of key-material packets. Version 3 packets 2305 1.1 agc were first generated by PGP 2.6. Version 4 keys first appeared in 2306 1.1 agc PGP 5.0 and are the preferred key version for OpenPGP. 2307 1.1 agc 2308 1.1 agc OpenPGP implementations MUST create keys with version 4 format. V3 2309 1.1 agc keys are deprecated; an implementation MUST NOT generate a V3 key, 2310 1.1 agc but MAY accept it. 2311 1.1 agc 2312 1.1 agc A version 3 public key or public-subkey packet contains: 2313 1.1 agc 2314 1.1 agc - A one-octet version number (3). 2315 1.1 agc 2316 1.1 agc - A four-octet number denoting the time that the key was created. 2317 1.1 agc 2318 1.1 agc - A two-octet number denoting the time in days that this key is 2319 1.1 agc valid. If this number is zero, then it does not expire. 2320 1.1 agc 2321 1.1 agc - A one-octet number denoting the public-key algorithm of this key. 2322 1.1 agc 2323 1.1 agc - A series of multiprecision integers comprising the key material: 2324 1.1 agc 2325 1.1 agc - a multiprecision integer (MPI) of RSA public modulus n; 2326 1.1 agc 2327 1.1 agc - an MPI of RSA public encryption exponent e. 2328 1.1 agc 2329 1.1 agc V3 keys are deprecated. They contain three weaknesses. First, it is 2330 1.1 agc relatively easy to construct a V3 key that has the same Key ID as any 2331 1.1 agc other key because the Key ID is simply the low 64 bits of the public 2332 1.1 agc modulus. Secondly, because the fingerprint of a V3 key hashes the 2333 1.1 agc key material, but not its length, there is an increased opportunity 2334 1.1 agc for fingerprint collisions. Third, there are weaknesses in the MD5 2335 1.1 agc 2336 1.1 agc 2337 1.1 agc 2338 1.1 agc Callas, et al Standards Track [Page 41] 2339 1.1 agc 2341 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2342 1.1 agc 2343 1.1 agc 2344 1.1 agc hash algorithm that make developers prefer other algorithms. See 2345 1.1 agc below for a fuller discussion of Key IDs and fingerprints. 2346 1.1 agc 2347 1.1 agc V2 keys are identical to the deprecated V3 keys except for the 2348 1.1 agc version number. An implementation MUST NOT generate them and MAY 2349 1.1 agc accept or reject them as it sees fit. 2350 1.1 agc 2351 1.1 agc The version 4 format is similar to the version 3 format except for 2352 1.1 agc the absence of a validity period. This has been moved to the 2353 1.1 agc Signature packet. In addition, fingerprints of version 4 keys are 2354 1.1 agc calculated differently from version 3 keys, as described in the 2355 1.1 agc section "Enhanced Key Formats". 2356 1.1 agc 2357 1.1 agc A version 4 packet contains: 2358 1.1 agc 2359 1.1 agc - A one-octet version number (4). 2360 1.1 agc 2361 1.1 agc - A four-octet number denoting the time that the key was created. 2362 1.1 agc 2363 1.1 agc - A one-octet number denoting the public-key algorithm of this key. 2364 1.1 agc 2365 1.1 agc - A series of multiprecision integers comprising the key material. 2366 1.1 agc This algorithm-specific portion is: 2367 1.1 agc 2368 1.1 agc Algorithm-Specific Fields for RSA public keys: 2369 1.1 agc 2370 1.1 agc - multiprecision integer (MPI) of RSA public modulus n; 2371 1.1 agc 2372 1.1 agc - MPI of RSA public encryption exponent e. 2373 1.1 agc 2374 1.1 agc Algorithm-Specific Fields for DSA public keys: 2375 1.1 agc 2376 1.1 agc - MPI of DSA prime p; 2377 1.1 agc 2378 1.1 agc - MPI of DSA group order q (q is a prime divisor of p-1); 2379 1.1 agc 2380 1.1 agc - MPI of DSA group generator g; 2381 1.1 agc 2382 1.1 agc - MPI of DSA public-key value y (= g**x mod p where x 2383 1.1 agc is secret). 2384 1.1 agc 2385 1.1 agc Algorithm-Specific Fields for Elgamal public keys: 2386 1.1 agc 2387 1.1 agc - MPI of Elgamal prime p; 2388 1.1 agc 2389 1.1 agc - MPI of Elgamal group generator g; 2390 1.1 agc 2391 1.1 agc 2392 1.1 agc 2393 1.1 agc 2394 1.1 agc 2395 1.1 agc Callas, et al Standards Track [Page 42] 2396 1.1 agc 2398 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2399 1.1 agc 2400 1.1 agc 2401 1.1 agc - MPI of Elgamal public key value y (= g**x mod p where x 2402 1.1 agc is secret). 2403 1.1 agc 2404 1.1 agc 5.5.3. Secret-Key Packet Formats 2405 1.1 agc 2406 1.1 agc The Secret-Key and Secret-Subkey packets contain all the data of the 2407 1.1 agc Public-Key and Public-Subkey packets, with additional algorithm- 2408 1.1 agc specific secret-key data appended, usually in encrypted form. 2409 1.1 agc 2410 1.1 agc The packet contains: 2411 1.1 agc 2412 1.1 agc - A Public-Key or Public-Subkey packet, as described above. 2413 1.1 agc 2414 1.1 agc - One octet indicating string-to-key usage conventions. Zero 2415 1.1 agc indicates that the secret-key data is not encrypted. 255 or 254 2416 1.1 agc indicates that a string-to-key specifier is being given. Any 2417 1.1 agc other value is a symmetric-key encryption algorithm identifier. 2418 1.1 agc 2419 1.1 agc - [Optional] If string-to-key usage octet was 255 or 254, a one- 2420 1.1 agc octet symmetric encryption algorithm. 2421 1.1 agc 2422 1.1 agc - [Optional] If string-to-key usage octet was 255 or 254, a 2423 1.1 agc string-to-key specifier. The length of the string-to-key 2424 1.1 agc specifier is implied by its type, as described above. 2425 1.1 agc 2426 1.1 agc - [Optional] If secret data is encrypted (string-to-key usage octet 2427 1.1 agc not zero), an Initial Vector (IV) of the same length as the 2428 1.1 agc cipher's block size. 2429 1.1 agc 2430 1.1 agc - Plain or encrypted multiprecision integers comprising the secret 2431 1.1 agc key data. These algorithm-specific fields are as described 2432 1.1 agc below. 2433 1.1 agc 2434 1.1 agc - If the string-to-key usage octet is zero or 255, then a two-octet 2435 1.1 agc checksum of the plaintext of the algorithm-specific portion (sum 2436 1.1 agc of all octets, mod 65536). If the string-to-key usage octet was 2437 1.1 agc 254, then a 20-octet SHA-1 hash of the plaintext of the 2438 1.1 agc algorithm-specific portion. This checksum or hash is encrypted 2439 1.1 agc together with the algorithm-specific fields (if string-to-key 2440 1.1 agc usage octet is not zero). Note that for all other values, a 2441 1.1 agc two-octet checksum is required. 2442 1.1 agc 2443 1.1 agc Algorithm-Specific Fields for RSA secret keys: 2444 1.1 agc 2445 1.1 agc - multiprecision integer (MPI) of RSA secret exponent d. 2446 1.1 agc 2447 1.1 agc - MPI of RSA secret prime value p. 2448 1.1 agc 2449 1.1 agc 2450 1.1 agc 2451 1.1 agc 2452 1.1 agc Callas, et al Standards Track [Page 43] 2453 1.1 agc 2455 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2456 1.1 agc 2457 1.1 agc 2458 1.1 agc - MPI of RSA secret prime value q (p < q). 2459 1.1 agc 2460 1.1 agc - MPI of u, the multiplicative inverse of p, mod q. 2461 1.1 agc 2462 1.1 agc Algorithm-Specific Fields for DSA secret keys: 2463 1.1 agc 2464 1.1 agc - MPI of DSA secret exponent x. 2465 1.1 agc 2466 1.1 agc Algorithm-Specific Fields for Elgamal secret keys: 2467 1.1 agc 2468 1.1 agc - MPI of Elgamal secret exponent x. 2469 1.1 agc 2470 1.1 agc Secret MPI values can be encrypted using a passphrase. If a string- 2471 1.1 agc to-key specifier is given, that describes the algorithm for 2472 1.1 agc converting the passphrase to a key, else a simple MD5 hash of the 2473 1.1 agc passphrase is used. Implementations MUST use a string-to-key 2474 1.1 agc specifier; the simple hash is for backward compatibility and is 2475 1.1 agc deprecated, though implementations MAY continue to use existing 2476 1.1 agc private keys in the old format. The cipher for encrypting the MPIs 2477 1.1 agc is specified in the Secret-Key packet. 2478 1.1 agc 2479 1.1 agc Encryption/decryption of the secret data is done in CFB mode using 2480 1.1 agc the key created from the passphrase and the Initial Vector from the 2481 1.1 agc packet. A different mode is used with V3 keys (which are only RSA) 2482 1.1 agc than with other key formats. With V3 keys, the MPI bit count prefix 2483 1.1 agc (i.e., the first two octets) is not encrypted. Only the MPI non- 2484 1.1 agc prefix data is encrypted. Furthermore, the CFB state is 2485 1.1 agc resynchronized at the beginning of each new MPI value, so that the 2486 1.1 agc CFB block boundary is aligned with the start of the MPI data. 2487 1.1 agc 2488 1.1 agc With V4 keys, a simpler method is used. All secret MPI values are 2489 1.1 agc encrypted in CFB mode, including the MPI bitcount prefix. 2490 1.1 agc 2491 1.1 agc The two-octet checksum that follows the algorithm-specific portion is 2492 1.1 agc the algebraic sum, mod 65536, of the plaintext of all the algorithm- 2493 1.1 agc specific octets (including MPI prefix and data). With V3 keys, the 2494 1.1 agc checksum is stored in the clear. With V4 keys, the checksum is 2495 1.1 agc encrypted like the algorithm-specific data. This value is used to 2496 1.1 agc check that the passphrase was correct. However, this checksum is 2497 1.1 agc deprecated; an implementation SHOULD NOT use it, but should rather 2498 1.1 agc use the SHA-1 hash denoted with a usage octet of 254. The reason for 2499 1.1 agc this is that there are some attacks that involve undetectably 2500 1.1 agc modifying the secret key. 2501 1.1 agc 2502 1.1 agc 2503 1.1 agc 2504 1.1 agc 2505 1.1 agc 2506 1.1 agc 2507 1.1 agc 2508 1.1 agc 2509 1.1 agc Callas, et al Standards Track [Page 44] 2510 1.1 agc 2512 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2513 1.1 agc 2514 1.1 agc 2515 1.1 agc 5.6. Compressed Data Packet (Tag 8) 2516 1.1 agc 2517 1.1 agc The Compressed Data packet contains compressed data. Typically, this 2518 1.1 agc packet is found as the contents of an encrypted packet, or following 2519 1.1 agc a Signature or One-Pass Signature packet, and contains a literal data 2520 1.1 agc packet. 2521 1.1 agc 2522 1.1 agc The body of this packet consists of: 2523 1.1 agc 2524 1.1 agc - One octet that gives the algorithm used to compress the packet. 2525 1.1 agc 2526 1.1 agc - Compressed data, which makes up the remainder of the packet. 2527 1.1 agc 2528 1.1 agc A Compressed Data Packet's body contains an block that compresses 2529 1.1 agc some set of packets. See section "Packet Composition" for details on 2530 1.1 agc how messages are formed. 2531 1.1 agc 2532 1.1 agc ZIP-compressed packets are compressed with raw RFC 1951 [RFC1951] 2533 1.1 agc DEFLATE blocks. Note that PGP V2.6 uses 13 bits of compression. If 2534 1.1 agc an implementation uses more bits of compression, PGP V2.6 cannot 2535 1.1 agc decompress it. 2536 1.1 agc 2537 1.1 agc ZLIB-compressed packets are compressed with RFC 1950 [RFC1950] ZLIB- 2538 1.1 agc style blocks. 2539 1.1 agc 2540 1.1 agc BZip2-compressed packets are compressed using the BZip2 [BZ2] 2541 1.1 agc algorithm. 2542 1.1 agc 2543 1.1 agc 5.7. Symmetrically Encrypted Data Packet (Tag 9) 2544 1.1 agc 2545 1.1 agc The Symmetrically Encrypted Data packet contains data encrypted with 2546 1.1 agc a symmetric-key algorithm. When it has been decrypted, it contains 2547 1.1 agc other packets (usually a literal data packet or compressed data 2548 1.1 agc packet, but in theory other Symmetrically Encrypted Data packets or 2549 1.1 agc sequences of packets that form whole OpenPGP messages). 2550 1.1 agc 2551 1.1 agc The body of this packet consists of: 2552 1.1 agc 2553 1.1 agc - Encrypted data, the output of the selected symmetric-key cipher 2554 1.1 agc operating in OpenPGP's variant of Cipher Feedback (CFB) mode. 2555 1.1 agc 2556 1.1 agc The symmetric cipher used may be specified in a Public-Key or 2557 1.1 agc Symmetric-Key Encrypted Session Key packet that precedes the 2558 1.1 agc Symmetrically Encrypted Data packet. In that case, the cipher 2559 1.1 agc algorithm octet is prefixed to the session key before it is 2560 1.1 agc encrypted. If no packets of these types precede the encrypted data, 2561 1.1 agc the IDEA algorithm is used with the session key calculated as the MD5 2562 1.1 agc hash of the passphrase, though this use is deprecated. 2563 1.1 agc 2564 1.1 agc 2565 1.1 agc 2566 1.1 agc Callas, et al Standards Track [Page 45] 2567 1.1 agc 2569 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2570 1.1 agc 2571 1.1 agc 2572 1.1 agc The data is encrypted in CFB mode, with a CFB shift size equal to the 2573 1.1 agc cipher's block size. The Initial Vector (IV) is specified as all 2574 1.1 agc zeros. Instead of using an IV, OpenPGP prefixes a string of length 2575 1.1 agc equal to the block size of the cipher plus two to the data before it 2576 1.1 agc is encrypted. The first block-size octets (for example, 8 octets for 2577 1.1 agc a 64-bit block length) are random, and the following two octets are 2578 1.1 agc copies of the last two octets of the IV. For example, in an 8-octet 2579 1.1 agc block, octet 9 is a repeat of octet 7, and octet 10 is a repeat of 2580 1.1 agc octet 8. In a cipher of length 16, octet 17 is a repeat of octet 15 2581 1.1 agc and octet 18 is a repeat of octet 16. As a pedantic clarification, 2582 1.1 agc in both these examples, we consider the first octet to be numbered 1. 2583 1.1 agc 2584 1.1 agc After encrypting the first block-size-plus-two octets, the CFB state 2585 1.1 agc is resynchronized. The last block-size octets of ciphertext are 2586 1.1 agc passed through the cipher and the block boundary is reset. 2587 1.1 agc 2588 1.1 agc The repetition of 16 bits in the random data prefixed to the message 2589 1.1 agc allows the receiver to immediately check whether the session key is 2590 1.1 agc incorrect. See the "Security Considerations" section for hints on 2591 1.1 agc the proper use of this "quick check". 2592 1.1 agc 2593 1.1 agc 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 2594 1.1 agc 2595 1.1 agc An experimental version of PGP used this packet as the Literal 2596 1.1 agc packet, but no released version of PGP generated Literal packets with 2597 1.1 agc this tag. With PGP 5.x, this packet has been reassigned and is 2598 1.1 agc reserved for use as the Marker packet. 2599 1.1 agc 2600 1.1 agc The body of this packet consists of: 2601 1.1 agc 2602 1.1 agc - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8). 2603 1.1 agc 2604 1.1 agc Such a packet MUST be ignored when received. It may be placed at the 2605 1.1 agc beginning of a message that uses features not available in PGP 2.6.x 2606 1.1 agc in order to cause that version to report that newer software is 2607 1.1 agc necessary to process the message. 2608 1.1 agc 2609 1.1 agc 5.9. Literal Data Packet (Tag 11) 2610 1.1 agc 2611 1.1 agc A Literal Data packet contains the body of a message; data that is 2612 1.1 agc not to be further interpreted. 2613 1.1 agc 2614 1.1 agc The body of this packet consists of: 2615 1.1 agc 2616 1.1 agc - A one-octet field that describes how the data is formatted. 2617 1.1 agc 2618 1.1 agc 2619 1.1 agc 2620 1.1 agc 2621 1.1 agc 2622 1.1 agc 2623 1.1 agc Callas, et al Standards Track [Page 46] 2624 1.1 agc 2626 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2627 1.1 agc 2628 1.1 agc 2629 1.1 agc If it is a 'b' (0x62), then the Literal packet contains binary data. 2630 1.1 agc If it is a 't' (0x74), then it contains text data, and thus may need 2631 1.1 agc line ends converted to local form, or other text-mode changes. The 2632 1.1 agc tag 'u' (0x75) means the same as 't', but also indicates that 2633 1.1 agc implementation believes that the literal data contains UTF-8 text. 2634 1.1 agc 2635 1.1 agc Early versions of PGP also defined a value of 'l' as a 'local' mode 2636 1.1 agc for machine-local conversions. RFC 1991 [RFC1991] incorrectly stated 2637 1.1 agc this local mode flag as '1' (ASCII numeral one). Both of these local 2638 1.1 agc modes are deprecated. 2639 1.1 agc 2640 1.1 agc - File name as a string (one-octet length, followed by a file 2641 1.1 agc name). This may be a zero-length string. Commonly, if the 2642 1.1 agc source of the encrypted data is a file, this will be the name of 2643 1.1 agc the encrypted file. An implementation MAY consider the file name 2644 1.1 agc in the Literal packet to be a more authoritative name than the 2645 1.1 agc actual file name. 2646 1.1 agc 2647 1.1 agc If the special name "_CONSOLE" is used, the message is considered to 2648 1.1 agc be "for your eyes only". This advises that the message data is 2649 1.1 agc unusually sensitive, and the receiving program should process it more 2650 1.1 agc carefully, perhaps avoiding storing the received data to disk, for 2651 1.1 agc example. 2652 1.1 agc 2653 1.1 agc - A four-octet number that indicates a date associated with the 2654 1.1 agc literal data. Commonly, the date might be the modification date 2655 1.1 agc of a file, or the time the packet was created, or a zero that 2656 1.1 agc indicates no specific time. 2657 1.1 agc 2658 1.1 agc - The remainder of the packet is literal data. 2659 1.1 agc 2660 1.1 agc Text data is stored with <CR><LF> text endings (i.e., network- 2661 1.1 agc normal line endings). These should be converted to native line 2662 1.1 agc endings by the receiving software. 2663 1.1 agc 2664 1.1 agc 5.10. Trust Packet (Tag 12) 2665 1.1 agc 2666 1.1 agc The Trust packet is used only within keyrings and is not normally 2667 1.1 agc exported. Trust packets contain data that record the user's 2668 1.1 agc specifications of which key holders are trustworthy introducers, 2669 1.1 agc along with other information that implementing software uses for 2670 1.1 agc trust information. The format of Trust packets is defined by a given 2671 1.1 agc implementation. 2672 1.1 agc 2673 1.1 agc Trust packets SHOULD NOT be emitted to output streams that are 2674 1.1 agc transferred to other users, and they SHOULD be ignored on any input 2675 1.1 agc other than local keyring files. 2676 1.1 agc 2677 1.1 agc 2678 1.1 agc 2679 1.1 agc 2680 1.1 agc Callas, et al Standards Track [Page 47] 2681 1.1 agc 2683 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2684 1.1 agc 2685 1.1 agc 2686 1.1 agc 5.11. User ID Packet (Tag 13) 2687 1.1 agc 2688 1.1 agc A User ID packet consists of UTF-8 text that is intended to represent 2689 1.1 agc the name and email address of the key holder. By convention, it 2690 1.1 agc includes an RFC 2822 [RFC2822] mail name-addr, but there are no 2691 1.1 agc restrictions on its content. The packet length in the header 2692 1.1 agc specifies the length of the User ID. 2693 1.1 agc 2694 1.1 agc 5.12. User Attribute Packet (Tag 17) 2695 1.1 agc 2696 1.1 agc The User Attribute packet is a variation of the User ID packet. It 2697 1.1 agc is capable of storing more types of data than the User ID packet, 2698 1.1 agc which is limited to text. Like the User ID packet, a User Attribute 2699 1.1 agc packet may be certified by the key owner ("self-signed") or any other 2700 1.1 agc key owner who cares to certify it. Except as noted, a User Attribute 2701 1.1 agc packet may be used anywhere that a User ID packet may be used. 2702 1.1 agc 2703 1.1 agc While User Attribute packets are not a required part of the OpenPGP 2704 1.1 agc standard, implementations SHOULD provide at least enough 2705 1.1 agc compatibility to properly handle a certification signature on the 2706 1.1 agc User Attribute packet. A simple way to do this is by treating the 2707 1.1 agc User Attribute packet as a User ID packet with opaque contents, but 2708 1.1 agc an implementation may use any method desired. 2709 1.1 agc 2710 1.1 agc The User Attribute packet is made up of one or more attribute 2711 1.1 agc subpackets. Each subpacket consists of a subpacket header and a 2712 1.1 agc body. The header consists of: 2713 1.1 agc 2714 1.1 agc - the subpacket length (1, 2, or 5 octets) 2715 1.1 agc 2716 1.1 agc - the subpacket type (1 octet) 2717 1.1 agc 2718 1.1 agc and is followed by the subpacket specific data. 2719 1.1 agc 2720 1.1 agc The only currently defined subpacket type is 1, signifying an image. 2721 1.1 agc An implementation SHOULD ignore any subpacket of a type that it does 2722 1.1 agc not recognize. Subpacket types 100 through 110 are reserved for 2723 1.1 agc private or experimental use. 2724 1.1 agc 2725 1.1 agc 5.12.1. The Image Attribute Subpacket 2726 1.1 agc 2727 1.1 agc The Image Attribute subpacket is used to encode an image, presumably 2728 1.1 agc (but not required to be) that of the key owner. 2729 1.1 agc 2730 1.1 agc The Image Attribute subpacket begins with an image header. The first 2731 1.1 agc two octets of the image header contain the length of the image 2732 1.1 agc header. Note that unlike other multi-octet numerical values in this 2733 1.1 agc document, due to a historical accident this value is encoded as a 2734 1.1 agc 2735 1.1 agc 2736 1.1 agc 2737 1.1 agc Callas, et al Standards Track [Page 48] 2738 1.1 agc 2740 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2741 1.1 agc 2742 1.1 agc 2743 1.1 agc little-endian number. The image header length is followed by a 2744 1.1 agc single octet for the image header version. The only currently 2745 1.1 agc defined version of the image header is 1, which is a 16-octet image 2746 1.1 agc header. The first three octets of a version 1 image header are thus 2747 1.1 agc 0x10, 0x00, 0x01. 2748 1.1 agc 2749 1.1 agc The fourth octet of a version 1 image header designates the encoding 2750 1.1 agc format of the image. The only currently defined encoding format is 2751 1.1 agc the value 1 to indicate JPEG. Image format types 100 through 110 are 2752 1.1 agc reserved for private or experimental use. The rest of the version 1 2753 1.1 agc image header is made up of 12 reserved octets, all of which MUST be 2754 1.1 agc set to 0. 2755 1.1 agc 2756 1.1 agc The rest of the image subpacket contains the image itself. As the 2757 1.1 agc only currently defined image type is JPEG, the image is encoded in 2758 1.1 agc the JPEG File Interchange Format (JFIF), a standard file format for 2759 1.1 agc JPEG images [JFIF]. 2760 1.1 agc 2761 1.1 agc An implementation MAY try to determine the type of an image by 2762 1.1 agc examination of the image data if it is unable to handle a particular 2763 1.1 agc version of the image header or if a specified encoding format value 2764 1.1 agc is not recognized. 2765 1.1 agc 2766 1.1 agc 5.13. Sym. Encrypted Integrity Protected Data Packet (Tag 18) 2767 1.1 agc 2768 1.1 agc The Symmetrically Encrypted Integrity Protected Data packet is a 2769 1.1 agc variant of the Symmetrically Encrypted Data packet. It is a new 2770 1.1 agc feature created for OpenPGP that addresses the problem of detecting a 2771 1.1 agc modification to encrypted data. It is used in combination with a 2772 1.1 agc Modification Detection Code packet. 2773 1.1 agc 2774 1.1 agc There is a corresponding feature in the features Signature subpacket 2775 1.1 agc that denotes that an implementation can properly use this packet 2776 1.1 agc type. An implementation MUST support decrypting these packets and 2777 1.1 agc SHOULD prefer generating them to the older Symmetrically Encrypted 2778 1.1 agc Data packet when possible. Since this data packet protects against 2779 1.1 agc modification attacks, this standard encourages its proliferation. 2780 1.1 agc While blanket adoption of this data packet would create 2781 1.1 agc interoperability problems, rapid adoption is nevertheless important. 2782 1.1 agc An implementation SHOULD specifically denote support for this packet, 2783 1.1 agc but it MAY infer it from other mechanisms. 2784 1.1 agc 2785 1.1 agc For example, an implementation might infer from the use of a cipher 2786 1.1 agc such as Advanced Encryption Standard (AES) or Twofish that a user 2787 1.1 agc supports this feature. It might place in the unhashed portion of 2788 1.1 agc another user's key signature a Features subpacket. It might also 2789 1.1 agc present a user with an opportunity to regenerate their own self- 2790 1.1 agc signature with a Features subpacket. 2791 1.1 agc 2792 1.1 agc 2793 1.1 agc 2794 1.1 agc Callas, et al Standards Track [Page 49] 2795 1.1 agc 2797 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2798 1.1 agc 2799 1.1 agc 2800 1.1 agc This packet contains data encrypted with a symmetric-key algorithm 2801 1.1 agc and protected against modification by the SHA-1 hash algorithm. When 2802 1.1 agc it has been decrypted, it will typically contain other packets (often 2803 1.1 agc a Literal Data packet or Compressed Data packet). The last decrypted 2804 1.1 agc packet in this packet's payload MUST be a Modification Detection Code 2805 1.1 agc packet. 2806 1.1 agc 2807 1.1 agc The body of this packet consists of: 2808 1.1 agc 2809 1.1 agc - A one-octet version number. The only currently defined value is 2810 1.1 agc 1. 2811 1.1 agc 2812 1.1 agc - Encrypted data, the output of the selected symmetric-key cipher 2813 1.1 agc operating in Cipher Feedback mode with shift amount equal to the 2814 1.1 agc block size of the cipher (CFB-n where n is the block size). 2815 1.1 agc 2816 1.1 agc The symmetric cipher used MUST be specified in a Public-Key or 2817 1.1 agc Symmetric-Key Encrypted Session Key packet that precedes the 2818 1.1 agc Symmetrically Encrypted Data packet. In either case, the cipher 2819 1.1 agc algorithm octet is prefixed to the session key before it is 2820 1.1 agc encrypted. 2821 1.1 agc 2822 1.1 agc The data is encrypted in CFB mode, with a CFB shift size equal to the 2823 1.1 agc cipher's block size. The Initial Vector (IV) is specified as all 2824 1.1 agc zeros. Instead of using an IV, OpenPGP prefixes an octet string to 2825 1.1 agc the data before it is encrypted. The length of the octet string 2826 1.1 agc equals the block size of the cipher in octets, plus two. The first 2827 1.1 agc octets in the group, of length equal to the block size of the cipher, 2828 1.1 agc are random; the last two octets are each copies of their 2nd 2829 1.1 agc preceding octet. For example, with a cipher whose block size is 128 2830 1.1 agc bits or 16 octets, the prefix data will contain 16 random octets, 2831 1.1 agc then two more octets, which are copies of the 15th and 16th octets, 2832 1.1 agc respectively. Unlike the Symmetrically Encrypted Data Packet, no 2833 1.1 agc special CFB resynchronization is done after encrypting this prefix 2834 1.1 agc data. See "OpenPGP CFB Mode" below for more details. 2835 1.1 agc 2836 1.1 agc The repetition of 16 bits in the random data prefixed to the message 2837 1.1 agc allows the receiver to immediately check whether the session key is 2838 1.1 agc incorrect. 2839 1.1 agc 2840 1.1 agc The plaintext of the data to be encrypted is passed through the SHA-1 2841 1.1 agc hash function, and the result of the hash is appended to the 2842 1.1 agc plaintext in a Modification Detection Code packet. The input to the 2843 1.1 agc hash function includes the prefix data described above; it includes 2844 1.1 agc all of the plaintext, and then also includes two octets of values 2845 1.1 agc 0xD3, 0x14. These represent the encoding of a Modification Detection 2846 1.1 agc Code packet tag and length field of 20 octets. 2847 1.1 agc 2848 1.1 agc 2849 1.1 agc 2850 1.1 agc 2851 1.1 agc Callas, et al Standards Track [Page 50] 2852 1.1 agc 2854 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2855 1.1 agc 2856 1.1 agc 2857 1.1 agc The resulting hash value is stored in a Modification Detection Code 2858 1.1 agc (MDC) packet, which MUST use the two octet encoding just given to 2859 1.1 agc represent its tag and length field. The body of the MDC packet is 2860 1.1 agc the 20-octet output of the SHA-1 hash. 2861 1.1 agc 2862 1.1 agc The Modification Detection Code packet is appended to the plaintext 2863 1.1 agc and encrypted along with the plaintext using the same CFB context. 2864 1.1 agc 2865 1.1 agc During decryption, the plaintext data should be hashed with SHA-1, 2866 1.1 agc including the prefix data as well as the packet tag and length field 2867 1.1 agc of the Modification Detection Code packet. The body of the MDC 2868 1.1 agc packet, upon decryption, is compared with the result of the SHA-1 2869 1.1 agc hash. 2870 1.1 agc 2871 1.1 agc Any failure of the MDC indicates that the message has been modified 2872 1.1 agc and MUST be treated as a security problem. Failures include a 2873 1.1 agc difference in the hash values, but also the absence of an MDC packet, 2874 1.1 agc or an MDC packet in any position other than the end of the plaintext. 2875 1.1 agc Any failure SHOULD be reported to the user. 2876 1.1 agc 2877 1.1 agc Note: future designs of new versions of this packet should consider 2878 1.1 agc rollback attacks since it will be possible for an attacker to change 2879 1.1 agc the version back to 1. 2880 1.1 agc 2881 1.1 agc NON-NORMATIVE EXPLANATION 2882 1.1 agc 2883 1.1 agc The MDC system, as packets 18 and 19 are called, were created to 2884 1.1 agc provide an integrity mechanism that is less strong than a 2885 1.1 agc signature, yet stronger than bare CFB encryption. 2886 1.1 agc 2887 1.1 agc It is a limitation of CFB encryption that damage to the ciphertext 2888 1.1 agc will corrupt the affected cipher blocks and the block following. 2889 1.1 agc Additionally, if data is removed from the end of a CFB-encrypted 2890 1.1 agc block, that removal is undetectable. (Note also that CBC mode has 2891 1.1 agc a similar limitation, but data removed from the front of the block 2892 1.1 agc is undetectable.) 2893 1.1 agc 2894 1.1 agc The obvious way to protect or authenticate an encrypted block is 2895 1.1 agc to digitally sign it. However, many people do not wish to 2896 1.1 agc habitually sign data, for a large number of reasons beyond the 2897 1.1 agc scope of this document. Suffice it to say that many people 2898 1.1 agc consider properties such as deniability to be as valuable as 2899 1.1 agc integrity. 2900 1.1 agc 2901 1.1 agc OpenPGP addresses this desire to have more security than raw 2902 1.1 agc encryption and yet preserve deniability with the MDC system. An 2903 1.1 agc MDC is intentionally not a MAC. Its name was not selected by 2904 1.1 agc accident. It is analogous to a checksum. 2905 1.1 agc 2906 1.1 agc 2907 1.1 agc 2908 1.1 agc Callas, et al Standards Track [Page 51] 2909 1.1 agc 2911 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2912 1.1 agc 2913 1.1 agc 2914 1.1 agc Despite the fact that it is a relatively modest system, it has 2915 1.1 agc proved itself in the real world. It is an effective defense to 2916 1.1 agc several attacks that have surfaced since it has been created. It 2917 1.1 agc has met its modest goals admirably. 2918 1.1 agc 2919 1.1 agc Consequently, because it is a modest security system, it has 2920 1.1 agc modest requirements on the hash function(s) it employs. It does 2921 1.1 agc not rely on a hash function being collision-free, it relies on a 2922 1.1 agc hash function being one-way. If a forger, Frank, wishes to send 2923 1.1 agc Alice a (digitally) unsigned message that says, "I've always 2924 1.1 agc secretly loved you, signed Bob", it is far easier for him to 2925 1.1 agc construct a new message than it is to modify anything intercepted 2926 1.1 agc from Bob. (Note also that if Bob wishes to communicate secretly 2927 1.1 agc with Alice, but without authentication or identification and with 2928 1.1 agc a threat model that includes forgers, he has a problem that 2929 1.1 agc transcends mere cryptography.) 2930 1.1 agc 2931 1.1 agc Note also that unlike nearly every other OpenPGP subsystem, there 2932 1.1 agc are no parameters in the MDC system. It hard-defines SHA-1 as its 2933 1.1 agc hash function. This is not an accident. It is an intentional 2934 1.1 agc choice to avoid downgrade and cross-grade attacks while making a 2935 1.1 agc simple, fast system. (A downgrade attack would be an attack that 2936 1.1 agc replaced SHA-256 with SHA-1, for example. A cross-grade attack 2937 1.1 agc would replace SHA-1 with another 160-bit hash, such as RIPE- 2938 1.1 agc MD/160, for example.) 2939 1.1 agc 2940 1.1 agc However, given the present state of hash function cryptanalysis 2941 1.1 agc and cryptography, it may be desirable to upgrade the MDC system to 2942 1.1 agc a new hash function. See Section 13.11 in the "IANA 2943 1.1 agc Considerations" for guidance. 2944 1.1 agc 2945 1.1 agc 5.14. Modification Detection Code Packet (Tag 19) 2946 1.1 agc 2947 1.1 agc The Modification Detection Code packet contains a SHA-1 hash of 2948 1.1 agc plaintext data, which is used to detect message modification. It is 2949 1.1 agc only used with a Symmetrically Encrypted Integrity Protected Data 2950 1.1 agc packet. The Modification Detection Code packet MUST be the last 2951 1.1 agc packet in the plaintext data that is encrypted in the Symmetrically 2952 1.1 agc Encrypted Integrity Protected Data packet, and MUST appear in no 2953 1.1 agc other place. 2954 1.1 agc 2955 1.1 agc A Modification Detection Code packet MUST have a length of 20 octets. 2956 1.1 agc 2957 1.1 agc 2958 1.1 agc 2959 1.1 agc 2960 1.1 agc 2961 1.1 agc 2962 1.1 agc 2963 1.1 agc 2964 1.1 agc 2965 1.1 agc Callas, et al Standards Track [Page 52] 2966 1.1 agc 2968 1.1 agc RFC 4880 OpenPGP Message Format November 2007 2969 1.1 agc 2970 1.1 agc 2971 1.1 agc The body of this packet consists of: 2972 1.1 agc 2973 1.1 agc - A 20-octet SHA-1 hash of the preceding plaintext data of the 2974 1.1 agc Symmetrically Encrypted Integrity Protected Data packet, 2975 1.1 agc including prefix data, the tag octet, and length octet of the 2976 1.1 agc Modification Detection Code packet. 2977 1.1 agc 2978 1.1 agc Note that the Modification Detection Code packet MUST always use a 2979 1.1 agc new format encoding of the packet tag, and a one-octet encoding of 2980 1.1 agc the packet length. The reason for this is that the hashing rules for 2981 1.1 agc modification detection include a one-octet tag and one-octet length 2982 1.1 agc in the data hash. While this is a bit restrictive, it reduces 2983 1.1 agc complexity. 2984 1.1 agc 2985 1.1 agc 6. Radix-64 Conversions 2986 1.1 agc 2987 1.1 agc As stated in the introduction, OpenPGP's underlying native 2988 1.1 agc representation for objects is a stream of arbitrary octets, and some 2989 1.1 agc systems desire these objects to be immune to damage caused by 2990 1.1 agc character set translation, data conversions, etc. 2991 1.1 agc 2992 1.1 agc In principle, any printable encoding scheme that met the requirements 2993 1.1 agc of the unsafe channel would suffice, since it would not change the 2994 1.1 agc underlying binary bit streams of the native OpenPGP data structures. 2995 1.1 agc The OpenPGP standard specifies one such printable encoding scheme to 2996 1.1 agc ensure interoperability. 2997 1.1 agc 2998 1.1 agc OpenPGP's Radix-64 encoding is composed of two parts: a base64 2999 1.1 agc encoding of the binary data and a checksum. The base64 encoding is 3000 1.1 agc identical to the MIME base64 content-transfer-encoding [RFC2045]. 3001 1.1 agc 3002 1.1 agc The checksum is a 24-bit Cyclic Redundancy Check (CRC) converted to 3003 1.1 agc four characters of radix-64 encoding by the same MIME base64 3004 1.1 agc transformation, preceded by an equal sign (=). The CRC is computed 3005 1.1 agc by using the generator 0x864CFB and an initialization of 0xB704CE. 3006 1.1 agc The accumulation is done on the data before it is converted to 3007 1.1 agc radix-64, rather than on the converted data. A sample implementation 3008 1.1 agc of this algorithm is in the next section. 3009 1.1 agc 3010 1.1 agc The checksum with its leading equal sign MAY appear on the first line 3011 1.1 agc after the base64 encoded data. 3012 1.1 agc 3013 1.1 agc Rationale for CRC-24: The size of 24 bits fits evenly into printable 3014 1.1 agc base64. The nonzero initialization can detect more errors than a 3015 1.1 agc zero initialization. 3016 1.1 agc 3017 1.1 agc 3018 1.1 agc 3019 1.1 agc 3020 1.1 agc 3021 1.1 agc 3022 1.1 agc Callas, et al Standards Track [Page 53] 3023 1.1 agc 3025 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3026 1.1 agc 3027 1.1 agc 3028 1.1 agc 6.1. An Implementation of the CRC-24 in "C" 3029 1.1 agc 3030 1.1 agc #define CRC24_INIT 0xB704CEL 3031 1.1 agc #define CRC24_POLY 0x1864CFBL 3032 1.1 agc 3033 1.1 agc typedef long crc24; 3034 1.1 agc crc24 crc_octets(unsigned char *octets, size_t len) 3035 1.1 agc { 3036 1.1 agc crc24 crc = CRC24_INIT; 3037 1.1 agc int i; 3038 1.1 agc while (len--) { 3039 1.1 agc crc ^= (*octets++) << 16; 3040 1.1 agc for (i = 0; i < 8; i++) { 3041 1.1 agc crc <<= 1; 3042 1.1 agc if (crc & 0x1000000) 3043 1.1 agc crc ^= CRC24_POLY; 3044 1.1 agc } 3045 1.1 agc } 3046 1.1 agc return crc & 0xFFFFFFL; 3047 1.1 agc } 3048 1.1 agc 3049 1.1 agc 6.2. Forming ASCII Armor 3050 1.1 agc 3051 1.1 agc When OpenPGP encodes data into ASCII Armor, it puts specific headers 3052 1.1 agc around the Radix-64 encoded data, so OpenPGP can reconstruct the data 3053 1.1 agc later. An OpenPGP implementation MAY use ASCII armor to protect raw 3054 1.1 agc binary data. OpenPGP informs the user what kind of data is encoded 3055 1.1 agc in the ASCII armor through the use of the headers. 3056 1.1 agc 3057 1.1 agc Concatenating the following data creates ASCII Armor: 3058 1.1 agc 3059 1.1 agc - An Armor Header Line, appropriate for the type of data 3060 1.1 agc 3061 1.1 agc - Armor Headers 3062 1.1 agc 3063 1.1 agc - A blank (zero-length, or containing only whitespace) line 3064 1.1 agc 3065 1.1 agc - The ASCII-Armored data 3066 1.1 agc 3067 1.1 agc - An Armor Checksum 3068 1.1 agc 3069 1.1 agc - The Armor Tail, which depends on the Armor Header Line 3070 1.1 agc 3071 1.1 agc An Armor Header Line consists of the appropriate header line text 3072 1.1 agc surrounded by five (5) dashes ('-', 0x2D) on either side of the 3073 1.1 agc header line text. The header line text is chosen based upon the type 3074 1.1 agc of data that is being encoded in Armor, and how it is being encoded. 3075 1.1 agc Header line texts include the following strings: 3076 1.1 agc 3077 1.1 agc 3078 1.1 agc 3079 1.1 agc Callas, et al Standards Track [Page 54] 3080 1.1 agc 3082 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3083 1.1 agc 3084 1.1 agc 3085 1.1 agc BEGIN PGP MESSAGE 3086 1.1 agc Used for signed, encrypted, or compressed files. 3087 1.1 agc 3088 1.1 agc BEGIN PGP PUBLIC KEY BLOCK 3089 1.1 agc Used for armoring public keys. 3090 1.1 agc 3091 1.1 agc BEGIN PGP PRIVATE KEY BLOCK 3092 1.1 agc Used for armoring private keys. 3093 1.1 agc 3094 1.1 agc BEGIN PGP MESSAGE, PART X/Y 3095 1.1 agc Used for multi-part messages, where the armor is split amongst Y 3096 1.1 agc parts, and this is the Xth part out of Y. 3097 1.1 agc 3098 1.1 agc BEGIN PGP MESSAGE, PART X 3099 1.1 agc Used for multi-part messages, where this is the Xth part of an 3100 1.1 agc unspecified number of parts. Requires the MESSAGE-ID Armor 3101 1.1 agc Header to be used. 3102 1.1 agc 3103 1.1 agc BEGIN PGP SIGNATURE 3104 1.1 agc Used for detached signatures, OpenPGP/MIME signatures, and 3105 1.1 agc cleartext signatures. Note that PGP 2.x uses BEGIN PGP MESSAGE 3106 1.1 agc for detached signatures. 3107 1.1 agc 3108 1.1 agc Note that all these Armor Header Lines are to consist of a complete 3109 1.1 agc line. That is to say, there is always a line ending preceding the 3110 1.1 agc starting five dashes, and following the ending five dashes. The 3111 1.1 agc header lines, therefore, MUST start at the beginning of a line, and 3112 1.1 agc MUST NOT have text other than whitespace following them on the same 3113 1.1 agc line. These line endings are considered a part of the Armor Header 3114 1.1 agc Line for the purposes of determining the content they delimit. This 3115 1.1 agc is particularly important when computing a cleartext signature (see 3116 1.1 agc below). 3117 1.1 agc 3118 1.1 agc The Armor Headers are pairs of strings that can give the user or the 3119 1.1 agc receiving OpenPGP implementation some information about how to decode 3120 1.1 agc or use the message. The Armor Headers are a part of the armor, not a 3121 1.1 agc part of the message, and hence are not protected by any signatures 3122 1.1 agc applied to the message. 3123 1.1 agc 3124 1.1 agc The format of an Armor Header is that of a key-value pair. A colon 3125 1.1 agc (':' 0x38) and a single space (0x20) separate the key and value. 3126 1.1 agc OpenPGP should consider improperly formatted Armor Headers to be 3127 1.1 agc corruption of the ASCII Armor. Unknown keys should be reported to 3128 1.1 agc the user, but OpenPGP should continue to process the message. 3129 1.1 agc 3130 1.1 agc Note that some transport methods are sensitive to line length. While 3131 1.1 agc there is a limit of 76 characters for the Radix-64 data (Section 3132 1.1 agc 6.3), there is no limit to the length of Armor Headers. Care should 3133 1.1 agc 3134 1.1 agc 3135 1.1 agc 3136 1.1 agc Callas, et al Standards Track [Page 55] 3137 1.1 agc 3139 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3140 1.1 agc 3141 1.1 agc 3142 1.1 agc be taken that the Armor Headers are short enough to survive 3143 1.1 agc transport. One way to do this is to repeat an Armor Header key 3144 1.1 agc multiple times with different values for each so that no one line is 3145 1.1 agc overly long. 3146 1.1 agc 3147 1.1 agc Currently defined Armor Header Keys are as follows: 3148 1.1 agc 3149 1.1 agc - "Version", which states the OpenPGP implementation and version 3150 1.1 agc used to encode the message. 3151 1.1 agc 3152 1.1 agc - "Comment", a user-defined comment. OpenPGP defines all text to 3153 1.1 agc be in UTF-8. A comment may be any UTF-8 string. However, the 3154 1.1 agc whole point of armoring is to provide seven-bit-clean data. 3155 1.1 agc Consequently, if a comment has characters that are outside the 3156 1.1 agc US-ASCII range of UTF, they may very well not survive transport. 3157 1.1 agc 3158 1.1 agc - "MessageID", a 32-character string of printable characters. The 3159 1.1 agc string must be the same for all parts of a multi-part message 3160 1.1 agc that uses the "PART X" Armor Header. MessageID strings should be 3161 1.1 agc unique enough that the recipient of the mail can associate all 3162 1.1 agc the parts of a message with each other. A good checksum or 3163 1.1 agc cryptographic hash function is sufficient. 3164 1.1 agc 3165 1.1 agc The MessageID SHOULD NOT appear unless it is in a multi-part 3166 1.1 agc message. If it appears at all, it MUST be computed from the 3167 1.1 agc finished (encrypted, signed, etc.) message in a deterministic 3168 1.1 agc fashion, rather than contain a purely random value. This is to 3169 1.1 agc allow the legitimate recipient to determine that the MessageID 3170 1.1 agc cannot serve as a covert means of leaking cryptographic key 3171 1.1 agc information. 3172 1.1 agc 3173 1.1 agc - "Hash", a comma-separated list of hash algorithms used in this 3174 1.1 agc message. This is used only in cleartext signed messages. 3175 1.1 agc 3176 1.1 agc - "Charset", a description of the character set that the plaintext 3177 1.1 agc is in. Please note that OpenPGP defines text to be in UTF-8. An 3178 1.1 agc implementation will get best results by translating into and out 3179 1.1 agc of UTF-8. However, there are many instances where this is easier 3180 1.1 agc said than done. Also, there are communities of users who have no 3181 1.1 agc need for UTF-8 because they are all happy with a character set 3182 1.1 agc like ISO Latin-5 or a Japanese character set. In such instances, 3183 1.1 agc an implementation MAY override the UTF-8 default by using this 3184 1.1 agc header key. An implementation MAY implement this key and any 3185 1.1 agc translations it cares to; an implementation MAY ignore it and 3186 1.1 agc assume all text is UTF-8. 3187 1.1 agc 3188 1.1 agc 3189 1.1 agc 3190 1.1 agc 3191 1.1 agc 3192 1.1 agc 3193 1.1 agc Callas, et al Standards Track [Page 56] 3194 1.1 agc 3196 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3197 1.1 agc 3198 1.1 agc 3199 1.1 agc The Armor Tail Line is composed in the same manner as the Armor 3200 1.1 agc Header Line, except the string "BEGIN" is replaced by the string 3201 1.1 agc "END". 3202 1.1 agc 3203 1.1 agc 6.3. Encoding Binary in Radix-64 3204 1.1 agc 3205 1.1 agc The encoding process represents 24-bit groups of input bits as output 3206 1.1 agc strings of 4 encoded characters. Proceeding from left to right, a 3207 1.1 agc 24-bit input group is formed by concatenating three 8-bit input 3208 1.1 agc groups. These 24 bits are then treated as four concatenated 6-bit 3209 1.1 agc groups, each of which is translated into a single digit in the 3210 1.1 agc Radix-64 alphabet. When encoding a bit stream with the Radix-64 3211 1.1 agc encoding, the bit stream must be presumed to be ordered with the most 3212 1.1 agc significant bit first. That is, the first bit in the stream will be 3213 1.1 agc the high-order bit in the first 8-bit octet, and the eighth bit will 3214 1.1 agc be the low-order bit in the first 8-bit octet, and so on. 3215 1.1 agc 3216 1.1 agc +--first octet--+-second octet--+--third octet--+ 3217 1.1 agc |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0| 3218 1.1 agc +-----------+---+-------+-------+---+-----------+ 3219 1.1 agc |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0| 3220 1.1 agc +--1.index--+--2.index--+--3.index--+--4.index--+ 3221 1.1 agc 3222 1.1 agc Each 6-bit group is used as an index into an array of 64 printable 3223 1.1 agc characters from the table below. The character referenced by the 3224 1.1 agc index is placed in the output string. 3225 1.1 agc 3226 1.1 agc Value Encoding Value Encoding Value Encoding Value Encoding 3227 1.1 agc 0 A 17 R 34 i 51 z 3228 1.1 agc 1 B 18 S 35 j 52 0 3229 1.1 agc 2 C 19 T 36 k 53 1 3230 1.1 agc 3 D 20 U 37 l 54 2 3231 1.1 agc 4 E 21 V 38 m 55 3 3232 1.1 agc 5 F 22 W 39 n 56 4 3233 1.1 agc 6 G 23 X 40 o 57 5 3234 1.1 agc 7 H 24 Y 41 p 58 6 3235 1.1 agc 8 I 25 Z 42 q 59 7 3236 1.1 agc 9 J 26 a 43 r 60 8 3237 1.1 agc 10 K 27 b 44 s 61 9 3238 1.1 agc 11 L 28 c 45 t 62 + 3239 1.1 agc 12 M 29 d 46 u 63 / 3240 1.1 agc 13 N 30 e 47 v 3241 1.1 agc 14 O 31 f 48 w (pad) = 3242 1.1 agc 15 P 32 g 49 x 3243 1.1 agc 16 Q 33 h 50 y 3244 1.1 agc 3245 1.1 agc The encoded output stream must be represented in lines of no more 3246 1.1 agc than 76 characters each. 3247 1.1 agc 3248 1.1 agc 3249 1.1 agc 3250 1.1 agc Callas, et al Standards Track [Page 57] 3251 1.1 agc 3253 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3254 1.1 agc 3255 1.1 agc 3256 1.1 agc Special processing is performed if fewer than 24 bits are available 3257 1.1 agc at the end of the data being encoded. There are three possibilities: 3258 1.1 agc 3259 1.1 agc 1. The last data group has 24 bits (3 octets). No special processing 3260 1.1 agc is needed. 3261 1.1 agc 3262 1.1 agc 2. The last data group has 16 bits (2 octets). The first two 6-bit 3263 1.1 agc groups are processed as above. The third (incomplete) data group 3264 1.1 agc has two zero-value bits added to it, and is processed as above. A 3265 1.1 agc pad character (=) is added to the output. 3266 1.1 agc 3267 1.1 agc 3. The last data group has 8 bits (1 octet). The first 6-bit group 3268 1.1 agc is processed as above. The second (incomplete) data group has 3269 1.1 agc four zero-value bits added to it, and is processed as above. Two 3270 1.1 agc pad characters (=) are added to the output. 3271 1.1 agc 3272 1.1 agc 6.4. Decoding Radix-64 3273 1.1 agc 3274 1.1 agc In Radix-64 data, characters other than those in the table, line 3275 1.1 agc breaks, and other white space probably indicate a transmission error, 3276 1.1 agc about which a warning message or even a message rejection might be 3277 1.1 agc appropriate under some circumstances. Decoding software must ignore 3278 1.1 agc all white space. 3279 1.1 agc 3280 1.1 agc Because it is used only for padding at the end of the data, the 3281 1.1 agc occurrence of any "=" characters may be taken as evidence that the 3282 1.1 agc end of the data has been reached (without truncation in transit). No 3283 1.1 agc such assurance is possible, however, when the number of octets 3284 1.1 agc transmitted was a multiple of three and no "=" characters are 3285 1.1 agc present. 3286 1.1 agc 3287 1.1 agc 3288 1.1 agc 3289 1.1 agc 3290 1.1 agc 3291 1.1 agc 3292 1.1 agc 3293 1.1 agc 3294 1.1 agc 3295 1.1 agc 3296 1.1 agc 3297 1.1 agc 3298 1.1 agc 3299 1.1 agc 3300 1.1 agc 3301 1.1 agc 3302 1.1 agc 3303 1.1 agc 3304 1.1 agc 3305 1.1 agc 3306 1.1 agc 3307 1.1 agc Callas, et al Standards Track [Page 58] 3308 1.1 agc 3310 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3311 1.1 agc 3312 1.1 agc 3313 1.1 agc 6.5. Examples of Radix-64 3314 1.1 agc 3315 1.1 agc Input data: 0x14FB9C03D97E 3316 1.1 agc Hex: 1 4 F B 9 C | 0 3 D 9 7 E 3317 1.1 agc 8-bit: 00010100 11111011 10011100 | 00000011 11011001 11111110 3318 1.1 agc 6-bit: 000101 001111 101110 011100 | 000000 111101 100111 111110 3319 1.1 agc Decimal: 5 15 46 28 0 61 37 62 3320 1.1 agc Output: F P u c A 9 l + 3321 1.1 agc Input data: 0x14FB9C03D9 3322 1.1 agc Hex: 1 4 F B 9 C | 0 3 D 9 3323 1.1 agc 8-bit: 00010100 11111011 10011100 | 00000011 11011001 3324 1.1 agc pad with 00 3325 1.1 agc 6-bit: 000101 001111 101110 011100 | 000000 111101 100100 3326 1.1 agc Decimal: 5 15 46 28 0 61 36 3327 1.1 agc pad with = 3328 1.1 agc Output: F P u c A 9 k = 3329 1.1 agc Input data: 0x14FB9C03 3330 1.1 agc Hex: 1 4 F B 9 C | 0 3 3331 1.1 agc 8-bit: 00010100 11111011 10011100 | 00000011 3332 1.1 agc pad with 0000 3333 1.1 agc 6-bit: 000101 001111 101110 011100 | 000000 110000 3334 1.1 agc Decimal: 5 15 46 28 0 48 3335 1.1 agc pad with = = 3336 1.1 agc Output: F P u c A w = = 3337 1.1 agc 3338 1.1 agc 6.6. Example of an ASCII Armored Message 3339 1.1 agc 3340 1.1 agc -----BEGIN PGP MESSAGE----- 3341 1.1 agc Version: OpenPrivacy 0.99 3342 1.1 agc 3343 1.1 agc yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS 3344 1.1 agc vBSFjNSiVHsuAA== 3345 1.1 agc =njUN 3346 1.1 agc -----END PGP MESSAGE----- 3347 1.1 agc 3348 1.1 agc Note that this example has extra indenting; an actual armored message 3349 1.1 agc would have no leading whitespace. 3350 1.1 agc 3351 1.1 agc 7. Cleartext Signature Framework 3352 1.1 agc 3353 1.1 agc It is desirable to be able to sign a textual octet stream without 3354 1.1 agc ASCII armoring the stream itself, so the signed text is still 3355 1.1 agc readable without special software. In order to bind a signature to 3356 1.1 agc such a cleartext, this framework is used. (Note that this framework 3357 1.1 agc is not intended to be reversible. RFC 3156 [RFC3156] defines another 3358 1.1 agc way to sign cleartext messages for environments that support MIME.) 3359 1.1 agc 3360 1.1 agc 3361 1.1 agc 3362 1.1 agc 3363 1.1 agc 3364 1.1 agc Callas, et al Standards Track [Page 59] 3365 1.1 agc 3367 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3368 1.1 agc 3369 1.1 agc 3370 1.1 agc The cleartext signed message consists of: 3371 1.1 agc 3372 1.1 agc - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a 3373 1.1 agc single line, 3374 1.1 agc 3375 1.1 agc - One or more "Hash" Armor Headers, 3376 1.1 agc 3377 1.1 agc - Exactly one empty line not included into the message digest, 3378 1.1 agc 3379 1.1 agc - The dash-escaped cleartext that is included into the message 3380 1.1 agc digest, 3381 1.1 agc 3382 1.1 agc - The ASCII armored signature(s) including the '-----BEGIN PGP 3383 1.1 agc SIGNATURE-----' Armor Header and Armor Tail Lines. 3384 1.1 agc 3385 1.1 agc If the "Hash" Armor Header is given, the specified message digest 3386 1.1 agc algorithm(s) are used for the signature. If there are no such 3387 1.1 agc headers, MD5 is used. If MD5 is the only hash used, then an 3388 1.1 agc implementation MAY omit this header for improved V2.x compatibility. 3389 1.1 agc If more than one message digest is used in the signature, the "Hash" 3390 1.1 agc armor header contains a comma-delimited list of used message digests. 3391 1.1 agc 3392 1.1 agc Current message digest names are described below with the algorithm 3393 1.1 agc IDs. 3394 1.1 agc 3395 1.1 agc An implementation SHOULD add a line break after the cleartext, but 3396 1.1 agc MAY omit it if the cleartext ends with a line break. This is for 3397 1.1 agc visual clarity. 3398 1.1 agc 3399 1.1 agc 7.1. Dash-Escaped Text 3400 1.1 agc 3401 1.1 agc The cleartext content of the message must also be dash-escaped. 3402 1.1 agc 3403 1.1 agc Dash-escaped cleartext is the ordinary cleartext where every line 3404 1.1 agc starting with a dash '-' (0x2D) is prefixed by the sequence dash '-' 3405 1.1 agc (0x2D) and space ' ' (0x20). This prevents the parser from 3406 1.1 agc recognizing armor headers of the cleartext itself. An implementation 3407 1.1 agc MAY dash-escape any line, SHOULD dash-escape lines commencing "From" 3408 1.1 agc followed by a space, and MUST dash-escape any line commencing in a 3409 1.1 agc dash. The message digest is computed using the cleartext itself, not 3410 1.1 agc the dash-escaped form. 3411 1.1 agc 3412 1.1 agc As with binary signatures on text documents, a cleartext signature is 3413 1.1 agc calculated on the text using canonical <CR><LF> line endings. The 3414 1.1 agc line ending (i.e., the <CR><LF>) before the '-----BEGIN PGP 3415 1.1 agc SIGNATURE-----' line that terminates the signed text is not 3416 1.1 agc considered part of the signed text. 3417 1.1 agc 3418 1.1 agc 3419 1.1 agc 3420 1.1 agc 3421 1.1 agc Callas, et al Standards Track [Page 60] 3422 1.1 agc 3424 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3425 1.1 agc 3426 1.1 agc 3427 1.1 agc When reversing dash-escaping, an implementation MUST strip the string 3428 1.1 agc "- " if it occurs at the beginning of a line, and SHOULD warn on "-" 3429 1.1 agc and any character other than a space at the beginning of a line. 3430 1.1 agc 3431 1.1 agc Also, any trailing whitespace -- spaces (0x20) and tabs (0x09) -- at 3432 1.1 agc the end of any line is removed when the cleartext signature is 3433 1.1 agc generated. 3434 1.1 agc 3435 1.1 agc 8. Regular Expressions 3436 1.1 agc 3437 1.1 agc A regular expression is zero or more branches, separated by '|'. It 3438 1.1 agc matches anything that matches one of the branches. 3439 1.1 agc 3440 1.1 agc A branch is zero or more pieces, concatenated. It matches a match 3441 1.1 agc for the first, followed by a match for the second, etc. 3442 1.1 agc 3443 1.1 agc A piece is an atom possibly followed by '*', '+', or '?'. An atom 3444 1.1 agc followed by '*' matches a sequence of 0 or more matches of the atom. 3445 1.1 agc An atom followed by '+' matches a sequence of 1 or more matches of 3446 1.1 agc the atom. An atom followed by '?' matches a match of the atom, or 3447 1.1 agc the null string. 3448 1.1 agc 3449 1.1 agc An atom is a regular expression in parentheses (matching a match for 3450 1.1 agc the regular expression), a range (see below), '.' (matching any 3451 1.1 agc single character), '^' (matching the null string at the beginning of 3452 1.1 agc the input string), '$' (matching the null string at the end of the 3453 1.1 agc input string), a '\' followed by a single character (matching that 3454 1.1 agc character), or a single character with no other significance 3455 1.1 agc (matching that character). 3456 1.1 agc 3457 1.1 agc A range is a sequence of characters enclosed in '[]'. It normally 3458 1.1 agc matches any single character from the sequence. If the sequence 3459 1.1 agc begins with '^', it matches any single character not from the rest of 3460 1.1 agc the sequence. If two characters in the sequence are separated 3461 1.1 agc by '-', this is shorthand for the full list of ASCII characters 3462 1.1 agc between them (e.g., '[0-9]' matches any decimal digit). To include a 3463 1.1 agc literal ']' in the sequence, make it the first character (following a 3464 1.1 agc possible '^'). To include a literal '-', make it the first or last 3465 1.1 agc character. 3466 1.1 agc 3467 1.1 agc 9. Constants 3468 1.1 agc 3469 1.1 agc This section describes the constants used in OpenPGP. 3470 1.1 agc 3471 1.1 agc Note that these tables are not exhaustive lists; an implementation 3472 1.1 agc MAY implement an algorithm not on these lists, so long as the 3473 1.1 agc algorithm numbers are chosen from the private or experimental 3474 1.1 agc algorithm range. 3475 1.1 agc 3476 1.1 agc 3477 1.1 agc 3478 1.1 agc Callas, et al Standards Track [Page 61] 3479 1.1 agc 3481 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3482 1.1 agc 3483 1.1 agc 3484 1.1 agc See the section "Notes on Algorithms" below for more discussion of 3485 1.1 agc the algorithms. 3486 1.1 agc 3487 1.1 agc 9.1. Public-Key Algorithms 3488 1.1 agc 3489 1.1 agc ID Algorithm 3490 1.1 agc -- --------- 3491 1.1 agc 1 - RSA (Encrypt or Sign) [HAC] 3492 1.1 agc 2 - RSA Encrypt-Only [HAC] 3493 1.1 agc 3 - RSA Sign-Only [HAC] 3494 1.1 agc 16 - Elgamal (Encrypt-Only) [ELGAMAL] [HAC] 3495 1.1 agc 17 - DSA (Digital Signature Algorithm) [FIPS186] [HAC] 3496 1.1 agc 18 - Reserved for Elliptic Curve 3497 1.1 agc 19 - Reserved for ECDSA 3498 1.1 agc 20 - Reserved (formerly Elgamal Encrypt or Sign) 3499 1.1 agc 21 - Reserved for Diffie-Hellman (X9.42, 3500 1.1 agc as defined for IETF-S/MIME) 3501 1.1 agc 100 to 110 - Private/Experimental algorithm 3502 1.1 agc 3503 1.1 agc Implementations MUST implement DSA for signatures, and Elgamal for 3504 1.1 agc encryption. Implementations SHOULD implement RSA keys (1). RSA 3505 1.1 agc Encrypt-Only (2) and RSA Sign-Only are deprecated and SHOULD NOT be 3506 1.1 agc generated, but may be interpreted. See Section 13.5. See Section 3507 1.1 agc 13.8 for notes on Elliptic Curve (18), ECDSA (19), Elgamal Encrypt or 3508 1.1 agc Sign (20), and X9.42 (21). Implementations MAY implement any other 3509 1.1 agc algorithm. 3510 1.1 agc 3511 1.1 agc 9.2. Symmetric-Key Algorithms 3512 1.1 agc 3513 1.1 agc ID Algorithm 3514 1.1 agc -- --------- 3515 1.1 agc 0 - Plaintext or unencrypted data 3516 1.1 agc 1 - IDEA [IDEA] 3517 1.1 agc 2 - TripleDES (DES-EDE, [SCHNEIER] [HAC] - 3518 1.1 agc 168 bit key derived from 192) 3519 1.1 agc 3 - CAST5 (128 bit key, as per [RFC2144]) 3520 1.1 agc 4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH] 3521 1.1 agc 5 - Reserved 3522 1.1 agc 6 - Reserved 3523 1.1 agc 7 - AES with 128-bit key [AES] 3524 1.1 agc 8 - AES with 192-bit key 3525 1.1 agc 9 - AES with 256-bit key 3526 1.1 agc 10 - Twofish with 256-bit key [TWOFISH] 3527 1.1 agc 100 to 110 - Private/Experimental algorithm 3528 1.1 agc 3529 1.1 agc Implementations MUST implement TripleDES. Implementations SHOULD 3530 1.1 agc implement AES-128 and CAST5. Implementations that interoperate with 3531 1.1 agc 3532 1.1 agc 3533 1.1 agc 3534 1.1 agc 3535 1.1 agc Callas, et al Standards Track [Page 62] 3536 1.1 agc 3538 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3539 1.1 agc 3540 1.1 agc 3541 1.1 agc PGP 2.6 or earlier need to support IDEA, as that is the only 3542 1.1 agc symmetric cipher those versions use. Implementations MAY implement 3543 1.1 agc any other algorithm. 3544 1.1 agc 3545 1.1 agc 9.3. Compression Algorithms 3546 1.1 agc 3547 1.1 agc ID Algorithm 3548 1.1 agc -- --------- 3549 1.1 agc 0 - Uncompressed 3550 1.1 agc 1 - ZIP [RFC1951] 3551 1.1 agc 2 - ZLIB [RFC1950] 3552 1.1 agc 3 - BZip2 [BZ2] 3553 1.1 agc 100 to 110 - Private/Experimental algorithm 3554 1.1 agc 3555 1.1 agc Implementations MUST implement uncompressed data. Implementations 3556 1.1 agc SHOULD implement ZIP. Implementations MAY implement any other 3557 1.1 agc algorithm. 3558 1.1 agc 3559 1.1 agc 9.4. Hash Algorithms 3560 1.1 agc 3561 1.1 agc ID Algorithm Text Name 3562 1.1 agc -- --------- --------- 3563 1.1 agc 1 - MD5 [HAC] "MD5" 3564 1.1 agc 2 - SHA-1 [FIPS180] "SHA1" 3565 1.1 agc 3 - RIPE-MD/160 [HAC] "RIPEMD160" 3566 1.1 agc 4 - Reserved 3567 1.1 agc 5 - Reserved 3568 1.1 agc 6 - Reserved 3569 1.1 agc 7 - Reserved 3570 1.1 agc 8 - SHA256 [FIPS180] "SHA256" 3571 1.1 agc 9 - SHA384 [FIPS180] "SHA384" 3572 1.1 agc 10 - SHA512 [FIPS180] "SHA512" 3573 1.1 agc 11 - SHA224 [FIPS180] "SHA224" 3574 1.1 agc 100 to 110 - Private/Experimental algorithm 3575 1.1 agc 3576 1.1 agc Implementations MUST implement SHA-1. Implementations MAY implement 3577 1.1 agc other algorithms. MD5 is deprecated. 3578 1.1 agc 3579 1.1 agc 10. IANA Considerations 3580 1.1 agc 3581 1.1 agc OpenPGP is highly parameterized, and consequently there are a number 3582 1.1 agc of considerations for allocating parameters for extensions. This 3583 1.1 agc section describes how IANA should look at extensions to the protocol 3584 1.1 agc as described in this document. 3585 1.1 agc 3586 1.1 agc 3587 1.1 agc 3588 1.1 agc 3589 1.1 agc 3590 1.1 agc 3591 1.1 agc 3592 1.1 agc Callas, et al Standards Track [Page 63] 3593 1.1 agc 3595 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3596 1.1 agc 3597 1.1 agc 3598 1.1 agc 10.1. New String-to-Key Specifier Types 3599 1.1 agc 3600 1.1 agc OpenPGP S2K specifiers contain a mechanism for new algorithms to turn 3601 1.1 agc a string into a key. This specification creates a registry of S2K 3602 1.1 agc specifier types. The registry includes the S2K type, the name of the 3603 1.1 agc S2K, and a reference to the defining specification. The initial 3604 1.1 agc values for this registry can be found in Section 3.7.1. Adding a new 3605 1.1 agc S2K specifier MUST be done through the IETF CONSENSUS method, as 3606 1.1 agc described in [RFC2434]. 3607 1.1 agc 3608 1.1 agc 10.2. New Packets 3609 1.1 agc 3610 1.1 agc Major new features of OpenPGP are defined through new packet types. 3611 1.1 agc This specification creates a registry of packet types. The registry 3612 1.1 agc includes the packet type, the name of the packet, and a reference to 3613 1.1 agc the defining specification. The initial values for this registry can 3614 1.1 agc be found in Section 4.3. Adding a new packet type MUST be done 3615 1.1 agc through the IETF CONSENSUS method, as described in [RFC2434]. 3616 1.1 agc 3617 1.1 agc 10.2.1. User Attribute Types 3618 1.1 agc 3619 1.1 agc The User Attribute packet permits an extensible mechanism for other 3620 1.1 agc types of certificate identification. This specification creates a 3621 1.1 agc registry of User Attribute types. The registry includes the User 3622 1.1 agc Attribute type, the name of the User Attribute, and a reference to 3623 1.1 agc the defining specification. The initial values for this registry can 3624 1.1 agc be found in Section 5.12. Adding a new User Attribute type MUST be 3625 1.1 agc done through the IETF CONSENSUS method, as described in [RFC2434]. 3626 1.1 agc 3627 1.1 agc 10.2.1.1. Image Format Subpacket Types 3628 1.1 agc 3629 1.1 agc Within User Attribute packets, there is an extensible mechanism for 3630 1.1 agc other types of image-based user attributes. This specification 3631 1.1 agc creates a registry of Image Attribute subpacket types. The registry 3632 1.1 agc includes the Image Attribute subpacket type, the name of the Image 3633 1.1 agc Attribute subpacket, and a reference to the defining specification. 3634 1.1 agc The initial values for this registry can be found in Section 5.12.1. 3635 1.1 agc Adding a new Image Attribute subpacket type MUST be done through the 3636 1.1 agc IETF CONSENSUS method, as described in [RFC2434]. 3637 1.1 agc 3638 1.1 agc 10.2.2. New Signature Subpackets 3639 1.1 agc 3640 1.1 agc OpenPGP signatures contain a mechanism for signed (or unsigned) data 3641 1.1 agc to be added to them for a variety of purposes in the Signature 3642 1.1 agc subpackets as discussed in Section 5.2.3.1. This specification 3643 1.1 agc creates a registry of Signature subpacket types. The registry 3644 1.1 agc includes the Signature subpacket type, the name of the subpacket, and 3645 1.1 agc a reference to the defining specification. The initial values for 3646 1.1 agc 3647 1.1 agc 3648 1.1 agc 3649 1.1 agc Callas, et al Standards Track [Page 64] 3650 1.1 agc 3652 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3653 1.1 agc 3654 1.1 agc 3655 1.1 agc this registry can be found in Section 5.2.3.1. Adding a new 3656 1.1 agc Signature subpacket MUST be done through the IETF CONSENSUS method, 3657 1.1 agc as described in [RFC2434]. 3658 1.1 agc 3659 1.1 agc 10.2.2.1. Signature Notation Data Subpackets 3660 1.1 agc 3661 1.1 agc OpenPGP signatures further contain a mechanism for extensions in 3662 1.1 agc signatures. These are the Notation Data subpackets, which contain a 3663 1.1 agc key/value pair. Notations contain a user space that is completely 3664 1.1 agc unmanaged and an IETF space. 3665 1.1 agc 3666 1.1 agc This specification creates a registry of Signature Notation Data 3667 1.1 agc types. The registry includes the Signature Notation Data type, the 3668 1.1 agc name of the Signature Notation Data, its allowed values, and a 3669 1.1 agc reference to the defining specification. The initial values for this 3670 1.1 agc registry can be found in Section 5.2.3.16. Adding a new Signature 3671 1.1 agc Notation Data subpacket MUST be done through the EXPERT REVIEW 3672 1.1 agc method, as described in [RFC2434]. 3673 1.1 agc 3674 1.1 agc 10.2.2.2. Key Server Preference Extensions 3675 1.1 agc 3676 1.1 agc OpenPGP signatures contain a mechanism for preferences to be 3677 1.1 agc specified about key servers. This specification creates a registry 3678 1.1 agc of key server preferences. The registry includes the key server 3679 1.1 agc preference, the name of the preference, and a reference to the 3680 1.1 agc defining specification. The initial values for this registry can be 3681 1.1 agc found in Section 5.2.3.17. Adding a new key server preference MUST 3682 1.1 agc be done through the IETF CONSENSUS method, as described in [RFC2434]. 3683 1.1 agc 3684 1.1 agc 10.2.2.3. Key Flags Extensions 3685 1.1 agc 3686 1.1 agc OpenPGP signatures contain a mechanism for flags to be specified 3687 1.1 agc about key usage. This specification creates a registry of key usage 3688 1.1 agc flags. The registry includes the key flags value, the name of the 3689 1.1 agc flag, and a reference to the defining specification. The initial 3690 1.1 agc values for this registry can be found in Section 5.2.3.21. Adding a 3691 1.1 agc new key usage flag MUST be done through the IETF CONSENSUS method, as 3692 1.1 agc described in [RFC2434]. 3693 1.1 agc 3694 1.1 agc 10.2.2.4. Reason for Revocation Extensions 3695 1.1 agc 3696 1.1 agc OpenPGP signatures contain a mechanism for flags to be specified 3697 1.1 agc about why a key was revoked. This specification creates a registry 3698 1.1 agc of "Reason for Revocation" flags. The registry includes the "Reason 3699 1.1 agc for Revocation" flags value, the name of the flag, and a reference to 3700 1.1 agc the defining specification. The initial values for this registry can 3701 1.1 agc be found in Section 5.2.3.23. Adding a new feature flag MUST be done 3702 1.1 agc through the IETF CONSENSUS method, as described in [RFC2434]. 3703 1.1 agc 3704 1.1 agc 3705 1.1 agc 3706 1.1 agc Callas, et al Standards Track [Page 65] 3707 1.1 agc 3709 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3710 1.1 agc 3711 1.1 agc 3712 1.1 agc 10.2.2.5. Implementation Features 3713 1.1 agc 3714 1.1 agc OpenPGP signatures contain a mechanism for flags to be specified 3715 1.1 agc stating which optional features an implementation supports. This 3716 1.1 agc specification creates a registry of feature-implementation flags. 3717 1.1 agc The registry includes the feature-implementation flags value, the 3718 1.1 agc name of the flag, and a reference to the defining specification. The 3719 1.1 agc initial values for this registry can be found in Section 5.2.3.24. 3720 1.1 agc Adding a new feature-implementation flag MUST be done through the 3721 1.1 agc IETF CONSENSUS method, as described in [RFC2434]. 3722 1.1 agc 3723 1.1 agc Also see Section 13.12 for more information about when feature flags 3724 1.1 agc are needed. 3725 1.1 agc 3726 1.1 agc 10.2.3. New Packet Versions 3727 1.1 agc 3728 1.1 agc The core OpenPGP packets all have version numbers, and can be revised 3729 1.1 agc by introducing a new version of an existing packet. This 3730 1.1 agc specification creates a registry of packet types. The registry 3731 1.1 agc includes the packet type, the number of the version, and a reference 3732 1.1 agc to the defining specification. The initial values for this registry 3733 1.1 agc can be found in Section 5. Adding a new packet version MUST be done 3734 1.1 agc through the IETF CONSENSUS method, as described in [RFC2434]. 3735 1.1 agc 3736 1.1 agc 10.3. New Algorithms 3737 1.1 agc 3738 1.1 agc Section 9 lists the core algorithms that OpenPGP uses. Adding in a 3739 1.1 agc new algorithm is usually simple. For example, adding in a new 3740 1.1 agc symmetric cipher usually would not need anything more than allocating 3741 1.1 agc a constant for that cipher. If that cipher had other than a 64-bit 3742 1.1 agc or 128-bit block size, there might need to be additional 3743 1.1 agc documentation describing how OpenPGP-CFB mode would be adjusted. 3744 1.1 agc Similarly, when DSA was expanded from a maximum of 1024-bit public 3745 1.1 agc keys to 3072-bit public keys, the revision of FIPS 186 contained 3746 1.1 agc enough information itself to allow implementation. Changes to this 3747 1.1 agc document were made mainly for emphasis. 3748 1.1 agc 3749 1.1 agc 10.3.1. Public-Key Algorithms 3750 1.1 agc 3751 1.1 agc OpenPGP specifies a number of public-key algorithms. This 3752 1.1 agc specification creates a registry of public-key algorithm identifiers. 3753 1.1 agc The registry includes the algorithm name, its key sizes and 3754 1.1 agc parameters, and a reference to the defining specification. The 3755 1.1 agc initial values for this registry can be found in Section 9. Adding a 3756 1.1 agc new public-key algorithm MUST be done through the IETF CONSENSUS 3757 1.1 agc method, as described in [RFC2434]. 3758 1.1 agc 3759 1.1 agc 3760 1.1 agc 3761 1.1 agc 3762 1.1 agc 3763 1.1 agc Callas, et al Standards Track [Page 66] 3764 1.1 agc 3766 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3767 1.1 agc 3768 1.1 agc 3769 1.1 agc 10.3.2. Symmetric-Key Algorithms 3770 1.1 agc 3771 1.1 agc OpenPGP specifies a number of symmetric-key algorithms. This 3772 1.1 agc specification creates a registry of symmetric-key algorithm 3773 1.1 agc identifiers. The registry includes the algorithm name, its key sizes 3774 1.1 agc and block size, and a reference to the defining specification. The 3775 1.1 agc initial values for this registry can be found in Section 9. Adding a 3776 1.1 agc new symmetric-key algorithm MUST be done through the IETF CONSENSUS 3777 1.1 agc method, as described in [RFC2434]. 3778 1.1 agc 3779 1.1 agc 10.3.3. Hash Algorithms 3780 1.1 agc 3781 1.1 agc OpenPGP specifies a number of hash algorithms. This specification 3782 1.1 agc creates a registry of hash algorithm identifiers. The registry 3783 1.1 agc includes the algorithm name, a text representation of that name, its 3784 1.1 agc block size, an OID hash prefix, and a reference to the defining 3785 1.1 agc specification. The initial values for this registry can be found in 3786 1.1 agc Section 9 for the algorithm identifiers and text names, and Section 3787 1.1 agc 5.2.2 for the OIDs and expanded signature prefixes. Adding a new 3788 1.1 agc hash algorithm MUST be done through the IETF CONSENSUS method, as 3789 1.1 agc described in [RFC2434]. 3790 1.1 agc 3791 1.1 agc 10.3.4. Compression Algorithms 3792 1.1 agc 3793 1.1 agc OpenPGP specifies a number of compression algorithms. This 3794 1.1 agc specification creates a registry of compression algorithm 3795 1.1 agc identifiers. The registry includes the algorithm name and a 3796 1.1 agc reference to the defining specification. The initial values for this 3797 1.1 agc registry can be found in Section 9.3. Adding a new compression key 3798 1.1 agc algorithm MUST be done through the IETF CONSENSUS method, as 3799 1.1 agc described in [RFC2434]. 3800 1.1 agc 3801 1.1 agc 11. Packet Composition 3802 1.1 agc 3803 1.1 agc OpenPGP packets are assembled into sequences in order to create 3804 1.1 agc messages and to transfer keys. Not all possible packet sequences are 3805 1.1 agc meaningful and correct. This section describes the rules for how 3806 1.1 agc packets should be placed into sequences. 3807 1.1 agc 3808 1.1 agc 11.1. Transferable Public Keys 3809 1.1 agc 3810 1.1 agc OpenPGP users may transfer public keys. The essential elements of a 3811 1.1 agc transferable public key are as follows: 3812 1.1 agc 3813 1.1 agc - One Public-Key packet 3814 1.1 agc 3815 1.1 agc - Zero or more revocation signatures 3816 1.1 agc 3817 1.1 agc 3818 1.1 agc 3819 1.1 agc 3820 1.1 agc Callas, et al Standards Track [Page 67] 3821 1.1 agc 3823 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3824 1.1 agc 3825 1.1 agc 3826 1.1 agc - One or more User ID packets 3827 1.1 agc 3828 1.1 agc - After each User ID packet, zero or more Signature packets 3829 1.1 agc (certifications) 3830 1.1 agc 3831 1.1 agc - Zero or more User Attribute packets 3832 1.1 agc 3833 1.1 agc - After each User Attribute packet, zero or more Signature packets 3834 1.1 agc (certifications) 3835 1.1 agc 3836 1.1 agc - Zero or more Subkey packets 3837 1.1 agc 3838 1.1 agc - After each Subkey packet, one Signature packet, plus optionally a 3839 1.1 agc revocation 3840 1.1 agc 3841 1.1 agc The Public-Key packet occurs first. Each of the following User ID 3842 1.1 agc packets provides the identity of the owner of this public key. If 3843 1.1 agc there are multiple User ID packets, this corresponds to multiple 3844 1.1 agc means of identifying the same unique individual user; for example, a 3845 1.1 agc user may have more than one email address, and construct a User ID 3846 1.1 agc for each one. 3847 1.1 agc 3848 1.1 agc Immediately following each User ID packet, there are zero or more 3849 1.1 agc Signature packets. Each Signature packet is calculated on the 3850 1.1 agc immediately preceding User ID packet and the initial Public-Key 3851 1.1 agc packet. The signature serves to certify the corresponding public key 3852 1.1 agc and User ID. In effect, the signer is testifying to his or her 3853 1.1 agc belief that this public key belongs to the user identified by this 3854 1.1 agc User ID. 3855 1.1 agc 3856 1.1 agc Within the same section as the User ID packets, there are zero or 3857 1.1 agc more User Attribute packets. Like the User ID packets, a User 3858 1.1 agc Attribute packet is followed by zero or more Signature packets 3859 1.1 agc calculated on the immediately preceding User Attribute packet and the 3860 1.1 agc initial Public-Key packet. 3861 1.1 agc 3862 1.1 agc User Attribute packets and User ID packets may be freely intermixed 3863 1.1 agc in this section, so long as the signatures that follow them are 3864 1.1 agc maintained on the proper User Attribute or User ID packet. 3865 1.1 agc 3866 1.1 agc After the User ID packet or Attribute packet, there may be zero or 3867 1.1 agc more Subkey packets. In general, subkeys are provided in cases where 3868 1.1 agc the top-level public key is a signature-only key. However, any V4 3869 1.1 agc key may have subkeys, and the subkeys may be encryption-only keys, 3870 1.1 agc signature-only keys, or general-purpose keys. V3 keys MUST NOT have 3871 1.1 agc subkeys. 3872 1.1 agc 3873 1.1 agc 3874 1.1 agc 3875 1.1 agc 3876 1.1 agc 3877 1.1 agc Callas, et al Standards Track [Page 68] 3878 1.1 agc 3880 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3881 1.1 agc 3882 1.1 agc 3883 1.1 agc Each Subkey packet MUST be followed by one Signature packet, which 3884 1.1 agc should be a subkey binding signature issued by the top-level key. 3885 1.1 agc For subkeys that can issue signatures, the subkey binding signature 3886 1.1 agc MUST contain an Embedded Signature subpacket with a primary key 3887 1.1 agc binding signature (0x19) issued by the subkey on the top-level key. 3888 1.1 agc 3889 1.1 agc Subkey and Key packets may each be followed by a revocation Signature 3890 1.1 agc packet to indicate that the key is revoked. Revocation signatures 3891 1.1 agc are only accepted if they are issued by the key itself, or by a key 3892 1.1 agc that is authorized to issue revocations via a Revocation Key 3893 1.1 agc subpacket in a self-signature by the top-level key. 3894 1.1 agc 3895 1.1 agc Transferable public-key packet sequences may be concatenated to allow 3896 1.1 agc transferring multiple public keys in one operation. 3897 1.1 agc 3898 1.1 agc 11.2. Transferable Secret Keys 3899 1.1 agc 3900 1.1 agc OpenPGP users may transfer secret keys. The format of a transferable 3901 1.1 agc secret key is the same as a transferable public key except that 3902 1.1 agc secret-key and secret-subkey packets are used instead of the public 3903 1.1 agc key and public-subkey packets. Implementations SHOULD include self- 3904 1.1 agc signatures on any user IDs and subkeys, as this allows for a complete 3905 1.1 agc public key to be automatically extracted from the transferable secret 3906 1.1 agc key. Implementations MAY choose to omit the self-signatures, 3907 1.1 agc especially if a transferable public key accompanies the transferable 3908 1.1 agc secret key. 3909 1.1 agc 3910 1.1 agc 11.3. OpenPGP Messages 3911 1.1 agc 3912 1.1 agc An OpenPGP message is a packet or sequence of packets that 3913 1.1 agc corresponds to the following grammatical rules (comma represents 3914 1.1 agc sequential composition, and vertical bar separates alternatives): 3915 1.1 agc 3916 1.1 agc OpenPGP Message :- Encrypted Message | Signed Message | 3917 1.1 agc Compressed Message | Literal Message. 3918 1.1 agc 3919 1.1 agc Compressed Message :- Compressed Data Packet. 3920 1.1 agc 3921 1.1 agc Literal Message :- Literal Data Packet. 3922 1.1 agc 3923 1.1 agc ESK :- Public-Key Encrypted Session Key Packet | 3924 1.1 agc Symmetric-Key Encrypted Session Key Packet. 3925 1.1 agc 3926 1.1 agc ESK Sequence :- ESK | ESK Sequence, ESK. 3927 1.1 agc 3928 1.1 agc Encrypted Data :- Symmetrically Encrypted Data Packet | 3929 1.1 agc Symmetrically Encrypted Integrity Protected Data Packet 3930 1.1 agc 3931 1.1 agc 3932 1.1 agc 3933 1.1 agc 3934 1.1 agc Callas, et al Standards Track [Page 69] 3935 1.1 agc 3937 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3938 1.1 agc 3939 1.1 agc 3940 1.1 agc Encrypted Message :- Encrypted Data | ESK Sequence, Encrypted Data. 3941 1.1 agc 3942 1.1 agc One-Pass Signed Message :- One-Pass Signature Packet, 3943 1.1 agc OpenPGP Message, Corresponding Signature Packet. 3944 1.1 agc 3945 1.1 agc Signed Message :- Signature Packet, OpenPGP Message | 3946 1.1 agc One-Pass Signed Message. 3947 1.1 agc 3948 1.1 agc In addition, decrypting a Symmetrically Encrypted Data packet or a 3949 1.1 agc Symmetrically Encrypted Integrity Protected Data packet as well as 3950 1.1 agc decompressing a Compressed Data packet must yield a valid OpenPGP 3951 1.1 agc Message. 3952 1.1 agc 3953 1.1 agc 11.4. Detached Signatures 3954 1.1 agc 3955 1.1 agc Some OpenPGP applications use so-called "detached signatures". For 3956 1.1 agc example, a program bundle may contain a file, and with it a second 3957 1.1 agc file that is a detached signature of the first file. These detached 3958 1.1 agc signatures are simply a Signature packet stored separately from the 3959 1.1 agc data for which they are a signature. 3960 1.1 agc 3961 1.1 agc 12. Enhanced Key Formats 3962 1.1 agc 3963 1.1 agc 12.1. Key Structures 3964 1.1 agc 3965 1.1 agc The format of an OpenPGP V3 key is as follows. Entries in square 3966 1.1 agc brackets are optional and ellipses indicate repetition. 3967 1.1 agc 3968 1.1 agc RSA Public Key 3969 1.1 agc [Revocation Self Signature] 3970 1.1 agc User ID [Signature ...] 3971 1.1 agc [User ID [Signature ...] ...] 3972 1.1 agc 3973 1.1 agc Each signature certifies the RSA public key and the preceding User 3974 1.1 agc ID. The RSA public key can have many User IDs and each User ID can 3975 1.1 agc have many signatures. V3 keys are deprecated. Implementations MUST 3976 1.1 agc NOT generate new V3 keys, but MAY continue to use existing ones. 3977 1.1 agc 3978 1.1 agc The format of an OpenPGP V4 key that uses multiple public keys is 3979 1.1 agc similar except that the other keys are added to the end as "subkeys" 3980 1.1 agc of the primary key. 3981 1.1 agc 3982 1.1 agc 3983 1.1 agc 3984 1.1 agc 3985 1.1 agc 3986 1.1 agc 3987 1.1 agc 3988 1.1 agc 3989 1.1 agc 3990 1.1 agc 3991 1.1 agc Callas, et al Standards Track [Page 70] 3992 1.1 agc 3994 1.1 agc RFC 4880 OpenPGP Message Format November 2007 3995 1.1 agc 3996 1.1 agc 3997 1.1 agc Primary-Key 3998 1.1 agc [Revocation Self Signature] 3999 1.1 agc [Direct Key Signature...] 4000 1.1 agc User ID [Signature ...] 4001 1.1 agc [User ID [Signature ...] ...] 4002 1.1 agc [User Attribute [Signature ...] ...] 4003 1.1 agc [[Subkey [Binding-Signature-Revocation] 4004 1.1 agc Primary-Key-Binding-Signature] ...] 4005 1.1 agc 4006 1.1 agc A subkey always has a single signature after it that is issued using 4007 1.1 agc the primary key to tie the two keys together. This binding signature 4008 1.1 agc may be in either V3 or V4 format, but SHOULD be V4. Subkeys that can 4009 1.1 agc issue signatures MUST have a V4 binding signature due to the REQUIRED 4010 1.1 agc embedded primary key binding signature. 4011 1.1 agc 4012 1.1 agc In the above diagram, if the binding signature of a subkey has been 4013 1.1 agc revoked, the revoked key may be removed, leaving only one key. 4014 1.1 agc 4015 1.1 agc In a V4 key, the primary key MUST be a key capable of certification. 4016 1.1 agc The subkeys may be keys of any other type. There may be other 4017 1.1 agc constructions of V4 keys, too. For example, there may be a single- 4018 1.1 agc key RSA key in V4 format, a DSA primary key with an RSA encryption 4019 1.1 agc key, or RSA primary key with an Elgamal subkey, etc. 4020 1.1 agc 4021 1.1 agc It is also possible to have a signature-only subkey. This permits a 4022 1.1 agc primary key that collects certifications (key signatures), but is 4023 1.1 agc used only for certifying subkeys that are used for encryption and 4024 1.1 agc signatures. 4025 1.1 agc 4026 1.1 agc 12.2. Key IDs and Fingerprints 4027 1.1 agc 4028 1.1 agc For a V3 key, the eight-octet Key ID consists of the low 64 bits of 4029 1.1 agc the public modulus of the RSA key. 4030 1.1 agc 4031 1.1 agc The fingerprint of a V3 key is formed by hashing the body (but not 4032 1.1 agc the two-octet length) of the MPIs that form the key material (public 4033 1.1 agc modulus n, followed by exponent e) with MD5. Note that both V3 keys 4034 1.1 agc and MD5 are deprecated. 4035 1.1 agc 4036 1.1 agc A V4 fingerprint is the 160-bit SHA-1 hash of the octet 0x99, 4037 1.1 agc followed by the two-octet packet length, followed by the entire 4038 1.1 agc Public-Key packet starting with the version field. The Key ID is the 4039 1.1 agc low-order 64 bits of the fingerprint. Here are the fields of the 4040 1.1 agc hash material, with the example of a DSA key: 4041 1.1 agc 4042 1.1 agc a.1) 0x99 (1 octet) 4043 1.1 agc 4044 1.1 agc a.2) high-order length octet of (b)-(e) (1 octet) 4045 1.1 agc 4046 1.1 agc 4047 1.1 agc 4048 1.1 agc Callas, et al Standards Track [Page 71] 4049 1.1 agc 4051 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4052 1.1 agc 4053 1.1 agc 4054 1.1 agc a.3) low-order length octet of (b)-(e) (1 octet) 4055 1.1 agc 4056 1.1 agc b) version number = 4 (1 octet); 4057 1.1 agc 4058 1.1 agc c) timestamp of key creation (4 octets); 4059 1.1 agc 4060 1.1 agc d) algorithm (1 octet): 17 = DSA (example); 4061 1.1 agc 4062 1.1 agc e) Algorithm-specific fields. 4063 1.1 agc 4064 1.1 agc Algorithm-Specific Fields for DSA keys (example): 4065 1.1 agc 4066 1.1 agc e.1) MPI of DSA prime p; 4067 1.1 agc 4068 1.1 agc e.2) MPI of DSA group order q (q is a prime divisor of p-1); 4069 1.1 agc 4070 1.1 agc e.3) MPI of DSA group generator g; 4071 1.1 agc 4072 1.1 agc e.4) MPI of DSA public-key value y (= g**x mod p where x is secret). 4073 1.1 agc 4074 1.1 agc Note that it is possible for there to be collisions of Key IDs -- two 4075 1.1 agc different keys with the same Key ID. Note that there is a much 4076 1.1 agc smaller, but still non-zero, probability that two different keys have 4077 1.1 agc the same fingerprint. 4078 1.1 agc 4079 1.1 agc Also note that if V3 and V4 format keys share the same RSA key 4080 1.1 agc material, they will have different Key IDs as well as different 4081 1.1 agc fingerprints. 4082 1.1 agc 4083 1.1 agc Finally, the Key ID and fingerprint of a subkey are calculated in the 4084 1.1 agc same way as for a primary key, including the 0x99 as the first octet 4085 1.1 agc (even though this is not a valid packet ID for a public subkey). 4086 1.1 agc 4087 1.1 agc 13. Notes on Algorithms 4088 1.1 agc 4089 1.1 agc 13.1. PKCS#1 Encoding in OpenPGP 4090 1.1 agc 4091 1.1 agc This standard makes use of the PKCS#1 functions EME-PKCS1-v1_5 and 4092 1.1 agc EMSA-PKCS1-v1_5. However, the calling conventions of these functions 4093 1.1 agc has changed in the past. To avoid potential confusion and 4094 1.1 agc interoperability problems, we are including local copies in this 4095 1.1 agc document, adapted from those in PKCS#1 v2.1 [RFC3447]. RFC 3447 4096 1.1 agc should be treated as the ultimate authority on PKCS#1 for OpenPGP. 4097 1.1 agc Nonetheless, we believe that there is value in having a self- 4098 1.1 agc contained document that avoids problems in the future with needed 4099 1.1 agc changes in the conventions. 4100 1.1 agc 4101 1.1 agc 4102 1.1 agc 4103 1.1 agc 4104 1.1 agc 4105 1.1 agc Callas, et al Standards Track [Page 72] 4106 1.1 agc 4108 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4109 1.1 agc 4110 1.1 agc 4111 1.1 agc 13.1.1. EME-PKCS1-v1_5-ENCODE 4112 1.1 agc 4113 1.1 agc Input: 4114 1.1 agc 4115 1.1 agc k = the length in octets of the key modulus 4116 1.1 agc 4117 1.1 agc M = message to be encoded, an octet string of length mLen, where 4118 1.1 agc mLen <= k - 11 4119 1.1 agc 4120 1.1 agc Output: 4121 1.1 agc 4122 1.1 agc EM = encoded message, an octet string of length k 4123 1.1 agc 4124 1.1 agc Error: "message too long" 4125 1.1 agc 4126 1.1 agc 1. Length checking: If mLen > k - 11, output "message too long" and 4127 1.1 agc stop. 4128 1.1 agc 4129 1.1 agc 2. Generate an octet string PS of length k - mLen - 3 consisting of 4130 1.1 agc pseudo-randomly generated nonzero octets. The length of PS will 4131 1.1 agc be at least eight octets. 4132 1.1 agc 4133 1.1 agc 3. Concatenate PS, the message M, and other padding to form an 4134 1.1 agc encoded message EM of length k octets as 4135 1.1 agc 4136 1.1 agc EM = 0x00 || 0x02 || PS || 0x00 || M. 4137 1.1 agc 4138 1.1 agc 4. Output EM. 4139 1.1 agc 4140 1.1 agc 13.1.2. EME-PKCS1-v1_5-DECODE 4141 1.1 agc 4142 1.1 agc Input: 4143 1.1 agc 4144 1.1 agc EM = encoded message, an octet string 4145 1.1 agc 4146 1.1 agc Output: 4147 1.1 agc 4148 1.1 agc M = message, an octet string 4149 1.1 agc 4150 1.1 agc Error: "decryption error" 4151 1.1 agc 4152 1.1 agc To decode an EME-PKCS1_v1_5 message, separate the encoded message EM 4153 1.1 agc into an octet string PS consisting of nonzero octets and a message M 4154 1.1 agc as follows 4155 1.1 agc 4156 1.1 agc EM = 0x00 || 0x02 || PS || 0x00 || M. 4157 1.1 agc 4158 1.1 agc 4159 1.1 agc 4160 1.1 agc 4161 1.1 agc 4162 1.1 agc Callas, et al Standards Track [Page 73] 4163 1.1 agc 4165 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4166 1.1 agc 4167 1.1 agc 4168 1.1 agc If the first octet of EM does not have hexadecimal value 0x00, if the 4169 1.1 agc second octet of EM does not have hexadecimal value 0x02, if there is 4170 1.1 agc no octet with hexadecimal value 0x00 to separate PS from M, or if the 4171 1.1 agc length of PS is less than 8 octets, output "decryption error" and 4172 1.1 agc stop. See also the security note in Section 14 regarding differences 4173 1.1 agc in reporting between a decryption error and a padding error. 4174 1.1 agc 4175 1.1 agc 13.1.3. EMSA-PKCS1-v1_5 4176 1.1 agc 4177 1.1 agc This encoding method is deterministic and only has an encoding 4178 1.1 agc operation. 4179 1.1 agc 4180 1.1 agc Option: 4181 1.1 agc 4182 1.1 agc Hash - a hash function in which hLen denotes the length in octets of 4183 1.1 agc the hash function output 4184 1.1 agc 4185 1.1 agc Input: 4186 1.1 agc 4187 1.1 agc M = message to be encoded 4188 1.1 agc 4189 1.1 agc mL = intended length in octets of the encoded message, at least tLen 4190 1.1 agc + 11, where tLen is the octet length of the DER encoding T of a 4191 1.1 agc certain value computed during the encoding operation 4192 1.1 agc 4193 1.1 agc Output: 4194 1.1 agc 4195 1.1 agc EM = encoded message, an octet string of length emLen 4196 1.1 agc 4197 1.1 agc Errors: "message too long"; "intended encoded message length too 4198 1.1 agc short" 4199 1.1 agc 4200 1.1 agc Steps: 4201 1.1 agc 4202 1.1 agc 1. Apply the hash function to the message M to produce a hash value 4203 1.1 agc H: 4204 1.1 agc 4205 1.1 agc H = Hash(M). 4206 1.1 agc 4207 1.1 agc If the hash function outputs "message too long," output "message 4208 1.1 agc too long" and stop. 4209 1.1 agc 4210 1.1 agc 2. Using the list in Section 5.2.2, produce an ASN.1 DER value for 4211 1.1 agc the hash function used. Let T be the full hash prefix from 4212 1.1 agc Section 5.2.2, and let tLen be the length in octets of T. 4213 1.1 agc 4214 1.1 agc 3. If emLen < tLen + 11, output "intended encoded message length 4215 1.1 agc too short" and stop. 4216 1.1 agc 4217 1.1 agc 4218 1.1 agc 4219 1.1 agc Callas, et al Standards Track [Page 74] 4220 1.1 agc 4222 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4223 1.1 agc 4224 1.1 agc 4225 1.1 agc 4. Generate an octet string PS consisting of emLen - tLen - 3 4226 1.1 agc octets with hexadecimal value 0xFF. The length of PS will be at 4227 1.1 agc least 8 octets. 4228 1.1 agc 4229 1.1 agc 5. Concatenate PS, the hash prefix T, and other padding to form the 4230 1.1 agc encoded message EM as 4231 1.1 agc 4232 1.1 agc EM = 0x00 || 0x01 || PS || 0x00 || T. 4233 1.1 agc 4234 1.1 agc 6. Output EM. 4235 1.1 agc 4236 1.1 agc 13.2. Symmetric Algorithm Preferences 4237 1.1 agc 4238 1.1 agc The symmetric algorithm preference is an ordered list of algorithms 4239 1.1 agc that the keyholder accepts. Since it is found on a self-signature, 4240 1.1 agc it is possible that a keyholder may have multiple, different 4241 1.1 agc preferences. For example, Alice may have TripleDES only specified 4242 1.1 agc for "alice (a] work.com" but CAST5, Blowfish, and TripleDES specified for 4243 1.1 agc "alice (a] home.org". Note that it is also possible for preferences to 4244 1.1 agc be in a subkey's binding signature. 4245 1.1 agc 4246 1.1 agc Since TripleDES is the MUST-implement algorithm, if it is not 4247 1.1 agc explicitly in the list, it is tacitly at the end. However, it is 4248 1.1 agc good form to place it there explicitly. Note also that if an 4249 1.1 agc implementation does not implement the preference, then it is 4250 1.1 agc implicitly a TripleDES-only implementation. 4251 1.1 agc 4252 1.1 agc An implementation MUST NOT use a symmetric algorithm that is not in 4253 1.1 agc the recipient's preference list. When encrypting to more than one 4254 1.1 agc recipient, the implementation finds a suitable algorithm by taking 4255 1.1 agc the intersection of the preferences of the recipients. Note that the 4256 1.1 agc MUST-implement algorithm, TripleDES, ensures that the intersection is 4257 1.1 agc not null. The implementation may use any mechanism to pick an 4258 1.1 agc algorithm in the intersection. 4259 1.1 agc 4260 1.1 agc If an implementation can decrypt a message that a keyholder doesn't 4261 1.1 agc have in their preferences, the implementation SHOULD decrypt the 4262 1.1 agc message anyway, but MUST warn the keyholder that the protocol has 4263 1.1 agc been violated. For example, suppose that Alice, above, has software 4264 1.1 agc that implements all algorithms in this specification. Nonetheless, 4265 1.1 agc she prefers subsets for work or home. If she is sent a message 4266 1.1 agc encrypted with IDEA, which is not in her preferences, the software 4267 1.1 agc warns her that someone sent her an IDEA-encrypted message, but it 4268 1.1 agc would ideally decrypt it anyway. 4269 1.1 agc 4270 1.1 agc 4271 1.1 agc 4272 1.1 agc 4273 1.1 agc 4274 1.1 agc 4275 1.1 agc 4276 1.1 agc Callas, et al Standards Track [Page 75] 4277 1.1 agc 4279 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4280 1.1 agc 4281 1.1 agc 4282 1.1 agc 13.3. Other Algorithm Preferences 4283 1.1 agc 4284 1.1 agc Other algorithm preferences work similarly to the symmetric algorithm 4285 1.1 agc preference, in that they specify which algorithms the keyholder 4286 1.1 agc accepts. There are two interesting cases that other comments need to 4287 1.1 agc be made about, though, the compression preferences and the hash 4288 1.1 agc preferences. 4289 1.1 agc 4290 1.1 agc 13.3.1. Compression Preferences 4291 1.1 agc 4292 1.1 agc Compression has been an integral part of PGP since its first days. 4293 1.1 agc OpenPGP and all previous versions of PGP have offered compression. 4294 1.1 agc In this specification, the default is for messages to be compressed, 4295 1.1 agc although an implementation is not required to do so. Consequently, 4296 1.1 agc the compression preference gives a way for a keyholder to request 4297 1.1 agc that messages not be compressed, presumably because they are using a 4298 1.1 agc minimal implementation that does not include compression. 4299 1.1 agc Additionally, this gives a keyholder a way to state that it can 4300 1.1 agc support alternate algorithms. 4301 1.1 agc 4302 1.1 agc Like the algorithm preferences, an implementation MUST NOT use an 4303 1.1 agc algorithm that is not in the preference vector. If the preferences 4304 1.1 agc are not present, then they are assumed to be [ZIP(1), 4305 1.1 agc Uncompressed(0)]. 4306 1.1 agc 4307 1.1 agc Additionally, an implementation MUST implement this preference to the 4308 1.1 agc degree of recognizing when to send an uncompressed message. A robust 4309 1.1 agc implementation would satisfy this requirement by looking at the 4310 1.1 agc recipient's preference and acting accordingly. A minimal 4311 1.1 agc implementation can satisfy this requirement by never generating a 4312 1.1 agc compressed message, since all implementations can handle messages 4313 1.1 agc that have not been compressed. 4314 1.1 agc 4315 1.1 agc 13.3.2. Hash Algorithm Preferences 4316 1.1 agc 4317 1.1 agc Typically, the choice of a hash algorithm is something the signer 4318 1.1 agc does, rather than the verifier, because a signer rarely knows who is 4319 1.1 agc going to be verifying the signature. This preference, though, allows 4320 1.1 agc a protocol based upon digital signatures ease in negotiation. 4321 1.1 agc 4322 1.1 agc Thus, if Alice is authenticating herself to Bob with a signature, it 4323 1.1 agc makes sense for her to use a hash algorithm that Bob's software uses. 4324 1.1 agc This preference allows Bob to state in his key which algorithms Alice 4325 1.1 agc may use. 4326 1.1 agc 4327 1.1 agc Since SHA1 is the MUST-implement hash algorithm, if it is not 4328 1.1 agc explicitly in the list, it is tacitly at the end. However, it is 4329 1.1 agc good form to place it there explicitly. 4330 1.1 agc 4331 1.1 agc 4332 1.1 agc 4333 1.1 agc Callas, et al Standards Track [Page 76] 4334 1.1 agc 4336 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4337 1.1 agc 4338 1.1 agc 4339 1.1 agc 13.4. Plaintext 4340 1.1 agc 4341 1.1 agc Algorithm 0, "plaintext", may only be used to denote secret keys that 4342 1.1 agc are stored in the clear. Implementations MUST NOT use plaintext in 4343 1.1 agc Symmetrically Encrypted Data packets; they must use Literal Data 4344 1.1 agc packets to encode unencrypted or literal data. 4345 1.1 agc 4346 1.1 agc 13.5. RSA 4347 1.1 agc 4348 1.1 agc There are algorithm types for RSA Sign-Only, and RSA Encrypt-Only 4349 1.1 agc keys. These types are deprecated. The "key flags" subpacket in a 4350 1.1 agc signature is a much better way to express the same idea, and 4351 1.1 agc generalizes it to all algorithms. An implementation SHOULD NOT 4352 1.1 agc create such a key, but MAY interpret it. 4353 1.1 agc 4354 1.1 agc An implementation SHOULD NOT implement RSA keys of size less than 4355 1.1 agc 1024 bits. 4356 1.1 agc 4357 1.1 agc 13.6. DSA 4358 1.1 agc 4359 1.1 agc An implementation SHOULD NOT implement DSA keys of size less than 4360 1.1 agc 1024 bits. It MUST NOT implement a DSA key with a q size of less 4361 1.1 agc than 160 bits. DSA keys MUST also be a multiple of 64 bits, and the 4362 1.1 agc q size MUST be a multiple of 8 bits. The Digital Signature Standard 4363 1.1 agc (DSS) [FIPS186] specifies that DSA be used in one of the following 4364 1.1 agc ways: 4365 1.1 agc 4366 1.1 agc * 1024-bit key, 160-bit q, SHA-1, SHA-224, SHA-256, SHA-384, or 4367 1.1 agc SHA-512 hash 4368 1.1 agc 4369 1.1 agc * 2048-bit key, 224-bit q, SHA-224, SHA-256, SHA-384, or SHA-512 4370 1.1 agc hash 4371 1.1 agc 4372 1.1 agc * 2048-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash 4373 1.1 agc 4374 1.1 agc * 3072-bit key, 256-bit q, SHA-256, SHA-384, or SHA-512 hash 4375 1.1 agc 4376 1.1 agc The above key and q size pairs were chosen to best balance the 4377 1.1 agc strength of the key with the strength of the hash. Implementations 4378 1.1 agc SHOULD use one of the above key and q size pairs when generating DSA 4379 1.1 agc keys. If DSS compliance is desired, one of the specified SHA hashes 4380 1.1 agc must be used as well. [FIPS186] is the ultimate authority on DSS, 4381 1.1 agc and should be consulted for all questions of DSS compliance. 4382 1.1 agc 4383 1.1 agc Note that earlier versions of this standard only allowed a 160-bit q 4384 1.1 agc with no truncation allowed, so earlier implementations may not be 4385 1.1 agc able to handle signatures with a different q size or a truncated 4386 1.1 agc hash. 4387 1.1 agc 4388 1.1 agc 4389 1.1 agc 4390 1.1 agc Callas, et al Standards Track [Page 77] 4391 1.1 agc 4393 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4394 1.1 agc 4395 1.1 agc 4396 1.1 agc 13.7. Elgamal 4397 1.1 agc 4398 1.1 agc An implementation SHOULD NOT implement Elgamal keys of size less than 4399 1.1 agc 1024 bits. 4400 1.1 agc 4401 1.1 agc 13.8. Reserved Algorithm Numbers 4402 1.1 agc 4403 1.1 agc A number of algorithm IDs have been reserved for algorithms that 4404 1.1 agc would be useful to use in an OpenPGP implementation, yet there are 4405 1.1 agc issues that prevent an implementer from actually implementing the 4406 1.1 agc algorithm. These are marked in Section 9.1, "Public-Key Algorithms", 4407 1.1 agc as "reserved for". 4408 1.1 agc 4409 1.1 agc The reserved public-key algorithms, Elliptic Curve (18), ECDSA (19), 4410 1.1 agc and X9.42 (21), do not have the necessary parameters, parameter 4411 1.1 agc order, or semantics defined. 4412 1.1 agc 4413 1.1 agc Previous versions of OpenPGP permitted Elgamal [ELGAMAL] signatures 4414 1.1 agc with a public-key identifier of 20. These are no longer permitted. 4415 1.1 agc An implementation MUST NOT generate such keys. An implementation 4416 1.1 agc MUST NOT generate Elgamal signatures. See [BLEICHENBACHER]. 4417 1.1 agc 4418 1.1 agc 13.9. OpenPGP CFB Mode 4419 1.1 agc 4420 1.1 agc OpenPGP does symmetric encryption using a variant of Cipher Feedback 4421 1.1 agc mode (CFB mode). This section describes the procedure it uses in 4422 1.1 agc detail. This mode is what is used for Symmetrically Encrypted Data 4423 1.1 agc Packets; the mechanism used for encrypting secret-key material is 4424 1.1 agc similar, and is described in the sections above. 4425 1.1 agc 4426 1.1 agc In the description below, the value BS is the block size in octets of 4427 1.1 agc the cipher. Most ciphers have a block size of 8 octets. The AES and 4428 1.1 agc Twofish have a block size of 16 octets. Also note that the 4429 1.1 agc description below assumes that the IV and CFB arrays start with an 4430 1.1 agc index of 1 (unlike the C language, which assumes arrays start with a 4431 1.1 agc zero index). 4432 1.1 agc 4433 1.1 agc OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and 4434 1.1 agc prefixes the plaintext with BS+2 octets of random data, such that 4435 1.1 agc octets BS+1 and BS+2 match octets BS-1 and BS. It does a CFB 4436 1.1 agc resynchronization after encrypting those BS+2 octets. 4437 1.1 agc 4438 1.1 agc Thus, for an algorithm that has a block size of 8 octets (64 bits), 4439 1.1 agc the IV is 10 octets long and octets 7 and 8 of the IV are the same as 4440 1.1 agc octets 9 and 10. For an algorithm with a block size of 16 octets 4441 1.1 agc (128 bits), the IV is 18 octets long, and octets 17 and 18 replicate 4442 1.1 agc octets 15 and 16. Those extra two octets are an easy check for a 4443 1.1 agc correct key. 4444 1.1 agc 4445 1.1 agc 4446 1.1 agc 4447 1.1 agc Callas, et al Standards Track [Page 78] 4448 1.1 agc 4450 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4451 1.1 agc 4452 1.1 agc 4453 1.1 agc Step by step, here is the procedure: 4454 1.1 agc 4455 1.1 agc 1. The feedback register (FR) is set to the IV, which is all zeros. 4456 1.1 agc 4457 1.1 agc 2. FR is encrypted to produce FRE (FR Encrypted). This is the 4458 1.1 agc encryption of an all-zero value. 4459 1.1 agc 4460 1.1 agc 3. FRE is xored with the first BS octets of random data prefixed to 4461 1.1 agc the plaintext to produce C[1] through C[BS], the first BS octets 4462 1.1 agc of ciphertext. 4463 1.1 agc 4464 1.1 agc 4. FR is loaded with C[1] through C[BS]. 4465 1.1 agc 4466 1.1 agc 5. FR is encrypted to produce FRE, the encryption of the first BS 4467 1.1 agc octets of ciphertext. 4468 1.1 agc 4469 1.1 agc 6. The left two octets of FRE get xored with the next two octets of 4470 1.1 agc data that were prefixed to the plaintext. This produces C[BS+1] 4471 1.1 agc and C[BS+2], the next two octets of ciphertext. 4472 1.1 agc 4473 1.1 agc 7. (The resynchronization step) FR is loaded with C[3] through 4474 1.1 agc C[BS+2]. 4475 1.1 agc 4476 1.1 agc 8. FR is encrypted to produce FRE. 4477 1.1 agc 4478 1.1 agc 9. FRE is xored with the first BS octets of the given plaintext, now 4479 1.1 agc that we have finished encrypting the BS+2 octets of prefixed 4480 1.1 agc data. This produces C[BS+3] through C[BS+(BS+2)], the next BS 4481 1.1 agc octets of ciphertext. 4482 1.1 agc 4483 1.1 agc 10. FR is loaded with C[BS+3] to C[BS + (BS+2)] (which is C11-C18 for 4484 1.1 agc an 8-octet block). 4485 1.1 agc 4486 1.1 agc 11. FR is encrypted to produce FRE. 4487 1.1 agc 4488 1.1 agc 12. FRE is xored with the next BS octets of plaintext, to produce 4489 1.1 agc the next BS octets of ciphertext. These are loaded into FR, and 4490 1.1 agc the process is repeated until the plaintext is used up. 4491 1.1 agc 4492 1.1 agc 13.10. Private or Experimental Parameters 4493 1.1 agc 4494 1.1 agc S2K specifiers, Signature subpacket types, user attribute types, 4495 1.1 agc image format types, and algorithms described in Section 9 all reserve 4496 1.1 agc the range 100 to 110 for private and experimental use. Packet types 4497 1.1 agc reserve the range 60 to 63 for private and experimental use. These 4498 1.1 agc are intentionally managed with the PRIVATE USE method, as described 4499 1.1 agc in [RFC2434]. 4500 1.1 agc 4501 1.1 agc 4502 1.1 agc 4503 1.1 agc 4504 1.1 agc Callas, et al Standards Track [Page 79] 4505 1.1 agc 4507 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4508 1.1 agc 4509 1.1 agc 4510 1.1 agc However, implementations need to be careful with these and promote 4511 1.1 agc them to full IANA-managed parameters when they grow beyond the 4512 1.1 agc original, limited system. 4513 1.1 agc 4514 1.1 agc 13.11. Extension of the MDC System 4515 1.1 agc 4516 1.1 agc As described in the non-normative explanation in Section 5.13, the 4517 1.1 agc MDC system is uniquely unparameterized in OpenPGP. This was an 4518 1.1 agc intentional decision to avoid cross-grade attacks. If the MDC system 4519 1.1 agc is extended to a stronger hash function, care must be taken to avoid 4520 1.1 agc downgrade and cross-grade attacks. 4521 1.1 agc 4522 1.1 agc One simple way to do this is to create new packets for a new MDC. 4523 1.1 agc For example, instead of the MDC system using packets 18 and 19, a new 4524 1.1 agc MDC could use 20 and 21. This has obvious drawbacks (it uses two 4525 1.1 agc packet numbers for each new hash function in a space that is limited 4526 1.1 agc to a maximum of 60). 4527 1.1 agc 4528 1.1 agc Another simple way to extend the MDC system is to create new versions 4529 1.1 agc of packet 18, and reflect this in packet 19. For example, suppose 4530 1.1 agc that V2 of packet 18 implicitly used SHA-256. This would require 4531 1.1 agc packet 19 to have a length of 32 octets. The change in the version 4532 1.1 agc in packet 18 and the size of packet 19 prevent a downgrade attack. 4533 1.1 agc 4534 1.1 agc There are two drawbacks to this latter approach. The first is that 4535 1.1 agc using the version number of a packet to carry algorithm information 4536 1.1 agc is not tidy from a protocol-design standpoint. It is possible that 4537 1.1 agc there might be several versions of the MDC system in common use, but 4538 1.1 agc this untidiness would reflect untidiness in cryptographic consensus 4539 1.1 agc about hash function security. The second is that different versions 4540 1.1 agc of packet 19 would have to have unique sizes. If there were two 4541 1.1 agc versions each with 256-bit hashes, they could not both have 32-octet 4542 1.1 agc packet 19s without admitting the chance of a cross-grade attack. 4543 1.1 agc 4544 1.1 agc Yet another, complex approach to extend the MDC system would be a 4545 1.1 agc hybrid of the two above -- create a new pair of MDC packets that are 4546 1.1 agc fully parameterized, and yet protected from downgrade and cross- 4547 1.1 agc grade. 4548 1.1 agc 4549 1.1 agc Any change to the MDC system MUST be done through the IETF CONSENSUS 4550 1.1 agc method, as described in [RFC2434]. 4551 1.1 agc 4552 1.1 agc 13.12. Meta-Considerations for Expansion 4553 1.1 agc 4554 1.1 agc If OpenPGP is extended in a way that is not backwards-compatible, 4555 1.1 agc meaning that old implementations will not gracefully handle their 4556 1.1 agc 4557 1.1 agc 4558 1.1 agc 4559 1.1 agc 4560 1.1 agc 4561 1.1 agc Callas, et al Standards Track [Page 80] 4562 1.1 agc 4564 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4565 1.1 agc 4566 1.1 agc 4567 1.1 agc absence of a new feature, the extension proposal can be declared in 4568 1.1 agc the key holder's self-signature as part of the Features signature 4569 1.1 agc subpacket. 4570 1.1 agc 4571 1.1 agc We cannot state definitively what extensions will not be upwards- 4572 1.1 agc compatible, but typically new algorithms are upwards-compatible, 4573 1.1 agc whereas new packets are not. 4574 1.1 agc 4575 1.1 agc If an extension proposal does not update the Features system, it 4576 1.1 agc SHOULD include an explanation of why this is unnecessary. If the 4577 1.1 agc proposal contains neither an extension to the Features system nor an 4578 1.1 agc explanation of why such an extension is unnecessary, the proposal 4579 1.1 agc SHOULD be rejected. 4580 1.1 agc 4581 1.1 agc 14. Security Considerations 4582 1.1 agc 4583 1.1 agc * As with any technology involving cryptography, you should check the 4584 1.1 agc current literature to determine if any algorithms used here have 4585 1.1 agc been found to be vulnerable to attack. 4586 1.1 agc 4587 1.1 agc * This specification uses Public-Key Cryptography technologies. It 4588 1.1 agc is assumed that the private key portion of a public-private key 4589 1.1 agc pair is controlled and secured by the proper party or parties. 4590 1.1 agc 4591 1.1 agc * Certain operations in this specification involve the use of random 4592 1.1 agc numbers. An appropriate entropy source should be used to generate 4593 1.1 agc these numbers (see [RFC4086]). 4594 1.1 agc 4595 1.1 agc * The MD5 hash algorithm has been found to have weaknesses, with 4596 1.1 agc collisions found in a number of cases. MD5 is deprecated for use 4597 1.1 agc in OpenPGP. Implementations MUST NOT generate new signatures using 4598 1.1 agc MD5 as a hash function. They MAY continue to consider old 4599 1.1 agc signatures that used MD5 as valid. 4600 1.1 agc 4601 1.1 agc * SHA-224 and SHA-384 require the same work as SHA-256 and SHA-512, 4602 1.1 agc respectively. In general, there are few reasons to use them 4603 1.1 agc outside of DSS compatibility. You need a situation where one needs 4604 1.1 agc more security than smaller hashes, but does not want to have the 4605 1.1 agc full 256-bit or 512-bit data length. 4606 1.1 agc 4607 1.1 agc * Many security protocol designers think that it is a bad idea to use 4608 1.1 agc a single key for both privacy (encryption) and integrity 4609 1.1 agc (signatures). In fact, this was one of the motivating forces 4610 1.1 agc behind the V4 key format with separate signature and encryption 4611 1.1 agc keys. If you as an implementer promote dual-use keys, you should 4612 1.1 agc at least be aware of this controversy. 4613 1.1 agc 4614 1.1 agc 4615 1.1 agc 4616 1.1 agc 4617 1.1 agc 4618 1.1 agc Callas, et al Standards Track [Page 81] 4619 1.1 agc 4621 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4622 1.1 agc 4623 1.1 agc 4624 1.1 agc * The DSA algorithm will work with any hash, but is sensitive to the 4625 1.1 agc quality of the hash algorithm. Verifiers should be aware that even 4626 1.1 agc if the signer used a strong hash, an attacker could have modified 4627 1.1 agc the signature to use a weak one. Only signatures using acceptably 4628 1.1 agc strong hash algorithms should be accepted as valid. 4629 1.1 agc 4630 1.1 agc * As OpenPGP combines many different asymmetric, symmetric, and hash 4631 1.1 agc algorithms, each with different measures of strength, care should 4632 1.1 agc be taken that the weakest element of an OpenPGP message is still 4633 1.1 agc sufficiently strong for the purpose at hand. While consensus about 4634 1.1 agc the strength of a given algorithm may evolve, NIST Special 4635 1.1 agc Publication 800-57 [SP800-57] recommends the following list of 4636 1.1 agc equivalent strengths: 4637 1.1 agc 4638 1.1 agc Asymmetric | Hash | Symmetric 4639 1.1 agc key size | size | key size 4640 1.1 agc ------------+--------+----------- 4641 1.1 agc 1024 160 80 4642 1.1 agc 2048 224 112 4643 1.1 agc 3072 256 128 4644 1.1 agc 7680 384 192 4645 1.1 agc 15360 512 256 4646 1.1 agc 4647 1.1 agc * There is a somewhat-related potential security problem in 4648 1.1 agc signatures. If an attacker can find a message that hashes to the 4649 1.1 agc same hash with a different algorithm, a bogus signature structure 4650 1.1 agc can be constructed that evaluates correctly. 4651 1.1 agc 4652 1.1 agc For example, suppose Alice DSA signs message M using hash algorithm 4653 1.1 agc H. Suppose that Mallet finds a message M' that has the same hash 4654 1.1 agc value as M with H'. Mallet can then construct a signature block 4655 1.1 agc that verifies as Alice's signature of M' with H'. However, this 4656 1.1 agc would also constitute a weakness in either H or H' or both. Should 4657 1.1 agc this ever occur, a revision will have to be made to this document 4658 1.1 agc to revise the allowed hash algorithms. 4659 1.1 agc 4660 1.1 agc * If you are building an authentication system, the recipient may 4661 1.1 agc specify a preferred signing algorithm. However, the signer would 4662 1.1 agc be foolish to use a weak algorithm simply because the recipient 4663 1.1 agc requests it. 4664 1.1 agc 4665 1.1 agc * Some of the encryption algorithms mentioned in this document have 4666 1.1 agc been analyzed less than others. For example, although CAST5 is 4667 1.1 agc presently considered strong, it has been analyzed less than 4668 1.1 agc TripleDES. Other algorithms may have other controversies 4669 1.1 agc surrounding them. 4670 1.1 agc 4671 1.1 agc 4672 1.1 agc 4673 1.1 agc 4674 1.1 agc 4675 1.1 agc Callas, et al Standards Track [Page 82] 4676 1.1 agc 4678 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4679 1.1 agc 4680 1.1 agc 4681 1.1 agc * In late summer 2002, Jallad, Katz, and Schneier published an 4682 1.1 agc interesting attack on the OpenPGP protocol and some of its 4683 1.1 agc implementations [JKS02]. In this attack, the attacker modifies a 4684 1.1 agc message and sends it to a user who then returns the erroneously 4685 1.1 agc decrypted message to the attacker. The attacker is thus using the 4686 1.1 agc user as a random oracle, and can often decrypt the message. 4687 1.1 agc 4688 1.1 agc Compressing data can ameliorate this attack. The incorrectly 4689 1.1 agc decrypted data nearly always decompresses in ways that defeat the 4690 1.1 agc attack. However, this is not a rigorous fix, and leaves open some 4691 1.1 agc small vulnerabilities. For example, if an implementation does not 4692 1.1 agc compress a message before encryption (perhaps because it knows it 4693 1.1 agc was already compressed), then that message is vulnerable. Because 4694 1.1 agc of this happenstance -- that modification attacks can be thwarted 4695 1.1 agc by decompression errors -- an implementation SHOULD treat a 4696 1.1 agc decompression error as a security problem, not merely a data 4697 1.1 agc problem. 4698 1.1 agc 4699 1.1 agc This attack can be defeated by the use of Modification Detection, 4700 1.1 agc provided that the implementation does not let the user naively 4701 1.1 agc return the data to the attacker. An implementation MUST treat an 4702 1.1 agc MDC failure as a security problem, not merely a data problem. 4703 1.1 agc 4704 1.1 agc In either case, the implementation MAY allow the user access to the 4705 1.1 agc erroneous data, but MUST warn the user as to potential security 4706 1.1 agc problems should that data be returned to the sender. 4707 1.1 agc 4708 1.1 agc While this attack is somewhat obscure, requiring a special set of 4709 1.1 agc circumstances to create it, it is nonetheless quite serious as it 4710 1.1 agc permits someone to trick a user to decrypt a message. 4711 1.1 agc Consequently, it is important that: 4712 1.1 agc 4713 1.1 agc 1. Implementers treat MDC errors and decompression failures as 4714 1.1 agc security problems. 4715 1.1 agc 4716 1.1 agc 2. Implementers implement Modification Detection with all due 4717 1.1 agc speed and encourage its spread. 4718 1.1 agc 4719 1.1 agc 3. Users migrate to implementations that support Modification 4720 1.1 agc Detection with all due speed. 4721 1.1 agc 4722 1.1 agc * PKCS#1 has been found to be vulnerable to attacks in which a system 4723 1.1 agc that reports errors in padding differently from errors in 4724 1.1 agc decryption becomes a random oracle that can leak the private key in 4725 1.1 agc mere millions of queries. Implementations must be aware of this 4726 1.1 agc attack and prevent it from happening. The simplest solution is to 4727 1.1 agc report a single error code for all variants of decryption errors so 4728 1.1 agc as not to leak information to an attacker. 4729 1.1 agc 4730 1.1 agc 4731 1.1 agc 4732 1.1 agc Callas, et al Standards Track [Page 83] 4733 1.1 agc 4735 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4736 1.1 agc 4737 1.1 agc 4738 1.1 agc * Some technologies mentioned here may be subject to government 4739 1.1 agc control in some countries. 4740 1.1 agc 4741 1.1 agc * In winter 2005, Serge Mister and Robert Zuccherato from Entrust 4742 1.1 agc released a paper describing a way that the "quick check" in OpenPGP 4743 1.1 agc CFB mode can be used with a random oracle to decrypt two octets of 4744 1.1 agc every cipher block [MZ05]. They recommend as prevention not using 4745 1.1 agc the quick check at all. 4746 1.1 agc 4747 1.1 agc Many implementers have taken this advice to heart for any data that 4748 1.1 agc is symmetrically encrypted and for which the session key is 4749 1.1 agc public-key encrypted. In this case, the quick check is not needed 4750 1.1 agc as the public-key encryption of the session key should guarantee 4751 1.1 agc that it is the right session key. In other cases, the 4752 1.1 agc implementation should use the quick check with care. 4753 1.1 agc 4754 1.1 agc On the one hand, there is a danger to using it if there is a random 4755 1.1 agc oracle that can leak information to an attacker. In plainer 4756 1.1 agc language, there is a danger to using the quick check if timing 4757 1.1 agc information about the check can be exposed to an attacker, 4758 1.1 agc particularly via an automated service that allows rapidly repeated 4759 1.1 agc queries. 4760 1.1 agc 4761 1.1 agc On the other hand, it is inconvenient to the user to be informed 4762 1.1 agc that they typed in the wrong passphrase only after a petabyte of 4763 1.1 agc data is decrypted. There are many cases in cryptographic 4764 1.1 agc engineering where the implementer must use care and wisdom, and 4765 1.1 agc this is one. 4766 1.1 agc 4767 1.1 agc 15. Implementation Nits 4768 1.1 agc 4769 1.1 agc This section is a collection of comments to help an implementer, 4770 1.1 agc particularly with an eye to backward compatibility. Previous 4771 1.1 agc implementations of PGP are not OpenPGP compliant. Often the 4772 1.1 agc differences are small, but small differences are frequently more 4773 1.1 agc vexing than large differences. Thus, this is a non-comprehensive 4774 1.1 agc list of potential problems and gotchas for a developer who is trying 4775 1.1 agc to be backward-compatible. 4776 1.1 agc 4777 1.1 agc * The IDEA algorithm is patented, and yet it is required for PGP 4778 1.1 agc 2.x interoperability. It is also the de-facto preferred 4779 1.1 agc algorithm for a V3 key with a V3 self-signature (or no self- 4780 1.1 agc signature). 4781 1.1 agc 4782 1.1 agc * When exporting a private key, PGP 2.x generates the header "BEGIN 4783 1.1 agc PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY BLOCK". 4784 1.1 agc All previous versions ignore the implied data type, and look 4785 1.1 agc directly at the packet data type. 4786 1.1 agc 4787 1.1 agc 4788 1.1 agc 4789 1.1 agc Callas, et al Standards Track [Page 84] 4790 1.1 agc 4792 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4793 1.1 agc 4794 1.1 agc 4795 1.1 agc * PGP 2.0 through 2.5 generated V2 Public-Key packets. These are 4796 1.1 agc identical to the deprecated V3 keys except for the version 4797 1.1 agc number. An implementation MUST NOT generate them and may accept 4798 1.1 agc or reject them as it sees fit. Some older PGP versions generated 4799 1.1 agc V2 PKESK packets (Tag 1) as well. An implementation may accept 4800 1.1 agc or reject V2 PKESK packets as it sees fit, and MUST NOT generate 4801 1.1 agc them. 4802 1.1 agc 4803 1.1 agc * PGP 2.6.x will not accept key-material packets with versions 4804 1.1 agc greater than 3. 4805 1.1 agc 4806 1.1 agc * There are many ways possible for two keys to have the same key 4807 1.1 agc material, but different fingerprints (and thus Key IDs). Perhaps 4808 1.1 agc the most interesting is an RSA key that has been "upgraded" to V4 4809 1.1 agc format, but since a V4 fingerprint is constructed by hashing the 4810 1.1 agc key creation time along with other things, two V4 keys created at 4811 1.1 agc different times, yet with the same key material will have 4812 1.1 agc different fingerprints. 4813 1.1 agc 4814 1.1 agc * If an implementation is using zlib to interoperate with PGP 2.x, 4815 1.1 agc then the "windowBits" parameter should be set to -13. 4816 1.1 agc 4817 1.1 agc * The 0x19 back signatures were not required for signing subkeys 4818 1.1 agc until relatively recently. Consequently, there may be keys in 4819 1.1 agc the wild that do not have these back signatures. Implementing 4820 1.1 agc software may handle these keys as it sees fit. 4821 1.1 agc 4822 1.1 agc * OpenPGP does not put limits on the size of public keys. However, 4823 1.1 agc larger keys are not necessarily better keys. Larger keys take 4824 1.1 agc more computation time to use, and this can quickly become 4825 1.1 agc impractical. Different OpenPGP implementations may also use 4826 1.1 agc different upper bounds for public key sizes, and so care should 4827 1.1 agc be taken when choosing sizes to maintain interoperability. As of 4828 1.1 agc 2007 most implementations have an upper bound of 4096 bits. 4829 1.1 agc 4830 1.1 agc * ASCII armor is an optional feature of OpenPGP. The OpenPGP 4831 1.1 agc working group strives for a minimal set of mandatory-to-implement 4832 1.1 agc features, and since there could be useful implementations that 4833 1.1 agc only use binary object formats, this is not a "MUST" feature for 4834 1.1 agc an implementation. For example, an implementation that is using 4835 1.1 agc OpenPGP as a mechanism for file signatures may find ASCII armor 4836 1.1 agc unnecessary. OpenPGP permits an implementation to declare what 4837 1.1 agc features it does and does not support, but ASCII armor is not one 4838 1.1 agc of these. Since most implementations allow binary and armored 4839 1.1 agc objects to be used indiscriminately, an implementation that does 4840 1.1 agc not implement ASCII armor may find itself with compatibility 4841 1.1 agc issues with general-purpose implementations. Moreover, 4842 1.1 agc implementations of OpenPGP-MIME [RFC3156] already have a 4843 1.1 agc 4844 1.1 agc 4845 1.1 agc 4846 1.1 agc Callas, et al Standards Track [Page 85] 4847 1.1 agc 4849 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4850 1.1 agc 4851 1.1 agc 4852 1.1 agc requirement for ASCII armor so those implementations will 4853 1.1 agc necessarily have support. 4854 1.1 agc 4855 1.1 agc 16. References 4856 1.1 agc 4857 1.1 agc 16.1. Normative References 4858 1.1 agc 4859 1.1 agc [AES] NIST, FIPS PUB 197, "Advanced Encryption Standard 4860 1.1 agc (AES)," November 2001. 4861 1.1 agc http://csrc.nist.gov/publications/fips/fips197/fips- 4862 1.1 agc 197.{ps,pdf} 4863 1.1 agc 4864 1.1 agc [BLOWFISH] Schneier, B. "Description of a New Variable-Length 4865 1.1 agc Key, 64-Bit Block Cipher (Blowfish)" Fast Software 4866 1.1 agc Encryption, Cambridge Security Workshop Proceedings 4867 1.1 agc (December 1993), Springer-Verlag, 1994, pp191-204 4868 1.1 agc <http://www.counterpane.com/bfsverlag.html> 4869 1.1 agc 4870 1.1 agc [BZ2] J. Seward, jseward (a] acm.org, "The Bzip2 and libbzip2 4871 1.1 agc home page" <http://www.bzip.org/> 4872 1.1 agc 4873 1.1 agc [ELGAMAL] T. Elgamal, "A Public-Key Cryptosystem and a 4874 1.1 agc Signature Scheme Based on Discrete Logarithms," IEEE 4875 1.1 agc Transactions on Information Theory, v. IT-31, n. 4, 4876 1.1 agc 1985, pp. 469-472. 4877 1.1 agc 4878 1.1 agc [FIPS180] Secure Hash Signature Standard (SHS) (FIPS PUB 180- 4879 1.1 agc 2). 4880 1.1 agc <http://csrc.nist.gov/publications/fips/fips180- 4881 1.1 agc 2/fips180-2withchangenotice.pdf> 4882 1.1 agc 4883 1.1 agc [FIPS186] Digital Signature Standard (DSS) (FIPS PUB 186-2). 4884 1.1 agc <http://csrc.nist.gov/publications/fips/fips186-2/ 4885 1.1 agc fips186-2-change1.pdf> FIPS 186-3 describes keys 4886 1.1 agc greater than 1024 bits. The latest draft is at: 4887 1.1 agc <http://csrc.nist.gov/publications/drafts/ 4888 1.1 agc fips_186-3/Draft-FIPS-186-3%20_March2006.pdf> 4889 1.1 agc 4890 1.1 agc [HAC] Alfred Menezes, Paul van Oorschot, and Scott 4891 1.1 agc Vanstone, "Handbook of Applied Cryptography," CRC 4892 1.1 agc Press, 1996. 4893 1.1 agc <http://www.cacr.math.uwaterloo.ca/hac/> 4894 1.1 agc 4895 1.1 agc [IDEA] Lai, X, "On the design and security of block 4896 1.1 agc ciphers", ETH Series in Information Processing, J.L. 4897 1.1 agc Massey (editor), Vol. 1, Hartung-Gorre Verlag 4898 1.1 agc Knostanz, Technische Hochschule (Zurich), 1992 4899 1.1 agc 4900 1.1 agc 4901 1.1 agc 4902 1.1 agc 4903 1.1 agc Callas, et al Standards Track [Page 86] 4904 1.1 agc 4906 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4907 1.1 agc 4908 1.1 agc 4909 1.1 agc [ISO10646] ISO/IEC 10646-1:1993. International Standard -- 4910 1.1 agc Information technology -- Universal Multiple-Octet 4911 1.1 agc Coded Character Set (UCS) -- Part 1: Architecture 4912 1.1 agc and Basic Multilingual Plane. 4913 1.1 agc 4914 1.1 agc [JFIF] JPEG File Interchange Format (Version 1.02). Eric 4915 1.1 agc Hamilton, C-Cube Microsystems, Milpitas, CA, 4916 1.1 agc September 1, 1992. 4917 1.1 agc 4918 1.1 agc [RFC1950] Deutsch, P. and J-L. Gailly, "ZLIB Compressed Data 4919 1.1 agc Format Specification version 3.3", RFC 1950, May 4920 1.1 agc 1996. 4921 1.1 agc 4922 1.1 agc [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format 4923 1.1 agc Specification version 1.3", RFC 1951, May 1996. 4924 1.1 agc 4925 1.1 agc [RFC2045] Freed, N. and N. Borenstein, "Multipurpose Internet 4926 1.1 agc Mail Extensions (MIME) Part One: Format of Internet 4927 1.1 agc Message Bodies", RFC 2045, November 1996 4928 1.1 agc 4929 1.1 agc [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 4930 1.1 agc Requirement Levels", BCP 14, RFC 2119, March 1997. 4931 1.1 agc 4932 1.1 agc [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC 4933 1.1 agc 2144, May 1997. 4934 1.1 agc 4935 1.1 agc [RFC2434] Narten, T. and H. Alvestrand, "Guidelines for 4936 1.1 agc Writing an IANA Considerations Section in RFCs", BCP 4937 1.1 agc 26, RFC 2434, October 1998. 4938 1.1 agc 4939 1.1 agc [RFC2822] Resnick, P., "Internet Message Format", RFC 2822, 4940 1.1 agc April 2001. 4941 1.1 agc 4942 1.1 agc [RFC3156] Elkins, M., Del Torto, D., Levien, R., and T. 4943 1.1 agc Roessler, "MIME Security with OpenPGP", RFC 3156, 4944 1.1 agc August 2001. 4945 1.1 agc 4946 1.1 agc [RFC3447] Jonsson, J. and B. Kaliski, "Public-Key Cryptography 4947 1.1 agc Standards (PKCS) #1: RSA Cryptography Specifications 4948 1.1 agc Version 2.1", RFC 3447, February 2003. 4949 1.1 agc 4950 1.1 agc [RFC3629] Yergeau, F., "UTF-8, a transformation format of ISO 4951 1.1 agc 10646", STD 63, RFC 3629, November 2003. 4952 1.1 agc 4953 1.1 agc [RFC4086] Eastlake, D., 3rd, Schiller, J., and S. Crocker, 4954 1.1 agc "Randomness Requirements for Security", BCP 106, RFC 4955 1.1 agc 4086, June 2005. 4956 1.1 agc 4957 1.1 agc 4958 1.1 agc 4959 1.1 agc 4960 1.1 agc Callas, et al Standards Track [Page 87] 4961 1.1 agc 4963 1.1 agc RFC 4880 OpenPGP Message Format November 2007 4964 1.1 agc 4965 1.1 agc 4966 1.1 agc [SCHNEIER] Schneier, B., "Applied Cryptography Second Edition: 4967 1.1 agc protocols, algorithms, and source code in C", 1996. 4968 1.1 agc 4969 1.1 agc [TWOFISH] B. Schneier, J. Kelsey, D. Whiting, D. Wagner, C. 4970 1.1 agc Hall, and N. Ferguson, "The Twofish Encryption 4971 1.1 agc Algorithm", John Wiley & Sons, 1999. 4972 1.1 agc 4973 1.1 agc 16.2. Informative References 4974 1.1 agc 4975 1.1 agc [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating Elgamal 4976 1.1 agc signatures without knowing the secret key," 4977 1.1 agc Eurocrypt 96. Note that the version in the 4978 1.1 agc proceedings has an error. A revised version is 4979 1.1 agc available at the time of writing from 4980 1.1 agc <ftp://ftp.inf.ethz.ch/pub/publications/papers/ti 4981 1.1 agc /isc/ElGamal.ps> 4982 1.1 agc 4983 1.1 agc [JKS02] Kahil Jallad, Jonathan Katz, Bruce Schneier 4984 1.1 agc "Implementation of Chosen-Ciphertext Attacks against 4985 1.1 agc PGP and GnuPG" http://www.counterpane.com/pgp- 4986 1.1 agc attack.html 4987 1.1 agc 4988 1.1 agc [MAURER] Ueli Maurer, "Modelling a Public-Key 4989 1.1 agc Infrastructure", Proc. 1996 European Symposium on 4990 1.1 agc Research in Computer Security (ESORICS' 96), Lecture 4991 1.1 agc Notes in Computer Science, Springer-Verlag, vol. 4992 1.1 agc 1146, pp. 325-350, Sep 1996. 4993 1.1 agc 4994 1.1 agc [MZ05] Serge Mister, Robert Zuccherato, "An Attack on CFB 4995 1.1 agc Mode Encryption As Used By OpenPGP," IACR ePrint 4996 1.1 agc Archive: Report 2005/033, 8 Feb 2005 4997 1.1 agc http://eprint.iacr.org/2005/033 4998 1.1 agc 4999 1.1 agc [REGEX] Jeffrey Friedl, "Mastering Regular Expressions," 5000 1.1 agc O'Reilly, ISBN 0-596-00289-0. 5001 1.1 agc 5002 1.1 agc [RFC1423] Balenson, D., "Privacy Enhancement for Internet 5003 1.1 agc Electronic Mail: Part III: Algorithms, Modes, and 5004 1.1 agc Identifiers", RFC 1423, February 1993. 5005 1.1 agc 5006 1.1 agc [RFC1991] Atkins, D., Stallings, W., and P. Zimmermann, "PGP 5007 1.1 agc Message Exchange Formats", RFC 1991, August 1996. 5008 1.1 agc 5009 1.1 agc [RFC2440] Callas, J., Donnerhacke, L., Finney, H., and R. 5010 1.1 agc Thayer, "OpenPGP Message Format", RFC 2440, November 5011 1.1 agc 1998. 5012 1.1 agc 5013 1.1 agc 5014 1.1 agc 5015 1.1 agc 5016 1.1 agc 5017 1.1 agc Callas, et al Standards Track [Page 88] 5018 1.1 agc 5020 1.1 agc RFC 4880 OpenPGP Message Format November 2007 5021 1.1 agc 5022 1.1 agc 5023 1.1 agc [SP800-57] NIST Special Publication 800-57, Recommendation on 5024 1.1 agc Key Management 5025 1.1 agc <http://csrc.nist.gov/publications/nistpubs/ 800- 5026 1.1 agc 57/SP800-57-Part1.pdf> 5027 1.1 agc <http://csrc.nist.gov/publications/nistpubs/ 800- 5028 1.1 agc 57/SP800-57-Part2.pdf> 5029 1.1 agc 5030 1.1 agc Acknowledgements 5031 1.1 agc 5032 1.1 agc This memo also draws on much previous work from a number of other 5033 1.1 agc authors, including: Derek Atkins, Charles Breed, Dave Del Torto, Marc 5034 1.1 agc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Ben Laurie, 5035 1.1 agc Raph Levien, Colin Plumb, Will Price, David Shaw, William Stallings, 5036 1.1 agc Mark Weaver, and Philip R. Zimmermann. 5037 1.1 agc 5038 1.1 agc Authors' Addresses 5039 1.1 agc 5040 1.1 agc The working group can be contacted via the current chair: 5041 1.1 agc 5042 1.1 agc Derek Atkins 5043 1.1 agc IHTFP Consulting, Inc. 5044 4 Farragut Ave 5045 Somerville, MA 02144 USA 5046 5047 EMail: derek (a] ihtfp.com 5048 Tel: +1 617 623 3745 5049 5050 The principal authors of this document are as follows: 5051 5052 Jon Callas 5053 EMail: jon (a] callas.org 5054 5055 Lutz Donnerhacke 5056 IKS GmbH 5057 Wildenbruchstr. 15 5058 07745 Jena, Germany 5059 EMail: lutz (a] iks-jena.de 5060 5061 Hal Finney 5062 EMail: hal (a] finney.org 5063 5064 David Shaw 5065 EMail: dshaw (a] jabberwocky.com 5066 5067 Rodney Thayer 5068 EMail: rodney (a] canola-jones.com 5069 5070 5071 5072 5073 5074 Callas, et al Standards Track [Page 89] 5075 5077 RFC 4880 OpenPGP Message Format November 2007 5078 5079 5080 Full Copyright Statement 5081 5082 Copyright (C) The IETF Trust (2007). 5083 5084 This document is subject to the rights, licenses and restrictions 5085 contained in BCP 78, and except as set forth therein, the authors 5086 retain all their rights. 5087 5088 This document and the information contained herein are provided on an 5089 "AS IS" basis and THE CONTRIBUTOR, THE ORGANIZATION HE/SHE REPRESENTS 5090 OR IS SPONSORED BY (IF ANY), THE INTERNET SOCIETY, THE IETF TRUST AND 5091 THE INTERNET ENGINEERING TASK FORCE DISCLAIM ALL WARRANTIES, EXPRESS 5092 OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF 5093 THE INFORMATION HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED 5094 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. 5095 5096 Intellectual Property 5097 5098 The IETF takes no position regarding the validity or scope of any 5099 Intellectual Property Rights or other rights that might be claimed to 5100 pertain to the implementation or use of the technology described in 5101 this document or the extent to which any license under such rights 5102 might or might not be available; nor does it represent that it has 5103 made any independent effort to identify any such rights. Information 5104 on the procedures with respect to rights in RFC documents can be 5105 found in BCP 78 and BCP 79. 5106 5107 Copies of IPR disclosures made to the IETF Secretariat and any 5108 assurances of licenses to be made available, or the result of an 5109 attempt made to obtain a general license or permission for the use of 5110 such proprietary rights by implementers or users of this 5111 specification can be obtained from the IETF on-line IPR repository at 5112 http://www.ietf.org/ipr. 5113 5114 The IETF invites any interested party to bring to its attention any 5115 copyrights, patents or patent applications, or other proprietary 5116 rights that may cover technology that may be required to implement 5117 this standard. Please address the information to the IETF at 5118 ietf-ipr (a] ietf.org. 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 Callas, et al Standards Track [Page 90] 5132 5134