Block cipher

From Citizendium
Revision as of 03:59, 27 October 2008 by imported>Sandy Harris (→‎The AES generation of ciphers)
Jump to navigation Jump to search
This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
Catalogs [?]
 
This editable Main Article is under development and subject to a disclaimer.
For more information, see: Cryptography.

Template:TOC-right

A block cipher is a symmetric cipher that operates on fixed-size blocks of plaintext, giving a block of ciphertext for each. The other main type of symmetric cipher is a stream cipher, which generates a stream of keying material to be mixed with messages. Block ciphers can be used in various modes when multiple blocks are to be encrypted.

There is an extensive literature both on the design of block ciphers and on methods of attacking them. For the design, see below and articles on specific ciphers. For the attacks, see cryptanalysis and articles on specific attacks. The standard references "Applied Cryptography" [1] and "Handbook of Applied Cryptography" [2], each have a large section on block ciphers. A useful web index of current work is the Block Cipher Lounge.

Among the best-known and most widely used block ciphers are two US government standards. The Data Encryption Standard (DES) from the 1970s is now considered obsolete; the Advanced Encryption Standard (AES) replaced it in 2002. Both of these ciphers are discussed below. Both also have their own articles; links are in the discussion below.

To choose the new standard, the National Institute of Standards and Technology ran an AES contest. Fifteen ciphers were entered, five finalists selected, and eventually AES chosen. Text below covers all five finalists — Rijndael which became AES, Twofish, Mars, RC6 and Serpent — and some other candidates.

In applications which encrypt a large volume of data, any cipher must be re-keyed from time to time. This prevents an enemy from accumulating large amounts of data encrypted with a single key; such a collection both facilitates some attacks and makes the payoff for breaking that key very large. Re-keying also limits the damage if a key is compromised in some other way. Block ciphers do not usually include a re-keying mechanism; some higher-level protocol manages that and re-keys the cipher using the normal keying mechanism.

Principles and techniques

Most of the principles discussed below for block ciphers also apply to other cryptographic primitives such as stream ciphers and cryptographic hash algorithms.

Adequate key size

Any cipher can be broken by a brute force attack if its key size is inadequate. Current block ciphers all use at least 128-bit keys to protect against this; many support larger keys as well. For a block cipher, the cost of brute force increases as 2keysize-1. For discussion, see the symmetric ciphers section of the "brute force attacks" article.

Key size is critical in stream ciphers as well as block ciphers, for the same reasons.

In many applications of cryptographic hash algorithms, no key is used. However in applications where a key is used, such as HMAC, key size is naturally an issue.

Iterated block ciphers

Nearly all block ciphers have multiple rounds, each applying the same transformation to the output of the previous round. At setup time the primary key undergoes key scheduling giving a number of round keys. In the actual encryption or decryption, each round uses its own round key. This allows the designer to define some relatively simple transformation and apply it repeatedly to create a cipher with enough overall complexity to thwart attacks. A cipher designed this way is called an iterated block cipher.

Two common ways to design iterated block ciphers — substitution-permutation networks and Feistel structures — and two important ways to look at the complexity requirements — avalanche and non-linearity — are covered in following sections.

There is a trade-off that can be made in the design. With a simple fast round function, many rounds may be required to achieve adequate security; for example, GOST and TEA both use 32 rounds. A more complex round function might allow fewer rounds; for example, IDEA uses only 8 rounds. Since the ciphers with fast round functions generally need more rounds and the ones with few rounds generally need slower round functions, neither strategy is clearly better. Secure and reasonably efficient ciphers can be designed either way, and compromises are common.

In choosing the number of rounds, a safety margin is often applied. If the cipher appears to be secure after a certain number of rounds, the designer generally specifies a larger number for actual use.

Variations

Some ciphers have an additional step called whitening; additional material derived from the key is mixed into the plaintext before the first round, or into the ciphertext after the last, or both. DES-X is an example.

In cryptanalysis it is common to attack reduced round versions of a cipher. For example, in attacking a 16-round cipher, the analyst might start by trying to break a two-round or four-round version. Such attacks are easier and success there may lead to insights that are useful in work against the full cipher, or even to an attack that can be extended to break the full cipher.

When a block cipher is constructed from another cryptographic primitive, there may be no need to iterate because the other primitive provides adequate security. For example, RSA can be used as a block cipher with block size equal to the RSA modulus, and other public key techniques can be used in the same way. In effect, this is one extreme of the trade-off between round function complexity and number of rounds described above. If the round function is itself cryptographically secure, then only one round is needed.

Iteration is used in cryptographic hash functions in much the same way it used in block ciphers.

Avalanche

The designer wants changes to propagate through the cipher so that, for example, a single-bit change at round n affects all bits of the ciphertext by round n+x for some reasonably small x. Ideally, x would be 1; certainly it must be much less than the total number of rounds. If the round function design gives a large x then the cipher will need more rounds to be secure.

This was named the avalanche effect in a paper [3] by Horst Feistel. The idea is that changes should build up like an avalanche, so that a tiny initial change quickly creates large effects. The term and its exact application were new, but the basic concept was not; avalanche is a variant of Claude Shannon's diffusion and that in turn is a formalisation of ideas that were already in use.

