studyhubInformation Assurance & Security

Notes / Module 18

Cryptography

Cryptography protects data on the wire: encryption hides it, hashes and signatures prove it was not changed and who sent it, and PKI says whose public key you are holding. The exam asks you to pick the right tool for each goal, and to do RSA and Diffie-Hellman by hand with small numbers.

18.1.1Symmetric and asymmetric encryption

Two classes of encryption provide data confidentiality, and they differ only in how they use keys. Symmetric algorithms use one pre-shared key to both encrypt and decrypt. Asymmetric algorithms use a key pair, so what one key encrypts only the other can decrypt.

Symmetric — one shared secret key

plaintext→encrypt with K→ciphertext→decrypt with K→plaintext

Asymmetric, for confidentiality — anyone can lock, only Bob can open

plaintext→encrypt with Bob's public key→ciphertext→decrypt with Bob's private key→plaintext

Asymmetric, for authentication — only Alice can lock, anyone can open

data→encrypt with Alice's private key→ciphertext→decrypt with Alice's public key→proves it came from Alice
One shared key on the left, a public and private key pair on the right.
FeatureSymmetricAsymmetric
KeysOne shared (pre-shared) secret keyPublic and private key pair
Key lengthShort, 40–256 bitsLong, 512–4096 bits
SpeedFast, low CPUSlow, computationally taxing
ExamplesDES, 3DES, AES, SEAL, RC seriesRSA, DH, DSA/DSS, ElGamal, elliptic curve
Typically used forBulk data such as VPN trafficQuick transactions such as HTTPS, digital signatures, key exchange

A pre-shared key, also called a secret key, is known by sender and receiver before any encrypted communication takes place. Symmetric algorithms suit VPNs because they use less CPU, so encryption and decryption stay fast. For symmetric keys, most are 112–256 bits and the minimum safe length is 128 bits; the longer the key, the longer it takes someone to discover it.

Block cipher
Transforms a fixed-length block of plaintext (64 or 128 bits) into ciphertext. DES uses 64-bit blocks, AES uses 128-bit blocks.
Stream cipher
Encrypts one byte or bit at a time. Basically a block cipher with a block size of one byte or bit, and typically faster because data is encrypted continuously. Examples: RC4 and A5 (GSM cell phones).
DES
Legacy symmetric algorithm with a short key. Must not be used.
3DES
The DES replacement; repeats the DES process three times. Avoid if possible (scheduled to be retired in 2023). If used, keep key lifetimes very short.
AES
Popular and recommended. 128-, 192- or 256-bit keys, encrypting 128-bit blocks (the NetAcad table says 128, 192 or 256-bit blocks, but its block-cipher section and the AES standard say 128).
SEAL
Software-Optimized Encryption Algorithm: a faster alternative to AES. A stream cipher with a 160-bit key and lower CPU impact.
RC series
Developed by Ron Rivest. RC4 was the most prevalent, a stream cipher once used for web traffic, but it has multiple vulnerabilities. Do not use.

Asymmetric algorithms are also called public-key algorithms. The decryption key cannot be calculated from the encryption key in any reasonable time. Because neither party has a shared secret, keys must be long: 2,048 bits or more can be trusted, 1,024 bits or shorter is insufficient. Their security rests on hard problems such as factoring huge numbers or computing discrete logarithms.

Because they are slow, asymmetric algorithms are used for low-volume jobs: digital signatures and key exchange. Their one advantage is simpler key management, since one of the two keys can be made public. Protocols that use them: IKE (core of IPsec VPNs), SSL/TLS, SSH and PGP.

AlgorithmKey lengthNotes
Diffie-Hellman (DH)512–4096Two parties agree on a shared key; encrypts nothing itself
DSS / DSA512–1024DSS specifies DSA for digital signatures; signing speed similar to RSA, verification 10 to 40 times slower
RSA512–2048Based on the difficulty of factoring very large numbers; first algorithm known to suit signing as well as encryption
ElGamal—Based on DH key agreement; ciphertext is about twice the message size, so only used for small messages such as keys
Elliptic curve224 or higherAdapts DH or ElGamal; main advantage is much smaller keys

18.1.4What each key does: confidentiality, authentication, integrity

Which key you encrypt with decides which goal you get. The pair works in both directions, but the complementary key is always needed to decrypt.

