Details of Cryptography
In this chapter:
-
Cryptology, cryptanalysis
-
Symmetric encryption: DES and AES
-
Asymmetric encryption: RSA and ECC
-
Message digests: SHA
-
Digital signatures: DSA/DSS
-
Quantum key distribution
A user’s manual describes the interface to and functions of a software product. If you really want to know how a piece of software is built, how it works, how to embed it in another piece of software, or what its detailed specifications are, you need a different kind of documentation. You do not normally need any of these advanced topics just to use the software, however.
This chapter complements the presentation of encryption in Chapter 2 . In that earlier chapter we introduced cryptography as a tool we then used many times in later chapters. For many people, the user’s manual to cryptography will be sufficient. But for people who want or need more details on the topic, we expand on cryptography in this chapter.
We begin with an introduction to cryptanalysis. Although throughout this book we have shown how technology fails or can be made to fail, we have not yet delved deeply into the rich topic of overcoming the protections of cryptography. After describing types of failings, we consider potential and real shortcomings of well-known cryptographic algorithms and implementations. We conclude this chapter with some applications in which cryptography is embedded: hash codes and digital signatures.
You should not expect this chapter to prepare you to appreciate the nuances of cryptography, much less to design your own cryptographic algorithms. Cryptography is a specialized topic that depends on several areas of mathematics and theoretical computer science, including number theory, finite field algebra, computational complexity, and logic. After reading this overview, you would need to develop a significant background to study cryptography in depth. And we caution you strongly against studying a little cryptography and concluding that you can design your own secure cryptosystem. The field of cryptography is littered with failed approaches designed even by experts, so nonexperts are well advised to “leave the driving to the professionals.” See, for example, Sidebar 12-1 on the perils of inventing your own cryptography.
Sidebar 12-1 Mafia Boss Uses Encryption
Arrested in Sicily in April 2006, the reputed head of an Italian Mafia family, Bernardo Provenzano, made notes— pizzini in the Sicilian dialect. When arrested, he left approximately 350 of the notes behind. In the pizzini he gives instructions to his lieutenants regarding particular people.
Instead of writing the name of a person, Provenzano used a variation of the Caesar cipher in which letters were replaced by numbers: A by 4, B by 5, … Z by 24 (there are only 21 letters in the Italian alphabet). So in one of his notes the string "I met 512151522 191212154 and we agreed that we will see each other after the holidays," refers to Binnu Riina, an associate arrested soon after Provenzano [ LOR06 ]. Police decrypted notes found before Provenzano’s capture and used clues in them to find the boss, wanted for 40 years.
All notes appear to use the same encryption, making them trivial to decrypt once police discerned the pattern.
Suggestions we might make to Sig. Provenzano: Use a strong encryption algorithm, change the encryption key from time to time, and hire a cryptologist.
12.1 Cryptology
In this section we study two related things: inventing codes and breaking them. Sports players learn offensive moves by studying defensive maneuvers, and vice versa. Therefore, we present the primitive aspects of making and breaking codes together.
Cryptanalysis
Remember from Chapter 2 that cryptanalysis is the act of studying a cryptographic algorithm, its implementation, plaintext, ciphertext, and any other available information to try to break the protection of encryption.
A cryptanalyst can attempt to do any or all of six things:
-
Break (decrypt) a single message.
-
Recognize patterns in encrypted messages, so as to break subsequent ones by applying a straightforward decryption algorithm.
-
Infer some meaning without even breaking the encryption, such as noticing an unusual frequency of communication or determining something by whether the communication was short or long.
-
Easily deduce the key to break one message, and perhaps subsequent ones.
-
Find weaknesses in the implementation or environment of use of encryption by the sender.
-
Find general weaknesses in an encryption algorithm, without necessarily having intercepted any messages.
In addition to these attacks, one other approach is worth mentioning, although it does not directly involve the encryption itself. An attacker can try to obtain data before encryption or after decryption, for example, by tapping a communications line or modifying a program or the operating system; another possibility, of course, is just to get the plaintext from someone with access, by bribery or coercion, for example. Although not a cryptographic technique, this method does reinforce that an attacker must be expected to use any means to obtain the desired data.
Attackers can—and will—use any means to obtain wanted data.
Ciphertext Only
Code-breakers will use anything they can obtain. The most readily available input is the ciphertext of a single message, but that may also be the hardest puzzle to solve. Analysts look for patterns, similarities, and discontinuities, but with little data to analyze, those signs are elusive. For this reason, code-breakers like to obtain large amounts of data—many messages—encrypted alike, as can happen when a sender does not change its encryption key often.
Plaintext and Ciphertext
Even better is to get a plaintext–ciphertext pair because that find lets the analyst see what transformations occurred.
Full or Partial Plaintext
The analyst may be fortunate enough to have a sample message and its decipherment. For example, a diplomatic service may have intercepted an encrypted message, suspected to be the text of an official statement. If the official statement (in plaintext) is subsequently released, the interceptor has both ciphertext C and plaintext P and need only deduce the encryption E for which C \= E P to find the decryption D . (Finding the correct E is, of course, no small task.) In this case the analyst is attempting to find E (or D ) by using a known plaintext attack.
The analyst may have additional information too. For example, the analyst may know that the message was intercepted from a diplomatic exchange between Germany and Austria. From that information, the analyst may guess that the German words for Bonn, Vienna, and Chancellor appear in the message. Alternatively, the message may be a memorandum to the salesforce from a corporate president, and the memo would have a particular form (To: Salesforce, From: The President, Subject: Weekly Sales Update, Date: nn/nn/nnnn).
In these cases, the analyst can use what is called a probable plaintext analysis. After doing part of the decryption, the analyst may find places where the known message fits with the deciphered parts, thereby giving more clues about the total translation.
Sometimes the analyst is lucky enough to obtain a copy of the encryption algorithm or machine, a situation described in Sidebar 12-2 . In this instance the analyst can generate many messages, run them through the machine, and see the result.
Sidebar 12-2 Human Fallibility Led to Cracked Codes
David Kahn [ KAH96 ] describes the history of the Enigma machine, a mechanical tool used by the Germans in World War II to scramble messages and prevent their enemies from understanding them. Enigma was based on revolving wheels, or rotors, that were wired together and connected to a typewriter keyboard. There were so many ways to encrypt a message that even if 1,000 analysts tried four different ways each minute, all day, every day, it would have taken the team 1.8 billion years to test them all.
So how did the Allies break the encryption? First, they made use of the likely chatter about each day’s events. By guessing that the Germans would be discussing certain places or issues, the Allies found sections of scrambled text that they could relate to the original messages, or cleartext. Next, they concentrated on Luftwaffe messages.
Counting on the likelihood that the Luftwaffe signalmen were not as well trained as those in the Army or Navy, the Allies then watched for slip-ups that increased the odds of understanding the encrypted messages. For instance, Luftwaffe signalmen often used “a girlfriend’s name for a key setting or beginning a second message with the same setting as that left at the ending of the first.” Such knowledge enabled the Allies to determine some of the Luftwaffe’s plans during the Battle of Britain.
Thus, sophisticated technology can be trumped when control protocols are not followed carefully and completely.
Ciphertext of Any Plaintext
The analyst, having infiltrated the sender’s transmission process, could advantageously cause messages to be encrypted and sent at will. This attack is called a chosen plaintext attack. For instance, the analyst could insert records into a database and observe the change in statistics after the insertions. Linear programming sometimes enables such an analyst to infer data in the database that should be kept confidential. Alternatively, an analyst may tap wires in a network and so notice the effect of sending a particular message to a particular network user. The cryptanalyst may be an insider or have an inside colleague who could cause certain transactions to be reflected in ciphertext; for example, the insider may forward messages resulting from receipt of a large order. A chosen plaintext attack favors the analyst. Another desirable situation is for the analyst to force the enemy to put particular content into the ciphertext stream, a situation described in Sidebar 12-3 .
Sidebar 12-3 Hidden Meanings Changed the Course of World War II
In spring 1942, the United States was fighting Japan in the Pacific. American cryptanalysts had cracked some of the Japanese naval codes, but they did not understand the extra encoding the Japanese used to describe particular sites. A message intercepted by the United States told the Allies’ officers that “AF” was to be the target of a major assault. The U.S. Navy suspected that the assault would be on Midway island, but it needed to be sure.
Commander Joseph Rochefort, head of the U.S. Navy’s cryptography center at Pearl Harbor, devised a clever plan to unearth the meaning of “AF.” He directed the naval group at Midway to send a message, requesting fresh water, saying that the water distillery had been damaged. Soon, the United States intercepted a Japanese message indicating that “AF” was short of water—verifying that “AF” indeed meant Midway! [ SEI01 ]
Other Weaknesses
A cryptanalyst works against humans, who can be hurried, lazy, careless, naïve, or uninformed. Humans sometimes fail to change cryptographic keys when needed, broadcast cryptographic keys in the clear, or choose keys in a predictable manner. That is, the algorithm may be strong and the implementation effective, but the people using it fail in some way and open up the ciphertext to detection. People have been known to carelessly discard sensitive material that could give a spy access to plaintext by matching known ciphertext. And humans can sometimes be bribed or coerced.
Not only are people fallible, but so are hardware and software implementations. Sometimes hardware fails in predictable ways, such as when disk-reading heads lose their track alignment, so sensitive data thought to be erased are still on the disk. At other times, seemingly small things can weaken an otherwise strong approach. For example, in one attack, the analyst accurately measured the electricity being used by a computer performing an encryption and deduced the key from the difference in power used to compute a 1 versus a 0.
These problems are separate from issues of the algorithm itself, but they offer ways that a cryptanalyst can approach the task of breaking the code. Remember that the only rule that applies to the attacker is that there are no rules. In Sidebar 12-4 we show an example of “anything that works” in cryptanalysis.
Sidebar 12-4 Really Cold Data
Alex Halderman and a research team at Princeton University investigated a novel way to obtain cryptographic keys [ HAL08 ]. Computer memory chips, dynamic random access memory modules (DRAMs), lose their contents after they lose power. For all practical purposes, data values disappear on power-off.
The performance of semiconductors at low temperatures varies from their behavior at room temperature. Because most semiconductors are used within a narrow temperature range ( - 20 ° C to + 40 ° C , for example) the effect is not important. But cryptanalysis is “no holds barred” combat.
As Halderman’s team explains, the DRAM data loss is not instantaneous. Data remain for a few seconds and the loss is gradual, not instantaneous. They found reports of a semiconductor device that held its data for a week when maintained in liquid nitrogen, approximately - 200 ° C ; they ran their own test and found only 0.17% data loss after 60 minutes in liquid nitrogen without power outside the computer.
Most attackers are not walking around with a container of liquid nitrogen. Halderman’s team used a readily available alternative: electronics shops sell aerosol cans of “canned air,” a spray to blow dust and other impurities out of electronics. Despite the name, these cans contain compressed gasses, a compressed fluorohydrocarbon refrigerant, that is approximately - 50 ° C in liquid form, and the liquid can leak out if the can is inverted. Halderman’s team used such products in their experiments, finding that they could preserve memory contents for several minutes.
So how does a computer chip lead to cryptanalysis? Encryption and decryption both require the key. If an application performs cryptography for a user, it has to store the key somewhere, usually in memory to be available for feeding into the encryption or decryption routine. Especially helpful is that encryption programs often precompute part of their work, trading an amount of memory space (to store precomputed tables) for the time saved by reducing the work to do each encryption or decryption. The pattern of these precomputed tables helps the team locate such tables in memory, making them easier to find than, say, a bank account number. Because Halderman’s team can preserve the contents of a memory chip, they have enough time to copy its entire contents to another stable medium before it decays seriously. Once the data are on a nonvolatile medium, the analysts have the luxury of time to perform detailed forensic analysis on memory, looking for clues that show where keys are stored.
Admittedly, this example shows a highly creative (some people might say bizarre or even pathological) approach to obtaining sensitive data. Nevertheless, it exemplifies two points we make in Chapter 1 : First, the attacker can use any tools or techniques; there is no concept of “playing nicely” in cryptanalysis (or in security). Second, motivation matters; a highly motivated attacker has incentive to develop and use highly sophisticated attacks that may yield a rich payoff.
This background information has readied you to study widely used encryption schemes today. Using these schemes is fairly easy, even though the detailed construction of the algorithms can be quite complex. As you study the three algorithms, keep in mind the possibility that cryptanalysts are also working to defeat these encryptions.
Cryptographic Primitives
Cryptography exploits the basic techniques of changing and rearranging. These operations can be applied in complex patterns. With computers, the complexity of the patterns is limited only by the time one is willing to devote to the encryption and decryption processes. With the speed of modern computers, complexity is seldom a concern.
Substitution and Transposition
The two cryptographic primitives are substitution (changing) and transposition (reordering). In a substitution , one set of bits is exchanged for another. If the encryption works on alphabetic letters, each letter can be replaced by another, much like the cryptogram puzzles published in some newspapers. Substitutions can also be done on bytes or data blocks of other sizes. The substitution often involves a simple table lookup, so it can be done quickly, and a hardware cryptographic processor can be optimized with the substitution table encoded within the processor’s memory.
A weakness of substitution is its regularity. In a letter-based substitution, if E is always replaced by p, the frequency of the ciphertext p will match that of plaintext E, giving a clue to the analyst. For this reason, substitutions are seldom used on their own. At times the substitution table is changed, so that, for example, E is replaced sometimes by p and sometimes by w. This use of multiple replacements helps smooth out apparent patterns in the output ciphertext. 1
- The Enigma machine, mentioned in Sidebar 12-2 , was a substitution code device used by Germans in World War II. See the description by David Kahn [ KAH96 ] of how it changed the substitution with each letter in a complex but algorithmic (and hence reversible) way.
Transposition involves rearranging the order of the ciphertext to break patterns in the underlying plaintext. Some newspapers also publish puzzles of individual words, the letters of which have been scrambled. Solvers of these puzzles look for common letter patterns, such as E-D, I-N-G, U-N, R-E, Q-U, and terminal S. If transposition is used by itself, these orthographic patterns help solve the puzzle.
Cryptography is built on substitution (replacing) and transposition (reordering).
Many cryptographic algorithms involve both substitution and transposition; the substitution smooths the distribution of ciphertext output and the transposition breaks up apparent patterns of succeeding plaintext units.
Confusion and Diffusion
Two additional important concepts are related to the amount of work required to perform an encryption. An encrypting algorithm should take the information from the plaintext and transform it so that the interceptor cannot readily recognize the message. The interceptor should not be able to predict what will happen to the ciphertext by changing one character in the plaintext. We call this characteristic confusion . An algorithm providing good confusion has a complex functional relationship between the plaintext/key pair and the ciphertext. In this way, an interceptor will need a long time to determine the relationship between plaintext, key, and ciphertext; therefore, the interceptor will take a long time to break the code. Substitution achieves confusion.
The cipher should also spread the information from the plaintext over the entire ciphertext so that changes in the plaintext affect many parts of the ciphertext. This principle is called diffusion , the characteristic of distributing the information from single plaintext letters over the entire output. Good diffusion means that the interceptor needs access to much of the ciphertext to be able to infer the algorithm. Transposition achieves diffusion.
Cryptography involves confusion (changing plaintext in a complex way) and diffusion (spreading the effect of change throughout the ciphertext).
One-Time Pads
Many cryptologists consider the one-time pad a perfect cipher. It is a pure substitution cipher. The name comes from an encryption method in which a large, nonrepeating set of keys is written on sheets of paper, glued together into a pad. For example, if the keys are 20 characters long and a sender must transmit a message 300 characters in length, the sender would tear off the next 15 pages of keys. The sender would write the key values one at a time above the letters of the plaintext and encipher each plaintext with a prearranged substitution involving each plaintext letter and the key value written above it. The sender would then destroy the used keys.
For the encryption to work, the receiver needs a pad identical to that of the sender. Upon receiving a message, the receiver takes the appropriate number of keys and deciphers the message as if it were a plain substitution with a long key. Essentially, this algorithm gives the effect of a key as long as the number of characters in the pad.
The one-time pad method has two problems: the need for absolute synchronization between sender and receiver, and the need for an unlimited number of keys. Although generating a large number of random keys is no problem, printing, distributing, storing, and accounting for such keys are problems.
Long Random Number Sequences
A close approximation of a one-time pad for use on computers is a random number generator. In fact, computer random numbers are not random; they really form a sequence with a very long period (that is, they go for a long time before repeating the sequence). In practice, a generator with a long period can be acceptable for a limited amount of time or plaintext.
Randomness is a peculiar concept. If you fairly flip a fair coin 50 times, you would be rightfully astounded if it landed heads all 50 times; you would expect approximately 25 heads and 25 tails. But in fact, 50 heads is a possible outcome, even if it is highly unlikely. When we want a computer algorithm to generate a series of random numbers, what we really want is a series of nonrandom numbers. You might reject a computer random number generator that 50 times in a row produced the output 1, even though we just argued that you could get heads 50 times in a row from flipping a coin. Random number generator computer programs (more precisely called pseudorandom number generators or PRNG s) are programs whose output matches our intuitive sense of randomness: similar counts of 0s and 1s, no long series of 0s or 1s, no proximate repeating sequences (no 01010101 outputs), and nonpredictability of the next output. Statisticians test these and other properties of nonrandomness using mathematics well beyond the scope of this book. Marsaglia [ MAR03 ] gives one of the best discussions of nonrandomness in PRNGs.
To use a random number generator, the sender with a 300-character message would interrogate the computer for the next 300 random numbers and use one number to encipher each character of the plaintext message.
The Vernam Cipher
The Vernam cipher is a type of one-time pad that Gilbert Vernam devised for AT&T and patented in 1919. The Vernam cipher is immune from most cryptanalytic attacks. The basic encryption involves an arbitrarily long nonrepeating sequence of numbers that are combined with the plaintext. Vernam’s invention used an arbitrarily long punched paper tape containing random numbers, fed into a teletype machine. The random numbers were combined with characters typed into the teletype. The sequence of numbers had no repeats, and each tape was used only once. (Note that this statement says the sequence does not repeat, not that no single number or even string of numbers repeats. The tape might have numbers a , b , c in two places, but at some point there would be a difference: a , b , c , … d in one place and a , b , c , … e in the other.) As long as the key tape does not repeat and is not reused, this type of cipher is immune from cryptanalytic attack because the available ciphertext does not reflect a pattern of the key. A model of this process is shown in Figure 12-1 .
FIGURE 12-1 Vernam Cipher
Long nonrepeating series of numbers leads to Exclusive OR or other combining function, and Exclusive OR or other combining function. Plaintext leads to Exclusive OR or other combining function, which leads to Exclusive OR or other combining function through Ciphertext. Exclusive OR or other combining function points at Original Plaintext.
Book Ciphers
Another source of supposedly “random” numbers is any book, piece of music, or other object of which the structure can be analyzed. Both the sender and receiver need access to identical objects. For example, a possible one-time pad can be based on a telephone book. The sender and receiver might agree to start at page 35 and use two middle digits ( ddd-DDdd ) of each seven-digit phone number, mod 26, as a key letter for a substitution cipher. They use an already agreed-on table (called a Vigenère tableau) that has all 26 letters
Any book can provide a key. The key is formed from the letters of the text, in order. This type of encryption was the basis for Ken Follett’s novel, The Key to Rebecca , in which Daphne du Maurier’s famous thriller Rebecca acted as the source of keys for spies in World War II. Were the sender and receiver known to be using a popular book, such as The Key to Rebecca , the bible, or Security in Computing , it would be easier for the cryptanalyst to try books against the ciphertext rather than look for patterns and use sophisticated tools. Of course, the analyst has to deduce the correct book.
We want to stress that these one-time pads and pseudo-one-time pads cannot repeat. If there is any repetition, the interceptor gets two streams of ciphertext: one for one block of plaintext, the other for a different plaintext, but both encrypted with the same key. The interceptor combines the two ciphertexts in such a way that the keys cancel each other out, leaving a combination of the two plaintexts. The interceptor can then do other analyses to expose patterns in the underlying plaintexts and give some likely plaintext elements. The worst case is that the user simply starts the pad over for a new message, for the interceptor may then be able to determine how to split the plaintexts and unzip the two plaintexts intact.
One-time pads derive their cryptographic power by having no repeating cycles.
Statistical Analysis
Text in any natural language has patterns. First are the frequencies of the letters themselves. The letters A, E, O, and T account for approximately 40% of all letters used in standard English text, and those letters plus N and I account for 50%. Furthermore, certain letter pairs, such as EN, RE, ER, and NT, and triples, such as ENT, ION, AND, and ING, occur with high frequency. 2 Alphabetic languages other than English have similar results.
- Note that the exact frequencies vary depending on the text being considered: The proportion of letters in a dictionary would be slightly different from that of a newspaper, a technical report, a medical article, or the King James Bible because the words used are drawn from a skewed population in each case.
Even non-language plaintext often reveals irregularities in distribution: Machine language, for example, reflects the operation codes of popular instructions, and program source code reflects the keywords of the language and programmers’ choices for variable names.
To the cryptanalyst these frequency distributions are helpful because they reflect certain irregularities of the underlying language that may be exhibited in the output ciphertext.
What Makes a “Secure” Encryption Algorithm?
Encryption algorithms abound, including many techniques beyond those we discuss in this book. Suppose you have text to encrypt. How do you choose an encryption algorithm for a particular application? To answer this question, reconsider what we have learned so far about encryption. We looked at two broad classes of algorithms: substitutions and transpositions. Substitutions “hide” the letters of the plaintext, and multiple substitutions dissipate high letter frequencies to make it harder to determine how the substitution is done. By contrast, transpositions scramble text so that adjacent-character analysis fails.
For each type of encryption we considered, we described the advantages and disadvantages. But there is a broader question: What does it mean for a cipher to be “good”? The meaning of “good” depends on the intended use of the cipher. A cipher to be used by military personnel in the field has different requirements from one to be used in a secure installation with substantial computer support. In this section we look more closely at the different characteristics of ciphers.
Shannon’s Characteristics of “Good” Ciphers
In 1949 Claude Shannon [ SHA49 ] proposed several characteristics that identify a good cipher.
- The amount of secrecy needed should determine the amount of labor appropriate for the encryption and decryption.
Principle 1 is a reiteration of the principle of timeliness from Chapter 1 and of the earlier observation that even a simple cipher may be strong enough to deter the casual interceptor or to hold off any interceptor for a short time.
- The set of keys and the enciphering algorithm should be free from complexity.
This principle implies that we should restrict neither the choice of keys nor the types of plaintext on which the algorithm can work. For instance, an algorithm that works only on plaintext having an equal number of instances of A and E is useless. Similarly, it would be difficult to select keys such that the sum of the values of the letters of the key is a prime number. Restrictions such as these make the use of the encipherment prohibitively complex. If the process is too complex, it will not be used. Furthermore, the key must be transmitted, stored, and remembered, so it must be short (for hand implementation, at least).
- The implementation of the process should be as simple as possible.
Manual implementation motivated principle 3: A complicated algorithm is prone to error or likely to be forgotten. With the development and popularity of digital computers, algorithms far too complex for hand implementation became feasible. Still, the issue of complexity is important. People will avoid an encryption algorithm whose implementation process severely hinders message transmission, thereby undermining security. And a complex algorithm is more likely to be programmed incorrectly.
- Errors in ciphering should not propagate and cause corruption of further information in the message.
Principle 4 acknowledges that humans make errors in their use of enciphering algorithms. One error early in the process should not throw off the entire remaining ciphertext. For example, dropping one letter in a transposition throws off the entire remaining encipherment. Unless the receiver can determine where the letter was dropped, the remainder of the message will be unintelligible. By contrast, reading the wrong row or column for a table-driven substitution affects only one character—remaining characters are unaffected.
- The size of the enciphered text should be no larger than the text of the original message.
Behind principle 5 is the idea that a ciphertext that expands dramatically in size cannot possibly carry more information than the plaintext, yet it gives the cryptanalyst more data from which to infer a pattern. Furthermore, a longer ciphertext requires more space for storage and more time to communicate.
These principles were developed just before the ready availability of digital computers, even though Shannon was aware of computers and the computational power they represented. Thus, some of the concerns he expressed about hand implementation are not really limitations on computer-based implementation. For example, a cipher’s implementation on a computer need not be simple, as long as the time complexity of the implementation is tolerable. Nevertheless, the rationale implied by these principles remains largely valid.
Properties of “Trustworthy” Encryption Algorithms
Commercial users have several requirements that must be satisfied when they select an encryption algorithm. Thus, when we say that encryption is “commercial grade” or “trustworthy,” we mean that it meets these constraints:
-
It is based on sound mathematics. Good cryptographic algorithms are not just invented; they are derived from solid principles.
-
It has been analyzed by competent experts and found to be sound. Even the best cryptographic experts can think of only so many possible attacks, and the developers may become too convinced of the strength of their own algorithm. Thus, a review by critical outside experts is essential.
-
It has stood the “test of time.” As a new algorithm gains popularity, people continue to review both its mathematical foundations and the way it builds on those foundations. Although a long period of successful use and analysis is not a guarantee of a good algorithm, the flaws in many algorithms are discovered relatively soon after their release.
Properties of “Trustworthy” Encryption Systems
We have just considered the algorithms for encrypting. As we emphasize throughout this book, there is more to encryption than just the algorithm. Phrased differently, a flawed implementation of a solid algorithm is still a flawed implementation.
We are not cryptologists, nor is the purpose of this book to prepare you to be cryptologists. We hope that reading this book might inspire some of you to take up that profession, but this book only introduces you to the subtleties of modern cryptography.
We should note that the algorithms of modern cryptography rarely fail. Because of careful work by a thoughtful community, flaws of mathematics or logic in public algorithms tend to be caught early.
Unfortunately, the same cannot be said of the systems that implement these algorithms. In Chapter 3 we describe the difficulty of translating an idea—an algorithm or system design, for example—into a program. The mathematics underlying an algorithm is precise, concise, and unambiguous, but programming language semantics are subtle. A programmer can represent a design in many ways. Because of Turing’s result [ TUR38 ], we know no program can decide whether any two programs produce the same result (although we can decide that for certain specific pairs of programs). Furthermore, programs can be long and can have nonobvious side effects. Thus, we are challenged to determine whether a program faithfully implements an algorithm.
To be secure, a solid cryptographic algorithm must also be implemented securely.
Correctness Proofs
In Chapter 3 we present the concept of proving a program’s correctness or, more precisely, proving that a program is consistent with a set of desired outcomes. The capability of such proof techniques has advanced significantly, to the point that now hardware (chip) manufacturers use them to prove that a chip correctly implements its instruction set [ SEL15 ], and Cisco network engineers use verification tools to prove that a network design change still adheres to the network’s security policy [ KAR18 ].
Specifications and implementations of cryptographic algorithms have also been proved formally. (See, for example, [ SMI08 ] and [ APP16 ].) Formal proof techniques have also been successfully applied to cryptographic protocols, for example in [ ROY08 ] and [ DEG11 ].
Blended Inductive–Deductive Analysis
Marv Schaefer [ SCH89 ] raised a warning flag about overdependence on formal analysis of security properties. He based his concern on the fact that any formal analysis of an artifact—algorithm, protocol, design, or implementation—is really examining an abstraction, a reduction of the idea behind the artifact to a series of symbols. He warned that analysts can unintentionally misrepresent the artifact in the abstraction and then prove properties about the abstraction that are not true of the artifact.
Herley and van Oorschot [ HER17 ] carefully analyzed what is often called the science of security, that is, the ways security analysis could profit from approaches used in other sciences. Taking note of the concern Schaefer raised, they called for use of both deductive and inductive analysis, among other things. Deductive reasoning, exemplified by the formal proofs just described, plays a solid role in supporting a claim of security. So, too, does inductive reasoning, collecting facts and deriving conclusions of security from observable properties. Thus, a hybrid model, involving both deductive and inductive reasoning, is another strong means for demonstrating the trustworthiness of cryptographic constructs such as algorithms and programs.
Now we turn to three cryptographic algorithms of prime importance in the commercial world: DES (Data Encryption Standard), which has been largely superseded by AES (Advanced Encryption Standard) for symmetric encryption, and RSA (Rivest–Shamir–Adleman, the names of its three inventors) for asymmetric encryption. These three algorithms (as well as others) meet our criteria for high-quality commercial-grade encryption. In the next sections we cover these three algorithms originally introduced in Chapter 2 . In this chapter we delve a bit more deeply into the internal structures. We do not go into complete detail on these algorithms because the referenced defining documents do that thoroughly. We elaborate as well on design choices and rationales for any interested readers. We also mention a few other algorithms in widespread use, although we do not delve into their structure or use, leaving that study for more comprehensive books on cryptography.
12.2 Symmetric Encryption Algorithms
For centuries, national military and diplomatic services have used cryptography to protect their secrets. In fact, the history of cryptography (beautifully told in David Kahn’s book [ KAH96 ] or the abbreviated version [ KAH67 ], if you can find it) almost exclusively involves governments and their military forces protecting things from other governments.
As digital computers became popular, companies that used those computers found they needed to protect data against exposure to competitors, as well as to ensure their workers’ privacy. And, as networking became more popular, they needed to prevent problems from faulty transmissions. So, for reasons of confidentiality and integrity, businesses and even some individuals began to search for encryption. Recognizing that lack of reliably high-quality encryption would hold back commerce, the U.S. Department of Commerce, through its National Bureau of Standards, took steps to make solid encryption available for industry.
DES
The Data Encryption Standard grew out of a project developed by IBM, which was at the time probably the largest supplier of mainframe computers to private industry. IBM figured that many of its customers would find encryption useful.
Background and History
In the early 1970s the U.S. National Bureau of Standards (NBS), later renamed the National Institute for Standards and Technology (NIST), recognized that the general public needed a secure encryption technique for protecting sensitive information. Historically, the U.S. Department of Defense and the Department of State had had continuing interest in encryption systems for protecting military and diplomatic secrets; it was thought that these departments were home to the greatest expertise in cryptology. However, precisely because of the sensitive nature of the information they were encrypting, the departments could not release any of their work. Thus, the responsibility for a more public encryption technique was delegated to the NBS.
At the same time, several private vendors had developed mechanical or software encryption devices that individuals or firms could buy to protect their sensitive communications. The difficulty with this commercial proliferation of encryption techniques was exchange: Two users with different devices could not exchange encrypted information. Furthermore, no independent body was capable of extensively testing the devices to verify that they properly implemented their algorithms, or even that the algorithms were worth using.
It soon became clear that encryption was ripe for assessment and standardization, to promote the ability of unrelated parties to exchange encrypted information and to provide a single encryption system that could be rigorously tested and publicly certified. As a result, in 1972 the NBS called for proposals for producing a public encryption algorithm. The call specified desirable criteria for such an algorithm:
-
able to provide a high level of security
-
specified and easy to understand
-
publishable, so that security does not depend on the secrecy of the algorithm
-
available to all users
-
adaptable for use in diverse applications
-
economical to implement in electronic devices
-
efficient to use
-
able to be validated
-
exportable
The NBS envisioned providing the encryption as a separate hardware device. To allow the algorithm to be public, NBS hoped to reveal the algorithm itself, basing the security of the system on the keys (which would be under the control of the users).
Few organizations responded to the call, so the NBS issued a second announcement in August 1974. The most promising submission was the Lucifer algorithm on which IBM had been working for several years. This idea had been published earlier, so the basic algorithm was already public and had been open to scrutiny and validation. Although lengthy, the algorithm was straightforward, a natural candidate for iterative implementation in a computer program. Furthermore, unlike some algorithms that use arithmetic on 500- or 1,000-digit or longer binary numbers (far larger than most machine instructions could handle as a single quantity), Lucifer used only simple logical operations on relatively small data blocks. Thus, the algorithm could be implemented fairly efficiently in either hardware or software on conventional computers.
The data encryption algorithm developed by IBM for NBS was based on Lucifer, and it became known as the Data Encryption Standard ( DES ), although its proper name is DEA (Data Encryption Algorithm) in the United States and DEA1 (Data Encryption Algorithm-1) in other countries. Then, NBS called on the Department of Defense through its National Security Agency (NSA) to analyze the strength of the encryption algorithm, and IBM changed it slightly. Finally, the NBS released the algorithm for public scrutiny and discussion.
DES was adopted as a U.S. federal standard [ NBS77 ] in November 1976, authorized by NBS for use on all public and private sector unclassified communication. Eventually, DES was accepted as an international standard by the International Standards Organization.
DES is the first government-endorsed cryptographic algorithm available for commercial and government use.
In the next section we give a fairly comprehensive explanation of the internal operation of the DES algorithm. This algorithm was a development of the 1970s, so by the time we are writing this book, DES has lived a good life and been mostly retired from public service. We describe it fully because it is a good example of a cryptographic algorithm’s design, detailed but not overly so. Along the way we also introduce some concepts of block ciphers in general, so we can anchor them to our DES explanation. And finally, most of the life cycle of DES is known, either released by its designers or inferred by cryptologists. This whole life history is informative as an example of a full cryptanalysis.
DES Algorithm
The algorithm leverages the two techniques Shannon identified to conceal information: confusion and diffusion. That is, the algorithm accomplishes two things: ensuring that the output bits have no obvious relationship to the input bits, and spreading the effect of one plaintext bit to other bits in the ciphertext. Substitution confuses; transposition diffuses. In general, DES affects plaintext by rounds of substitution and permutation.
The full DES algorithm is reported in the original definition document [ NBS77 ], so we omit some fine points. We do want you to see the basic structure of the algorithm so that you can appreciate the origin of its cryptographic strength.
The basis of DES is two different ciphers, applied alternately. Shannon noted that two weak but complementary ciphers can be made more secure by being applied together (called the “product” of the two ciphers) alternatingly, in a structure called a product cipher .
After initialization, the DES algorithm operates on blocks of data. It splits a data block in half, scrambles each half independently, combines the key with one half, and swaps the two halves. This process is repeated 16 times. It is an iterative algorithm using just table lookups and simple bit operations. Although the bit-level manipulations of the algorithm are complex, the algorithm itself can be implemented quite efficiently. Data manipulations are on bit strings ranging from 32 to 64 bits, using only table lookups, logical operations (AND, OR, exclusive OR), and bit shifts and rotations, making these procedures ideal for implementation on computers with 32- or 64-bit word sizes.
Input to DES is divided into blocks of 64 bits. The 64 data bits are permuted by a so-called initial permutation. The data bits are transformed by a 64-bit key (of which only 56 bits are used). The key is reduced from 64 bits to 56 bits by the dropping of bits 8, 16, 24, ... 64 (where the most significant bit is named bit “1”). The ignored bits may be used as parity bits that carry no information in the key.
Next begins the sequence of operations known as a cycle or a round . The 64 permuted data bits are broken into a left half and a right half of 32 bits each. For a 32-bit right half to be combined with a 56-bit key, two changes are needed. First, the algorithm expands the 32-bit half to 48 bits by repeating certain bits, while reducing the 56-bit key to 48 bits by choosing only certain bits according to tables called S-boxes. These last two operations are called expansion permutations and permuted choice using tables called P-boxes.
The key is shifted left by a number of bits and also permuted (scrambled). The key is combined with the right half, which is then combined with the left half. The result of these combinations becomes the new right half; the old right half becomes the new left half. This sequence of activities, which constitutes a cycle, is shown in Figure 12-2 . The cycles are repeated 16 times. After the last cycle is a final permutation, which is the inverse of the initial permutation.
FIGURE 12-2 A Cycle in DES
Left Data Half 32 bits leads to the second circle divided into four segments. Right Data Half 32 bits and Expansion Permutation 48 bits lead to New Left Data Half (Old Right Half) and to the first circle divided into four segments which leads to Substitution, Permuted Choice 32 bits. Permuted Choice 32 bits leads to Permutation which leads to the second circle divided into four segments, which leads to New Right Data Half. Key Shifted 56 bits is linked multiple times to Key Permuted 48 bits which leads to the first circle divided into four segments.
This same process is repeated separately for each plaintext data block.
Complete DES
Now we can put all the pieces back together, as shown in Figure 12-3 . First, the key is reduced to 56 bits. Then, a block of 64 data bits is permuted by the initial permutation. Following are 16 cycles in which the key is shifted and permuted, half of the data block is transformed with the substitution and permutation functions, and the result is combined with the remaining half of the data block. After the last cycle, the data block is permuted with the final permutation.
FIGURE 12-3 The Complete DES
Input leads to Initial Permutation which leads to L subscript 0 and R subscript 0. Cycle 1 begins. R subscript 0 leads to L subscript 1 = R subscript 0, and also leads to Substitution which leads to Permutation which leads to the first circle divided into four segments. This leads to R subscript 1. Key Shifted shows a left arrow and is linked multiple times to Key Permuted. Cycle 1 ends and cycle 2 begins. L subscript 1 = R subscript 0 leads to the second circle divided into four segments. R subscript 1 leads to L subscript 2 = R subscript 1 which lead to L subscript 15 = R subscript 14 through a dotted line. R subscript 1 also leads to Substitution, Permutation, and to the second circle divided into four segments. The second circle divided into four segments leads to R subscript 2 which leads to R subscript 15 through a dotted line. Key Shifted shows a left arrow and is linked multiple times to Key Permuted. Cycle 2 ends and cycle 3 begins. L subscript 15 = R subscript 14 leads to third circle divided into four segments. R subscript 15 leads to L subscript 16 = R subscript 15. which leads to Inverse Initial Permutation which leads to output. R subscript 15 leads to Substitution, Permutation, and to the third circle divided into four segments which leads to R subscript 16. Key Shifted shows a left arrow and is linked multiple times to Key Permuted. Cycle 3 ends. R subscript 15 leads to Inverse Initial Permutation which leads to output. R subscript 16 leads to Inverse Initial Permutation which leads to output.
Decryption of DES
The same DES algorithm is used both for encryption and decryption . This result is true because cycle j derives from cycle j - 1 in the following manner:
L j \= R j - 1 1
R j \= L j - 1 ⊕ f R j - 1 , k j 2
where ⊕ is the exclusive-OR operation and f is the function computed in an expand-shift-substitute-permute cycle. These two equations show that the result of each cycle depends only on the previous cycle.
By rewriting these equations in terms of R j - 1 and L j - 1 , we get
R j - 1 \= L j 3
and
L j - 1 \= R j ⊕ f R j - 1 , k j 4
Substituting (3) into (4) gives
L j - 1 \= R j ⊕ f L j , k j 5
Equations (3) and (5) show that these same values could be obtained from the results of later cycles. This property makes DES a reversible procedure; we can encrypt a string and also decrypt the result to derive the plaintext again.
With DES, the same function f is used forward to encrypt or backward to decrypt. The only change is that the keys must be taken in reverse order k 16 , k 15 , … , k 1 for decryption. Using one algorithm either to encrypt or to decrypt is convenient for a hardware or software implementation of DES.
Questions About the Security of DES
Since its first announcement, there was controversy concerning the security provided by DES. Although much of this controversy has appeared in the open literature, certain features of DES have only been inferred by outside analysts.
Design of the Algorithm
Initially, there was concern with the basic algorithm itself. During development of the algorithm, the National Security Agency (NSA) indicated that key elements of the algorithm design were “sensitive” and would not be made public. These elements include the rationale behind transformations of the S-boxes, the P-boxes, and the key changes. There are many possibilities for the S-box substitutions, but one particular set was chosen for DES. Inquiring minds immediately wondered why that set.
Two issues arose about the design’s secrecy. The first involved a fear that certain “trapdoors” had been imbedded in the DES algorithm so that a covert, easy means was available to decrypt any DES-encrypted message. For instance, such trapdoors would give the NSA the ability to inspect private communications.
After a congressional inquiry, the results of which are classified, an unclassified summary exonerated the NSA from any improper involvement in the DES design. (For a good discussion on the design of DES, see [ SMI88 ].)
The second issue addressed the possibility that a design flaw would be (or perhaps has been) discovered by a cryptanalyst, this time giving an interceptor the ability to access private communications.
Both Bell Laboratories [ MOR77 ] and the Lexan Corporation [ LEX76 ] scrutinized the operation (not the design) of the S-boxes. Neither analysis revealed any weakness that impairs the proper functioning of the S-boxes. The DES algorithm has been studied extensively and, to date, no serious flaws have been published.
In response to criticism, the NSA released certain information on the selection of the S-boxes ([ KON81 , BRA77 ]).
-
No S-box is a linear or affine function of its input; that is, the four output bits cannot be expressed as a system of linear equations of the six input bits.
-
Changing one bit in the input of an S-box results in changing at least two output bits; that is, the S-boxes diffuse their information well throughout their outputs.
-
The S-boxes were chosen to minimize the difference between the number of 1s and 0s when any single input bit is held constant; that is, holding a single bit constant as a 0 or 1 and changing the bits around it should not lead to disproportionately many 0s or 1s in the output.
Number of Iterations
Many analysts wonder whether 16 iterations are sufficient. Since each iteration diffuses the information of the plaintext throughout the ciphertext, it is not clear that 16 cycles or rounds diffuse the information sufficiently. For example, with only one cycle, a single ciphertext bit is affected by only a few bits of plaintext. With more cycles, the diffusion becomes greater, so ideally no one ciphertext bit depends on any subset of plaintext bits. Phrased differently, any single bit change to the plaintext affects many bits of the output ciphertext.
Experimentation with both DES and its IBM predecessor Lucifer was performed by the NBS and by IBM as part of the certification process of the DES algorithm. These experiments have shown [ KON81 ] that 8 iterations are sufficient to eliminate any observed dependence. Thus, the 16 iterations of the DES constitute a wide margin for safety.
Differential Cryptanalysis
In 1990, Eli Biham and Adi Shamir [ BIH90 , BIH91 and BIH93 ] announced a technique they named differential cryptanalysis . The technique applied to cryptographic algorithms that use substitution and permutation. This powerful technique was the first to have impressive effects against a broad range of algorithms of this type.
The technique uses carefully selected pairs of plaintext with subtle differences and studies the effects of these differences on resulting ciphertexts. If particular combinations of input bits are modified simultaneously, particular intermediate bits are also likely with a high probability to change in a particular way. The technique looks at the exclusive OR (XOR) of a pair of inputs; the XOR will have a 0 in any bit in which the inputs are identical and a 1 where they differ.
The full analysis is rather complicated, but we present a sketch of it here. The S-boxes transform 6 bits into 4. If the S-boxes were perfectly uniform, one would expect all 4-bit outputs to be equally likely. However, as Biham and Shamir show, certain similar texts are more likely to produce similar outputs than others. For example, examining all pairs of 6-bit strings with an XOR pattern 35 in hexadecimal notation (that is, strings of the form ddsdsd where d means the bit value is different between the two strings and s means the bit value is the same) for S-box S 1 , the researchers found that the pairs have an output pattern of dsss 14 times, ddds 14 times, and all other patterns a frequency ranging between 0 and 8. That says that an input of the form ddsdsd has an output of the form dsss 14 times out of 64, and ddds another 14 times out of 64; each of these results is disproportionately high, almost 1/4, which continues to the next round. Biham and Shamir call each of these recognizable effects a “characteristic”; they then extend their result by concatenating characteristics. The attack lets them infer values in specific positions of the key. If m bits of a k -bit key can be found, the remaining k - m bits can be found through an exhaustive search of all 2 k - m possible keys; if m is large enough, the 2 k - m exhaustive search is feasible.
In [ BIH90 ], the authors present the conclusions of many results they have produced by using differential cryptanalysis; they describe the details of these results in the succeeding papers. The attack on Lucifer, the IBM-designed predecessor to DES, succeeds with only 30 ciphertext pairs. FEAL is an algorithm similar to DES that uses any number of rounds; the n -round version is called FEAL- n . FEAL-4 can be broken with 20 chosen plaintext items [ MUR90 ], FEAL-8 [ MIY89 ] with 10,000 pairs [ GIL90 ]; and FEAL- n for n ≤ 31 can be broken faster by differential cryptanalysis than by full exhaustive search [ BIH91 ]. In short, FEAL is vulnerable to differential cryptanalysis.
The results concerning DES are impressive. Shortening DES to fewer than its normal 16 rounds allows a key to be determined from chosen ciphertexts in fewer than the 2 56 (actually, expected value of 2 55 ) searches. For example, with 15 rounds, only 2 52 tests are needed (which is still a large number of tests); with 10 rounds, the number of tests falls to 2 35 , and with 6 rounds, only 2 8 tests are needed. However, with the full 16 rounds, this technique requires 2 58 tests, or 2 2 \= 4 times more effort than exhaustive search would require. In other words, differential cryptanalysis reduces the amount of work to derive a key for the FEAL ciphers and for a restricted version of DES with fewer than the standard 16 rounds. On the other hand, differential cryptanalysis produces no saving of work, and in fact increases the expected work, for regular DES.
Finally, the authors show that with randomly selected S-box values, DES is easy to break. Indeed, even with a change of only one entry in one S-box, DES becomes easy to break. One might conclude that the design of the S-boxes and the number of rounds were chosen to be optimal.
In fact, that is true. Don Coppersmith of IBM, one of the original team working on Lucifer and DES, acknowledged [ COP92 ] that when they were designing DES in 1974, the design team did know of the technique of differential cryptanalysis. The team structured the S-boxes and permutations in such a way as to defeat that line of attack. The differential cryptanalysis work shows that the basis of DES was indeed solid, and NSA’s unexplained design changes only strengthened it.
Attacking Ciphertext
By the time they are in use, cryptographic algorithms are generally solid. The community of cryptologists includes many bright minds who attack each others’ results aggressively but with good nature. The minor details of implementation and use are more problematic.
In this section we consider two problems and two solutions common to block ciphers. We present them here because they relate to how DES, and other symmetric algorithms such as AES, are used.
Chaining
You may have noticed a weakness in description of the DES algorithm. DES uses the same process for each 64-bit block. That means that any identical plaintext blocks encrypted with the same key will have the same output. Of course, you might say, the process has to be regular and consistent for decryption to be possible, and that is certainly true.
Now think like an attacker. Suppose a bank uses DES to encrypt a network stream of data containing instructions to transfer money from one account to another. The bank chooses a key to use for some period of time, for example, a day, because changing keys is cumbersome. Just to make this argument simple, assume the amount and account number are both exactly 64 bits long and happen to appear on 64-bit boundaries within the transfer message. (A similar argument will work regardless of the lengths and positions of the fields.) In Figure 12-4 we depict the general form of these messages. The figure also shows four examples, to transfer (1) $100 from Annie to Brian, (2) $500 from Carole to Drew, (3) $0.01 from Evin to our malicious agent Zelda, and (4) the same amount from Feng to Zelda. (Note: the encrypted values in these four example figures are fictitious, created just for these explanations; no real cryptography was applied.)
FIGURE 12-4 Transfer Messages
The column headers read, Date (64 bits), From acct, To acct, Trf Num, and Amount. Table 1: 1 Aug, Annie, Brian, 0001, 100.00; ciphertext: apqrwx, w2z%pr, grd#d#, wenh55, and 3dhop3. Table 2: 1 Aug, Carole, Drew, 0002, 500.00; apqrwx, df7ynm, gyl615, 23opdw, and kslw4l. Table 3: 1 Aug, Evin, Zelda, 0003, and 0.01; apqrwx, bze4n4, cd4wx7, wenh55, and otm4m5. Table 4: 1 Aug, Feng, Zelda, 0004, and 0.01; apqrwx, br5hun, cd4wx7, ztpztp, and otm4m5.
Because these are networked communications, Zelda can see them but only in ciphertext form. Although she cannot interpret the content, she can look for similarities. Let us assume she knows where to look for the different fields. She will see two messages with the same encrypted destination account numbers and infer that those are probably the two transfers to her account. With that knowledge, she can create new messages, as shown in Figure 12-5 , to transfer money from Annie and Carole to her account.
FIGURE 12-5 Fabricated Transfer Messages
Table 1: 1 Aug, Annie, Zelda, 0001, and 100.0; apqrwx, w2z%pr, cd4wx7, wenh55, and 3dhop3. Table 2: 1 Aug, Carole, Zelda, 0002, and 500.00; apqrwx, df7ynm, cd4wx7, ztpztp, and kslw4l.
Without ever accessing the underlying plaintext, Zelda has fabricated two encrypted messages that might pass. (She still has a little more work to do to cover for her reuse of a previous transaction number.) The problem described here occurs because each plaintext block is encrypted independently from all other blocks, so an attacker can reorder and substitute blocks undetected.
The solution to this problem is called chaining . If the encryption of each block depends not only on the direct ciphertext of its distinct content but also on previous content, the order and position of each block in the chain is fixed. Chaining would detect Zelda’s attempt to reuse blocks from previous encryptions. Similarly, chaining would reveal whether Zelda shuffled the blocks of ciphertext.
Chaining connects blocks of ciphertext to prevent swapping or reordering of blocks.
In Figure 12-6 you can see the effect of chaining. In the previous figure Annie’s account number encrypted twice as w2z%pr. But in this figure Annie’s account number is first combined with the encryption of the date block using the exclusive-OR (⊕) function, producing the result C4UI6H. That C4UI6H is then encrypted, producing the result bl3tfr. Comparing the top and bottom of the figure, you can see that the first field, the date, encrypts the same in both halves, but the next fields differ, so all subsequent blocks are influenced by this difference. The encrypted value of each block feeds into the plaintext of the next block, and so each encrypted block depends on the values of all preceding blocks. Thus, no attacker can reorder or substitute encrypted blocks without destroying this chain of encryption. If we had shown results for the last two lines from the original figure, you would see that the two Zelda blocks would be different because each depends on different preceding data.
FIGURE 12-6 Chained Encryption
Table 1: 1 Aug, Annie, Brian, 0001, 100.00; ciphertext: apqrwx, chained to a positive signed apqrwx over C4UI6H bl3tfr which is chained to a positive signed bl3tfr over RMX22A lbl9id. Table 2: 1 Aug, Carole, Drew, 0002, 500.00; apqrwx, chained to a positive signed apqrwx over ABCDEF 3fhosb which is chained to a positive signed 3fhosb over OBX34H h4e5oe.
Chaining works only if the underlying plaintext has some structure. A date field, for example, might have the form ddmmyyyy where dd is between 1 and 31, mm is between 1 and 12, and yyyy is between 1900 and 2100. If decryption yields a result of 47540099, the recipient and any processing program would detect a fault. If the value represents an account balance, and any value from 0 to 99999999 is possible, modification might go undetected. For this reason, system designers build in error detection codes to determine whether received data have been tampered with.
Initialization Vector
You may have noticed one more difficulty with the chaining example. Although data blocks along the chain are distinct, the first block (the date) has no prior context on which to depend, and thus it would always encrypt the same. The solution to this difficulty is a slight extension to the chaining approach.
To start the encryption of a data stream, you first create one extra block containing any value. (Such an arbitrary value is known as a nonce .) The exact value is insignificant as long as it changes for each encryption; a random number generator is useful. Then, as shown in Figure 12-7 , you apply chained encryption, starting with the first block (the nonce), and linking subsequent blocks together as in the previous example. In this way, the first real data block (actually the second block encrypted) is different from one time to the next because the random initialization vector is different.
An initialization vector prevents identical plaintext from yielding identical ciphertext in separate data streams.
FIGURE 12-7 Chained Encryption with an Initialization Vector
Table 1: Init. Vect., 1, 1 Aug, Annie, Brian, 0001, 100.00; ciphertext: chained to sst501 over 4R6YHH smd21x, smd21x over DHP5W3 0xkpr9, 0xkpr9 over RJE32A s360xp, etc. Table 2: Init. Vect. 2, 1 Aug, Carole, Drew, 0002, 500.00; ciphertext: qfu444 chained to qfu444 over FLP5P5, wd40rt over GT457U kp7p7p, kp7p7p over OR1F8E h4e5oe.
These two chaining techniques are similarly applicable with most symmetric ciphers.
AES
As we have said, DES has now outlived its usefulness. Because of the concerns about the fixed-sized key of DES and the fact that computing power was continually increasing against that stationary target, security analysts began to search for a replacement for DES about 20 years after it was developed.
The AES Contest
In January 1997, NIST (as the NBS was renamed in 1988) called for cryptographers to develop a new encryption system. As with the call for candidates from which DES was selected, NIST made several important restrictions. The algorithm had to be unclassified and publicly disclosed, and, to promote widespread use by businesses, NIST stipulated that the algorithm be offered royalty free for use worldwide. The DES replacement would also have to be a symmetric block cipher that could operate on blocks of at least 128 bits. Finally, to overcome the key-length limitation of DES, NIST required the new algorithm to be able to use keys 128, 192, and 256 bits long. In August 1998, 15 algorithms were chosen from among those submitted; a year later, the field of candidates was narrowed to 5 finalists. The 5 then underwent extensive public and private scrutiny. The final selection was made on the basis not only of security but also of cost or efficiency of operation and ease of implementation in software. NIST described the finalists not chosen as also having adequate security for AES—no cryptographic flaws were identified in any of the 5. Thus, the selection was based on efficiency and implementation characteristics. The winning algorithm, submitted by two Dutch cryptographers, was Rijndael (pronounced RINE dahl); the algorithm’s name is derived from the creators’ names, Vincent Rijmen and Joan Daemen.
The algorithm is based on arithmetic in the finite field GF 2 8 , but most encryption operations can be done by table lookup, thereby simplifying the implementation of AES.
The algorithm consists of 10, 12, or 14 cycles, for a 128-, 192-, or 256-bit key, respectively. Each cycle (called a “round” in the algorithm) consists of four steps:
-
Byte substitution. This step uses a substitution replacing each byte of a 128-bit block according to a substitution table. This is a straight diffusion operation.
-
Shift row. Certain bits are shifted to other positions. This is a straight confusion operation.
-
Mix column. This step involves shifting left and XORing bits with themselves. These operations implement both confusion and diffusion.
-
Add subkey. Here, a portion of the key unique to this cycle is XORed with the cycle result. This operation delivers confusion and incorporates the key.
Each round performs both confusion and diffusion, as well as blending the key into the result. The structure of AES is shown in Figure 12-8 .
FIGURE 12-8 Structure of AES
An arrow labeled input points at 1. Byte sub which connects to 3. Mix columns through 2. Shift row. Each row in the byte column shows a box linked to another box with the letter S. Under Mix columns, there are four rows and four columns of boxes. The first S connects to the first box of mix columns which links to the first and second boxes in the second row. The second box in the second row links to the second and third in the third column. The second box in the third row links to the first and the second boxes in the fourth row. The second S points at the fourth row first box. The third S points at the second row first box. The fourth S points at the third row first box. Each box in the fourth row is linked to a box with the text k (4. Add Round key). There are four boxes below the boxes labeled k, followed by an output arrow. The next cycle continues.
Strength of Rijndael
The Rijndael algorithm underwent extensive cryptanalysis by both government and independent cryptographers. Its Dutch inventors have no relationship to the NSA or any other part of the U.S. government, so there is no suspicion that the government somehow weakened the algorithm or added a trapdoor. Although the steps of a cycle are simple to describe and seem to be almost random transformations of bits, these transformations have a sound mathematical origin.
When Rijndael’s predecessor, DES, was adopted, two questions quickly arose:
-
How strong is it, and in particular, are there any backdoors?
-
How long would it be until the encrypted code could be routinely cracked?
With many years of use, suspicions of weakness of DES (intentional or not) and backdoors have pretty much been quashed. Not only have analysts failed to find any significant flaws, but research described earlier in this chapter has shown that seemingly insignificant changes weaken the strength of the algorithm—that is, the algorithm is the best it can be. The second question, about how long DES would last, went unanswered for a long time but then was answered very quickly by two experiments in 1997 and 1998, in which DES was cracked in days [ EFF98 ]. Thus, more than 20 years after the launch of DES, the power of individual specialized processors and of massive parallel searches finally overtook the fixed DES key size.
We must ask the same questions about AES: Does it have flaws, and for how long will it remain sound? We cannot address the question of flaws yet, other than to say that teams of cryptanalysts pored over the design of Rijndael during the two-year review period without finding any problems. Furthermore, since AES was adopted in 2001, the only serious challenges to its security have been highly specialized and theoretical.
The longevity question is more difficult, but also more optimistic, to answer for AES than for DES. Remember that extending the key by one bit doubles the effort of a brute force attack. The AES algorithm as defined can use keys 128, 192, or 256 bits long. Thus, relative to a 56-bit DES key, a 128-bit AES key results in 72 doublings, which means the work is 2 72 (approximately 4 * 10 21 ) times as hard. Key lengths of 192 and 256 bits extend this already prodigious effort even more. But because there is an evident underlying structure to AES, it is even possible to use the same general approach on a slightly different underlying problem and accommodate keys of even larger size. Thus, unlike DES, AES lets users move to longer keys any time technology threatens to allow an analyst to overtake the current key size. Furthermore, this extended key length builds in a margin of safety if clever attacks divide the effort in a brute force attack.
Keys in AES can be as long as 256 bits, a length unlikely to succumb to cryptanalytic attacks in the reasonable future.
Nevertheless, cryptanalysts have continued to explore AES. From its introduction in 2001, there have been minor exposures of an academic interest, but nothing threatening the security of AES. One researcher described one of these attacks: “While these complexities are much faster than exhaustive search, they are completely non-practical, and do not seem to pose any real threat to the security of AES-based systems” [ BIR10 ]. That research effort went on to demonstrate an attack that reduced from 2 256 to 2 45 the effort to deduce a single key, but this attack used a 10-round version of AES, not the standard 14 rounds. Such an attack is a noticeable reduction in time, but the attack is rather like fighting a man who has one hand tied behind his back. A fairer attack is presented by Andrey Bogdanov and colleagues [ BOG11 ], in which they reduce the complexity of deriving a key by a multiple of four, that is, from 2 256 to 2 254 , with similar results for 128- and 192-bit key versions. Reducing the work by a factor of four is hardly any change at all.
No attack to date has raised serious question as to the overall strength of AES.
Other Symmetric Algorithms
There are thousands of other symmetric encryption algorithms. As we state earlier in this chapter, cryptology is an extraordinarily complex subject, certainly not one to be tackled lightly. Although a friend of a friend might have the background to devise a solid algorithm, be wary of amateurs practicing cryptology (or brain surgery, for that matter). You should choose cryptography with care, and certainly match your assessment of the strength of a technique to the value of the data you want to protect. Well-known algorithms that have withstood concerted scrutiny are your best tools.
We now turn to even more sophisticated algorithms in asymmetric cryptography.
12.3 Asymmetric Encryption
As we present in Chapter 2 , asymmetric cryptography, also known as public key, uses two different but related keys. One key encrypts data, and its matching counterpart decrypts. Mathematically, it is infeasible to derive one key from the other, so it is safe to release one key (often called the public key) as long as you do not disclose the other one (often called the private key).
The RSA algorithm is a cryptosystem based on an underlying hard problem. This algorithm was introduced in 1978 by Rivest, Shamir, and Adleman [ RIV78 ]. RSA has been the subject of extensive cryptanalysis. No serious flaws have yet been found—not a guarantee of its security but suggesting a high degree of confidence in its use.
The RSA Algorithm
In this section we present the RSA algorithm in two parts. First, we outline RSA, to give you an idea of how it works. Then, we delve more deeply into a detailed analysis of the steps involved.
Introduction to the RSA Algorithm
The RSA algorithm requires finding terms that multiply to a particular product, more commonly called factorization. The RSA encryption algorithm incorporates results from number theory, combined with the difficulty of determining the prime factors of a target. The RSA algorithm operates with arithmetic mod n , which makes factorization extremely difficult.
The encryption algorithm is based on the underlying problem of factoring large numbers, a problem for which the fastest known algorithm is exponential in time.
Two keys, d and e , are used for decryption and encryption. They are actually interchangeable. The plaintext block P is encrypted as P e mod n . Because the exponentiation is performed mod n , factoring P e to uncover the encrypted plaintext is daunting. However, the decrypting key d is carefully chosen so that P e d mod n \= P . Thus, the legitimate receiver who knows d simply raises ciphertext P e to the power d , obtaining P e d mod n \= P and recovers P without having to factor P e mod n.
Detailed Description of the Encryption Algorithm
The RSA algorithm uses two keys, d and e , which work in pairs, for decryption and encryption, respectively. A plaintext message P is encrypted to ciphertext C by
c \= P e mod n
The plaintext is recovered by
P \= C d mon n
Because of symmetry in modular arithmetic, encryption and decryption are mutual inverses and commutative. Therefore,
P \= C d mod n \= P e d mod n \= P d e mod n
This relationship means that one can apply the encrypting transformation and then the decrypting one, or the decrypting one followed by the encrypting one.
Deriving a Key Pair
The encryption key consists of the pair of integers ( e , n ), and the decryption key is ( d , n ). The starting point in finding keys for this algorithm is selection of a value for n. The value of n should be quite large, a product of two primes p and q . Both p and q should be large themselves. Typically, p and q are at least 100 decimal digits each, so n is approximately 200 digits (about 512 bits) long; depending on the application, 768, 1024, or more bits may be more appropriate. A large value of n effectively inhibits factoring n to infer p and q .
Next, a relatively large integer e is chosen so that e is relatively prime to p - 1 * q - 1 . (Recall that “relatively prime” means that e has no factors in common with p - 1 * q - 1 .) An easy way to guarantee that e is relatively prime to p - 1 * q - 1 is to choose e as a prime that is larger than both p - 1 and q - 1 ; as a prime, e will have no nontrivial factors.
Finally, select d such that
e * d \= 1 mod p - 1 * q - 1
Strength of the RSA Algorithm
The RSA algorithm derives strength from the fact that it is based on the problem of efficiently factoring numbers in a finite field, a long-standing open problem in number theory. The problem is, of course, solvable, using the brute force technique of trying all possible factors, but in a large field, that is, for large values of n , the brute force technique is infeasible. The trick that makes RSA encryption workable depends on a hidden technique for picking n.
Mathematical Foundations of the RSA Algorithm
The Euler totient function φ( n ) is the number of positive integers less than n that are relatively prime to n . If p is prime, then
φ p \= p - 1
Furthermore, if n \= p * q , where p and q are both prime, then
φ n \= φ p * φ q \= p - 1 * q - 1
Euler and Fermat proved that
x φ n ≡ 1 mod n
for any integer x if n and x are relatively prime.
Suppose we encrypt a plaintext message P by the RSA algorithm so that E P \= P e . We need to be sure we can recover the message. The value e is selected so we can easily find its inverse d . Because e and d are inverses mod φ( n ),
e * d ≡ 1 mod φ n
or
e * d \= k * φ n + 1 a
for some integer k.
Because of the Euler–Fermat result, assuming P and p are relatively prime,
P p - 1 ≡ 1 mod p
and, since p - 1 is a factor of φ( n ),
P k * φ n ≡ 1 mod p
Multiplying by P produces
P k * φ n + 1 ≡ P mod p
The same argument holds for q , so
P k * φ n + 1 ≡ P mod q
Combining these last two results with (a) produces
P e d \= P e * d \= P k * φ n + 1 \= P mod p \= P mod q
so that
P e d \= P mod n
and e and d are inverse operations.
Example
Let p \= 11 and q \= 12 , so that n \= p * q \= 143 and φ n \= p - 1 * q - 1 \= 10 * 12 \= 120 . Next, an integer e is needed, and e must be relatively prime to p - 1 * q - 1 . Choose e \= 11 .
The inverse of 11 mod 120 is also 11, since 11 * 11 \= 121 \= 1 mod 120 . Thus, both encryption and decryption keys are the same: e \= d \= 11 . (For the example, e \= d is not a problem, but in a real application you would want to choose values where e is not equal to d .)
Let P be a “message” to be encrypted. For this example we use P \= 7 . The message is encrypted as follows: 7 11 mod 143 \= 106 , so that E 7 \= 106 . (Note: This result can be computed fairly easily with the use of a common pocket calculator. 7 11 \= 7 9 * 7 2 . Then 7 9 \= 40 353 607 , but we do not have to work with figures that large. Because of the reducibility rule, a * b mod n \= a mod n * b mod n mod n . Since we will reduce our final result mod 143, we can reduce any term, such as 7 9 , which is 8 mod 143. Then, 8 * 7 2 mod 143 \= 392 mod 143 \= 106 .)
This answer is correct since D 106 \= 106 11 mod 143 \= 7 .
Use of the Algorithm
The user of the RSA algorithm chooses primes p and q , from which the value n \= p * q is obtained. Next, e is chosen to be relatively prime to p - 1 * q - 1 ; e is usually a prime larger than p - 1 or q - 1 . Finally, d is computed as the inverse of e mod (φ( n )).
The user distributes e and n and keeps d secret; p , q , and φ( n ) may be discarded (but not revealed) at this point. Notice that even though n is known to be the product of two primes, if they are relatively large (256 or more bits long), it will not be feasible to determine the primes p and q or the private key d from e . Therefore, this scheme provides adequate security for d .
It is not even practical to verify that p and q themselves are primes since that would require considering on the order of 10 50 possible factors. A heuristic algorithm from Solovay and Strassen [ SOL77 ] can determine the probability of primality to any desired degree of confidence.
Every prime number passes two tests. If p is prime and r is any number less than p , then
gcd p , r \= 1
(where gcd is the greatest common divisor function) and
J r , p ≡ r p - 1 / 2 mod p
where J ( r , p ) is the Jacobi function defined as follows.
J r , p \= 1 if r \= 1 J r / 2 , p * - 1 p 2 - 1 / 8 if r is even J p mod r , r * - 1 r - 1 * p - 1 / 4 if r is odd and r ≠ 1
If a number is suspected to be prime but fails either of these tests, it is definitely not a prime. If a number is suspected to be a prime and passes both of these tests, the likelihood that it is prime is at least 1/2.
The problem relative to the RSA algorithm is to find two large primes p and q . With the Solovay and Strassen approach, you first guess a large candidate potential prime p . You then generate a random number r and compute gcd( p , r ) and J ( r , p ). If either of these tests fails, p was not a prime, and you stop the procedure. If both pass, the likelihood that p was not prime is at most 1/2. You repeat the process with a new value for r , again chosen at random. If this second r passes, the likelihood that a nonprime p could pass both tests is at most 1/4. In general, after the process is repeated k times without either test failing, the likelihood that p is not a prime is at most 1 / 2 k . If the candidate p fails, you simply choose another candidate for p and start the procedure again.
Cryptanalysis of the RSA Algorithm
The RSA method has been scrutinized intensely by professionals in computer security and cryptanalysis. Several minor problems have been identified with it, none of significant concern; Boneh [ BON99 ] catalogs known attacks on RSA. He notes no successful attacks on RSA itself, but several serious but improbable attacks on implementation and use of RSA.
Elliptic Curve Cryptosystems
Elliptic Curve Cryptography (ECC) is another asymmetric algorithm that was discovered in 1985 by Victor Miller (IBM) and Neil Koblitz (University of Washington) [ MIL85 , KOB87 ] as an alternative mechanism for implementing public key cryptography. Unlike RSA, ECC is based on logarithms in finite fields; an advantage of ECC is that equivalent security can be had with shorter key lengths than RSA.
The mathematics behind elliptic curve cryptography is quite sophisticated, more so than we can possibly present here. The elliptic curves are ( x , y ) coordinates of points that satisfy an equation such as y 2 \= x 3 + a x + b for constants a and b. Nick Sullivan [ SUL13 ] points out that any nonvertical straight line passes through at most three points on the curve. And, given any two points, P and Q, we can find the third point R through which the line PQR passes. When P \= x p , y p and Q \= x Q , y Q ),
P + Q \= R
where
s \= y P - y Q / x P - x Q x R \= s 2 - x P - x Q
and
y R \= - y P + s * x P - x R
Note that s is the slope of the line through P and Q. Thus, given P and Q, we can find the third point R on the line PQR algebraically. That means we can also find the next point T on QRT, then V on RTV, and so on. There is also a formula that lets us start with a single point and derive a second: One point can get us a second, and two points get us a third.
The elliptic curve cryptosystems add one more twist, which should be familiar from the mathematics of the RSA algorithm: ECC operations are done in a finite group, the integers mod p for some prime p . Thus, although both x and y values increase without bound in the basic ECC equation, restricting the arithmetic to a finite field is what makes the cryptographic problem hard to reverse. Given a starting point P and an end point Z and constraining results to be in a finite field, the question is how many steps does it take to get from P to Z. More formally, find the value k for which P k \= Z . In other words, find k, the base P logarithm of Z. It turns out the fastest known way to answer that question is to start with P and generate all intermediate points until you obtain Z.
Elliptic curve cryptography is seldom used by itself for public key encryption. However, it is often used as a component in digital signatures. In 2005, the NSA presented its strategy and recommendations for securing U.S. government sensitive and unclassified communications. The strategy included a recommended set of advanced cryptography algorithms known as Suite B. The protocols included in Suite B are Elliptic Curve Diffie-Hellman (ECDH) and Elliptic Curve Menezes-Qu-Vanstone (ECMQV) for key exchange and agreement; the Elliptic Curve Digital Signature Algorithm (ECDSA) for digital signatures; the Advanced Encryption Standard (AES) for symmetric encryption; and the Secure Hashing Algorithm (SHA). What appealed to the NSA about ECC was its strong security, efficiency, and scalability over public key cryptography algorithms.
Digression: Diffie–Hellman Key Exchange
If your skills of exponentiation and factoring in a finite field are not overstressed, we have one more point to make in that area. In Chapter 2 we present the Rivest–Shamir key exchange protocol [ RIV84 ] (not to be confused with the RSA encryption algorithm), by which our two friends Amy and Bill can securely agree on a cryptographic key. That protocol has Amy and Bill sending their public keys to each other, and then one (Amy, for example) sending half of a symmetric key to Bill. Bill responds with half of a random number, Amy responds with the other half of the key, and Bill and Amy exchange another number to guard against a man-in-the-middle. The whole process is straightforward and uses no higher mathematics.
Diffie and Hellman [ DIF76 ] have a different, shorter (fewer steps) protocol that uses some of the same mathematical operations as RSA encryption. Although it is for key exchange, not encryption, we present it here because of its relation to the asymmetric algorithms just presented.
For Amy and Bill to agree on a secret (symmetric) encryption key, they follow these steps.
-
Amy and Bill agree on a base g and modulus p .
-
Amy chooses a secret integer a and sends Bill A \= g a mod p .
-
Bill chooses a secret integer b and sends Amy B \= g b mod p .
-
Amy computes s \= B a mod p \= g b a mod p .
-
Bill computes s \= A b mod p \= g a b mod p \= g b a mod p .
-
Amy and Bill now share s.
Although simple, this protocol remains solid. It is typically used in SSL or HTTPS transmissions on the internet, often with p < 2 1024 . The only known weakness is the work factor. If p is too small, the search for factors of g a mod p becomes feasible. A well-funded, dedicated attacker—for example, a malicious government—could afford special-purpose hardware to do the exhaustive factoring. A protocol based on the ECC scheme avoids this problem.
Now we turn to two applications of cryptography: message digests and digital signatures, both of which we introduce in Chapter 2 . In this chapter we explore the algorithms in more detail.
12.4 Message Digests
In Chapter 2 we introduce the concept of error detection and correction codes. In particular, we describe one-way and cryptographic hash functions, both of which are designed to protect against malicious attempts to modify data while adjusting the code value to match the modified data.
Hash Functions
As presented in Chapter 2 , hash or message digest functions are ways to detect possible changes to a block of data. These functions signal unintentional changes as well as intentional (malicious) ones.
For unintentional changes, the signal function can be open, for example, parity bits or more complicated error detection and correction codes, such as Hamming codes [ HAM50 ] and Reed Solomon codes [ REE60 ]. In this book we are more interested in schemes for detecting malicious change and preventing the attacker from subverting the detection technique.
One-Way Hash Functions
One-way hash functions are a cryptographic construct with multiple uses. They are used in conjunction with public key algorithms for both encryption and digital signatures. They are used for integrity checking. They are used in authentication. They are used in communications protocols. Perhaps more than encryption algorithms, one-way hash functions are real workhorses of modern cryptography.
One-way functions prevent an outsider from taking an existing hash result and determining other data values that match that hash result. Thus, Hector might have received a message saying “I willingly give to Hector my prized golden sponge cake recipe” and some other things. Hector can certainly change “sponge cake recipe” to “cryptocurrency collection,” but then Hector is stuck: He needs to make other changes to the message, but he needs to know other content that would produce the original hash value. With a one-way function he can guess “recipe file,” “box of pieces of string too short to use,” and so forth. But he has to invent each such phrase and test it. It would be easier if he could run the hash function in reverse and get a list of inputs that would produce a given hash result. Alas, with a one-way function Hector is going to have to keep trying until he finds a match. As shown in Chapter 2 , hash function, results are sensitive to even minute changes: Adding or changing one bit profoundly changes the output.
Modern hash functions must meet two criteria: They are one-way, meaning that they convert input to a digest, but it is infeasible to start with a digest value and infer an input that could have produced that digest. Second, they do not have obvious collisions, meaning that it is infeasible to find a pair of different plaintexts that produce the same digest. 3
- Note: Some authors refer to this second property as “collision free,” but that is a misleading term. Every hash function will have many collisions because the function takes a relatively large input and produces a relatively small digest. It is mathematically impossible to reduce 512 bits to a 128-bit digest and not have collisions. The point is that the collisions are unpredictable. We know collisions will occur; it is just infeasible to predict which pairs will collide or, given one input, to enumerate other inputs with which the first will collide.
Hash functions must be one-way and have no feasible way to force collisions.
Message Digests
The most widely used cryptographic hash functions are MD4, MD5 (where MD stands for Message Digest), and SHA or SHS (Secure Hash Algorithm or Standard). The MD4/5 algorithms were invented by Ronald Rivest and RSA Laboratories in 1990–1992. MD5 is an improved version of MD4. Both condense a message of any size to a 128-bit digest.
SHA is actually a growing family of algorithms: SHA-0, the original SHA, based on MD4/MD5, was published by NIST in 1993 but was withdrawn shortly thereafter because of an undisclosed “significant flaw.” It was replaced by a slightly revised version, known as SHA-1. SHA-1 produces a 160-bit message digest from any input up to 2 64 bits.
Wang et al. [ WAN05 ] announced cryptanalytic attacks on SHA-1, MD4, and MD5. For SHA-1, the attack is able to find two plaintexts that produce the same hash digest in approximately 2 63 steps, far short of the 2 80 steps that would be expected of a 160-bit hash function and feasible for a moderately well financed attacker. Although this attack does not mean SHA-1 is useless (the attacker must collect and analyze a large number of ciphertext samples), it does suggest use of long digests and long keys.
SHA-2
In 2008, NIST published a new hash standard, FIPS 180-3 [ NIS08 ], that defines algorithms based on the SHA algorithm but that produce significantly longer digests, which counteract the attack described by Wang. These new algorithms are known collectively as SHA-2.
SHA-3
NIST also commenced a competition in 2008 to select a new hash algorithm to be known as SHA-3. In 2012, NIST formally announced selection of K ECCAK [ NIS14 , BER14 ] as the winner, to be designated SHA-3; like SHA-2, it is also a family of algorithms. SHA-3 also allows more variation than its predecessors: The input and block size are virtually unlimited. More important, a form of SHA-3 called SHAKE allows a variable-length digest size. (SHAKE stands for SHA algorithm based on K ECCAK .) Longer digests have fewer collisions, which implies less likelihood of finding two input strings that result in the same digest.
Immediately after the announcement there arose a controversy because of changes NIST sought in the internal structure of the algorithm. The basis of concern was a fear that NSA had somehow weakened the internals to make the algorithm easier for it to break. In fact, it seems that NIST requested some minor changes for performance reasons, but those changes do not weaken the algorithm. Bruce Schneier essentially put such concerns to rest in his blog [ SCH13 ]:
The K ECCAK permutation remains unchanged. What NIST proposed was reducing the hash function’s capacity in the name of performance. One of K ECCAK ’s nice features is that it’s highly tunable.
I do not believe that the NIST changes were suggested by the NSA. Nor do I believe that the changes make the algorithm easier to break by the NSA. I believe NIST made the changes in good faith, and the result is a better security/performance trade-off.
The structure of SHA-3 is different from its predecessors in that it uses far fewer cycles, thus improving performance significantly. The algorithms do use considerably more internal memory (1600 bits as opposed to 512 for SHA-2), but that amount of added space is available for most application domains.
Properties of MD5 and the SHA algorithms are presented in Table 12-1 .
Table 12-1 Current Secure Hash Standard Properties
| Algorithm | Maximum Message Size (bits) | Block Size (bits) | Rounds | Message Digest Size (bits) |
|---|---|---|---|---|
| MD5 | 2 64 | 512 | 64 | 128 |
| SHA-1 | 2 64 | 512 | 80 | 160 |
| SHA-2-224 | 2 64 | 512 | 64 | 224 |
| SHA-2-256 | 2 64 | 512 | 64 | 256 |
| SHA-2-384 | 2 128 | 1024 | 80 | 384 |
| SHA-2-512 | 2 128 | 1024 | 80 | 512 |
| SHA-3-256 | unlimited | 1088 | 24 | 256 |
| SHA-3-512 | unlimited | 576 | 24 | 512 |
| SHAKE128 | unlimited | variable | depends on block size | variable ≤ 256 |
| SHAKE256 | unlimited | variable | depends on block size | variable ≤ 512 |
Authenticated Encryption
We have claimed that encryption protects integrity because an attacker cannot change the ciphertext to allow meaningful change to the underlying plaintext. However, randomly changing the ciphertext has some impact on the result of the decryption. If the plaintext is words, the decrypted text will likely be garbled. If, however, the plaintext is data—images of space being captured continuously, data from a physics experiment, or vital signs of a patient in surgery, for example—the change may not be detected readily.
To counter these problems, cryptographers combine encryption with content validation, using a process known as authenticated encryption or AE . Essentially, the scheme uses a code to prevent undetected modification (either malicious or accidental). This code, sometimes known as an authentication tag , is an integral part of the encryption process. In this way, even if the attacker maliciously changes the ciphertext just to be nasty, the validation code lets the actual receiver know that the received text is not what was sent. Knowing the ciphertext was tampered with does not help the receiver recover the true plaintext, but at least the receiver is on notice to disregard the ciphertext received.
Forms of Automated Encryption
Authenticated encryption comes in several forms, of which the two most popular ones are shown in Figure 12-9 . In encrypt-then-MAC form, the plaintext is first encrypted and then an authentication code is produced from the ciphertext. In encrypt-and-MAC form, the message is encrypted, and concurrently an authentication code is produced from the plaintext. In both forms the ciphertext and its associated authentication code are handled together. When the combination is to be decrypted, the authentication code is recomputed for the decrypted plaintext to ensure no changes have occurred between start and finish.
FIGURE 12-9 Authenticated Encryption (a) Encrypt-then-MAC (b) Encrypt-and-MAC
(a) Encrypt-then-MAC: Plaintext leads to Encryption which leads to Ciphertext, and Hash function leads to MAC. Key1 points at Encryption. Key2 points at Hash function. (b) Encrypt-and-MAC: Plaintext points at Encryption which leads to Ciphertext, and Hash function leads to MAC. Key lies between Encryption and Hash function.
Authenticated Encryption with Additional Data
The goal of authenticated encryption is to provide secrecy and authenticity. The first of these requires an encryption algorithm, typically symmetric, usually AES; the second requires a message digest or message authentication code, usually one of the SHA-1, SHA-2, or SHA-3 algorithms. Numerous other symmetric and hash algorithms exist. Users seldom know what algorithms are used, let alone how to choose among them intelligently.
Authenticated encryption with additional data ( AEAD ) is a variant of AE that allows a recipient to check the integrity of both the encrypted and unencrypted information in a message. AEAD binds the additional (unencrypted) data to the ciphertext so that attempts to insert a valid ciphertext into a different context are detected and rejected. AEAD is required, for example, in network traffic for which the header must be visible, the payload encrypted, and both unmodified and authentic.
Authenticated encryption with additional data treats the encryption–authentication processes as a bundle. Even though the encryption and authentication processes are separate, choosing a prepackaged set of algorithms helps ensure the algorithms are compatible.
AE and AEAD are solutions to long-standing problems, in which encryption for confidentiality or authenticity or integrity alone is insufficient.
ChaCha-Poly
A relative newcomer to the AEAD space is ChaCha20-Poly1305. That mouthful covers two algorithms invented by Daniel Bernstein. ChaCha20 [ BER08 ] is actually a stream cipher, meaning that it generates a pseudorandom stream of bits that is then combined with plaintext bits using the exclusive-OR (XOR) function. The 20 in ChaCha20 means that the algorithm repeats for 20 rounds total. Poly1305 [ BER05 ] is a keyed, message authentication code function. The original version of Poly1305, called Poly1305-AES, used AES as an underlying base, but now Poly1305 refers to a variant with ChaCha20 as a base.
ChaCha20 is more than three times faster than AES, so it is well suited to lower-powered devices like smartphones, tablets, and other personal computing devices. (Special-purpose AES hardware can be added to computers that will perform significant SSL traffic, such as web servers. With such hardware acceleration, AES is faster.)
To be clear, AES is strong, and there are no indications that AES is flawed or that it might be broken, even by a well-financed, dedicated adversary.
In Chapter 4 we describe SSL/TLS, the cryptographic functions that implement secure webpage interaction, HTTPS. The latest version is TLS 1.3 of August 2018. To accommodate clients and servers with different cryptographic capabilities and to allow easy upgrade or replacement of cryptographic algorithms, SSL involves a cryptographic negotiation between client and server in which the client proposes cryptographic algorithms it can handle in preference order, the server responds with algorithms it can handle, and the two settle on a mutually agreeable algorithm. In fact, in the negotiation, client and server choose a suite of algorithms to perform (symmetric) encryption, key exchange, and message authenticity (integrity). DES and AES were the symmetric encryption workhorses; another accepted algorithm was RC4, which was designed in 1987. DES faded in popularity. Then in 2013 the whistleblower Edward Snowden revealed classified documents from NSA suggesting that major countries did or might soon have the computing capability to break RC4 encryption. AES was left as the only viable algorithm for SSL.
Google and the Internet Engineering Task Force (IETF) did not like having only one family of encryptions for all secured internet traffic. Google wanted an alternative to AES so that users had another option in case a flaw was found in AES. In June 2016, the IETF published RFC (Request for Comments, the IETF name for a standards document) 7905; that RFC adds ChaCha20-Poly1305 as algorithms clients and servers can use for SSL/TLS 1.3 connections.
The field of cryptography is continually evolving. Old algorithms are retired, and new ones are invented. The newest widely accepted encryptions are ChaCha20-Poly1305, although by the time you read this, those algorithms, too, may have been superseded. Evolution is good for a field, as improvements help everyone.
Next we turn to digital signing, another area in which content integrity is critical.
12.5 Digital Signatures
Recall from Chapter 2 that a digital signature is, like a handwritten signature, a means of associating a mark unique to an individual with a body of text. The mark should be unforgeable, meaning that only the originator should be able to compute the signature value. But the mark should also be verifiable, meaning that other people should be able to check that the signature comes from the claimed originator.
Digital signatures can be used on electronic documents. They can also attest to the authenticity of music or a recording, a piece of art, or a software program.
The general way of computing digital signatures is with public key encryption; the signer computes a signature value by using a private key, and others can use the public key to verify that the signature came from the corresponding private key.
As we point out in Chapter 2 , a digital signature must meet two requirements and ideally satisfies two more. These constraints are detailed in [ GOL88 ]:
-
Unforgeable (mandatory ). No one other than the signer can produce the signature without the signer’s private key.
-
Authentic (mandatory ). The receiver can determine that the signature really came from the signer.
-
Not alterable (desirable ). No signer, receiver, or any interceptor can modify the signature without the tampering being evident.
-
Not reusable (desirable ). Any attempt to reuse a previous signature will be detected by receiver.
To support digital signatures, we need strong public key algorithms. The RSA algorithm described earlier in this chapter is fine for digital signatures, but it is not the only possibility.
The U.S. Digital Signature Algorithm ( DSA ) [ NIS94 ], the basis of the U.S. Digital Signature Standard ( DSS ), is a variation on regular public key cryptography with a few restrictions. Initially the length of the key in DSS was required to be between 512 and 1024 bits, although now lengths of 2048 to 3072 are recommended, and even longer keys are possible. Second, two primes, p and q , are chosen such that p - 1 is a multiple of q . The values p , q , and n are used similarly to ordinary RSA encryption. The algorithm explicitly uses H(m) , a hash value, instead of the full message text m . The DSS uses encryption algorithm RSA, although a different standard, ECDSS, uses elliptic curve cryptography.
Having devised the digital signature algorithm DSA, the U.S. government defined a standard for use of that algorithm to make digital signatures. However, the government was a bit late to the game: Private industry had already converged around a digital signature approach based on RSA encryption, and a standards committee for the banking community had settled on a third method using ECC. Thus, FIPS Publication 186-3, Digital Signature Standard [ NIS09 ], covers and approves for government use all three methods. A new standard, version 186-5 [NIS23] was published February 2023.
12.6 Quantum Key Distribution
In this chapter we address several topics, including symmetric and asymmetric encryption, message digests and hash codes, and digital signatures. Central to all of these topics is the need for secure distribution of encryption keys between parties who may have had no previous relationship. We present the Diffie–Hellman key exchange protocol that is used in most SSL/HTTPS internet exchanges.
These topics are all based in mathematics: computing logarithms, factoring, using prime numbers. Indeed, demonstrably hard mathematical problems form a solid foundation on which much of modern cryptography is based.
Sometimes in science it is productive to explore work in other disciplines. In the final section of this chapter we explore how work in physics has led to a new and promising approach for key exchange. And as we present in Chapter 13 , the same work holds promise for improvements in computing in general.
Two concepts have similar-sounding names but different activity. In this section we describe quantum key distribution , using the principles of quantum physics to distribute cryptographic keys. The other field of quantum computing (introduced in Chapter 13 ) refers to a style of computing that has the potential to address problems too large or complex for current digital computers. The 2022 Nobel Prize in physics was awarded to three researchers for their pioneering experiments in quantum information science, a burgeoning field underpinning both quantum key distribution and quantum computing.
Key Distribution
We conclude this chapter with an emerging discipline based on advances in physics. Some analysts say this work has the potential to revolutionize distributing cryptographic keys.
We have seen how researchers rely on aspects of mathematics to generate hard problems and to devise algorithms. In this section we look at an alternative to this mathematical approach. The mechanics of physics, specifically how light is transmitted, give rise to a different means of transmitting keys.
The beauty of this approach is that it is extremely difficult, if even possible, to intercept without detection. Because it protects secrecy so well, you might think it would be important for communicating highly sensitive data, which is true, sort of. Throughout our study of cryptography, the key to secrecy is, well, the key. The encryption algorithms are public, as are their implementations and known limitations or vulnerabilities. Ciphertext is often available to anyone with the means to intercept it. And as we have said, there is nothing to stop the attacker from trying to reverse the encryption by any means available. Thus, the primary thing protecting sensitive data is the key. So when we speak of preserving secrecy of highly sensitive data, the most sensitive part is the encryption keys.
But as we have explained, the hard part is exchanging keys: establishing a channel through which two previously unknown parties can securely exchange a few bits. We discuss the Rivest–Shamir and the Diffie–Hellman key exchange protocols earlier in this chapter.
The approach we describe requires specialized and rather expensive equipment, so it is not appropriate for all situations. But it illustrates the need for creative thinking in inventing new encryption techniques. Although the science behind this approach is difficult, the approach itself is really quite simple.
The novel technique, using quantum physics, is in a way a variant of the idea behind a one-time pad. Remember from earlier in this chapter that the one-time pad is the only provably unbreakable encryption scheme. The one-time pad requires two copies of a long string of unpredictable numbers, one copy each for the sender and receiver. The sender combines a number with a unit of plaintext to produce the ciphertext. If the numbers are truly unpredictable (that is, they have absolutely no discernible pattern), the attacker cannot separate the numbers from the ciphertext. Using quantum physics to share numbers securely was first explored by Wiesner [ WIE83 ] in the 1980s; then the idea was refined by Bennett a decade later [ BEN92a , BEN92b ].
Quantum Physics
We start with the behavior of light particles, known as photons . They travel through space, vibrating in all directions; we say they have the directional orientation of their primary vibration.
Photon Orientation
Although photons can have any directional orientation from 0° to 360°, we can represent them with only four directional orientations (by rounding each actual orientation to the nearest 90°). We denote these four orientations with four symbols, ↔, ↕, ⤢, and ⤡. It is possible to distinguish between a ↔ and ↕ photon with high certainty because these photons’ orientations differ by approximately 90°. However, the ⤢ and ⤡ photons are sometimes interpreted as ↔ or ↕ because the differences in orientation are closer to 45°. Similarly, it is possible to distinguish between ⤢ and ⤡, but sometimes ↔ and ↕ will be recognized as ⤢ or ⤡. Fortunately, those uncertainties actually provide some of the confusion of the cryptographic algorithm.
The most important property of this approach is that no one can eavesdrop on a communication without affecting the communication. With a little simple error detection coding, the sender and receiver can easily detect the presence of an eavesdropper. Heisenberg’s uncertainty principle says that we cannot know both the speed and location of a particle at any given time; once we measure the speed, the location has already changed, and once we measure the location, the speed has already changed. Because of this principle, when we measure any property of a particle, it affects other properties. So, for example, measuring the orientation of a photon affects the photon. As we are about to describe, a horizontal slit filter blocks all ↕ and half of the ⤢ and ⤡ photons, so it affects the photon stream coming through. The sender knows what was sent, the receiver knows what was received, but an eavesdropper will alter the photon stream so dramatically that sender and receiver can easily determine someone is listening.
Filtering Photons
A polarizing filter is a device or procedure that accepts any photons as input but produces only certain kinds of photons as output. For this application there are two types of photon filters: + and × . A + filter correctly distinguishes ↔ from ↕ photons, but it incorrectly classifies ⤢ or ⤡; conversely, a × filter differentiates ⤢ and ⤡ but mischaracterizes ↔ and ↕ photons. Think of a + filter as a pair of horizontal and vertical slits through which a ↔ or ↕ photon can slide easily, but a ⤢ or ⤡ will twist through, perhaps not being recognized correctly.
Our sender Sam wants to derive a cryptographic key securely that he shares with his receiver, Ruth. He does not care what bit values he shares with Ruth as long as there are enough of them (the key length) and only he and Ruth can access them. Sam starts with a stream of photons for which he randomly chooses filters, as shown in Figure 12-10 .
FIGURE 12-10 Results Interpreted Through Filters
Filters Sam applied: plus sign, cross sign, cross sign, plus sign, cross sign, plus sign, plus sign, cross sign, plus sign, cross sign, and cross sign. Sam transmitted: horizontal double-head arrow, right tilted double-head arrow, right tilted double-head arrow, vertical double-head arrow, left tilted double-head arrow, horizontal double-head arrow, vertical double-head arrow, right tilted double-head arrow, vertical double-head arrow, right tilted double-head arrow, and left tilted double-head arrow. Data: 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1.
Sam randomly selects a filter for each bit he will transmit. If the photon has either a ↕ orientation with a + filter or a ⤡ orientation with a × filter, we say he transmits a 1; the case for a 0 is just the opposite. Figure 12-10 shows the photons and binary values Sam transmits, as produced by the filters he has chosen randomly.
Now, Ruth uses either a + or × filter at random for each photon, recording the result. Remember that a + filter will accurately distinguish between a ↔ and ↕ photon but will also declare a ⤢ or ⤡ as a ↔ or ↕ indiscriminately. So Ruth does not know whether the results she measures are what Sam sent. Ruth’s choice of filters, and the results she obtained, are shown in Figure 12-11 . (As a reminder, we repeat what Sam transmitted at the top of this figure, although Ruth does not know those values.) Notice that depending on the filters Ruth chose, some of her results are correct and some are incorrect. That does not matter at this time.
FIGURE 12-11 Results from Ruth’s Chosen Filters
Sam's data (reminder): 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, and 1. Filters Ruth applied: plus sign, cross sign, plus sign, plus sign, cross sign, cross sign, plus sign, plus sign, plus sign, cross sign, and plus sign. Results Ruth: 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, and 0. Actually received: horizontal double-head arrow, right tilted double-head arrow, vertical double-head arrow, vertical double-head arrow, left tilted double-head arrow, left tilted double-head arrow, vertical double-head arrow, horizontal double-head arrow, vertical double-head arrow, right tilted double-head arrow, and horizontal double-head arrow.
Now Ruth tells Sam which kind of filter she used for each bit, as shown in Figure 12-12 . We show the filters Ruth chose, as well as the ones Sam applied originally (which are just for your use; Ruth does not know what Sam used). As you can see, some of Ruth’s choices were not the same as Sam’s. Again, that does not matter at this time.
FIGURE 12-12 Filters Used
Filters Ruth applied: plus sign, cross sign, plus sign, plus sign, cross sign, cross sign, plus sign, plus sign, plus sign, cross sign, and plus sign. Filters Sam applied: plus sign, cross sign, cross sign, plus sign, cross sign, plus sign, plus sign, cross sign, plus sign, cross sign, and cross sign.
Sam then tells Ruth which of the filters she used were the correct ones. He only needs to tell her which filters were correct, not the corresponding value. We highlight Ruth’s correct guesses with boxes in Figure 12-13 .
FIGURE 12-13 Correct Filters
Filters Ruth applied: plus sign, cross sign, plus sign, plus sign, cross sign, cross sign, plus sign, plus sign, plus sign, cross sign, and plus sign. Filters Sam applied: plus sign, cross sign, cross sign, plus sign, cross sign, plus sign, plus sign, cross sign, plus sign, cross sign, and cross sign. Ruth's correct guesses: Two squares, two squares, single square, and two squares.
From Sam’s indication of her correct guesses for filters, Ruth can determine which of the results she obtained were correct, as shown in Figure 12-14 . (The results not in boxes are of no interest to Ruth because they may or may not be correct.) In this example, Ruth happened to choose the right filter 7 times out of 11, slightly higher than expected, and so 7 of the 11 photons transmitted were received correctly. Remembering that ↔ or ⤢means 0 and ↕ or ⤡ means 1, Ruth can convert the photons to bits, as shown in the figure.
FIGURE 12-14 Correct Results
Data (reminder): 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, and 1. Filters Sam applied: plus sign, cross sign, cross sign, plus sign, cross sign, plus sign, plus sign, cross sign, plus sign, cross sign, and cross sign. Filters Ruth applied: plus sign, cross sign, plus sign, plus sign, cross sign, cross sign, plus sign, plus sign, plus sign, cross sign, and plus sign. Ruth's correct guesses: inside boxes 0, 0; no box 1; inside boxes 1, 1; no box 1; inside box 1; no box 0; inside boxes 1, 0; and no box 0.
Thus, Ruth and Sam both know which result bits were correct, so in this example they now share 7 bits nobody else can know. They can continue this process as long as needed to accumulate enough shared bit values.
Analysis
This scheme has several subtleties.
-
Sam and Ruth want to derive a shared cryptographic key, and we have placed no restriction on the nature of the key: Any stream of bits is just as acceptable as any other. When Ruth happens to guess correctly, a bit is communicated; when she guesses incorrectly, she and Sam simply go to the next bit. Ruth might need to make a lot of guesses if she and Sam need to communicate a long key, but there is no penalty for an incorrect guess.
-
An intruder cannot tap this photon communication line without detection. That is, measuring the angle of the photon distorts it in a way the sender and receiver can detect. This quality makes eavesdropping futile.
-
There is no need to hide which filters Ruth used and which of her guesses were correct. Sam can openly communicate where she succeeded (1, 2, 4, 5, 7, 9, 10) publicly.
-
The scheme does not depend on Ruth’s guessing well. By chance we might expect Ruth’s correct guess rate to approach 0.5, but even a significantly lower rate is still adequate for key distribution.
-
The data stream can be enhanced with codes for detecting and correcting errors (introduced in Chapter 2 ). Thus, if needed, we can compensate for lost bits, duplications, or other kinds of imperfections in the communication stream.
-
An interceptor can see which filters Ruth used and which filter guesses were correct, but this does not compromise security. Without being able to assess the photons’ orientations, knowing only filter guesses tells the intruder nothing about what results passed through the filters.
Implementation
The theory of quantum key distribution is solid, but some technical difficulties still must be worked out before the scheme can be put into practice. To implement this approach, we need a source of photons randomly but detectably oriented (for the sender) and a means of filtering the sent and received photons reliably. A photon gun can fire photons on demand. Several different research teams are working to develop photon guns for cryptography. The best current technology involves pulsed lasers, but there is a problem. Occasionally the laser emits not one but two photons, which disturbs the pattern of reception and transmission. However, with error correcting codes on the stream of bits, it is relatively easy to detect and correct a few erroneous bits.
Starting in 2008, experimental distribution projects have operated over distances of up to 400 km and at speeds of 12.7 kb/sec. These works have taken place in China, England, India, Switzerland, the United States, and a collaboration in Europe. Most work is done using optical fiber, which is especially well suited for photon transmission, but in January 2022 the Indian Space Research Organisation was able to create a channel through the air; it plans to develop a communications capability using ground stations that communicate via satellites.
Commercial ventures in Australia, France, India, Russia, Switzerland, and the United States offer quantum key distribution systems, with other companies engaged in active research programs.
These results show significant progress as quantum key distribution moves from the research bench to the prototype lab. Although it has not yet achieved widespread public adoption, quantum key distribution is currently usable for high-secrecy needs and could see widespread commercial use within the next decade.
12.7 Conclusion
As we said at the beginning of this chapter, cryptography is a highly specialized area of study. Even in this chapter of details, we have presented only the top layer of this rich field. If you struggled with exponentiation in a field, modular arithmetic, and finding large primes, you may not agree this is just the surface. Trust us: Cryptography goes much deeper.
Unlike the other chapters of this book, this chapter includes no exercises. Problems in code breaking rapidly become difficult. Exercises involving hand calculation of any of the ciphers in this chapter are exhausting and tedious; the educational value of those problems is debatable. And questions asking you to find a flaw in one algorithm or invent a new algorithm to do something are the subjects of graduate papers, not exercises in a course. We know our readers can answer questions of rote memorization, and anything other than that is too much work.
Readers who want to learn more about cryptography should study the more advanced books on the topic, bearing in mind that many require a strong background in mathematics. And for the history of this very interesting field, we recommend David Kahn’s encyclopedic The Codebreakers [ KAH96 ].
In the next and final chapter of this book we raise several topics for which we have no answers. These are major areas that have important computer security issues. We encourage our readers to become involved in helping to see that the security aspects of these topics are addressed as the fields themselves mature.