The strict avalanche criterion [4] is a strong version of the requirement for good avalanche properties. Complementing any single bit of input should give a 50% chance of a change in any given bit of output.

Cryptographic hash functions also require a form of avalanche, to ensure adequate mixing of the inputs.

Cipher structures

Two structures are very commonly used in building block ciphers — SP networks and the Feistel structure. Not all block ciphers use one of these, but most do. We describe both in this section.

Either structure is a known quantity for a cipher designer, part of the toolkit. He or she gets big chunks of a design — an overall cipher structure with a well-defined hole for the round function to fit into — from the structure, This leaves him or her free to concentrate on the hard part, designing the actual round function.

Neither structure gives good avalanche in a single round but, with a good round function, both can give excellent avalanche after a few rounds.

SP networks

A substitution-permutation network or SP network or SPN is one way to build the round function in an iterated block cipher.

The idea originated with Claude Shannon [5]. In his terms, a cipher needs both confusion and diffusion. In an SP network, there are two layers in each round: a substitution layer provides confusion, then a permutation layer provides diffusion.

The S-layer typically uses look-up tables called S-boxes or substitution boxes, though other mechanisms are also possible. The input is XOR-ed with a round key, split into parts and each part used as an index into an S-box. The S-box output then replaces that part so the combined S-box outputs become the S-layer output. S-boxes are discussed in more detail in their own section below.

The P-layer permutes the resulting bits, adding confusion or in Feistel's terms helping to ensure avalanche.

A single round of an SP network does not usually provide good avalanche properties; output bits are affected only by inputs to their S-box. not by all input bits. However, the P-layer ensures that the output of one S-box in one round will affect several in the next round so, after a few rounds, overall avalanche properties can be very good.

Feistel structure

Another way to build the round function for an iterated block cipher is to use the Feistel structure, devised by Horst Feistel of IBM and used in DES. Such ciphers are known as Feistel ciphers.

Each round uses a function F whose input and output are each half a block. Splitting the block into right and left halves and showing XOR as ^ and round key for round n as kn, even numbered rounds are then:

leftn = leftn-1 ^ F(rightn-1, kn)
rightn = rightn-1

and odd-numbered rounds are

rightn = rightn-1 ^ F(leftn-1, kn)
leftn = leftn-1

A single round in a Feistel cipher has less than ideal avalanche properties. In our first example above, half the output bits (on the right) are unchanged and the leftn-1 input bits each affect only one output; this falls well short of the ideal in which every input bit affects every output bit. However, the other half is changed in the next round and the F function can be designed so that small changes in its inputs (half-block or round key) produce large output changes. Within a few rounds, a Feistel cipher can have excellent overall avalanche properties.

Since XOR is its own inverse and the half-block that is used in the F function is unchanged in each round, reversing a Feistel round is straightforward. For example, the decryption step matching the first example above is:

leftn-1 = leftn ^ F(rightn, kn)
rightn-1 = rightn

In some ciphers, including those based on SP networks, all operations must be reversible so that decryption can work. The main advantage of a Feistel cipher over an SP network is that the F function itself need not be reversible, only repeatable. This gives the designer extra flexibility; almost any operation he can think up can be used in the F function. On the other hand, in the Feistel construction, only half the output changes in each round while an SP network can change all of it in a single round.

The hard part of Feistel cipher design is of course the F function. Design goals include efficiency, easy implementation, and good avalanche properties. Also, it is critically important that the F-function be highly non-linear. All other operations in a Feistel cipher are linear and a cipher without enough non-linearity is weak; see the next section.

Non-linearity

To be secure, every cipher must contain non-linear operations. If all operations in a cipher were linear — in any algebraic system, with the attacker making the choice of system and allowed to try as many as he likes — then the cipher could be reduced to a system of linear equations. Any system of simultaneous linear equations, in any algebra, can be solved straightforwardly if the number of equations matches or exceeds the number of variables.

Attacks on linear ciphers

To break a cipher that uses only linear operations, an attacker can just plug in known plaintext/ciphertext pairs until there are at least as many equations as variables, then solve for the key.

For example, for a cipher with 64-bit blocks and a 128-bit key, the attacker could write 64 equations each expressing one output bit in terms of 64 inputs and 128 key bits. Plug in a known plaintext/ciphertext pair and only the key bits remain as variables. He has 64 equations in 128 variables, not a soluble system. However, if he has a second known pair, that gives him a different set of 64 equations with the same 128 key bits as variables. The total system is now 128 equations in 128 variables. If the equations are all linear, this is soluble by standard techniques. However, he also has the option of plugging in a third known pair to get a system with 192 equations in 128 variables if that is easier to solve, or going even further if that helps.

If the key schedule causes difficulties for him, he has the option of bypassing it. Instead of solving for the 128-bit master key, he can try to solve for all the round keys, 512 to 1024 bits in typical block ciphers. This requires more known plaintext/ciphertext pairs and the number of equations becomes distinctly unwieldy, but if all the equations are linear then the system is still, at least in theory, straightforwardly soluble. Finding the round keys breaks the cipher just as finding the master key would; an attacker can try either or both.

