Cambridge AS & A Level · Part 3 · Chapter 21
Security
How data stays secret, how you know who sent it, and how you know nobody changed it on the way. Every figure, question and exam question from the chapter is here, with labs where you encrypt, sign, certify and swap keys yourself.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to:
- show understanding of how encryption works
- show understanding of digital certification
- show awareness of the Secure Socket Layer (SSL) / Transport Layer Security (TLS) protocols
🔑 21.01 Encryption fundamentals
Encryption can be a routine part of storing data, but this chapter is about encrypting data while it is being transmitted over a network. Three questions run through the whole chapter:
- Is the encryption algorithm robust enough that an unauthorised third party cannot decrypt the data?
- How can a secret key stay secret?
- How can the receiver be sure who sent the communication?
The process starts with the original data, the plaintext, whatever form it takes. An encryption algorithm uses a key to turn it into ciphertext, which is what gets transmitted. The receiver uses a decryption algorithm and a key to get the original plaintext back.
🛡️ Security concerns
Five concerns apply to any transmission:
| Concern | What it means |
|---|---|
| Confidentiality | Only the intended recipient should be able to decrypt the ciphertext. |
| Authenticity | The receiver must be certain who sent the ciphertext. |
| Integrity | The ciphertext must not be modified during transmission. |
| Non-repudiation | Neither sender nor receiver should be able to deny being involved in the transmission. |
| Availability | Nothing should stop the receiver from receiving the transmission. |
The chapter only deals with the first three. Confidentiality matters because a message can be intercepted and read by an unauthorised person. Integrity covers both deliberate interference and accidental corruption of data during transmission.
🎮 Which concern is it?
Read the situation and pick the security concern it threatens.
🔐 Encryption methods
The fundamental principle: the encryption algorithm must not be secret; it is in the public domain. The key must be secret. There are two approaches:
Symmetric: one shared secret
There is just one key, a secret shared by sender and receiver. The sender uses the algorithm and the key to encrypt; the receiver decrypts with the same key. The problem is key delivery: how does the secret key reach the receiver securely in the first place?
Asymmetric: a matched pair
Two different keys are used, and only one of them is secret. Someone who owns a key pair sends the public key to anyone who will communicate with them and keeps the private key, which is never sent to anyone. So there is no secret key to deliver.
Usually the key-pair owner wants to receive. A sender encrypts the plaintext with the receiver's public key. Because the keys are a matched pair, only the receiver's private key can decrypt it. Any number of people can have the public key and all of them can send private messages to the receiver.
- For two-way communication, both people need their own key pair and must send their public key to the other.
- To keep an intercepted message confidential, the algorithm must be complex and the key must have a large number of bits.
🎮 Which key is used?
Alice sends to Bob. Pick the key that does the job.
One method an unauthorised person can use to decrypt a message is a brute-force attack: trying every possible value of the key. Calculate how long it would take to try all possibilities for a 64-bit or a 128-bit key, assuming each attempt takes 1 second.
🔬 Lab: brute-force calculator
Set the key length and how fast the attacker can try keys.
- A 64-bit key has 264 ≈ 1.8 × 1019 possible values. At 1 per second that is 1.8 × 1019 s ÷ (60 × 60 × 24 × 365) ≈ 5.8 × 1011 years (about 585 billion years).
- A 128-bit key has 2128 ≈ 3.4 × 1038 values: about 1.1 × 1031 years.
- On average the attacker finds the key halfway through, but that only halves these times. Each extra bit doubles the work.
That still does not fully explain how encryption works in practice. The missing piece is an organisation that provides keys and makes sure they are delivered safely, which is the next section.
✍️ 21.02 Digital signatures
Asymmetric keys also work the other way round. Someone can encrypt a message with their private key, and anyone with the matching public key can decrypt it. That is useless for secrets, because anyone might have the public key. But it proves who sent it: only the sender has the private key, and the public key only works with that one private key. If decryption succeeds, the message has in effect arrived with a digital signature.
Encrypting the whole message just to sign it is slow. Instead the sender uses a public cryptographic one-way hash function, which produces a number that is uniquely defined for that particular message, called the digest.
- The sender hashes the message to get the digest.
- The sender encrypts the digest with their private key. The encrypted digest is the digital signature.
- The message goes as plaintext, with the signature as a separate file. The digest is much smaller than the message, so encrypting and sending it is quicker.
- The receiver hashes the received message with the same public hash function.
- The receiver decrypts the signature with the sender's public key, which gives the original digest.
- If the two digests are identical, the message is authentic and was transmitted unaltered.
A digital signature is different every time, because the digest depends on the message it was made from.
🔬 Lab: sign it, tamper with it, verify it
A toy version with tiny numbers. The hash is a 16-bit toy hash reduced mod n, and Alice's RSA key pair is n = 3233, e = 17 (public), d = 2753 (private). Real systems use SHA-256 and 2048-bit keys, but the steps are the same.
📜 Digital certificates Figure 21.04
A signature only proves the message came from whoever sent you that public key. Someone could make a key pair and pretend to be someone else. Stricter authentication comes from a Certification Authority (CA), part of a Public Key Infrastructure (PKI).
A would-be receiver, person A, has a public–private key pair and wants senders to be confident of A's identity. To obtain a digital certificate:
- Person A, who has a public–private key pair, contacts a local CA.
- The CA confirms the identity of person A.
- Person A's public key is given to the CA.
- The CA creates a public-key certificate (a digital certificate) and writes person A's public key into it.
- The CA uses encryption with the CA's private key to add a digital signature to the certificate.
- The digital certificate is given to person A.
- Person A posts the digital certificate on a website, either their own or one designed for keeping certificate data.
Anyone who wants the public key from the certificate has to use the CA's public key. All of this needs agreed standards for the PKI and for certificates; the standard is called X.509.
Two similar processes have been described. In one, someone with a private key sends a public key to someone else. In the other, the CA sends a digital certificate containing a public key. Don't confuse them.
🎮 Put the certificate steps in order
Use the arrows to move each step. Then check.
🗂️ The options, summarised
- Start with someone who has a public–private key pair for a particular asymmetric algorithm.
- They could just make the public key available to anyone who will send or receive.
- For the best security they send the public key to a Certification Authority instead.
- The CA creates a digital certificate containing the public key with proof of who owns it.
- Anyone who wants the public key gets it from this certificate.
- A message encrypted with the public key can be sent to the owner of the private key.
- A message encrypted with the private key can be sent to anyone who has the public key.
- The private-key owner can create a digital signature to authenticate an email (Chapter 9, Section 9.03).
🧮 21.03 Symmetric key encryption methods
For many years the Data Encryption Standard (DES) was the usual choice for symmetric key encryption. When DES became too weak, Triple DES took its place. In 2001 the Advanced Encryption Standard (AES) was introduced as a better approach. For teaching only, a simplified DES (S-DES) shows the kind of operations encryption performs.
S-DES is a block cipher: it encrypts blocks of bits, here 8-bit blocks, using a 10-bit key.
Stage 1: make two 8-bit keys from the 10-bit key
| Step | Rule | Book's example |
|---|---|---|
| Chosen 10-bit key | — | 0101010101 |
| Permutation (reorder the bits) | 3 5 2 7 4 10 1 9 8 6 | 0010110011 |
| Circular left shift of the first 5 bits and of the last 5 bits | shift each half by 1 | 0101000111 |
| Permutation to 8 bits → first key K1 | 6 3 7 4 8 5 10 9 | 00011011 |
Bit positions are numbered left to right, so the permuted key takes the old bit 3, then the old bit 5, and so on. A slightly modified version of the same steps makes the second key, K2.
Stage 2: encrypt, in five steps
- An initial permutation.
- A function applied using the permuted code and the first key, K1.
- A switch of the first and last 4-bit halves.
- The function applied again, this time with the second key, K2.
- A final permutation, the reverse of the initial one.
Decryption uses the same two keys and follows the process in reverse.
🔬 Lab: S-DES, bit by bit
Tap bits to change them. The key starts as the book's example. The book does not print every table, so the lab uses the standard S-DES tables (Schaefer's): K2 comes from a further 2-place left shift of each half, then the same 8-bit permutation.
10-bit key
8-bit plaintext block
AES
AES uses a 128-bit block, and the user can choose a 128, 192 or 256-bit key. The chance of working out the key from transmitted ciphertext is small. The main worry is how to get the key safely to both sender and receiver.
Would you like to investigate S-DES further? You could attempt an encryption and decryption.
With the standard S-DES tables, key 1010000010 gives K1 = 10100100 and K2 = 01000011. The plaintext 01110010 encrypts to 01110111, and decrypting 01110111 with K2 first, then K1, gives 01110010 back. Type these into the lab to check every stage.
🗝️ 21.04 Public key encryption methods
RSA (Rivest–Shamir–Adleman), the usual public key method, is named after its three creators. Its main parts are the key generation algorithm and the encryption function.
Key generation
- Choose two very large prime numbers, p and q, and calculate their product n.
- Calculate (p−1)(q−1).
- Choose a prime e less than (p−1)(q−1) that is not a factor of it (65537 is the usual choice).
- Find a number d such that d × e divided by (p−1)(q−1) leaves a remainder of 1.
- The public key is the pair (n, e).
- The private key is the pair (n, d).
RSA is secure because factorising a very large number is not feasible in any reasonable time. Working out n from p and q is easy, but finding p and q from n is not.
RSA works on numbers, so text is first turned into numbers with a sensible coding scheme. A number x is encrypted to y by
y = xe mod n
and a similar relationship using d instead of e decrypts it.
Public key encryption is inherently more secure than symmetric encryption, but its algorithms are slower. So public key encryption is often used just to deliver a key securely, and that key is then used for symmetric encryption.
🔬 Lab: make an RSA key pair and use it
Tiny primes, so you can see every number. Each character is coded as its ASCII value, which needs n > 127.
🌐 21.05 SSL and TLS
When you visit a website there are two worries: is the website genuine, and is it safe to send it sensitive personal data, for example to buy something? The Secure Socket Layer (SSL) protocol was created to reassure the user of a client–server application.
As described in Chapter 17 (Section 17.04), an application talks to TCP through a port number. An IP address plus a port number is called a socket. SSL adds an extra layer between TCP in the transport layer and the application layer. With SSL in place, HTTP becomes HTTPS.
Facts about SSL
- Although it is called a protocol, SSL is really a protocol suite.
- The Record Protocol deals with the format of data transmission.
- The Handshake Protocol is responsible for security.
- SSL works without any action from the user.
- It starts with TCP establishing a connection between client and server.
- The client browser then invokes the Handshake Protocol from the SSL suite.
- The Handshake Protocol asks the server for its SSL certificate, a digital certificate confirming its identity.
- The server sends this certificate plus its public key.
- The browser uses that public key to encrypt a one-off session key, used for symmetric encryption of the data transferred during the session.
- The two sides may also need to agree at this point which encryption algorithms to use.
SSL was originally proprietary. The Internet Engineering Task Force (IETF) took it over to produce a standard version, which reached version 3.0. When an improved version was needed, the IETF gave it a new name: Transport Layer Security (TLS), the upgraded version recommended because of security concerns with SSL. Even so, SSL is still in general use.
🔬 Lab: step through a handshake
Watch what each side knows after every message.
💻 Browser (client)
🖥️ Web server
Encryption has always been controversial. Two aspects matter most: should powerful, unbreakable encryption algorithms be available to the public, and what about key escrow, which lets governments access all secret keys? Think about how this connects with Chapter 9 and Chapter 10.
- For strong public encryption: privacy is a right; online banking, shopping and medical records depend on it; weakened encryption can be exploited by criminals as well as governments.
- For key escrow: police and security services could read the messages of criminals and terrorists with a court order.
- Against key escrow: the store of keys becomes a single, very attractive target; it may be misused for surveillance; criminals can simply use non-escrowed software.
- Links: data protection laws and privacy (Chapter 9), and professional ethics (Chapter 10).
⚛️ 21.06 Quantum cryptography
Light is carried by particles called photons. Photons behave like waves, so each one vibrates in a particular direction at right angles to its direction of travel. That direction is its polarisation, drawn as a double-ended arrow. A photon can be created with a chosen polarisation to represent a bit. With four possible polarisations there are two ways to show a 1 and two ways to show a 0:
A sender and receiver can use this to create a shared secret code made of bits:
Table 21.01 Creation of a ‘shared secret’ code, rebuilt with a photon row added. Matching bases are green. The original table is below.
- Row 1 is the bit sent; row 2 is the basis used: + for vertical/horizontal, × for the diagonal pair.
- The sender picks the bit pattern and the basis for each bit at random.
- Row 3 is the receiver's choice of basis for each photon, also random.
- After the transmission the sender tells the receiver which basis was used for each value. The receiver replies saying which ones matched. Each match gives a stored bit, so here the shared secret is 1001.
This scheme is used in Quantum Key Distribution (QKD) systems. QKD is another way to transfer a key that is then used for symmetric encryption in the normal way. Its advantage is that nothing is transferred except photons. Anyone who intercepts them to find their polarisation will, by the laws of quantum mechanics, destroy them: a photon cannot be detected and measured and then sent on again.
The main drawback is that QKD cannot use standard communication media. It needs a dedicated, special-purpose quantum channel between sender and receiver, which is very expensive, so routine use is unlikely. Quantum computing progress is slow, but QKD is one of the few areas with real success.
🔬 Lab: build a shared secret with photons
Random bits and bases, just like the table. Switch on Eve to see why an eavesdropper gives herself away: she has to measure, guess a basis and resend, which spoils some bits.
The idea of a ‘shared secret’ has also been used in traditional encryption schemes, for example the Diffie–Hellman key agreement method. Investigate the principles behind how it works.
🔬 Lab: Diffie–Hellman with small numbers
Public: prime p = 23 and base g = 5. Alice and Bob each pick a secret number and never send it.
- Both sides agree, in public, a large prime p and a base g.
- Alice picks a secret a and sends A = ga mod p; Bob picks a secret b and sends B = gb mod p.
- Alice works out Ba mod p and Bob works out Ab mod p. Both equal gab mod p, so they now share a secret that was never transmitted.
- An eavesdropper sees p, g, A and B, but getting a or b from them (the discrete logarithm problem) is not feasible for large numbers.
- The shared secret is then used as, or to make, a symmetric key. On its own Diffie–Hellman does not prove identity, so it is combined with certificates or signatures to stop a man-in-the-middle.
Chapter 21 has some difficult ideas. Have you made sure you understand the overriding principles and the definitions used? Try the flashcards in the next tab.
📌 Summary
- Encryption converts plaintext to ciphertext; decryption reverses the process.
- The five main security concerns when transmitting messages are confidentiality, authenticity, integrity, non-repudiation and availability.
- Encryption can be symmetric, using one key, or asymmetric, using two different keys.
- Authentication can be achieved using a digital signature and a digital certificate.
- A digital certificate is provided by a certification authority within a public key infrastructure.
- DES and AES are examples of symmetric key encryption.
- RSA is an important asymmetric key method. (The book misprints it as “RAS” here.)
- Secure Socket Layer (SSL), which became Transport Layer Security (TLS), provides security when accessing a website.
- Quantum Key Distribution systems use polarised photons.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
📝 Exam-style questions
Write your answer first, then open the model answer. These are my mark-scheme-style points, not official mark schemes.
- Confidentiality: only the intended recipient can read the data / decrypt the ciphertext; an interceptor cannot understand it.
- Authenticity: the receiver can be certain who sent the data; the sender is who they claim to be.
- Integrity: the data has not been changed during transmission…
- …whether by deliberate tampering or by accidental corruption.
Symmetric:
- There is one secret key, shared by sender and receiver.
- The same key is used to encrypt and to decrypt.
- The key has to be delivered securely to the receiver beforehand, which is the weakness.
Asymmetric:
- The receiver owns a matched pair: a public key and a private key.
- The public key is given to anyone who wants to send; the private key is never sent to anyone.
- The sender encrypts with the receiver's public key; only the receiver's private key can decrypt it.
- For two-way communication each person needs their own key pair.
- Signature: the sender hashes the message to make a digest and encrypts the digest with their own private key.
- The receiver decrypts the signature with the sender's public key and hashes the received message again.
- Matching digests show the message is authentic and unaltered.
- Certificate: issued by a Certification Authority after it has checked the owner's identity.
- It contains the owner's public key and is signed with the CA's private key, so anyone can check it with the CA's public key and trust that the public key really belongs to that person.
- A set of related protocols that work together…
- …each handling one part of the job: in SSL the Record Protocol formats the data being transmitted and the Handshake Protocol handles security.
- Together they form a layer between TCP (transport layer) and the application layer.
- A client (web browser) communicating with a web server, i.e. a client–server application.
- Where the user must be sure the website is genuine…
- …and is sending sensitive or personal data, such as card details when buying online, online banking, or logging in with a password.
- The web address uses HTTPS instead of HTTP, and it all happens without any action from the user.
- The browser's Handshake Protocol asks the server for its SSL certificate.
- The server sends the certificate, issued and signed by a CA, with its public key.
- The browser checks the CA's signature using the CA's public key; if it is valid, the server's identity is confirmed and its public key can be trusted.
- The server's public key comes with its certificate.
- The browser generates a one-off session key.
- It encrypts the session key with the server's public key and sends it.
- Only the server can decrypt it, using its private key.
- Both sides then use the session key for symmetric encryption of all data in that session; the algorithms are agreed during the handshake.
- Asymmetric encryption is only used to deliver the key because symmetric encryption is much faster.
Any three: the owner's (subject's) name or organisation; the owner's public key; the name of the issuing CA; the CA's digital signature; a serial number; the dates it is valid from and to; the algorithms used.
- (i) public: the public key is what goes into the certificate; a private key is never sent to anyone.
- (ii) public: anyone can get the CA's public key, and only the CA, holding the matching private key, can decrypt the application.
- (iii) private: only the CA has its private key, so a signature made with it proves the certificate came from the CA; anyone can check it with the CA's public key.
(i) A digital signature.
(ii) Beena decrypts the digest with Alexa's public key, taken from Alexa's digital certificate. She hashes the received message herself with the same hash function. If the two digests match, the message has not been changed, and it must have come from Alexa because only Alexa has the private key that made the signature.
(iii) Any two: emails with legal or financial content; contracts and other legal documents; software downloads and updates; online banking transactions; e-government forms such as tax returns.
Cambridge International AS & A Level Computer Science 9608, Paper 31 Q2, June 2016
(i) A set of rules for communication between devices, covering how data is formatted and transmitted.
(ii) A web browser.
(iii) A web server.
(iv) Any two: data being intercepted and read (confidentiality); a fake website pretending to be genuine (authenticity); data being altered in transit (integrity).
Any two, each with a description:
- Protocol version: which version of SSL/TLS both sides support and will use.
- Encryption algorithm (cipher suite): the symmetric algorithm for the data, e.g. AES.
- Key exchange method: how the session key is delivered, e.g. RSA or Diffie–Hellman.
- Hash / MAC algorithm: used to check the integrity of each message.
- Session key: the one-off key generated for this session only.
Any two: email clients and servers; instant messaging; voice over IP (VoIP) / video calls; secure file transfer (FTPS); VPNs; mobile banking apps. (The book prints “SSL of TLS”; it means “SSL or TLS”.)
Cambridge International AS & A Level Computer Science 9608, Paper 32 Q4, November 2016
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 21 Security · Figures from the Cambridge coursebook (Langfield & Duddell)