Latest / CyberCode Academy / Course 17 - Computer Network Security Protocols And Techniques | Episode 3: Modern Ciphers: Structure, Standards (DES/AES)
Transcript
- 0:00Speaker 1: If you are relying on any part of your modern
- 0:02Speaker 1: digital life, I mean secure payments, streaming, high definition audio
- 0:06Speaker 1: and video, we're just sending a private text. You are
- 0:09Speaker 1: relying on this massive, invisible fortress of mathematical secrets.
- 0:14Speaker 2: And what's really crucial to realize is that for centuries,
- 0:18Speaker 2: secrets were about manipulating the alphabet, you know, substituting A
- 0:21Speaker 2: for D, scrambling letters around. But now your entire digital
- 0:26Speaker 2: world is binary. It's just streams of zeros and ones.
- 0:29Speaker 2: So modern cryptography has to be about manipulating bits.
- 0:33Speaker 1: That's the core realization, isn't it. We're not jumbling characters anymore.
- 0:37Speaker 1: We are jumbling bits at light speed. And the really
- 0:40Speaker 1: fantastic trick here is that the algorithm's protecting trillions of
- 0:43Speaker 1: dollars today. Like AES. They aren't based on one giant
- 0:47Speaker 1: complex equation.
- 0:48Speaker 2: No, not at all. They are simply an intricate, relentless
- 0:51Speaker 2: combination of four or five incredibly basic, simple digital operations.
- 0:56Speaker 1: It's simplicity layered into complexity exactly.
- 0:59Speaker 2: So we're going to break down those fundamental building blogs
- 1:01Speaker 2: first and then show you how they combine to create
- 1:04Speaker 2: the most secure encruption standards. In the world.
- 1:06Speaker 1: Okay, let's unpack this and start with the simplest, most
- 1:09Speaker 1: fundamental building block in modern digital ciphers, the exclusive or
- 1:14Speaker 1: R or xor operation.
- 1:16Speaker 2: The xor cipher is foundational because it has one perfect property.
- 1:21Speaker 2: It's it's perfectly reversible.
- 1:23Speaker 1: How does that work.
- 1:24Speaker 2: It's pure digital logic. You take an input bit, you
- 1:27Speaker 2: xor it with a key bit, you get an output bit.
- 1:30Speaker 2: If you want to decrypt it, you simply xo R
- 1:32Speaker 2: the output bit with the exact same.
- 1:34Speaker 1: Key bit, and you get the original back.
- 1:35Speaker 2: And you instantly get your original input back. It's the
- 1:38Speaker 2: ultimate digital.
- 1:39Speaker 1: Reversible key So xor provides that necessary element of key
- 1:43Speaker 1: dependent chaos. What's the next basic operation we use to
- 1:48Speaker 1: shake up.
- 1:49Speaker 2: The data movement, pure and simple. We use the rotation cipher.
- 1:52Speaker 1: Okay.
- 1:52Speaker 2: This is literally just shifting the input bits either left
- 1:55Speaker 2: or right in the cyclical fashion. Imagine a ring of bits.
- 1:59Speaker 2: If you do a one bit left rotation, the bit
- 2:01Speaker 2: on the far left doesn't disappear.
- 2:03Speaker 1: It wraps around.
- 2:04Speaker 2: It wraps around and becomes the new bit on the
- 2:05Speaker 2: far right. It is pure permutation of position.
- 2:08Speaker 1: Okay, So rotation handles the movement, but movement alone isn't
- 2:12Speaker 1: going to secure the data. For that, we need the
- 2:15Speaker 1: two core concepts that define classic cryptography, but applied ruthlessly
- 2:19Speaker 1: at the bit level, substitution and transposition. Giving let's tackle
- 2:24Speaker 1: substitution first, also known as the substitution box or s box.
- 2:27Speaker 2: The S box is where the cipher achieves what cryptographers
- 2:30Speaker 2: call confusion Confusion. Confusion is the deliberate process of obscuring
- 2:35Speaker 2: the relationship between the key and the resulting ciphertext. We
- 2:39Speaker 2: want to make it virtually impossible to look at the
- 2:41Speaker 2: scrambled output and work backward to figure out what key
- 2:44Speaker 2: was used.
- 2:45Speaker 1: And how does an S box do that? With just bits?
- 2:48Speaker 2: It substitutes one group of input bits for a new
- 2:51Speaker 2: group of output bits. And while the simplest S box
- 2:54Speaker 2: just replaces one bit with another, a one to one swap,
- 2:56Speaker 2: the really powerful s boxes are where the number of
- 2:59Speaker 2: input bits en is smaller than the number of output bits.
- 3:02Speaker 1: And oh, that's interesting. So why is that difference where
- 3:05Speaker 1: the input is smaller than the output so effective?
- 3:08Speaker 2: Because if you have fewer inputs than outputs, some of
- 3:11Speaker 2: those original input bits have to be used to generate
- 3:14Speaker 2: multiple output bits. This means a change in just one
- 3:17Speaker 2: input bit causes this dramatic nonlinear change across several output bits.
- 3:23Speaker 2: It just drastically mixes the data.
- 3:24Speaker 1: And that nonlinearity is the key.
- 3:26Speaker 2: It's essential. It's what prevents simple linear algebra from just
- 3:30Speaker 2: breaking the code.
- 3:31Speaker 1: That makes a lot of sense. So if substitution introduces confusion,
- 3:36Speaker 1: then transposition the permutation box or T box, that introduces
- 3:40Speaker 1: the second critical property, which is diffusion.
- 3:43Speaker 2: Right. Diffusion is the mechanism that ensures that if you
- 3:45Speaker 2: change just one single bit in the original plaintext, that
- 3:48Speaker 2: single change spreads its influence to affect every subsequent bit
- 3:52Speaker 2: in the entire resulting ciphertext block.
- 3:54Speaker 1: You're scrambling their physical positions.
- 3:56Speaker 2: We are scrambling their physical positions across the entire block.
- 4:00Speaker 2: The most common case where the number of input and
- 4:01Speaker 2: output bits are the same, it's a pure positional reordering.
- 4:05Speaker 2: But just like with the S box, the best tea
- 4:07Speaker 2: boxes allow for inputs to be duplicated and spread out,
- 4:10Speaker 2: ensuring maximum coverage. The goal is just to maximize the
- 4:13Speaker 2: spread of influence.
- 4:14Speaker 1: So we take these simple operations xor rotation, S boxes
- 4:18Speaker 1: for confusion and T boxes for diffusion, and we start
- 4:22Speaker 1: combining them hundreds of times. This brings us to the
- 4:25Speaker 1: structure that really defined modern cryptography, the round cipher. Yeah.
- 4:30Speaker 2: Round ciphers are ingenious because they don't try to build
- 4:32Speaker 2: one huge bespoke operation. Instead, they take one reasonably complex
- 4:38Speaker 2: set of functions around and they just repeat it multiple times,
- 4:41Speaker 2: sixteen times, twenty times or more.
- 4:43Speaker 1: And critically, each pass or around uses a different key.
- 4:47Speaker 2: A unique key, yet derived from a single master key.
- 4:50Speaker 1: So the classic blueprint for this is the Data Encryption
- 4:52Speaker 1: Standard or DIES, designed by IBM. What does that architecture
- 4:56Speaker 1: look like.
- 4:57Speaker 2: DEES operates on a sixty four bit plaintext input block.
- 5:00Speaker 2: It begins with an initial transposition or permutation, and it
- 5:04Speaker 2: ends with a final one. In Between those bookends are
- 5:06Speaker 2: sixteen identical complex.
- 5:08Speaker 1: Rounds, and the key that's powering this whole engine.
- 5:10Speaker 2: The DEES master key, is fifty six bits long. It's
- 5:13Speaker 2: often stored in a sixty four bit space where every
- 5:15Speaker 2: eighth bit is just ignored, and that fifty six bit
- 5:18Speaker 2: key is the source material for the round key generator,
- 5:22Speaker 2: which then produces sixteen unique forty eight bit keys, one
- 5:26Speaker 2: for each round.
- 5:27Speaker 1: Let's zoom in on a single round, because this is
- 5:29Speaker 1: where the genius lies right the feistal structure. Why is
- 5:32Speaker 1: that so important and clever.
- 5:34Speaker 2: Because it allows the complex one way function the encryption
- 5:38Speaker 2: to be perfectly reversible using the exact same hardware for decryption,
- 5:42Speaker 2: all you do is change the order of the keys.
- 5:44Speaker 1: Okay, let's see how a single round takes a sixty
- 5:47Speaker 1: four bit input and what it splits it.
- 5:50Speaker 2: It immediately splits it into two thirty two bit halfs.
- 5:52Speaker 2: You get a left side L and a right side ARE.
- 5:55Speaker 1: And what happens next The process.
- 5:57Speaker 2: Involves a substitution in a swap. The thirty two bits
- 5:59Speaker 2: from the right side simply become the new left side
- 6:01Speaker 2: of the output for the next round. That's the straightforward part,
- 6:04Speaker 2: easy enough. But simultaneously, those same thirty two R bits
- 6:07Speaker 2: are fed into this highly complex mixing chamber the dees
- 6:11Speaker 2: function or F function.
- 6:12Speaker 1: And the output of that F function that modifies the
- 6:14Speaker 1: original left.
- 6:15Speaker 2: Side precisely, the output of that F function is xrd
- 6:19Speaker 2: with the original thirty two left bits of the input,
- 6:23Speaker 2: and the result of that xor becomes the new right
- 6:25Speaker 2: side for the next round. So, because the F function
- 6:28Speaker 2: is complex and non reversible, but the combination is done
- 6:32Speaker 2: with the reversible.
- 6:33Speaker 1: Xor you can just run the whole thing backward.
- 6:35Speaker 2: You run it sixteen times in reverse with the keys
- 6:38Speaker 2: in reverse order, and it perfectly reconstructs the original plaintext.
- 6:41Speaker 1: That is truly ingenious. But the real magic, the real chaos,
- 6:45Speaker 1: has to be inside that F function. What are the
- 6:48Speaker 1: four critical steps happening in there?
- 6:49Speaker 2: So the F function is designed for maximal confusion and
- 6:52Speaker 2: diffusion fast Step one the expansion permutation box. It takes
- 6:58Speaker 2: the thirty two input bits and immediately permutes and expands
- 7:01Speaker 2: them to forty eight bits.
- 7:02Speaker 1: Hold on, why do we expand the data just to
- 7:04Speaker 1: shrink it later? What's the functional point of.
- 7:06Speaker 2: That great question? It guarantees maximum diffusion before the substitution.
- 7:10Speaker 2: By expanding to forty eight bits, we make sure every
- 7:12Speaker 2: single bit has a chance to interact with the wider
- 7:14Speaker 2: range of the master key. Step two. Immediately after that,
- 7:18Speaker 2: the forty eight bit result is XRD with the forty
- 7:21Speaker 2: eight bit round key. This introduces the key dependency.
- 7:24Speaker 1: So now we have forty eight bits of key dependence
- 7:27Speaker 1: spread out data.
- 7:28Speaker 2: Which brings us to step three, the substitution boxes. The
- 7:32Speaker 2: forty eight bits are fed into S boxes, which are
- 7:34Speaker 2: the main source of the nonlinearity. This step performs a
- 7:36Speaker 2: complex substitution that reduces the data back down to thirty two.
- 7:40Speaker 1: Bits, creating that confusion we talked about.
- 7:42Speaker 2: Exactly and finally, before it exits the f function. Step
- 7:45Speaker 2: four is the straight permutation box, a final t box
- 7:49Speaker 2: that just reorders the thirty two bits one last time
- 7:51Speaker 2: before the result is XR with the other half of
- 7:54Speaker 2: the original block.
- 7:55Speaker 1: It's an incredibly tight efficient cycle repeated sixteen.
- 7:58Speaker 2: Times sixteen times.
- 8:00Speaker 1: So they built this incredible engine, but no engine is
- 8:03Speaker 1: perfect forever. What was the Achilles heel that eventually made
- 8:07Speaker 1: DES obsolete?
- 8:08Speaker 2: It was the key length, plain and simple. I mean,
- 8:10Speaker 2: fifty six bits was incredibly powerful in nineteen seventies, but
- 8:13Speaker 2: as computing power followed Moore's law, it just became vulnerable
- 8:17Speaker 2: to brute force attacks. The search space was just too small.
- 8:20Speaker 1: And the fix was temporary but effective. Triple DES or
- 8:23Speaker 1: three d S.
- 8:24Speaker 2: Yeah, three DS was the rapid solution to extend the
- 8:27Speaker 2: life of the DES algorithm without inventing anything new. It
- 8:30Speaker 2: just uses the DES algorithm three times in sequence. Encrypt
- 8:34Speaker 2: with key one, decrypt with KE two, and then encrypt
- 8:37Speaker 2: again with K three.
- 8:38Speaker 1: And that decrypt encrypt sequence is run in two main flavors.
- 8:42Speaker 2: Right, that's right. The two key three DES uses the
- 8:45Speaker 2: same key for K one and K three, which gives
- 8:47Speaker 2: you an effective key length of one hundred and twelve bits.
- 8:50Speaker 2: The most robust flavor uses three totally independent keys K one,
- 8:55Speaker 2: K two, and K three, pushing the total effective key
- 8:57Speaker 2: length up two hundred and sixty eight bits.
- 9:00Speaker 1: But while three the es solve the security problem, it
- 9:03Speaker 1: must have been inherently slow. You're running this complex process
- 9:06Speaker 1: three times.
- 9:06Speaker 2: Well, it was slow, and that performance hit led directly
- 9:09Speaker 2: to the development of the global standard we all use today,
- 9:11Speaker 2: the Advanced Encryption Standard or AES.
- 9:14Speaker 1: AES is the modern champion, it really is.
- 9:16Speaker 2: It's significantly faster than three DES and highly scalable. Instead
- 9:20Speaker 2: of a fixed sixty four bit block size like DES,
- 9:22Speaker 2: AEES typically uses one hundred and twenty eight bit blocks,
- 9:25Speaker 2: and its key size determines the number of rounds.
- 9:27Speaker 1: It runs, and those key sizes are standardized for different
- 9:29Speaker 1: security needs.
- 9:30Speaker 2: Exactly, you have one hundred and twenty eight bit keys
- 9:33Speaker 2: which run ten complex rounds, one hundred and ninety two
- 9:35Speaker 2: big keys which run twelve rounds, and the highest level
- 9:38Speaker 2: the two hundred and fifty six bit key, which runs
- 9:40Speaker 2: fourteen complex rounds. The core concept is the same repetition
- 9:44Speaker 2: of confusion and diffusion, but with a structure optimized for
- 9:48Speaker 2: modern processors.
- 9:49Speaker 1: Okay, so now we have these incredibly secure, fast, powerful
- 9:52Speaker 1: block ciphers like AES, which only encrypt a fixed sized block,
- 9:56Speaker 1: say one hundred and twenty eight bits. But how do
- 9:59Speaker 1: we handle a mass of file like a gigabyte of
- 10:01Speaker 1: streaming video. This requires operational modes.
- 10:05Speaker 2: That's the logistical challenge. Block ciphers are high security tunnels,
- 10:08Speaker 2: but you need these modes of operation to feed the
- 10:11Speaker 2: real world stream of data into them securely.
- 10:13Speaker 1: So let's start with the simplest mode, the Electronic Codebook
- 10:15Speaker 1: or ECB.
- 10:16Speaker 2: ECB is brutally simple. You just divide the data into
- 10:19Speaker 2: ended blocks, and each block is encrypted entirely independently with
- 10:22Speaker 2: the same key. Block one goes in ciphertext, one comes out.
- 10:25Speaker 2: Block two goes in ciphertext, two comes out.
- 10:27Speaker 1: But this simplicity creates a huge vulnerability. What does this
- 10:30Speaker 1: all mean when we look at the security implications.
- 10:33Speaker 2: Here, it means patterns leak If two plaintext blocks are identical,
- 10:37Speaker 2: say a section of blank video, or a predictable header
- 10:41Speaker 2: and a network protocol, their resulting ciphertexts will always be identical.
- 10:45Speaker 1: Ah.
- 10:46Speaker 2: This breaks the crucial element of concealment. You might have
- 10:50Speaker 2: seen the famous visual example when you encrypt an image
- 10:53Speaker 2: of a penguin using ECB. You can still see the
- 10:56Speaker 2: outline of the penguin and the encrypted.
- 10:58Speaker 1: Result because all the identical color blocks produce identical ciphertext blocks,
- 11:02Speaker 1: leaking the structure and exactly so that predictability is what's
- 11:04Speaker 1: eliminated by the second mode. Cipher blockchaining or CBC.
- 11:08Speaker 2: PHBC is the standard fix. It introduces a dependency a chain.
- 11:12Speaker 2: Before encrypting the current plaintext block, we xor it with
- 11:16Speaker 2: the resulting previous ciphertext block. I see so because the
- 11:19Speaker 2: previous ciphertext is unique. Even if you have ten identical
- 11:22Speaker 2: blocks of pure white in a file, each one will
- 11:25Speaker 2: produce a completely different, unique ciphertext block. The pattern is
- 11:29Speaker 2: completely masked, and.
- 11:30Speaker 1: You still need a way to kick off the chain
- 11:31Speaker 1: for that very first block, since there's no previous ciphertext right.
- 11:35Speaker 2: For that, we use an initialization vector, or for war.
- 11:38Speaker 2: It's a randomized block of data that both the center
- 11:40Speaker 2: and receiver have to agree upon. It just serves as
- 11:43Speaker 2: the previous ciphertext.
- 11:44Speaker 1: For a block one, So CBC is more secure against
- 11:47Speaker 1: pattern recognition, but it introduces a major trade off error propagation.
- 11:53Speaker 2: That's the drawback. It's tied directly to the chain. If
- 11:56Speaker 2: an error occurs in one ciphertext block during transmission, the
- 11:59Speaker 2: error affects the decryption of that corrupted block, of course,
- 12:02Speaker 2: but because that corrupted block is then used to xor
- 12:05Speaker 2: the next incoming block.
- 12:06Speaker 1: The air cascades, it messes up the next block too.
- 12:08Speaker 2: It guarantees corruption in the decryption of the subsequent block.
- 12:11Speaker 1: Okay, now, let's look at two modes, specifically for stream
- 12:14Speaker 1: applications where we might be sending data in chunks, say
- 12:19Speaker 1: arbits that are smaller than the full block size and bits.
- 12:23Speaker 1: First up cipher feedback or CFB.
- 12:26Speaker 2: CFP uses a concept like a sliding window or a
- 12:28Speaker 2: shift register. It takes arbits from the previous cipher block,
- 12:31Speaker 2: shifts them in, encrypts the full end bit register content,
- 12:34Speaker 2: and then xor is the first arbits of that encrypted
- 12:37Speaker 2: output with the arbit plaintext to get the rbit ciphertext.
- 12:40Speaker 1: Because CFB is feeding back the previous ciphertext into the mechanism.
- 12:45Speaker 1: I'm guessing the problem of transmission error propagation is still here.
- 12:48Speaker 2: It absolutely is. An error in a transmitted arbit cipher
- 12:52Speaker 2: block propagates to the following blocks during decryption because that
- 12:55Speaker 2: corrupted data is being used as the input for the
- 12:58Speaker 2: next rounds mechanism.
- 12:59Speaker 1: So how do we finally get to the holy grail
- 13:02Speaker 1: of stream encryption, which is high security without that error
- 13:06Speaker 1: propagation That would be the output feedback mode OFB.
- 13:09Speaker 2: OFB solves the error propagation problem by breaking the feedback
- 13:13Speaker 2: dependency on the transmission line. Instead of feeding back the
- 13:16Speaker 2: previous ciphertext, OFB feeds back the output of the cipher
- 13:20Speaker 2: algorithm itself, so.
- 13:21Speaker 1: The stream of key material being generated is purely internal.
- 13:24Speaker 1: It doesn't care if the transmitted data got corrupted or not.
- 13:27Speaker 2: Exactly. The key stream generator is running on its own
- 13:30Speaker 2: independent clock. If an error happens in one cipher block
- 13:33Speaker 2: during transmission, the key stream generation for the next block
- 13:37Speaker 2: is completely unaffected. OFB gives your perfect security against pattern
- 13:40Speaker 2: leaks like CBC, but it ensures transmission errors only corrupt
- 13:44Speaker 2: the specific block where they occur.
- 13:46Speaker 1: That is a phenomenal journey. I mean we started with
- 13:48Speaker 1: the basic digital math of xor and rotation, moved through
- 13:52Speaker 1: the ingenious mechanics of the feistal structure in DEES, scaled
- 13:56Speaker 1: up to the speed and security of AES, and finally
- 13:59Speaker 1: covered the essential operational modes that let these fixed block
- 14:02Speaker 1: ciphers protect real world data streams.
- 14:05Speaker 2: The final synthesis here for you is to understand that
- 14:08Speaker 2: the complexity protecting your banking or your private messages isn't
- 14:12Speaker 2: some secret formula. It's the persistent application of key principles
- 14:17Speaker 2: confusion and diffusion created through the combination of basic digital steps,
- 14:22Speaker 2: all built into architectures that maximize efficiency and security.
- 14:25Speaker 1: And this leaves you with a final thought to mall over.
- 14:27Speaker 2: If you were tasked with selecting a secure operational mode
- 14:30Speaker 2: for a highly sensitive satellite transmission where data collection is
- 14:33Speaker 2: a frequent possibility, which mode cipher blockchaining CBC or output
- 14:37Speaker 2: feedback ofb would you choose? And why is the trade
- 14:40Speaker 2: off in that design so critical for maintaining data integrity
- 14:43Speaker 2: in that specific environment.