The attacker can also try linear cryptanalysis. If he can find a good enough linear approximation for the round function and has enough known plaintext/ciphertext pairs, then this will break the cipher. Defining "enough" in the two places where it occurs in the previous sentence is rather complex; see linear cryptanalysis. Simplifying outrageously, a good rule for the cipher designer is the more non-linearity the better; have at least some components that are not even close to linear.

What makes these attacks impractical is a combination of the sheer size of the system of equations used and non-linearity in the relations involved. In any algebra, solving a system of linear equations is more-or-less straightforward provided there are more equations than variables. However, solving non-linear systems of equations is far harder so the cipher designer strives to introduce non-linearity to the system. Combined with good avalanche properties and enough rounds, this makes both direct algebraic analysis and linear cryptanalysis prohibitively difficult.

Adding non-linearity

There are several ways to add non-linearity; some ciphers rely on only one while others use several.

One method is mixing operations from different algebras. If the cipher relies only on Boolean operations, the cryptanalyst can try to attack using Boolean algebra; if it uses only arithmetic operations, he can try normal algebra. If it uses both, he has a problem. Of course arithmetic operations can be expressed in Boolean algebra or vice versa, but the expressions are inconveniently (for the cryptanalyst!) complex and non-linear whichever way he tries it.

For example, in the CAST-128 or Blowfish F function, it is necessary to combine four 32-bit words into one. This is not done with a straightforward x = a+b+c+d or x=a^b^c^d but instead with something like x = (a+b)^(c-d). On most computers this costs no more, but it makes the analyst's job harder.

Other operations can also be used, albeit at higher costs. IDEA uses multiplication modulo 216+1 and AES does matrix multiplications in a field.

Rotations, also called circular shifts, on words or registers are non-linear in normal algebra, though they are easily described in Boolean algebra. Some ciphers such as GOST use rotations by a constant amount. CAST-128 uses a key-dependent rotation in the F function. In RC-5 and RC-6 data-dependent rotations are heavily used.

A general operation for introducing non-linearity is the substitution box or S-box; see following section.

Non-linearity is also an important consideration in the design of stream ciphers and cryptographic hash algorithms. For hashes, much of the mathematics and many of the techniques used are similar to those for block ciphers. For stream ciphers, rather different mathematics and methods apply (see Berlekamp-Massey algorithm for example), but the basic principle is the same.

S-boxes

S-boxes or substitution boxes are look-up tables. The basic operation involved is a = sbox[b] which, at least for reasonable sizes of a and b, is easily done on any computer.

S-boxes are often used in the S-layer of an SP Network. In this application, the S-box must have an inverse to be used in decryption. It must therefore have the same number of bits for input and output; only n*n S-boxes can be used. Another common application is in the F function of a Feistel cipher. Since the F function need not be reversible, there is no need to construct an inverse s-box for decryption and S-boxes of any size may be used. With either an SP network or a Feistel construction, non-linear S-boxes and enough rounds give a highly non-linear cipher.

There is an extensive literature on the design of good S-boxes, much of it emphasizing achieving high non-linearity though other criteria are also used. See this online literature survey and references below.

S-boxes are described as m*n or m by n, with m representing the number of input bits and n the number of output bits. For example, DES uses 6 by 4 S-boxes. The storage requirement for an m*n S-box is 2m*n bits, so large values of m (many input bits) are problematic. Values up to eight are common; going much beyond that would be expensive. Large values of n (many output bits) are not a problem; 32 is common and at least one system, the Tiger hash [1], uses 64.

In early Feistel ciphers, DES and GOST, the F function is essentially one round of an SP Network. These ciphers use eight 6*4 or 4*4 S-boxes to get 32 bits of S-box output. Those bits, reordered by a simple transformation, become the 32-bit output of the F function. Avalanche properties are less than ideal since each output bit depends only on the inputs to one S-box. The output transformation compensates for this, ensuring that the output from one S-box in one round affects several in the next round, so that good avalanche is achieved after a few rounds.

Later Feistel ciphers use bigger S-boxes and do not use S-box bits directly as F function output. For example, Blowfish and CAST-128 use four 8*32 S-boxes. The 32-bit input is XORed with the round key then split into four bytes and each byte is passed through a different S-box, giving four 32-bit results. Those results are then combined (non-linearly) to get the 32-bit F function output. Such an F function has ideal avalanche properties — all output bits depend on all input bits and all key bits. No output transformation is required. Of course, one may be used anyway; CAST-128 has a key-dependent rotation.

S-boxes as a model of other things

S-boxes may be used in analysis even when they are not actually used in the cipher. Any operation whose output is fully determined by its inputs can be described by an S-box; concatenate all inputs into an index, look that index up, get the output.

For example, the multiplication in IDEA has two inputs and one output, all 16-bit, so it can be modeled as a 32*16 S-box. In an academic paper, one might look at this as an S-box in order to apply standard tools for measuring non-linearity, or to compare it with other ciphers that do use S-boxes. A well-funded cryptanalyst might actually build the S-box (8 gigabytes of memory) either as a step in analysis or to speed up an attack.

