CSS411 Cryptography

PGP

Slide deck 20. Pretty Good Privacy: email security services, PGP operation, keys, key rings and the web of trust.

23 min read

Email securitySearch on YouTube

The problemSearch on YouTube

Email is one of the most widely used and regarded network services. At present, the contents of a message are not secure:

Who can read the emailWhere
An eavesdropperIn transit, while the message crosses relays
Privileged usersOn the destination system, with suitable rights

Four security enhancementsSearch on YouTube

Four enhancements fix this problem. A secure email system must supply these services:

EnhancementProtection from
ConfidentialityDisclosure of contents
Authentication (of the sender)A forged sender identity
Message integrityModification of contents
Non-repudiation of originDenial by the sender

Learn the four enhancements in two pairs. The message pair is confidentiality and integrity: they protect the contents. The sender pair is authentication and non-repudiation of origin: they protect the claim "A sent this".

PGP overviewSearch on YouTube

What PGP isSearch on YouTube

PGP (Pretty Good Privacy) is widely used for secure email:

  • Phil Zimmermann developed PGP.
  • PGP selected the best available crypto algorithms and integrated them into a single program.
  • PGP runs on Unix, PC, Macintosh and other systems.
  • PGP was originally free. Commercial versions are also available.

Current applicationsSearch on YouTube

Today, PGP means the OpenPGP standard for encryption and digital signatures. The slide shows four use cases:

ScenarioFlow on the slideHow PGP/OpenPGP is used
Secure email (Thunderbird)Sender → encrypted email → recipient. Only the intended recipient can decryptSupports OpenPGP encryption and digital signatures when the user configures it
Protected file sharing (GnuPG)Document → encrypted file → authorized recipient. Encrypt before sending or storingEncrypts and signs files. GnuPG is an implementation, not a separate cryptographic standard
Software release verification (Linux kernel releases)Release + signature → signature verification → integrity checkUses detached PGP signatures to verify downloaded releases. The software itself is not encrypted
Signed development history (Git commits and tags)Developer → signed commit/tag → signature verificationCan use OpenPGP signatures through GnuPG. Signing is optional, and Git also supports other signature formats

This table has three exam traps. GnuPG implements OpenPGP; it is not a different algorithm. Linux releases use detached signatures, and the software is not encrypted. Git signing is optional and is not always OpenPGP.

The slide ends with one rule: the public-key identity must be verified. If you encrypt with the wrong public key, the wrong person can read the message. The section on key management returns to this problem.

PGP operationSearch on YouTube

AuthenticationSearch on YouTube

A digital signature gives authentication, integrity and non-repudiation of origin. The five steps are:

  1. The sender creates the message.
  2. The sender makes a SHA-1 160-bit hash of the message.
  3. The sender attaches the RSA-signed hash to the message.
  4. The receiver decrypts the signature and recovers the hash code.
  5. The receiver verifies the hash of the received message.

signature=E(PRa, H(M)),H(M)∈{0,1}160\text{signature} = E(PR_a,\ H(M)), \qquad H(M) \in \{0,1\}^{160}

PRaPR_a is the private key of the sender. Only the holder of PRaPR_a can make a signature that the public key PUaPU_a accepts. Thus, the signature also identifies the sender.

verify: D(PUa, signature)=?H(M)\text{verify}: \ D(PU_a,\ \text{signature}) \stackrel{?}{=} H(M)

The receiver recovers the hash with the public key of the sender. Then the receiver hashes the received message again and compares the two values. Equal values show that the message did not change after signing.

ConfidentialitySearch on YouTube

Encryption of the contents gives confidentiality. The five steps are:

  1. The sender forms a 128-bit random session key for this message only.
  2. The sender encrypts the message with the session key (symmetric cipher).
  3. The sender attaches the session key, encrypted with RSA.
  4. The receiver decrypts and recovers the session key.
  5. The receiver uses the session key to decrypt the message.

output=E(PUb, Ks)∥E(Ks, X)\text{output} = E(PU_b,\ K_s) \Vert E(K_s,\ X)

KsK_s is the session key and PUbPU_b is the public key of the recipient. RSA carries the small secret, and the fast symmetric cipher carries the long message. Each message gets a new KsK_s.

Both servicesSearch on YouTube

PGP can use both services on the same message:

  1. Create the signature and attach it to the message.
  2. Encrypt the message and the signature with the session key.
  3. Attach the session key, encrypted with RSA/ElGamal.

signed=E(PRa, H(M))∥M→E(PUb, Ks)∥E(Ks, signed)\text{signed} = E(PR_a,\ H(M)) \Vert M \quad \rightarrow \quad E(PU_b,\ K_s) \Vert E(K_s,\ \text{signed})