GoalEncrypt withDecrypt withWhy it works
ConfidentialityReceiver's public keyReceiver's private keyOnly the receiver holds the private key, so only the receiver can read it
AuthenticationSender's private keySender's public keyOnly the sender holds the private key, so only the sender could have produced it; anyone can verify with the public key
  1. Confidentiality. Alice gets Bob's public key, encrypts the message with it, and sends it. Only Bob's private key decrypts it. If the private key is compromised, generate a new key pair.
  2. Authentication. Alice encrypts with her own private key. Bob requests Alice's public key and decrypts. Success proves the message came from Alice.
  3. Both, plus integrity. Alice encrypts the message with Bob's public key (confidentiality) and encrypts a hash of the message with her private key (authenticity and integrity). Bob decrypts the hash with Alice's public key, hashes the message himself, and compares the two.

18.1.3RSA

RSA (Rivest, Shamir, Adleman, 1977) is a public-key algorithm built from two prime numbers. Its security rests on the difficulty of factoring n back into p and q. It is used for encryption, digital signatures and key exchange, with typical key sizes of 2048–4096 bits; 512-bit keys are easily broken.

  1. Pick two primes p and q.
  2. Compute the modulus n = p × q (part of both keys).
  3. Compute φ(n) = (p − 1)(q − 1).
  4. Pick public exponent e with 1 < e < φ(n) and gcd(e, φ(n)) = 1.
  5. Find private exponent d where (d × e) mod φ(n) = 1.
  6. Public key = (e, n). Private key = (d, n).

n = p × q

n
the modulus, shared by the public and private key
p, q
two prime numbers, kept secret

φ(n) = (p − 1)(q − 1)

φ(n)
Euler's totient of n, used only to find d and never published

e · d ≡ 1 (mod φ(n))

e
public exponent
d
private exponent, the modular inverse of e

e must satisfy gcd(e, φ(n)) = 1 or no d exists. For large numbers d is found with the Extended Euclidean Algorithm, not trial and error; real keys commonly use e = 65537.

C = Mᵉ mod n

C
ciphertext
M
plaintext message, as a number smaller than n

M = Cᵈ mod n

d
private exponent; only the key owner has it

For signing, swap the keys: sign with the private key d, verify with the public key e.

Try it

n = p × q3 × 11 = 33
φ(n) = (p − 1)(q − 1)2 × 10 = 20
gcd(e, φ(n))gcd(3, 20) = 1 ✓
e · d ≡ 1 (mod φ(n))d = 7, since 3 × 7 = 21 = 1·20 + 1
public key(e, n) = (3, 33)
private key(d, n) = (7, 33)
C = Mᵉ mod n43 mod 33 = 31
M = Cᵈ mod n317 mod 33 = 4
Pick p, q and e, then watch n, φ(n), d, encryption and decryption update.

Worked example

p = 3, q = 11, M = 4

  1. 1n = 3 × 11 = 33.
  2. 2φ(n) = (3 − 1)(11 − 1) = 2 × 10 = 20.
  3. 3Choose e = 3, since gcd(3, 20) = 1.
  4. 4Find d: 3 × 7 = 21 and 21 mod 20 = 1, so d = 7. Public key (3, 33), private key (7, 33).
  5. 5Encrypt: C = 4³ mod 33 = 64 mod 33 = 31.
  6. 6Decrypt: M = 31⁷ mod 33. Since 31 ≡ −2 (mod 33), (−2)⁷ = −128, and −128 mod 33 = 4. The original message 4 is back.

Worked example

Practice: p = 7, q = 11, e = 7. Find n, φ(n), d and encrypt M = 2

  1. 1n = 7 × 11 = 77.
  2. 2φ(n) = 6 × 10 = 60. Check gcd(7, 60) = 1, so e = 7 is valid.
  3. 3Find d: 7 × 43 = 301 = 5 × 60 + 1, so 301 mod 60 = 1 and d = 43.
  4. 4Encrypt: C = 2⁷ mod 77 = 128 mod 77 = 51.
  5. 5Answer: n = 77, φ(n) = 60, d = 43, C = 51.

Modular exponent tip. Break a big power into squares (x², x⁴, x⁸), reduce mod n after every step, then multiply only the pieces you need. Negative equivalents save arithmetic: 31 ≡ −2 (mod 33). Computers use the same idea (exponentiation by squaring), which needs only about log n steps.

18.1.7Diffie-Hellman

Diffie-Hellman (DH), 1976, lets two computers generate an identical shared secret without having communicated before. The shared key is never actually sent; both sides compute it. Because the secret is only agreed, not delivered by encryption, DH encrypts nothing itself. It is used with IPsec VPNs (IKE), SSH and TLS, and the bulk traffic is then encrypted with a symmetric algorithm such as 3DES or AES.