In theory, larger components, or even the whole cipher, can be modeled in the same way. For the F function in a Feistel cipher, the inputs are only half a block and a round key; this gives an 80*32 or 64*32 S-box, much too big for an attacker to actually build but perhaps usable in theoretical work. Try to model anything bigger — a whole cipher, a round of a non-Feistel cipher, or multiple rounds of a Feistel cipher — and S-box dimensions become astronomical. Consider AES with 128-bit blocks and (the minimum) 128-bit key size; this can be modeled as a 256*128 S-box, an array with 2256 entries, but the model is unlikely to be useful.

DES and alternatives

The Data Encryption Standard, DES, started an era when it was made a US government standard in the late 70s. It was extremely widely used and very extensively analysed. For an entire generation of cryptographers, the main objectives of work on block ciphers were either to find a way to break DES or to devise a cipher that was demonstrably better than DES.

This section covers DES and the generation of block ciphers which followed DES in the 80s and 90s — such as GOST, Blowfish, CAST-128 and IDEA. All of those used 64-bit blocks, like DES, but all used 128-bit or longer keys for better resistance to brute force. Many of the techniques used came from DES and many of the design principles came from analysis of DES.

The era effectively ended when the US government began working on a cipher to replace DES, the Advanced Encryption Standard or AES. A whole new generation of ciphers arose, of course still drawing on DES experience but quite different in design; in particular, they all use 128-bit blocks. We cover those in a later section.

DES

The Data Encryption Standard, DES, is among the the best known and most thoroughly analysed block ciphers. It was invented by IBM, and was made a US government standard for non-classified government data and for regulated industries such as banking, in the late 70s. From then until about the turn of the century, it was very widely used. DES operates on 64-bit blocks and takes a 56-bit key.

DES is now considered obsolete; its small key size makes it vulnerable to a brute force attack, given modern computers. In 2002, DES was replaced as a US government standard by the Advanced Encryption Standard which uses 128-bit blocks and takes 128, 192 or 256-bit keys.

Some applications still use Triple DES, a variant which applies DES three times with two or three different keys; see next section.

Every new cryptanalytic technique invented since DES became a standard has been tested against DES. None of them have broken it completely, but two — differential cryptanalysis and linear cryptanalysis — give attacks theoretically significantly better than brute force. This does not appear to have much practical importance since both require enormous numbers of known plaintexts and since DES has been repeatedly broken by brute force anyway. All the older publicly known cryptanalytic techniques have also been tried, or at least considered, for use against DES; none of them work.

DES internals

DES operates on 64-bit blocks and takes a 56-bit key. It is a Feistel cipher with 16 rounds and a 48-bit round key for each round, To generate the round keys, the 56-bit key is split into two 28-bit halves and those halves are circularly shifted after each round by one or two bits. Then 48 bits from them are selected and permuted to form the round key.

DES uses eight S-boxes, each 6 bits in and 4 out. The F function works as follows:

expand the 32-bit input to 48 bits, simply by copying some bits twice
XOR with the 48-bit round key
split the result into 8 6-bit chunks
pass each chunk through a different S-box, giving 32 output bits
permute the output bits

The permutation ensures rapid avalanche; a one-bit change in key affects one S-box; a one-bit change in the input block affects one or two S-boxes. With the permutation, changing the output of one S-box affects several in the next round. After a few rounds, the effect spreads to the entire output.

DES is not secure

DES can no longer be considered secure because its 56-bit key is simply too short. It is vulnerable to a brute force search of the whole key space, either by large collections of general-purpose machines or even more quickly by specialized hardware. Of course this also applies to any other cipher with only a 56-bit key.

In 1998, the Electronic Frontier Foundation built a DES-cracking machine; it can find a DES key in an average of a few days' search. The details were published in "Cracking DES" [6]. That machine cost just over $200,000 in 1998. By Moore's Law the cost in 2007, 9 years later, should be down to $200,000/29/1.5 = $3125, and a quarter of that by 2010. Of course we cannot actually say with any precision what such a cracker would cost today. However, we can say with certainty that DES should no longer be used to protect valuable data.

Before the definitive EFF effort, DES had been cracked several times by people using many machines. See this press release for example. Almost any large organisation — business, government, criminal or whatever — could break DES that way.

Variations on DES

DES is vulnerable to brute force attack because of its small key. However, it has withstood decades of intensive analysis with no catastrophic flaws found, so it appears to be basically a remarkably solid design. Various people have therefore sought ways to achieve larger key size while retaining the basic DES algorithm.

Ron Rivest proposed DES-X or DESX [2], essentially DES with whitening. 64 bits of key material are XORed into the plaintext before encryption, and 64 more into the ciphertext afterward. With the 56 bits of DES key, the gives 184 total keys bits so the cipher is safe from brute force attacks. Encryption overheads are only a tiny bit more than DES; the cost of the XORs. Analysis [7] of resistance to linear cryptanalysis and differential cryptanalysis shows that it is better than DES against these attacks, but not hugely so.