MSHA-1160 bitsSignE(PRa​, H)Sig ‖ MEncryptE(Ks​, ·)OutputE(PUb​, Ks​)‖E(Ks​, Sig ‖ M)Ks​128-bit randomRSAE(PUb​, Ks​)The signature is inside the encryption, so an eavesdropper cannot see the signer.
PGP with both services: sign the SHA-1 hash with the private key, then encrypt message and signature with a session key that RSA protects.

The signature is inside the encryption. Thus, an eavesdropper cannot see who signed the message.

CompressionSearch on YouTube

By default, PGP compresses the message after signing but before encrypting. The slide gives the reason:

PointExplanation
Storage for later verificationPGP can store the uncompressed message and the signature, and verify them later
Non-determinismCompression is non-deterministic: the result depends on user preferences. A signature on compressed data may not verify after a new compression
AlgorithmPGP uses the ZIP compression algorithm

The order is exam material: sign first, compress second, encrypt third. Compression before encryption also removes redundancy in the plaintext. Less redundancy makes cryptanalysis of the cipher more difficult.

Email compatibilitySearch on YouTube

PGP produces binary data (encrypted message, signature, encrypted session key). But email was designed only for text. Thus:

  • PGP must encode the raw binary data into printable ASCII characters.
  • PGP uses the radix-64 algorithm, also called "ASCII Armour".
    • Radix-64 maps 3 bytes to 4 printable characters (it is the Base64 of MIME).
    • Radix-64 also appends a 24-bit CRC.
  • PGP also segments messages that are too big.

radix-64: 3×8=24 bits → 4×6=24 bits → 4 printable chars\text{radix-64}: \ 3 \times 8 = 24 \text{ bits} \ \rightarrow \ 4 \times 6 = 24 \text{ bits} \ \rightarrow \ 4 \text{ printable chars}

Armour makes the data about 33% larger (factor 4/34/3). Compression recovers part of this increase.

Operation summarySearch on YouTube

The summary slide shows two flowcharts. Transmission (from A):

X←fileX \leftarrow \text{file}

signature required? →X←signature∥X\text{signature required? } \rightarrow X \leftarrow \text{signature} \Vert X

X←Z(X)(compress)X \leftarrow Z(X) \qquad \text{(compress)}

confidentiality required? →X←E(PUb, Ks)∥E(Ks, X)\text{confidentiality required? } \rightarrow X \leftarrow E(PU_b,\ K_s) \Vert E(K_s,\ X)

X←R64[X](convert to radix-64)X \leftarrow R64[X] \qquad \text{(convert to radix-64)}

Reception (to B):

X←R64−1[X]X \leftarrow R64^{-1}[X]

confidentiality required? →Ks←D(PRb, E(PUb, Ks)),X←D(Ks, E(Ks, X))\text{confidentiality required? } \rightarrow K_s \leftarrow D(PR_b,\ E(PU_b,\ K_s)), \quad X \leftarrow D(K_s,\ E(K_s,\ X))

X←Z−1(X)(decompress)X \leftarrow Z^{-1}(X) \qquad \text{(decompress)}

signature required? →strip signature from X, verify signature\text{signature required? } \rightarrow \text{strip signature from } X, \text{ verify signature}

StepTransmissionReception
1Sign (optional)Convert from radix-64
2CompressDecrypt key, then message (optional)
3Encrypt key and message (optional)Decompress
4Convert to radix-64Strip and verify signature (optional)

Reception does the steps in the reverse order. Compression and radix-64 conversion always occur.

Transmission order: S-C-E-R, "Sign, Compress, Encrypt, Radix-64". Reception reads it backwards: R-E-C-S.

Keys and message formatSearch on YouTube

Session keysSearch on YouTube

PGP needs a session key for each message:

  • Session keys have varying sizes: 56-bit DES, 128-bit CAST or IDEA, 168-bit Triple-DES.
  • PGP generates them with the ANSI X12.17 mode (the slide name; Stallings calls it ANSI X9.17).
  • The generator uses random inputs from previous uses and from the keystroke timing of the user.

A session key is like a hotel keycard for one night. It opens one message and then PGP discards it. If an attacker breaks one message, the attacker gets only that one key, not the long-term keys.

Key identifiersSearch on YouTube

One user may have many public/private key pairs in use. Thus, each message must identify which key encrypted the session key:

  • PGP could send the full public key with every message, but this is inefficient.
  • Instead, PGP uses a key identifier (key ID) based on the key.
  • The key ID is the least significant 64 bits of the key. It is very likely unique.
  • PGP also uses the key ID in signatures.

Key ID=PU mod 264\text{Key ID} = PU \bmod 2^{64}

The session key component carries the key ID of the recipient. The signature carries the key ID of the sender. The receiver finds the correct key-ring entry with one lookup.

Message formatSearch on YouTube

A PGP message has three components:

