Home | History | Annotate | Line # | Download | only in ref
      1 
      2 
      3 
      4 
      5 
      6 
      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.
     11                                                               H. Finney
     12                                                      Network Associates
     13                                                               R. Thayer
     14                                                         EIS Corporation
     15                                                           November 1998
     16 
     17 
     18                          OpenPGP Message Format
     19 
     20 Status of this Memo
     21 
     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.
     27 
     28 Copyright Notice
     29 
     30    Copyright (C) The Internet Society (1998).  All Rights Reserved.
     31 
     32 IESG Note
     33 
     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.
     46 
     47 Abstract
     48 
     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,
     55 
     56 
     57 
     58 Callas, et. al.             Standards Track                     [Page 1]
     59 
     61 RFC 2440                 OpenPGP Message Format            November 1998
     62 
     63 
     64    however, discuss implementation issues necessary to avoid security
     65    flaws.
     66 
     67    Open-PGP software uses a combination of strong public-key and
     68    symmetric cryptography to provide security services for electronic
     69    communications and data storage.  These services include
     70    confidentiality, key management, authentication, and digital
     71    signatures. This document specifies the message formats used in
     72    OpenPGP.
     73 
     74 Table of Contents
     75 
     76             Status of this Memo                                       1
     77             IESG Note                                                 1
     78             Abstract                                                  1
     79             Table of Contents                                         2
     80    1.       Introduction                                              4
     81    1.1.     Terms                                                     5
     82    2.       General functions                                         5
     83    2.1.     Confidentiality via Encryption                            5
     84    2.2.     Authentication via Digital signature                      6
     85    2.3.     Compression                                               7
     86    2.4.     Conversion to Radix-64                                    7
     87    2.5.     Signature-Only Applications                               7
     88    3.       Data Element Formats                                      7
     89    3.1.     Scalar numbers                                            8
     90    3.2.     Multi-Precision Integers                                  8
     91    3.3.     Key IDs                                                   8
     92    3.4.     Text                                                      8
     93    3.5.     Time fields                                               9
     94    3.6.     String-to-key (S2K) specifiers                            9
     95    3.6.1.   String-to-key (S2k) specifier types                       9
     96    3.6.1.1. Simple S2K                                                9
     97    3.6.1.2. Salted S2K                                               10
     98    3.6.1.3. Iterated and Salted S2K                                  10
     99    3.6.2.   String-to-key usage                                      11
    100    3.6.2.1. Secret key encryption                                    11
    101    3.6.2.2. Symmetric-key message encryption                         11
    102    4.       Packet Syntax                                            12
    103    4.1.     Overview                                                 12
    104    4.2.     Packet Headers                                           12
    105    4.2.1.   Old-Format Packet Lengths                                13
    106    4.2.2.   New-Format Packet Lengths                                13
    107    4.2.2.1. One-Octet Lengths                                        14
    108    4.2.2.2. Two-Octet Lengths                                        14
    109    4.2.2.3. Five-Octet Lengths                                       14
    110    4.2.2.4. Partial Body Lengths                                     14
    111    4.2.3.   Packet Length Examples                                   14
    112 
    113 
    114 
    115 Callas, et. al.             Standards Track                     [Page 2]
    116 
    118 RFC 2440                 OpenPGP Message Format            November 1998
    119 
    120 
    121    4.3.     Packet Tags                                              15
    122    5.       Packet Types                                             16
    123    5.1.     Public-Key Encrypted Session Key Packets (Tag 1)         16
    124    5.2.     Signature Packet (Tag 2)                                 17
    125    5.2.1.   Signature Types                                          17
    126    5.2.2.   Version 3 Signature Packet Format                        19
    127    5.2.3.   Version 4 Signature Packet Format                        21
    128    5.2.3.1. Signature Subpacket Specification                        22
    129    5.2.3.2. Signature Subpacket Types                                24
    130    5.2.3.3. Signature creation time                                  25
    131    5.2.3.4. Issuer                                                   25
    132    5.2.3.5. Key expiration time                                      25
    133    5.2.3.6. Preferred symmetric algorithms                           25
    134    5.2.3.7. Preferred hash algorithms                                25
    135    5.2.3.8. Preferred compression algorithms                         26
    136    5.2.3.9. Signature expiration time                                26
    137    5.2.3.10.Exportable Certification                                 26
    138    5.2.3.11.Revocable                                                27
    139    5.2.3.12.Trust signature                                          27
    140    5.2.3.13.Regular expression                                       27
    141    5.2.3.14.Revocation key                                           27
    142    5.2.3.15.Notation Data                                            28
    143    5.2.3.16.Key server preferences                                   28
    144    5.2.3.17.Preferred key server                                     29
    145    5.2.3.18.Primary user id                                          29
    146    5.2.3.19.Policy URL                                               29
    147    5.2.3.20.Key Flags                                                29
    148    5.2.3.21.Signer's User ID                                         30
    149    5.2.3.22.Reason for Revocation                                    30
    150    5.2.4.   Computing Signatures                                     31
    151    5.2.4.1. Subpacket Hints                                          32
    152    5.3.     Symmetric-Key Encrypted Session-Key Packets (Tag 3)      32
    153    5.4.     One-Pass Signature Packets (Tag 4)                       33
    154    5.5.     Key Material Packet                                      34
    155    5.5.1.   Key Packet Variants                                      34
    156    5.5.1.1. Public Key Packet (Tag 6)                                34
    157    5.5.1.2. Public Subkey Packet (Tag 14)                            34
    158    5.5.1.3. Secret Key Packet (Tag 5)                                35
    159    5.5.1.4. Secret Subkey Packet (Tag 7)                             35
    160    5.5.2.   Public Key Packet Formats                                35
    161    5.5.3.   Secret Key Packet Formats                                37
    162    5.6.     Compressed Data Packet (Tag 8)                           38
    163    5.7.     Symmetrically Encrypted Data Packet (Tag 9)              39
    164    5.8.     Marker Packet (Obsolete Literal Packet) (Tag 10)         39
    165    5.9.     Literal Data Packet (Tag 11)                             40
    166    5.10.    Trust Packet (Tag 12)                                    40
    167    5.11.    User ID Packet (Tag 13)                                  41
    168    6.       Radix-64 Conversions                                     41
    169 
    170 
    171 
    172 Callas, et. al.             Standards Track                     [Page 3]
    173 
    175 RFC 2440                 OpenPGP Message Format            November 1998
    176 
    177 
    178    6.1.     An Implementation of the CRC-24 in "C"                   42
    179    6.2.     Forming ASCII Armor                                      42
    180    6.3.     Encoding Binary in Radix-64                              44
    181    6.4.     Decoding Radix-64                                        46
    182    6.5.     Examples of Radix-64                                     46
    183    6.6.     Example of an ASCII Armored Message                      47
    184    7.       Cleartext signature framework                            47
    185    7.1.     Dash-Escaped Text                                        47
    186    8.       Regular Expressions                                      48
    187    9.       Constants                                                49
    188    9.1.     Public Key Algorithms                                    49
    189    9.2.     Symmetric Key Algorithms                                 49
    190    9.3.     Compression Algorithms                                   50
    191    9.4.     Hash Algorithms                                          50
    192    10.      Packet Composition                                       50
    193    10.1.    Transferable Public Keys                                 50
    194    10.2.    OpenPGP Messages                                         52
    195    10.3.    Detached Signatures                                      52
    196    11.      Enhanced Key Formats                                     52
    197    11.1.    Key Structures                                           52
    198    11.2.    Key IDs and Fingerprints                                 53
    199    12.      Notes on Algorithms                                      54
    200    12.1.    Symmetric Algorithm Preferences                          54
    201    12.2.    Other Algorithm Preferences                              55
    202    12.2.1.  Compression Preferences                                  56
    203    12.2.2.  Hash Algorithm Preferences                               56
    204    12.3.    Plaintext                                                56
    205    12.4.    RSA                                                      56
    206    12.5.    Elgamal                                                  57
    207    12.6.    DSA                                                      58
    208    12.7.    Reserved Algorithm Numbers                               58
    209    12.8.    OpenPGP CFB mode                                         58
    210    13.      Security Considerations                                  59
    211    14.      Implementation Nits                                      60
    212    15.      Authors and Working Group Chair                          62
    213    16.      References                                               63
    214    17.      Full Copyright Statement                                 65
    215 
    216 1. Introduction
    217 
    218    This document provides information on the message-exchange packet
    219    formats used by OpenPGP to provide encryption, decryption, signing,
    220    and key management functions. It builds on the foundation provided in
    221    RFC 1991 "PGP Message Exchange Formats."
    222 
    223 
    224 
    225 
    226 
    227 
    228 
    229 Callas, et. al.             Standards Track                     [Page 4]
    230 
    232 RFC 2440                 OpenPGP Message Format            November 1998
    233 
    234 
    235 1.1. Terms
    236 
    237      * OpenPGP - This is a definition for security software that uses
    238        PGP 5.x as a basis.
    239 
    240      * PGP - Pretty Good Privacy. PGP is a family of software systems
    241        developed by Philip R. Zimmermann from which OpenPGP is based.
    242 
    243      * PGP 2.6.x - This version of PGP has many variants, hence the term
    244        PGP 2.6.x. It used only RSA, MD5, and IDEA for its cryptographic
    245        transforms. An informational RFC, RFC 1991, was written
    246        describing this version of PGP.
    247 
    248      * PGP 5.x - This version of PGP is formerly known as "PGP 3" in the
    249        community and also in the predecessor of this document, RFC 1991.
    250        It has new formats and corrects a number of problems in the PGP
    251        2.6.x design. It is referred to here as PGP 5.x because that
    252        software was the first release of the "PGP 3" code base.
    253 
    254    "PGP", "Pretty Good", and "Pretty Good Privacy" are trademarks of
    255    Network Associates, Inc. and are used with permission.
    256 
    257    This document uses the terms "MUST", "SHOULD", and "MAY" as defined
    258    in RFC 2119, along with the negated forms of those terms.
    259 
    260 2. General functions
    261 
    262    OpenPGP provides data integrity services for messages and data files
    263    by using these core technologies:
    264 
    265      - digital signatures
    266 
    267      - encryption
    268 
    269      - compression
    270 
    271      - radix-64 conversion
    272 
    273    In addition, OpenPGP provides key management and certificate
    274    services, but many of these are beyond the scope of this document.
    275 
    276 2.1. Confidentiality via Encryption
    277 
    278    OpenPGP uses two encryption methods to provide confidentiality:
    279    symmetric-key encryption and public key encryption. With public-key
    280    encryption, the object is encrypted using a symmetric encryption
    281    algorithm.  Each symmetric key is used only once. A new "session key"
    282    is generated as a random number for each message. Since it is used
    283 
    284 
    285 
    286 Callas, et. al.             Standards Track                     [Page 5]
    287 
    289 RFC 2440                 OpenPGP Message Format            November 1998
    290 
    291 
    292    only once, the session key is bound to the message and transmitted
    293    with it.  To protect the key, it is encrypted with the receiver's
    294    public key. The sequence is as follows:
    295 
    296    1.  The sender creates a message.
    297 
    298    2.  The sending OpenPGP generates a random number to be used as a
    299        session key for this message only.
    300 
    301    3.  The session key is encrypted using each recipient's public key.
    302        These "encrypted session keys" start the message.
    303 
    304    4.  The sending OpenPGP encrypts the message using the session key,
    305        which forms the remainder of the message. Note that the message
    306        is also usually compressed.
    307 
    308    5.  The receiving OpenPGP decrypts the session key using the
    309        recipient's private key.
    310 
    311    6.  The receiving OpenPGP decrypts the message using the session key.
    312        If the message was compressed, it will be decompressed.
    313 
    314    With symmetric-key encryption, an object may be encrypted with a
    315    symmetric key derived from a passphrase (or other shared secret), or
    316    a two-stage mechanism similar to the public-key method described
    317    above in which a session key is itself encrypted with a symmetric
    318    algorithm keyed from a shared secret.
    319 
    320    Both digital signature and confidentiality services may be applied to
    321    the same message. First, a signature is generated for the message and
    322    attached to the message. Then, the message plus signature is
    323    encrypted using a symmetric session key. Finally, the session key is
    324    encrypted using public-key encryption and prefixed to the encrypted
    325    block.
    326 
    327 2.2. Authentication via Digital signature
    328 
    329    The digital signature uses a hash code or message digest algorithm,
    330    and a public-key signature algorithm. The sequence is as follows:
    331 
    332    1.  The sender creates a message.
    333 
    334    2.  The sending software generates a hash code of the message.
    335 
    336    3.  The sending software generates a signature from the hash code
    337        using the sender's private key.
    338 
    339    4.  The binary signature is attached to the message.
    340 
    341 
    342 
    343 Callas, et. al.             Standards Track                     [Page 6]
    344 
    346 RFC 2440                 OpenPGP Message Format            November 1998
    347 
    348 
    349    5.  The receiving software keeps a copy of the message signature.
    350 
    351    6.  The receiving software generates a new hash code for the
    352        received message and verifies it using the message's signature.
    353        If the verification is successful, the message is accepted as
    354        authentic.
    355 
    356 2.3. Compression
    357 
    358    OpenPGP implementations MAY compress the message after applying the
    359    signature but before encryption.
    360 
    361 2.4. Conversion to Radix-64
    362 
    363    OpenPGP's underlying native representation for encrypted messages,
    364    signature certificates, and keys is a stream of arbitrary octets.
    365    Some systems only permit the use of blocks consisting of seven-bit,
    366    printable text. For transporting OpenPGP's native raw binary octets
    367    through channels that are not safe to raw binary data, a printable
    368    encoding of these binary octets is needed.  OpenPGP provides the
    369    service of converting the raw 8-bit binary octet stream to a stream
    370    of printable ASCII characters, called Radix-64 encoding or ASCII
    371    Armor.
    372 
    373    Implementations SHOULD provide Radix-64 conversions.
    374 
    375    Note that many applications, particularly messaging applications,
    376    will want more advanced features as described in the OpenPGP-MIME
    377    document, RFC 2015. An application that implements OpenPGP for
    378    messaging SHOULD implement OpenPGP-MIME.
    379 
    380 2.5. Signature-Only Applications
    381 
    382    OpenPGP is designed for applications that use both encryption and
    383    signatures, but there are a number of problems that are solved by a
    384    signature-only implementation. Although this specification requires
    385    both encryption and signatures, it is reasonable for there to be
    386    subset implementations that are non-comformant only in that they omit
    387    encryption.
    388 
    389 3. Data Element Formats
    390 
    391    This section describes the data elements used by OpenPGP.
    392 
    393 
    394 
    395 
    396 
    397 
    398 
    399 
    400 Callas, et. al.             Standards Track                     [Page 7]
    401 
    403 RFC 2440                 OpenPGP Message Format            November 1998
    404 
    405 
    406 3.1. Scalar numbers
    407 
    408    Scalar numbers are unsigned, and are always stored in big-endian
    409    format. Using n[k] to refer to the kth octet being interpreted, the
    410    value of a two-octet scalar is ((n[0] << 8) + n[1]). The value of a
    411    four-octet scalar is ((n[0] << 24) + (n[1] << 16) + (n[2] << 8) +
    412    n[3]).
    413 
    414 3.2. Multi-Precision Integers
    415 
    416    Multi-Precision Integers (also called MPIs) are unsigned integers
    417    used to hold large integers such as the ones used in cryptographic
    418    calculations.
    419 
    420    An MPI consists of two pieces: a two-octet scalar that is the length
    421    of the MPI in bits followed by a string of octets that contain the
    422    actual integer.
    423 
    424    These octets form a big-endian number; a big-endian number can be
    425    made into an MPI by prefixing it with the appropriate length.
    426 
    427    Examples:
    428 
    429    (all numbers are in hexadecimal)
    430 
    431    The string of octets [00 01 01] forms an MPI with the value 1. The
    432    string [00 09 01 FF] forms an MPI with the value of 511.
    433 
    434    Additional rules:
    435 
    436    The size of an MPI is ((MPI.length + 7) / 8) + 2 octets.
    437 
    438    The length field of an MPI describes the length starting from its
    439    most significant non-zero bit. Thus, the MPI [00 02 01] is not formed
    440    correctly. It should be [00 01 01].
    441 
    442 3.3. Key IDs
    443 
    444    A Key ID is an eight-octet scalar that identifies a key.
    445    Implementations SHOULD NOT assume that Key IDs are unique. The
    446    section, "Enhanced Key Formats" below describes how Key IDs are
    447    formed.
    448 
    449 3.4. Text
    450 
    451    The default character set for text is the UTF-8 [RFC2279] encoding of
    452    Unicode [ISO10646].
    453 
    454 
    455 
    456 
    457 Callas, et. al.             Standards Track                     [Page 8]
    458 
    460 RFC 2440                 OpenPGP Message Format            November 1998
    461 
    462 
    463 3.5. Time fields
    464 
    465    A time field is an unsigned four-octet number containing the number
    466    of seconds elapsed since midnight, 1 January 1970 UTC.
    467 
    468 3.6. String-to-key (S2K) specifiers
    469 
    470    String-to-key (S2K) specifiers are used to convert passphrase strings
    471    into symmetric-key encryption/decryption keys.  They are used in two
    472    places, currently: to encrypt the secret part of private keys in the
    473    private keyring, and to convert passphrases to encryption keys for
    474    symmetrically encrypted messages.
    475 
    476 3.6.1. String-to-key (S2k) specifier types
    477 
    478    There are three types of S2K specifiers currently supported, as
    479    follows:
    480 
    481 3.6.1.1. Simple S2K
    482 
    483    This directly hashes the string to produce the key data.  See below
    484    for how this hashing is done.
    485 
    486        Octet 0:        0x00
    487        Octet 1:        hash algorithm
    488 
    489    Simple S2K hashes the passphrase to produce the session key.  The
    490    manner in which this is done depends on the size of the session key
    491    (which will depend on the cipher used) and the size of the hash
    492    algorithm's output. If the hash size is greater than or equal to the
    493    session key size, the high-order (leftmost) octets of the hash are
    494    used as the key.
    495 
    496    If the hash size is less than the key size, multiple instances of the
    497    hash context are created -- enough to produce the required key data.
    498    These instances are preloaded with 0, 1, 2, ... octets of zeros (that
    499    is to say, the first instance has no preloading, the second gets
    500    preloaded with 1 octet of zero, the third is preloaded with two
    501    octets of zeros, and so forth).
    502 
    503    As the data is hashed, it is given independently to each hash
    504    context. Since the contexts have been initialized differently, they
    505    will each produce different hash output.  Once the passphrase is
    506    hashed, the output data from the multiple hashes is concatenated,
    507    first hash leftmost, to produce the key data, with any excess octets
    508    on the right discarded.
    509 
    510 
    511 
    512 
    513 
    514 Callas, et. al.             Standards Track                     [Page 9]
    515 
    517 RFC 2440                 OpenPGP Message Format            November 1998
    518 
    519 
    520 3.6.1.2. Salted S2K
    521 
    522    This includes a "salt" value in the S2K specifier -- some arbitrary
    523    data -- that gets hashed along with the passphrase string, to help
    524    prevent dictionary attacks.
    525 
    526        Octet 0:        0x01
    527        Octet 1:        hash algorithm
    528        Octets 2-9:     8-octet salt value
    529 
    530    Salted S2K is exactly like Simple S2K, except that the input to the
    531    hash function(s) consists of the 8 octets of salt from the S2K
    532    specifier, followed by the passphrase.
    533 
    534 3.6.1.3. Iterated and Salted S2K
    535 
    536    This includes both a salt and an octet count.  The salt is combined
    537    with the passphrase and the resulting value is hashed repeatedly.
    538    This further increases the amount of work an attacker must do to try
    539    dictionary attacks.
    540 
    541        Octet  0:        0x03
    542        Octet  1:        hash algorithm
    543        Octets 2-9:      8-octet salt value
    544        Octet  10:       count, a one-octet, coded value
    545 
    546    The count is coded into a one-octet number using the following
    547    formula:
    548 
    549        #define EXPBIAS 6
    550            count = ((Int32)16 + (c & 15)) << ((c >> 4) + EXPBIAS);
    551 
    552    The above formula is in C, where "Int32" is a type for a 32-bit
    553    integer, and the variable "c" is the coded count, Octet 10.
    554 
    555    Iterated-Salted S2K hashes the passphrase and salt data multiple
    556    times. The total number of octets to be hashed is specified in the
    557    encoded count in the S2K specifier.  Note that the resulting count
    558    value is an octet count of how many octets will be hashed, not an
    559    iteration count.
    560 
    561    Initially, one or more hash contexts are set up as with the other S2K
    562    algorithms, depending on how many octets of key data are needed.
    563    Then the salt, followed by the passphrase data is repeatedly hashed
    564    until the number of octets specified by the octet count has been
    565    hashed.  The one exception is that if the octet count is less than
    566    the size of the salt plus passphrase, the full salt plus passphrase
    567    will be hashed even though that is greater than the octet count.
    568 
    569 
    570 
    571 Callas, et. al.             Standards Track                    [Page 10]
    572 
    574 RFC 2440                 OpenPGP Message Format            November 1998
    575 
    576 
    577    After the hashing is done the data is unloaded from the hash
    578    context(s) as with the other S2K algorithms.
    579 
    580 3.6.2. String-to-key usage
    581 
    582    Implementations SHOULD use salted or iterated-and-salted S2K
    583    specifiers, as simple S2K specifiers are more vulnerable to
    584    dictionary attacks.
    585 
    586 3.6.2.1. Secret key encryption
    587 
    588    An S2K specifier can be stored in the secret keyring to specify how
    589    to convert the passphrase to a key that unlocks the secret data.
    590    Older versions of PGP just stored a cipher algorithm octet preceding
    591    the secret data or a zero to indicate that the secret data was
    592    unencrypted. The MD5 hash function was always used to convert the
    593    passphrase to a key for the specified cipher algorithm.
    594 
    595    For compatibility, when an S2K specifier is used, the special value
    596    255 is stored in the position where the hash algorithm octet would
    597    have been in the old data structure.  This is then followed
    598    immediately by a one-octet algorithm identifier, and then by the S2K
    599    specifier as encoded above.
    600 
    601    Therefore, preceding the secret data there will be one of these
    602    possibilities:
    603 
    604        0:           secret data is unencrypted (no pass phrase)
    605        255:         followed by algorithm octet and S2K specifier
    606        Cipher alg:  use Simple S2K algorithm using MD5 hash
    607 
    608    This last possibility, the cipher algorithm number with an implicit
    609    use of MD5 and IDEA, is provided for backward compatibility; it MAY
    610    be understood, but SHOULD NOT be generated, and is deprecated.
    611 
    612    These are followed by an 8-octet Initial Vector for the decryption of
    613    the secret values, if they are encrypted, and then the secret key
    614    values themselves.
    615 
    616 3.6.2.2. Symmetric-key message encryption
    617 
    618    OpenPGP can create a Symmetric-key Encrypted Session Key (ESK) packet
    619    at the front of a message.  This is used to allow S2K specifiers to
    620    be used for the passphrase conversion or to create messages with a
    621    mix of symmetric-key ESKs and public-key ESKs. This allows a message
    622    to be decrypted either with a passphrase or a public key.
    623 
    624 
    625 
    626 
    627 
    628 Callas, et. al.             Standards Track                    [Page 11]
    629 
    631 RFC 2440                 OpenPGP Message Format            November 1998
    632 
    633 
    634    PGP 2.X always used IDEA with Simple string-to-key conversion when
    635    encrypting a message with a symmetric algorithm. This is deprecated,
    636    but MAY be used for backward-compatibility.
    637 
    638 4. Packet Syntax
    639 
    640    This section describes the packets used by OpenPGP.
    641 
    642 4.1. Overview
    643 
    644    An OpenPGP message is constructed from a number of records that are
    645    traditionally called packets. A packet is a chunk of data that has a
    646    tag specifying its meaning. An OpenPGP message, keyring, certificate,
    647    and so forth consists of a number of packets. Some of those packets
    648    may contain other OpenPGP packets (for example, a compressed data
    649    packet, when uncompressed, contains OpenPGP packets).
    650 
    651    Each packet consists of a packet header, followed by the packet body.
    652    The packet header is of variable length.
    653 
    654 4.2. Packet Headers
    655 
    656    The first octet of the packet header is called the "Packet Tag." It
    657    determines the format of the header and denotes the packet contents.
    658    The remainder of the packet header is the length of the packet.
    659 
    660    Note that the most significant bit is the left-most bit, called bit
    661    7. A mask for this bit is 0x80 in hexadecimal.
    662 
    663               +---------------+
    664          PTag |7 6 5 4 3 2 1 0|
    665               +---------------+
    666          Bit 7 -- Always one
    667          Bit 6 -- New packet format if set
    668 
    669    PGP 2.6.x only uses old format packets. Thus, software that
    670    interoperates with those versions of PGP must only use old format
    671    packets. If interoperability is not an issue, either format may be
    672    used. Note that old format packets have four bits of content tags,
    673    and new format packets have six; some features cannot be used and
    674    still be backward-compatible.
    675 
    676    Old format packets contain:
    677 
    678          Bits 5-2 -- content tag
    679          Bits 1-0 - length-type
    680 
    681 
    682 
    683 
    684 
    685 Callas, et. al.             Standards Track                    [Page 12]
    686 
    688 RFC 2440                 OpenPGP Message Format            November 1998
    689 
    690 
    691    New format packets contain:
    692 
    693          Bits 5-0 -- content tag
    694 
    695 4.2.1. Old-Format Packet Lengths
    696 
    697    The meaning of the length-type in old-format packets is:
    698 
    699    0 - The packet has a one-octet length. The header is 2 octets long.
    700 
    701    1 - The packet has a two-octet length. The header is 3 octets long.
    702 
    703    2 - The packet has a four-octet length. The header is 5 octets long.
    704 
    705    3 - The packet is of indeterminate length.  The header is 1 octet
    706        long, and the implementation must determine how long the packet
    707        is. If the packet is in a file, this means that the packet
    708        extends until the end of the file. In general, an implementation
    709        SHOULD NOT use indeterminate length packets except where the end
    710        of the data will be clear from the context, and even then it is
    711        better to use a definite length, or a new-format header. The
    712        new-format headers described below have a mechanism for precisely
    713        encoding data of indeterminate length.
    714 
    715 4.2.2. New-Format Packet Lengths
    716 
    717    New format packets have four possible ways of encoding length:
    718 
    719     1. A one-octet Body Length header encodes packet lengths of up to
    720        191 octets.
    721 
    722    2. A two-octet Body Length header encodes packet lengths of 192 to
    723        8383 octets.
    724 
    725     3. A five-octet Body Length header encodes packet lengths of up to
    726        4,294,967,295 (0xFFFFFFFF) octets in length. (This actually
    727        encodes a four-octet scalar number.)
    728 
    729     4. When the length of the packet body is not known in advance by the
    730        issuer, Partial Body Length headers encode a packet of
    731        indeterminate length, effectively making it a stream.
    732 
    733 
    734 
    735 
    736 
    737 
    738 
    739 
    740 
    741 
    742 Callas, et. al.             Standards Track                    [Page 13]
    743 
    745 RFC 2440                 OpenPGP Message Format            November 1998
    746 
    747 
    748 4.2.2.1. One-Octet Lengths
    749 
    750    A one-octet Body Length header encodes a length of from 0 to 191
    751    octets. This type of length header is recognized because the one
    752    octet value is less than 192.  The body length is equal to:
    753 
    754        bodyLen = 1st_octet;
    755 
    756 4.2.2.2. Two-Octet Lengths
    757 
    758    A two-octet Body Length header encodes a length of from 192 to 8383
    759    octets.  It is recognized because its first octet is in the range 192
    760    to 223.  The body length is equal to:
    761 
    762        bodyLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
    763 
    764 4.2.2.3. Five-Octet Lengths
    765 
    766    A five-octet Body Length header consists of a single octet holding
    767    the value 255, followed by a four-octet scalar. The body length is
    768    equal to:
    769 
    770        bodyLen = (2nd_octet << 24) | (3rd_octet << 16) |
    771                  (4th_octet << 8)  | 5th_octet
    772 
    773 4.2.2.4. Partial Body Lengths
    774 
    775    A Partial Body Length header is one octet long and encodes the length
    776    of only part of the data packet. This length is a power of 2, from 1
    777    to 1,073,741,824 (2 to the 30th power).  It is recognized by its one
    778    octet value that is greater than or equal to 224, and less than 255.
    779    The partial body length is equal to:
    780 
    781        partialBodyLen = 1 << (1st_octet & 0x1f);
    782 
    783    Each Partial Body Length header is followed by a portion of the
    784    packet body data. The Partial Body Length header specifies this
    785    portion's length. Another length header (of one of the three types --
    786    one octet, two-octet, or partial) follows that portion. The last
    787    length header in the packet MUST NOT be a partial Body Length header.
    788    Partial Body Length headers may only be used for the non-final parts
    789    of the packet.
    790 
    791 4.2.3. Packet Length Examples
    792 
    793    These examples show ways that new-format packets might encode the
    794    packet lengths.
    795 
    796 
    797 
    798 
    799 Callas, et. al.             Standards Track                    [Page 14]
    800 
    802 RFC 2440                 OpenPGP Message Format            November 1998
    803 
    804 
    805    A packet with length 100 may have its length encoded in one octet:
    806    0x64. This is followed by 100 octets of data.
    807 
    808    A packet with length 1723 may have its length coded in two octets:
    809    0xC5, 0xFB.  This header is followed by the 1723 octets of data.
    810 
    811    A packet with length 100000 may have its length encoded in five
    812    octets: 0xFF, 0x00, 0x01, 0x86, 0xA0.
    813 
    814    It might also be encoded in the following octet stream: 0xEF, first
    815    32768 octets of data; 0xE1, next two octets of data; 0xE0, next one
    816    octet of data; 0xF0, next 65536 octets of data; 0xC5, 0xDD, last 1693
    817    octets of data.  This is just one possible encoding, and many
    818    variations are possible on the size of the Partial Body Length
    819    headers, as long as a regular Body Length header encodes the last
    820    portion of the data. Note also that the last Body Length header can
    821    be a zero-length header.
    822 
    823    An implementation MAY use Partial Body Lengths for data packets, be
    824    they literal, compressed, or encrypted. The first partial length MUST
    825    be at least 512 octets long. Partial Body Lengths MUST NOT be used
    826    for any other packet types.
    827 
    828    Please note that in all of these explanations, the total length of
    829    the packet is the length of the header(s) plus the length of the
    830    body.
    831 
    832 4.3. Packet Tags
    833 
    834    The packet tag denotes what type of packet the body holds. Note that
    835    old format headers can only have tags less than 16, whereas new
    836    format headers can have tags as great as 63. The defined tags (in
    837    decimal) are:
    838 
    839        0        -- Reserved - a packet tag must not have this value
    840        1        -- Public-Key Encrypted Session Key Packet
    841        2        -- Signature Packet
    842        3        -- Symmetric-Key Encrypted Session Key Packet
    843        4        -- One-Pass Signature Packet
    844        5        -- Secret Key Packet
    845        6        -- Public Key Packet
    846        7        -- Secret Subkey Packet
    847        8        -- Compressed Data Packet
    848        9        -- Symmetrically Encrypted Data Packet
    849        10       -- Marker Packet
    850        11       -- Literal Data Packet
    851        12       -- Trust Packet
    852 
    853 
    854 
    855 
    856 Callas, et. al.             Standards Track                    [Page 15]
    857 
    859 RFC 2440                 OpenPGP Message Format            November 1998
    860 
    861 
    862        13       -- User ID Packet
    863        14       -- Public Subkey Packet
    864        60 to 63 -- Private or Experimental Values
    865 
    866 5. Packet Types
    867 
    868 5.1. Public-Key Encrypted Session Key Packets (Tag 1)
    869 
    870    A Public-Key Encrypted Session Key packet holds the session key used
    871    to encrypt a message. Zero or more Encrypted Session Key packets
    872    (either Public-Key or Symmetric-Key) may precede a Symmetrically
    873    Encrypted Data Packet, which holds an encrypted message.  The message
    874    is encrypted with the session key, and the session key is itself
    875    encrypted and stored in the Encrypted Session Key packet(s).  The
    876    Symmetrically Encrypted Data Packet is preceded by one Public-Key
    877    Encrypted Session Key packet for each OpenPGP key to which the
    878    message is encrypted.  The recipient of the message finds a session
    879    key that is encrypted to their public key, decrypts the session key,
    880    and then uses the session key to decrypt the message.
    881 
    882    The body of this packet consists of:
    883 
    884      - A one-octet number giving the version number of the packet type.
    885        The currently defined value for packet version is 3. An
    886        implementation should accept, but not generate a version of 2,
    887        which is equivalent to V3 in all other respects.
    888 
    889      - An eight-octet number that gives the key ID of the public key
    890        that the session key is encrypted to.
    891 
    892      - A one-octet number giving the public key algorithm used.
    893 
    894      - A string of octets that is the encrypted session key. This string
    895        takes up the remainder of the packet, and its contents are
    896        dependent on the public key algorithm used.
    897 
    898    Algorithm Specific Fields for RSA encryption
    899 
    900      - multiprecision integer (MPI) of RSA encrypted value m**e mod n.
    901 
    902    Algorithm Specific Fields for Elgamal encryption:
    903 
    904      - MPI of Elgamal (Diffie-Hellman) value g**k mod p.
    905 
    906      - MPI of Elgamal (Diffie-Hellman) value m * y**k mod p.
    907 
    908 
    909 
    910 
    911 
    912 
    913 Callas, et. al.             Standards Track                    [Page 16]
    914 
    916 RFC 2440                 OpenPGP Message Format            November 1998
    917 
    918 
    919    The value "m" in the above formulas is derived from the session key
    920    as follows.  First the session key is prefixed with a one-octet
    921    algorithm identifier that specifies the symmetric encryption
    922    algorithm used to encrypt the following Symmetrically Encrypted Data
    923    Packet.  Then a two-octet checksum is appended which is equal to the
    924    sum of the preceding session key octets, not including the algorithm
    925    identifier, modulo 65536.  This value is then padded as described in
    926    PKCS-1 block type 02 [RFC2313] to form the "m" value used in the
    927    formulas above.
    928 
    929    Note that when an implementation forms several PKESKs with one
    930    session key, forming a message that can be decrypted by several keys,
    931    the implementation MUST make new PKCS-1 padding for each key.
    932 
    933    An implementation MAY accept or use a Key ID of zero as a "wild card"
    934    or "speculative" Key ID. In this case, the receiving implementation
    935    would try all available private keys, checking for a valid decrypted
    936    session key. This format helps reduce traffic analysis of messages.
    937 
    938 5.2. Signature Packet (Tag 2)
    939 
    940    A signature packet describes a binding between some public key and
    941    some data. The most common signatures are a signature of a file or a
    942    block of text, and a signature that is a certification of a user ID.
    943 
    944    Two versions of signature packets are defined.  Version 3 provides
    945    basic signature information, while version 4 provides an expandable
    946    format with subpackets that can specify more information about the
    947    signature. PGP 2.6.x only accepts version 3 signatures.
    948 
    949    Implementations MUST accept V3 signatures. Implementations SHOULD
    950    generate V4 signatures.  Implementations MAY generate a V3 signature
    951    that can be verified by PGP 2.6.x.
    952 
    953    Note that if an implementation is creating an encrypted and signed
    954    message that is encrypted to a V3 key, it is reasonable to create a
    955    V3 signature.
    956 
    957 5.2.1. Signature Types
    958 
    959    There are a number of possible meanings for a signature, which are
    960    specified in a signature type octet in any given signature. These
    961    meanings are:
    962 
    963    0x00: Signature of a binary document.
    964          Typically, this means the signer owns it, created it, or
    965          certifies that it has not been modified.
    966 
    967 
    968 
    969 
    970 Callas, et. al.             Standards Track                    [Page 17]
    971 
    973 RFC 2440                 OpenPGP Message Format            November 1998
    974 
    975 
    976    0x01: Signature of a canonical text document.
    977          Typically, this means the signer owns it, created it, or
    978          certifies that it has not been modified.  The signature is
    979          calculated over the text data with its line endings converted
    980          to <CR><LF> and trailing blanks removed.
    981 
    982    0x02: Standalone signature.
    983          This signature is a signature of only its own subpacket
    984          contents. It is calculated identically to a signature over a
    985          zero-length binary document. Note that it doesn't make sense to
    986          have a V3 standalone signature.
    987 
    988    0x10: Generic certification of a User ID and Public Key packet.
    989          The issuer of this certification does not make any particular
    990          assertion as to how well the certifier has checked that the
    991          owner of the key is in fact the person described by the user
    992          ID.  Note that all PGP "key signatures" are this type of
    993          certification.
    994 
    995    0x11: Persona certification of a User ID and Public Key packet.
    996          The issuer of this certification has not done any verification
    997          of the claim that the owner of this key is the user ID
    998          specified.
    999 
   1000    0x12: Casual certification of a User ID and Public Key packet.
   1001          The issuer of this certification has done some casual
   1002          verification of the claim of identity.
   1003 
   1004    0x13: Positive certification of a User ID and Public Key packet.
   1005          The issuer of this certification has done substantial
   1006          verification of the claim of identity.
   1007 
   1008          Please note that the vagueness of these certification claims is
   1009          not a flaw, but a feature of the system. Because PGP places
   1010          final authority for validity upon the receiver of a
   1011          certification, it may be that one authority's casual
   1012          certification might be more rigorous than some other
   1013          authority's positive certification. These classifications allow
   1014          a certification authority to issue fine-grained claims.
   1015 
   1016    0x18: Subkey Binding Signature
   1017          This signature is a statement by the top-level signing key
   1018          indicates that it owns the subkey. This signature is calculated
   1019          directly on the subkey itself, not on any User ID or other
   1020          packets.
   1021 
   1022 
   1023 
   1024 
   1025 
   1026 
   1027 Callas, et. al.             Standards Track                    [Page 18]
   1028 
   1030 RFC 2440                 OpenPGP Message Format            November 1998
   1031 
   1032 
   1033    0x1F: Signature directly on a key
   1034          This signature is calculated directly on a key.  It binds the
   1035          information in the signature subpackets to the key, and is
   1036          appropriate to be used for subpackets that provide information
   1037          about the key, such as the revocation key subpacket. It is also
   1038          appropriate for statements that non-self certifiers want to
   1039          make about the key itself, rather than the binding between a
   1040          key and a name.
   1041 
   1042    0x20: Key revocation signature
   1043          The signature is calculated directly on the key being revoked.
   1044          A revoked key is not to be used.  Only revocation signatures by
   1045          the key being revoked, or by an authorized revocation key,
   1046          should be considered valid revocation signatures.
   1047 
   1048    0x28: Subkey revocation signature
   1049          The signature is calculated directly on the subkey being
   1050          revoked.  A revoked subkey is not to be used.  Only revocation
   1051          signatures by the top-level signature key that is bound to this
   1052          subkey, or by an authorized revocation key, should be
   1053          considered valid revocation signatures.
   1054 
   1055    0x30: Certification revocation signature
   1056          This signature revokes an earlier user ID certification
   1057          signature (signature class 0x10 through 0x13). It should be
   1058          issued by the same key that issued the revoked signature or an
   1059          authorized revocation key The signature should have a later
   1060          creation date than the signature it revokes.
   1061 
   1062    0x40: Timestamp signature.
   1063          This signature is only meaningful for the timestamp contained
   1064          in it.
   1065 
   1066 5.2.2. Version 3 Signature Packet Format
   1067 
   1068    The body of a version 3 Signature Packet contains:
   1069 
   1070      - One-octet version number (3).
   1071 
   1072      - One-octet length of following hashed material.  MUST be 5.
   1073 
   1074          - One-octet signature type.
   1075 
   1076          - Four-octet creation time.
   1077 
   1078      - Eight-octet key ID of signer.
   1079 
   1080      - One-octet public key algorithm.
   1081 
   1082 
   1083 
   1084 Callas, et. al.             Standards Track                    [Page 19]
   1085 
   1087 RFC 2440                 OpenPGP Message Format            November 1998
   1088 
   1089 
   1090      - One-octet hash algorithm.
   1091 
   1092      - Two-octet field holding left 16 bits of signed hash value.
   1093 
   1094      - One or more multi-precision integers comprising the signature.
   1095        This portion is algorithm specific, as described below.
   1096 
   1097    The data being signed is hashed, and then the signature type and
   1098    creation time from the signature packet are hashed (5 additional
   1099    octets).  The resulting hash value is used in the signature
   1100    algorithm. The high 16 bits (first two octets) of the hash are
   1101    included in the signature packet to provide a quick test to reject
   1102    some invalid signatures.
   1103 
   1104    Algorithm Specific Fields for RSA signatures:
   1105 
   1106      - multiprecision integer (MPI) of RSA signature value m**d.
   1107 
   1108    Algorithm Specific Fields for DSA signatures:
   1109 
   1110      - MPI of DSA value r.
   1111 
   1112      - MPI of DSA value s.
   1113 
   1114    The signature calculation is based on a hash of the signed data, as
   1115    described above.  The details of the calculation are different for
   1116    DSA signature than for RSA signatures.
   1117 
   1118    With RSA signatures, the hash value is encoded as described in PKCS-1
   1119    section 10.1.2, "Data encoding", producing an ASN.1 value of type
   1120    DigestInfo, and then padded using PKCS-1 block type 01 [RFC2313].
   1121    This requires inserting the hash value as an octet string into an
   1122    ASN.1 structure. The object identifier for the type of hash being
   1123    used is included in the structure.  The hexadecimal representations
   1124    for the currently defined hash algorithms are:
   1125 
   1126      - MD2:        0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02
   1127 
   1128      - MD5:        0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05
   1129 
   1130      - RIPEMD-160: 0x2B, 0x24, 0x03, 0x02, 0x01
   1131 
   1132      - SHA-1:      0x2B, 0x0E, 0x03, 0x02, 0x1A
   1133 
   1134 
   1135 
   1136 
   1137 
   1138 
   1139 
   1140 
   1141 Callas, et. al.             Standards Track                    [Page 20]
   1142 
   1144 RFC 2440                 OpenPGP Message Format            November 1998
   1145 
   1146 
   1147    The ASN.1 OIDs are:
   1148 
   1149      - MD2:        1.2.840.113549.2.2
   1150 
   1151      - MD5:        1.2.840.113549.2.5
   1152 
   1153      - RIPEMD-160: 1.3.36.3.2.1
   1154 
   1155      - SHA-1:      1.3.14.3.2.26
   1156 
   1157    The full hash prefixes for these are:
   1158 
   1159        MD2:        0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86,
   1160                    0x48, 0x86, 0xF7, 0x0D, 0x02, 0x02, 0x05, 0x00,
   1161                    0x04, 0x10
   1162 
   1163        MD5:        0x30, 0x20, 0x30, 0x0C, 0x06, 0x08, 0x2A, 0x86,
   1164                    0x48, 0x86, 0xF7, 0x0D, 0x02, 0x05, 0x05, 0x00,
   1165                    0x04, 0x10
   1166 
   1167        RIPEMD-160: 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2B, 0x24,
   1168                    0x03, 0x02, 0x01, 0x05, 0x00, 0x04, 0x14
   1169 
   1170        SHA-1:      0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0E,
   1171                    0x03, 0x02, 0x1A, 0x05, 0x00, 0x04, 0x14
   1172 
   1173    DSA signatures MUST use hashes with a size of 160 bits, to match q,
   1174    the size of the group generated by the DSA key's generator value.
   1175    The hash function result is treated as a 160 bit number and used
   1176    directly in the DSA signature algorithm.
   1177 
   1178 5.2.3. Version 4 Signature Packet Format
   1179 
   1180    The body of a version 4 Signature Packet contains:
   1181 
   1182      - One-octet version number (4).
   1183 
   1184      - One-octet signature type.
   1185 
   1186      - One-octet public key algorithm.
   1187 
   1188      - One-octet hash algorithm.
   1189 
   1190      - Two-octet scalar octet count for following hashed subpacket
   1191        data. Note that this is the length in octets of all of the hashed
   1192        subpackets; a pointer incremented by this number will skip over
   1193        the hashed subpackets.
   1194 
   1195 
   1196 
   1197 
   1198 Callas, et. al.             Standards Track                    [Page 21]
   1199 
   1201 RFC 2440                 OpenPGP Message Format            November 1998
   1202 
   1203 
   1204      - Hashed subpacket data. (zero or more subpackets)
   1205 
   1206      - Two-octet scalar octet count for following unhashed subpacket
   1207        data. Note that this is the length in octets of all of the
   1208        unhashed subpackets; a pointer incremented by this number will
   1209        skip over the unhashed subpackets.
   1210 
   1211      - Unhashed subpacket data. (zero or more subpackets)
   1212 
   1213      - Two-octet field holding left 16 bits of signed hash value.
   1214 
   1215      - One or more multi-precision integers comprising the signature.
   1216        This portion is algorithm specific, as described above.
   1217 
   1218    The data being signed is hashed, and then the signature data from the
   1219    version number through the hashed subpacket data (inclusive) is
   1220    hashed. The resulting hash value is what is signed.  The left 16 bits
   1221    of the hash are included in the signature packet to provide a quick
   1222    test to reject some invalid signatures.
   1223 
   1224    There are two fields consisting of signature subpackets.  The first
   1225    field is hashed with the rest of the signature data, while the second
   1226    is unhashed.  The second set of subpackets is not cryptographically
   1227    protected by the signature and should include only advisory
   1228    information.
   1229 
   1230    The algorithms for converting the hash function result to a signature
   1231    are described in a section below.
   1232 
   1233 5.2.3.1. Signature Subpacket Specification
   1234 
   1235    The subpacket fields consist of zero or more signature subpackets.
   1236    Each set of subpackets is preceded by a two-octet scalar count of the
   1237    length of the set of subpackets.
   1238 
   1239    Each subpacket consists of a subpacket header and a body.  The header
   1240    consists of:
   1241 
   1242      - the subpacket length (1,  2, or 5 octets)
   1243 
   1244      - the subpacket type (1 octet)
   1245 
   1246    and is followed by the subpacket specific data.
   1247 
   1248    The length includes the type octet but not this length. Its format is
   1249    similar to the "new" format packet header lengths, but cannot have
   1250    partial body lengths. That is:
   1251 
   1252 
   1253 
   1254 
   1255 Callas, et. al.             Standards Track                    [Page 22]
   1256 
   1258 RFC 2440                 OpenPGP Message Format            November 1998
   1259 
   1260 
   1261        if the 1st octet <  192, then
   1262            lengthOfLength = 1
   1263            subpacketLen = 1st_octet
   1264 
   1265        if the 1st octet >= 192 and < 255, then
   1266            lengthOfLength = 2
   1267            subpacketLen = ((1st_octet - 192) << 8) + (2nd_octet) + 192
   1268 
   1269        if the 1st octet = 255, then
   1270            lengthOfLength = 5
   1271            subpacket length = [four-octet scalar starting at 2nd_octet]
   1272 
   1273    The value of the subpacket type octet may be:
   1274 
   1275        2 = signature creation time
   1276        3 = signature expiration time
   1277        4 = exportable certification
   1278        5 = trust signature
   1279        6 = regular expression
   1280        7 = revocable
   1281        9 = key expiration time
   1282        10 = placeholder for backward compatibility
   1283        11 = preferred symmetric algorithms
   1284        12 = revocation key
   1285        16 = issuer key ID
   1286        20 = notation data
   1287        21 = preferred hash algorithms
   1288        22 = preferred compression algorithms
   1289        23 = key server preferences
   1290        24 = preferred key server
   1291        25 = primary user id
   1292        26 = policy URL
   1293        27 = key flags
   1294        28 = signer's user id
   1295        29 = reason for revocation
   1296        100 to 110 = internal or user-defined
   1297 
   1298    An implementation SHOULD ignore any subpacket of a type that it does
   1299    not recognize.
   1300 
   1301    Bit 7 of the subpacket type is the "critical" bit.  If set, it
   1302    denotes that the subpacket is one that is critical for the evaluator
   1303    of the signature to recognize.  If a subpacket is encountered that is
   1304    marked critical but is unknown to the evaluating software, the
   1305    evaluator SHOULD consider the signature to be in error.
   1306 
   1307 
   1308 
   1309 
   1310 
   1311 
   1312 Callas, et. al.             Standards Track                    [Page 23]
   1313 
   1315 RFC 2440                 OpenPGP Message Format            November 1998
   1316 
   1317 
   1318    An evaluator may "recognize" a subpacket, but not implement it. The
   1319    purpose of the critical bit is to allow the signer to tell an
   1320    evaluator that it would prefer a new, unknown feature to generate an
   1321    error than be ignored.
   1322 
   1323    Implementations SHOULD implement "preferences".
   1324 
   1325 5.2.3.2. Signature Subpacket Types
   1326 
   1327    A number of subpackets are currently defined.  Some subpackets apply
   1328    to the signature itself and some are attributes of the key.
   1329    Subpackets that are found on a self-signature are placed on a user id
   1330    certification made by the key itself. Note that a key may have more
   1331    than one user id, and thus may have more than one self-signature, and
   1332    differing subpackets.
   1333 
   1334    A self-signature is a binding signature made by the key the signature
   1335    refers to. There are three types of self-signatures, the
   1336    certification signatures (types 0x10-0x13), the direct-key signature
   1337    (type 0x1f), and the subkey binding signature (type 0x18). For
   1338    certification self-signatures, each user ID may have a self-
   1339    signature, and thus different subpackets in those self-signatures.
   1340    For subkey binding signatures, each subkey in fact has a self-
   1341    signature. Subpackets that appear in a certification self-signature
   1342    apply to the username, and subpackets that appear in the subkey
   1343    self-signature apply to the subkey. Lastly, subpackets on the direct
   1344    key signature apply to the entire key.
   1345 
   1346    Implementing software should interpret a self-signature's preference
   1347    subpackets as narrowly as possible. For example, suppose a key has
   1348    two usernames, Alice and Bob. Suppose that Alice prefers the
   1349    symmetric algorithm CAST5, and Bob prefers IDEA or Triple-DES. If the
   1350    software locates this key via Alice's name, then the preferred
   1351    algorithm is CAST5, if software locates the key via Bob's name, then
   1352    the preferred algorithm is IDEA. If the key is located by key id,
   1353    then algorithm of the default user id of the key provides the default
   1354    symmetric algorithm.
   1355 
   1356    A subpacket may be found either in the hashed or unhashed subpacket
   1357    sections of a signature. If a subpacket is not hashed, then the
   1358    information in it cannot be considered definitive because it is not
   1359    part of the signature proper.
   1360 
   1361 
   1362 
   1363 
   1364 
   1365 
   1366 
   1367 
   1368 
   1369 Callas, et. al.             Standards Track                    [Page 24]
   1370 
   1372 RFC 2440                 OpenPGP Message Format            November 1998
   1373 
   1374 
   1375 5.2.3.3. Signature creation time
   1376 
   1377    (4 octet time field)
   1378 
   1379    The time the signature was made.
   1380 
   1381    MUST be present in the hashed area.
   1382 
   1383 5.2.3.4. Issuer
   1384 
   1385    (8 octet key ID)
   1386 
   1387    The OpenPGP key ID of the key issuing the signature.
   1388 
   1389 5.2.3.5. Key expiration time
   1390 
   1391    (4 octet time field)
   1392 
   1393    The validity period of the key.  This is the number of seconds after
   1394    the key creation time that the key expires.  If this is not present
   1395    or has a value of zero, the key never expires. This is found only on
   1396    a self-signature.
   1397 
   1398 5.2.3.6. Preferred symmetric algorithms
   1399 
   1400    (sequence of one-octet values)
   1401 
   1402    Symmetric algorithm numbers that indicate which algorithms the key
   1403    holder prefers to use.  The subpacket body is an ordered list of
   1404    octets with the most preferred listed first. It is assumed that only
   1405    algorithms listed are supported by the recipient's software.
   1406    Algorithm numbers in section 9. This is only found on a self-
   1407    signature.
   1408 
   1409 5.2.3.7. Preferred hash algorithms
   1410 
   1411    (array of one-octet values)
   1412 
   1413    Message digest algorithm numbers that indicate which algorithms the
   1414    key holder prefers to receive. Like the preferred symmetric
   1415    algorithms, the list is ordered. Algorithm numbers are in section 6.
   1416    This is only found on a self-signature.
   1417 
   1418 
   1419 
   1420 
   1421 
   1422 
   1423 
   1424 
   1425 
   1426 Callas, et. al.             Standards Track                    [Page 25]
   1427 
   1429 RFC 2440                 OpenPGP Message Format            November 1998
   1430 
   1431 
   1432 5.2.3.8. Preferred compression algorithms
   1433 
   1434    (array of one-octet values)
   1435 
   1436    Compression algorithm numbers that indicate which algorithms the key
   1437    holder prefers to use. Like the preferred symmetric algorithms, the
   1438    list is ordered. Algorithm numbers are in section 6. If this
   1439    subpacket is not included, ZIP is preferred. A zero denotes that
   1440    uncompressed data is preferred; the key holder's software might have
   1441    no compression software in that implementation. This is only found on
   1442    a self-signature.
   1443 
   1444 5.2.3.9. Signature expiration time
   1445 
   1446    (4 octet time field)
   1447 
   1448    The validity period of the signature.  This is the number of seconds
   1449    after the signature creation time that the signature expires. If this
   1450    is not present or has a value of zero, it never expires.
   1451 
   1452 5.2.3.10. Exportable Certification
   1453 
   1454    (1 octet of exportability, 0 for not, 1 for exportable)
   1455 
   1456    This subpacket denotes whether a certification signature is
   1457    "exportable", to be used by other users than the signature's issuer.
   1458    The packet body contains a boolean flag indicating whether the
   1459    signature is exportable. If this packet is not present, the
   1460    certification is exportable; it is equivalent to a flag containing a
   1461    1.
   1462 
   1463    Non-exportable, or "local", certifications are signatures made by a
   1464    user to mark a key as valid within that user's implementation only.
   1465    Thus, when an implementation prepares a user's copy of a key for
   1466    transport to another user (this is the process of "exporting" the
   1467    key), any local certification signatures are deleted from the key.
   1468 
   1469    The receiver of a transported key "imports" it, and likewise trims
   1470    any local certifications. In normal operation, there won't be any,
   1471    assuming the import is performed on an exported key. However, there
   1472    are instances where this can reasonably happen. For example, if an
   1473    implementation allows keys to be imported from a key database in
   1474    addition to an exported key, then this situation can arise.
   1475 
   1476    Some implementations do not represent the interest of a single user
   1477    (for example, a key server). Such implementations always trim local
   1478    certifications from any key they handle.
   1479 
   1480 
   1481 
   1482 
   1483 Callas, et. al.             Standards Track                    [Page 26]
   1484 
   1486 RFC 2440                 OpenPGP Message Format            November 1998
   1487 
   1488 
   1489 5.2.3.11. Revocable
   1490 
   1491    (1 octet of revocability, 0 for not, 1 for revocable)
   1492 
   1493    Signature's revocability status.  Packet body contains a boolean flag
   1494    indicating whether the signature is revocable.  Signatures that are
   1495    not revocable have any later revocation signatures ignored.  They
   1496    represent a commitment by the signer that he cannot revoke his
   1497    signature for the life of his key.  If this packet is not present,
   1498    the signature is revocable.
   1499 
   1500 5.2.3.12. Trust signature
   1501 
   1502    (1 octet "level" (depth), 1 octet of trust amount)
   1503 
   1504    Signer asserts that the key is not only valid, but also trustworthy,
   1505    at the specified level.  Level 0 has the same meaning as an ordinary
   1506    validity signature.  Level 1 means that the signed key is asserted to
   1507    be a valid trusted introducer, with the 2nd octet of the body
   1508    specifying the degree of trust. Level 2 means that the signed key is
   1509    asserted to be trusted to issue level 1 trust signatures, i.e. that
   1510    it is a "meta introducer". Generally, a level n trust signature
   1511    asserts that a key is trusted to issue level n-1 trust signatures.
   1512    The trust amount is in a range from 0-255, interpreted such that
   1513    values less than 120 indicate partial trust and values of 120 or
   1514    greater indicate complete trust.  Implementations SHOULD emit values
   1515    of 60 for partial trust and 120 for complete trust.
   1516 
   1517 5.2.3.13. Regular expression
   1518 
   1519    (null-terminated regular expression)
   1520 
   1521    Used in conjunction with trust signature packets (of level > 0) to
   1522    limit the scope of trust that is extended.  Only signatures by the
   1523    target key on user IDs that match the regular expression in the body
   1524    of this packet have trust extended by the trust signature subpacket.
   1525    The regular expression uses the same syntax as the Henry Spencer's
   1526    "almost public domain" regular expression package. A description of
   1527    the syntax is found in a section below.
   1528 
   1529 5.2.3.14. Revocation key
   1530 
   1531    (1 octet of class, 1 octet of algid, 20 octets of fingerprint)
   1532 
   1533    Authorizes the specified key to issue revocation signatures for this
   1534    key.  Class octet must have bit 0x80 set. If the bit 0x40 is set,
   1535    then this means that the revocation information is sensitive.  Other
   1536    bits are for future expansion to other kinds of authorizations. This
   1537 
   1538 
   1539 
   1540 Callas, et. al.             Standards Track                    [Page 27]
   1541 
   1543 RFC 2440                 OpenPGP Message Format            November 1998
   1544 
   1545 
   1546    is found on a self-signature.
   1547 
   1548    If the "sensitive" flag is set, the keyholder feels this subpacket
   1549    contains private trust information that describes a real-world
   1550    sensitive relationship. If this flag is set, implementations SHOULD
   1551    NOT export this signature to other users except in cases where the
   1552    data needs to be available: when the signature is being sent to the
   1553    designated revoker, or when it is accompanied by a revocation
   1554    signature from that revoker.  Note that it may be appropriate to
   1555    isolate this subpacket within a separate signature so that it is not
   1556    combined with other subpackets that need to be exported.
   1557 
   1558 5.2.3.15. Notation Data
   1559 
   1560        (4 octets of flags, 2 octets of name length (M),
   1561                            2 octets of value length (N),
   1562                            M octets of name data,
   1563                            N octets of value data)
   1564 
   1565    This subpacket describes a "notation" on the signature that the
   1566    issuer wishes to make. The notation has a name and a value, each of
   1567    which are strings of octets. There may be more than one notation in a
   1568    signature. Notations can be used for any extension the issuer of the
   1569    signature cares to make. The "flags" field holds four octets of
   1570    flags.
   1571 
   1572    All undefined flags MUST be zero. Defined flags are:
   1573 
   1574        First octet: 0x80 = human-readable. This note is text, a note
   1575                            from one person to another, and has no
   1576                            meaning to software.
   1577        Other octets: none.
   1578 
   1579 5.2.3.16. Key server preferences
   1580 
   1581    (N octets of flags)
   1582 
   1583    This is a list of flags that indicate preferences that the key holder
   1584    has about how the key is handled on a key server. All undefined flags
   1585    MUST be zero.
   1586 
   1587    First octet: 0x80 = No-modify
   1588        the key holder requests that this key only be modified or updated
   1589        by the key holder or an administrator of the key server.
   1590 
   1591    This is found only on a self-signature.
   1592 
   1593 
   1594 
   1595 
   1596 
   1597 Callas, et. al.             Standards Track                    [Page 28]
   1598 
   1600 RFC 2440                 OpenPGP Message Format            November 1998
   1601 
   1602 
   1603 5.2.3.17. Preferred key server
   1604 
   1605    (String)
   1606 
   1607    This is a URL of a key server that the key holder prefers be used for
   1608    updates. Note that keys with multiple user ids can have a preferred
   1609    key server for each user id. Note also that since this is a URL, the
   1610    key server can actually be a copy of the key retrieved by ftp, http,
   1611    finger, etc.
   1612 
   1613 5.2.3.18. Primary user id
   1614 
   1615    (1 octet, boolean)
   1616 
   1617    This is a flag in a user id's self signature that states whether this
   1618    user id is the main user id for this key. It is reasonable for an
   1619    implementation to resolve ambiguities in preferences, etc. by
   1620    referring to the primary user id. If this flag is absent, its value
   1621    is zero. If more than one user id in a key is marked as primary, the
   1622    implementation may resolve the ambiguity in any way it sees fit.
   1623 
   1624 5.2.3.19. Policy URL
   1625 
   1626    (String)
   1627 
   1628    This subpacket contains a URL of a document that describes the policy
   1629    that the signature was issued under.
   1630 
   1631 5.2.3.20. Key Flags
   1632 
   1633    (Octet string)
   1634 
   1635    This subpacket contains a list of binary flags that hold information
   1636    about a key. It is a string of octets, and an implementation MUST NOT
   1637    assume a fixed size. This is so it can grow over time. If a list is
   1638    shorter than an implementation expects, the unstated flags are
   1639    considered to be zero. The defined flags are:
   1640 
   1641        First octet:
   1642 
   1643        0x01 - This key may be used to certify other keys.
   1644 
   1645        0x02 - This key may be used to sign data.
   1646 
   1647        0x04 - This key may be used to encrypt communications.
   1648 
   1649        0x08 - This key may be used to encrypt storage.
   1650 
   1651 
   1652 
   1653 
   1654 Callas, et. al.             Standards Track                    [Page 29]
   1655 
   1657 RFC 2440                 OpenPGP Message Format            November 1998
   1658 
   1659 
   1660        0x10 - The private component of this key may have been split by a
   1661        secret-sharing mechanism.
   1662 
   1663        0x80 - The private component of this key may be in the possession
   1664        of more than one person.
   1665 
   1666    Usage notes:
   1667 
   1668    The flags in this packet may appear in self-signatures or in
   1669    certification signatures. They mean different things depending on who
   1670    is making the statement -- for example, a certification signature
   1671    that has the "sign data" flag is stating that the certification is
   1672    for that use. On the other hand, the "communications encryption" flag
   1673    in a self-signature is stating a preference that a given key be used
   1674    for communications. Note however, that it is a thorny issue to
   1675    determine what is "communications" and what is "storage." This
   1676    decision is left wholly up to the implementation; the authors of this
   1677    document do not claim any special wisdom on the issue, and realize
   1678    that accepted opinion may change.
   1679 
   1680    The "split key" (0x10) and "group key" (0x80) flags are placed on a
   1681    self-signature only; they are meaningless on a certification
   1682    signature. They SHOULD be placed only on a direct-key signature (type
   1683    0x1f) or a subkey signature (type 0x18), one that refers to the key
   1684    the flag applies to.
   1685 
   1686 5.2.3.21. Signer's User ID
   1687 
   1688    This subpacket allows a keyholder to state which user id is
   1689    responsible for the signing. Many keyholders use a single key for
   1690    different purposes, such as business communications as well as
   1691    personal communications. This subpacket allows such a keyholder to
   1692    state which of their roles is making a signature.
   1693 
   1694 5.2.3.22. Reason for Revocation
   1695 
   1696    (1 octet of revocation code, N octets of reason string)
   1697 
   1698    This subpacket is used only in key revocation and certification
   1699    revocation signatures. It describes the reason why the key or
   1700    certificate was revoked.
   1701 
   1702    The first octet contains a machine-readable code that denotes the
   1703    reason for the revocation:
   1704 
   1705 
   1706 
   1707 
   1708 
   1709 
   1710 
   1711 Callas, et. al.             Standards Track                    [Page 30]
   1712 
   1714 RFC 2440                 OpenPGP Message Format            November 1998
   1715 
   1716 
   1717        0x00 - No reason specified (key revocations or cert revocations)
   1718        0x01 - Key is superceded (key revocations)
   1719        0x02 - Key material has been compromised (key revocations)
   1720        0x03 - Key is no longer used (key revocations)
   1721        0x20 - User id information is no longer valid (cert revocations)
   1722 
   1723    Following the revocation code is a string of octets which gives
   1724    information about the reason for revocation in human-readable form
   1725    (UTF-8). The string may be null, that is, of zero length. The length
   1726    of the subpacket is the length of the reason string plus one.
   1727 
   1728 5.2.4. Computing Signatures
   1729 
   1730    All signatures are formed by producing a hash over the signature
   1731    data, and then using the resulting hash in the signature algorithm.
   1732 
   1733    The signature data is simple to compute for document signatures
   1734    (types 0x00 and 0x01), for which the document itself is the data.
   1735    For standalone signatures, this is a null string.
   1736 
   1737    When a signature is made over a key, the hash data starts with the
   1738    octet 0x99, followed by a two-octet length of the key, and then body
   1739    of the key packet. (Note that this is an old-style packet header for
   1740    a key packet with two-octet length.) A subkey signature (type 0x18)
   1741    then hashes the subkey, using the same format as the main key. Key
   1742    revocation signatures (types 0x20 and 0x28) hash only the key being
   1743    revoked.
   1744 
   1745    A certification signature (type 0x10 through 0x13) hashes the user id
   1746    being bound to the key into the hash context after the above data. A
   1747    V3 certification hashes the contents of the name packet, without any
   1748    header. A V4 certification hashes the constant 0xb4 (which is an
   1749    old-style packet header with the length-of-length set to zero), a
   1750    four-octet number giving the length of the username, and then the
   1751    username data.
   1752 
   1753    Once the data body is hashed, then a trailer is hashed. A V3
   1754    signature hashes five octets of the packet body, starting from the
   1755    signature type field. This data is the signature type, followed by
   1756    the four-octet signature time. A V4 signature hashes the packet body
   1757    starting from its first field, the version number, through the end of
   1758    the hashed subpacket data. Thus, the fields hashed are the signature
   1759    version, the signature type, the public key algorithm, the hash
   1760    algorithm, the hashed subpacket length, and the hashed subpacket
   1761    body.
   1762 
   1763 
   1764 
   1765 
   1766 
   1767 
   1768 Callas, et. al.             Standards Track                    [Page 31]
   1769 
   1771 RFC 2440                 OpenPGP Message Format            November 1998
   1772 
   1773 
   1774    V4 signatures also hash in a final trailer of six octets: the version
   1775    of the signature packet, i.e. 0x04; 0xFF; a four-octet, big-endian
   1776    number that is the length of the hashed data from the signature
   1777    packet (note that this number does not include these final six
   1778    octets.
   1779 
   1780    After all this has been hashed, the resulting hash field is used in
   1781    the signature algorithm, and placed at the end of the signature
   1782    packet.
   1783 
   1784 5.2.4.1. Subpacket Hints
   1785 
   1786    An implementation SHOULD put the two mandatory subpackets, creation
   1787    time and issuer, as the first subpackets in the subpacket list,
   1788    simply to make it easier for the implementer to find them.
   1789 
   1790    It is certainly possible for a signature to contain conflicting
   1791    information in subpackets. For example, a signature may contain
   1792    multiple copies of a preference or multiple expiration times. In most
   1793    cases, an implementation SHOULD use the last subpacket in the
   1794    signature, but MAY use any conflict resolution scheme that makes more
   1795    sense. Please note that we are intentionally leaving conflict
   1796    resolution to the implementer; most conflicts are simply syntax
   1797    errors, and the wishy-washy language here allows a receiver to be
   1798    generous in what they accept, while putting pressure on a creator to
   1799    be stingy in what they generate.
   1800 
   1801    Some apparent conflicts may actually make sense -- for example,
   1802    suppose a keyholder has an V3 key and a V4 key that share the same
   1803    RSA key material. Either of these keys can verify a signature created
   1804    by the other, and it may be reasonable for a signature to contain an
   1805    issuer subpacket for each key, as a way of explicitly tying those
   1806    keys to the signature.
   1807 
   1808 5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3)
   1809 
   1810    The Symmetric-Key Encrypted Session Key packet holds the symmetric-
   1811    key encryption of a session key used to encrypt a message.  Zero or
   1812    more Encrypted Session Key packets and/or Symmetric-Key Encrypted
   1813    Session Key packets may precede a Symmetrically Encrypted Data Packet
   1814    that holds an encrypted message.  The message is encrypted with a
   1815    session key, and the session key is itself encrypted and stored in
   1816    the Encrypted Session Key packet or the Symmetric-Key Encrypted
   1817    Session Key packet.
   1818 
   1819    If the Symmetrically Encrypted Data Packet is preceded by one or more
   1820    Symmetric-Key Encrypted Session Key packets, each specifies a
   1821    passphrase that may be used to decrypt the message.  This allows a
   1822 
   1823 
   1824 
   1825 Callas, et. al.             Standards Track                    [Page 32]
   1826 
   1828 RFC 2440                 OpenPGP Message Format            November 1998
   1829 
   1830 
   1831    message to be encrypted to a number of public keys, and also to one
   1832    or more pass phrases. This packet type is new, and is not generated
   1833    by PGP 2.x or PGP 5.0.
   1834 
   1835    The body of this packet consists of:
   1836 
   1837      - A one-octet version number. The only currently defined version
   1838        is 4.
   1839 
   1840      - A one-octet number describing the symmetric algorithm used.
   1841 
   1842      - A string-to-key (S2K) specifier, length as defined above.
   1843 
   1844      - Optionally, the encrypted session key itself, which is decrypted
   1845        with the string-to-key object.
   1846 
   1847    If the encrypted session key is not present (which can be detected on
   1848    the basis of packet length and S2K specifier size), then the S2K
   1849    algorithm applied to the passphrase produces the session key for
   1850    decrypting the file, using the symmetric cipher algorithm from the
   1851    Symmetric-Key Encrypted Session Key packet.
   1852 
   1853    If the encrypted session key is present, the result of applying the
   1854    S2K algorithm to the passphrase is used to decrypt just that
   1855    encrypted session key field, using CFB mode with an IV of all zeros.
   1856     The decryption result consists of a one-octet algorithm identifier
   1857    that specifies the symmetric-key encryption algorithm used to encrypt
   1858    the following Symmetrically Encrypted Data Packet, followed by the
   1859    session key octets themselves.
   1860 
   1861    Note: because an all-zero IV is used for this decryption, the S2K
   1862    specifier MUST use a salt value, either a Salted S2K or an Iterated-
   1863    Salted S2K.  The salt value will insure that the decryption key is
   1864    not repeated even if the passphrase is reused.
   1865 
   1866 5.4. One-Pass Signature Packets (Tag 4)
   1867 
   1868    The One-Pass Signature packet precedes the signed data and contains
   1869    enough information to allow the receiver to begin calculating any
   1870    hashes needed to verify the signature.  It allows the Signature
   1871    Packet to be placed at the end of the message, so that the signer can
   1872    compute the entire signed message in one pass.
   1873 
   1874    A One-Pass Signature does not interoperate with PGP 2.6.x or earlier.
   1875 
   1876    The body of this packet consists of:
   1877 
   1878 
   1879 
   1880 
   1881 
   1882 Callas, et. al.             Standards Track                    [Page 33]
   1883 
   1885 RFC 2440                 OpenPGP Message Format            November 1998
   1886 
   1887 
   1888      - A one-octet version number. The current version is 3.
   1889 
   1890      - A one-octet signature type. Signature types are described in
   1891        section 5.2.1.
   1892 
   1893      - A one-octet number describing the hash algorithm used.
   1894 
   1895      - A one-octet number describing the public key algorithm used.
   1896 
   1897      - An eight-octet number holding the key ID of the signing key.
   1898 
   1899      - A one-octet number holding a flag showing whether the signature
   1900        is nested.  A zero value indicates that the next packet is
   1901        another One-Pass Signature packet that describes another
   1902        signature to be applied to the same message data.
   1903 
   1904    Note that if a message contains more than one one-pass signature,
   1905    then the signature packets bracket the message; that is, the first
   1906    signature packet after the message corresponds to the last one-pass
   1907    packet and the final signature packet corresponds to the first one-
   1908    pass packet.
   1909 
   1910 5.5. Key Material Packet
   1911 
   1912    A key material packet contains all the information about a public or
   1913    private key.  There are four variants of this packet type, and two
   1914    major versions. Consequently, this section is complex.
   1915 
   1916 5.5.1. Key Packet Variants
   1917 
   1918 5.5.1.1. Public Key Packet (Tag 6)
   1919 
   1920    A Public Key packet starts a series of packets that forms an OpenPGP
   1921    key (sometimes called an OpenPGP certificate).
   1922 
   1923 5.5.1.2. Public Subkey Packet (Tag 14)
   1924 
   1925    A Public Subkey packet (tag 14) has exactly the same format as a
   1926    Public Key packet, but denotes a subkey. One or more subkeys may be
   1927    associated with a top-level key.  By convention, the top-level key
   1928    provides signature services, and the subkeys provide encryption
   1929    services.
   1930 
   1931    Note: in PGP 2.6.x, tag 14 was intended to indicate a comment packet.
   1932    This tag was selected for reuse because no previous version of PGP
   1933    ever emitted comment packets but they did properly ignore them.
   1934    Public Subkey packets are ignored by PGP 2.6.x and do not cause it to
   1935    fail, providing a limited degree of backward compatibility.
   1936 
   1937 
   1938 
   1939 Callas, et. al.             Standards Track                    [Page 34]
   1940 
   1942 RFC 2440                 OpenPGP Message Format            November 1998
   1943 
   1944 
   1945 5.5.1.3. Secret Key Packet (Tag 5)
   1946 
   1947    A Secret Key packet contains all the information that is found in a
   1948    Public Key packet, including the public key material, but also
   1949    includes the secret key material after all the public key fields.
   1950 
   1951 5.5.1.4. Secret Subkey Packet (Tag 7)
   1952 
   1953    A Secret Subkey packet (tag 7) is the subkey analog of the Secret Key
   1954    packet, and has exactly the same format.
   1955 
   1956 5.5.2. Public Key Packet Formats
   1957 
   1958    There are two versions of key-material packets. Version 3 packets
   1959    were first generated by PGP 2.6. Version 2 packets are identical in
   1960    format to Version 3 packets, but are generated by PGP 2.5 or before.
   1961    V2 packets are deprecated and they MUST NOT be generated.  PGP 5.0
   1962    introduced version 4 packets, with new fields and semantics.  PGP
   1963    2.6.x will not accept key-material packets with versions greater than
   1964    3.
   1965 
   1966    OpenPGP implementations SHOULD create keys with version 4 format. An
   1967    implementation MAY generate a V3 key to ensure interoperability with
   1968    old software; note, however, that V4 keys correct some security
   1969    deficiencies in V3 keys. These deficiencies are described below. An
   1970    implementation MUST NOT create a V3 key with a public key algorithm
   1971    other than RSA.
   1972 
   1973    A version 3 public key or public subkey packet contains:
   1974 
   1975      - A one-octet version number (3).
   1976 
   1977      - A four-octet number denoting the time that the key was created.
   1978 
   1979      - A two-octet number denoting the time in days that this key is
   1980        valid. If this number is zero, then it does not expire.
   1981 
   1982      - A one-octet number denoting the public key algorithm of this key
   1983 
   1984      - A series of multi-precision integers comprising the key
   1985        material:
   1986 
   1987          - a multiprecision integer (MPI) of RSA public modulus n;
   1988 
   1989          - an MPI of RSA public encryption exponent e.
   1990 
   1991 
   1992 
   1993 
   1994 
   1995 
   1996 Callas, et. al.             Standards Track                    [Page 35]
   1997 
   1999 RFC 2440                 OpenPGP Message Format            November 1998
   2000 
   2001 
   2002    V3 keys SHOULD only be used for backward compatibility because of
   2003    three weaknesses in them. First, it is relatively easy to construct a
   2004    V3 key that has the same key ID as any other key because the key ID
   2005    is simply the low 64 bits of the public modulus. Secondly, because
   2006    the fingerprint of a V3 key hashes the key material, but not its
   2007    length, which increases the opportunity for fingerprint collisions.
   2008    Third, there are minor weaknesses in the MD5 hash algorithm that make
   2009    developers prefer other algorithms. See below for a fuller discussion
   2010    of key IDs and fingerprints.
   2011 
   2012    The version 4 format is similar to the version 3 format except for
   2013    the absence of a validity period.  This has been moved to the
   2014    signature packet.  In addition, fingerprints of version 4 keys are
   2015    calculated differently from version 3 keys, as described in section
   2016    "Enhanced Key Formats."
   2017 
   2018    A version 4 packet contains:
   2019 
   2020      - A one-octet version number (4).
   2021 
   2022      - A four-octet number denoting the time that the key was created.
   2023 
   2024      - A one-octet number denoting the public key algorithm of this key
   2025 
   2026      - A series of multi-precision integers comprising the key
   2027        material.  This algorithm-specific portion is:
   2028 
   2029        Algorithm Specific Fields for RSA public keys:
   2030 
   2031          - multiprecision integer (MPI) of RSA public modulus n;
   2032 
   2033          - MPI of RSA public encryption exponent e.
   2034 
   2035        Algorithm Specific Fields for DSA public keys:
   2036 
   2037          - MPI of DSA prime p;
   2038 
   2039          - MPI of DSA group order q (q is a prime divisor of p-1);
   2040 
   2041          - MPI of DSA group generator g;
   2042 
   2043          - MPI of DSA public key value y (= g**x where x is secret).
   2044 
   2045        Algorithm Specific Fields for Elgamal public keys:
   2046 
   2047          - MPI of Elgamal prime p;
   2048 
   2049          - MPI of Elgamal group generator g;
   2050 
   2051 
   2052 
   2053 Callas, et. al.             Standards Track                    [Page 36]
   2054 
   2056 RFC 2440                 OpenPGP Message Format            November 1998
   2057 
   2058 
   2059          - MPI of Elgamal public key value y (= g**x where x is
   2060            secret).
   2061 
   2062 5.5.3. Secret Key Packet Formats
   2063 
   2064    The Secret Key and Secret Subkey packets contain all the data of the
   2065    Public Key and Public Subkey packets, with additional algorithm-
   2066    specific secret key data appended, in encrypted form.
   2067 
   2068    The packet contains:
   2069 
   2070      - A Public Key or Public Subkey packet, as described above
   2071 
   2072      - One octet indicating string-to-key usage conventions.  0
   2073        indicates that the secret key data is not encrypted.  255
   2074        indicates that a string-to-key specifier is being given.  Any
   2075        other value is a symmetric-key encryption algorithm specifier.
   2076 
   2077      - [Optional] If string-to-key usage octet was 255, a one-octet
   2078        symmetric encryption algorithm.
   2079 
   2080      - [Optional] If string-to-key usage octet was 255, a string-to-key
   2081        specifier.  The length of the string-to-key specifier is implied
   2082        by its type, as described above.
   2083 
   2084      - [Optional] If secret data is encrypted, eight-octet Initial
   2085        Vector (IV).
   2086 
   2087      - Encrypted multi-precision integers comprising the secret key
   2088        data. These algorithm-specific fields are as described below.
   2089 
   2090      - Two-octet checksum of the plaintext of the algorithm-specific
   2091        portion (sum of all octets, mod 65536).
   2092 
   2093        Algorithm Specific Fields for RSA secret keys:
   2094 
   2095        - multiprecision integer (MPI) of RSA secret exponent d.
   2096 
   2097        - MPI of RSA secret prime value p.
   2098 
   2099        - MPI of RSA secret prime value q (p < q).
   2100 
   2101        - MPI of u, the multiplicative inverse of p, mod q.
   2102 
   2103        Algorithm Specific Fields for DSA secret keys:
   2104 
   2105        - MPI of DSA secret exponent x.
   2106 
   2107 
   2108 
   2109 
   2110 Callas, et. al.             Standards Track                    [Page 37]
   2111 
   2113 RFC 2440                 OpenPGP Message Format            November 1998
   2114 
   2115 
   2116        Algorithm Specific Fields for Elgamal secret keys:
   2117 
   2118        - MPI of Elgamal secret exponent x.
   2119 
   2120    Secret MPI values can be encrypted using a passphrase.  If a string-
   2121    to-key specifier is given, that describes the algorithm for
   2122    converting the passphrase to a key, else a simple MD5 hash of the
   2123    passphrase is used.  Implementations SHOULD use a string-to-key
   2124    specifier; the simple hash is for backward compatibility. The cipher
   2125    for encrypting the MPIs is specified in the secret key packet.
   2126 
   2127    Encryption/decryption of the secret data is done in CFB mode using
   2128    the key created from the passphrase and the Initial Vector from the
   2129    packet. A different mode is used with V3 keys (which are only RSA)
   2130    than with other key formats. With V3 keys, the MPI bit count prefix
   2131    (i.e., the first two octets) is not encrypted.  Only the MPI non-
   2132    prefix data is encrypted.  Furthermore, the CFB state is
   2133    resynchronized at the beginning of each new MPI value, so that the
   2134    CFB block boundary is aligned with the start of the MPI data.
   2135 
   2136    With V4 keys, a simpler method is used.  All secret MPI values are
   2137    encrypted in CFB mode, including the MPI bitcount prefix.
   2138 
   2139    The 16-bit checksum that follows the algorithm-specific portion is
   2140    the algebraic sum, mod 65536, of the plaintext of all the algorithm-
   2141    specific octets (including MPI prefix and data).  With V3 keys, the
   2142    checksum is stored in the clear.  With V4 keys, the checksum is
   2143    encrypted like the algorithm-specific data.  This value is used to
   2144    check that the passphrase was correct.
   2145 
   2146 5.6. Compressed Data Packet (Tag 8)
   2147 
   2148    The Compressed Data packet contains compressed data. Typically, this
   2149    packet is found as the contents of an encrypted packet, or following
   2150    a Signature or One-Pass Signature packet, and contains literal data
   2151    packets.
   2152 
   2153    The body of this packet consists of:
   2154 
   2155      - One octet that gives the algorithm used to compress the packet.
   2156 
   2157      - The remainder of the packet is compressed data.
   2158 
   2159    A Compressed Data Packet's body contains an block that compresses
   2160    some set of packets. See section "Packet Composition" for details on
   2161    how messages are formed.
   2162 
   2163 
   2164 
   2165 
   2166 
   2167 Callas, et. al.             Standards Track                    [Page 38]
   2168 
   2170 RFC 2440                 OpenPGP Message Format            November 1998
   2171 
   2172 
   2173    ZIP-compressed packets are compressed with raw RFC 1951 DEFLATE
   2174    blocks. Note that PGP V2.6 uses 13 bits of compression. If an
   2175    implementation uses more bits of compression, PGP V2.6 cannot
   2176    decompress it.
   2177 
   2178    ZLIB-compressed packets are compressed with RFC 1950 ZLIB-style
   2179    blocks.
   2180 
   2181 5.7. Symmetrically Encrypted Data Packet (Tag 9)
   2182 
   2183    The Symmetrically Encrypted Data packet contains data encrypted with
   2184    a symmetric-key algorithm. When it has been decrypted, it will
   2185    typically contain other packets (often literal data packets or
   2186    compressed data packets).
   2187 
   2188    The body of this packet consists of:
   2189 
   2190      - Encrypted data, the output of the selected symmetric-key cipher
   2191        operating in PGP's variant of Cipher Feedback (CFB) mode.
   2192 
   2193    The symmetric cipher used may be specified in an Public-Key or
   2194    Symmetric-Key Encrypted Session Key packet that precedes the
   2195    Symmetrically Encrypted Data Packet.  In that case, the cipher
   2196    algorithm octet is prefixed to the session key before it is
   2197    encrypted.  If no packets of these types precede the encrypted data,
   2198    the IDEA algorithm is used with the session key calculated as the MD5
   2199    hash of the passphrase.
   2200 
   2201    The data is encrypted in CFB mode, with a CFB shift size equal to the
   2202    cipher's block size.  The Initial Vector (IV) is specified as all
   2203    zeros.  Instead of using an IV, OpenPGP prefixes a 10-octet string to
   2204    the data before it is encrypted.  The first eight octets are random,
   2205    and the 9th and 10th octets are copies of the 7th and 8th octets,
   2206    respectively. After encrypting the first 10 octets, the CFB state is
   2207    resynchronized if the cipher block size is 8 octets or less.  The
   2208    last 8 octets of ciphertext are passed through the cipher and the
   2209    block boundary is reset.
   2210 
   2211    The repetition of 16 bits in the 80 bits of random data prefixed to
   2212    the message allows the receiver to immediately check whether the
   2213    session key is incorrect.
   2214 
   2215 5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
   2216 
   2217    An experimental version of PGP used this packet as the Literal
   2218    packet, but no released version of PGP generated Literal packets with
   2219    this tag. With PGP 5.x, this packet has been re-assigned and is
   2220    reserved for use as the Marker packet.
   2221 
   2222 
   2223 
   2224 Callas, et. al.             Standards Track                    [Page 39]
   2225 
   2227 RFC 2440                 OpenPGP Message Format            November 1998
   2228 
   2229 
   2230    The body of this packet consists of:
   2231 
   2232      - The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
   2233 
   2234    Such a packet MUST be ignored when received.  It may be placed at the
   2235    beginning of a message that uses features not available in PGP 2.6.x
   2236    in order to cause that version to report that newer software is
   2237    necessary to process the message.
   2238 
   2239 5.9. Literal Data Packet (Tag 11)
   2240 
   2241    A Literal Data packet contains the body of a message; data that is
   2242    not to be further interpreted.
   2243 
   2244    The body of this packet consists of:
   2245 
   2246      - A one-octet field that describes how the data is formatted.
   2247 
   2248    If it is a 'b' (0x62), then the literal packet contains binary data.
   2249    If it is a 't' (0x74), then it contains text data, and thus may need
   2250    line ends converted to local form, or other text-mode changes.  RFC
   2251    1991 also defined a value of 'l' as a 'local' mode for machine-local
   2252    conversions.  This use is now deprecated.
   2253 
   2254      - File name as a string (one-octet length, followed by file name),
   2255        if the encrypted data should be saved as a file.
   2256 
   2257    If the special name "_CONSOLE" is used, the message is considered to
   2258    be "for your eyes only".  This advises that the message data is
   2259    unusually sensitive, and the receiving program should process it more
   2260    carefully, perhaps avoiding storing the received data to disk, for
   2261    example.
   2262 
   2263      - A four-octet number that indicates the modification date of the
   2264        file, or the creation time of the packet, or a zero that
   2265        indicates the present time.
   2266 
   2267      - The remainder of the packet is literal data.
   2268 
   2269    Text data is stored with <CR><LF> text endings (i.e. network-normal
   2270    line endings).  These should be converted to native line endings by
   2271    the receiving software.
   2272 
   2273 5.10. Trust Packet (Tag 12)
   2274 
   2275    The Trust packet is used only within keyrings and is not normally
   2276    exported.  Trust packets contain data that record the user's
   2277    specifications of which key holders are trustworthy introducers,
   2278 
   2279 
   2280 
   2281 Callas, et. al.             Standards Track                    [Page 40]
   2282 
   2284 RFC 2440                 OpenPGP Message Format            November 1998
   2285 
   2286 
   2287    along with other information that implementing software uses for
   2288    trust information.
   2289 
   2290    Trust packets SHOULD NOT be emitted to output streams that are
   2291    transferred to other users, and they SHOULD be ignored on any input
   2292    other than local keyring files.
   2293 
   2294 5.11. User ID Packet (Tag 13)
   2295 
   2296    A User ID packet consists of data that is intended to represent the
   2297    name and email address of the key holder.  By convention, it includes
   2298    an RFC 822 mail name, but there are no restrictions on its content.
   2299    The packet length in the header specifies the length of the user id.
   2300    If it is text, it is encoded in UTF-8.
   2301 
   2302 6. Radix-64 Conversions
   2303 
   2304    As stated in the introduction, OpenPGP's underlying native
   2305    representation for objects is a stream of arbitrary octets, and some
   2306    systems desire these objects to be immune to damage caused by
   2307    character set translation, data conversions, etc.
   2308 
   2309    In principle, any printable encoding scheme that met the requirements
   2310    of the unsafe channel would suffice, since it would not change the
   2311    underlying binary bit streams of the native OpenPGP data structures.
   2312    The OpenPGP standard specifies one such printable encoding scheme to
   2313    ensure interoperability.
   2314 
   2315    OpenPGP's Radix-64 encoding is composed of two parts: a base64
   2316    encoding of the binary data, and a checksum.  The base64 encoding is
   2317    identical to the MIME base64 content-transfer-encoding [RFC2231,
   2318    Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to
   2319    protect the raw binary data.
   2320 
   2321    The checksum is a 24-bit CRC converted to four characters of radix-64
   2322    encoding by the same MIME base64 transformation, preceded by an
   2323    equals sign (=).  The CRC is computed by using the generator 0x864CFB
   2324    and an initialization of 0xB704CE.  The accumulation is done on the
   2325    data before it is converted to radix-64, rather than on the converted
   2326    data.  A sample implementation of this algorithm is in the next
   2327    section.
   2328 
   2329    The checksum with its leading equal sign MAY appear on the first line
   2330    after the Base64 encoded data.
   2331 
   2332    Rationale for CRC-24: The size of 24 bits fits evenly into printable
   2333    base64.  The nonzero initialization can detect more errors than a
   2334    zero initialization.
   2335 
   2336 
   2337 
   2338 Callas, et. al.             Standards Track                    [Page 41]
   2339 
   2341 RFC 2440                 OpenPGP Message Format            November 1998
   2342 
   2343 
   2344 6.1. An Implementation of the CRC-24 in "C"
   2345 
   2346        #define CRC24_INIT 0xb704ceL
   2347        #define CRC24_POLY 0x1864cfbL
   2348 
   2349        typedef long crc24;
   2350        crc24 crc_octets(unsigned char *octets, size_t len)
   2351        {
   2352            crc24 crc = CRC24_INIT;
   2353            int i;
   2354 
   2355            while (len--) {
   2356                crc ^= (*octets++) << 16;
   2357                for (i = 0; i < 8; i++) {
   2358                    crc <<= 1;
   2359                    if (crc & 0x1000000)
   2360                        crc ^= CRC24_POLY;
   2361                }
   2362            }
   2363            return crc & 0xffffffL;
   2364        }
   2365 
   2366 6.2. Forming ASCII Armor
   2367 
   2368    When OpenPGP encodes data into ASCII Armor, it puts specific headers
   2369    around the data, so OpenPGP can reconstruct the data later. OpenPGP
   2370    informs the user what kind of data is encoded in the ASCII armor
   2371    through the use of the headers.
   2372 
   2373    Concatenating the following data creates ASCII Armor:
   2374 
   2375      - An Armor Header Line, appropriate for the type of data
   2376 
   2377      - Armor Headers
   2378 
   2379      - A blank (zero-length, or containing only whitespace) line
   2380 
   2381      - The ASCII-Armored data
   2382 
   2383      - An Armor Checksum
   2384 
   2385      - The Armor Tail, which depends on the Armor Header Line.
   2386 
   2387    An Armor Header Line consists of the appropriate header line text
   2388    surrounded by five (5) dashes ('-', 0x2D) on either side of the
   2389    header line text.  The header line text is chosen based upon the type
   2390    of data that is being encoded in Armor, and how it is being encoded.
   2391    Header line texts include the following strings:
   2392 
   2393 
   2394 
   2395 Callas, et. al.             Standards Track                    [Page 42]
   2396 
   2398 RFC 2440                 OpenPGP Message Format            November 1998
   2399 
   2400 
   2401    BEGIN PGP MESSAGE
   2402        Used for signed, encrypted, or compressed files.
   2403 
   2404    BEGIN PGP PUBLIC KEY BLOCK
   2405        Used for armoring public keys
   2406 
   2407    BEGIN PGP PRIVATE KEY BLOCK
   2408        Used for armoring private keys
   2409 
   2410    BEGIN PGP MESSAGE, PART X/Y
   2411        Used for multi-part messages, where the armor is split amongst Y
   2412        parts, and this is the Xth part out of Y.
   2413 
   2414    BEGIN PGP MESSAGE, PART X
   2415        Used for multi-part messages, where this is the Xth part of an
   2416        unspecified number of parts. Requires the MESSAGE-ID Armor Header
   2417        to be used.
   2418 
   2419    BEGIN PGP SIGNATURE
   2420        Used for detached signatures, OpenPGP/MIME signatures, and
   2421        natures following clearsigned messages. Note that PGP 2.x s BEGIN
   2422        PGP MESSAGE for detached signatures.
   2423 
   2424    The Armor Headers are pairs of strings that can give the user or the
   2425    receiving OpenPGP implementation some information about how to decode
   2426    or use the message.  The Armor Headers are a part of the armor, not a
   2427    part of the message, and hence are not protected by any signatures
   2428    applied to the message.
   2429 
   2430    The format of an Armor Header is that of a key-value pair.  A colon
   2431    (':' 0x38) and a single space (0x20) separate the key and value.
   2432    OpenPGP should consider improperly formatted Armor Headers to be
   2433    corruption of the ASCII Armor.  Unknown keys should be reported to
   2434    the user, but OpenPGP should continue to process the message.
   2435 
   2436    Currently defined Armor Header Keys are:
   2437 
   2438      - "Version", that states the OpenPGP Version used to encode the
   2439        message.
   2440 
   2441      - "Comment", a user-defined comment.
   2442 
   2443      - "MessageID", a 32-character string of printable characters.  The
   2444        string must be the same for all parts of a multi-part message
   2445        that uses the "PART X" Armor Header.  MessageID strings should be
   2446 
   2447 
   2448 
   2449 
   2450 
   2451 
   2452 Callas, et. al.             Standards Track                    [Page 43]
   2453 
   2455 RFC 2440                 OpenPGP Message Format            November 1998
   2456 
   2457 
   2458        unique enough that the recipient of the mail can associate all
   2459        the parts of a message with each other. A good checksum or
   2460        cryptographic hash function is sufficient.
   2461 
   2462      - "Hash", a comma-separated list of hash algorithms used in this
   2463        message. This is used only in clear-signed messages.
   2464 
   2465      - "Charset", a description of the character set that the plaintext
   2466        is in. Please note that OpenPGP defines text to be in UTF-8 by
   2467        default. An implementation will get best results by translating
   2468        into and out of UTF-8. However, there are many instances where
   2469        this is easier said than done. Also, there are communities of
   2470        users who have no need for UTF-8 because they are all happy with
   2471        a character set like ISO Latin-5 or a Japanese character set. In
   2472        such instances, an implementation MAY override the UTF-8 default
   2473        by using this header key. An implementation MAY implement this
   2474        key and any translations it cares to; an implementation MAY
   2475        ignore it and assume all text is UTF-8.
   2476 
   2477        The MessageID SHOULD NOT appear unless it is in a multi-part
   2478        message. If it appears at all, it MUST be computed from the
   2479        finished (encrypted, signed, etc.) message in a deterministic
   2480        fashion, rather than contain a purely random value.  This is to
   2481        allow the legitimate recipient to determine that the MessageID
   2482        cannot serve as a covert means of leaking cryptographic key
   2483        information.
   2484 
   2485    The Armor Tail Line is composed in the same manner as the Armor
   2486    Header Line, except the string "BEGIN" is replaced by the string
   2487    "END."
   2488 
   2489 6.3. Encoding Binary in Radix-64
   2490 
   2491    The encoding process represents 24-bit groups of input bits as output
   2492    strings of 4 encoded characters. Proceeding from left to right, a
   2493    24-bit input group is formed by concatenating three 8-bit input
   2494    groups. These 24 bits are then treated as four concatenated 6-bit
   2495    groups, each of which is translated into a single digit in the
   2496    Radix-64 alphabet. When encoding a bit stream with the Radix-64
   2497    encoding, the bit stream must be presumed to be ordered with the
   2498    most-significant-bit first. That is, the first bit in the stream will
   2499    be the high-order bit in the first 8-bit octet, and the eighth bit
   2500    will be the low-order bit in the first 8-bit octet, and so on.
   2501 
   2502 
   2503 
   2504 
   2505 
   2506 
   2507 
   2508 
   2509 Callas, et. al.             Standards Track                    [Page 44]
   2510 
   2512 RFC 2440                 OpenPGP Message Format            November 1998
   2513 
   2514 
   2515          +--first octet--+-second octet--+--third octet--+
   2516          |7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|
   2517          +-----------+---+-------+-------+---+-----------+
   2518          |5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|
   2519          +--1.index--+--2.index--+--3.index--+--4.index--+
   2520 
   2521    Each 6-bit group is used as an index into an array of 64 printable
   2522    characters from the table below. The character referenced by the
   2523    index is placed in the output string.
   2524 
   2525      Value Encoding  Value Encoding  Value Encoding  Value Encoding
   2526          0 A            17 R            34 i            51 z
   2527          1 B            18 S            35 j            52 0
   2528          2 C            19 T            36 k            53 1
   2529          3 D            20 U            37 l            54 2
   2530          4 E            21 V            38 m            55 3
   2531          5 F            22 W            39 n            56 4
   2532          6 G            23 X            40 o            57 5
   2533          7 H            24 Y            41 p            58 6
   2534          8 I            25 Z            42 q            59 7
   2535          9 J            26 a            43 r            60 8
   2536         10 K            27 b            44 s            61 9
   2537         11 L            28 c            45 t            62 +
   2538         12 M            29 d            46 u            63 /
   2539         13 N            30 e            47 v
   2540         14 O            31 f            48 w         (pad) =
   2541         15 P            32 g            49 x
   2542         16 Q            33 h            50 y
   2543 
   2544    The encoded output stream must be represented in lines of no more
   2545    than 76 characters each.
   2546 
   2547    Special processing is performed if fewer than 24 bits are available
   2548    at the end of the data being encoded. There are three possibilities:
   2549 
   2550     1. The last data group has 24 bits (3 octets). No special
   2551        processing is needed.
   2552 
   2553     2. The last data group has 16 bits (2 octets). The first two 6-bit
   2554        groups are processed as above. The third (incomplete) data group
   2555        has two zero-value bits added to it, and is processed as above.
   2556        A pad character (=) is added to the output.
   2557 
   2558     3. The last data group has 8 bits (1 octet). The first 6-bit group
   2559        is processed as above. The second (incomplete) data group has
   2560        four zero-value bits added to it, and is processed as above. Two
   2561        pad characters (=) are added to the output.
   2562 
   2563 
   2564 
   2565 
   2566 Callas, et. al.             Standards Track                    [Page 45]
   2567 
   2569 RFC 2440                 OpenPGP Message Format            November 1998
   2570 
   2571 
   2572 6.4. Decoding Radix-64
   2573 
   2574    Any characters outside of the base64 alphabet are ignored in Radix-64
   2575    data. Decoding software must ignore all line breaks or other
   2576    characters not found in the table above.
   2577 
   2578    In Radix-64 data, characters other than those in the table, line
   2579    breaks, and other white space probably indicate a transmission error,
   2580    about which a warning message or even a message rejection might be
   2581    appropriate under some circumstances.
   2582 
   2583    Because it is used only for padding at the end of the data, the
   2584    occurrence of any "=" characters may be taken as evidence that the
   2585    end of the data has been reached (without truncation in transit). No
   2586    such assurance is possible, however, when the number of octets
   2587    transmitted was a multiple of three and no "=" characters are
   2588    present.
   2589 
   2590 6.5. Examples of Radix-64
   2591 
   2592        Input data:  0x14fb9c03d97e
   2593        Hex:     1   4    f   b    9   c     | 0   3    d   9    7   e
   2594        8-bit:   00010100 11111011 10011100  | 00000011 11011001
   2595        11111110
   2596        6-bit:   000101 001111 101110 011100 | 000000 111101 100111
   2597        111110
   2598        Decimal: 5      15     46     28       0      61     37     62
   2599        Output:  F      P      u      c        A      9      l      +
   2600 
   2601        Input data:  0x14fb9c03d9
   2602        Hex:     1   4    f   b    9   c     | 0   3    d   9
   2603        8-bit:   00010100 11111011 10011100  | 00000011 11011001
   2604                                                        pad with 00
   2605        6-bit:   000101 001111 101110 011100 | 000000 111101 100100
   2606        Decimal: 5      15     46     28       0      61     36
   2607                                                           pad with =
   2608        Output:  F      P      u      c        A      9      k      =
   2609 
   2610        Input data:  0x14fb9c03
   2611        Hex:     1   4    f   b    9   c     | 0   3
   2612        8-bit:   00010100 11111011 10011100  | 00000011
   2613                                               pad with 0000
   2614        6-bit:   000101 001111 101110 011100 | 000000 110000
   2615        Decimal: 5      15     46     28       0      48
   2616                                                    pad with =      =
   2617        Output:  F      P      u      c        A      w      =      =
   2618 
   2619 
   2620 
   2621 
   2622 
   2623 Callas, et. al.             Standards Track                    [Page 46]
   2624 
   2626 RFC 2440                 OpenPGP Message Format            November 1998
   2627 
   2628 
   2629 6.6. Example of an ASCII Armored Message
   2630 
   2631 
   2632   -----BEGIN PGP MESSAGE-----
   2633   Version: OpenPrivacy 0.99
   2634 
   2635   yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
   2636   vBSFjNSiVHsuAA==
   2637   =njUN
   2638   -----END PGP MESSAGE-----
   2639 
   2640    Note that this example is indented by two spaces.
   2641 
   2642 7. Cleartext signature framework
   2643 
   2644    It is desirable to sign a textual octet stream without ASCII armoring
   2645    the stream itself, so the signed text is still readable without
   2646    special software. In order to bind a signature to such a cleartext,
   2647    this framework is used.  (Note that RFC 2015 defines another way to
   2648    clear sign messages for environments that support MIME.)
   2649 
   2650    The cleartext signed message consists of:
   2651 
   2652      - The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a
   2653        single line,
   2654 
   2655      - One or more "Hash" Armor Headers,
   2656 
   2657      - Exactly one empty line not included into the message digest,
   2658 
   2659      - The dash-escaped cleartext that is included into the message
   2660        digest,
   2661 
   2662      - The ASCII armored signature(s) including the '-----BEGIN PGP
   2663        SIGNATURE-----' Armor Header and Armor Tail Lines.
   2664 
   2665    If the "Hash" armor header is given, the specified message digest
   2666    algorithm is used for the signature. If there are no such headers,
   2667    MD5 is used, an implementation MAY omit them for V2.x compatibility.
   2668    If more than one message digest is used in the signature, the "Hash"
   2669    armor header contains a comma-delimited list of used message digests.
   2670 
   2671    Current message digest names are described below with the algorithm
   2672    IDs.
   2673 
   2674 7.1. Dash-Escaped Text
   2675 
   2676    The cleartext content of the message must also be dash-escaped.
   2677 
   2678 
   2679 
   2680 Callas, et. al.             Standards Track                    [Page 47]
   2681 
   2683 RFC 2440                 OpenPGP Message Format            November 1998
   2684 
   2685 
   2686    Dash escaped cleartext is the ordinary cleartext where every line
   2687    starting with a dash '-' (0x2D) is prefixed by the sequence dash '-'
   2688    (0x2D) and space ' ' (0x20). This prevents the parser from
   2689    recognizing armor headers of the cleartext itself. The message digest
   2690    is computed using the cleartext itself, not the dash escaped form.
   2691 
   2692    As with binary signatures on text documents, a cleartext signature is
   2693    calculated on the text using canonical <CR><LF> line endings.  The
   2694    line ending (i.e. the <CR><LF>) before the '-----BEGIN PGP
   2695    SIGNATURE-----' line that terminates the signed text is not
   2696    considered part of the signed text.
   2697 
   2698    Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of
   2699    any line is ignored when the cleartext signature is calculated.
   2700 
   2701 8. Regular Expressions
   2702 
   2703    A regular expression is zero or more branches, separated by '|'. It
   2704    matches anything that matches one of the branches.
   2705 
   2706    A branch is zero or more pieces, concatenated. It matches a match for
   2707    the first, followed by a match for the second, etc.
   2708 
   2709    A piece is an atom possibly followed by '*', '+', or '?'. An atom
   2710    followed by '*' matches a sequence of 0 or more matches of the atom.
   2711    An atom followed by '+' matches a sequence of 1 or more matches of
   2712    the atom. An atom followed by '?' matches a match of the atom, or the
   2713    null string.
   2714 
   2715    An atom is a regular expression in parentheses (matching a match for
   2716    the regular expression), a range (see below), '.' (matching any
   2717    single character), '^' (matching the null string at the beginning of
   2718    the input string), '$' (matching the null string at the end of the
   2719    input string), a '\' followed by a single character (matching that
   2720    character), or a single character with no other significance
   2721    (matching that character).
   2722 
   2723    A range is a sequence of characters enclosed in '[]'. It normally
   2724    matches any single character from the sequence. If the sequence
   2725    begins with '^', it matches any single character not from the rest of
   2726    the sequence. If two characters in the sequence are separated by '-',
   2727    this is shorthand for the full list of ASCII characters between them
   2728    (e.g. '[0-9]' matches any decimal digit). To include a literal ']' in
   2729    the sequence, make it the first character (following a possible '^').
   2730    To include a literal '-', make it the first or last character.
   2731 
   2732 
   2733 
   2734 
   2735 
   2736 
   2737 Callas, et. al.             Standards Track                    [Page 48]
   2738 
   2740 RFC 2440                 OpenPGP Message Format            November 1998
   2741 
   2742 
   2743 9. Constants
   2744 
   2745    This section describes the constants used in OpenPGP.
   2746 
   2747    Note that these tables are not exhaustive lists; an implementation
   2748    MAY implement an algorithm not on these lists.
   2749 
   2750    See the section "Notes on Algorithms" below for more discussion of
   2751    the algorithms.
   2752 
   2753 9.1. Public Key Algorithms
   2754 
   2755        ID           Algorithm
   2756        --           ---------
   2757        1          - RSA (Encrypt or Sign)
   2758        2          - RSA Encrypt-Only
   2759        3          - RSA Sign-Only
   2760        16         - Elgamal (Encrypt-Only), see [ELGAMAL]
   2761        17         - DSA (Digital Signature Standard)
   2762        18         - Reserved for Elliptic Curve
   2763        19         - Reserved for ECDSA
   2764        20         - Elgamal (Encrypt or Sign)
   2765 
   2766 
   2767 
   2768 
   2769 
   2770        21         - Reserved for Diffie-Hellman (X9.42,
   2771                     as defined for IETF-S/MIME)
   2772        100 to 110 - Private/Experimental algorithm.
   2773 
   2774    Implementations MUST implement DSA for signatures, and Elgamal for
   2775    encryption. Implementations SHOULD implement RSA keys.
   2776    Implementations MAY implement any other algorithm.
   2777 
   2778 9.2. Symmetric Key Algorithms
   2779 
   2780        ID           Algorithm
   2781        --           ---------
   2782        0          - Plaintext or unencrypted data
   2783        1          - IDEA [IDEA]
   2784        2          - Triple-DES (DES-EDE, as per spec -
   2785                     168 bit key derived from 192)
   2786        3          - CAST5 (128 bit key, as per RFC 2144)
   2787        4          - Blowfish (128 bit key, 16 rounds) [BLOWFISH]
   2788        5          - SAFER-SK128 (13 rounds) [SAFER]
   2789        6          - Reserved for DES/SK
   2790        7          - Reserved for AES with 128-bit key
   2791 
   2792 
   2793 
   2794 Callas, et. al.             Standards Track                    [Page 49]
   2795 
   2797 RFC 2440                 OpenPGP Message Format            November 1998
   2798 
   2799 
   2800        8          - Reserved for AES with 192-bit key
   2801        9          - Reserved for AES with 256-bit key
   2802        100 to 110 - Private/Experimental algorithm.
   2803 
   2804    Implementations MUST implement Triple-DES. Implementations SHOULD
   2805    implement IDEA and CAST5.Implementations MAY implement any other
   2806    algorithm.
   2807 
   2808 9.3. Compression Algorithms
   2809 
   2810        ID           Algorithm
   2811        --           ---------
   2812        0          - Uncompressed
   2813        1          - ZIP (RFC 1951)
   2814        2          - ZLIB (RFC 1950)
   2815        100 to 110 - Private/Experimental algorithm.
   2816 
   2817    Implementations MUST implement uncompressed data. Implementations
   2818    SHOULD implement ZIP. Implementations MAY implement ZLIB.
   2819 
   2820 9.4. Hash Algorithms
   2821 
   2822        ID           Algorithm                              Text Name
   2823        --           ---------                              ---- ----
   2824        1          - MD5                                    "MD5"
   2825        2          - SHA-1                                  "SHA1"
   2826        3          - RIPE-MD/160                            "RIPEMD160"
   2827        4          - Reserved for double-width SHA (experimental)
   2828        5          - MD2                                    "MD2"
   2829        6          - Reserved for TIGER/192                 "TIGER192"
   2830        7          - Reserved for HAVAL (5 pass, 160-bit)
   2831        "HAVAL-5-160"
   2832        100 to 110 - Private/Experimental algorithm.
   2833 
   2834    Implementations MUST implement SHA-1. Implementations SHOULD
   2835    implement MD5.
   2836 
   2837 10. Packet Composition
   2838 
   2839    OpenPGP packets are assembled into sequences in order to create
   2840    messages and to transfer keys.  Not all possible packet sequences are
   2841    meaningful and correct.  This describes the rules for how packets
   2842    should be placed into sequences.
   2843 
   2844 10.1. Transferable Public Keys
   2845 
   2846    OpenPGP users may transfer public keys. The essential elements of a
   2847    transferable public key are:
   2848 
   2849 
   2850 
   2851 Callas, et. al.             Standards Track                    [Page 50]
   2852 
   2854 RFC 2440                 OpenPGP Message Format            November 1998
   2855 
   2856 
   2857      - One Public Key packet
   2858 
   2859      - Zero or more revocation signatures
   2860 
   2861      - One or more User ID packets
   2862 
   2863      - After each User ID packet, zero or more signature packets
   2864        (certifications)
   2865 
   2866      - Zero or more Subkey packets
   2867 
   2868      - After each Subkey packet, one signature packet, optionally a
   2869        revocation.
   2870 
   2871    The Public Key packet occurs first.  Each of the following User ID
   2872    packets provides the identity of the owner of this public key.  If
   2873    there are multiple User ID packets, this corresponds to multiple
   2874    means of identifying the same unique individual user; for example, a
   2875    user may have more than one email address, and construct a User ID
   2876    for each one.
   2877 
   2878    Immediately following each User ID packet, there are zero or more
   2879    signature packets. Each signature packet is calculated on the
   2880    immediately preceding User ID packet and the initial Public Key
   2881    packet. The signature serves to certify the corresponding public key
   2882    and user ID.  In effect, the signer is testifying to his or her
   2883    belief that this public key belongs to the user identified by this
   2884    user ID.
   2885 
   2886    After the User ID packets there may be one or more Subkey packets.
   2887    In general, subkeys are provided in cases where the top-level public
   2888    key is a signature-only key.  However, any V4 key may have subkeys,
   2889    and the subkeys may be encryption-only keys, signature-only keys, or
   2890    general-purpose keys.
   2891 
   2892    Each Subkey packet must be followed by one Signature packet, which
   2893    should be a subkey binding signature issued by the top level key.
   2894 
   2895    Subkey and Key packets may each be followed by a revocation Signature
   2896    packet to indicate that the key is revoked.  Revocation signatures
   2897    are only accepted if they are issued by the key itself, or by a key
   2898    that is authorized to issue revocations via a revocation key
   2899    subpacket in a self-signature by the top level key.
   2900 
   2901    Transferable public key packet sequences may be concatenated to allow
   2902    transferring multiple public keys in one operation.
   2903 
   2904 
   2905 
   2906 
   2907 
   2908 Callas, et. al.             Standards Track                    [Page 51]
   2909 
   2911 RFC 2440                 OpenPGP Message Format            November 1998
   2912 
   2913 
   2914 10.2. OpenPGP Messages
   2915 
   2916    An OpenPGP message is a packet or sequence of packets that
   2917    corresponds to the following grammatical rules (comma represents
   2918    sequential composition, and vertical bar separates alternatives):
   2919 
   2920    OpenPGP Message :- Encrypted Message | Signed Message |
   2921                       Compressed Message | Literal Message.
   2922 
   2923    Compressed Message :- Compressed Data Packet.
   2924 
   2925    Literal Message :- Literal Data Packet.
   2926 
   2927    ESK :- Public Key Encrypted Session Key Packet |
   2928           Symmetric-Key Encrypted Session Key Packet.
   2929 
   2930    ESK Sequence :- ESK | ESK Sequence, ESK.
   2931 
   2932    Encrypted Message :- Symmetrically Encrypted Data Packet |
   2933                ESK Sequence, Symmetrically Encrypted Data Packet.
   2934 
   2935    One-Pass Signed Message :- One-Pass Signature Packet,
   2936                OpenPGP Message, Corresponding Signature Packet.
   2937 
   2938    Signed Message :- Signature Packet, OpenPGP Message |
   2939                One-Pass Signed Message.
   2940 
   2941    In addition, decrypting a Symmetrically Encrypted Data packet and
   2942 
   2943    decompressing a Compressed Data packet must yield a valid OpenPGP
   2944    Message.
   2945 
   2946 10.3. Detached Signatures
   2947 
   2948    Some OpenPGP applications use so-called "detached signatures." For
   2949    example, a program bundle may contain a file, and with it a second
   2950    file that is a detached signature of the first file. These detached
   2951    signatures are simply a signature packet stored separately from the
   2952    data that they are a signature of.
   2953 
   2954 11. Enhanced Key Formats
   2955 
   2956 11.1. Key Structures
   2957 
   2958    The format of an OpenPGP V3 key is as follows.  Entries in square
   2959    brackets are optional and ellipses indicate repetition.
   2960 
   2961 
   2962 
   2963 
   2964 
   2965 Callas, et. al.             Standards Track                    [Page 52]
   2966 
   2968 RFC 2440                 OpenPGP Message Format            November 1998
   2969 
   2970 
   2971            RSA Public Key
   2972               [Revocation Self Signature]
   2973                User ID [Signature ...]
   2974               [User ID [Signature ...] ...]
   2975 
   2976    Each signature certifies the RSA public key and the preceding user
   2977    ID. The RSA public key can have many user IDs and each user ID can
   2978    have many signatures.
   2979 
   2980    The format of an OpenPGP V4 key that uses two public keys is similar
   2981    except that the other keys are added to the end as 'subkeys' of the
   2982    primary key.
   2983 
   2984            Primary-Key
   2985               [Revocation Self Signature]
   2986               [Direct Key Self Signature...]
   2987                User ID [Signature ...]
   2988               [User ID [Signature ...] ...]
   2989               [[Subkey [Binding-Signature-Revocation]
   2990                       Primary-Key-Binding-Signature] ...]
   2991 
   2992    A subkey always has a single signature after it that is issued using
   2993    the primary key to tie the two keys together.  This binding signature
   2994    may be in either V3 or V4 format, but V4 is preferred, of course.
   2995 
   2996    In the above diagram, if the binding signature of a subkey has been
   2997    revoked, the revoked binding signature may be removed, leaving only
   2998    one signature.
   2999 
   3000    In a key that has a main key and subkeys, the primary key MUST be a
   3001    key capable of signing. The subkeys may be keys of any other type.
   3002    There may be other constructions of V4 keys, too. For example, there
   3003    may be a single-key RSA key in V4 format, a DSA primary key with an
   3004    RSA encryption key, or RSA primary key with an Elgamal subkey, etc.
   3005 
   3006    It is also possible to have a signature-only subkey. This permits a
   3007    primary key that collects certifications (key signatures) but is used
   3008    only used for certifying subkeys that are used for encryption and
   3009    signatures.
   3010 
   3011 11.2. Key IDs and Fingerprints
   3012 
   3013    For a V3 key, the eight-octet key ID consists of the low 64 bits of
   3014    the public modulus of the RSA key.
   3015 
   3016    The fingerprint of a V3 key is formed by hashing the body (but not
   3017    the two-octet length) of the MPIs that form the key material (public
   3018    modulus n, followed by exponent e) with MD5.
   3019 
   3020 
   3021 
   3022 Callas, et. al.             Standards Track                    [Page 53]
   3023 
   3025 RFC 2440                 OpenPGP Message Format            November 1998
   3026 
   3027 
   3028    A V4 fingerprint is the 160-bit SHA-1 hash of the one-octet Packet
   3029    Tag, followed by the two-octet packet length, followed by the entire
   3030    Public Key packet starting with the version field.  The key ID is the
   3031    low order 64 bits of the fingerprint.  Here are the fields of the
   3032    hash material, with the example of a DSA key:
   3033 
   3034   a.1) 0x99 (1 octet)
   3035 
   3036   a.2) high order length octet of (b)-(f) (1 octet)
   3037 
   3038   a.3) low order length octet of (b)-(f) (1 octet)
   3039 
   3040     b) version number = 4 (1 octet);
   3041 
   3042     c) time stamp of key creation (4 octets);
   3043 
   3044     d) algorithm (1 octet): 17 = DSA (example);
   3045 
   3046     e) Algorithm specific fields.
   3047 
   3048    Algorithm Specific Fields for DSA keys (example):
   3049 
   3050   e.1) MPI of DSA prime p;
   3051 
   3052   e.2) MPI of DSA group order q (q is a prime divisor of p-1);
   3053 
   3054   e.3) MPI of DSA group generator g;
   3055 
   3056   e.4) MPI of DSA public key value y (= g**x where x is secret).
   3057 
   3058    Note that it is possible for there to be collisions of key IDs -- two
   3059    different keys with the same key ID. Note that there is a much
   3060    smaller, but still non-zero probability that two different keys have
   3061    the same fingerprint.
   3062 
   3063    Also note that if V3 and V4 format keys share the same RSA key
   3064    material, they will have different key ids as well as different
   3065    fingerprints.
   3066 
   3067 12. Notes on Algorithms
   3068 
   3069 12.1. Symmetric Algorithm Preferences
   3070 
   3071    The symmetric algorithm preference is an ordered list of algorithms
   3072    that the keyholder accepts. Since it is found on a self-signature, it
   3073    is possible that a keyholder may have different preferences. For
   3074    example, Alice may have TripleDES only specified for "alice (a] work.com"
   3075    but CAST5, Blowfish, and TripleDES specified for "alice (a] home.org".
   3076 
   3077 
   3078 
   3079 Callas, et. al.             Standards Track                    [Page 54]
   3080 
   3082 RFC 2440                 OpenPGP Message Format            November 1998
   3083 
   3084 
   3085    Note that it is also possible for preferences to be in a subkey's
   3086    binding signature.
   3087 
   3088    Since TripleDES is the MUST-implement algorithm, if it is not
   3089    explicitly in the list, it is tacitly at the end. However, it is good
   3090    form to place it there explicitly. Note also that if an
   3091    implementation does not implement the preference, then it is
   3092    implicitly a TripleDES-only implementation.
   3093 
   3094    An implementation MUST not use a symmetric algorithm that is not in
   3095    the recipient's preference list. When encrypting to more than one
   3096    recipient, the implementation finds a suitable algorithm by taking
   3097    the intersection of the preferences of the recipients. Note that the
   3098    MUST-implement algorithm, TripleDES, ensures that the intersection is
   3099    not null. The implementation may use any mechanism to pick an
   3100    algorithm in the intersection.
   3101 
   3102    If an implementation can decrypt a message that a keyholder doesn't
   3103    have in their preferences, the implementation SHOULD decrypt the
   3104    message anyway, but MUST warn the keyholder than protocol has been
   3105    violated. (For example, suppose that Alice, above, has software that
   3106    implements all algorithms in this specification. Nonetheless, she
   3107    prefers subsets for work or home. If she is sent a message encrypted
   3108    with IDEA, which is not in her preferences, the software warns her
   3109    that someone sent her an IDEA-encrypted message, but it would ideally
   3110    decrypt it anyway.)
   3111 
   3112    An implementation that is striving for backward compatibility MAY
   3113    consider a V3 key with a V3 self-signature to be an implicit
   3114    preference for IDEA, and no ability to do TripleDES. This is
   3115    technically non-compliant, but an implementation MAY violate the
   3116    above rule in this case only and use IDEA to encrypt the message,
   3117    provided that the message creator is warned. Ideally, though, the
   3118    implementation would follow the rule by actually generating two
   3119    messages, because it is possible that the OpenPGP user's
   3120    implementation does not have IDEA, and thus could not read the
   3121    message. Consequently, an implementation MAY, but SHOULD NOT use IDEA
   3122    in an algorithm conflict with a V3 key.
   3123 
   3124 12.2. Other Algorithm Preferences
   3125 
   3126    Other algorithm preferences work similarly to the symmetric algorithm
   3127    preference, in that they specify which algorithms the keyholder
   3128    accepts. There are two interesting cases that other comments need to
   3129    be made about, though, the compression preferences and the hash
   3130    preferences.
   3131 
   3132 
   3133 
   3134 
   3135 
   3136 Callas, et. al.             Standards Track                    [Page 55]
   3137 
   3139 RFC 2440                 OpenPGP Message Format            November 1998
   3140 
   3141 
   3142 12.2.1. Compression Preferences
   3143 
   3144    Compression has been an integral part of PGP since its first days.
   3145    OpenPGP and all previous versions of PGP have offered compression.
   3146    And in this specification, the default is for messages to be
   3147    compressed, although an implementation is not required to do so.
   3148    Consequently, the compression preference gives a way for a keyholder
   3149    to request that messages not be compressed, presumably because they
   3150    are using a minimal implementation that does not include compression.
   3151    Additionally, this gives a keyholder a way to state that it can
   3152    support alternate algorithms.
   3153 
   3154    Like the algorithm preferences, an implementation MUST NOT use an
   3155    algorithm that is not in the preference vector. If the preferences
   3156    are not present, then they are assumed to be [ZIP(1),
   3157    UNCOMPRESSED(0)].
   3158 
   3159 12.2.2. Hash Algorithm Preferences
   3160 
   3161    Typically, the choice of a hash algorithm is something the signer
   3162    does, rather than the verifier, because a signer does not typically
   3163    know who is going to be verifying the signature. This preference,
   3164    though, allows a protocol based upon digital signatures ease in
   3165    negotiation.
   3166 
   3167    Thus, if Alice is authenticating herself to Bob with a signature, it
   3168    makes sense for her to use a hash algorithm that Bob's software uses.
   3169    This preference allows Bob to state in his key which algorithms Alice
   3170    may use.
   3171 
   3172 12.3. Plaintext
   3173 
   3174    Algorithm 0, "plaintext", may only be used to denote secret keys that
   3175    are stored in the clear. Implementations must not use plaintext in
   3176    Symmetrically Encrypted Data Packets; they must use Literal Data
   3177    Packets to encode unencrypted or literal data.
   3178 
   3179 12.4. RSA
   3180 
   3181    There are algorithm types for RSA-signature-only, and RSA-encrypt-
   3182    only keys. These types are deprecated. The "key flags" subpacket in a
   3183    signature is a much better way to express the same idea, and
   3184    generalizes it to all algorithms. An implementation SHOULD NOT create
   3185    such a key, but MAY interpret it.
   3186 
   3187    An implementation SHOULD NOT implement RSA keys of size less than 768
   3188    bits.
   3189 
   3190 
   3191 
   3192 
   3193 Callas, et. al.             Standards Track                    [Page 56]
   3194 
   3196 RFC 2440                 OpenPGP Message Format            November 1998
   3197 
   3198 
   3199    It is permissible for an implementation to support RSA merely for
   3200    backward compatibility; for example, such an implementation would
   3201    support V3 keys with IDEA symmetric cryptography. Note that this is
   3202    an exception to the other MUST-implement rules. An implementation
   3203    that supports RSA in V4 keys MUST implement the MUST-implement
   3204    features.
   3205 
   3206 12.5. Elgamal
   3207 
   3208    If an Elgamal key is to be used for both signing and encryption,
   3209    extra care must be taken in creating the key.
   3210 
   3211    An ElGamal key consists of a generator g, a prime modulus p, a secret
   3212    exponent x, and a public value y = g^x mod p.
   3213 
   3214    The generator and prime must be chosen so that solving the discrete
   3215    log problem is intractable.  The group g should generate the
   3216    multiplicative group mod p-1 or a large subgroup of it, and the order
   3217    of g should have at least one large prime factor.  A good choice is
   3218    to use a "strong" Sophie-Germain prime in choosing p, so that both p
   3219    and (p-1)/2 are primes. In fact, this choice is so good that
   3220    implementors SHOULD do it, as it avoids a small subgroup attack.
   3221 
   3222    In addition, a result of Bleichenbacher [BLEICHENBACHER] shows that
   3223    if the generator g has only small prime factors, and if g divides the
   3224    order of the group it generates, then signatures can be forged.  In
   3225    particular, choosing g=2 is a bad choice if the group order may be
   3226    even. On the other hand, a generator of 2 is a fine choice for an
   3227    encryption-only key, as this will make the encryption faster.
   3228 
   3229    While verifying Elgamal signatures, note that it is important to test
   3230    that r and s are less than p.  If this test is not done then
   3231    signatures can be trivially forged by using large r values of
   3232    approximately twice the length of p.  This attack is also discussed
   3233    in the Bleichenbacher paper.
   3234 
   3235    Details on safe use of Elgamal signatures may be found in [MENEZES],
   3236    which discusses all the weaknesses described above.
   3237 
   3238    If an implementation allows Elgamal signatures, then it MUST use the
   3239    algorithm identifier 20 for an Elgamal public key that can sign.
   3240 
   3241    An implementation SHOULD NOT implement Elgamal keys of size less than
   3242    768 bits. For long-term security, Elgamal keys should be 1024 bits or
   3243    longer.
   3244 
   3245 
   3246 
   3247 
   3248 
   3249 
   3250 Callas, et. al.             Standards Track                    [Page 57]
   3251 
   3253 RFC 2440                 OpenPGP Message Format            November 1998
   3254 
   3255 
   3256 12.6. DSA
   3257 
   3258    An implementation SHOULD NOT implement DSA keys of size less than 768
   3259    bits. Note that present DSA is limited to a maximum of 1024 bit keys,
   3260    which are recommended for long-term use.
   3261 
   3262 12.7. Reserved Algorithm Numbers
   3263 
   3264    A number of algorithm IDs have been reserved for algorithms that
   3265    would be useful to use in an OpenPGP implementation, yet there are
   3266    issues that prevent an implementor from actually implementing the
   3267    algorithm. These are marked in the Public Algorithms section as
   3268    "(reserved for)".
   3269 
   3270    The reserved public key algorithms, Elliptic Curve (18), ECDSA (19),
   3271    and X9.42 (21) do not have the necessary parameters, parameter order,
   3272    or semantics defined.
   3273 
   3274    The reserved symmetric key algorithm, DES/SK (6), does not have
   3275    semantics defined.
   3276 
   3277    The reserved hash algorithms, TIGER192 (6), and HAVAL-5-160 (7), do
   3278    not have OIDs. The reserved algorithm number 4, reserved for a
   3279    double-width variant of SHA1, is not presently defined.
   3280 
   3281    We have reserver three algorithm IDs for the US NIST's Advanced
   3282    Encryption Standard. This algorithm will work with (at least) 128,
   3283    192, and 256-bit keys. We expect that this algorithm will be selected
   3284    from the candidate algorithms in the year 2000.
   3285 
   3286 12.8. OpenPGP CFB mode
   3287 
   3288    OpenPGP does symmetric encryption using a variant of Cipher Feedback
   3289    Mode (CFB mode). This section describes the procedure it uses in
   3290    detail. This mode is what is used for Symmetrically Encrypted Data
   3291    Packets; the mechanism used for encrypting secret key material is
   3292    similar, but described in those sections above.
   3293 
   3294    OpenPGP CFB mode uses an initialization vector (IV) of all zeros, and
   3295    prefixes the plaintext with ten octets of random data, such that
   3296    octets 9 and 10 match octets 7 and 8.  It does a CFB "resync" after
   3297    encrypting those ten octets.
   3298 
   3299    Note that for an algorithm that has a larger block size than 64 bits,
   3300    the equivalent function will be done with that entire block.  For
   3301    example, a 16-octet block algorithm would operate on 16 octets, and
   3302    then produce two octets of check, and then work on 16-octet blocks.
   3303 
   3304 
   3305 
   3306 
   3307 Callas, et. al.             Standards Track                    [Page 58]
   3308 
   3310 RFC 2440                 OpenPGP Message Format            November 1998
   3311 
   3312 
   3313    Step by step, here is the procedure:
   3314 
   3315    1.  The feedback register (FR) is set to the IV, which is all zeros.
   3316 
   3317    2.  FR is encrypted to produce FRE (FR Encrypted).  This is the
   3318        encryption of an all-zero value.
   3319 
   3320    3.  FRE is xored with the first 8 octets of random data prefixed to
   3321        the plaintext to produce C1-C8, the first 8 octets of ciphertext.
   3322 
   3323    4.  FR is loaded with C1-C8.
   3324 
   3325    5.  FR is encrypted to produce FRE, the encryption of the first 8
   3326        octets of ciphertext.
   3327 
   3328    6.  The left two octets of FRE get xored with the next two octets of
   3329        data that were prefixed to the plaintext.  This produces C9-C10,
   3330        the next two octets of ciphertext.
   3331 
   3332    7.  (The resync step) FR is loaded with C3-C10.
   3333 
   3334    8.  FR is encrypted to produce FRE.
   3335 
   3336    9.  FRE is xored with the first 8 octets of the given plaintext, now
   3337        that we have finished encrypting the 10 octets of prefixed data.
   3338        This produces C11-C18, the next 8 octets of ciphertext.
   3339 
   3340    10.  FR is loaded with C11-C18
   3341 
   3342    11.  FR is encrypted to produce FRE.
   3343 
   3344    12.  FRE is xored with the next 8 octets of plaintext, to produce the
   3345        next 8 octets of ciphertext.  These are loaded into FR and the
   3346        process is repeated until the plaintext is used up.
   3347 
   3348 13. Security Considerations
   3349 
   3350    As with any technology involving cryptography, you should check the
   3351    current literature to determine if any algorithms used here have been
   3352    found to be vulnerable to attack.
   3353 
   3354    This specification uses Public Key Cryptography technologies.
   3355    Possession of the private key portion of a public-private key pair is
   3356    assumed to be controlled by the proper party or parties.
   3357 
   3358    Certain operations in this specification involve the use of random
   3359    numbers.  An appropriate entropy source should be used to generate
   3360    these numbers.  See RFC 1750.
   3361 
   3362 
   3363 
   3364 Callas, et. al.             Standards Track                    [Page 59]
   3365 
   3367 RFC 2440                 OpenPGP Message Format            November 1998
   3368 
   3369 
   3370    The MD5 hash algorithm has been found to have weaknesses (pseudo-
   3371    collisions in the compress function) that make some people deprecate
   3372    its use.  They consider the SHA-1 algorithm better.
   3373 
   3374    Many security protocol designers think that it is a bad idea to use a
   3375    single key for both privacy (encryption) and integrity (signatures).
   3376    In fact, this was one of the motivating forces behind the V4 key
   3377    format with separate signature and encryption keys. If you as an
   3378    implementor promote dual-use keys, you should at least be aware of
   3379    this controversy.
   3380 
   3381    The DSA algorithm will work with any 160-bit hash, but it is
   3382    sensitive to the quality of the hash algorithm, if the hash algorithm
   3383    is broken, it can leak the secret key. The Digital Signature Standard
   3384    (DSS) specifies that DSA be used with SHA-1.  RIPEMD-160 is
   3385    considered by many cryptographers to be as strong. An implementation
   3386    should take care which hash algorithms are used with DSA, as a weak
   3387    hash can not only allow a signature to be forged, but could leak the
   3388    secret key. These same considerations about the quality of the hash
   3389    algorithm apply to Elgamal signatures.
   3390 
   3391    If you are building an authentication system, the recipient may
   3392    specify a preferred signing algorithm. However, the signer would be
   3393    foolish to use a weak algorithm simply because the recipient requests
   3394    it.
   3395 
   3396    Some of the encryption algorithms mentioned in this document have
   3397    been analyzed less than others.  For example, although CAST5 is
   3398    presently considered strong, it has been analyzed less than Triple-
   3399    DES. Other algorithms may have other controversies surrounding them.
   3400 
   3401    Some technologies mentioned here may be subject to government control
   3402    in some countries.
   3403 
   3404 14. Implementation Nits
   3405 
   3406    This section is a collection of comments to help an implementer,
   3407    particularly with an eye to backward compatibility. Previous
   3408    implementations of PGP are not OpenPGP-compliant. Often the
   3409    differences are small, but small differences are frequently more
   3410    vexing than large differences. Thus, this list of potential problems
   3411    and gotchas for a developer who is trying to be backward-compatible.
   3412 
   3413      * PGP 5.x does not accept V4 signatures for anything other than
   3414        key material.
   3415 
   3416      * PGP 5.x does not recognize the "five-octet" lengths in new-format
   3417        headers or in signature subpacket lengths.
   3418 
   3419 
   3420 
   3421 Callas, et. al.             Standards Track                    [Page 60]
   3422 
   3424 RFC 2440                 OpenPGP Message Format            November 1998
   3425 
   3426 
   3427      * PGP 5.0 rejects an encrypted session key if the keylength differs
   3428        from the S2K symmetric algorithm. This is a bug in its validation
   3429        function.
   3430 
   3431      * PGP 5.0 does not handle multiple one-pass signature headers and
   3432        trailers. Signing one will compress the one-pass signed literal
   3433        and prefix a V3 signature instead of doing a nested one-pass
   3434        signature.
   3435 
   3436      * When exporting a private key, PGP 2.x generates the header "BEGIN
   3437        PGP SECRET KEY BLOCK" instead of "BEGIN PGP PRIVATE KEY BLOCK".
   3438        All previous versions ignore the implied data type, and look
   3439        directly at the packet data type.
   3440 
   3441      * In a clear-signed signature, PGP 5.0 will figure out the correct
   3442        hash algorithm if there is no "Hash:" header, but it will reject
   3443        a mismatch between the header and the actual algorithm used. The
   3444        "standard" (i.e. Zimmermann/Finney/et al.) version of PGP 2.x
   3445        rejects the "Hash:" header and assumes MD5. There are a number of
   3446        enhanced variants of PGP 2.6.x that have been modified for SHA-1
   3447        signatures.
   3448 
   3449      * PGP 5.0 can read an RSA key in V4 format, but can only recognize
   3450        it with a V3 keyid, and can properly use only a V3 format RSA
   3451        key.
   3452 
   3453      * Neither PGP 5.x nor PGP 6.0 recognize Elgamal Encrypt and Sign
   3454        keys. They only handle Elgamal Encrypt-only keys.
   3455 
   3456      * There are many ways possible for two keys to have the same key
   3457        material, but different fingerprints (and thus key ids). Perhaps
   3458        the most interesting is an RSA key that has been "upgraded" to V4
   3459        format, but since a V4 fingerprint is constructed by hashing the
   3460        key creation time along with other things, two V4 keys created at
   3461        different times, yet with the same key material will have
   3462        different fingerprints.
   3463 
   3464      * If an implementation is using zlib to interoperate with PGP 2.x,
   3465        then the "windowBits" parameter should be set to -13.
   3466 
   3467 
   3468 
   3469 
   3470 
   3471 
   3472 
   3473 
   3474 
   3475 
   3476 
   3477 
   3478 Callas, et. al.             Standards Track                    [Page 61]
   3479 
   3481 RFC 2440                 OpenPGP Message Format            November 1998
   3482 
   3483 
   3484 15. Authors and Working Group Chair
   3485 
   3486    The working group can be contacted via the current chair:
   3487 
   3488    John W. Noerenberg, II
   3489    Qualcomm, Inc
   3490    6455 Lusk Blvd
   3491    San Diego, CA 92131 USA
   3492 
   3493    Phone: +1 619-658-3510
   3494    EMail: jwn2 (a] qualcomm.com
   3495 
   3496 
   3497    The principal authors of this memo are:
   3498 
   3499    Jon Callas
   3500    Network Associates, Inc.
   3501    3965 Freedom Circle
   3502    Santa Clara, CA 95054, USA
   3503 
   3504    Phone: +1 408-346-5860
   3505    EMail: jon (a] pgp.com, jcallas (a] nai.com
   3506 
   3507 
   3508    Lutz Donnerhacke
   3509    IKS GmbH
   3510    Wildenbruchstr. 15
   3511    07745 Jena, Germany
   3512 
   3513    Phone: +49-3641-675642
   3514    EMail: lutz (a] iks-jena.de
   3515 
   3516 
   3517    Hal Finney
   3518    Network Associates, Inc.
   3519    3965 Freedom Circle
   3520    Santa Clara, CA 95054, USA
   3521 
   3522    EMail: hal (a] pgp.com
   3523 
   3524 
   3525    Rodney Thayer
   3526    EIS Corporation
   3527    Clearwater, FL 33767, USA
   3528 
   3529    EMail: rodney (a] unitran.com
   3530 
   3531 
   3532 
   3533 
   3534 
   3535 Callas, et. al.             Standards Track                    [Page 62]
   3536 
   3538 RFC 2440                 OpenPGP Message Format            November 1998
   3539 
   3540 
   3541    This memo also draws on much previous work from a number of other
   3542    authors who include: Derek Atkins, Charles Breed, Dave Del Torto,
   3543    Marc Dyksterhouse, Gail Haspert, Gene Hoffman, Paul Hoffman, Raph
   3544    Levien, Colin Plumb, Will Price, William Stallings, Mark Weaver, and
   3545    Philip R. Zimmermann.
   3546 
   3547 16. References
   3548 
   3549    [BLEICHENBACHER] Bleichenbacher, Daniel, "Generating ElGamal
   3550                     signatures without knowing the secret key,"
   3551                     Eurocrypt 96.  Note that the version in the
   3552                     proceedings has an error.  A revised version is
   3553                     available at the time of writing from
   3554                     <ftp://ftp.inf.ethz.ch/pub/publications/papers/ti/isc
   3555                     /ElGamal.ps>
   3556 
   3557    [BLOWFISH]       Schneier, B. "Description of a New Variable-Length
   3558                     Key, 64-Bit Block Cipher (Blowfish)" Fast Software
   3559                     Encryption, Cambridge Security Workshop Proceedings
   3560                     (December 1993), Springer-Verlag, 1994, pp191-204
   3561 
   3562                     <http://www.counterpane.com/bfsverlag.html>
   3563 
   3564    [DONNERHACKE]    Donnerhacke, L., et. al, "PGP263in - an improved
   3565                     international version of PGP", ftp://ftp.iks-
   3566                     jena.de/mitarb/lutz/crypt/software/pgp/
   3567 
   3568    [ELGAMAL]        T. ElGamal, "A Public-Key Cryptosystem and a
   3569                     Signature Scheme Based on Discrete Logarithms," IEEE
   3570                     Transactions on Information Theory, v. IT-31, n. 4,
   3571                     1985, pp. 469-472.
   3572 
   3573    [IDEA]           Lai, X, "On the design and security of block
   3574                     ciphers", ETH Series in Information Processing, J.L.
   3575                     Massey (editor), Vol. 1, Hartung-Gorre Verlag
   3576                     Knostanz, Technische Hochschule (Zurich), 1992
   3577 
   3578    [ISO-10646]      ISO/IEC 10646-1:1993. International Standard --
   3579                     Information technology -- Universal Multiple-Octet
   3580                     Coded Character Set (UCS) -- Part 1: Architecture
   3581                     and Basic Multilingual Plane.  UTF-8 is described in
   3582                     Annex R, adopted but not yet published.  UTF-16 is
   3583                     described in Annex Q, adopted but not yet published.
   3584 
   3585    [MENEZES]        Alfred Menezes, Paul van Oorschot, and Scott
   3586                     Vanstone, "Handbook of Applied Cryptography," CRC
   3587                     Press, 1996.
   3588 
   3589 
   3590 
   3591 
   3592 Callas, et. al.             Standards Track                    [Page 63]
   3593 
   3595 RFC 2440                 OpenPGP Message Format            November 1998
   3596 
   3597 
   3598    [RFC822]         Crocker, D., "Standard for the format of ARPA
   3599                     Internet text messages", STD 11, RFC 822, August
   3600                     1982.
   3601 
   3602    [RFC1423]        Balenson, D., "Privacy Enhancement for Internet
   3603                     Electronic Mail: Part III: Algorithms, Modes, and
   3604                     Identifiers", RFC 1423, October 1993.
   3605 
   3606    [RFC1641]        Goldsmith, D. and M. Davis, "Using Unicode with
   3607                     MIME", RFC 1641, July 1994.
   3608 
   3609    [RFC1750]        Eastlake, D., Crocker, S. and J. Schiller,
   3610                     "Randomness Recommendations for Security", RFC 1750,
   3611                     December 1994.
   3612 
   3613    [RFC1951]        Deutsch, P., "DEFLATE Compressed Data Format
   3614                     Specification version 1.3.", RFC 1951, May 1996.
   3615 
   3616    [RFC1983]        Malkin, G., "Internet Users' Glossary", FYI 18, RFC
   3617                     1983, August 1996.
   3618 
   3619    [RFC1991]        Atkins, D., Stallings, W. and P. Zimmermann, "PGP
   3620                     Message Exchange Formats", RFC 1991, August 1996.
   3621 
   3622    [RFC2015]        Elkins, M., "MIME Security with Pretty Good Privacy
   3623                     (PGP)", RFC 2015, October 1996.
   3624 
   3625    [RFC2231]        Borenstein, N. and N. Freed, "Multipurpose Internet
   3626                     Mail Extensions (MIME) Part One: Format of Internet
   3627                     Message Bodies.", RFC 2231, November 1996.
   3628 
   3629    [RFC2119]        Bradner, S., "Key words for use in RFCs to Indicate
   3630                     Requirement Level", BCP 14, RFC 2119, March 1997.
   3631 
   3632    [RFC2144]        Adams, C., "The CAST-128 Encryption Algorithm", RFC
   3633                     2144, May 1997.
   3634 
   3635    [RFC2279]        Yergeau., F., "UTF-8, a transformation format of
   3636                     Unicode and ISO 10646", RFC 2279, January 1998.
   3637 
   3638    [RFC2313]        Kaliski, B., "PKCS #1: RSA Encryption Standard
   3639                     version 1.5", RFC 2313, March 1998.
   3640 
   3641    [SAFER]          Massey, J.L. "SAFER K-64: One Year Later", B.
   3642                     Preneel, editor, Fast Software Encryption, Second
   3643                     International Workshop (LNCS 1008) pp212-241,
   3644                     Springer-Verlag 1995
   3645 
   3646 
   3647 
   3648 
   3649 Callas, et. al.             Standards Track                    [Page 64]
   3650 
   3652 RFC 2440                 OpenPGP Message Format            November 1998
   3653 
   3654 
   3655 17.  Full Copyright Statement
   3656 
   3657    Copyright (C) The Internet Society (1998).  All Rights Reserved.
   3658 
   3659    This document and translations of it may be copied and furnished to
   3660    others, and derivative works that comment on or otherwise explain it
   3661    or assist in its implementation may be prepared, copied, published
   3662    and distributed, in whole or in part, without restriction of any
   3663    kind, provided that the above copyright notice and this paragraph are
   3664    included on all such copies and derivative works.  However, this
   3665    document itself may not be modified in any way, such as by removing
   3666    the copyright notice or references to the Internet Society or other
   3667    Internet organizations, except as needed for the purpose of
   3668    developing Internet standards in which case the procedures for
   3669    copyrights defined in the Internet Standards process must be
   3670    followed, or as required to translate it into languages other than
   3671    English.
   3672 
   3673    The limited permissions granted above are perpetual and will not be
   3674    revoked by the Internet Society or its successors or assigns.
   3675 
   3676    This document and the information contained herein is provided on an
   3677    "AS IS" basis and THE INTERNET SOCIETY AND THE INTERNET ENGINEERING
   3678    TASK FORCE DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
   3679    BUT NOT LIMITED TO ANY WARRANTY THAT THE USE OF THE INFORMATION
   3680    HEREIN WILL NOT INFRINGE ANY RIGHTS OR ANY IMPLIED WARRANTIES OF
   3681    MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
   3682 
   3683 
   3684 
   3685 
   3686 
   3687 
   3688 
   3689 
   3690 
   3691 
   3692 
   3693 
   3694 
   3695 
   3696 
   3697 
   3698 
   3699 
   3700 
   3701 
   3702 
   3703 
   3704 
   3705 
   3706 Callas, et. al.             Standards Track                    [Page 65]
   3707 
   3709