Security rests on the discrete logarithm problem: raising a number to a power is easy, but given g, p and gᵃ mod p, finding a is infeasible for large primes. An eavesdropper may know p, g, A and B and still cannot get the secret.

  1. Both agree publicly on a prime p and a base g (neither is secret).
  2. Alice picks secret a; Bob picks secret b.
  3. Alice sends A = gᵃ mod p; Bob sends B = gᵇ mod p.
  4. Alice computes s = Bᵃ mod p; Bob computes s = Aᵇ mod p. Both get the same s.

A = gᵃ mod p

A
Alice's public value, sent in the open
g
public base
a
Alice's private key
p
public prime

B = gᵇ mod p

B
Bob's public value, sent in the open
b
Bob's private key

s = Bᵃ mod p = Aᵇ mod p = gᵃᵇ mod p

s
the shared secret, never transmitted; used as a symmetric key

Try it

Alice — keeps a private

a6
A = gᵃ mod p56 mod 23 = 8
s = Bᵃ mod p196 mod 23 = 2

On the wire — anyone can read

p, g23, 5
A →8
← B19

Bob — keeps b private

b15
B = gᵇ mod p515 mod 23 = 19
s = Aᵇ mod p815 mod 23 = 2

Both reach s = 2; it never crossed the wire. An eavesdropper holding p, g, A and B would have to find a or b — the discrete logarithm problem.

Change p, g, a and b and see both sides reach the same secret.

Worked example

p = 23, g = 5, a = 6, b = 15

  1. 1Alice: A = 5⁶ mod 23. 5² = 25 → 2; 5⁴ = 2² = 4; 5⁶ = 4 × 2 = 8.
  2. 2Bob: B = 5¹⁵ mod 23. 5⁸ = 4² = 16; 5¹⁵ = 5⁸ × 5⁴ × 5² × 5 = 16 × 4 × 2 × 5 = 640, and 640 − 621 = 19.
  3. 3Alice receives B = 19: s = 19⁶ mod 23. 19 ≡ −4, so (−4)⁶ = 4096, and 4096 − 4094 = 2.
  4. 4Bob receives A = 8: s = 8¹⁵ mod 23. 8² → 18, 8⁴ → 2, 8⁸ → 4, so 4 × 2 × 18 × 8 = 1152, and 1152 − 1150 = 2.
  5. 5Both reach s = 2 without ever sending it.

Worked example

Practice: p = 11, g = 2, a = 3, b = 4. Find A, B and s

  1. 1A = 2³ mod 11 = 8.
  2. 2B = 2⁴ mod 11 = 16 mod 11 = 5.
  3. 3Alice: s = Bᵃ = 5³ mod 11 = 125 mod 11 = 4.
  4. 4Bob: s = Aᵇ = 8⁴ mod 11 = 4096 mod 11 = 4 (8² = 64 → 9, 9² = 81 → 4). Both agree.
  5. 5Answer: A = 8, B = 5, s = 4.

DH groups set the strength of the key agreement. Higher group numbers are more secure but take longer to compute.

DH groupSize
Group 1768 bits
Group 21024 bits
Group 51536 bits
Group 142048 bits
Group 153072 bits
Group 164096 bits
Groups 19, 20, 24Based on elliptic curve cryptography
RSADiffie-Hellman
PurposeEncryption, signatures, key exchangeKey agreement only
Hard problemFactoring nDiscrete logarithm
KeysFixed public/private pairFresh secrets per session possible
AuthenticationYes, via signaturesNone alone; needs RSA/DSA signatures or certificates

18.2Obscuring data: masking and steganography

Data masking replaces sensitive data with realistic, non-sensitive versions that applications still accept. It is commonly used in non-production environments and test data sets, and can be applied dynamically when a risky request is detected.

Substitution
Authentic-looking values replace the real ones.
Shuffling
The substitution set is drawn from the same column.
Nulling out
A null value completely prevents visibility.

Steganography hides that a message exists at all, by concealing it in a graphic, audio or video file, so it draws no extra attention. Cryptography scrambles a message you can see; steganography makes nobody look for one.

Embedded data
The secret message.
Cover
The text, image or audio that hides it; the result is the stego text, image or audio.
Stego key
Controls the hiding process.
LSB method
Hides message bits in the least significant bit of each pixel's red, green and blue values. A 24-bit colour pixel stores three bits, and the eye cannot see the change.
Social steganography
A message hidden in plain sight by prior agreement, e.g. 'going to the movies' secretly means 'going to the beach'.
Steganalysis
Discovering hidden information, e.g. comparing an original image with the stego image, disk utilities reporting hidden data in unused clusters, or filters catching data in packet headers.