ComponentContentsOperation on it
Session key componentKey ID of the public key of the recipient (PUbPU_b); session key (KsK_s)KsK_s is encrypted with E(PUb,⋅)E(PU_b, \cdot)
SignatureTimestamp; key ID of the public key of the sender (PUaPU_a); leading two octets of the message digest; message digestThe digest is encrypted with E(PRa,⋅)E(PR_a, \cdot)
MessageFilename; timestamp; data—

The operations on the whole message are:

  • ZIP and E(Ks,⋅)E(K_s, \cdot) cover the signature and the message. They do not cover the session key component.
  • R64 covers all three components.
SymbolMeaning
E(PUb,⋅)E(PU_b, \cdot)Encryption with the public key of user B
E(PRa,⋅)E(PR_a, \cdot)Encryption with the private key of user A
E(Ks,⋅)E(K_s, \cdot)Encryption with the session key
ZIPZIPZip compression function
R64R64Radix-64 conversion function

Learn the components top to bottom as K-Sig-M: Key component, Signature, Message.

  • Signature: timestamp, key ID of PUaPU_a, leading 2 octets, digest.
  • Message: filename, timestamp, data.

Key rings and processingSearch on YouTube

Key ringsSearch on YouTube

Each PGP user has a pair of keyrings:

RingContainsIndexed by
Public-key ringAll the public keys of other PGP users that this user knowsKey ID (the table also marks User ID)
Private-key ringThe public/private key pair(s) of this userKey ID and User ID

The private-key ring stores each private key encrypted with a key from a hashed passphrase. Thus, the security of the private keys depends on the security of the passphrase.

The slide tables show these fields:

Private-key ring fieldsPublic-key ring fields
Timestamp TiT_iTimestamp TiT_i
Key ID* (PUi mod 264PU_i \bmod 2^{64})Key ID* (PUi mod 264PU_i \bmod 2^{64})
Public key (PUiPU_i)Public key (PUiPU_i)
Encrypted private key, E(H(Pi),PRi)E(H(P_i), PR_i)Owner trust (trust_flagi\text{trust\_flag}_i)
User ID*User ID*
—Key legitimacy (trust_flagi\text{trust\_flag}_i)
—Signature(s)
—Signature trust(s)

* = field used to index the table.

Message generationSearch on YouTube

The generation slide connects the key rings to the operations (sign and encrypt):

  1. The sender enters a passphrase. PGP hashes it (H).
  2. The sender ID (IDAID_A) selects the entry in the private-key ring. The passphrase hash decrypts (DC) the encrypted private key and gives PRaPR_a.
  3. PGP hashes message MM (H) to get the message digest. PRaPR_a encrypts the digest (EP).
  4. PGP joins the signature, the key ID of the sender and the message (concatenation).
  5. The RNG makes the session key KsK_s. KsK_s encrypts the signature and message (EC).
  6. The recipient ID (IDBID_B) selects PUbPU_b in the public-key ring. PUbPU_b encrypts KsK_s (EP).
  7. The output is the key ID of PUbPU_b, the encrypted session key, and the encrypted signature + message.

Alice signs and encrypts a message for Bob. Her passphrase unlocks PRaPR_a in her private-key ring. SHA-1 hashes the message, and PRaPR_a signs the hash. A new KsK_s encrypts the signed message. Bob's ID selects PUbPU_b in her public-key ring, and PUbPU_b encrypts KsK_s.

Message receptionSearch on YouTube

The reception slide shows the reverse path:

  1. The key ID of the receiver selects the entry in the private-key ring.
  2. The hash (H) of the passphrase decrypts (DC) the encrypted private key. This gives PRbPR_b.
  3. PRbPR_b decrypts (DP) the encrypted session key. This gives KsK_s.
  4. KsK_s decrypts (DC) the encrypted message + signature.
  5. The key ID of the sender selects PUaPU_a in the public-key ring.
  6. PUaPU_a decrypts (DP) the encrypted digest.
  7. PGP hashes the message again (H) and compares the two digests. Equal values verify the signature.
Field read at receptionLeads to
Key ID of the receiverPrivate-key ring entry, unlocked by the passphrase
Encrypted session keyKsK_s, through DP with PRbPR_b
Key ID of the senderPublic-key ring entry, PUaPU_a
Encrypted digestRecovered hash, compared with a new hash of the message

Key managementSearch on YouTube

Web of trustSearch on YouTube

PGP does not rely on certificate authorities (CAs). Instead:

  • Each user is a CA. A user can sign keys for users that the user knows directly.
  • This forms a "web of trust":
    • Trust the keys that you signed.
    • Trust keys that others signed if you have a chain of signatures to them.
  • The key ring includes trust indicators (owner trust, key legitimacy, signature trust).
  • Users can also revoke their keys.
PGPX.509 / CA model
Distributed: users sign the keys of usersCentralized: an authority issues certificates
Trust comes from personal knowledgeTrust comes from the authority
A chain of signatures gives legitimacyA chain of certificates gives legitimacy

