Lesson 2 of 5 Cryptographic Solutions

Symmetric and Asymmetric Cryptography

Symmetric and asymmetric cryptography solve different problems and are usually combined. This lesson explains each, elliptic curve cryptography and hybrid encryption.

Learning outcomes

After completing this lesson, you will be able to:

  • Compare symmetric and asymmetric cryptography.
  • Calculate the number of keys needed for a group of users.
  • Explain hybrid cryptography and forward secrecy.

Symmetric cryptography

Symmetric (secret key) cryptography uses the same key to encrypt and decrypt. It is fast and suits bulk data. The Advanced Encryption Standard (AES), with 128, 192 or 256-bit keys and a 128-bit block size, is the standard block cipher; ChaCha20 is a widely used stream cipher. Older algorithms include DES (56-bit key, broken), 3DES (retired), Blowfish, Twofish and IDEA.

Block ciphers need a mode of operation. ECB encrypts each block independently and leaks patterns, so it should not be used; CBC chains blocks with an IV; CTR turns the block cipher into a stream cipher; and GCM provides authenticated encryption, adding integrity to confidentiality. Symmetric cryptography's weaknesses are key distribution (both parties need the key securely) and scale: n users need n(n-1)/2 keys for every pair to communicate privately. It also cannot provide nonrepudiation.

The weakness of ECB mode is easy to see. Because each 16-byte block is encrypted independently with the same key, identical plaintext blocks always produce identical ciphertext blocks. An image encrypted in ECB mode still shows the outline of the original picture, because areas of the same colour encrypt to the same repeated pattern. CBC avoids this by combining each plaintext block with the previous ciphertext block before encryption, starting from a random IV, so repeated plaintext no longer produces repeated ciphertext.

Authenticated encryption matters because confidentiality alone does not stop tampering. In CBC or CTR mode without a separate integrity check, an attacker who cannot read the message can still flip chosen bits of the ciphertext, which changes predictable bits of the decrypted plaintext, for example altering an amount in a payment message. GCM and similar modes compute an authentication tag over the ciphertext, and decryption fails if anything has been changed.

The scale problem grows quickly. Ten users need 45 keys for every pair to communicate privately; 1,000 users need 499,500. With asymmetric cryptography, the same 1,000 users need 2,000 keys, a public and private key each. This difference is the main reason asymmetric cryptography exists.

Scenario questions

Choosing a mode

Exam skills 3.6.2

Choose the block cipher mode or algorithm that fits each case.

Log in to try this activity Interactive activities are free with an account.

Asymmetric and elliptic curve cryptography

Asymmetric (public key) cryptography uses a key pair: a public key that can be shared freely and a private key that only the owner holds. Data encrypted with the public key can be decrypted only with the private key, which provides confidentiality; data signed with the private key can be verified with the public key, which provides authenticity and nonrepudiation. Each user needs only one key pair, so n users need 2n keys.

RSA relies on the difficulty of factoring large numbers and is used for encryption of small data, key transport and signatures. Diffie-Hellman lets two parties agree a shared secret over an insecure channel but does not authenticate them, so it must be combined with authentication to stop man-in-the-middle attacks. Elliptic curve cryptography (ECC), such as ECDH and ECDSA, provides equivalent security with much smaller keys, which suits mobile and IoT devices. Asymmetric operations are much slower than symmetric ones.

A small-number example shows how Diffie-Hellman lets two parties agree a secret without ever sending it. Alice and Bob publicly agree on a prime p = 23 and a base g = 5. Alice chooses a private value a = 6 and sends Bob A = 56 mod 23 = 8. Bob chooses b = 15 and sends Alice B = 515 mod 23 = 19. Alice computes 196 mod 23 = 2, and Bob computes 815 mod 23 = 2. Both now hold the shared secret 2, while an eavesdropper who saw only 23, 5, 8 and 19 would have to solve the discrete logarithm problem to find a or b. With numbers hundreds of digits long, that is infeasible for classical computers.

The same example shows the weakness. Nothing in the exchange proves that the value 19 came from Bob. An attacker in the middle could replace it with their own value and run a separate exchange with each party, which is why Diffie-Hellman in practice is always authenticated, for example by signing the exchanged values with a key bound to a certificate. The following figures summarise key sizes of comparable strength and the number of keys each approach needs.

128bits

AES key; strength comparable to RSA-3072

256bits

ECC key; strength comparable to RSA-3072

n(n-1)/2keys

Symmetric keys for n users

2nkeys

Asymmetric keys for n users

Fill in the value

Keys and Diffie-Hellman

Exam skills 3.6.2

Work through key counts and a small Diffie-Hellman exchange.

Log in to try this activity Interactive activities are free with an account.

Hybrid cryptography

Real systems combine both. In hybrid cryptography, asymmetric techniques authenticate the parties and establish a random symmetric session key, which then encrypts the bulk data efficiently. TLS works this way: an ephemeral Diffie-Hellman exchange authenticated by the server's certificate creates session keys, providing forward secrecy, so that compromising the server's long-term key later does not expose past sessions. Email encryption with S/MIME or PGP encrypts the message with a symmetric key and that key with each recipient's public key.

Symmetric
KeysOne shared secret key
SpeedFast
Main usesBulk encryption
NonrepudiationNo
Keys for n usersn(n-1)/2
Asymmetric
KeysPublic and private key pair
SpeedSlow
Main usesKey exchange, signatures, small data
NonrepudiationYes, with signatures
Keys for n users2n

The following diagram shows which key is used at each step of a signed, confidential message.

The keys used to send a signed, confidential message. The sender signs a hash with their private key, encrypts the message and signature with a random session key, and encrypts the session key with the recipient's public key. The recipient decrypts the session key with their private key, decrypts the message and verifies the signature with the sender's public key.
The session key is symmetric; the key pairs are asymmetric.
Put in order

Encrypting an email for two recipients

Exam skills 3.6.2

Arrange how S/MIME or PGP combines symmetric and asymmetric encryption.

Log in to try this activity Interactive activities are free with an account.
Worked example

Which key to use

Alice wants to send Bob a confidential contract and prove that it came from her. Which keys are used, and in what order?

To prove origin, Alice signs a hash of the contract with her private key. For confidentiality, she encrypts the contract (and signature) with a random symmetric session key, and encrypts that session key with Bob's public key. Bob decrypts the session key with his private key, decrypts the contract, and verifies the signature with Alice's public key. Encrypting with Alice's private key would not provide confidentiality, because anyone with her public key could decrypt it.

Check yourself

How many symmetric keys do 10 users need so every pair can communicate privately?

Show answer

10 x 9 / 2 = 45 keys.

Exam Tips

Remember for the exam

  • Encrypt for confidentiality with the recipient's public key.
  • Sign with your own private key.
  • n users: n(n-1)/2 symmetric keys, 2n asymmetric keys.
  • Never use ECB mode; prefer authenticated modes such as GCM.