18.3.1The four goals of secure communication

Data crossing links, especially to branch, telecommuter and partner sites, needs four guarantees. Each has a tool that provides it.

GoalGuaranteesProvided by
Data integrityThe message was not altered; any change in transit is detectedHashing: SHA-2 or SHA-3 (avoid MD5)
Origin authenticationThe message is not a forgery and comes from whom it statesHMAC; digital signatures
Data confidentialityOnly authorised users can read it; interception does not help within a reasonable timeSymmetric and asymmetric encryption
Data non-repudiationThe sender cannot refute having sent the message, because only the sender has the unique signatureDigital signatures

18.3.2Hash functions and HMAC

A hash function takes data of any length and produces a fixed-length value called the hash, also known as the message digest, digest or digital fingerprint. It is a one-way function: easy to compute, hard to reverse, like grinding coffee beans. Any change to the data changes the hash.

  • The input can be any length.
  • The output has a fixed length.
  • h = H(x) is relatively easy to compute for any given x.
  • One way: given h, it is computationally infeasible to find x with H(x) = h.
  • Collision free: two different inputs give different hashes (a collision is two inputs with the same hash).
HashOutputStatus
MD5128 bitsDeveloped by Ron Rivest. Legacy, avoid; use SHA-2 or SHA-3.
SHA-1160 bitsNSA, 1995. Known flaws, legacy.
SHA-2224, 256, 384 or 512 bitsNSA. Use SHA-256, 384 or 512 where possible.
SHA-3224, 256, 384 or 512 bitsNewest, from NIST; eventual replacement for SHA-2.

To check integrity, the sender attaches the hash to the message; the receiver hashes the message again and compares. A mismatch means the message cannot be trusted. Both the message and the hash travel in plaintext.

HMAC (keyed-hash message authentication code) feeds a secret key into the hash function along with the data. Only parties holding the key can compute the digest, which gives integrity plus origin authentication and defeats man-in-the-middle attacks. HMAC is used in SSL, IPsec and SSH. Cisco routers use it for OSPF authentication: R1 hashes the link-state update with the secret key and sends the result; R2 recomputes it, accepts the update if the hashes match and discards it if not.

18.4Using hashes: files, passwords and salts

  • Verifying files. Cisco publishes MD5 and SHA checksums for IOS images; compare against the hash of the file you hold. If they do not match, the file was tampered with, so do not use it.
  • Digital forensics. The examiner hashes the original media and the bit-for-bit copy; a match establishes fixity (the copy is identical).
  • Passwords. The system stores only the hash, never the password. At login the entered password is hashed and compared with the stored hash.

Stored password hashes are attacked by dictionary attacks (a predefined list of words and phrases) and brute force (every possible combination of characters, which takes a lot of processor time). Attackers also use precomputed tables.

Lookup table
Precomputed hashes of dictionary passwords, stored with the matching password.
Reverse lookup table
Maps each breached hash to the users who have it.
Rainbow table
Sacrifices cracking speed for a smaller table.
Salt
A random string added to the password before hashing, so identical passwords hash differently and precomputed tables fail. Stored beside the hash; it does not have to be secret.
CSPRNG
Cryptographically secure pseudo-random number generator, used to create salts.
Key stretching
Makes each guess very slow, blunting high-end cracking hardware.

Salting rules: make the salt unique per password, never reuse it, make it as long as the hash output, generate it with a CSPRNG, and always hash on the server in a web application.

18.5Digital signatures

A digital signature is a hash encrypted with the sender's private key. It provides authenticity, integrity and non-repudiation using asymmetric cryptography. The signature cannot be forged (authentic), a signed document cannot be altered, the signature cannot be moved to another document (not reusable), and it is as good as a physical signature (non-repudiated).

Sender signs

document→hash→digest→encrypt with sender's private key→signaturesent with the document

Receiver verifies — two digests, compared

signature→decrypt with sender's public key→digest 1

document→hash again→digest 2equal → authentic, unchanged, and the sender can't deny it
Hash the document, encrypt the hash with the private key, verify with the public key.
  1. The sender hashes the document.
  2. The sender encrypts the hash with their private key. The encrypted hash appended to the document is the signature.
  3. The receiver decrypts the signature with the sender's public key and hashes the document independently.
  4. If the two hashes match, the document was sent by the signer and is unchanged since.