Trust model exampleSearch on YouTube

The web-of-trust diagram uses this legend:

SymbolMeaning
??Unknown signatory
X→YX \rightarrow YXX is signed by YY
Grey nodeYou trust the owner of the key to sign keys
Half-grey nodeYou partly trust the owner of the key to sign keys
Dot in the nodeYou deem the key legitimate

In the PGP trust model, a key becomes legitimate in these ways:

  • You signed the key yourself.
  • One owner that you fully trust signed the key.
  • Two owners that you partly trust signed the key.

A signature from an unknown (??) signatory gives no legitimacy. A signature from a legitimate key whose owner you do not trust also gives no legitimacy.

You signed A to F, so all six keys are legitimate. You fully trust D, E, F and L, and you partly trust A and B. H is legitimate because both A and B signed it. G is not legitimate: only A (partly trusted) and an unknown signatory signed it. M, N and O are legitimate because E signed them. L is legitimate because D signed it. P and Q are legitimate because L signed them. You do not trust C, so I, J and K stay not legitimate. R (signed by N) and S (signed only by unknown signatories) are also not legitimate.

Quick self-testSearch on YouTube

Why is plain email not secure?

The contents of the message are not secure. An eavesdropper can inspect them in transit. Privileged users on the destination system can also inspect them.

List the four email security enhancements.

Confidentiality: protection from disclosure. Authentication: of the sender of the message. Message integrity: protection from modification. Non-repudiation of origin: protection from denial by the sender.

Give the five steps of PGP authentication.
  1. The sender creates the message. 2. The sender makes a SHA-1 160-bit hash. 3. The sender attaches the RSA-signed hash. 4. The receiver decrypts and recovers the hash code. 5. The receiver verifies the hash of the received message.
Give the five steps of PGP confidentiality.
  1. The sender forms a 128-bit random session key. 2. The sender encrypts the message with it. 3. The sender attaches the session key, encrypted with RSA. 4. The receiver decrypts and recovers the session key. 5. The receiver decrypts the message with the session key.
When PGP uses both services, what is the order?

PGP creates the signature and attaches it to the message. Then PGP encrypts the message and the signature with the session key. Then PGP attaches the session key, encrypted with RSA/ElGamal.

Why does PGP compress after signing but before encrypting?

PGP can then store the uncompressed message and the signature for later verification. Compression is non-deterministic, because the result depends on user preferences. PGP uses the ZIP algorithm.

What does radix-64 armour do?

Radix-64 (ASCII Armour) maps 3 bytes to 4 printable characters, so binary data can go through text-only email. It also appends a 24-bit CRC. PGP also segments messages that are too big.

Give the sizes and the random sources of PGP session keys.

Sizes: 56-bit DES, 128-bit CAST or IDEA, 168-bit Triple-DES. PGP generates the keys with ANSI X12.17 mode. The random inputs come from previous uses and from the keystroke timing of the user.

What is a PGP key ID, and how big is it?

A key ID is the least significant 64 bits of the public key. It is very likely unique. The session key component carries the key ID of the recipient, and the signature carries the key ID of the sender.

Name the three components of the PGP message format.

Session key component: key ID of PUbPU_b and KsK_s, encrypted with E(PUb,⋅)E(PU_b, \cdot). Signature: timestamp, key ID of PUaPU_a, leading two octets of the digest, and the digest encrypted with E(PRa,⋅)E(PR_a, \cdot). Message: filename, timestamp, data. ZIP and E(Ks,⋅)E(K_s, \cdot) cover the signature and message, and R64 covers all.

How does a key become legitimate in the PGP web of trust?

PGP has no certificate authority, and each user signs the keys of people that the user knows. A key is legitimate if you signed it, or one fully trusted owner signed it, or two partly trusted owners signed it. Unknown signatories give no legitimacy.

  • Email contents are open in transit and on the destination system. PGP (Phil Zimmermann) gives confidentiality, sender authentication, message integrity and non-repudiation of origin.
  • Authentication: a SHA-1 160-bit hash, signed with RSA. Confidentiality: a 128-bit random session key, encrypted with the public key of the recipient.
  • Order: sign, compress (ZIP), encrypt, convert to radix-64. Radix-64 maps 3 bytes to 4 ASCII characters and adds a 24-bit CRC. Reception does the reverse.
  • Session keys: one per message, 56-bit DES, 128-bit CAST/IDEA or 168-bit Triple-DES. A 64-bit key ID identifies each public key.
  • Message format: session key component, signature, message. ZIP and E(Ks)E(K_s) cover the signature and message; R64 covers all.
  • Each user has a public-key ring and a private-key ring. A hashed passphrase protects the private keys.
  • Trust: no CA. Each user signs keys and builds a web of trust with trust indicators and revocation.