Another approach is to use independent round keys. DES has 16 48-bit round keys, a total of 768 bits of keying material, but in normal DES they are all derived from the 56-bit main key. Use 768 independent key bits and the cipher is obviously resistant to brute force, one proposal was G-DES or Generalised DES [8]. However, Schneier at al. [3] demonstrate that the technique has weaknesses.

Triple DES

Another way to derive a stronger cipher from DES is to apply DES multiple times with different keys.

Just applying DES twice, double DES, is ineffective. Using two 56-bit keys, one might expect an attacker to have to do 2112 work to break it. In fact, only 257 work is required with a meet-in-the-middle attack, though a large amount of memory is also required. That is, double DES is only four times stronger than DES, which can be broken by brute force with 255 encryptions.

Triple DES, sometimes written 3DES, is effective. Apply DES three times with two or three different keys. This is also vulnerable to a meet-in-the-middle attack, but the work factor for that attack is 2112. That provides adequate protection for many applications, and no better attack is known.

Triple DES can be somewhat slow compared to other ciphers. It requires three DES encryptions per block. DES was designed for hardware implementation and includes some operations which are difficult in software. For new applications, a newer cipher such as AES will generally be both faster and more secure; Triple DES provides only 2112 strength against the best known attack, meet-in-the-middle. AES is resistant to that attack and gives 2128 or more against the best known attack on it, brute force.

Triple DES is, however, still widely deployed in legacy applications. Consider a bank with several thousand ATM machines, with built-in hardware or well-tested software for triple DES. Changing those will certainly be expensive and will entail some risk of bugs in the new system; it may not be worth it.

Triple DES can be done with three keys, two keys or just one key, though the one-key variant should never be used. In all cases, the order of operations is EDE or encrypt-decrypt-encrypt.

The three-key variant is widely used; for example RFC 2451 specifies it for use in IPsec.

In the two-key variant the first and third keys are the same. This gives a saving in key storage and key transmission overheads; only 112 bits are required rather than 168. This is not significant in most applications. 3DES with three keys has only 2112 strength against a meet-in-the-middle attack, so it is possible that the two key version, with 2112 against either brute force or meet-in-the-middle, is just as strong.

The one-key variant is a "worst of both worlds" solution, the overheads of triple DES (three times those of DES) with the security of DES (inadequate against brute force attacks). The only possible reason for doing this would be if one of the communicating systems only supported DES while the other had only triple DES. By using single-key triple DES on one end, you could get the two to encrypt their communications, albeit not securely.

GOST

The GOST cipher, and the related GOST hash algorithm, were standards in the Soviet Union.

The GOST cipher [1] resembles DES in many ways; it is an iterated block cipher with a Feistel structure using eight s-boxes in the F function; each s-box produces four bits of output and these are combined to produce the 32-bit output. However, it differs from DES in other ways. There is no expansion from 32 bits to 48, so s-box inputs are only four bits rather than six, and there is no permutation of the output bits, only an 11-bit circular shift; these differences make GOST easier to implement in software than DES. However, they may also weaken the cipher; GOST compensates by increasing the number of rounds to 32 rather than DES's 16.

GOST also uses a 256-bit key which makes it, unlike DES, thoroughly resistant to brute force attacks.

CAST

The original work on CAST was in Carlisle Adams' PhD thesis [9]. A well-known paper is "Constructing Symmetric Ciphers using the CAST Design Procedure". [10]. There is also a US patent on some of the techniques.

"CAST" is a general procedure for constructing a family of ciphers; individual ciphers have names like "CAST-128".

CAST S-boxes

CAST ciphers are Feistel ciphers using large S-boxes, 8*32 rather than the 6*4 of DES. They are primarily designed for software implementation, rather than the 1970s hardware DES was designed for, so looking up a full computer word at a time makes sense. An 8*32 S-box takes one K byte of storage; several can be used on a modern machine without difficulty. Multiple S-box outputs are combined in such a way that every S-box affects all output bits.

The S-boxes use bent functions (the most highly non-linear Boolean functions) as their columns. That is, the mapping from all the input bits to any single output bit is a bent function. Such S-boxes meet the Strict Avalanche Criterion [4]; not only does every every bit of round input and every bit of round key affect every bit of round output, but complementing any input bit has exactly a 50% chance of changing any given output bit. The F function as a whole has ideal avalanche properties.

A paper on generating the S-boxes is Mister & Adams "Practical S-box Design" [11]. Bent functions are combined to get additional desirable traits — a balanced S-box (equal probability of 0 and 1 output), miniumum correlation among output bits, and high overall S-box non-linearity.

Resisting linear & differential attacks

One objective of the CAST design procedure is to produce ciphers provably immune to both linear cryptanalysis and differential cryptanalysis [12]. These are the only known attacks that break DES with less effort than brute force. More generally, they are the most powerful known attacks against block ciphers. Both, however, require large numbers of known or chosen plaintexts, so the usual defense against them is to re-key often enough that the enemy cannot collect sufficient texts. CAST attempts to go further, building a cipher that is not vulnerable to them with any number of texts.