DSS algorithmNotes
DSAThe original standard for key pairs and for generating and verifying signatures.
RSAAsymmetric; commonly used for signatures.
ECDSANewer DSA variant with efficient computation, small signatures and minimal bandwidth.
Code signing
Executables are wrapped in a digitally signed envelope. Assures the code is authentic, unmodified since publishing, and undeniably published. FIPS 140-3 says downloadable software is to be digitally signed and verified. It does not mean the code is error or virus free.
Digital certificate
An electronic passport. Verifies an identity and carries the public key used to check the signature.

A certificate verifies who someone is; a signature verifies that something came from that identity.

18.6PKI, certificate authorities and trust

A public key infrastructure (PKI) is the hardware, software, people, policies and procedures needed to create, manage, store, distribute and revoke digital certificates. It supports large-scale distribution and identification of public keys. A certificate authority (CA) is a trusted third party that verifies identity and signs certificates with its private key, like a licensing bureau issuing a driver's licence.

PKI certificate
Holds the owner's public key, its purpose, the CA that issued it, the date range it is valid, and the signature algorithm. The format is defined by X.509 v3, used by SSL/TLS, IPsec (IKE), S/MIME and EAP-TLS.
Certificate store
On the local computer; holds issued certificates and private keys.
Certificate database
Stores all certificates the CA approved.
Registration authority (RA)
NetAcad: a subordinate CA certified by a root CA to issue certificates for specific uses. The study guide words it as the party that verifies identities for the CA.
Self-signed certificate
The CA's own public key, which every PKI system needs to verify certificates the CA issued. Only a root CA can issue one recognised by other CAs; browsers ship with public root certificates.
ClassUsed for
0Testing; no checks performed
1Individuals who need email verification
2Organisations that need proof of identity
3Servers and software signing; independent verification of identity and authority
4Online business transactions between companies
5Private organisations or government security; most trusted

The class number reflects how rigorous the identity check was when the certificate was issued: higher means more trusted.

Trust topologyHow it worksTrade-off
Single-rootOne root CA issues every certificateSimple, but strictly centralised: a single point of failure that is hard to scale
Cross-certifiedPeer CAs establish trust by cross-certifying each otherPeer-to-peer; provides redundancy and no single point of failure
HierarchicalA root CA issues to end users and to subordinate CAsScalable and manageable; the root keeps the community of trust

Hierarchical and cross-certified topologies can be combined into a hybrid infrastructure. Enrolment retrieves the CA certificate in-band over the network, while authenticating it happens out-of-band, for example by telephone. Certificates are revoked when a key is compromised or no longer needed, using one of two methods.

MethodHow it works
CRLA list of revoked certificate serial numbers; PKI entities regularly poll for the current list
OCSPQueries an OCSP server for the status of a certificate; revocation information is pushed immediately to an online database

18.7Applications and impact of cryptography

PKI is used for SSL/TLS peer authentication, IPsec VPNs, HTTPS, 802.1x authentication, S/MIME, secure instant messaging, code signing, the Encrypting File System (EFS), two-factor authentication with smart cards, and securing USB storage devices.

  • Browser warnings come from certificate validity (X.509 v3 specifies a not-before and a not-after date) or from failed signature validation when the CA hierarchy's root certificate is missing from the browser store.
  • An SSL/TLS cipher suite has four components: MAC algorithm, encryption algorithm, key exchange algorithm and authentication algorithm. They can be changed without replacing the whole protocol.
  • Encryption hides threats too. Growing SSL/TLS traffic lets threat actors hide malware, data loss and intrusions, because normal monitoring cannot see inside it. Malware command and control and exfiltration can be hidden the same way.
  • Monitoring encrypted traffic: separate SSL from non-SSL traffic, validate server certificates with CRLs and OCSP, filter HTTPS with antimalware and URL filtering, decrypt through a Cisco SSL Appliance and send it to IPS appliances. For site-to-site VPNs, place the IPS where it sees unencrypted traffic.
  • Attacks can target the algorithms themselves. A cracked algorithm exposes all captured encrypted data.

Check yourself

Answer these out loud, without scrolling up. Any you can't, reread that section — then let the deck mark you.

  1. 1.Which key encrypts and which decrypts when you want confidentiality, and which pair gives authentication?
  2. 2.Why does symmetric encryption carry VPN traffic while asymmetric is kept for signatures and key exchange?
  3. 3.Do RSA by hand for p = 3, q = 11, M = 4: n, φ(n), e, d, C, and decrypt back to M.
  4. 4.Do Diffie-Hellman for p = 23, g = 5, a = 6, b = 15, and say what an eavesdropper sees and why DH still needs authentication.
  5. 5.Why does a plain hash fail against a deliberate attacker, and what does HMAC add?
  6. 6.Describe how a digital signature is created and verified, and what PKI adds to it.