7 Network Working Group J. Callas
8 Request for Comments: 2440 Network Associates
9 Category: Standards Track L. Donnerhacke
10 IN-Root-CA Individual Network e.V.
18 OpenPGP Message Format
22 This document specifies an Internet standards track protocol for the
23 Internet community, and requests discussion and suggestions for
24 improvements. Please refer to the current edition of the "Internet
25 Official Protocol Standards" (STD 1) for the standardization state
26 and status of this protocol. Distribution of this memo is unlimited.
30 Copyright (C) The Internet Society (1998). All Rights Reserved.
34 This document defines many tag values, yet it doesn't describe a
35 mechanism for adding new tags (for new features). Traditionally the
36 Internet Assigned Numbers Authority (IANA) handles the allocation of
37 new values for future expansion and RFCs usually define the procedure
38 to be used by the IANA. However, there are subtle (and not so
39 subtle) interactions that may occur in this protocol between new
40 features and existing features which result in a significant
41 reduction in over all security. Therefore, this document does not
42 define an extension procedure. Instead requests to define new tag
43 values (say for new encryption algorithms for example) should be
44 forwarded to the IESG Security Area Directors for consideration or
45 forwarding to the appropriate IETF Working Group for consideration.
49 This document is maintained in order to publish all necessary
50 information needed to develop interoperable applications based on the
51 OpenPGP format. It is not a step-by-step cookbook for writing an
52 application. It describes only the format and methods needed to read,
53 check, generate, and write conforming packets crossing any network.
54 It does not deal with storage and implementation questions. It does,
58 Callas, et. al. Standards Track [Page 1]
60 RFC 2440 OpenPGP Message Format November 1998
63 however, discuss implementation issues necessary to avoid security
66 Open-PGP software uses a combination of strong public-key and
67 symmetric cryptography to provide security services for electronic
68 communications and data storage. These services include
69 confidentiality, key management, authentication, and digital
70 signatures. This document specifies the message formats used in
81 2. General functions 5
82 2.1. Confidentiality via Encryption 5
83 2.2. Authentication via Digital signature 6
85 2.4. Conversion to Radix-64 7
86 2.5. Signature-Only Applications 7
87 3. Data Element Formats 7
89 3.2. Multi-Precision Integers 8
93 3.6. String-to-key (S2K) specifiers 9
94 3.6.1. String-to-key (S2k) specifier types 9
96 3.6.1.2. Salted S2K 10
97 3.6.1.3. Iterated and Salted S2K 10
98 3.6.2. String-to-key usage 11
99 3.6.2.1. Secret key encryption 11
100 3.6.2.2. Symmetric-key message encryption 11
103 4.2. Packet Headers 12
104 4.2.1. Old-Format Packet Lengths 13
105 4.2.2. New-Format Packet Lengths 13
106 4.2.2.1. One-Octet Lengths 14
107 4.2.2.2. Two-Octet Lengths 14
108 4.2.2.3. Five-Octet Lengths 14
109 4.2.2.4. Partial Body Lengths 14
110 4.2.3. Packet Length Examples 14
114 Callas, et. al. Standards Track [Page 2]
116 RFC 2440 OpenPGP Message Format November 1998
121 5.1. Public-Key Encrypted Session Key Packets (Tag 1) 16
122 5.2. Signature Packet (Tag 2) 17
123 5.2.1. Signature Types 17
124 5.2.2. Version 3 Signature Packet Format 19
125 5.2.3. Version 4 Signature Packet Format 21
126 5.2.3.1. Signature Subpacket Specification 22
127 5.2.3.2. Signature Subpacket Types 24
128 5.2.3.3. Signature creation time 25
130 5.2.3.5. Key expiration time 25
131 5.2.3.6. Preferred symmetric algorithms 25
132 5.2.3.7. Preferred hash algorithms 25
133 5.2.3.8. Preferred compression algorithms 26
134 5.2.3.9. Signature expiration time 26
135 5.2.3.10.Exportable Certification 26
136 5.2.3.11.Revocable 27
137 5.2.3.12.Trust signature 27
138 5.2.3.13.Regular expression 27
139 5.2.3.14.Revocation key 27
140 5.2.3.15.Notation Data 28
141 5.2.3.16.Key server preferences 28
142 5.2.3.17.Preferred key server 29
143 5.2.3.18.Primary user id 29
144 5.2.3.19.Policy URL 29
145 5.2.3.20.Key Flags 29
146 5.2.3.21.Signer's User ID 30
147 5.2.3.22.Reason for Revocation 30
148 5.2.4. Computing Signatures 31
149 5.2.4.1. Subpacket Hints 32
150 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3) 32
151 5.4. One-Pass Signature Packets (Tag 4) 33
152 5.5. Key Material Packet 34
153 5.5.1. Key Packet Variants 34
154 5.5.1.1. Public Key Packet (Tag 6) 34
155 5.5.1.2. Public Subkey Packet (Tag 14) 34
156 5.5.1.3. Secret Key Packet (Tag 5) 35
157 5.5.1.4. Secret Subkey Packet (Tag 7) 35
158 5.5.2. Public Key Packet Formats 35
159 5.5.3. Secret Key Packet Formats 37
160 5.6. Compressed Data Packet (Tag 8) 38
161 5.7. Symmetrically Encrypted Data Packet (Tag 9) 39
162 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10) 39
163 5.9. Literal Data Packet (Tag 11) 40
164 5.10. Trust Packet (Tag 12) 40
165 5.11. User ID Packet (Tag 13) 41
166 6. Radix-64 Conversions 41
170 Callas, et. al. Standards Track [Page 3]
172 RFC 2440 OpenPGP Message Format November 1998
175 6.1. An Implementation of the CRC-24 in "C" 42
176 6.2. Forming ASCII Armor 42
177 6.3. Encoding Binary in Radix-64 44
178 6.4. Decoding Radix-64 46
179 6.5. Examples of Radix-64 46
180 6.6. Example of an ASCII Armored Message 47
181 7. Cleartext signature framework 47
182 7.1. Dash-Escaped Text 47
183 8. Regular Expressions 48
185 9.1. Public Key Algorithms 49
186 9.2. Symmetric Key Algorithms 49
187 9.3. Compression Algorithms 50
188 9.4. Hash Algorithms 50
189 10. Packet Composition 50
190 10.1. Transferable Public Keys 50
191 10.2. OpenPGP Messages 52
192 10.3. Detached Signatures 52
193 11. Enhanced Key Formats 52
194 11.1. Key Structures 52
195 11.2. Key IDs and Fingerprints 53
196 12. Notes on Algorithms 54
197 12.1. Symmetric Algorithm Preferences 54
198 12.2. Other Algorithm Preferences 55
199 12.2.1. Compression Preferences 56
200 12.2.2. Hash Algorithm Preferences 56
205 12.7. Reserved Algorithm Numbers 58
206 12.8. OpenPGP CFB mode 58
207 13. Security Considerations 59
208 14. Implementation Nits 60
209 15. Authors and Working Group Chair 62
211 17. Full Copyright Statement 65
215 This document provides information on the message-exchange packet
216 formats used by OpenPGP to provide encryption, decryption, signing,
217 and key management functions. It builds on the foundation provided in
218 RFC 1991 "PGP Message Exchange Formats."
226 Callas, et. al. Standards Track [Page 4]
228 RFC 2440 OpenPGP Message Format November 1998
233 * OpenPGP - This is a definition for security software that uses
236 * PGP - Pretty Good Privacy. PGP is a family of software systems
237 developed by Philip R. Zimmermann from which OpenPGP is based.
239 * PGP 2.6.x - This version of PGP has many variants, hence the term
240 PGP 2.6.x. It used only RSA, MD5, and IDEA for its cryptographic
241 transforms. An informational RFC, RFC 1991, was written
242 describing this version of PGP.
244 * PGP 5.x - This version of PGP is formerly known as "PGP 3" in the
245 community and also in the predecessor of this document, RFC 1991.
246 It has new formats and corrects a number of problems in the PGP
247 2.6.x design. It is referred to here as PGP 5.x because that
248 software was the first release of the "PGP 3" code base.
250 "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of
251 Network Associates, Inc. and are used with permission.
253 This document uses the terms "MUST", "SHOULD", and "MAY" as defined
254 in RFC 2119, along with the negated forms of those terms.
258 OpenPGP provides data integrity services for messages and data files
259 by using these core technologies:
267 - radix-64 conversion
269 In addition, OpenPGP provides key management and certificate
270 services, but many of these are beyond the scope of this document.
272 2.1. Confidentiality via Encryption
274 OpenPGP uses two encryption methods to provide confidentiality:
275 symmetric-key encryption and public key encryption. With public-key
276 encryption, the object is encrypted using a symmetric encryption
277 algorithm. Each symmetric key is used only once. A new "session key"
278 is generated as a random number for each message. Since it is used
282 Callas, et. al. Standards Track [Page 5]
284 RFC 2440 OpenPGP Message Format November 1998
287 only once, the session key is bound to the message and transmitted
288 with it. To protect the key, it is encrypted with the receiver's
289 public key. The sequence is as follows:
291 1. The sender creates a message.
293 2. The sending OpenPGP generates a random number to be used as a
294 session key for this message only.
296 3. The session key is encrypted using each recipient's public key.
297 These "encrypted session keys" start the message.
299 4. The sending OpenPGP encrypts the message using the session key,
300 which forms the remainder of the message. Note that the message
301 is also usually compressed.
303 5. The receiving OpenPGP decrypts the session key using the
304 recipient's private key.
306 6. The receiving OpenPGP decrypts the message using the session key.
307 If the message was compressed, it will be decompressed.
309 With symmetric-key encryption, an object may be encrypted with a
310 symmetric key derived from a passphrase (or other shared secret), or
311 a two-stage mechanism similar to the public-key method described
312 above in which a session key is itself encrypted with a symmetric
313 algorithm keyed from a shared secret.
315 Both digital signature and confidentiality services may be applied to
316 the same message. First, a signature is generated for the message and
317 attached to the message. Then, the message plus signature is
318 encrypted using a symmetric session key. Finally, the session key is
319 encrypted using public-key encryption and prefixed to the encrypted
322 2.2. Authentication via Digital signature
324 The digital signature uses a hash code or message digest algorithm,
325 and a public-key signature algorithm. The sequence is as follows:
327 1. The sender creates a message.
329 2. The sending software generates a hash code of the message.
331 3. The sending software generates a signature from the hash code
332 using the sender's private key.
334 4. The binary signature is attached to the message.
338 Callas, et. al. Standards Track [Page 6]
340 RFC 2440 OpenPGP Message Format November 1998
343 5. The receiving software keeps a copy of the message signature.
345 6. The receiving software generates a new hash code for the
346 received message and verifies it using the message's signature.
347 If the verification is successful, the message is accepted as
352 OpenPGP implementations MAY compress the message after applying the
353 signature but before encryption.
355 2.4. Conversion to Radix-64
357 OpenPGP's underlying native representation for encrypted messages,
358 signature certificates, and keys is a stream of arbitrary octets.
359 Some systems only permit the use of blocks consisting of seven-bit,
360 printable text. For transporting OpenPGP's native raw binary octets
361 through channels that are not safe to raw binary data, a printable
362 encoding of these binary octets is needed. OpenPGP provides the
363 service of converting the raw 8-bit binary octet stream to a stream
364 of printable ASCII characters, called Radix-64 encoding or ASCII
367 Implementations SHOULD provide Radix-64 conversions.
369 Note that many applications, particularly messaging applications,
370 will want more advanced features as described in the OpenPGP-MIME
371 document, RFC 2015. An application that implements OpenPGP for
372 messaging SHOULD implement OpenPGP-MIME.
374 2.5. Signature-Only Applications
376 OpenPGP is designed for applications that use both encryption and
377 signatures, but there are a number of problems that are solved by a
378 signature-only implementation. Although this specification requires
379 both encryption and signatures, it is reasonable for there to be
380 subset implementations that are non-comformant only in that they omit
383 3. Data Element Formats
385 This section describes the data elements used by OpenPGP.
394 Callas, et. al. Standards Track [Page 7]
396 RFC 2440 OpenPGP Message Format November 1998
401 Scalar numbers are unsigned, and are always stored in big-endian
402 format. Using n[k] to refer to the kth octet being interpreted, the
403 value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a
404 four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) +
407 3.2. Multi-Precision Integers
409 Multi-Precision Integers (also called MPIs) are unsigned integers
410 used to hold large integers such as the ones used in cryptographic
413 An MPI consists of two pieces: a two-octet scalar that is the length
414 of the MPI in bits followed by a string of octets that contain the
417 These octets form a big-endian number; a big-endian number can be
418 made into an MPI by prefixing it with the appropriate length.
422 (all numbers are in hexadecimal)
424 The string of octets [00 01 01] forms an MPI with the value 1. The
425 string [00 09 01 FF] forms an MPI with the value of 511.
429 The size of an MPI is ((MPI.length + 7) / 8) + 2 octets.
431 The length field of an MPI describes the length starting from its
432 most significant non-zero bit. Thus, the MPI [00 02 01] is not formed
433 correctly. It should be [00 01 01].
437 A Key ID is an eight-octet scalar that identifies a key.
438 Implementations SHOULD NOT assume that Key IDs are unique. The
439 section, "Enhanced Key Formats" below describes how Key IDs are
444 The default character set for text is the UTF-8 [RFC2279] encoding of
450 Callas, et. al. Standards Track [Page 8]
452 RFC 2440 OpenPGP Message Format November 1998
457 A time field is an unsigned four-octet number containing the number
458 of seconds elapsed since midnight, 1 January 1970 UTC.
460 3.6. String-to-key (S2K) specifiers
462 String-to-key (S2K) specifiers are used to convert passphrase strings
463 into symmetric-key encryption/decryption keys. They are used in two
464 places, currently: to encrypt the secret part of private keys in the
465 private keyring, and to convert passphrases to encryption keys for
466 symmetrically encrypted messages.
468 3.6.1. String-to-key (S2k) specifier types
470 There are three types of S2K specifiers currently supported, as
475 This directly hashes the string to produce the key data. See below
476 for how this hashing is done.
479 Octet 1: hash algorithm
481 Simple S2K hashes the passphrase to produce the session key. The
482 manner in which this is done depends on the size of the session key
483 (which will depend on the cipher used) and the size of the hash
484 algorithm's output. If the hash size is greater than or equal to the
485 session key size, the high-order (leftmost) octets of the hash are
488 If the hash size is less than the key size, multiple instances of the
489 hash context are created -- enough to produce the required key data.
490 These instances are preloaded with 0, 1, 2, ... octets of zeros (that
491 is to say, the first instance has no preloading, the second gets
492 preloaded with 1 octet of zero, the third is preloaded with two
493 octets of zeros, and so forth).
495 As the data is hashed, it is given independently to each hash
496 context. Since the contexts have been initialized differently, they
497 will each produce different hash output. Once the passphrase is
498 hashed, the output data from the multiple hashes is concatenated,
499 first hash leftmost, to produce the key data, with any excess octets
500 on the right discarded.
506 Callas, et. al. Standards Track [Page 9]
508 RFC 2440 OpenPGP Message Format November 1998
513 This includes a "salt" value in the S2K specifier -- some arbitrary
514 data -- that gets hashed along with the passphrase string, to help
515 prevent dictionary attacks.
518 Octet 1: hash algorithm
519 Octets 2-9: 8-octet salt value
521 Salted S2K is exactly like Simple S2K, except that the input to the
522 hash function(s) consists of the 8 octets of salt from the S2K
523 specifier, followed by the passphrase.
525 3.6.1.3. Iterated and Salted S2K
527 This includes both a salt and an octet count. The salt is combined
528 with the passphrase and the resulting value is hashed repeatedly.
529 This further increases the amount of work an attacker must do to try
533 Octet 1: hash algorithm
534 Octets 2-9: 8-octet salt value
535 Octet 10: count, a one-octet, coded value
537 The count is coded into a one-octet number using the following
541 count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS);
543 The above formula is in C, where "Int32" is a type for a 32-bit
544 integer, and the variable "c" is the coded count, Octet 10.
546 Iterated-Salted S2K hashes the passphrase and salt data multiple
547 times. The total number of octets to be hashed is specified in the
548 encoded count in the S2K specifier. Note that the resulting count
549 value is an octet count of how many octets will be hashed, not an
552 Initially, one or more hash contexts are set up as with the other S2K
553 algorithms, depending on how many octets of key data are needed.
554 Then the salt, followed by the passphrase data is repeatedly hashed
555 until the number of octets specified by the octet count has been
556 hashed. The one exception is that if the octet count is less than
557 the size of the salt plus passphrase, the full salt plus passphrase
558 will be hashed even though that is greater than the octet count.
562 Callas, et. al. Standards Track [Page 10]
564 RFC 2440 OpenPGP Message Format November 1998
567 After the hashing is done the data is unloaded from the hash
568 context(s) as with the other S2K algorithms.
570 3.6.2. String-to-key usage
572 Implementations SHOULD use salted or iterated-and-salted S2K
573 specifiers, as simple S2K specifiers are more vulnerable to
576 3.6.2.1. Secret key encryption
578 An S2K specifier can be stored in the secret keyring to specify how
579 to convert the passphrase to a key that unlocks the secret data.
580 Older versions of PGP just stored a cipher algorithm octet preceding
581 the secret data or a zero to indicate that the secret data was
582 unencrypted. The MD5 hash function was always used to convert the
583 passphrase to a key for the specified cipher algorithm.
585 For compatibility, when an S2K specifier is used, the special value
586 255 is stored in the position where the hash algorithm octet would
587 have been in the old data structure. This is then followed
588 immediately by a one-octet algorithm identifier, and then by the S2K
589 specifier as encoded above.
591 Therefore, preceding the secret data there will be one of these
594 0: secret data is unencrypted (no pass phrase)
595 255: followed by algorithm octet and S2K specifier
596 Cipher alg: use Simple S2K algorithm using MD5 hash
598 This last possibility, the cipher algorithm number with an implicit
599 use of MD5 and IDEA, is provided for backward compatibility; it MAY
600 be understood, but SHOULD NOT be generated, and is deprecated.
602 These are followed by an 8-octet Initial Vector for the decryption of
603 the secret values, if they are encrypted, and then the secret key
606 3.6.2.2. Symmetric-key message encryption
608 OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) packet
609 at the front of a message. This is used to allow S2K specifiers to
610 be used for the passphrase conversion or to create messages with a
611 mix of symmetric-key ESKs and public-key ESKs. This allows a message
612 to be decrypted either with a passphrase or a public key.
618 Callas, et. al. Standards Track [Page 11]
620 RFC 2440 OpenPGP Message Format November 1998
623 PGP 2.X always used IDEA with Simple string-to-key conversion when
624 encrypting a message with a symmetric algorithm. This is deprecated,
625 but MAY be used for backward-compatibility.
629 This section describes the packets used by OpenPGP.
633 An OpenPGP message is constructed from a number of records that are
634 traditionally called packets. A packet is a chunk of data that has a
635 tag specifying its meaning. An OpenPGP message, keyring, certificate,
636 and so forth consists of a number of packets. Some of those packets
637 may contain other OpenPGP packets (for example, a compressed data
638 packet, when uncompressed, contains OpenPGP packets).
640 Each packet consists of a packet header, followed by the packet body.
641 The packet header is of variable length.
645 The first octet of the packet header is called the "Packet Tag." It
646 determines the format of the header and denotes the packet contents.
647 The remainder of the packet header is the length of the packet.
649 Note that the most significant bit is the left-most bit, called bit
650 7. A mask for this bit is 0x80 in hexadecimal.
653 PTag |7 6 5 4 3 2 1 0|
656 Bit 6 -- New packet format if set
658 PGP 2.6.x only uses old format packets. Thus, software that
659 interoperates with those versions of PGP must only use old format
660 packets. If interoperability is not an issue, either format may be
661 used. Note that old format packets have four bits of content tags,
662 and new format packets have six; some features cannot be used and
663 still be backward-compatible.
665 Old format packets contain:
667 Bits 5-2 -- content tag
668 Bits 1-0 - length-type
674 Callas, et. al. Standards Track [Page 12]
676 RFC 2440 OpenPGP Message Format November 1998
679 New format packets contain:
681 Bits 5-0 -- content tag
683 4.2.1. Old-Format Packet Lengths
685 The meaning of the length-type in old-format packets is:
687 0 - The packet has a one-octet length. The header is 2 octets long.
689 1 - The packet has a two-octet length. The header is 3 octets long.
691 2 - The packet has a four-octet length. The header is 5 octets long.
693 3 - The packet is of indeterminate length. The header is 1 octet
694 long, and the implementation must determine how long the packet
695 is. If the packet is in a file, this means that the packet
696 extends until the end of the file. In general, an implementation
697 SHOULD NOT use indeterminate length packets except where the end
698 of the data will be clear from the context, and even then it is
699 better to use a definite length, or a new-format header. The
700 new-format headers described below have a mechanism for precisely
701 encoding data of indeterminate length.
703 4.2.2. New-Format Packet Lengths
705 New format packets have four possible ways of encoding length:
707 1. A one-octet Body Length header encodes packet lengths of up to
710 2. A two-octet Body Length header encodes packet lengths of 192 to
713 3. A five-octet Body Length header encodes packet lengths of up to
714 4,294,967,295 (0xFFFFFFFF) octets in length. (This actually
715 encodes a four-octet scalar number.)
717 4. When the length of the packet body is not known in advance by the
718 issuer, Partial Body Length headers encode a packet of
719 indeterminate length, effectively making it a stream.
730 Callas, et. al. Standards Track [Page 13]
732 RFC 2440 OpenPGP Message Format November 1998
735 4.2.2.1. One-Octet Lengths
737 A one-octet Body Length header encodes a length of from 0 to 191
738 octets. This type of length header is recognized because the one
739 octet value is less than 192. The body length is equal to:
743 4.2.2.2. Two-Octet Lengths
745 A two-octet Body Length header encodes a length of from 192 to 8383
746 octets. It is recognized because its first octet is in the range 192
747 to 223. The body length is equal to:
749 bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
751 4.2.2.3. Five-Octet Lengths
753 A five-octet Body Length header consists of a single octet holding
754 the value 255, followed by a four-octet scalar. The body length is
757 bodyLen = (2nd_octet << 24) | (3rd_octet << 16) |
758 (4th_octet << 8) | 5th_octet
760 4.2.2.4. Partial Body Lengths
762 A Partial Body Length header is one octet long and encodes the length
763 of only part of the data packet. This length is a power of 2, from 1
764 to 1,073,741,824 (2 to the 30th power). It is recognized by its one
765 octet value that is greater than or equal to 224, and less than 255.
766 The partial body length is equal to:
768 partialBodyLen = 1 << (1st_octet & 0x1f);
770 Each Partial Body Length header is followed by a portion of the
771 packet body data. The Partial Body Length header specifies this
772 portion's length. Another length header (of one of the three types --
773 one octet, two-octet, or partial) follows that portion. The last
774 length header in the packet MUST NOT be a partial Body Length header.
775 Partial Body Length headers may only be used for the non-final parts
778 4.2.3. Packet Length Examples
780 These examples show ways that new-format packets might encode the
786 Callas, et. al. Standards Track [Page 14]
788 RFC 2440 OpenPGP Message Format November 1998
791 A packet with length 100 may have its length encoded in one octet:
792 0x64. This is followed by 100 octets of data.
794 A packet with length 1723 may have its length coded in two octets:
795 0xC5, 0xFB. This header is followed by the 1723 octets of data.
797 A packet with length 100000 may have its length encoded in five
798 octets: 0xFF, 0x00, 0x01, 0x86, 0xA0.
800 It might also be encoded in the following octet stream: 0xEF, first
801 32768 octets of data; 0xE1, next two octets of data; 0xE0, next one
802 octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 1693
803 octets of data. This is just one possible encoding, and many
804 variations are possible on the size of the Partial Body Length
805 headers, as long as a regular Body Length header encodes the last
806 portion of the data. Note also that the last Body Length header can
807 be a zero-length header.
809 An implementation MAY use Partial Body Lengths for data packets, be
810 they literal, compressed, or encrypted. The first partial length MUST
811 be at least 512 octets long. Partial Body Lengths MUST NOT be used
812 for any other packet types.
814 Please note that in all of these explanations, the total length of
815 the packet is the length of the header(s) plus the length of the
820 The packet tag denotes what type of packet the body holds. Note that
821 old format headers can only have tags less than 16, whereas new
822 format headers can have tags as great as 63. The defined tags (in
825 0 -- Reserved - a packet tag must not have this value
826 1 -- Public-Key Encrypted Session Key Packet
827 2 -- Signature Packet
828 3 -- Symmetric-Key Encrypted Session Key Packet
829 4 -- One-Pass Signature Packet
830 5 -- Secret Key Packet
831 6 -- Public Key Packet
832 7 -- Secret Subkey Packet
833 8 -- Compressed Data Packet
834 9 -- Symmetrically Encrypted Data Packet
836 11 -- Literal Data Packet
842 Callas, et. al. Standards Track [Page 15]
844 RFC 2440 OpenPGP Message Format November 1998
848 14 -- Public Subkey Packet
849 60 to 63 -- Private or Experimental Values
853 5.1. Public-Key Encrypted Session Key Packets (Tag 1)
855 A Public-Key Encrypted Session Key packet holds the session key used
856 to encrypt a message. Zero or more Encrypted Session Key packets
857 (either Public-Key or Symmetric-Key) may precede a Symmetrically
858 Encrypted Data Packet, which holds an encrypted message. The message
859 is encrypted with the session key, and the session key is itself
860 encrypted and stored in the Encrypted Session Key packet(s). The
861 Symmetrically Encrypted Data Packet is preceded by one Public-Key
862 Encrypted Session Key packet for each OpenPGP key to which the
863 message is encrypted. The recipient of the message finds a session
864 key that is encrypted to their public key, decrypts the session key,
865 and then uses the session key to decrypt the message.
867 The body of this packet consists of:
869 - A one-octet number giving the version number of the packet type.
870 The currently defined value for packet version is 3. An
871 implementation should accept, but not generate a version of 2,
872 which is equivalent to V3 in all other respects.
874 - An eight-octet number that gives the key ID of the public key
875 that the session key is encrypted to.
877 - A one-octet number giving the public key algorithm used.
879 - A string of octets that is the encrypted session key. This string
880 takes up the remainder of the packet, and its contents are
881 dependent on the public key algorithm used.
883 Algorithm Specific Fields for RSA encryption
885 - multiprecision integer (MPI) of RSA encrypted value m**e mod n.
887 Algorithm Specific Fields for Elgamal encryption:
889 - MPI of Elgamal (Diffie-Hellman) value g**k mod p.
891 - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p.
898 Callas, et. al. Standards Track [Page 16]
900 RFC 2440 OpenPGP Message Format November 1998
903 The value "m" in the above formulas is derived from the session key
904 as follows. First the session key is prefixed with a one-octet
905 algorithm identifier that specifies the symmetric encryption
906 algorithm used to encrypt the following Symmetrically Encrypted Data
907 Packet. Then a two-octet checksum is appended which is equal to the
908 sum of the preceding session key octets, not including the algorithm
909 identifier, modulo 65536. This value is then padded as described in
910 PKCS-1 block type 02 [RFC2313] to form the "m" value used in the
913 Note that when an implementation forms several PKESKs with one
914 session key, forming a message that can be decrypted by several keys,
915 the implementation MUST make new PKCS-1 padding for each key.
917 An implementation MAY accept or use a Key ID of zero as a "wild card"
918 or "speculative" Key ID. In this case, the receiving implementation
919 would try all available private keys, checking for a valid decrypted
920 session key. This format helps reduce traffic analysis of messages.
922 5.2. Signature Packet (Tag 2)
924 A signature packet describes a binding between some public key and
925 some data. The most common signatures are a signature of a file or a
926 block of text, and a signature that is a certification of a user ID.
928 Two versions of signature packets are defined. Version 3 provides
929 basic signature information, while version 4 provides an expandable
930 format with subpackets that can specify more information about the
931 signature. PGP 2.6.x only accepts version 3 signatures.
933 Implementations MUST accept V3 signatures. Implementations SHOULD
934 generate V4 signatures. Implementations MAY generate a V3 signature
935 that can be verified by PGP 2.6.x.
937 Note that if an implementation is creating an encrypted and signed
938 message that is encrypted to a V3 key, it is reasonable to create a
941 5.2.1. Signature Types
943 There are a number of possible meanings for a signature, which are
944 specified in a signature type octet in any given signature. These
947 0x00: Signature of a binary document.
948 Typically, this means the signer owns it, created it, or
949 certifies that it has not been modified.
954 Callas, et. al. Standards Track [Page 17]
956 RFC 2440 OpenPGP Message Format November 1998
959 0x01: Signature of a canonical text document.
960 Typically, this means the signer owns it, created it, or
961 certifies that it has not been modified. The signature is
962 calculated over the text data with its line endings converted
963 to <CR><LF> and trailing blanks removed.
965 0x02: Standalone signature.
966 This signature is a signature of only its own subpacket
967 contents. It is calculated identically to a signature over a
968 zero-length binary document. Note that it doesn't make sense to
969 have a V3 standalone signature.
971 0x10: Generic certification of a User ID and Public Key packet.
972 The issuer of this certification does not make any particular
973 assertion as to how well the certifier has checked that the
974 owner of the key is in fact the person described by the user
975 ID. Note that all PGP "key signatures" are this type of
978 0x11: Persona certification of a User ID and Public Key packet.
979 The issuer of this certification has not done any verification
980 of the claim that the owner of this key is the user ID
983 0x12: Casual certification of a User ID and Public Key packet.
984 The issuer of this certification has done some casual
985 verification of the claim of identity.
987 0x13: Positive certification of a User ID and Public Key packet.
988 The issuer of this certification has done substantial
989 verification of the claim of identity.
991 Please note that the vagueness of these certification claims is
992 not a flaw, but a feature of the system. Because PGP places
993 final authority for validity upon the receiver of a
994 certification, it may be that one authority's casual
995 certification might be more rigorous than some other
996 authority's positive certification. These classifications allow
997 a certification authority to issue fine-grained claims.
999 0x18: Subkey Binding Signature
1000 This signature is a statement by the top-level signing key
1001 indicates that it owns the subkey. This signature is calculated
1002 directly on the subkey itself, not on any User ID or other
1010 Callas, et. al. Standards Track [Page 18]
1012 RFC 2440 OpenPGP Message Format November 1998
1015 0x1F: Signature directly on a key
1016 This signature is calculated directly on a key. It binds the
1017 information in the signature subpackets to the key, and is
1018 appropriate to be used for subpackets that provide information
1019 about the key, such as the revocation key subpacket. It is also
1020 appropriate for statements that non-self certifiers want to
1021 make about the key itself, rather than the binding between a
1024 0x20: Key revocation signature
1025 The signature is calculated directly on the key being revoked.
1026 A revoked key is not to be used. Only revocation signatures by
1027 the key being revoked, or by an authorized revocation key,
1028 should be considered valid revocation signatures.
1030 0x28: Subkey revocation signature
1031 The signature is calculated directly on the subkey being
1032 revoked. A revoked subkey is not to be used. Only revocation
1033 signatures by the top-level signature key that is bound to this
1034 subkey, or by an authorized revocation key, should be
1035 considered valid revocation signatures.
1037 0x30: Certification revocation signature
1038 This signature revokes an earlier user ID certification
1039 signature (signature class 0x10 through 0x13). It should be
1040 issued by the same key that issued the revoked signature or an
1041 authorized revocation key The signature should have a later
1042 creation date than the signature it revokes.
1044 0x40: Timestamp signature.
1045 This signature is only meaningful for the timestamp contained
1048 5.2.2. Version 3 Signature Packet Format
1050 The body of a version 3 Signature Packet contains:
1052 - One-octet version number (3).
1054 - One-octet length of following hashed material. MUST be 5.
1056 - One-octet signature type.
1058 - Four-octet creation time.
1060 - Eight-octet key ID of signer.
1062 - One-octet public key algorithm.
1066 Callas, et. al. Standards Track [Page 19]
1068 RFC 2440 OpenPGP Message Format November 1998
1071 - One-octet hash algorithm.
1073 - Two-octet field holding left 16 bits of signed hash value.
1075 - One or more multi-precision integers comprising the signature.
1076 This portion is algorithm specific, as described below.
1078 The data being signed is hashed, and then the signature type and
1079 creation time from the signature packet are hashed (5 additional
1080 octets). The resulting hash value is used in the signature
1081 algorithm. The high 16 bits (first two octets) of the hash are
1082 included in the signature packet to provide a quick test to reject
1083 some invalid signatures.
1085 Algorithm Specific Fields for RSA signatures:
1087 - multiprecision integer (MPI) of RSA signature value m**d.
1089 Algorithm Specific Fields for DSA signatures:
1091 - MPI of DSA value r.
1093 - MPI of DSA value s.
1095 The signature calculation is based on a hash of the signed data, as
1096 described above. The details of the calculation are different for
1097 DSA signature than for RSA signatures.
1099 With RSA signatures, the hash value is encoded as described in PKCS-1
1100 section 10.1.2, "Data encoding", producing an ASN.1 value of type
1101 DigestInfo, and then padded using PKCS-1 block type 01 [RFC2313].
1102 This requires inserting the hash value as an octet string into an
1103 ASN.1 structure. The object identifier for the type of hash being
1104 used is included in the structure. The hexadecimal representations
1105 for the currently defined hash algorithms are:
1107 - MD2: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02
1109 - MD5: 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05
1111 - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01
1113 - SHA-1: 0x2B, 0x0E, 0x03, 0x02, 0x1A
1122 Callas, et. al. Standards Track [Page 20]
1124 RFC 2440 OpenPGP Message Format November 1998
1129 - MD2: 1.2.840.113549.2.2
1131 - MD5: 1.2.840.113549.2.5
1133 - RIPEMD-160: 1.3.36.3.2.1
1135 - SHA-1: 1.3.14.3.2.26
1137 The full hash prefixes for these are:
1139 MD2: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86,
1140 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00,
1143 MD5: 0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86,
1144 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00,
1147 RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24,
1148 0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14
1150 SHA-1: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E,
1151 0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14
1153 DSA signatures MUST use hashes with a size of 160 bits, to match q,
1154 the size of the group generated by the DSA key's generator value.
1155 The hash function result is treated as a 160 bit number and used
1156 directly in the DSA signature algorithm.
1158 5.2.3. Version 4 Signature Packet Format
1160 The body of a version 4 Signature Packet contains:
1162 - One-octet version number (4).
1164 - One-octet signature type.
1166 - One-octet public key algorithm.
1168 - One-octet hash algorithm.
1170 - Two-octet scalar octet count for following hashed subpacket
1171 data. Note that this is the length in octets of all of the hashed
1172 subpackets; a pointer incremented by this number will skip over
1173 the hashed subpackets.
1178 Callas, et. al. Standards Track [Page 21]
1180 RFC 2440 OpenPGP Message Format November 1998
1183 - Hashed subpacket data. (zero or more subpackets)
1185 - Two-octet scalar octet count for following unhashed subpacket
1186 data. Note that this is the length in octets of all of the
1187 unhashed subpackets; a pointer incremented by this number will
1188 skip over the unhashed subpackets.
1190 - Unhashed subpacket data. (zero or more subpackets)
1192 - Two-octet field holding left 16 bits of signed hash value.
1194 - One or more multi-precision integers comprising the signature.
1195 This portion is algorithm specific, as described above.
1197 The data being signed is hashed, and then the signature data from the
1198 version number through the hashed subpacket data (inclusive) is
1199 hashed. The resulting hash value is what is signed. The left 16 bits
1200 of the hash are included in the signature packet to provide a quick
1201 test to reject some invalid signatures.
1203 There are two fields consisting of signature subpackets. The first
1204 field is hashed with the rest of the signature data, while the second
1205 is unhashed. The second set of subpackets is not cryptographically
1206 protected by the signature and should include only advisory
1209 The algorithms for converting the hash function result to a signature
1210 are described in a section below.
1212 5.2.3.1. Signature Subpacket Specification
1214 The subpacket fields consist of zero or more signature subpackets.
1215 Each set of subpackets is preceded by a two-octet scalar count of the
1216 length of the set of subpackets.
1218 Each subpacket consists of a subpacket header and a body. The header
1221 - the subpacket length (1, 2, or 5 octets)
1223 - the subpacket type (1 octet)
1225 and is followed by the subpacket specific data.
1227 The length includes the type octet but not this length. Its format is
1228 similar to the "new" format packet header lengths, but cannot have
1229 partial body lengths. That is:
1234 Callas, et. al. Standards Track [Page 22]
1236 RFC 2440 OpenPGP Message Format November 1998
1239 if the 1st octet < 192, then
1241 subpacketLen = 1st_octet
1243 if the 1st octet >= 192 and < 255, then
1245 subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
1247 if the 1st octet = 255, then
1249 subpacket length = [four-octet scalar starting at 2nd_octet]
1251 The value of the subpacket type octet may be:
1253 2 = signature creation time
1254 3 = signature expiration time
1255 4 = exportable certification
1257 6 = regular expression
1259 9 = key expiration time
1260 10 = placeholder for backward compatibility
1261 11 = preferred symmetric algorithms
1265 21 = preferred hash algorithms
1266 22 = preferred compression algorithms
1267 23 = key server preferences
1268 24 = preferred key server
1269 25 = primary user id
1272 28 = signer's user id
1273 29 = reason for revocation
1274 100 to 110 = internal or user-defined
1276 An implementation SHOULD ignore any subpacket of a type that it does
1279 Bit 7 of the subpacket type is the "critical" bit. If set, it
1280 denotes that the subpacket is one that is critical for the evaluator
1281 of the signature to recognize. If a subpacket is encountered that is
1282 marked critical but is unknown to the evaluating software, the
1283 evaluator SHOULD consider the signature to be in error.
1290 Callas, et. al. Standards Track [Page 23]
1292 RFC 2440 OpenPGP Message Format November 1998
1295 An evaluator may "recognize" a subpacket, but not implement it. The
1296 purpose of the critical bit is to allow the signer to tell an
1297 evaluator that it would prefer a new, unknown feature to generate an
1298 error than be ignored.
1300 Implementations SHOULD implement "preferences".
1302 5.2.3.2. Signature Subpacket Types
1304 A number of subpackets are currently defined. Some subpackets apply
1305 to the signature itself and some are attributes of the key.
1306 Subpackets that are found on a self-signature are placed on a user id
1307 certification made by the key itself. Note that a key may have more
1308 than one user id, and thus may have more than one self-signature, and
1309 differing subpackets.
1311 A self-signature is a binding signature made by the key the signature
1312 refers to. There are three types of self-signatures, the
1313 certification signatures (types 0x10-0x13), the direct-key signature
1314 (type 0x1f), and the subkey binding signature (type 0x18). For
1315 certification self-signatures, each user ID may have a self-
1316 signature, and thus different subpackets in those self-signatures.
1317 For subkey binding signatures, each subkey in fact has a self-
1318 signature. Subpackets that appear in a certification self-signature
1319 apply to the username, and subpackets that appear in the subkey
1320 self-signature apply to the subkey. Lastly, subpackets on the direct
1321 key signature apply to the entire key.
1323 Implementing software should interpret a self-signature's preference
1324 subpackets as narrowly as possible. For example, suppose a key has
1325 two usernames, Alice and Bob. Suppose that Alice prefers the
1326 symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If the
1327 software locates this key via Alice's name, then the preferred
1328 algorithm is CAST5, if software locates the key via Bob's name, then
1329 the preferred algorithm is IDEA. If the key is located by key id,
1330 then algorithm of the default user id of the key provides the default
1331 symmetric algorithm.
1333 A subpacket may be found either in the hashed or unhashed subpacket
1334 sections of a signature. If a subpacket is not hashed, then the
1335 information in it cannot be considered definitive because it is not
1336 part of the signature proper.
1346 Callas, et. al. Standards Track [Page 24]
1348 RFC 2440 OpenPGP Message Format November 1998
1351 5.2.3.3. Signature creation time
1353 (4 octet time field)
1355 The time the signature was made.
1357 MUST be present in the hashed area.
1363 The OpenPGP key ID of the key issuing the signature.
1365 5.2.3.5. Key expiration time
1367 (4 octet time field)
1369 The validity period of the key. This is the number of seconds after
1370 the key creation time that the key expires. If this is not present
1371 or has a value of zero, the key never expires. This is found only on
1374 5.2.3.6. Preferred symmetric algorithms
1376 (sequence of one-octet values)
1378 Symmetric algorithm numbers that indicate which algorithms the key
1379 holder prefers to use. The subpacket body is an ordered list of
1380 octets with the most preferred listed first. It is assumed that only
1381 algorithms listed are supported by the recipient's software.
1382 Algorithm numbers in section 9. This is only found on a self-
1385 5.2.3.7. Preferred hash algorithms
1387 (array of one-octet values)
1389 Message digest algorithm numbers that indicate which algorithms the
1390 key holder prefers to receive. Like the preferred symmetric
1391 algorithms, the list is ordered. Algorithm numbers are in section 6.
1392 This is only found on a self-signature.
1402 Callas, et. al. Standards Track [Page 25]
1404 RFC 2440 OpenPGP Message Format November 1998
1407 5.2.3.8. Preferred compression algorithms
1409 (array of one-octet values)
1411 Compression algorithm numbers that indicate which algorithms the key
1412 holder prefers to use. Like the preferred symmetric algorithms, the
1413 list is ordered. Algorithm numbers are in section 6. If this
1414 subpacket is not included, ZIP is preferred. A zero denotes that
1415 uncompressed data is preferred; the key holder's software might have
1416 no compression software in that implementation. This is only found on
1419 5.2.3.9. Signature expiration time
1421 (4 octet time field)
1423 The validity period of the signature. This is the number of seconds
1424 after the signature creation time that the signature expires. If this
1425 is not present or has a value of zero, it never expires.
1427 5.2.3.10. Exportable Certification
1429 (1 octet of exportability, 0 for not, 1 for exportable)
1431 This subpacket denotes whether a certification signature is
1432 "exportable", to be used by other users than the signature's issuer.
1433 The packet body contains a boolean flag indicating whether the
1434 signature is exportable. If this packet is not present, the
1435 certification is exportable; it is equivalent to a flag containing a
1438 Non-exportable, or "local", certifications are signatures made by a
1439 user to mark a key as valid within that user's implementation only.
1440 Thus, when an implementation prepares a user's copy of a key for
1441 transport to another user (this is the process of "exporting" the
1442 key), any local certification signatures are deleted from the key.
1444 The receiver of a transported key "imports" it, and likewise trims
1445 any local certifications. In normal operation, there won't be any,
1446 assuming the import is performed on an exported key. However, there
1447 are instances where this can reasonably happen. For example, if an
1448 implementation allows keys to be imported from a key database in
1449 addition to an exported key, then this situation can arise.
1451 Some implementations do not represent the interest of a single user
1452 (for example, a key server). Such implementations always trim local
1453 certifications from any key they handle.
1458 Callas, et. al. Standards Track [Page 26]
1460 RFC 2440 OpenPGP Message Format November 1998
1465 (1 octet of revocability, 0 for not, 1 for revocable)
1467 Signature's revocability status. Packet body contains a boolean flag
1468 indicating whether the signature is revocable. Signatures that are
1469 not revocable have any later revocation signatures ignored. They
1470 represent a commitment by the signer that he cannot revoke his
1471 signature for the life of his key. If this packet is not present,
1472 the signature is revocable.
1474 5.2.3.12. Trust signature
1476 (1 octet "level" (depth), 1 octet of trust amount)
1478 Signer asserts that the key is not only valid, but also trustworthy,
1479 at the specified level. Level 0 has the same meaning as an ordinary
1480 validity signature. Level 1 means that the signed key is asserted to
1481 be a valid trusted introducer, with the 2nd octet of the body
1482 specifying the degree of trust. Level 2 means that the signed key is
1483 asserted to be trusted to issue level 1 trust signatures, i.e. that
1484 it is a "meta introducer". Generally, a level n trust signature
1485 asserts that a key is trusted to issue level n-1 trust signatures.
1486 The trust amount is in a range from 0-255, interpreted such that
1487 values less than 120 indicate partial trust and values of 120 or
1488 greater indicate complete trust. Implementations SHOULD emit values
1489 of 60 for partial trust and 120 for complete trust.
1491 5.2.3.13. Regular expression
1493 (null-terminated regular expression)
1495 Used in conjunction with trust signature packets (of level > 0) to
1496 limit the scope of trust that is extended. Only signatures by the
1497 target key on user IDs that match the regular expression in the body
1498 of this packet have trust extended by the trust signature subpacket.
1499 The regular expression uses the same syntax as the Henry Spencer's
1500 "almost public domain" regular expression package. A description of
1501 the syntax is found in a section below.
1503 5.2.3.14. Revocation key
1505 (1 octet of class, 1 octet of algid, 20 octets of fingerprint)
1507 Authorizes the specified key to issue revocation signatures for this
1508 key. Class octet must have bit 0x80 set. If the bit 0x40 is set,
1509 then this means that the revocation information is sensitive. Other
1510 bits are for future expansion to other kinds of authorizations. This
1514 Callas, et. al. Standards Track [Page 27]
1516 RFC 2440 OpenPGP Message Format November 1998
1519 is found on a self-signature.
1521 If the "sensitive" flag is set, the keyholder feels this subpacket
1522 contains private trust information that describes a real-world
1523 sensitive relationship. If this flag is set, implementations SHOULD
1524 NOT export this signature to other users except in cases where the
1525 data needs to be available: when the signature is being sent to the
1526 designated revoker, or when it is accompanied by a revocation
1527 signature from that revoker. Note that it may be appropriate to
1528 isolate this subpacket within a separate signature so that it is not
1529 combined with other subpackets that need to be exported.
1531 5.2.3.15. Notation Data
1533 (4 octets of flags, 2 octets of name length (M),
1534 2 octets of value length (N),
1535 M octets of name data,
1536 N octets of value data)
1538 This subpacket describes a "notation" on the signature that the
1539 issuer wishes to make. The notation has a name and a value, each of
1540 which are strings of octets. There may be more than one notation in a
1541 signature. Notations can be used for any extension the issuer of the
1542 signature cares to make. The "flags" field holds four octets of
1545 All undefined flags MUST be zero. Defined flags are:
1547 First octet: 0x80 = human-readable. This note is text, a note
1548 from one person to another, and has no
1549 meaning to software.
1552 5.2.3.16. Key server preferences
1556 This is a list of flags that indicate preferences that the key holder
1557 has about how the key is handled on a key server. All undefined flags
1560 First octet: 0x80 = No-modify
1561 the key holder requests that this key only be modified or updated
1562 by the key holder or an administrator of the key server.
1564 This is found only on a self-signature.
1570 Callas, et. al. Standards Track [Page 28]
1572 RFC 2440 OpenPGP Message Format November 1998
1575 5.2.3.17. Preferred key server
1579 This is a URL of a key server that the key holder prefers be used for
1580 updates. Note that keys with multiple user ids can have a preferred
1581 key server for each user id. Note also that since this is a URL, the
1582 key server can actually be a copy of the key retrieved by ftp, http,
1585 5.2.3.18. Primary user id
1589 This is a flag in a user id's self signature that states whether this
1590 user id is the main user id for this key. It is reasonable for an
1591 implementation to resolve ambiguities in preferences, etc. by
1592 referring to the primary user id. If this flag is absent, its value
1593 is zero. If more than one user id in a key is marked as primary, the
1594 implementation may resolve the ambiguity in any way it sees fit.
1596 5.2.3.19. Policy URL
1600 This subpacket contains a URL of a document that describes the policy
1601 that the signature was issued under.
1607 This subpacket contains a list of binary flags that hold information
1608 about a key. It is a string of octets, and an implementation MUST NOT
1609 assume a fixed size. This is so it can grow over time. If a list is
1610 shorter than an implementation expects, the unstated flags are
1611 considered to be zero. The defined flags are:
1615 0x01 - This key may be used to certify other keys.
1617 0x02 - This key may be used to sign data.
1619 0x04 - This key may be used to encrypt communications.
1621 0x08 - This key may be used to encrypt storage.
1626 Callas, et. al. Standards Track [Page 29]
1628 RFC 2440 OpenPGP Message Format November 1998
1631 0x10 - The private component of this key may have been split by a
1632 secret-sharing mechanism.
1634 0x80 - The private component of this key may be in the possession
1635 of more than one person.
1639 The flags in this packet may appear in self-signatures or in
1640 certification signatures. They mean different things depending on who
1641 is making the statement -- for example, a certification signature
1642 that has the "sign data" flag is stating that the certification is
1643 for that use. On the other hand, the "communications encryption" flag
1644 in a self-signature is stating a preference that a given key be used
1645 for communications. Note however, that it is a thorny issue to
1646 determine what is "communications" and what is "storage." This
1647 decision is left wholly up to the implementation; the authors of this
1648 document do not claim any special wisdom on the issue, and realize
1649 that accepted opinion may change.
1651 The "split key" (0x10) and "group key" (0x80) flags are placed on a
1652 self-signature only; they are meaningless on a certification
1653 signature. They SHOULD be placed only on a direct-key signature (type
1654 0x1f) or a subkey signature (type 0x18), one that refers to the key
1655 the flag applies to.
1657 5.2.3.21. Signer's User ID
1659 This subpacket allows a keyholder to state which user id is
1660 responsible for the signing. Many keyholders use a single key for
1661 different purposes, such as business communications as well as
1662 personal communications. This subpacket allows such a keyholder to
1663 state which of their roles is making a signature.
1665 5.2.3.22. Reason for Revocation
1667 (1 octet of revocation code, N octets of reason string)
1669 This subpacket is used only in key revocation and certification
1670 revocation signatures. It describes the reason why the key or
1671 certificate was revoked.
1673 The first octet contains a machine-readable code that denotes the
1674 reason for the revocation:
1682 Callas, et. al. Standards Track [Page 30]
1684 RFC 2440 OpenPGP Message Format November 1998
1687 0x00 - No reason specified (key revocations or cert revocations)
1688 0x01 - Key is superceded (key revocations)
1689 0x02 - Key material has been compromised (key revocations)
1690 0x03 - Key is no longer used (key revocations)
1691 0x20 - User id information is no longer valid (cert revocations)
1693 Following the revocation code is a string of octets which gives
1694 information about the reason for revocation in human-readable form
1695 (UTF-8). The string may be null, that is, of zero length. The length
1696 of the subpacket is the length of the reason string plus one.
1698 5.2.4. Computing Signatures
1700 All signatures are formed by producing a hash over the signature
1701 data, and then using the resulting hash in the signature algorithm.
1703 The signature data is simple to compute for document signatures
1704 (types 0x00 and 0x01), for which the document itself is the data.
1705 For standalone signatures, this is a null string.
1707 When a signature is made over a key, the hash data starts with the
1708 octet 0x99, followed by a two-octet length of the key, and then body
1709 of the key packet. (Note that this is an old-style packet header for
1710 a key packet with two-octet length.) A subkey signature (type 0x18)
1711 then hashes the subkey, using the same format as the main key. Key
1712 revocation signatures (types 0x20 and 0x28) hash only the key being
1715 A certification signature (type 0x10 through 0x13) hashes the user id
1716 being bound to the key into the hash context after the above data. A
1717 V3 certification hashes the contents of the name packet, without any
1718 header. A V4 certification hashes the constant 0xb4 (which is an
1719 old-style packet header with the length-of-length set to zero), a
1720 four-octet number giving the length of the username, and then the
1723 Once the data body is hashed, then a trailer is hashed. A V3
1724 signature hashes five octets of the packet body, starting from the
1725 signature type field. This data is the signature type, followed by
1726 the four-octet signature time. A V4 signature hashes the packet body
1727 starting from its first field, the version number, through the end of
1728 the hashed subpacket data. Thus, the fields hashed are the signature
1729 version, the signature type, the public key algorithm, the hash
1730 algorithm, the hashed subpacket length, and the hashed subpacket
1738 Callas, et. al. Standards Track [Page 31]
1740 RFC 2440 OpenPGP Message Format November 1998
1743 V4 signatures also hash in a final trailer of six octets: the version
1744 of the signature packet, i.e. 0x04; 0xFF; a four-octet, big-endian
1745 number that is the length of the hashed data from the signature
1746 packet (note that this number does not include these final six
1749 After all this has been hashed, the resulting hash field is used in
1750 the signature algorithm, and placed at the end of the signature
1753 5.2.4.1. Subpacket Hints
1755 An implementation SHOULD put the two mandatory subpackets, creation
1756 time and issuer, as the first subpackets in the subpacket list,
1757 simply to make it easier for the implementer to find them.
1759 It is certainly possible for a signature to contain conflicting
1760 information in subpackets. For example, a signature may contain
1761 multiple copies of a preference or multiple expiration times. In most
1762 cases, an implementation SHOULD use the last subpacket in the
1763 signature, but MAY use any conflict resolution scheme that makes more
1764 sense. Please note that we are intentionally leaving conflict
1765 resolution to the implementer; most conflicts are simply syntax
1766 errors, and the wishy-washy language here allows a receiver to be
1767 generous in what they accept, while putting pressure on a creator to
1768 be stingy in what they generate.
1770 Some apparent conflicts may actually make sense -- for example,
1771 suppose a keyholder has an V3 key and a V4 key that share the same
1772 RSA key material. Either of these keys can verify a signature created
1773 by the other, and it may be reasonable for a signature to contain an
1774 issuer subpacket for each key, as a way of explicitly tying those
1775 keys to the signature.
1777 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3)
1779 The Symmetric-Key Encrypted Session Key packet holds the symmetric-
1780 key encryption of a session key used to encrypt a message. Zero or
1781 more Encrypted Session Key packets and/or Symmetric-Key Encrypted
1782 Session Key packets may precede a Symmetrically Encrypted Data Packet
1783 that holds an encrypted message. The message is encrypted with a
1784 session key, and the session key is itself encrypted and stored in
1785 the Encrypted Session Key packet or the Symmetric-Key Encrypted
1788 If the Symmetrically Encrypted Data Packet is preceded by one or more
1789 Symmetric-Key Encrypted Session Key packets, each specifies a
1790 passphrase that may be used to decrypt the message. This allows a
1794 Callas, et. al. Standards Track [Page 32]
1796 RFC 2440 OpenPGP Message Format November 1998
1799 message to be encrypted to a number of public keys, and also to one
1800 or more pass phrases. This packet type is new, and is not generated
1801 by PGP 2.x or PGP 5.0.
1803 The body of this packet consists of:
1805 - A one-octet version number. The only currently defined version
1808 - A one-octet number describing the symmetric algorithm used.
1810 - A string-to-key (S2K) specifier, length as defined above.
1812 - Optionally, the encrypted session key itself, which is decrypted
1813 with the string-to-key object.
1815 If the encrypted session key is not present (which can be detected on
1816 the basis of packet length and S2K specifier size), then the S2K
1817 algorithm applied to the passphrase produces the session key for
1818 decrypting the file, using the symmetric cipher algorithm from the
1819 Symmetric-Key Encrypted Session Key packet.
1821 If the encrypted session key is present, the result of applying the
1822 S2K algorithm to the passphrase is used to decrypt just that
1823 encrypted session key field, using CFB mode with an IV of all zeros.
1824 The decryption result consists of a one-octet algorithm identifier
1825 that specifies the symmetric-key encryption algorithm used to encrypt
1826 the following Symmetrically Encrypted Data Packet, followed by the
1827 session key octets themselves.
1829 Note: because an all-zero IV is used for this decryption, the S2K
1830 specifier MUST use a salt value, either a Salted S2K or an Iterated-
1831 Salted S2K. The salt value will insure that the decryption key is
1832 not repeated even if the passphrase is reused.
1834 5.4. One-Pass Signature Packets (Tag 4)
1836 The One-Pass Signature packet precedes the signed data and contains
1837 enough information to allow the receiver to begin calculating any
1838 hashes needed to verify the signature. It allows the Signature
1839 Packet to be placed at the end of the message, so that the signer can
1840 compute the entire signed message in one pass.
1842 A One-Pass Signature does not interoperate with PGP 2.6.x or earlier.
1844 The body of this packet consists of:
1850 Callas, et. al. Standards Track [Page 33]
1852 RFC 2440 OpenPGP Message Format November 1998
1855 - A one-octet version number. The current version is 3.
1857 - A one-octet signature type. Signature types are described in
1860 - A one-octet number describing the hash algorithm used.
1862 - A one-octet number describing the public key algorithm used.
1864 - An eight-octet number holding the key ID of the signing key.
1866 - A one-octet number holding a flag showing whether the signature
1867 is nested. A zero value indicates that the next packet is
1868 another One-Pass Signature packet that describes another
1869 signature to be applied to the same message data.
1871 Note that if a message contains more than one one-pass signature,
1872 then the signature packets bracket the message; that is, the first
1873 signature packet after the message corresponds to the last one-pass
1874 packet and the final signature packet corresponds to the first one-
1877 5.5. Key Material Packet
1879 A key material packet contains all the information about a public or
1880 private key. There are four variants of this packet type, and two
1881 major versions. Consequently, this section is complex.
1883 5.5.1. Key Packet Variants
1885 5.5.1.1. Public Key Packet (Tag 6)
1887 A Public Key packet starts a series of packets that forms an OpenPGP
1888 key (sometimes called an OpenPGP certificate).
1890 5.5.1.2. Public Subkey Packet (Tag 14)
1892 A Public Subkey packet (tag 14) has exactly the same format as a
1893 Public Key packet, but denotes a subkey. One or more subkeys may be
1894 associated with a top-level key. By convention, the top-level key
1895 provides signature services, and the subkeys provide encryption
1898 Note: in PGP 2.6.x, tag 14 was intended to indicate a comment packet.
1899 This tag was selected for reuse because no previous version of PGP
1900 ever emitted comment packets but they did properly ignore them.
1901 Public Subkey packets are ignored by PGP 2.6.x and do not cause it to
1902 fail, providing a limited degree of backward compatibility.
1906 Callas, et. al. Standards Track [Page 34]
1908 RFC 2440 OpenPGP Message Format November 1998
1911 5.5.1.3. Secret Key Packet (Tag 5)
1913 A Secret Key packet contains all the information that is found in a
1914 Public Key packet, including the public key material, but also
1915 includes the secret key material after all the public key fields.
1917 5.5.1.4. Secret Subkey Packet (Tag 7)
1919 A Secret Subkey packet (tag 7) is the subkey analog of the Secret Key
1920 packet, and has exactly the same format.
1922 5.5.2. Public Key Packet Formats
1924 There are two versions of key-material packets. Version 3 packets
1925 were first generated by PGP 2.6. Version 2 packets are identical in
1926 format to Version 3 packets, but are generated by PGP 2.5 or before.
1927 V2 packets are deprecated and they MUST NOT be generated. PGP 5.0
1928 introduced version 4 packets, with new fields and semantics. PGP
1929 2.6.x will not accept key-material packets with versions greater than
1932 OpenPGP implementations SHOULD create keys with version 4 format. An
1933 implementation MAY generate a V3 key to ensure interoperability with
1934 old software; note, however, that V4 keys correct some security
1935 deficiencies in V3 keys. These deficiencies are described below. An
1936 implementation MUST NOT create a V3 key with a public key algorithm
1939 A version 3 public key or public subkey packet contains:
1941 - A one-octet version number (3).
1943 - A four-octet number denoting the time that the key was created.
1945 - A two-octet number denoting the time in days that this key is
1946 valid. If this number is zero, then it does not expire.
1948 - A one-octet number denoting the public key algorithm of this key
1950 - A series of multi-precision integers comprising the key
1953 - a multiprecision integer (MPI) of RSA public modulus n;
1955 - an MPI of RSA public encryption exponent e.
1962 Callas, et. al. Standards Track [Page 35]
1964 RFC 2440 OpenPGP Message Format November 1998
1967 V3 keys SHOULD only be used for backward compatibility because of
1968 three weaknesses in them. First, it is relatively easy to construct a
1969 V3 key that has the same key ID as any other key because the key ID
1970 is simply the low 64 bits of the public modulus. Secondly, because
1971 the fingerprint of a V3 key hashes the key material, but not its
1972 length, which increases the opportunity for fingerprint collisions.
1973 Third, there are minor weaknesses in the MD5 hash algorithm that make
1974 developers prefer other algorithms. See below for a fuller discussion
1975 of key IDs and fingerprints.
1977 The version 4 format is similar to the version 3 format except for
1978 the absence of a validity period. This has been moved to the
1979 signature packet. In addition, fingerprints of version 4 keys are
1980 calculated differently from version 3 keys, as described in section
1981 "Enhanced Key Formats."
1983 A version 4 packet contains:
1985 - A one-octet version number (4).
1987 - A four-octet number denoting the time that the key was created.
1989 - A one-octet number denoting the public key algorithm of this key
1991 - A series of multi-precision integers comprising the key
1992 material. This algorithm-specific portion is:
1994 Algorithm Specific Fields for RSA public keys:
1996 - multiprecision integer (MPI) of RSA public modulus n;
1998 - MPI of RSA public encryption exponent e.
2000 Algorithm Specific Fields for DSA public keys:
2002 - MPI of DSA prime p;
2004 - MPI of DSA group order q (q is a prime divisor of p-1);
2006 - MPI of DSA group generator g;
2008 - MPI of DSA public key value y (= g**x where x is secret).
2010 Algorithm Specific Fields for Elgamal public keys:
2012 - MPI of Elgamal prime p;
2014 - MPI of Elgamal group generator g;
2018 Callas, et. al. Standards Track [Page 36]
2020 RFC 2440 OpenPGP Message Format November 1998
2023 - MPI of Elgamal public key value y (= g**x where x is
2026 5.5.3. Secret Key Packet Formats
2028 The Secret Key and Secret Subkey packets contain all the data of the
2029 Public Key and Public Subkey packets, with additional algorithm-
2030 specific secret key data appended, in encrypted form.
2032 The packet contains:
2034 - A Public Key or Public Subkey packet, as described above
2036 - One octet indicating string-to-key usage conventions. 0
2037 indicates that the secret key data is not encrypted. 255
2038 indicates that a string-to-key specifier is being given. Any
2039 other value is a symmetric-key encryption algorithm specifier.
2041 - [Optional] If string-to-key usage octet was 255, a one-octet
2042 symmetric encryption algorithm.
2044 - [Optional] If string-to-key usage octet was 255, a string-to-key
2045 specifier. The length of the string-to-key specifier is implied
2046 by its type, as described above.
2048 - [Optional] If secret data is encrypted, eight-octet Initial
2051 - Encrypted multi-precision integers comprising the secret key
2052 data. These algorithm-specific fields are as described below.
2054 - Two-octet checksum of the plaintext of the algorithm-specific
2055 portion (sum of all octets, mod 65536).
2057 Algorithm Specific Fields for RSA secret keys:
2059 - multiprecision integer (MPI) of RSA secret exponent d.
2061 - MPI of RSA secret prime value p.
2063 - MPI of RSA secret prime value q (p < q).
2065 - MPI of u, the multiplicative inverse of p, mod q.
2067 Algorithm Specific Fields for DSA secret keys:
2069 - MPI of DSA secret exponent x.
2074 Callas, et. al. Standards Track [Page 37]
2076 RFC 2440 OpenPGP Message Format November 1998
2079 Algorithm Specific Fields for Elgamal secret keys:
2081 - MPI of Elgamal secret exponent x.
2083 Secret MPI values can be encrypted using a passphrase. If a string-
2084 to-key specifier is given, that describes the algorithm for
2085 converting the passphrase to a key, else a simple MD5 hash of the
2086 passphrase is used. Implementations SHOULD use a string-to-key
2087 specifier; the simple hash is for backward compatibility. The cipher
2088 for encrypting the MPIs is specified in the secret key packet.
2090 Encryption/decryption of the secret data is done in CFB mode using
2091 the key created from the passphrase and the Initial Vector from the
2092 packet. A different mode is used with V3 keys (which are only RSA)
2093 than with other key formats. With V3 keys, the MPI bit count prefix
2094 (i.e., the first two octets) is not encrypted. Only the MPI non-
2095 prefix data is encrypted. Furthermore, the CFB state is
2096 resynchronized at the beginning of each new MPI value, so that the
2097 CFB block boundary is aligned with the start of the MPI data.
2099 With V4 keys, a simpler method is used. All secret MPI values are
2100 encrypted in CFB mode, including the MPI bitcount prefix.
2102 The 16-bit checksum that follows the algorithm-specific portion is
2103 the algebraic sum, mod 65536, of the plaintext of all the algorithm-
2104 specific octets (including MPI prefix and data). With V3 keys, the
2105 checksum is stored in the clear. With V4 keys, the checksum is
2106 encrypted like the algorithm-specific data. This value is used to
2107 check that the passphrase was correct.
2109 5.6. Compressed Data Packet (Tag 8)
2111 The Compressed Data packet contains compressed data. Typically, this
2112 packet is found as the contents of an encrypted packet, or following
2113 a Signature or One-Pass Signature packet, and contains literal data
2116 The body of this packet consists of:
2118 - One octet that gives the algorithm used to compress the packet.
2120 - The remainder of the packet is compressed data.
2122 A Compressed Data Packet's body contains an block that compresses
2123 some set of packets. See section "Packet Composition" for details on
2124 how messages are formed.
2130 Callas, et. al. Standards Track [Page 38]
2132 RFC 2440 OpenPGP Message Format November 1998
2135 ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE
2136 blocks. Note that PGP V2.6 uses 13 bits of compression. If an
2137 implementation uses more bits of compression, PGP V2.6 cannot
2140 ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style
2143 5.7. Symmetrically Encrypted Data Packet (Tag 9)
2145 The Symmetrically Encrypted Data packet contains data encrypted with
2146 a symmetric-key algorithm. When it has been decrypted, it will
2147 typically contain other packets (often literal data packets or
2148 compressed data packets).
2150 The body of this packet consists of:
2152 - Encrypted data, the output of the selected symmetric-key cipher
2153 operating in PGP's variant of Cipher Feedback (CFB) mode.
2155 The symmetric cipher used may be specified in an Public-Key or
2156 Symmetric-Key Encrypted Session Key packet that precedes the
2157 Symmetrically Encrypted Data Packet. In that case, the cipher
2158 algorithm octet is prefixed to the session key before it is
2159 encrypted. If no packets of these types precede the encrypted data,
2160 the IDEA algorithm is used with the session key calculated as the MD5
2161 hash of the passphrase.
2163 The data is encrypted in CFB mode, with a CFB shift size equal to the
2164 cipher's block size. The Initial Vector (IV) is specified as all
2165 zeros. Instead of using an IV, OpenPGP prefixes a 10-octet string to
2166 the data before it is encrypted. The first eight octets are random,
2167 and the 9th and 10th octets are copies of the 7th and 8th octets,
2168 respectively. After encrypting the first 10 octets, the CFB state is
2169 resynchronized if the cipher block size is 8 octets or less. The
2170 last 8 octets of ciphertext are passed through the cipher and the
2171 block boundary is reset.
2173 The repetition of 16 bits in the 80 bits of random data prefixed to
2174 the message allows the receiver to immediately check whether the
2175 session key is incorrect.
2177 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
2179 An experimental version of PGP used this packet as the Literal
2180 packet, but no released version of PGP generated Literal packets with
2181 this tag. With PGP 5.x, this packet has been re-assigned and is
2182 reserved for use as the Marker packet.
2186 Callas, et. al. Standards Track [Page 39]
2188 RFC 2440 OpenPGP Message Format November 1998
2191 The body of this packet consists of:
2193 - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
2195 Such a packet MUST be ignored when received. It may be placed at the
2196 beginning of a message that uses features not available in PGP 2.6.x
2197 in order to cause that version to report that newer software is
2198 necessary to process the message.
2200 5.9. Literal Data Packet (Tag 11)
2202 A Literal Data packet contains the body of a message; data that is
2203 not to be further interpreted.
2205 The body of this packet consists of:
2207 - A one-octet field that describes how the data is formatted.
2209 If it is a 'b' (0x62), then the literal packet contains binary data.
2210 If it is a 't' (0x74), then it contains text data, and thus may need
2211 line ends converted to local form, or other text-mode changes. RFC
2212 1991 also defined a value of 'l' as a 'local' mode for machine-local
2213 conversions. This use is now deprecated.
2215 - File name as a string (one-octet length, followed by file name),
2216 if the encrypted data should be saved as a file.
2218 If the special name "_CONSOLE" is used, the message is considered to
2219 be "for your eyes only". This advises that the message data is
2220 unusually sensitive, and the receiving program should process it more
2221 carefully, perhaps avoiding storing the received data to disk, for
2224 - A four-octet number that indicates the modification date of the
2225 file, or the creation time of the packet, or a zero that
2226 indicates the present time.
2228 - The remainder of the packet is literal data.
2230 Text data is stored with <CR><LF> text endings (i.e. network-normal
2231 line endings). These should be converted to native line endings by
2232 the receiving software.
2234 5.10. Trust Packet (Tag 12)
2236 The Trust packet is used only within keyrings and is not normally
2237 exported. Trust packets contain data that record the user's
2238 specifications of which key holders are trustworthy introducers,
2242 Callas, et. al. Standards Track [Page 40]
2244 RFC 2440 OpenPGP Message Format November 1998
2247 along with other information that implementing software uses for
2250 Trust packets SHOULD NOT be emitted to output streams that are
2251 transferred to other users, and they SHOULD be ignored on any input
2252 other than local keyring files.
2254 5.11. User ID Packet (Tag 13)
2256 A User ID packet consists of data that is intended to represent the
2257 name and email address of the key holder. By convention, it includes
2258 an RFC 822 mail name, but there are no restrictions on its content.
2259 The packet length in the header specifies the length of the user id.
2260 If it is text, it is encoded in UTF-8.
2262 6. Radix-64 Conversions
2264 As stated in the introduction, OpenPGP's underlying native
2265 representation for objects is a stream of arbitrary octets, and some
2266 systems desire these objects to be immune to damage caused by
2267 character set translation, data conversions, etc.
2269 In principle, any printable encoding scheme that met the requirements
2270 of the unsafe channel would suffice, since it would not change the
2271 underlying binary bit streams of the native OpenPGP data structures.
2272 The OpenPGP standard specifies one such printable encoding scheme to
2273 ensure interoperability.
2275 OpenPGP's Radix-64 encoding is composed of two parts: a base64
2276 encoding of the binary data, and a checksum. The base64 encoding is
2277 identical to the MIME base64 content-transfer-encoding [RFC2231,
2278 Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to
2279 protect the raw binary data.
2281 The checksum is a 24-bit CRC converted to four characters of radix-64
2282 encoding by the same MIME base64 transformation, preceded by an
2283 equals sign (=). The CRC is computed by using the generator 0x864CFB
2284 and an initialization of 0xB704CE. The accumulation is done on the
2285 data before it is converted to radix-64, rather than on the converted
2286 data. A sample implementation of this algorithm is in the next
2289 The checksum with its leading equal sign MAY appear on the first line
2290 after the Base64 encoded data.
2292 Rationale for CRC-24: The size of 24 bits fits evenly into printable
2293 base64. The nonzero initialization can detect more errors than a
2294 zero initialization.
2298 Callas, et. al. Standards Track [Page 41]
2300 RFC 2440 OpenPGP Message Format November 1998
2303 6.1. An Implementation of the CRC-24 in "C"
2305 #define CRC24_INIT 0xb704ceL
2306 #define CRC24_POLY 0x1864cfbL
2309 crc24 crc_octets(unsigned char *octets, size_t len)
2311 crc24 crc = CRC24_INIT;
2315 crc ^= (*octets++) << 16;
2316 for (i = 0; i < 8; i++) {
2318 if (crc & 0x1000000)
2322 return crc & 0xffffffL;
2325 6.2. Forming ASCII Armor
2327 When OpenPGP encodes data into ASCII Armor, it puts specific headers
2328 around the data, so OpenPGP can reconstruct the data later. OpenPGP
2329 informs the user what kind of data is encoded in the ASCII armor
2330 through the use of the headers.
2332 Concatenating the following data creates ASCII Armor:
2334 - An Armor Header Line, appropriate for the type of data
2338 - A blank (zero-length, or containing only whitespace) line
2340 - The ASCII-Armored data
2344 - The Armor Tail, which depends on the Armor Header Line.
2346 An Armor Header Line consists of the appropriate header line text
2347 surrounded by five (5) dashes ('-', 0x2D) on either side of the
2348 header line text. The header line text is chosen based upon the type
2349 of data that is being encoded in Armor, and how it is being encoded.
2350 Header line texts include the following strings:
2354 Callas, et. al. Standards Track [Page 42]
2356 RFC 2440 OpenPGP Message Format November 1998
2360 Used for signed, encrypted, or compressed files.
2362 BEGIN PGP PUBLIC KEY BLOCK
2363 Used for armoring public keys
2365 BEGIN PGP PRIVATE KEY BLOCK
2366 Used for armoring private keys
2368 BEGIN PGP MESSAGE, PART X/Y
2369 Used for multi-part messages, where the armor is split amongst Y
2370 parts, and this is the Xth part out of Y.
2372 BEGIN PGP MESSAGE, PART X
2373 Used for multi-part messages, where this is the Xth part of an
2374 unspecified number of parts. Requires the MESSAGE-ID Armor Header
2378 Used for detached signatures, OpenPGP/MIME signatures, and
2379 natures following clearsigned messages. Note that PGP 2.x s BEGIN
2380 PGP MESSAGE for detached signatures.
2382 The Armor Headers are pairs of strings that can give the user or the
2383 receiving OpenPGP implementation some information about how to decode
2384 or use the message. The Armor Headers are a part of the armor, not a
2385 part of the message, and hence are not protected by any signatures
2386 applied to the message.
2388 The format of an Armor Header is that of a key-value pair. A colon
2389 (':' 0x38) and a single space (0x20) separate the key and value.
2390 OpenPGP should consider improperly formatted Armor Headers to be
2391 corruption of the ASCII Armor. Unknown keys should be reported to
2392 the user, but OpenPGP should continue to process the message.
2394 Currently defined Armor Header Keys are:
2396 - "Version", that states the OpenPGP Version used to encode the
2399 - "Comment", a user-defined comment.
2401 - "MessageID", a 32-character string of printable characters. The
2402 string must be the same for all parts of a multi-part message
2403 that uses the "PART X" Armor Header. MessageID strings should be
2410 Callas, et. al. Standards Track [Page 43]
2412 RFC 2440 OpenPGP Message Format November 1998
2415 unique enough that the recipient of the mail can associate all
2416 the parts of a message with each other. A good checksum or
2417 cryptographic hash function is sufficient.
2419 - "Hash", a comma-separated list of hash algorithms used in this
2420 message. This is used only in clear-signed messages.
2422 - "Charset", a description of the character set that the plaintext
2423 is in. Please note that OpenPGP defines text to be in UTF-8 by
2424 default. An implementation will get best results by translating
2425 into and out of UTF-8. However, there are many instances where
2426 this is easier said than done. Also, there are communities of
2427 users who have no need for UTF-8 because they are all happy with
2428 a character set like ISO Latin-5 or a Japanese character set. In
2429 such instances, an implementation MAY override the UTF-8 default
2430 by using this header key. An implementation MAY implement this
2431 key and any translations it cares to; an implementation MAY
2432 ignore it and assume all text is UTF-8.
2434 The MessageID SHOULD NOT appear unless it is in a multi-part
2435 message. If it appears at all, it MUST be computed from the
2436 finished (encrypted, signed, etc.) message in a deterministic
2437 fashion, rather than contain a purely random value. This is to
2438 allow the legitimate recipient to determine that the MessageID
2439 cannot serve as a covert means of leaking cryptographic key
2442 The Armor Tail Line is composed in the same manner as the Armor
2443 Header Line, except the string "BEGIN" is replaced by the string
2446 6.3. Encoding Binary in Radix-64
2448 The encoding process represents 24-bit groups of input bits as output
2449 strings of 4 encoded characters. Proceeding from left to right, a
2450 24-bit input group is formed by concatenating three 8-bit input
2451 groups. These 24 bits are then treated as four concatenated 6-bit
2452 groups, each of which is translated into a single digit in the
2453 Radix-64 alphabet. When encoding a bit stream with the Radix-64
2454 encoding, the bit stream must be presumed to be ordered with the
2455 most-significant-bit first. That is, the first bit in the stream will
2456 be the high-order bit in the first 8-bit octet, and the eighth bit
2457 will be the low-order bit in the first 8-bit octet, and so on.
2466 Callas, et. al. Standards Track [Page 44]
2468 RFC 2440 OpenPGP Message Format November 1998
2471 +--first octet--+-second octet--+--third octet--+
2472 |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|
2473 +-----------+---+-------+-------+---+-----------+
2474 |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|
2475 +--1.index--+--2.index--+--3.index--+--4.index--+
2477 Each 6-bit group is used as an index into an array of 64 printable
2478 characters from the table below. The character referenced by the
2479 index is placed in the output string.
2481 Value Encoding Value Encoding Value Encoding Value Encoding
2496 14 O 31 f 48 w (pad) =
2500 The encoded output stream must be represented in lines of no more
2501 than 76 characters each.
2503 Special processing is performed if fewer than 24 bits are available
2504 at the end of the data being encoded. There are three possibilities:
2506 1. The last data group has 24 bits (3 octets). No special
2507 processing is needed.
2509 2. The last data group has 16 bits (2 octets). The first two 6-bit
2510 groups are processed as above. The third (incomplete) data group
2511 has two zero-value bits added to it, and is processed as above.
2512 A pad character (=) is added to the output.
2514 3. The last data group has 8 bits (1 octet). The first 6-bit group
2515 is processed as above. The second (incomplete) data group has
2516 four zero-value bits added to it, and is processed as above. Two
2517 pad characters (=) are added to the output.
2522 Callas, et. al. Standards Track [Page 45]
2524 RFC 2440 OpenPGP Message Format November 1998
2527 6.4. Decoding Radix-64
2529 Any characters outside of the base64 alphabet are ignored in Radix-64
2530 data. Decoding software must ignore all line breaks or other
2531 characters not found in the table above.
2533 In Radix-64 data, characters other than those in the table, line
2534 breaks, and other white space probably indicate a transmission error,
2535 about which a warning message or even a message rejection might be
2536 appropriate under some circumstances.
2538 Because it is used only for padding at the end of the data, the
2539 occurrence of any "=" characters may be taken as evidence that the
2540 end of the data has been reached (without truncation in transit). No
2541 such assurance is possible, however, when the number of octets
2542 transmitted was a multiple of three and no "=" characters are
2545 6.5. Examples of Radix-64
2547 Input data: 0x14fb9c03d97e
2548 Hex: 1 4 f b 9 c | 0 3 d 9 7 e
2549 8-bit: 00010100 11111011 10011100 | 00000011 11011001
2551 6-bit: 000101 001111 101110 011100 | 000000 111101 100111
2553 Decimal: 5 15 46 28 0 61 37 62
2554 Output: F P u c A 9 l +
2556 Input data: 0x14fb9c03d9
2557 Hex: 1 4 f b 9 c | 0 3 d 9
2558 8-bit: 00010100 11111011 10011100 | 00000011 11011001
2560 6-bit: 000101 001111 101110 011100 | 000000 111101 100100
2561 Decimal: 5 15 46 28 0 61 36
2563 Output: F P u c A 9 k =
2565 Input data: 0x14fb9c03
2566 Hex: 1 4 f b 9 c | 0 3
2567 8-bit: 00010100 11111011 10011100 | 00000011
2569 6-bit: 000101 001111 101110 011100 | 000000 110000
2570 Decimal: 5 15 46 28 0 48
2572 Output: F P u c A w = =
2578 Callas, et. al. Standards Track [Page 46]
2580 RFC 2440 OpenPGP Message Format November 1998
2583 6.6. Example of an ASCII Armored Message
2586 -----BEGIN PGP MESSAGE-----
2587 Version: OpenPrivacy 0.99
2589 yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
2592 -----END PGP MESSAGE-----
2594 Note that this example is indented by two spaces.
2596 7. Cleartext signature framework
2598 It is desirable to sign a textual octet stream without ASCII armoring
2599 the stream itself, so the signed text is still readable without
2600 special software. In order to bind a signature to such a cleartext,
2601 this framework is used. (Note that RFC 2015 defines another way to
2602 clear sign messages for environments that support MIME.)
2604 The cleartext signed message consists of:
2606 - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a
2609 - One or more "Hash" Armor Headers,
2611 - Exactly one empty line not included into the message digest,
2613 - The dash-escaped cleartext that is included into the message
2616 - The ASCII armored signature(s) including the '-----BEGIN PGP
2617 SIGNATURE-----' Armor Header and Armor Tail Lines.
2619 If the "Hash" armor header is given, the specified message digest
2620 algorithm is used for the signature. If there are no such headers,
2621 MD5 is used, an implementation MAY omit them for V2.x compatibility.
2622 If more than one message digest is used in the signature, the "Hash"
2623 armor header contains a comma-delimited list of used message digests.
2625 Current message digest names are described below with the algorithm
2628 7.1. Dash-Escaped Text
2630 The cleartext content of the message must also be dash-escaped.
2634 Callas, et. al. Standards Track [Page 47]
2636 RFC 2440 OpenPGP Message Format November 1998
2639 Dash escaped cleartext is the ordinary cleartext where every line
2640 starting with a dash '-' (0x2D) is prefixed by the sequence dash '-'
2641 (0x2D) and space ' ' (0x20). This prevents the parser from
2642 recognizing armor headers of the cleartext itself. The message digest
2643 is computed using the cleartext itself, not the dash escaped form.
2645 As with binary signatures on text documents, a cleartext signature is
2646 calculated on the text using canonical <CR><LF> line endings. The
2647 line ending (i.e. the <CR><LF>) before the '-----BEGIN PGP
2648 SIGNATURE-----' line that terminates the signed text is not
2649 considered part of the signed text.
2651 Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of
2652 any line is ignored when the cleartext signature is calculated.
2654 8. Regular Expressions
2656 A regular expression is zero or more branches, separated by '|'. It
2657 matches anything that matches one of the branches.
2659 A branch is zero or more pieces, concatenated. It matches a match for
2660 the first, followed by a match for the second, etc.
2662 A piece is an atom possibly followed by '*', '+', or '?'. An atom
2663 followed by '*' matches a sequence of 0 or more matches of the atom.
2664 An atom followed by '+' matches a sequence of 1 or more matches of
2665 the atom. An atom followed by '?' matches a match of the atom, or the
2668 An atom is a regular expression in parentheses (matching a match for
2669 the regular expression), a range (see below), '.' (matching any
2670 single character), '^' (matching the null string at the beginning of
2671 the input string), '$' (matching the null string at the end of the
2672 input string), a '\' followed by a single character (matching that
2673 character), or a single character with no other significance
2674 (matching that character).
2676 A range is a sequence of characters enclosed in '[]'. It normally
2677 matches any single character from the sequence. If the sequence
2678 begins with '^', it matches any single character not from the rest of
2679 the sequence. If two characters in the sequence are separated by '-',
2680 this is shorthand for the full list of ASCII characters between them
2681 (e.g. '[0-9]' matches any decimal digit). To include a literal ']' in
2682 the sequence, make it the first character (following a possible '^').
2683 To include a literal '-', make it the first or last character.
2690 Callas, et. al. Standards Track [Page 48]
2692 RFC 2440 OpenPGP Message Format November 1998
2697 This section describes the constants used in OpenPGP.
2699 Note that these tables are not exhaustive lists; an implementation
2700 MAY implement an algorithm not on these lists.
2702 See the section "Notes on Algorithms" below for more discussion of
2705 9.1. Public Key Algorithms
2709 1 - RSA (Encrypt or Sign)
2710 2 - RSA Encrypt-Only
2712 16 - Elgamal (Encrypt-Only), see [ELGAMAL]
2713 17 - DSA (Digital Signature Standard)
2714 18 - Reserved for Elliptic Curve
2715 19 - Reserved for ECDSA
2716 20 - Elgamal (Encrypt or Sign)
2722 21 - Reserved for Diffie-Hellman (X9.42,
2723 as defined for IETF-S/MIME)
2724 100 to 110 - Private/Experimental algorithm.
2726 Implementations MUST implement DSA for signatures, and Elgamal for
2727 encryption. Implementations SHOULD implement RSA keys.
2728 Implementations MAY implement any other algorithm.
2730 9.2. Symmetric Key Algorithms
2734 0 - Plaintext or unencrypted data
2736 2 - Triple-DES (DES-EDE, as per spec -
2737 168 bit key derived from 192)
2738 3 - CAST5 (128 bit key, as per RFC 2144)
2739 4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH]
2740 5 - SAFER-SK128 (13 rounds) [SAFER]
2741 6 - Reserved for DES/SK
2742 7 - Reserved for AES with 128-bit key
2746 Callas, et. al. Standards Track [Page 49]
2748 RFC 2440 OpenPGP Message Format November 1998
2751 8 - Reserved for AES with 192-bit key
2752 9 - Reserved for AES with 256-bit key
2753 100 to 110 - Private/Experimental algorithm.
2755 Implementations MUST implement Triple-DES. Implementations SHOULD
2756 implement IDEA and CAST5.Implementations MAY implement any other
2759 9.3. Compression Algorithms
2766 100 to 110 - Private/Experimental algorithm.
2768 Implementations MUST implement uncompressed data. Implementations
2769 SHOULD implement ZIP. Implementations MAY implement ZLIB.
2771 9.4. Hash Algorithms
2773 ID Algorithm Text Name
2774 -- --------- ---- ----
2777 3 - RIPE-MD/160 "RIPEMD160"
2778 4 - Reserved for double-width SHA (experimental)
2780 6 - Reserved for TIGER/192 "TIGER192"
2781 7 - Reserved for HAVAL (5 pass, 160-bit)
2783 100 to 110 - Private/Experimental algorithm.
2785 Implementations MUST implement SHA-1. Implementations SHOULD
2788 10. Packet Composition
2790 OpenPGP packets are assembled into sequences in order to create
2791 messages and to transfer keys. Not all possible packet sequences are
2792 meaningful and correct. This describes the rules for how packets
2793 should be placed into sequences.
2795 10.1. Transferable Public Keys
2797 OpenPGP users may transfer public keys. The essential elements of a
2798 transferable public key are:
2802 Callas, et. al. Standards Track [Page 50]
2804 RFC 2440 OpenPGP Message Format November 1998
2807 - One Public Key packet
2809 - Zero or more revocation signatures
2811 - One or more User ID packets
2813 - After each User ID packet, zero or more signature packets
2816 - Zero or more Subkey packets
2818 - After each Subkey packet, one signature packet, optionally a
2821 The Public Key packet occurs first. Each of the following User ID
2822 packets provides the identity of the owner of this public key. If
2823 there are multiple User ID packets, this corresponds to multiple
2824 means of identifying the same unique individual user; for example, a
2825 user may have more than one email address, and construct a User ID
2828 Immediately following each User ID packet, there are zero or more
2829 signature packets. Each signature packet is calculated on the
2830 immediately preceding User ID packet and the initial Public Key
2831 packet. The signature serves to certify the corresponding public key
2832 and user ID. In effect, the signer is testifying to his or her
2833 belief that this public key belongs to the user identified by this
2836 After the User ID packets there may be one or more Subkey packets.
2837 In general, subkeys are provided in cases where the top-level public
2838 key is a signature-only key. However, any V4 key may have subkeys,
2839 and the subkeys may be encryption-only keys, signature-only keys, or
2840 general-purpose keys.
2842 Each Subkey packet must be followed by one Signature packet, which
2843 should be a subkey binding signature issued by the top level key.
2845 Subkey and Key packets may each be followed by a revocation Signature
2846 packet to indicate that the key is revoked. Revocation signatures
2847 are only accepted if they are issued by the key itself, or by a key
2848 that is authorized to issue revocations via a revocation key
2849 subpacket in a self-signature by the top level key.
2851 Transferable public key packet sequences may be concatenated to allow
2852 transferring multiple public keys in one operation.
2858 Callas, et. al. Standards Track [Page 51]
2860 RFC 2440 OpenPGP Message Format November 1998
2863 10.2. OpenPGP Messages
2865 An OpenPGP message is a packet or sequence of packets that
2866 corresponds to the following grammatical rules (comma represents
2867 sequential composition, and vertical bar separates alternatives):
2869 OpenPGP Message :- Encrypted Message | Signed Message |
2870 Compressed Message | Literal Message.
2872 Compressed Message :- Compressed Data Packet.
2874 Literal Message :- Literal Data Packet.
2876 ESK :- Public Key Encrypted Session Key Packet |
2877 Symmetric-Key Encrypted Session Key Packet.
2879 ESK Sequence :- ESK | ESK Sequence, ESK.
2881 Encrypted Message :- Symmetrically Encrypted Data Packet |
2882 ESK Sequence, Symmetrically Encrypted Data Packet.
2884 One-Pass Signed Message :- One-Pass Signature Packet,
2885 OpenPGP Message, Corresponding Signature Packet.
2887 Signed Message :- Signature Packet, OpenPGP Message |
2888 One-Pass Signed Message.
2890 In addition, decrypting a Symmetrically Encrypted Data packet and
2892 decompressing a Compressed Data packet must yield a valid OpenPGP
2895 10.3. Detached Signatures
2897 Some OpenPGP applications use so-called "detached signatures." For
2898 example, a program bundle may contain a file, and with it a second
2899 file that is a detached signature of the first file. These detached
2900 signatures are simply a signature packet stored separately from the
2901 data that they are a signature of.
2903 11. Enhanced Key Formats
2905 11.1. Key Structures
2907 The format of an OpenPGP V3 key is as follows. Entries in square
2908 brackets are optional and ellipses indicate repetition.
2914 Callas, et. al. Standards Track [Page 52]
2916 RFC 2440 OpenPGP Message Format November 1998
2920 [Revocation Self Signature]
2921 User ID [Signature ...]
2922 [User ID [Signature ...] ...]
2924 Each signature certifies the RSA public key and the preceding user
2925 ID. The RSA public key can have many user IDs and each user ID can
2926 have many signatures.
2928 The format of an OpenPGP V4 key that uses two public keys is similar
2929 except that the other keys are added to the end as 'subkeys' of the
2933 [Revocation Self Signature]
2934 [Direct Key Self Signature...]
2935 User ID [Signature ...]
2936 [User ID [Signature ...] ...]
2937 [[Subkey [Binding-Signature-Revocation]
2938 Primary-Key-Binding-Signature] ...]
2940 A subkey always has a single signature after it that is issued using
2941 the primary key to tie the two keys together. This binding signature
2942 may be in either V3 or V4 format, but V4 is preferred, of course.
2944 In the above diagram, if the binding signature of a subkey has been
2945 revoked, the revoked binding signature may be removed, leaving only
2948 In a key that has a main key and subkeys, the primary key MUST be a
2949 key capable of signing. The subkeys may be keys of any other type.
2950 There may be other constructions of V4 keys, too. For example, there
2951 may be a single-key RSA key in V4 format, a DSA primary key with an
2952 RSA encryption key, or RSA primary key with an Elgamal subkey, etc.
2954 It is also possible to have a signature-only subkey. This permits a
2955 primary key that collects certifications (key signatures) but is used
2956 only used for certifying subkeys that are used for encryption and
2959 11.2. Key IDs and Fingerprints
2961 For a V3 key, the eight-octet key ID consists of the low 64 bits of
2962 the public modulus of the RSA key.
2964 The fingerprint of a V3 key is formed by hashing the body (but not
2965 the two-octet length) of the MPIs that form the key material (public
2966 modulus n, followed by exponent e) with MD5.
2970 Callas, et. al. Standards Track [Page 53]
2972 RFC 2440 OpenPGP Message Format November 1998
2975 A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet
2976 Tag, followed by the two-octet packet length, followed by the entire
2977 Public Key packet starting with the version field. The key ID is the
2978 low order 64 bits of the fingerprint. Here are the fields of the
2979 hash material, with the example of a DSA key:
2983 a.2) high order length octet of (b)-(f) (1 octet)
2985 a.3) low order length octet of (b)-(f) (1 octet)
2987 b) version number = 4 (1 octet);
2989 c) time stamp of key creation (4 octets);
2991 d) algorithm (1 octet): 17 = DSA (example);
2993 e) Algorithm specific fields.
2995 Algorithm Specific Fields for DSA keys (example):
2997 e.1) MPI of DSA prime p;
2999 e.2) MPI of DSA group order q (q is a prime divisor of p-1);
3001 e.3) MPI of DSA group generator g;
3003 e.4) MPI of DSA public key value y (= g**x where x is secret).
3005 Note that it is possible for there to be collisions of key IDs -- two
3006 different keys with the same key ID. Note that there is a much
3007 smaller, but still non-zero probability that two different keys have
3008 the same fingerprint.
3010 Also note that if V3 and V4 format keys share the same RSA key
3011 material, they will have different key ids as well as different
3014 12. Notes on Algorithms
3016 12.1. Symmetric Algorithm Preferences
3018 The symmetric algorithm preference is an ordered list of algorithms
3019 that the keyholder accepts. Since it is found on a self-signature, it
3020 is possible that a keyholder may have different preferences. For
3021 example, Alice may have TripleDES only specified for "alice@work.com"
3022 but CAST5, Blowfish, and TripleDES specified for "alice@home.org".
3026 Callas, et. al. Standards Track [Page 54]
3028 RFC 2440 OpenPGP Message Format November 1998
3031 Note that it is also possible for preferences to be in a subkey's
3034 Since TripleDES is the MUST-implement algorithm, if it is not
3035 explicitly in the list, it is tacitly at the end. However, it is good
3036 form to place it there explicitly. Note also that if an
3037 implementation does not implement the preference, then it is
3038 implicitly a TripleDES-only implementation.
3040 An implementation MUST not use a symmetric algorithm that is not in
3041 the recipient's preference list. When encrypting to more than one
3042 recipient, the implementation finds a suitable algorithm by taking
3043 the intersection of the preferences of the recipients. Note that the
3044 MUST-implement algorithm, TripleDES, ensures that the intersection is
3045 not null. The implementation may use any mechanism to pick an
3046 algorithm in the intersection.
3048 If an implementation can decrypt a message that a keyholder doesn't
3049 have in their preferences, the implementation SHOULD decrypt the
3050 message anyway, but MUST warn the keyholder than protocol has been
3051 violated. (For example, suppose that Alice, above, has software that
3052 implements all algorithms in this specification. Nonetheless, she
3053 prefers subsets for work or home. If she is sent a message encrypted
3054 with IDEA, which is not in her preferences, the software warns her
3055 that someone sent her an IDEA-encrypted message, but it would ideally
3058 An implementation that is striving for backward compatibility MAY
3059 consider a V3 key with a V3 self-signature to be an implicit
3060 preference for IDEA, and no ability to do TripleDES. This is
3061 technically non-compliant, but an implementation MAY violate the
3062 above rule in this case only and use IDEA to encrypt the message,
3063 provided that the message creator is warned. Ideally, though, the
3064 implementation would follow the rule by actually generating two
3065 messages, because it is possible that the OpenPGP user's
3066 implementation does not have IDEA, and thus could not read the
3067 message. Consequently, an implementation MAY, but SHOULD NOT use IDEA
3068 in an algorithm conflict with a V3 key.
3070 12.2. Other Algorithm Preferences
3072 Other algorithm preferences work similarly to the symmetric algorithm
3073 preference, in that they specify which algorithms the keyholder
3074 accepts. There are two interesting cases that other comments need to
3075 be made about, though, the compression preferences and the hash
3082 Callas, et. al. Standards Track [Page 55]
3084 RFC 2440 OpenPGP Message Format November 1998
3087 12.2.1. Compression Preferences
3089 Compression has been an integral part of PGP since its first days.
3090 OpenPGP and all previous versions of PGP have offered compression.
3091 And in this specification, the default is for messages to be
3092 compressed, although an implementation is not required to do so.
3093 Consequently, the compression preference gives a way for a keyholder
3094 to request that messages not be compressed, presumably because they
3095 are using a minimal implementation that does not include compression.
3096 Additionally, this gives a keyholder a way to state that it can
3097 support alternate algorithms.
3099 Like the algorithm preferences, an implementation MUST NOT use an
3100 algorithm that is not in the preference vector. If the preferences
3101 are not present, then they are assumed to be [ZIP(1),
3104 12.2.2. Hash Algorithm Preferences
3106 Typically, the choice of a hash algorithm is something the signer
3107 does, rather than the verifier, because a signer does not typically
3108 know who is going to be verifying the signature. This preference,
3109 though, allows a protocol based upon digital signatures ease in
3112 Thus, if Alice is authenticating herself to Bob with a signature, it
3113 makes sense for her to use a hash algorithm that Bob's software uses.
3114 This preference allows Bob to state in his key which algorithms Alice
3119 Algorithm 0, "plaintext", may only be used to denote secret keys that
3120 are stored in the clear. Implementations must not use plaintext in
3121 Symmetrically Encrypted Data Packets; they must use Literal Data
3122 Packets to encode unencrypted or literal data.
3126 There are algorithm types for RSA-signature-only, and RSA-encrypt-
3127 only keys. These types are deprecated. The "key flags" subpacket in a
3128 signature is a much better way to express the same idea, and
3129 generalizes it to all algorithms. An implementation SHOULD NOT create
3130 such a key, but MAY interpret it.
3132 An implementation SHOULD NOT implement RSA keys of size less than 768
3138 Callas, et. al. Standards Track [Page 56]
3140 RFC 2440 OpenPGP Message Format November 1998
3143 It is permissible for an implementation to support RSA merely for
3144 backward compatibility; for example, such an implementation would
3145 support V3 keys with IDEA symmetric cryptography. Note that this is
3146 an exception to the other MUST-implement rules. An implementation
3147 that supports RSA in V4 keys MUST implement the MUST-implement
3152 If an Elgamal key is to be used for both signing and encryption,
3153 extra care must be taken in creating the key.
3155 An ElGamal key consists of a generator g, a prime modulus p, a secret
3156 exponent x, and a public value y = g^x mod p.
3158 The generator and prime must be chosen so that solving the discrete
3159 log problem is intractable. The group g should generate the
3160 multiplicative group mod p-1 or a large subgroup of it, and the order
3161 of g should have at least one large prime factor. A good choice is
3162 to use a "strong" Sophie-Germain prime in choosing p, so that both p
3163 and (p-1)/2 are primes. In fact, this choice is so good that
3164 implementors SHOULD do it, as it avoids a small subgroup attack.
3166 In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that
3167 if the generator g has only small prime factors, and if g divides the
3168 order of the group it generates, then signatures can be forged. In
3169 particular, choosing g=2 is a bad choice if the group order may be
3170 even. On the other hand, a generator of 2 is a fine choice for an
3171 encryption-only key, as this will make the encryption faster.
3173 While verifying Elgamal signatures, note that it is important to test
3174 that r and s are less than p. If this test is not done then
3175 signatures can be trivially forged by using large r values of
3176 approximately twice the length of p. This attack is also discussed
3177 in the Bleichenbacher paper.
3179 Details on safe use of Elgamal signatures may be found in [MENEZES],
3180 which discusses all the weaknesses described above.
3182 If an implementation allows Elgamal signatures, then it MUST use the
3183 algorithm identifier 20 for an Elgamal public key that can sign.
3185 An implementation SHOULD NOT implement Elgamal keys of size less than
3186 768 bits. For long-term security, Elgamal keys should be 1024 bits or
3194 Callas, et. al. Standards Track [Page 57]
3196 RFC 2440 OpenPGP Message Format November 1998
3201 An implementation SHOULD NOT implement DSA keys of size less than 768
3202 bits. Note that present DSA is limited to a maximum of 1024 bit keys,
3203 which are recommended for long-term use.
3205 12.7. Reserved Algorithm Numbers
3207 A number of algorithm IDs have been reserved for algorithms that
3208 would be useful to use in an OpenPGP implementation, yet there are
3209 issues that prevent an implementor from actually implementing the
3210 algorithm. These are marked in the Public Algorithms section as
3213 The reserved public key algorithms, Elliptic Curve (18), ECDSA (19),
3214 and X9.42 (21) do not have the necessary parameters, parameter order,
3215 or semantics defined.
3217 The reserved symmetric key algorithm, DES/SK (6), does not have
3220 The reserved hash algorithms, TIGER192 (6), and HAVAL-5-160 (7), do
3221 not have OIDs. The reserved algorithm number 4, reserved for a
3222 double-width variant of SHA1, is not presently defined.
3224 We have reserver three algorithm IDs for the US NIST's Advanced
3225 Encryption Standard. This algorithm will work with (at least) 128,
3226 192, and 256-bit keys. We expect that this algorithm will be selected
3227 from the candidate algorithms in the year 2000.
3229 12.8. OpenPGP CFB mode
3231 OpenPGP does symmetric encryption using a variant of Cipher Feedback
3232 Mode (CFB mode). This section describes the procedure it uses in
3233 detail. This mode is what is used for Symmetrically Encrypted Data
3234 Packets; the mechanism used for encrypting secret key material is
3235 similar, but described in those sections above.
3237 OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and
3238 prefixes the plaintext with ten octets of random data, such that
3239 octets 9 and 10 match octets 7 and 8. It does a CFB "resync" after
3240 encrypting those ten octets.
3242 Note that for an algorithm that has a larger block size than 64 bits,
3243 the equivalent function will be done with that entire block. For
3244 example, a 16-octet block algorithm would operate on 16 octets, and
3245 then produce two octets of check, and then work on 16-octet blocks.
3250 Callas, et. al. Standards Track [Page 58]
3252 RFC 2440 OpenPGP Message Format November 1998
3255 Step by step, here is the procedure:
3257 1. The feedback register (FR) is set to the IV, which is all zeros.
3259 2. FR is encrypted to produce FRE (FR Encrypted). This is the
3260 encryption of an all-zero value.
3262 3. FRE is xored with the first 8 octets of random data prefixed to
3263 the plaintext to produce C1-C8, the first 8 octets of ciphertext.
3265 4. FR is loaded with C1-C8.
3267 5. FR is encrypted to produce FRE, the encryption of the first 8
3268 octets of ciphertext.
3270 6. The left two octets of FRE get xored with the next two octets of
3271 data that were prefixed to the plaintext. This produces C9-C10,
3272 the next two octets of ciphertext.
3274 7. (The resync step) FR is loaded with C3-C10.
3276 8. FR is encrypted to produce FRE.
3278 9. FRE is xored with the first 8 octets of the given plaintext, now
3279 that we have finished encrypting the 10 octets of prefixed data.
3280 This produces C11-C18, the next 8 octets of ciphertext.
3282 10. FR is loaded with C11-C18
3284 11. FR is encrypted to produce FRE.
3286 12. FRE is xored with the next 8 octets of plaintext, to produce the
3287 next 8 octets of ciphertext. These are loaded into FR and the
3288 process is repeated until the plaintext is used up.
3290 13. Security Considerations
3292 As with any technology involving cryptography, you should check the
3293 current literature to determine if any algorithms used here have been
3294 found to be vulnerable to attack.
3296 This specification uses Public Key Cryptography technologies.
3297 Possession of the private key portion of a public-private key pair is
3298 assumed to be controlled by the proper party or parties.
3300 Certain operations in this specification involve the use of random
3301 numbers. An appropriate entropy source should be used to generate
3302 these numbers. See RFC 1750.
3306 Callas, et. al. Standards Track [Page 59]
3308 RFC 2440 OpenPGP Message Format November 1998
3311 The MD5 hash algorithm has been found to have weaknesses (pseudo-
3312 collisions in the compress function) that make some people deprecate
3313 its use. They consider the SHA-1 algorithm better.
3315 Many security protocol designers think that it is a bad idea to use a
3316 single key for both privacy (encryption) and integrity (signatures).
3317 In fact, this was one of the motivating forces behind the V4 key
3318 format with separate signature and encryption keys. If you as an
3319 implementor promote dual-use keys, you should at least be aware of
3322 The DSA algorithm will work with any 160-bit hash, but it is
3323 sensitive to the quality of the hash algorithm, if the hash algorithm
3324 is broken, it can leak the secret key. The Digital Signature Standard
3325 (DSS) specifies that DSA be used with SHA-1. RIPEMD-160 is
3326 considered by many cryptographers to be as strong. An implementation
3327 should take care which hash algorithms are used with DSA, as a weak
3328 hash can not only allow a signature to be forged, but could leak the
3329 secret key. These same considerations about the quality of the hash
3330 algorithm apply to Elgamal signatures.
3332 If you are building an authentication system, the recipient may
3333 specify a preferred signing algorithm. However, the signer would be
3334 foolish to use a weak algorithm simply because the recipient requests
3337 Some of the encryption algorithms mentioned in this document have
3338 been analyzed less than others. For example, although CAST5 is
3339 presently considered strong, it has been analyzed less than Triple-
3340 DES. Other algorithms may have other controversies surrounding them.
3342 Some technologies mentioned here may be subject to government control
3345 14. Implementation Nits
3347 This section is a collection of comments to help an implementer,
3348 particularly with an eye to backward compatibility. Previous
3349 implementations of PGP are not OpenPGP-compliant. Often the
3350 differences are small, but small differences are frequently more
3351 vexing than large differences. Thus, this list of potential problems
3352 and gotchas for a developer who is trying to be backward-compatible.
3354 * PGP 5.x does not accept V4 signatures for anything other than
3357 * PGP 5.x does not recognize the "five-octet" lengths in new-format
3358 headers or in signature subpacket lengths.
3362 Callas, et. al. Standards Track [Page 60]
3364 RFC 2440 OpenPGP Message Format November 1998
3367 * PGP 5.0 rejects an encrypted session key if the keylength differs
3368 from the S2K symmetric algorithm. This is a bug in its validation
3371 * PGP 5.0 does not handle multiple one-pass signature headers and
3372 trailers. Signing one will compress the one-pass signed literal
3373 and prefix a V3 signature instead of doing a nested one-pass
3376 * When exporting a private key, PGP 2.x generates the header "BEGIN
3377 PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY BLOCK".
3378 All previous versions ignore the implied data type, and look
3379 directly at the packet data type.
3381 * In a clear-signed signature, PGP 5.0 will figure out the correct
3382 hash algorithm if there is no "Hash:" header, but it will reject
3383 a mismatch between the header and the actual algorithm used. The
3384 "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x
3385 rejects the "Hash:" header and assumes MD5. There are a number of
3386 enhanced variants of PGP 2.6.x that have been modified for SHA-1
3389 * PGP 5.0 can read an RSA key in V4 format, but can only recognize
3390 it with a V3 keyid, and can properly use only a V3 format RSA
3393 * Neither PGP 5.x nor PGP 6.0 recognize Elgamal Encrypt and Sign
3394 keys. They only handle Elgamal Encrypt-only keys.
3396 * There are many ways possible for two keys to have the same key
3397 material, but different fingerprints (and thus key ids). Perhaps
3398 the most interesting is an RSA key that has been "upgraded" to V4
3399 format, but since a V4 fingerprint is constructed by hashing the
3400 key creation time along with other things, two V4 keys created at
3401 different times, yet with the same key material will have
3402 different fingerprints.
3404 * If an implementation is using zlib to interoperate with PGP 2.x,
3405 then the "windowBits" parameter should be set to -13.
3418 Callas, et. al. Standards Track [Page 61]
3420 RFC 2440 OpenPGP Message Format November 1998
3423 15. Authors and Working Group Chair
3425 The working group can be contacted via the current chair:
3427 John W. Noerenberg, II
3430 San Diego, CA 92131 USA
3432 Phone: +1 619-658-3510
3433 EMail: jwn2@qualcomm.com
3436 The principal authors of this memo are:
3439 Network Associates, Inc.
3441 Santa Clara, CA 95054, USA
3443 Phone: +1 408-346-5860
3444 EMail: jon@pgp.com, jcallas@nai.com
3452 Phone: +49-3641-675642
3453 EMail: lutz@iks-jena.de
3457 Network Associates, Inc.
3459 Santa Clara, CA 95054, USA
3466 Clearwater, FL 33767, USA
3468 EMail: rodney@unitran.com
3474 Callas, et. al. Standards Track [Page 62]
3476 RFC 2440 OpenPGP Message Format November 1998
3479 This memo also draws on much previous work from a number of other
3480 authors who include: Derek Atkins, Charles Breed, Dave Del Torto,
3481 Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph
3482 Levien, Colin Plumb, Will Price, William Stallings, Mark Weaver, and
3483 Philip R. Zimmermann.
3487 [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal
3488 signatures without knowing the secret key,"
3489 Eurocrypt 96. Note that the version in the
3490 proceedings has an error. A revised version is
3491 available at the time of writing from
3492 <ftp://ftp.inf.ethz.ch/pub/publications/papers/ti/isc
3495 [BLOWFISH] Schneier, B. "Description of a New Variable-Length
3496 Key, 64-Bit Block Cipher (Blowfish)" Fast Software
3497 Encryption, Cambridge Security Workshop Proceedings
3498 (December 1993), Springer-Verlag, 1994, pp191-204
3500 <http://www.counterpane.com/bfsverlag.html>
3502 [DONNERHACKE] Donnerhacke, L., et. al, "PGP263in - an improved
3503 international version of PGP", ftp://ftp.iks-
3504 jena.de/mitarb/lutz/crypt/software/pgp/
3506 [ELGAMAL] T. ElGamal, "A Public-Key Cryptosystem and a
3507 Signature Scheme Based on Discrete Logarithms," IEEE
3508 Transactions on Information Theory, v. IT-31, n. 4,
3511 [IDEA] Lai, X, "On the design and security of block
3512 ciphers", ETH Series in Information Processing, J.L.
3513 Massey (editor), Vol. 1, Hartung-Gorre Verlag
3514 Knostanz, Technische Hochschule (Zurich), 1992
3516 [ISO-10646] ISO/IEC 10646-1:1993. International Standard --
3517 Information technology -- Universal Multiple-Octet
3518 Coded Character Set (UCS) -- Part 1: Architecture
3519 and Basic Multilingual Plane. UTF-8 is described in
3520 Annex R, adopted but not yet published. UTF-16 is
3521 described in Annex Q, adopted but not yet published.
3523 [MENEZES] Alfred Menezes, Paul van Oorschot, and Scott
3524 Vanstone, "Handbook of Applied Cryptography," CRC
3530 Callas, et. al. Standards Track [Page 63]
3532 RFC 2440 OpenPGP Message Format November 1998
3535 [RFC822] Crocker, D., "Standard for the format of ARPA
3536 Internet text messages", STD 11, RFC 822, August
3539 [RFC1423] Balenson, D., "Privacy Enhancement for Internet
3540 Electronic Mail: Part III: Algorithms, Modes, and
3541 Identifiers", RFC 1423, October 1993.
3543 [RFC1641] Goldsmith, D. and M. Davis, "Using Unicode with
3544 MIME", RFC 1641, July 1994.
3546 [RFC1750] Eastlake, D., Crocker, S. and J. Schiller,
3547 "Randomness Recommendations for Security", RFC 1750,
3550 [RFC1951] Deutsch, P., "DEFLATE Compressed Data Format
3551 Specification version 1.3.", RFC 1951, May 1996.
3553 [RFC1983] Malkin, G., "Internet Users' Glossary", FYI 18, RFC
3556 [RFC1991] Atkins, D., Stallings, W. and P. Zimmermann, "PGP
3557 Message Exchange Formats", RFC 1991, August 1996.
3559 [RFC2015] Elkins, M., "MIME Security with Pretty Good Privacy
3560 (PGP)", RFC 2015, October 1996.
3562 [RFC2231] Borenstein, N. and N. Freed, "Multipurpose Internet
3563 Mail Extensions (MIME) Part One: Format of Internet
3564 Message Bodies.", RFC 2231, November 1996.
3566 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate
3567 Requirement Level", BCP 14, RFC 2119, March 1997.
3569 [RFC2144] Adams, C., "The CAST-128 Encryption Algorithm", RFC
3572 [RFC2279] Yergeau., F., "UTF-8, a transformation format of
3573 Unicode and ISO 10646", RFC 2279, January 1998.
3575 [RFC2313] Kaliski, B., "PKCS #1: RSA Encryption Standard
3576 version 1.5", RFC 2313, March 1998.
3578 [SAFER] Massey, J.L. "SAFER K-64: One Year Later", B.
3579 Preneel, editor, Fast Software Encryption, Second
3580 International Workshop (LNCS 1008) pp212-241,
3581 Springer-Verlag 1995
3586 Callas, et. al. Standards Track [Page 64]
3588 RFC 2440 OpenPGP Message Format November 1998
3591 17. Full Copyright Statement
3593 Copyright (C) The Internet Society (1998). All Rights Reserved.
3595 This document and translations of it may be copied and furnished to
3596 others, and derivative works that comment on or otherwise explain it
3597 or assist in its implementation may be prepared, copied, published
3598 and distributed, in whole or in part, without restriction of any
3599 kind, provided that the above copyright notice and this paragraph are
3600 included on all such copies and derivative works. However, this
3601 document itself may not be modified in any way, such as by removing
3602 the copyright notice or references to the Internet Society or other
3603 Internet organizations, except as needed for the purpose of
3604 developing Internet standards in which case the procedures for
3605 copyrights defined in the Internet Standards process must be
3606 followed, or as required to translate it into languages other than
3609 The limited permissions granted above are perpetual and will not be
3610 revoked by the Internet Society or its successors or assigns.
3612 This document and the information contained herein is provided on an
3613 "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
3614 TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
3615 BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
3616 HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
3617 MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
3642 Callas, et. al. Standards Track [Page 65]