A cipher that has adequate key size to prevent brute force and is immune to those two attacks is resistant to all of the best known cryptanalytic methods.

The method, taking linear cryptanalysis as our example and abbreviating it LC, is as follows:

start from properties of the F function, particularly the bent functions in the S-boxes
derive a limit m, the maximum possible quality of any linear approximation to a single round
consider r, the number of rounds, as a variable
derive an expression for e, the effort required to break the cipher by LC, in terms of r and m
find the minimum r such that e exceeds the effort required for brute force, making LC impractical
derive an expression for c, the number of chosen plaintexts required for LC, also in terms of r and m
find the minimum r such that c exceeds the number of possible plaintexts, 2blocksize, making LC impossible

A similar approach applied to differentials gives values for r that make differential cryptanalysis impractical or impossible. Choose the actual number of rounds so that, at a minimum, both attacks are impractical. Ideally, make both impossible, then add a safety factor.

The original CAST cipher

The first CAST cipher [1] (in the thesis) was a Feistel cipher with 64-bit blocks, a 64-bit key, 8 rounds with 16-bit round keys, and six 8*32 S-boxes. For the F function, split the 32-bit input into 4 bytes and the round key into 2 bytes. Run each of the 6 bytes through a different S-box to get 6 32-bit outputs. Combine those using XOR.

This was not much used; when people mention "CAST", they almost always mean the widely deployed CAST-128 which we cover next.

CAST-128

CAST-128, also called CAST5, is the best-known and most widely used CAST cipher. It replaced IDEA in PGP in version 3.0 and is specified in all versions of the OpenPGP standard, including the current RFC 4880, Nortel and their spin-off Entrust also used it in several products; Adams worked for both companies.

CAST-128 is a Feistel cipher with 64-bit blocks and 16 rounds. Key sizes from 40 to 128 bits are supported; 128 is almost invariably used. There are eight 8*32 S-boxes, four used in the key schedule and the other four in actual encryption. Round keys are 37 bits.

The F function XORs the input with 32 bits of round key, splits the result into bytes and runs each byte through a different S-box to get four 32-bit results. Those are combined non-linearly with different functions in different rounds. Finally, the output is given a rotation controlled by the other 5 round key bits.

A CAST-128 specification is in RFC 2144. The cipher is freely available for any use.

A descendant named CAST-256 was an AES candidate.

Blowfish

Blowfish was designed by Bruce Schneier and the cipher has a home page.

It is a Feistel cipher with 64-bit blocks and 16 rounds. Supported key sizes are 32 to 448 bits; at least 128 is recommended. The F function XORs the input with the 32-bit round key, splits the result into bytes and runs each byte through a different S-box to get four 32-bit results. Those are combined non-linearly with x = ((a+b)^c)+d.

Blowfish S-boxes are key-dependent, randomly generated at cipher setup time. For some applications, this key setup is inconveniently expensive; Blowfish may not be the best choice if keys need to be changed often, However, the actual encryption and decryption are fast.

The cipher is freely available for any use.

IDEA

IDEA [13] is the International Data Encryption Algorithm, a European standard. It is a iterated block cipher, but does not have a Feistel structure. Block size is 64 bits, key 128. No S-boxes are used.

IDEA achieves non-linearity by mixing operations from three different algebraic systems. All operations have 16-bit words as both input and output. Two are just bitwise XOR and addition modulo 216. The third is basically multiplication, modulo 216+1, but with some additional code so the "x*0 yields zero for all x" case does not weaken the cipher.

IDEA multiplication

To see how the IDEA multiplication works, consider this multiplication table modulo 5:

   0  1  2  3  4
0  0  0  0  0  0
1  0  1  2  3  4
2  0  2  4  1  3
3  0  3  1  4  2
4  0  4  3  2  1

Note that, ignoring multiplications by zero, every column and every row is a permutation of the set (1,2,3,4). This is true for any prime modulus.

Our inputs are 2-bit numbers (0,1,2,3). We map them to (4,1,2,3) and then multiply them modulo 5; all multiplications use the non-zero part of the table. Results are in (1,2,3,4), which we map back to (1,2,3,0) so we get 2-bit output.

C code for IDEA multiplication of 2-bit numbers (range 0-3) would be:

#define NBITS 2
#define MAX (1<<NBITS)
#define MOD (MAX+1)
unsigned idea_multiply(unsigned x, unsigned y)
{
   unsigned z ;
   // make sure inputs are in range
   x %= MAX ;
   y %= MAX ;
   // adjust the range
   // avoid multiplying by zero
   if( x == 0 ) x = MAX ;
   if( y == 0 ) y = MAX ;
   // calculate the result
   // see table above
   z = (x*y) % MOD ;
   // adjust it
   // avoid returning MAX
   if( z == MAX ) z = 0 ;
   return( z ) ;
}

Change NBITS to 16 and you have real IDEA multiplication, operating on 16-bit quantities. This works correctly because MOD is then the prime 216+1. On a 32-bit processor, you need to add a bit of extra code to avoid having MAX*MAX overflow a 32-bit register, but that is the only special case.

Overheads

