limit the scope of trust that is extended. Only signatures by the
target key on user IDs that match the regular expression in the body
of this packet have trust extended by the trust signature subpacket.
The regular expression uses the same syntax as the Henry Spencer's
"almost public domain" regular expression package. A description of
the syntax is found in a section below.
5.2.3.14. Revocation key
(1 octet of class, 1 octet of algid, 20 octets of fingerprint)
Authorizes the specified key to issue revocation signatures for this
key. Class octet must have bit 0x80 set. If the bit 0x40 is set,
then this means that the revocation information is sensitive. Other
bits are for future expansion to other kinds of authorizations. This
is found on a self-signature.
If the "sensitive" flag is set, the keyholder feels this subpacket
contains private trust information that describes a real-world
sensitive relationship. If this flag is set, implementations SHOULD
NOT export this signature to other users except in cases where the
data needs to be available: when the signature is being sent to the
designated revoker, or when it is accompanied by a revocation
signature from that revoker. Note that it may be appropriate to
isolate this subpacket within a separate signature so that it is not
combined with other subpackets that need to be exported.
5.2.3.15. Notation Data
(4 octets of flags, 2 octets of name length (M),
2 octets of value length (N),
M octets of name data,
N octets of value data)
This subpacket describes a "notation" on the signature that the
issuer wishes to make. The notation has a name and a value, each of
which are strings of octets. There may be more than one notation in a
signature. Notations can be used for any extension the issuer of the
signature cares to make. The "flags" field holds four octets of
flags.
All undefined flags MUST be zero. Defined flags are:
First octet: 0x80 = human-readable. This note is text, a note
from one person to another, and has no
meaning to software.
Other octets: none.
5.2.3.16. Key server preferences
(N octets of flags)
This is a list of flags that indicate preferences that the key holder
has about how the key is handled on a key server. All undefined flags
MUST be zero.
First octet: 0x80 = No-modify
the key holder requests that this key only be modified or updated
by the key holder or an administrator of the key server.
This is found only on a self-signature.
5.2.3.17. Preferred key server
(String)
This is a URL of a key server that the key holder prefers be used for
updates. Note that keys with multiple user ids can have a preferred
key server for each user id. Note also that since this is a URL, the
key server can actually be a copy of the key retrieved by ftp, http,
finger, etc.
5.2.3.18. Primary user id
(1 octet, boolean)
This is a flag in a user id's self signature that states whether this
user id is the main user id for this key. It is reasonable for an
implementation to resolve ambiguities in preferences, etc. by
referring to the primary user id. If this flag is absent, its value
is zero. If more than one user id in a key is marked as primary, the
implementation may resolve the ambiguity in any way it sees fit.
5.2.3.19. Policy URL
(String)
This subpacket contains a URL of a document that describes the policy
that the signature was issued under.
5.2.3.20. Key Flags
(Octet string)
This subpacket contains a list of binary flags that hold information
about a key. It is a string of octets, and an implementation MUST NOT
assume a fixed size. This is so it can grow over time. If a list is
shorter than an implementation expects, the unstated flags are
considered to be zero. The defined flags are:
First octet:
0x01 - This key may be used to certify other keys.
0x02 - This key may be used to sign data.
0x04 - This key may be used to encrypt communications.
0x08 - This key may be used to encrypt storage.
0x10 - The private component of this key may have been split by a
secret-sharing mechanism.
0x80 - The private component of this key may be in the possession
of more than one person.
Usage notes:
The flags in this packet may appear in self-signatures or in
certification signatures. They mean different things depending on who
is making the statement -- for example, a certification signature
that has the "sign data" flag is stating that the certification is
for that use. On the other hand, the "communications encryption" flag
in a self-signature is stating a preference that a given key be used
for communications. Note however, that it is a thorny issue to
determine what is "communications" and what is "storage." This
decision is left wholly up to the implementation; the authors of this
document do not claim any special wisdom on the issue, and realize
that accepted opinion may change.
The "split key" (0x10) and "group key" (0x80) flags are placed on a
self-signature only; they are meaningless on a certification
signature. They SHOULD be placed only on a direct-key signature (type
0x1f) or a subkey signature (type 0x18), one that refers to the key
the flag applies to.
5.2.3.21. Signer's User ID
This subpacket allows a keyholder to state which user id is
responsible for the signing. Many keyholders use a single key for
different purposes, such as business communications as well as
personal communications. This subpacket allows such a keyholder to
state which of their roles is making a signature.
5.2.3.22. Reason for Revocation
(1 octet of revocation code, N octets of reason string)
This subpacket is used only in key revocation and certification
revocation signatures. It describes the reason why the key or
certificate was revoked.
The first octet contains a machine-readable code that denotes the
reason for the revocation:
0x00 - No reason specified (key revocations or cert revocations)
0x01 - Key is superceded (key revocations)
0x02 - Key material has been compromised (key revocations)
0x03 - Key is no longer used (key revocations)
0x20 - User id information is no longer valid (cert revocations)
Following the revocation code is a string of octets which gives
information about the reason for revocation in human-readable form
(UTF-8). The string may be null, that is, of zero length. The length
of the subpacket is the length of the reason string plus one.
5.2.4. Computing Signatures
All signatures are formed by producing a hash over the signature
data, and then using the resulting hash in the signature algorithm.
The signature data is simple to compute for document signatures
(types 0x00 and 0x01), for which the document itself is the data.
For standalone signatures, this is a null string.
When a signature is made over a key, the hash data starts with the
octet 0x99, followed by a two-octet length of the key, and then body
of the key packet. (Note that this is an old-style packet header for
a key packet with two-octet length.) A subkey signature (type 0x18)
then hashes the subkey, using the same format as the main key. Key
revocation signatures (types 0x20 and 0x28) hash only the key being
revoked.
A certification signature (type 0x10 through 0x13) hashes the user id
being bound to the key into the hash context after the above data. A
V3 certification hashes the contents of the name packet, without any
header. A V4 certification hashes the constant 0xb4 (which is an
old-style packet header with the length-of-length set to zero), a
four-octet number giving the length of the username, and then the
username data.
Once the data body is hashed, then a trailer is hashed. A V3
signature hashes five octets of the packet body, starting from the
signature type field. This data is the signature type, followed by
the four-octet signature time. A V4 signature hashes the packet body
starting from its first field, the version number, through the end of
the hashed subpacket data. Thus, the fields hashed are the signature
version, the signature type, the public key algorithm, the hash
algorithm, the hashed subpacket length, and the hashed subpacket
body.
V4 signatures also hash in a final trailer of six octets: the version
of the signature packet, i.e. 0x04; 0xFF; a four-octet, big-endian
number that is the length of the hashed data from the signature
packet (note that this number does not include these final six
octets.
After all this has been hashed, the resulting hash field is used in
the signature algorithm, and placed at the end of the signature
packet.
5.2.4.1. Subpacket Hints
An implementation SHOULD put the two mandatory subpackets, creation
time and issuer, as the first subpackets in the subpacket list,
simply to make it easier for the implementer to find them.
It is certainly possible for a signature to contain conflicting
information in subpackets. For example, a signature may contain
multiple copies of a preference or multiple expiration times. In most
cases, an implementation SHOULD use the last subpacket in the
signature, but MAY use any conflict resolution scheme that makes more
sense. Please note that we are intentionally leaving conflict
resolution to the implementer; most conflicts are simply syntax
errors, and the wishy-washy language here allows a receiver to be
generous in what they accept, while putting pressure on a creator to
be stingy in what they generate.
Some apparent conflicts may actually make sense -- for example,
suppose a keyholder has an V3 key and a V4 key that share the same
RSA key material. Either of these keys can verify a signature created
by the other, and it may be reasonable for a signature to contain an
issuer subpacket for each key, as a way of explicitly tying those
keys to the signature.
5.3. Symmetric-Key Encrypted Session-Key Packets (Tag 3)
The Symmetric-Key Encrypted Session Key packet holds the symmetric-
key encryption of a session key used to encrypt a message. Zero or
more Encrypted Session Key packets and/or Symmetric-Key Encrypted
Session Key packets may precede a Symmetrically Encrypted Data Packet
that holds an encrypted message. The message is encrypted with a
session key, and the session key is itself encrypted and stored in
the Encrypted Session Key packet or the Symmetric-Key Encrypted
Session Key packet.
If the Symmetrically Encrypted Data Packet is preceded by one or more
Symmetric-Key Encrypted Session Key packets, each specifies a
passphrase that may be used to decrypt the message. This allows a
message to be encrypted to a number of public keys, and also to one
or more pass phrases. This packet type is new, and is not generated
by PGP 2.x or PGP 5.0.
The body of this packet consists of:
- A one-octet version number. The only currently defined version
is 4.
- A one-octet number describing the symmetric algorithm used.
- A string-to-key (S2K) specifier, length as defined above.
- Optionally, the encrypted session key itself, which is decrypted
with the string-to-key object.
If the encrypted session key is not present (which can be detected on
the basis of packet length and S2K specifier size), then the S2K
algorithm applied to the passphrase produces the session key for
decrypting the file, using the symmetric cipher algorithm from the
Symmetric-Key Encrypted Session Key packet.
If the encrypted session key is present, the result of applying the
S2K algorithm to the passphrase is used to decrypt just that
encrypted session key field, using CFB mode with an IV of all zeros.
The decryption result consists of a one-octet algorithm identifier
that specifies the symmetric-key encryption algorithm used to encrypt
the following Symmetrically Encrypted Data Packet, followed by the
session key octets themselves.
Note: because an all-zero IV is used for this decryption, the S2K
specifier MUST use a salt value, either a Salted S2K or an Iterated-
Salted S2K. The salt value will insure that the decryption key is
not repeated even if the passphrase is reused.
5.4. One-Pass Signature Packets (Tag 4)
The One-Pass Signature packet precedes the signed data and contains
enough information to allow the receiver to begin calculating any
hashes needed to verify the signature. It allows the Signature
Packet to be placed at the end of the message, so that the signer can
compute the entire signed message in one pass.
A One-Pass Signature does not interoperate with PGP 2.6.x or earlier.
The body of this packet consists of:
- A one-octet version number. The current version is 3.
- A one-octet signature type. Signature types are described in
section 5.2.1.
- A one-octet number describing the hash algorithm used.
- A one-octet number describing the public key algorithm used.
- An eight-octet number holding the key ID of the signing key.
- A one-octet number holding a flag showing whether the signature
is nested. A zero value indicates that the next packet is
another One-Pass Signature packet that describes another
signature to be applied to the same message data.
Note that if a message contains more than one one-pass signature,
then the signature packets bracket the message; that is, the first
signature packet after the message corresponds to the last one-pass
packet and the final signature packet corresponds to the first one-
pass packet.
5.5. Key Material Packet
A key material packet contains all the information about a public or
private key. There are four variants of this packet type, and two
major versions. Consequently, this section is complex.
5.5.1. Key Packet Variants
5.5.1.1. Public Key Packet (Tag 6)
A Public Key packet starts a series of packets that forms an OpenPGP
key (sometimes called an OpenPGP certificate).
5.5.1.2. Public Subkey Packet (Tag 14)
A Public Subkey packet (tag 14) has exactly the same format as a
Public Key packet, but denotes a subkey. One or more subkeys may be
associated with a top-level key. By convention, the top-level key
provides signature services, and the subkeys provide encryption
services.
Note: in PGP 2.6.x, tag 14 was intended to indicate a comment packet.
This tag was selected for reuse because no previous version of PGP
ever emitted comment packets but they did properly ignore them.
Public Subkey packets are ignored by PGP 2.6.x and do not cause it to
fail, providing a limited degree of backward compatibility.
5.5.1.3. Secret Key Packet (Tag 5)
A Secret Key packet contains all the information that is found in a
Public Key packet, including the public key material, but also
includes the secret key material after all the public key fields.
5.5.1.4. Secret Subkey Packet (Tag 7)
A Secret Subkey packet (tag 7) is the subkey analog of the Secret Key
packet, and has exactly the same format.
5.5.2. Public Key Packet Formats
There are two versions of key-material packets. Version 3 packets
were first generated by PGP 2.6. Version 2 packets are identical in
format to Version 3 packets, but are generated by PGP 2.5 or before.
V2 packets are deprecated and they MUST NOT be generated. PGP 5.0
introduced version 4 packets, with new fields and semantics. PGP
2.6.x will not accept key-material packets with versions greater than
3.
OpenPGP implementations SHOULD create keys with version 4 format. An
implementation MAY generate a V3 key to ensure interoperability with
old software; note, however, that V4 keys correct some security
deficiencies in V3 keys. These deficiencies are described below. An
implementation MUST NOT create a V3 key with a public key algorithm
other than RSA.
A version 3 public key or public subkey packet contains:
- A one-octet version number (3).
- A four-octet number denoting the time that the key was created.
- A two-octet number denoting the time in days that this key is
valid. If this number is zero, then it does not expire.
- A one-octet number denoting the public key algorithm of this key
- A series of multi-precision integers comprising the key
material:
- a multiprecision integer (MPI) of RSA public modulus n;
- an MPI of RSA public encryption exponent e.
V3 keys SHOULD only be used for backward compatibility because of
three weaknesses in them. First, it is relatively easy to construct a
V3 key that has the same key ID as any other key because the key ID
is simply the low 64 bits of the public modulus. Secondly, because
the fingerprint of a V3 key hashes the key material, but not its
length, which increases the opportunity for fingerprint collisions.
Third, there are minor weaknesses in the MD5 hash algorithm that make
developers prefer other algorithms. See below for a fuller discussion
of key IDs and fingerprints.
The version 4 format is similar to the version 3 format except for
the absence of a validity period. This has been moved to the
signature packet. In addition, fingerprints of version 4 keys are
calculated differently from version 3 keys, as described in section
"Enhanced Key Formats."
A version 4 packet contains:
- A one-octet version number (4).
- A four-octet number denoting the time that the key was created.
- A one-octet number denoting the public key algorithm of this key
- A series of multi-precision integers comprising the key
material. This algorithm-specific portion is:
Algorithm Specific Fields for RSA public keys:
- multiprecision integer (MPI) of RSA public modulus n;
- MPI of RSA public encryption exponent e.
Algorithm Specific Fields for DSA public keys:
- MPI of DSA prime p;
- MPI of DSA group order q (q is a prime divisor of p-1);
- MPI of DSA group generator g;
- MPI of DSA public key value y (= g**x where x is secret).
Algorithm Specific Fields for Elgamal public keys:
- MPI of Elgamal prime p;
- MPI of Elgamal group generator g;
- MPI of Elgamal public key value y (= g**x where x is
secret).
5.5.3. Secret Key Packet Formats
The Secret Key and Secret Subkey packets contain all the data of the
Public Key and Public Subkey packets, with additional algorithm-
specific secret key data appended, in encrypted form.
The packet contains:
- A Public Key or Public Subkey packet, as described above
- One octet indicating string-to-key usage conventions. 0
indicates that the secret key data is not encrypted. 255
indicates that a string-to-key specifier is being given. Any
other value is a symmetric-key encryption algorithm specifier.
- [Optional] If string-to-key usage octet was 255, a one-octet
symmetric encryption algorithm.
- [Optional] If string-to-key usage octet was 255, a string-to-key
specifier. The length of the string-to-key specifier is implied
by its type, as described above.
- [Optional] If secret data is encrypted, eight-octet Initial
Vector (IV).
- Encrypted multi-precision integers comprising the secret key
data. These algorithm-specific fields are as described below.
- Two-octet checksum of the plaintext of the algorithm-specific
portion (sum of all octets, mod 65536).
Algorithm Specific Fields for RSA secret keys:
- multiprecision integer (MPI) of RSA secret exponent d.
- MPI of RSA secret prime value p.
- MPI of RSA secret prime value q (p < q).
- MPI of u, the multiplicative inverse of p, mod q.
Algorithm Specific Fields for DSA secret keys:
- MPI of DSA secret exponent x.
Algorithm Specific Fields for Elgamal secret keys:
- MPI of Elgamal secret exponent x.
Secret MPI values can be encrypted using a passphrase. If a string-
to-key specifier is given, that describes the algorithm for
converting the passphrase to a key, else a simple MD5 hash of the
passphrase is used. Implementations SHOULD use a string-to-key
specifier; the simple hash is for backward compatibility. The cipher
for encrypting the MPIs is specified in the secret key packet.
Encryption/decryption of the secret data is done in CFB mode using
the key created from the passphrase and the Initial Vector from the
packet. A different mode is used with V3 keys (which are only RSA)
than with other key formats. With V3 keys, the MPI bit count prefix
(i.e., the first two octets) is not encrypted. Only the MPI non-
prefix data is encrypted. Furthermore, the CFB state is
resynchronized at the beginning of each new MPI value, so that the
CFB block boundary is aligned with the start of the MPI data.
With V4 keys, a simpler method is used. All secret MPI values are
encrypted in CFB mode, including the MPI bitcount prefix.
The 16-bit checksum that follows the algorithm-specific portion is
the algebraic sum, mod 65536, of the plaintext of all the algorithm-
specific octets (including MPI prefix and data). With V3 keys, the
checksum is stored in the clear. With V4 keys, the checksum is
encrypted like the algorithm-specific data. This value is used to
check that the passphrase was correct.
5.6. Compressed Data Packet (Tag 8)
The Compressed Data packet contains compressed data. Typically, this
packet is found as the contents of an encrypted packet, or following
a Signature or One-Pass Signature packet, and contains literal data
packets.
The body of this packet consists of:
- One octet that gives the algorithm used to compress the packet.
- The remainder of the packet is compressed data.
A Compressed Data Packet's body contains an block that compresses
some set of packets. See section "Packet Composition" for details on
how messages are formed.
ZIP-compressed packets are compressed with raw RFC1951 DEFLATE
blocks. Note that PGP V2.6 uses 13 bits of compression. If an
implementation uses more bits of compression, PGP V2.6 cannot
decompress it.
ZLIB-compressed packets are compressed with RFC1950 ZLIB-style
blocks.
5.7. Symmetrically Encrypted Data Packet (Tag 9)
The Symmetrically Encrypted Data packet contains data encrypted with
a symmetric-key algorithm. When it has been decrypted, it will
typically contain other packets (often literal data packets or
compressed data packets).
The body of this packet consists of:
- Encrypted data, the output of the selected symmetric-key cipher
operating in PGP's variant of Cipher Feedback (CFB) mode.
The symmetric cipher used may be specified in an Public-Key or
Symmetric-Key Encrypted Session Key packet that precedes the
Symmetrically Encrypted Data Packet. In that case, the cipher
algorithm octet is prefixed to the session key before it is
encrypted. If no packets of these types precede the encrypted data,
the IDEA algorithm is used with the session key calculated as the MD5
hash of the passphrase.
The data is encrypted in CFB mode, with a CFB shift size equal to the
cipher's block size. The Initial Vector (IV) is specified as all
zeros. Instead of using an IV, OpenPGP prefixes a 10-octet string to
the data before it is encrypted. The first eight octets are random,
and the 9th and 10th octets are copies of the 7th and 8th octets,
respectively. After encrypting the first 10 octets, the CFB state is
resynchronized if the cipher block size is 8 octets or less. The
last 8 octets of ciphertext are passed through the cipher and the
block boundary is reset.
The repetition of 16 bits in the 80 bits of random data prefixed to
the message allows the receiver to immediately check whether the
session key is incorrect.
5.8. Marker Packet (Obsolete Literal Packet) (Tag 10)
An experimental version of PGP used this packet as the Literal
packet, but no released version of PGP generated Literal packets with
this tag. With PGP 5.x, this packet has been re-assigned and is
reserved for use as the Marker packet.
The body of this packet consists of:
- The three octets 0x50, 0x47, 0x50 (which spell "PGP" in UTF-8).
Such a packet MUST be ignored when received. It may be placed at the
beginning of a message that uses features not available in PGP 2.6.x
in order to cause that version to report that newer software is
necessary to process the message.
5.9. Literal Data Packet (Tag 11)
A Literal Data packet contains the body of a message; data that is
not to be further interpreted.
The body of this packet consists of:
- A one-octet field that describes how the data is formatted.
If it is a 'b' (0x62), then the literal packet contains binary data.
If it is a 't' (0x74), then it contains text data, and thus may need
line ends converted to local form, or other text-mode changes. RFC
1991 also defined a value of 'l' as a 'local' mode for machine-local
conversions. This use is now deprecated.
- File name as a string (one-octet length, followed by file name),
if the encrypted data should be saved as a file.
If the special name "_CONSOLE" is used, the message is considered to
be "for your eyes only". This advises that the message data is
unusually sensitive, and the receiving program should process it more
carefully, perhaps avoiding storing the received data to disk, for
example.
- A four-octet number that indicates the modification date of the
file, or the creation time of the packet, or a zero that
indicates the present time.
- The remainder of the packet is literal data.
Text data is stored with <CR><LF> text endings (i.e. network-normal
line endings). These should be converted to native line endings by
the receiving software.
5.10. Trust Packet (Tag 12)
The Trust packet is used only within keyrings and is not normally
exported. Trust packets contain data that record the user's
specifications of which key holders are trustworthy introducers,
along with other information that implementing software uses for
trust information.
Trust packets SHOULD NOT be emitted to output streams that are
transferred to other users, and they SHOULD be ignored on any input
other than local keyring files.
5.11. User ID Packet (Tag 13)
A User ID packet consists of data that is intended to represent the
name and email address of the key holder. By convention, it includes
an RFC822 mail name, but there are no restrictions on its content.
The packet length in the header specifies the length of the user id.
If it is text, it is encoded in UTF-8.
6. Radix-64 Conversions
As stated in the introduction, OpenPGP's underlying native
representation for objects is a stream of arbitrary octets, and some
systems desire these objects to be immune to damage caused by
character set translation, data conversions, etc.
In principle, any printable encoding scheme that met the requirements
of the unsafe channel would suffice, since it would not change the
underlying binary bit streams of the native OpenPGP data structures.
The OpenPGP standard specifies one such printable encoding scheme to
ensure interoperability.
OpenPGP's Radix-64 encoding is composed of two parts: a base64
encoding of the binary data, and a checksum. The base64 encoding is
identical to the MIME base64 content-transfer-encoding [RFC2231,
Section 6.8]. An OpenPGP implementation MAY use ASCII Armor to
protect the raw binary data.
The checksum is a 24-bit CRC converted to four characters of radix-64
encoding by the same MIME base64 transformation, preceded by an
equals sign (=). The CRC is computed by using the generator 0x864CFB
and an initialization of 0xB704CE. The accumulation is done on the
data before it is converted to radix-64, rather than on the converted
data. A sample implementation of this algorithm is in the next
section.
The checksum with its leading equal sign MAY appear on the first line
after the Base64 encoded data.
Rationale for CRC-24: The size of 24 bits fits evenly into printable
base64. The nonzero initialization can detect more errors than a
zero initialization.
6.1. An Implementation of the CRC-24 in "C"
#define CRC24_INIT 0xb704ceL
#define CRC24_POLY 0x1864cfbL
typedef long crc24;
crc24 crc_octets(unsigned char *octets, size_t len)
{
crc24 crc = CRC24_INIT;
int i;
while (len--) {
crc ^= (*octets++) << 16;
for (i = 0; i < 8; i++) {
crc <<= 1;
if (crc & 0x1000000)
crc ^= CRC24_POLY;
}
}
return crc & 0xffffffL;
}
6.2. Forming ASCII Armor
When OpenPGP encodes data into ASCII Armor, it puts specific headers
around the data, so OpenPGP can reconstruct the data later. OpenPGP
informs the user what kind of data is encoded in the ASCII armor
through the use of the headers.
Concatenating the following data creates ASCII Armor:
- An Armor Header Line, appropriate for the type of data
- Armor Headers
- A blank (zero-length, or containing only whitespace) line
- The ASCII-Armored data
- An Armor Checksum
- The Armor Tail, which depends on the Armor Header Line.
An Armor Header Line consists of the appropriate header line text
surrounded by five (5) dashes ('-', 0x2D) on either side of the
header line text. The header line text is chosen based upon the type
of data that is being encoded in Armor, and how it is being encoded.
Header line texts include the following strings:
BEGIN PGP MESSAGE
Used for signed, encrypted, or compressed files.
BEGIN PGP PUBLIC KEY BLOCK
Used for armoring public keys
BEGIN PGP PRIVATE KEY BLOCK
Used for armoring private keys
BEGIN PGP MESSAGE, PART X/Y
Used for multi-part messages, where the armor is split amongst Y
parts, and this is the Xth part out of Y.
BEGIN PGP MESSAGE, PART X
Used for multi-part messages, where this is the Xth part of an
unspecified number of parts. Requires the MESSAGE-ID Armor Header
to be used.
BEGIN PGP SIGNATURE
Used for detached signatures, OpenPGP/MIME signatures, and
natures following clearsigned messages. Note that PGP 2.x s BEGIN
PGP MESSAGE for detached signatures.
The Armor Headers are pairs of strings that can give the user or the
receiving OpenPGP implementation some information about how to decode
or use the message. The Armor Headers are a part of the armor, not a
part of the message, and hence are not protected by any signatures
applied to the message.
The format of an Armor Header is that of a key-value pair. A colon
(':' 0x38) and a single space (0x20) separate the key and value.
OpenPGP should consider improperly formatted Armor Headers to be
corruption of the ASCII Armor. Unknown keys should be reported to
the user, but OpenPGP should continue to process the message.
Currently defined Armor Header Keys are:
- "Version", that states the OpenPGP Version used to encode the
message.
- "Comment", a user-defined comment.
- "MessageID", a 32-character string of printable characters. The
string must be the same for all parts of a multi-part message
that uses the "PART X" Armor Header. MessageID strings should be
unique enough that the recipient of the mail can associate all
the parts of a message with each other. A good checksum or
cryptographic hash function is sufficient.
- "Hash", a comma-separated list of hash algorithms used in this
message. This is used only in clear-signed messages.
- "Charset", a description of the character set that the plaintext
is in. Please note that OpenPGP defines text to be in UTF-8 by
default. An implementation will get best results by translating
into and out of UTF-8. However, there are many instances where
this is easier said than done. Also, there are communities of
users who have no need for UTF-8 because they are all happy with
a character set like ISO Latin-5 or a Japanese character set. In
such instances, an implementation MAY override the UTF-8 default
by using this header key. An implementation MAY implement this
key and any translations it cares to; an implementation MAY
ignore it and assume all text is UTF-8.
The MessageID SHOULD NOT appear unless it is in a multi-part
message. If it appears at all, it MUST be computed from the
finished (encrypted, signed, etc.) message in a deterministic
fashion, rather than contain a purely random value. This is to
allow the legitimate recipient to determine that the MessageID
cannot serve as a covert means of leaking cryptographic key
information.
The Armor Tail Line is composed in the same manner as the Armor
Header Line, except the string "BEGIN" is replaced by the string
"END."
6.3. Encoding Binary in Radix-64
The encoding process represents 24-bit groups of input bits as output
strings of 4 encoded characters. Proceeding from left to right, a
24-bit input group is formed by concatenating three 8-bit input
groups. These 24 bits are then treated as four concatenated 6-bit
groups, each of which is translated into a single digit in the
Radix-64 alphabet. When encoding a bit stream with the Radix-64
encoding, the bit stream must be presumed to be ordered with the
most-significant-bit first. That is, the first bit in the stream will
be the high-order bit in the first 8-bit octet, and the eighth bit
will be the low-order bit in the first 8-bit octet, and so on.
+--first octet--+-second octet--+--third octet--+
|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|7 6 5 4 3 2 1 0|
+-----------+---+-------+-------+---+-----------+
|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|5 4 3 2 1 0|
+--1.index--+--2.index--+--3.index--+--4.index--+
Each 6-bit group is used as an index into an array of 64 printable
characters from the table below. The character referenced by the
index is placed in the output string.
Value Encoding Value Encoding Value Encoding Value Encoding
0 A 17 R 34 i 51 z
1 B 18 S 35 j 52 0
2 C 19 T 36 k 53 1
3 D 20 U 37 l 54 2
4 E 21 V 38 m 55 3
5 F 22 W 39 n 56 4
6 G 23 X 40 o 57 5
7 H 24 Y 41 p 58 6
8 I 25 Z 42 q 59 7
9 J 26 a 43 r 60 8
10 K 27 b 44 s 61 9
11 L 28 c 45 t 62 +
12 M 29 d 46 u 63 /
13 N 30 e 47 v
14 O 31 f 48 w (pad) =
15 P 32 g 49 x
16 Q 33 h 50 y
The encoded output stream must be represented in lines of no more
than 76 characters each.
Special processing is performed if fewer than 24 bits are available
at the end of the data being encoded. There are three possibilities:
1. The last data group has 24 bits (3 octets). No special
processing is needed.
2. The last data group has 16 bits (2 octets). The first two 6-bit
groups are processed as above. The third (incomplete) data group
has two zero-value bits added to it, and is processed as above.
A pad character (=) is added to the output.
3. The last data group has 8 bits (1 octet). The first 6-bit group
is processed as above. The second (incomplete) data group has
four zero-value bits added to it, and is processed as above. Two
pad characters (=) are added to the output.
6.4. Decoding Radix-64
Any characters outside of the base64 alphabet are ignored in Radix-64
data. Decoding software must ignore all line breaks or other
characters not found in the table above.
In Radix-64 data, characters other than those in the table, line
breaks, and other white space probably indicate a transmission error,
about which a warning message or even a message rejection might be
appropriate under some circumstances.
Because it is used only for padding at the end of the data, the
occurrence of any "=" characters may be taken as evidence that the
end of the data has been reached (without truncation in transit). No
such assurance is possible, however, when the number of octets
transmitted was a multiple of three and no "=" characters are
present.
6.5. Examples of Radix-64
Input data: 0x14fb9c03d97e
Hex: 1 4 f b 9 c | 0 3 d 9 7 e
8-bit: 00010100 11111011 10011100 | 00000011 11011001
11111110
6-bit: 000101 001111 101110 011100 | 000000 111101 100111
111110
Decimal: 5 15 46 28 0 61 37 62
Output: F P u c A 9 l +
Input data: 0x14fb9c03d9
Hex: 1 4 f b 9 c | 0 3 d 9
8-bit: 00010100 11111011 10011100 | 00000011 11011001
pad with 00
6-bit: 000101 001111 101110 011100 | 000000 111101 100100
Decimal: 5 15 46 28 0 61 36
pad with =
Output: F P u c A 9 k =
Input data: 0x14fb9c03
Hex: 1 4 f b 9 c | 0 3
8-bit: 00010100 11111011 10011100 | 00000011
pad with 0000
6-bit: 000101 001111 101110 011100 | 000000 110000
Decimal: 5 15 46 28 0 48
pad with = =
Output: F P u c A w = =
6.6. Example of an ASCII Armored Message
-----BEGIN PGP MESSAGE-----
Version: OpenPrivacy 0.99
yDgBO22WxBHv7O8X7O/jygAEzol56iUKiXmV+XmpCtmpqQUKiQrFqclFqUDBovzS
vBSFjNSiVHsuAA==
=njUN
-----END PGP MESSAGE-----
Note that this example is indented by two spaces.
7. Cleartext signature framework
It is desirable to sign a textual octet stream without ASCII armoring
the stream itself, so the signed text is still readable without
special software. In order to bind a signature to such a cleartext,
this framework is used. (Note that RFC2015 defines another way to
clear sign messages for environments that support MIME.)
The cleartext signed message consists of:
- The cleartext header '-----BEGIN PGP SIGNED MESSAGE-----' on a
single line,
- One or more "Hash" Armor Headers,
- Exactly one empty line not included into the message digest,
- The dash-escaped cleartext that is included into the message
digest,
- The ASCII armored signature(s) including the '-----BEGIN PGP
SIGNATURE-----' Armor Header and Armor Tail Lines.
If the "Hash" armor header is given, the specified message digest
algorithm is used for the signature. If there are no such headers,
MD5 is used, an implementation MAY omit them for V2.x compatibility.
If more than one message digest is used in the signature, the "Hash"
armor header contains a comma-delimited list of used message digests.
Current message digest names are described below with the algorithm
IDs.
7.1. Dash-Escaped Text
The cleartext content of the message must also be dash-escaped.
Dash escaped cleartext is the ordinary cleartext where every line
starting with a dash '-' (0x2D) is prefixed by the sequence dash '-'
(0x2D) and space ' ' (0x20). This prevents the parser from
recognizing armor headers of the cleartext itself. The message digest
is computed using the cleartext itself, not the dash escaped form.
As with binary signatures on text documents, a cleartext signature is
calculated on the text using canonical <CR><LF> line endings. The
line ending (i.e. the <CR><LF>) before the '-----BEGIN PGP
SIGNATURE-----' line that terminates the signed text is not
considered part of the signed text.
Also, any trailing whitespace (spaces, and tabs, 0x09) at the end of
any line is ignored when the cleartext signature is calculated.
8. Regular Expressions
A regular expression is zero or more branches, separated by '|'. It
matches anything that matches one of the branches.
A branch is zero or more pieces, concatenated. It matches a match for
the first, followed by a match for the second, etc.
A piece is an atom possibly followed by '*', '+', or '?'. An atom
followed by '*' matches a sequence of 0 or more matches of the atom.
An atom followed by '+' matches a sequence of 1 or more matches of
the atom. An atom followed by '?' matches a match of the atom, or the
null string.
An atom is a regular expression in parentheses (matching a match for
the regular expression), a range (see below), '.' (matching any
single character), '^' (matching the null string at the beginning of
the input string), '$' (matching the null string at the end of the
input string), a '\' followed by a single character (matching that
character), or a single character with no other significance
(matching that character).
A range is a sequence of characters enclosed in '[]'. It normally
matches any single character from the sequence. If the sequence
begins with '^', it matches any single character not from the rest of
the sequence. If two characters in the sequence are separated by '-',
this is shorthand for the full list of ASCII characters between them
(e.g. '[0-9]' matches any decimal digit). To include a literal ']' in
the sequence, make it the first character (following a possible '^').
To include a literal '-', make it the first or last character.
9. Constants
This section describes the constants used in OpenPGP.
Note that these tables are not exhaustive lists; an implementation
MAY implement an algorithm not on these lists.
See the section "Notes on Algorithms" below for more discussion of
the algorithms.
9.1. Public Key Algorithms
ID Algorithm
-- ---------
1 - RSA (Encrypt or Sign)
2 - RSA Encrypt-Only
3 - RSA Sign-Only
16 - Elgamal (Encrypt-Only), see [ELGAMAL]
17 - DSA (Digital Signature Standard)
18 - Reserved for Elliptic Curve
19 - Reserved for ECDSA
20 - Elgamal (Encrypt or Sign)
21 - Reserved for Diffie-Hellman (X9.42,
as defined for IETF-S/MIME)
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement DSA for signatures, and Elgamal for
encryption. Implementations SHOULD implement RSA keys.
Implementations MAY implement any other algorithm.
9.2. Symmetric Key Algorithms
ID Algorithm
-- ---------
0 - Plaintext or unencrypted data
1 - IDEA [IDEA]
2 - Triple-DES (DES-EDE, as per spec -
168 bit key derived from 192)
3 - CAST5 (128 bit key, as per RFC2144)
4 - Blowfish (128 bit key, 16 rounds) [BLOWFISH]
5 - SAFER-SK128 (13 rounds) [SAFER]
6 - Reserved for DES/SK
7 - Reserved for AES with 128-bit key
8 - Reserved for AES with 192-bit key
9 - Reserved for AES with 256-bit key
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement Triple-DES. Implementations SHOULD
implement IDEA and CAST5.Implementations MAY implement any other
algorithm.
9.3. Compression Algorithms
ID Algorithm
-- ---------
0 - Uncompressed
1 - ZIP (RFC1951)
2 - ZLIB (RFC1950)
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement uncompressed data. Implementations
SHOULD implement ZIP. Implementations MAY implement ZLIB.
9.4. Hash Algorithms
ID Algorithm Text Name
-- --------- ---- ----
1 - MD5 "MD5"
2 - SHA-1 "SHA1"
3 - RIPE-MD/160 "RIPEMD160"
4 - Reserved for double-width SHA (experimental)
5 - MD2 "MD2"
6 - Reserved for TIGER/192 "TIGER192"
7 - Reserved for HAVAL (5 pass, 160-bit)
"HAVAL-5-160"
100 to 110 - Private/Experimental algorithm.
Implementations MUST implement SHA-1. Implementations SHOULD
implement MD5.
10. Packet Composition
OpenPGP packets are assembled into sequences in order to create
messages and to transfer keys. Not all possible packet sequences are
meaningful and correct. This describes the rules for how packets
should be placed into sequences.
10.1. Transferable Public Keys
OpenPGP users may transfer public keys. The essential elements of a
transferable public key are:
- One Public Key packet
- Zero or more revocation signatures
- One or more User ID packets
- After each User ID packet, zero or more signature packets
(certifications)
- Zero or more Subkey packets
- After each Subkey packet, one signature packet, optionally a
revocation.
The Public Key packet occurs first. Each of the following User ID
packets provides the identity of the owner of this public key. If
there are multiple User ID packets, this corresponds to multiple
means of identifying the same unique individual user; for example, a
user may have more than one email address, and construct a User ID
for each one.
Immediately following each User ID packet, there are zero or more
signature packets. Each signature packet is calculated on the
immediately preceding User ID packet and the initial Public Key
packet. The signature serves to certify the corresponding public key
and user ID. In effect, the signer is testifying to his or her
belief that this public key belongs to the user identified by this
user ID.
After the User ID packets there may be one or more Subkey packets.
In general, subkeys are provided in cases where the top-level public
key is a signature-only key. However, any V4 key may have subkeys,
and the subkeys may be encryption-only keys, signature-only keys, or
general-purpose keys.
Each Subkey packet must be followed by one Signature packet, which
should be a subkey binding signature issued by the top level key.
Subkey and Key packets may each be followed by a revocation Signature
packet to indicate that the key is revoked. Revocation signatures
are only accepted if they are issued by the key itself, or by a key
that is authorized to issue revocations via a revocation key
subpacket in a self-signature by the top level key.
Transferable public key packet sequences may be concatenated to allow
transferring multiple public keys in one operation.
10.2. OpenPGP Messages
An OpenPGP message is a packet or sequence of packets that
corresponds to the following grammatical rules (comma represents
sequential composition, and vertical bar separates alternatives):
OpenPGP Message :- Encrypted Message | Signed Message |
Compressed Message | Literal Message.
Compressed Message :- Compressed Data Packet.
Literal Message :- Literal Data Packet.
ESK :- Public Key Encrypted Session Key Packet |
Symmetric-Key Encrypted Session Key Packet.
ESK Sequence :- ESK | ESK Sequence, ESK.
Encrypted Message :- Symmetrically Encrypted Data Packet |
ESK Sequence, Symmetrically Encrypted Data Packet.
One-Pass Signed Message :- One-Pass Signature Packet,
OpenPGP Message, Corresponding Signature Packet.
Signed Message :- Signature Packet, OpenPGP Message |
One-Pass Signed Message.
In addition, decrypting a Symmetrically Encrypted Data packet and
decompressing a Compressed Data packet must yield a valid OpenPGP
Message.
10.3. Detached Signatures
Some OpenPGP applications use so-called "detached signatures." For
example, a program bundle may contain a file, and with it a second
file that is a detached signature of the first file. These detached
signatures are simply a signature packet stored separately from the
data that they are a signature of.
11. Enhanced Key Formats
11.1. Key Structures
The format of an OpenPGP V3 key is as follows. Entries in square
brackets are optional and ellipses indicate repetition.
RSA Public Key
[Revocation Self Signature]
User ID [Signature ...]
[User ID [Signature ...] ...]
Each signature certifies the RSA public key and the preceding user
ID. The RSA public key can have many user IDs and each user ID can
have many signatures.
The format of an OpenPGP V4 key that uses two public keys is similar
except that the other keys are added to the end as 'subkeys' of the
primary key.
Primary-Key
[Revocation Self Signature]
[Direct Key Self Signature...]
User ID [Signature ...]
[User ID [Signature ...] ...]
[[Subkey [Binding-Signature-Revocation]
Primary-Key-Binding-Signature] ...]
A subkey always has a single signature after it that is issued using
the primary key to tie the two keys together. This binding signature
may be in either V3 or V4 format, but V4 is preferred, of course.