Under the armour, OpenPGP data is a sequence of packets. This page gives the packet frame, the packet types, the key packets and the algorithm IDs, following RFC 9580 (sections 3, 4, 5.5, 9 and 10.1) and the IANA OpenPGP registries. Numbers (scalars) are unsigned and big-endian. Times are 4-byte counts of seconds since midnight, 1 January 1970 UTC.
Packet header
The first byte always has bit 7 set. Bit 6 chooses the format:
| Format | First byte | Length |
|---|---|---|
| OpenPGP (new), bit 6 = 1 | Bits 5–0: packet type, 0–63. | Follows as described below. |
| Legacy (old), bit 6 = 0 | Bits 5–2: packet type, 0–15. Bits 1–0: length type. | Length type 0: one byte; 1: two bytes; 2: four bytes; 3: indeterminate, to the end of the data (must not be written). The legacy format should not be written at all. |
| First length byte | Length |
|---|---|
| 0–191 | That byte: 0 to 191. |
| 192–223 | Two bytes: ((first − 192) × 256) + second + 192, giving 192 to 8,383. |
| 224–254 | Partial body length: 2(first AND 31) bytes follow, then another length header; the last one must not be partial. Only for literal, compressed and encrypted data packets, and the first part must be at least 512 bytes. |
| 255 | Four more bytes give the length. |
So 98 33 is a legacy packet of type 6 with a one-byte length of 51, and
C6 33 the same in the new format.
Packet types
| Type | Packet |
|---|---|
| 0 | Reserved; must not be used |
| 1 | Public-Key Encrypted Session Key (PKESK) |
| 2 | Signature (SIG) |
| 3 | Symmetric-Key Encrypted Session Key (SKESK) |
| 4 | One-Pass Signature (OPS) |
| 5 | Secret Key |
| 6 | Public Key |
| 7 | Secret Subkey |
| 8 | Compressed Data |
| 9 | Symmetrically Encrypted Data (obsolete, no integrity check) |
| 10 | Marker (the bytes PGP; ignored) |
| 11 | Literal Data |
| 12 | Trust (local to a keyring; not exported) |
| 13 | User ID (UTF-8 text, such as Alice <alice@example.org>) |
| 14 | Public Subkey |
| 15–16 | Not listed in RFC 9580’s table |
| 17 | User Attribute (such as a JPEG photo) |
| 18 | Symmetrically Encrypted and Integrity Protected Data (SEIPD) |
| 19 | Reserved (formerly Modification Detection Code) |
| 20 | Reserved |
| 21 | Padding |
| 22–39 | Unassigned, critical |
| 40–59 | Unassigned, non-critical |
| 60–63 | Private or experimental use (non-critical) |
Types 0–39 are critical: a reader that meets an unknown critical type must reject the whole packet sequence. An unknown non-critical packet (40–63) must be ignored (section 4.3).
A transferable public key (an OpenPGP certificate), the usual content of a key
.asc, is laid out as follows for version 6 (section 10.1.1); brackets
are optional, “…” repeats, and a Marker packet may appear anywhere:
Primary Key
[Revocation Signature...]
Direct Key Signature...
[User ID or User Attribute
[Certification Revocation Signature...]
[Certification Signature...]]...
[Subkey [Subkey Revocation Signature...]
Subkey Binding Signature...]...
[Padding]
A version 4 key (section 10.1.3) has an optional single Revocation Signature, optional Direct Key Signatures, then User IDs or User Attributes each with their signatures, then subkeys each with at least one Subkey Binding Signature.
Key packets
| Field | Size | Version 4 | Version 6 |
|---|---|---|---|
| Version | 1 | 4 | 6 |
| Creation time | 4 | Seconds since 1970 | Seconds since 1970 |
| Algorithm | 1 | See public key algorithms | Same |
| Key material length | 4 | – | Bytes of key material that follow |
| Key material | varies | Algorithm-specific; RSA: MPI n, MPI e | Algorithm-specific |
An MPI (multiprecision integer) is a 2-byte count of bits, counted from the most
significant non-zero bit, followed by the number, big-endian, in the fewest bytes:
00 09 01 FF is 511 (section 3.2). Implementations should create version
6 keys; version 4 keys are deprecated but should be accepted; version 3 keys (RSA
only, with a validity period in days) and version 2 keys must not be generated
(section 5.5.2).
| Version | Fingerprint | Key ID |
|---|---|---|
| 4 | SHA-1 of 99, a 2-byte length and the packet body: 20 bytes | The low-order 64 bits of the fingerprint |
| 6 | SHA2-256 of 9B, a 4-byte length and the packet body: 32 bytes | The high-order 64 bits of the fingerprint |
Subkeys are hashed the same way, starting with 99 or 9B
(section 5.5.4).
Secret key packets
A Secret Key or Secret Subkey packet is the public key packet’s fields followed by an S2K usage byte and, depending on it, how the secret part is protected:
| S2K usage | Meaning |
|---|---|
| 0 | Unprotected; the secret key material follows, then (v3 and v4 only) a 2-byte checksum, the sum of its bytes mod 65,536. |
| 253 | AEAD: (v6: parameter length), cipher, AEAD mode, (v6: S2K specifier length), S2K specifier, nonce. |
| 254 | CFB with a SHA-1 hash of the secrets: (v6: parameter length), cipher, (v6: S2K specifier length), S2K specifier, IV. |
| 255 | MalleableCFB, with the 2-byte checksum: cipher, S2K specifier, IV. Must not be generated. |
| A cipher ID | LegacyCFB (before RFC 2440): the byte is the symmetric cipher ID and the key is the MD5 of the passphrase; an IV follows. Must not be generated. |
Version 6 secret keys using a “must not be generated” form must be rejected, and Argon2 may only be used with usage 253 (section 3.7.2.1).
| S2K type | Specifier |
|---|---|
| 0 | Simple: hash algorithm (2 bytes in all). Must not be generated. |
| 1 | Salted: hash algorithm, 8-byte salt (10 bytes). Only for high-entropy strings. |
| 2 | Reserved. |
| 3 | Iterated and salted: hash algorithm, 8-byte salt, count byte c (11 bytes); (16 + (c AND 15)) × 2(c ÷ 16) + 6 bytes of salt and passphrase are hashed, an octet count, not an iteration count. |
| 4 | Argon2 (Argon2id, version 0x13): 16-byte salt, passes t, parallelism p, and m where the memory is 2m KiB, from 3 + ⌈log2 p⌉ to 31 (20 bytes). Recommended. |
| 100–110 | Private or experimental. |
Key material by algorithm
RFC 9580 section 5.5.5. The public part follows the key packet’s algorithm byte (after the 4-byte length in version 6); the secret part follows the S2K fields. An OID field is a 1-byte length (0 and 0xFF reserved) and the curve OID’s contents; MPI is as above.
| Algorithm | Public part | Secret part |
|---|---|---|
| RSA (1–3) | MPI n, MPI e | MPI d, MPI p, MPI q (p < q), MPI u (the inverse of p mod q) |
| DSA (17) | MPI p, MPI q (a prime divisor of p − 1), MPI g, MPI y (= gx mod p) | MPI x |
| Elgamal (16) | MPI p, MPI g, MPI y (= gx mod p) | MPI x |
| ECDSA (19) | OID field (curve), MPI of the EC point | MPI of the secret scalar |
| EdDSALegacy (22, deprecated) | OID field (only Ed25519Legacy is defined), MPI of the point Q in prefixed native form | MPI holding the native secret key (fixed-width random octets for the curve) |
| ECDH (18) | OID field, MPI of the EC point in the curve’s point format, then the KDF parameters: 1-byte size (0 and 0xFF reserved), the byte 1 (reserved), a hash function ID, and the symmetric algorithm ID used to wrap the message key | MPI of the secret key in the curve’s format. For the NIST and Brainpool curves a plain integer. For Curve25519Legacy (deprecated; not in version 6 keys) a big-endian MPI of 255 bits, always starting 00 FF, whose 32 following bytes reversed are the native key, which must be divisible by 8, at least 2254 and below 2255 |
| X25519 (25) | 32 bytes, the native public key | 32 bytes, the native secret key (the original random octets) |
| X448 (26) | 56 bytes | 56 bytes |
| Ed25519 (27) | 32 bytes | 32 bytes |
| Ed448 (28) | 57 bytes | 57 bytes |
The post-quantum algorithms 30–36 (RFC 9980) are not laid out here.
Message packets
RFC 9580 section 5. Each packet body starts with a version byte where one is listed.
Public-Key Encrypted Session Key (1)
| Version | Fields |
|---|---|
| 3 (precedes a v1 SEIPD) | Version 3; 8-byte Key ID of the recipient key or subkey (all zeros for an anonymous recipient); public key algorithm; the algorithm’s fields |
| 6 (precedes a v2 SEIPD) | Version 6; 1-byte size of the next two fields (may be 0 for an anonymous recipient, omitting both); key version byte; the key’s fingerprint (20 bytes for a version 4 key, 32 for version 6); public key algorithm; the algorithm’s fields |
Algorithm fields: RSA one MPI, the value me mod n, where m is
the PKCS#1 v1.5 encoding (RFC 8017 section 7.2.1) of the algorithm byte (v3 only), the
session key and its 2-byte sum modulo 65,536; Elgamal two MPIs,
gk mod p and m × yk mod p, m formed the same way (v6 must not be
generated); ECDH an MPI of the ephemeral public point, a 1-byte size,
then the wrapped key; X25519 32 bytes of ephemeral public key, a
1-byte size, the cipher ID in plain (v3 only, which must then be AES-128, -192 or
-256), and the encrypted session key; X448 the same with 56 bytes.
X25519 derives its key with HKDF-SHA256 (info OpenPGP X25519, no salt)
over the ephemeral key, the recipient key and the shared secret and wraps with AES-128
key wrap (RFC 3394); X448 uses HKDF-SHA512 (info OpenPGP X448) and AES-256
wrap; neither adds a checksum or padding.
Symmetric-Key Encrypted Session Key (3)
| Version | Fields |
|---|---|
| 4 (precedes a v1 SEIPD) | Version 4; symmetric cipher ID; S2K specifier; optionally the encrypted session key. Without it, the S2K output is the session key. With it, the S2K output decrypts it in CFB mode with an all-zero IV to a cipher ID byte followed by the key, so the S2K must use a salt (or Argon2). |
| 6 (precedes a v2 SEIPD) | Version 6; 1-byte count of the five fields that follow; cipher ID; AEAD ID; 1-byte count of the S2K specifier; S2K specifier; IV of the AEAD’s size; the encrypted session key; the AEAD authentication tag. A key-encryption key comes from HKDF-SHA256 over the S2K output (no salt; info: the packet type byte 0xC3, the version, the cipher ID and the AEAD ID), and the session key is encrypted with the AEAD in one piece, with the same bytes as additional data (for AES-128 with OCB: C3 06 07 02). |
One-Pass Signature (4)
Version (3 or 6; there is no version 4, version 4 keys use 3); signature type; hash algorithm; public key algorithm; version 6 only: a 1-byte salt size (the size Table 23 gives for the hash) and the salt, equal to the signature’s; version 3 only: the 8-byte Key ID; version 6 only: the 32-byte fingerprint of the signing key; a 1-byte nesting flag, where 0 means the next packet is another One-Pass Signature packet for the same data. With several, the signatures after the data come in the reverse order.
Compressed Data (8)
One byte for the algorithm (0 none, 1 ZIP: raw DEFLATE, RFC 1951; 2 ZLIB, RFC 1950; 3 BZip2), then the compressed series of packets to the end. It must be written with the new packet format.
Symmetrically Encrypted Data (9, obsolete)
No version byte. CFB-encrypted data with an all-zero IV, whose first block-size bytes are random followed by a copy of the last two; the CFB state is then resynchronised on the last block of that first ciphertext. The cipher comes from the preceding session key packet (IDEA with an MD5 of the passphrase if there is none). It has no integrity check and must not be created.
Marker (10)
The three bytes 50 47 50 (“PGP”); ignored.
Literal Data (11)
A format byte: 62 (b) binary, 75 (u) UTF-8 text, 74
(t) text of unspecified encoding (deprecated; read as UTF-8), and 6C (l)
or 31 machine-local modes (deprecated); a 1-byte file name length and the
name (the name _CONSOLE asks for “for your eyes only”, deprecated and
unenforceable); a 4-byte date (0 for none); then the data. Text has CR LF line ends. A
signature does not cover the format byte, name or date, so they must not be trusted.
Trust (12)
Used in keyrings only and defined by the implementation; ignore it on input other than local keyring files, and do not send it.
User ID (13) and User Attribute (17)
A User ID is UTF-8 text, usually a name and an email address in the form of RFC 2822
name-addr, with no restriction. A User Attribute is a series of
subpackets, each a length (1, 2 or 5 bytes), a type byte and the data. Type 1 is an
image (types 100–110 private). Its data begins with an image header whose first two
bytes are its length, little-endian; version 1 is 16 bytes:
10 00 01, an encoding byte (1 JPEG in JFIF, 100–110 private) and 12 zero
bytes; then the image. Unknown subpackets are ignored.
Symmetrically Encrypted and Integrity Protected Data (18)
| Version | Contents |
|---|---|
| 1 | Version 1, then CFB-encrypted data (the cipher comes from the session key packet; the IV is zero). The plaintext is block-size random bytes plus a copy of the last two of them, the data, the bytes D3 14 and a SHA-1 of everything before it (the Modification Detection Code), all in one CFB context. A mismatch is a security failure. |
| 2 | Version 2; cipher ID; AEAD ID; chunk size byte c (the chunk is 2c + 6 bytes; 0 to 16 must be accepted, above 16 not created, so at most 4 MiB); 32-byte salt; the chunks each followed by an authentication tag; a final tag over the empty string whose additional data also holds the 8-byte total plaintext length, to detect truncation. A message key and IV come from HKDF-SHA256 with the session key as input, the salt, and as info the type byte D2, the version, cipher ID, AEAD ID and chunk byte. The nonce is the derived IV followed by the 8-byte chunk index, starting at 0. |
AEAD modes (all with 16-byte blocks and tags): EAX nonce 16 bytes, OCB nonce 15 bytes, GCM nonce 12 bytes.
Padding (21)
Random bytes, ignored. Put at the end of a version 6 transferable public key sent over an encrypted channel, and as the last packet inside a v2 SEIPD message.
Public key algorithms
| ID | Algorithm |
|---|---|
| 0 | Reserved |
| 1 | RSA (encrypt or sign); deprecated, should not be generated |
| 2 | RSA encrypt-only; deprecated, must not be generated |
| 3 | RSA sign-only; deprecated, must not be generated |
| 16 | Elgamal (encrypt-only); deprecated, must not be generated |
| 17 | DSA; deprecated, must not be generated |
| 18 | ECDH |
| 19 | ECDSA |
| 20 | Reserved (formerly Elgamal encrypt or sign) |
| 21 | Reserved for Diffie–Hellman (X9.42) |
| 22 | EdDSALegacy (deprecated) |
| 23 | Reserved (AEDH) |
| 24 | Reserved (AEDSA) |
| 25 | X25519 (must be implemented, for encryption) |
| 26 | X448 |
| 27 | Ed25519 (must be implemented, for signatures) |
| 28 | Ed448 |
| 30 | ML-DSA-65+Ed25519 (RFC 9980) |
| 31 | ML-DSA-87+Ed448 |
| 32 | SLH-DSA-SHAKE-128s |
| 33 | SLH-DSA-SHAKE-128f |
| 34 | SLH-DSA-SHAKE-256s |
| 35 | ML-KEM-768+X25519 |
| 36 | ML-KEM-1024+X448 |
| 4–15, 29, 37–99, 111–255 | Unassigned |
| 100–110 | Private or experimental |
IDs 0–28 are from RFC 9580 Table 18; 30–36 were added to the IANA registry (updated 2026-07-02) by RFC 9980.
ECDH, ECDSA and EdDSALegacy keys name their curve by OID (RFC 9580 Table 19; the key
stores the DER encoding without its tag and length bytes): NIST P-256
(1.2.840.10045.3.1.7), P-384 (1.3.132.0.34), P-521
(1.3.132.0.35), brainpoolP256r1 (1.3.36.3.3.2.8.1.1.7),
brainpoolP384r1 (…1.1.11), brainpoolP512r1 (…1.1.13),
Ed25519Legacy (1.3.6.1.4.1.11591.15.1) and Curve25519Legacy
(1.3.6.1.4.1.3029.1.5.1).
Other algorithm IDs
| ID | Symmetric cipher |
|---|---|
| 0 | Plaintext |
| 1 | IDEA |
| 2 | TripleDES |
| 3 | CAST5 |
| 4 | Blowfish |
| 5–6 | Reserved |
| 7, 8, 9 | AES-128, AES-192, AES-256 |
| 10 | Twofish |
| 11, 12, 13 | Camellia-128, -192, -256 |
| 100–110 | Private or experimental |
| 253–255 | Reserved (they would clash with S2K usage values) |
| ID | Hash |
|---|---|
| 0 | Reserved |
| 1 | MD5 |
| 2 | SHA-1 |
| 3 | RIPEMD-160 |
| 4–7 | Reserved |
| 8 | SHA2-256 |
| 9 | SHA2-384 |
| 10 | SHA2-512 |
| 11 | SHA2-224 |
| 12 | SHA3-256 |
| 13 | Reserved |
| 14 | SHA3-512 |
| 100–110 | Private or experimental |
| ID | Compression | ID | AEAD mode |
|---|---|---|---|
| 0 | Uncompressed | 0 | Reserved |
| 1 | ZIP (raw deflate) | 1 | EAX |
| 2 | ZLIB | 2 | OCB |
| 3 | BZip2 | 3 | GCM |
| 100–110 | Private or experimental | 100–110 | Private or experimental |