The IDEA multiplication operation is highly non-linear and has good avalanche properties; every output bit depends on all the inputs. It is not nearly as cheap as addition or XOR, but it is reasonably fast on a modern 32-bit or larger CPU. In most environments it will be more expensive than S-box lookups but in some, such as an embedded processor with limited cache, it may be cheaper.

In any case, IDEA uses only 8 rounds so it can afford a moderately expensive operation in the round function.

RC5

RC5, Rivest Cipher 5 was from Ron Rivest. It was the first well-known cipher to make extensive use of data-dependent rotations to achieve non-linearity. It is a Feistel cipher.

RFC 2040 gives an RC5 specification for Internet use.

Its descendant RC6, also using data-dependent rotations, was an AES finalist. RSA Laboratories have a page describing both ciphers.

TEA

The Tiny Encryption Algorithm, or TEA [14] is a cipher designed for small size and easy software implementation. It is a Feistel cipher with 64-bit blocks, a 128-bit key, 32 rounds and a very simple round function using only 32-bit addition, bitwise XOR and shifts.

It has a home page. The cipher is freely available for any use.

The AES generation of ciphers

Starting in the late 90s, the US National Institute of Standards and Technology (NIST) ran a contest to find a block cipher to replace DES. The requirements specified a block cipher with 128-bit block size and support for 128, 192 or 256-bit keys. Evaluation criteria included security, performance on a range of platforms from 8-bit CPUs (e.g. in smart cards) up, and ease of implementation in both software and hardware.

Fifteen submissions meeting basic criteria were received, not just from the US but from many other countries as well. After about a year of analysis and testing, and two conferences, the field was narrowed to five finalists — Twofish, MARS, Serpent, RC6, and Rjindael. All finalists and some other candidates are described below.

In October 2002, they announced [4] the winner — Rijndael. Rijndael then became the Advanced Encryption Standard or AES.

The contest was open and international and extensive work was done on testing and comparing the various candidates. To facilitate this, NIST defined some standard interfaces which everybody used. For almost all candidate ciphers, implementations with these interfaces are readily available [5], [6]. Many, though not all, of these ciphers have open licenses.

This means that anyone implementing AES has the option of adding other ciphers at minimum cost, in particular the other three finalists with open licenses — Twofish, MARS, and Serpent. This gives a cheap insurance policy against the (presumably remote) chance of someone finding a good attack on AES.

AES

The Advanced Encryption Standard or AES is the algorithm formerly known as Rijndael (pronounced approximately "rhine doll"). It was designed by two Belgians, Joan Daemen and Vincent Rijmen.

It is an iterated block cipher which does not use the Feistel structure. It encrypts 128-bit blocks with a 128, 192 or 256-bit key. Non-linearity is obtained by mixing operations from different algebraic groups.

The number of rounds varies with key size: 10 for 128-bit keys, 12 for 192-bit keys and 14 for 256-bit keys.

The NIST page on AES [7] has much detail. The cipher is freely available for any use.

Twofish

Twofish was an AES finalist cipher from Bruce Schneier's company Counterpane. The cipher has a home page which includes a link to the main design paper [15].

Like all AES candidates, it uses 128-bit blocks and supports key sizes of 128, 192 or 256 bits. The cipher is freely available for any use.

Serpent

Serpent was an AES finalist cipher from an international team — Ross Anderson (UK), Eli Biham (Israel), and Lars Knudsen (Norway). The cipher home page has extensive information.

Like all AES candidates, it uses 128-bit blocks and supports key sizes of 128, 192 or 256 bits.

Serpent is an SP network with 32 rounds. It uses eight 4 by 4 S-boxes, but unlike other ciphers it does not use them all in each round. Instead each rounds uses eight copies of the same S-box, but each of the eight S-boxes is used in four different rounds,

The cipher is freely available for any use.

RC6

RC6 was an AES finalist cipher designed by Ron Rivest. Like all AES candidates, it uses 128-bit blocks and supports key sizes of 128, 192 or 256 bits.

Like RC5, RC6 made extensive use of data-dependent rotations. RSA Laboratories have a page describing both ciphers.

RC6 is the only one of the five finalists which does not have a completely open license; it is still proprietary to RSA Laboratories.

MARS

MARS was an AES finalist cipher from IBM. Like all AES candidates, it uses 128-bit blocks and supports key sizes of 128, 192 or 256 bits. Like RC6, it uses data-dependent rotations.

The cipher has a home page and is now freely available.

CAST 256

CAST-256 was an AES candidate cipher; it did not make it into the finals. Like all AES candidates, it uses 128-bit blocks and supports key sizes of 128, 192 or 256 bits.

It is a Feistel-like cipher extended to four 32-bit sub-blocks instead of the two sub-blocks used in CAST-128 for 64-bit blocks. Each round takes one 32-bit sub-block as input and alters one 32-bit sub-block; 48 rounds are used. The F function and S-boxes are from CAST-128.

A CAST-256 specification is in RFC 2612. The cipher is freely available for any use.

Hasty Pudding

The Hasty Pudding cipher (HPC), from Rich Schroeppel was, in some ways, the most interesting of the AES candidates. It did not make it into the finals.

Hasty Pudding is a variable size block cipher; blocks can be any size the application requires. It therefore might be ideal for things like encrypting disk blocks. Also, quoting the home page "Arbitrary sets, such as dates, or the printable subset of ascii, or the 20-bit primes, can be encrypted to themselves." Key size is also variable; any integer number of bits.

The cipher has a home page and is freely available for any use.

Block cipher modes

Various modes of operation for block cipher usage were originally defined for DES in a US Federal Information Processing Standard (FIPS) [16]. The most recent NIST recommendations are in "Recommendation for Block Cipher Modes of Operation" [17]

These modes can be applied to any block cipher.

Electronic Code Book, ECB

In Electronic Code Book mode, the cipher is just applied to each block of plaintext independently.

The disadvantage is that the same plaintext block always encrypts to the same ciphertext; this gives an enemy some information. ECB is therefore generally not used.

Cipher Block Chaining, CBC

In cipher block chaining mode, the ciphertext output from the previous block is XORed into the plaintext before encryption. Encryption of block n is then:

 cn = encrypt( pn XOR cn-1)

For this to work for n=1, an initialisation vector (IV) must be provided to act as c0. This need not be secret, but it must be different for each message and should be random. If the same IV is repeatedly used, then if two or more messages start with the same text, they will encrypt identically for the first block or the first few blocks. This is an unnecessary weakness; using unique IVs is therefore standard practice.

CBC mode makes the encryption of any block depend on all blocks previously encrypted. A bit error in an encrypted block, such as might be caused by line noise, will cause the decryption of that block and the next to be garbled, but later blocks will not be affected. CBC is self-recovering against bit-flipping errors. However, loss of synchronisation is fatal; if even a single bit is dropped or added, then the affected block and all that follow it will be garbled. Authentication of the packet or message can prevent such problems if decryption is only applied to data that has passed authentication,

Cipher block chaining is much the most widely used mode. IPsec specifies it as the only permitted mode. PGP and TLS use it as well.

Cipher feedback, CFB

Output Feedback, OFB

Counter, CTR

In counter mode, a counter is encrypted to generate a series of pseudo-random output blocks. It can be used to create a pseudorandom number generator or a stream cipher; if the block cipher is secure and is keyed and re-keyed appropriately, these will be secure as well.,

Counter mode is used in the Yarrow [18] random number generator.

It is possible to re-key using some of the system output as the new key; Yarrow does this every 10 iterations, just to complicate any analysis. However, this is not enough for security if large amounts of output are required; the cipher must also be re-keyed (much less often) from an external source of genuine random numbers. The Yarrow paper demonstrates an attack after 2keysize/3 outputs, so any use of counter mode should be externally re-keyed well before that.

References

  1. 1.0 1.1 1.2 Schneier, Bruce (2nd edition, 1996,), Applied Cryptography, John Wiley & Sons, ISBN 0-471-11709-9
  2. Menezes, AJ; PC van Oorschot & SA Vanstone (Fifth Edition, 2001), Handbook of Applied Cryptography, ISBN 0-8493-8523-7
  3. Horst Feistel (1973). Cryptography and Computer Privacy.
  4. 4.0 4.1 A. F. Webster and Stafford E. Tavares (1985). "On the design of S-boxes".
  5. C. E. Shannon (1949). "Communication Theory of Secrecy Systems".
  6. Electronic Frontier Foundation (1998). Cracking DES: Secrets of Encryption Research, Wiretap Politics, and Chip Design. Electronic Frontier Foundation. ISBN ISBN: 1-56592-520-3. 
  7. Joe Kilian and Phillip Rogaway (1996). How to protect DES against exhaustive key search. Springer-Verlag.
  8. Andreas Pfitzmann and Ralf Amann. "More Efficient Software Implementations of Generalized DES".
  9. C. M. Adams (1990). "A Formal and Practical Design Procedure for Substitution-Permutation Network Cryptosystems". Department of Electrical Engineering, Queen's University.
  10. C. M. Adams (November 1997). Constructing Symmetric Ciphers using the CAST Design Procedure. Springer Netherlands.
  11. S. Mister, C. Adams (August, 1996). "Practical S-Box Design".
  12. H.M. Heys and S.E. Tavares (September 1994). "On the Security of the CAST Encryption Algorithm".
  13. X. Lai (1992). "On the Design and Security of Block Ciphers". Hartung-Gorre Verlag.
  14. David J. Wheeler, Roger M. Needham (1994). TEA, a Tiny Encryption Algorithm.
  15. Bruce Schneier, John Kelsey, Doug Whiting, David Wagner, Chris Hall, Niels Ferguson (1998). Twofish: A 128-Bit Block Cipher.
  16. (December 1980). FIPS 81: DES Modes of Operation.
  17. (2001). Recommendation for Block Cipher Modes of Operation. National Institute for Standards & Technology.
  18. J. Kelsey, B. Schneier, and N. Ferguson (1999). Yarrow-160: Notes on the Design and Analysis of the Yarrow Cryptographic Pseudorandom Number Generator.