Encryption https://scienceblogs.com/ en Turing Award to the Institute’s Prof. Shafi Goldwasser https://scienceblogs.com/weizmann/2013/03/13/turing-award-to-the-institutes-prof-shafi-goldwasser <span>Turing Award to the Institute’s Prof. Shafi Goldwasser</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>Prof. Shafi Goldwasser, who is at both the Weizmann Institute and MIT, <a href="http://wis-wander.weizmann.ac.il/turing-award-to-the-weizmann-institute%E2%80%99s-shafi-goldwasser-for-advances-that-revolutionized-the-science-of-cryptography#.UT8GaTceW_M" target="_blank">will receive the 2012 A.M.</a> Turing Award, together with Prof. Silvio Micali of MIT. Goldwasser is only the third woman to receive the Award since its inception in 1966, and she is the third faculty member of the Weizmann Institute to receive what is considered to be the “Nobel Prize in computing.” </p> <p><a href="/files/weizmann/files/2013/03/GOLDVASSER.jpg"><img src="http://scienceblogs.com/weizmann/files/2013/03/GOLDVASSER-300x300.jpg" alt="GOLDVASSER" width="300" height="300" class="aligncenter size-medium wp-image-476" /></a></p> <p>Goldwasser and Micali’s work in the 1980s laid the foundations of modern cryptography – the science that, among other things, keeps your electronic transactions secure. </p> <p>The basis of their work is a series of riffs on the concepts of probability and proof. For example, in their seminal “zero-knowledge interactive proofs” paper, they changed, forever, the paradigm of a mathematical proof that must be written down, step-by-step, page after page. Instead, they suggested that a proof can come out of a conversation between two parties – a “prover” and a “verifier.” </p> <p>Laszlo Lovasz describes it thus: </p> <blockquote><p>It sounds paradoxical, but there is a scheme which allows the customer to convince the bank that he knows the password – without giving the slightest hint as to what the password is! ….The most interesting aspect of this scheme is that it extends the notion of a proof, thought (at least in classical mathematics) to be well established for more than 2000 years. In the classical sense, a proof is written down entirely by the author (whom we call the Prover), and then it is verified by the reader (whom we call the Verifier). Here, there is interaction between the Prover and the Verifier: The action taken by the Prover depends on the “questions” of the Verifier. </p></blockquote> <p>In other words, by asking a series of questions, each one randomly based on the answer to the previous question, the verifier can ascertain whether the prover has the mathematical proof -- without actually learning anything about the proof, itself. Obviously, using a method like this can keep your password from being stolen, but it can also be used by people working together online who want to jointly compute functions without giving away their data. </p> <p>In fact, Goldwasser and Micali’s work has major implications for the entire field of mathematics known as complexity theory. Lovasz imagines using the method to referee an “exponentially long paper”: </p> <blockquote><p>There is a way to write down a proof so that a referee can check the correctness of a theorem by reading only a tiny fraction of it. The proof becomes longer than necessary, but not much longer. The number of characters the referee has to read is only around the logarithm of the original proof length! </p></blockquote> <p>Just as important, says Goldwasser, you can use such methods to establish that a mathematical statement is not correct, by proving "non existence" of classical proofs.</p> </div> <span><a title="View user profile." href="/author/jhalper" lang="" about="/author/jhalper" typeof="schema:Person" property="schema:name" datatype="">jhalper</a></span> <span>Wed, 03/13/2013 - 08:00</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/awards" hreflang="en">awards</a></div> <div class="field--item"><a href="/tag/basic-research" hreflang="en">basic research</a></div> <div class="field--item"><a href="/tag/computer-science" hreflang="en">Computer Science</a></div> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> <div class="field--item"><a href="/tag/internet" hreflang="en">Internet</a></div> <div class="field--item"><a href="/tag/mathematical-model" hreflang="en">mathematical model</a></div> <div class="field--item"><a href="/tag/women-science" hreflang="en">women in science</a></div> <div class="field--item"><a href="/tag/complexity" hreflang="en">complexity</a></div> <div class="field--item"><a href="/tag/computer-security" hreflang="en">computer security</a></div> <div class="field--item"><a href="/tag/mathe" hreflang="en">mathe</a></div> <div class="field--item"><a href="/tag/shafi-goldwasser" hreflang="en">Shafi Goldwasser</a></div> <div class="field--item"><a href="/tag/basic-research" hreflang="en">basic research</a></div> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> <div class="field--item"><a href="/tag/mathematical-model" hreflang="en">mathematical model</a></div> <div class="field--item"><a href="/tag/women-science" hreflang="en">women in science</a></div> </div> </div> <div class="field field--name-field-blog-categories field--type-entity-reference field--label-inline"> <div class="field--label">Categories</div> <div class="field--items"> <div class="field--item"><a href="/channel/free-thought" hreflang="en">Free Thought</a></div> </div> </div> <section> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/weizmann/2013/03/13/turing-award-to-the-institutes-prof-shafi-goldwasser%23comment-form">Log in</a> to post comments</li></ul> Wed, 13 Mar 2013 12:00:29 +0000 jhalper 71236 at https://scienceblogs.com No Need for Decryption https://scienceblogs.com/weizmann/2011/12/15/working-on-encrypted-data <span>No Need for Decryption</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p>Is it possible to perform operations on encrypted data, while keeping it secure from all prying eyes (or circuits), even if that data is stored remotely, in the "cloud?" Will our end result still be encrypted, and when we decode it with our private decryption key, will our result be correct? To put it another way, could we allow sensitive data - say private medical information - to be monitored on-line and feel completely secure in the knowledge that no one can access it without our express permission? Can we use a cloud service to store our encrypted data and perform a search on that data without allowing the servers to "see" our search? </p> <p>Welcome to the world of fully homomorphic encryption. The concept was first proposed in 1978 - long before the advent of remote computing services - by Rivest, Adelman and Dertouzos. (Rivest and Adelman, together with the Weizmann Institute's Prof. Adi Shamir, invented the RSA scheme used for almost all computer encryption today.) Since then, various researchers have come up with "partly homomorphic" methods, but none of them enabled full homomorphism. Only in 2009 was a fully homomorphic method demonstrated, by Craig Gentry at Stanford. That method, though proof of concept, was much too heavy and slow to be of any practical use.</p> <p>Gentry published his method as his Ph.D. thesis. But it could be <a href="http://wis-wander.weizmann.ac.il/improving-security-in-the-cloud?press-room-rb">the doctoral work</a> of another recent graduate - Dr. Zvika Brakerski from the Weizmann Institute (a student of Prof. Shafi Goldwasser) - that ultimately enables fully homomorphic encryption to become reality. Brakerski worked with Dr. Vinod Vaikuntanathan, a former student of Goldwasser's at MIT, who was at Microsoft Research at the time and is currently a professor at the University of Toronto.</p> <p>In a nutshell: Gentry made some assumptions about the complexity of the math needed to achieve fully homomorphic encryption, and then used "a bit of a hack" (his words) to make it all work. Brakerski and Vaikuntanathan managed to change some of those assumptions (to "weaker" - more plausible and widely accepted - assumptions), simplifying the math and even eliminating the need for some of the hacks. The result, they say, is a method that is hundreds or even thousands of times faster than the original, but still fully homomorphic. </p> <p>Brakerski, now doing postdoctoral research at Stanford, is continuing to research the math involved in fully homomorphic encryption. In the meantime, software engineers are already applying his insights to the future of data security. </p> <p><a href="http://scienceblogs.com/weizmann/Shafi%20Goldwasser.jpg"><img alt="Shafi Goldwasser.jpg" src="http://scienceblogs.com/weizmann/assets_c/2011/12/Shafi Goldwasser-thumb-250x167-71331.jpg" width="250" height="167" class="mt-image-center" style="text-align: center; display: block; margin: 0 auto 20px;" /></a></p> <div style="text-align: center;"><em>Prof. Shafi Goldwasser and Dr. Zvika Brakerski<br /> </em></div> <p>Also today at the Weizmann Institute:<br /> <a href="http://wis-wander.weizmann.ac.il/hide-and-seek-signals">White blood cells that reach into the blood vessel lining</a> looking for "exit signs" and the <a href="http://wis-wander.weizmann.ac.il/a-supernova-with-a-view?press-room-rb">closest supernova observation in the past 25 years </a>yields new insights into how stars explode. </p> </div> <span><a title="View user profile." href="/author/jhalper" lang="" about="/author/jhalper" typeof="schema:Person" property="schema:name" datatype="">jhalper</a></span> <span>Wed, 12/14/2011 - 20:03</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/cloud-computing" hreflang="en">cloud computing</a></div> <div class="field--item"><a href="/tag/computer-science" hreflang="en">Computer Science</a></div> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> <div class="field--item"><a href="/tag/computer-security" hreflang="en">computer security</a></div> <div class="field--item"><a href="/tag/fully-homomorphic" hreflang="en">Fully homomorphic</a></div> <div class="field--item"><a href="/tag/rsa" hreflang="en">RSA</a></div> <div class="field--item"><a href="/tag/shafi-goldwasser" hreflang="en">Shafi Goldwasser</a></div> <div class="field--item"><a href="/tag/vinod-vaikuntanathan" hreflang="en">Vinod Vaikuntanathan</a></div> <div class="field--item"><a href="/tag/zvika-brakerski" hreflang="en">Zvika Brakerski</a></div> <div class="field--item"><a href="/tag/cloud-computing" hreflang="en">cloud computing</a></div> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <div class="field field--name-field-blog-categories field--type-entity-reference field--label-inline"> <div class="field--label">Categories</div> <div class="field--items"> <div class="field--item"><a href="/channel/free-thought" hreflang="en">Free Thought</a></div> </div> </div> <section> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/weizmann/2011/12/15/working-on-encrypted-data%23comment-form">Log in</a> to post comments</li></ul> Thu, 15 Dec 2011 01:03:52 +0000 jhalper 71195 at https://scienceblogs.com Cryptographic Padding in RSA https://scienceblogs.com/goodmath/2009/01/08/cryptographic-padding-in-rsa <span>Cryptographic Padding in RSA</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p> Ok, away from politics, and back to the good stuff. When I left off talking about<br /> encryption, we were <a></a> href="http://scienceblogs.com/goodmath/2008/12/public_key_cryptography_using.php"&gt;looking at<br /> RSA, as an example of an asymmetric encryption system.</p> <p> Since it's been a while, I'll start off with a quick review of RSA.</p> <p> Asymmetric encryption systems like RSA are based on computations that are easy to perform if you know the keys, and incredibly hard to perform if you don't. In the specific case<br /> of RSA, everything is based on a pair of very large prime numbers. If you know those two<br /> primes, and you know the public key, it's really easy to compute the private key. But<br /> if you <em>don't</em> know the two prime numbers, then even given the public key,<br /> it's incredibly difficult to compute the private key.</p> <p> To be a bit more specific, in RSA, you get a pair of large prime numbers, P and Q. You<br /> compute from them a <em>totient</em> of their product, which is the number<br /> N=(P-1)×(Q-1). Then you arbitrarily pick a public exponent, E, which is<br /> smaller than N, and which is prime relative to N. You can then compute<br /> the private key exponent, D. If you know what P and Q are, it's pretty easy to compute<br /> D.</p> <p> Once you've got D and E, your public key is the pair is (N,E), and the private key is the pair is (N,D).</p> <p> If you've got a plaintext message M, then encrypting it with the public key<br /> is done by computing M<sup>E</sup> mod N. If you've got a ciphertext C encrypted<br /> with the public key, then decrypting it is done by computing C<sup>D</sup> mod N.</p> <p> <em>Encrypting</em> a plaintext with the public key is <em>exactly</em> the same process<br /> as <em>decrypting</em> a ciphertext produced with the private key. And vice versa.</p> <!--more--><p> RSA is amazingly elegant. Every time I look at it for any reason, I'm struck<br /> by its beauty and it's simplicity. It's really an amazing example of how<br /> something seemingly abstract like number theory can produce practical, down-to-earth,<br /> and useful.</p> <p> But RSA isn't perfect. In fact, it's got a some rather serious problems that<br /> are a direct result of its mathematical structure. I'm just going to mention<br /> one, but there are several of them.</p> <p> Suppose you've got your public/private keypair. You want to encrypt two messages, I<br /> and J with your private key. Let's call the function for encrypting a message<br /> with the private key E - so E(M) = M<sup>D</sup> mod N. Then<br /> C<sub>I</sub> = E(I), and C<sub>J</sub>=E(J). Good so far.</p> <p> The problem is that given those two messages - for which an attacker has access to both<br /> the plaintext and the ciphertext - it happens that there's a vulnerability. Because of the<br /> way that encryption works, E(I×J) = E(I) × E(J)!</p> <p> This opens you up to something called <em>chosen ciphertext attacks</em>. A chosen<br /> ciphertext attack is one where you attack an crytographic system by running chosen<br /> ciphertexts through the decryption system to see if you can compute the encryption key.<br /> There's an effective attack against the naive use of RSA based on a selected ciphertext<br /> method. </p> <p> In addition to this, there are a few other interesting attacks that I won't describe in<br /> detail. They all rely on various problems of the numerical structure of RSA encryption. In<br /> order to defeat those attacks, RSA is typically used with something called a <em>padding<br /> scheme</em>. The idea of the padding scheme is twofold. First, it increases the size of the<br /> message - which guarantees that the encrypted message is large enough that it will not be<br /> easy to use for an attack. Second, it intersperses pseudo-random information in a way that<br /> means that a given plaintext message could be encrypted to a wide range of different<br /> ciphertexts, depending on the choices made during padding.</p> <p> A common scheme for padding is OAEP - Optimal Asymmetric Encryption Padding. OAEP<br /> is a basic Feistel network system, like the ones I described when I was talking<br /> about DES. OAEP ends up doing a mixture of permuting the plaintext, and<br /> adding pseudo-random noise to it. It's a reversible transformation,<br /> and the receiver of the encrypted message (and thus any attacker) knows how to<br /> do the reversal of the padding given the decrypted plaintext. But the process<br /> of permutation and random injection performed by the padding has the effect<br /> of breaking the properties of RSA that make it easy to attack the system.</p> <p> For example, suppose that the padding function is called P. E(P(I))×E(P(J)) is<br /> <em>not</em> equal to E(P(I×J)). Similarly, the message-size-related problems<br /> with RSA are not usable on messages whose size is increased past the vulnerability threshold<br /> using OAEP padding.</p> <p> So what does the padding look like? Let's start with the pieces.</p> <ol> <li> You have a number, N, which is the length of the cryptographic modulus.</li> <li> You have two integers, k<sub>0</sub> and k<sub>1</sub>, which are parameters<br /> of the protocol in use.</li> <li> You have the original plaintext message, M. By definition, the length of M is<br /> (n - k<sub>0</sub> - k<sub>1</sub>). (The protocol is responsible for breaking<br /> up large messages into sub-messages via an appropriate mode of operation.)</li> <li> You have a 0-padded version of M, M', which is M followed by k<sub>1</sub><br /> zeros - so M' has length N-k<sub>0</sub>.</li> <li> You have a random string of bits, r, which has length k<sub>0</sub>.</li> <li> You have a cryptographic hash function G, which expands a string of<br /> k<sub>0</sub> bits to a string of N-k<sub>0</sub> bits.</li> <li> You have another cryptographic hash function H, which contracts<br /> a string of n-k<sub>0</sub> bits to a srting of k<sub>0</sub> bits.</li> </ol> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-d4cd342a16a036ff88b7f784fd466a7f-oaep.png" alt="i-d4cd342a16a036ff88b7f784fd466a7f-oaep.png" /></p> <p> The OAEP padding algorithm is illustrated off to the side. The way that<br /> it works is: you compute G(r), giving you a string of N-k<sub>0</sub> bits.<br /> You XOR G(r) with M', producing a string of N-k<sub>0</sub> bits, which we'll<br /> call X. Then compute H(X), and XOR that with r, producing a result that we'll call<br /> Y. The end result of the padding is the concatenation of X and Y.</p> <p> The way to understand this is that you've got some random bits in R, which you're shuffling up (using G and H) and mixing with the bits of the original message. The resulting message is longer, and has a random element mixed into it, which defeats the numerical properties that make some attacks against RSA work. It's easy to compute<br /> X and Y given M and r. And given X and Y, if you know G and H it's easy to compute<br /> M and r. But given E(X concat Y), as an attacker, you're screwed. You can<br /> still decript the message, and get X and Y, decode them, and get the plaintext. But<br /> the process of doing the padding obscures the numerical properties of RSA so that<br /> even knowing the padding function, your attacks won't work.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Thu, 01/08/2009 - 15:52</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <div class="field field--name-field-blog-categories field--type-entity-reference field--label-inline"> <div class="field--label">Categories</div> <div class="field--items"> <div class="field--item"><a href="/channel/free-thought" hreflang="en">Free Thought</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2122663" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231493398"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>It seems like an interesting fix but, since G and H have to remain secret, doesn't it turn the whole scheme into a symmetric encryption method? Don't you loose all benefits of using asymmetric cryptography?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122663&amp;1=default&amp;2=en&amp;3=" token="45Sq7S1PlaXbFOZKR9cG25SH-5zUw5NPBnOVNDLHvIY"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Simon (not verified)</span> on 09 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122663">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2122664" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231494092"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Simon:</p> <p>G and H don't have to remain secret. In fact, they're specifically *not* secret. Their purpose isn't to encrypt the message; it's just to scramble things to change their numeric properties. So, for example, a pair of original plaintext messages P and Q no longer have the property that E(P)×E(Q) = E(P×Q).</p> <p>It's true that E(OAEP(P))×E(OAEP(Q)) = E(OAEP(P)×OAEP(Q)). But since OAEP(P)×OAEP(Q) does <em>not</em> equal OAEP(P×Q), that doesn't help an attacker. </p> <p>The reason that G and H are cryptographic hashes is because<br /> they given a particular value of G(M), it's very hard to compute an M' such that G(M') = G(M), and so it's very difficult to create messages that let you exploit the numerical properties of RSA.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122664&amp;1=default&amp;2=en&amp;3=" token="lEJvkRndPmxRZenM-6-17zPdmgVUe3BOdyzP6LiX7yk"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 09 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122664">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2122665" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231495142"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Mark:</p> <p>Thank you! So the equation E(P)*E(Q) = E(P*Q) tells you something about the private key? Then, given any public key, an attacker could choose carefully his plaintext to discover the information this padding scheme is supposed to hide. Am I wrong?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122665&amp;1=default&amp;2=en&amp;3=" token="ywYAByTQuaWZxw5Enk2qafuBqo3FmReIl70dV56ruYI"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Simon (not verified)</span> on 09 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122665">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2122666" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231495484"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Simon:</p> <p>Yes, exactly. The fact that E(P)×E(Q)=E(P×Q) provides a handle that an attacker can use to deduce the secret key. There are also a number of similar vulnerabilities in RSA, based on similar numerical properties. The point of the padding scheme is just to change the structure of the message enough to make it very difficult for an attacker to produce messages that they can use to deduce the private key.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122666&amp;1=default&amp;2=en&amp;3=" token="MHc8dqakqa_i4POLvQ7FUqEUnKh7hh0P2qxBu_tymxU"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 09 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122666">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2122667" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231764560"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I'll add some small print :)</p> <p>Correct me if I'm wrong, but another flaw with RSA is it depends on calculating large prime numbers. After a certain point it becomes quite impractical to do normal prime tests and you need to use probabilistic prime tests. There are composite numbers (like Carmichael numbers) that can fool these tests into thinking that they are prime.<br /> Another thing to note is that there are certain Ns that are relatively easy to factor using methods such as Pollard's p-1 or quadratic sieve that depend on certain properties of the P and Q you are using.<br /> I'm not sure if these numbers are common enough that it matters or not, but it might be a good idea to keep these in mind when building an implementation of RSA.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122667&amp;1=default&amp;2=en&amp;3=" token="NKIvZGYlEEqpBN9tnGg4kh7gXEp3sHUdE6ZX0fhklK4"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://lovehateubuntu.blogspot.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Rob Britton (not verified)</a> on 12 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122667">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2122668" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231765289"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Rob:</p> <p>First, I would <em>never</em> advise anyone to do their own implementation of RSA. There are plenty of really solid, tested implementations out there that people can use. Cryptographic algorithms are <em>very</em> easy to get wrong, and the slightest mistake can completely undermine the security of the system. Crypto isn't an area where you should roll your own; building your own crpyto should be a last resort, and if it needs to be done, it should be done with incredible care, including things like code audits by outside crypto experts.</p> <p>That said, yes, there is a real problem with ensuring that you <em>do</em> get prime numbers as the basis for the keys. We do typically use probabilistic approaches to computing primes - but without exhaustive analysis, we can't be sure that the probabilistic approaches are correct. If you're generating your own key-pair, you should throw as much computational power at it as you possibly can - in order to ensure, to the best of your ability, that the primes you use for your keys are really honest-to-goodness primes. </p> <p>In general, though, most standard implementations do that. They give you a choice of how long you're willing to take to generate the keys, and they test the primes and the generated keys against the basic attacks to ensure that you haven't ended up with an easily crackable key-pair.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122668&amp;1=default&amp;2=en&amp;3=" token="_WXyQPBErwyiKU4tspeL0G5HE6WQNJIBwS7ncH4GJN4"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 12 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122668">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2122669" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231766054"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Dorthy Denning solved this problem long ago. Philip Zimmerman and Bruce Schneier described and implemented solutions to these problems long ago.</p> <p>See for example: </p> <p>Davida, G.I. <a href="http://www.uwm.edu/~davida/papers/chosen/">"Chosen Signature Cryptanalysis of the RSA (MIT) Public Key Cryptosystem,"</a> <em>Technical Report TR-CS-82-2</em>, Department of EECS, University of Wisconsin, 1982<br /> Denning, D.E. <em>Cryptography and Data Security</em> Addison Wesley, 1982</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122669&amp;1=default&amp;2=en&amp;3=" token="Nu9u23VfHyZ6-2BtUAEYPEWEh5bNIqf0kC-duf3szJg"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://blog.coincidencetheories.com" lang="" typeof="schema:Person" property="schema:name" datatype="">William Wallace (not verified)</a> on 12 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122669">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2122670" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231781825"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>"<em>Cryptographic algorithms are very easy to get wrong, and the slightest mistake can completely undermine the security of the system.</em>"</p> <p>This is true.</p> <p>But, to be honest, if you are a very good programmer, and are confident in your ability to rigourously and automatically test your code with a custom built regression test suite, and you are confident in your ability to identify boundary conditions, and you have spent a good deal of time learning about other's mistakes, you might have a more trustworthy implementation if you roll your own. But it is not for the weak kneeed.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122670&amp;1=default&amp;2=en&amp;3=" token="Q4EXcTq3RP4t86rOA1Q6B2XBIehkdl1JEvpXxRxEyxM"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://blog.coincidencethreories.com" lang="" typeof="schema:Person" property="schema:name" datatype="">William Wallace (not verified)</a> on 12 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122670">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2122671" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231782851"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Actually, I would say that if you're a very good programmer, and are confident in your ability to rigourously and automatically test your code, etc., you're <em>exactly</em> the kind of person who <em>should know better</em> than to write your own crypto code.</p> <p>The thing about crypto is that there's a lot more than just boundary cases. There are tons of corners where the slightest mistake can totally screw you. And the confident solo programmer is exactly the guy who's going to make that kind of mistake.</p> <p>Real serious crypto code requires <em>at least</em> three groups of people:<br /> (1) a group of programmers to write the code.<br /> (2) A group of testers to write the test, who have <em>never seen</em> the actual implementation, and who know nothing more about the design of the code than the formal description of the algorithm.<br /> (3) A group of crypto experts to review and audit the design, code, and tests.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122671&amp;1=default&amp;2=en&amp;3=" token="Olc-WOnCU8HKU9sS3rwjJHeqlRGwk3I4jLAr3hfNpO4"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 12 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122671">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2122672" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231784795"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Actually, I would say that if you're a very good programmer, and are confident in your ability to rigourously and automatically test your code, etc., you're <em>exactly</em> the kind of person who <em>should know better</em> than to write your own crypto code.</p> <p>The thing about crypto is that there's a lot more than just boundary cases. There are tons of corners where the slightest mistake can totally screw you. And the confident solo programmer is exactly the guy who's going to make that kind of mistake.</p> <p>Real serious crypto code requires <em>at least</em> three groups of people:<br /> (1) a group of programmers to write the code.<br /> (2) A group of testers to write the test, who have <em>never seen</em> the actual implementation, and who know nothing more about the design of the code than the formal description of the algorithm.<br /> (3) A group of crypto experts to review and audit the design, code, and tests.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122672&amp;1=default&amp;2=en&amp;3=" token="YMZUMRUre_VXgUrR_xE11rGqELNVRQiP9GphcFjHiO8"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 12 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122672">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2122673" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231816268"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>OT1: It is an ironic coincidence that you posted your response twice. I just cut, pasted, and saved both versions of your response, and I did not detect any difference in information in the in second (#10) compared to the first (#9). Was the duplicate intentional? </p> <p>OT2: Is the typepad login feature a scienceblogs imposed requirement, or just for goodmath?</p> <p>You might also consider adding a fourth team that systematically inserts faults into a sandbox version of the design, and then subjects the intentionally sabotaged version to the test suites, as a form of quality control.</p> <p>The additional amount of resources necessary for this is relatively small, and it is a relatively productive use of resources.</p> <p>But I haven't had much luck convincing others of this fact.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122673&amp;1=default&amp;2=en&amp;3=" token="ncbwex6P03Fw-jZn1HfQFkrKb3oXcGVpL9uInOAnM9c"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://blog.coincidencetheories.com" lang="" typeof="schema:Person" property="schema:name" datatype="">William Wallace (not verified)</a> on 12 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122673">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2122674" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1231830583"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>William:</p> <p>We're still getting used to the newly upgraded MoveableType installation, and there are a few glitches as we get it up and running. When I tried to respond to you yesterday, the system was timing out posting comments. One attempt seemed to fail - it timed out, and the comment didn't appear. But apparently it did get done by the backend, and just hadn't appeared yet. So I reposted, only to discover it had already successfully posted. </p> <p>The typepad stuff isn't intended to be a requirement; I'm trying to set it up as an option, where you <em>can</em> use it if you want, but you don't have to.</p> <p>I agree that a fault-based testing scheme is a <em>really</em> excellent idea for serious crypto code. </p> <p>But at the moment, convincing people that they shouldn't just roll their own crypto for the fun of it is difficult<br /> enough. Once you get people to understand how tricky it is to get crypto implementations to be really secure, then I think getting them the rest of the way isn't that hard.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122674&amp;1=default&amp;2=en&amp;3=" token="gpvRT8yAdsWfZoKrhtsLijC73attYy4tbQ1heoGsGXw"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 13 Jan 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122674">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2122675" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1239260428"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Hi there. </p> <p>Please excuse a total novice. I have always wondered why encryption is not used in tandem. That is, encrypt messages twice with two diffrent algorithms and/or encryption keys.</p> <p>This would, not make the encryption stronger per say but, it seems to me, the test to confirm success should become almost impossible. </p> <p>Say you scramble an RSA encoded padded message, with a simple substitution/transposition cipher. Musn't you then first crack the simple cipher to be able to attack the RSA?<br /> And how do you confirm that you have cracked it?</p> <p>This has always puzzled me. I would be glad if you could enlighten me.<br /> /Chasapros</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2122675&amp;1=default&amp;2=en&amp;3=" token="Za2NFEXmcwnPJXQaWxhhy5yGbExQTZ3sZ8E055Jn62U"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Chasparos (not verified)</span> on 09 Apr 2009 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2122675">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2009/01/08/cryptographic-padding-in-rsa%23comment-form">Log in</a> to post comments</li></ul> Thu, 08 Jan 2009 20:52:29 +0000 goodmath 92678 at https://scienceblogs.com Public Key Cryptography using RSA https://scienceblogs.com/goodmath/2008/12/01/public-key-cryptography-using <span>Public Key Cryptography using RSA</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p><span class="technoratitag">Technorati Tags: <a href="http://www.technorati.com/tags/cryptography" rel="tag">cryptography</a>, <a href="http://www.technorati.com/tags/public-key" rel="tag">public-key</a>, <a href="http://www.technorati.com/tags/encryption" rel="tag">encryption</a>, <a href="http://www.technorati.com/tags/RSA" rel="tag">RSA</a>, <a href="http://www.technorati.com/tags/asymmetric-encryption" rel="tag">asymmetric encryption</a></span></p> <p> The most successful public key cryptosystem in use today is RSA - named for its inventors Rivest, Shamir, and Adleman. I first learned about RSA in grad school from one of my professors, <a href="http://www.cis.udel.edu/~elloyd/">Errol Lloyd</a>, who was one of Ron Rivest's students. Errol is without a doubt the best <em>teacher</em> I've ever had (and also a thoroughly nice guy). If you want to go to grad school to study algorithms, you frankly couldn't do better than heading to Delaware to work with Errol. I have very fond memories of Errol's class where we talked about this. He's got a way of teaching where he doesn't come out and <em>tell</em> you anything; what he does is ask questions that lead you through the process of figuring it out yourself. That's an incredibly effective way to teach <em>if</em> you can carry it off. Personally, I <em>can't</em>. And I've never known anyone except Errol who could do it for a topic like RSA encryption!</p> <p> Anyway, moving on... In general, public key cryptosystems are based on problems that are easy to solve computationally in one direction, but really hard to solve computationally in the other. In the case of RSA, the basic underlying problem involves prime numbers: if you've got two really large prime numbers, then multiplying them together is easy; but if you've got a number that's the product of two really large primes, factoring it is <em>very</em> hard.</p> <!--more--><p> One of the things that makes RSA difficult to explain is that it's hard to find a starting point. The actual encryption and decryption processes are so simple that<br /> they seem like they can't possibly work; there's just no way to make sense out<br /> of <em>why</em> they work without understanding where the keys come from; but it's strange to describe an encryption system by starting with how to generate keys, when you don't yet know how they're going to get used. </p> <p> The reason for this tangling comes back to the fundamental goal of a public key<br /> system: you've got to have two keys which share a complex mathematical relationship.<br /> The encryption system itself is really just a simple expression of the relationship<br /> between the keys. So the algorithm is (conceptually) very simple; the whole thing is<br /> based on the nature of the keys, their relationship, and the way that they're<br /> generate. It's not like symmetric cryptography, where you can simply chose a key; in<br /> public key systems, the keys have to be generated to satisfy a set of mathematical<br /> relationships.</p> <p> With that it mind, we'll start working through the way that RSA works by showing<br /> how you can create a public/private key pair. The key generation process is actually<br /> pretty simple, but most descriptions of it get tangled up because it uses a lot of<br /> terminology from number theory. I'll try to present the standard terms as clearly as I<br /> can.</p> <p> The basic structure underlying an RSA key pair is a pair of two large prime<br /> numbers. What's large? That depends on how hard you want it to be to crack. The<br /> tradeoff is that the larger the original pair of primes are, the more complex it is to<br /> compute ciphertext using a key. So you need to choose a key size which makes your keys<br /> hard to crack, without making the cost of encryption and decryption unacceptably<br /> high. Once you've decided on a key size, that dictates the size of your two prime numbers, and you're ready to compute a key pair, as follows.</p> <ol> <li> Compute two large primes, which are typically named P and Q. </li> <li> Using P and Q, you compute a number N=P×Q, which is called the <em>modulus</em> of the keys being generated. </li> <li> Compute the <em>totient</em> of the modulus. For any integer, I,<br /> the totient of I (written φ(I)) is the number of integers <em>smaller</em><br /> than I that are relatively prime to I. Because P and Q are prime, φ(P×Q)=(P-1)×(Q-1). (The totient of P is P-1, because there are P-1 numbers relatively prime to P; the totient of Q is Q-1 for the same reason; and since P and Q are (trivially) relatively prime to each other, the totient of P×Q is (P-1)×(Q-1)).</li> <li> Choose an integer, E, smaller than and relatively prime to φ(N). E is<br /> called the <em>public key exponent</em>.</li> <li> Compute an integer D such that D×E=1 mod φ(N). D is called the <em>private key exponent</em>.</li> </ol> <p> The public key is the pair (N, E) of the modulus and the public key exponent; and the private key is the pain (N, D) of the modulus and the private key exponent. So you've got your key pair.</p> <p> Encryption and decryption are amazingly simple.</p> <p> Suppose that the ubiquitous Alice and Bob want to communicate. Alice gives Bob her<br /> public key, (N, E). Now, when Alice wants to send a message to Bob, she encodes the<br /> plaintext of the message as an integer, M. (I'll leave the exact encoding of plaintext open for now.) To encrypt with her private key, (N, D),<br /> she takes that integer and computes:</p> <p></p><center><br /> Ciphertext = M<sup>D</sup> mod N<br /> </center> <p> Then to decrypt the message, Bob uses his key pair, and computes:</p> <p></p><center><br /> M = Ciphertext<sup>E</sup> mod N<br /> </center> <p> For Bob to encrypt a message for Alice, he does <em>exactly</em> the same thing that he did to the ciphertext - except he does it to the encoded message, M. For Alice to decrypt that, she does exactly what she did to <em>encrypt</em> the original M, except that she uses the ciphertext she recieved from Bob instead of the encoded plaintext M. In other words, if you've got a ciphertext message encrypted by the private key, decrypting it is <em>exactly</em> the same process as <em>encrypting</em> a plaintext with the public key, and vice versa. (This point is what used to cause me lots of confusion remembering what was symmetric and what was assymetric - RSA style asymmetric encryption is really very symmetric in how the algorithm works.)</p> <p> How can this possibly work? On the face of it, it looks ridiculous! You encode by exponentiating once; you decode not by taking a root, but by exponentiating again!</p> <p> It all comes back to the way the keys were generated. If we look at the process<br /> in terms of modulo arithmetic, it's pretty easy to see why it works:</p> <ul> <li> Take an original message, M. Encrypted, it's<br /> C = M<sup>D</sup> mod N.</li> <li> Now, take the ciphertext, C, and decrypt it.<br /> M' = C<sup>E</sup> mod N.</li> <li> Now, expand C: M' = (M<sup>D</sup> mod N)<sup>E</sup> mod N.</li> <li> Now, we can combine the exponents: M' = M<sup>D×E</sup> mod N.</li> <li> D×E = 1 mod N.</li> <li> By some trickiness, related to the fact that D and E are relative primes related to both each other and N by their relation to the<br /> totient of N, we can show that the fact that D×E = 1 mod N means<br /> that M' = M<sup>D×E</sup> = M<sup>1</sup> = M.</li> </ul> <p> Watch how we can walk through a ridiculously simplified example. Let's start with<br /> a pair of primes - 29 and 61.</p> <ol> <li> Generate keys: <ul> <li> First, we compute the modulus: 29×61=1769.</li> <li> Then we compute the totient: 1680.</li> <li> Then we choose an E which is relatively prime with 1680. To make things easy,<br /> I'll just pick a prime number: E=13. </li><li> Now, I need to compute a D, such that D×E=1 mod 1680;<br /> or to pull out a bit of standard terminology, D is the modular multiplicative<br /> inverse of E mod 1680. Doing that is an exercise in modulo arithmetic<br /> which gets beyond the scope of what I want to talk about today, so I'll<br /> cheat: whipping out Mathematica, I get D=517.</li> <li> So, the public key is (1769,13), and the private key is (1769,517).</li> </ul> </li> <li> Now, let's encode a message. Say the message is 236. So, encrypted by<br /> the public key, that's 236<sup>13</sup> mod 1769 = 7044595136617487310722334457856 mod 1769 = 573.</li> <li> And now, let's decode it. That's 573<sup>517</sup> mod 1769 = 9245694881849602770197401240655288154608138663291308421093411147578949\<br /> 4462244595981994549450775979702694154377539110666284415651476199963925\<br /> 1321729713042853618725578035043275339491371655153997356248940804495270\<br /> 8984801258907252216498797520780679511957335315751292762455167434140192\<br /> 4399386435156204841871858091160737587648566008200581107378219553124074\<br /> 9374669246678685272914050993442585237015640426625522901746517901417734\<br /> 7954757584818934596889432709457570226928654243870833959974236930834811\<br /> 3204280174093386319717080086558480154647619900966739378086145377566860\<br /> 9195850562761848872414474511076491179637551417498920992360433000710853\<br /> 3935087767676514264669956171228256961906386882369681633698604708335082\<br /> 4532038380922358459546076540454839797340473363177061704334483341984626\<br /> 0992808331110751927026090969022077767175228102822099312339565763871188\<br /> 4006940217478961345132678704142880421227822352750998264777937728911493\<br /> 6283819708613556665220171457755862562705567302041244568283475209225680\<br /> 3828781673802145987568796646578059853165517716374603716155560308698631\<br /> 2650416428650673915642280074852668462543146649056536263032788685526436\<br /> 7863995916605455190338263161582118236712167656565774640875461698797822\<br /> 0025671340803745351386743506255677806855116853206286798808454276083160\<br /> 2812779603110688541701764925723493557773173917037390830611160570524069\<br /> 7471206139919064156642428626093922418127017110711925314998235480530680\<br /> 56675958655700624098981453 mod 1769 = 236.</li> </ol> <p> So it works - but computing those results is not exactly trivial. It happens that there is a fast algorithm for doing those sorts of exponentiations - but "fast" is a relative term. RSA encryption is a <em>lot</em> slower than most symmetric encryptions, by a significant factor.</p> <p> In real-world use, RSA is rarely used for full-message encryption. It's used for signatures (where you encrypt a small summary of a message), and for protocol negotiations to allow the two sides to settle on a symmetric encryption key to<br /> use for the rest of their communication. </p> <p> You'll notice that I still haven't gotten back to how you take a message<br /> and convert it to an integer. That's <em>not</em> trivial. The problem is,<br /> for certain message sizes, or messages with certain numeric properties,<br /> RSA can be easily broken. So you need to protect against those cases. That's<br /> done by <em>padding</em> the message - adding bits to it in a way that removes<br /> or obscures the properties of the message that would otherwise make it vulnerable.<br /> Discussing the vulnerabilities of RSA for certain types of messages, and how<br /> to build a padding system that defeats them is a topic for another post.</p> <p> In future posts, I'll also describe the two most common uses of RSA in more detail - both using RSA for signing a message to prove that you really wrote it; and using<br /> RSA as part of a secure cryptographic protocol where most of the traffic is really<br /> encrypted using a symmetric algorithm.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Mon, 12/01/2008 - 03:29</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <div class="field field--name-field-blog-categories field--type-entity-reference field--label-inline"> <div class="field--label">Categories</div> <div class="field--items"> <div class="field--item"><a href="/channel/free-thought" hreflang="en">Free Thought</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2121503" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228131628"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Ah! Brilliant, thank you for that post! I always wanted to understand how RSA works. Can I ask for posts here? (Or make a couple of suggestions anyhow). I'd love to see an explanation on the Off-The-Record Messaging protocol, in particular what makes it so different than others and how this was done... and also, drifting a bit from your original intention with this series of posts, I'd like to know how my privacy is assured by third parties... banks, web applications, mobile phone companies. What are they doing to protect my privacy, and should I trust them?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121503&amp;1=default&amp;2=en&amp;3=" token="lGGhSNBK3MIR_eVk70H-1vQNaOMXXqAykRaNYf2kxfc"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Bruno (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121503">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121504" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228134144"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>"He's got a way of teaching where he doesn't come out and tell you anything; what he does is ask questions that lead you through the process of figuring it out yourself."<br /> I think that's colloquially known as the Socratic Method. The same style is used in book form in the <i>The Little Schemer</i> (formerly <i>The Little LISPer</i>, I believe) to teach Scheme. On the darker side of things, someone who is very skilled at arguing can use this technique to great effect to trap you with your own reasoning.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121504&amp;1=default&amp;2=en&amp;3=" token="9OSJaby1Q48cayfSaS4qK9qfg4d4Vh3ANBv-S9P4jXk"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Xyz (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121504">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121505" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228135048"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>It's indeed a nice post, but I have a question: in the examples you give, encryption is done with the <b>private</b> key. Isn't this the way digital signatures are done? (Actually on real systems it's not, as they are typically hybrids that use both asymmetric and symmetric algorithms, to overcome the speed limitations you mentioned, but I digress).<br /> My point is, by saying things like <i>encrypt with her private key</i>, without explaining that's for digital signatures (instead of encryption proper), aren't you creating a source of confusion? Even if you reserve the details of public key system for a later post, I think you should have at least mentioned that here. But as I said in the beginning, it's a nice post nonetheless :-)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121505&amp;1=default&amp;2=en&amp;3=" token="uD5dZGNzIEM7MXlj73BUgwRLdJJ4mbxsUrmgkUtSu00"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Oscar (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121505">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121506" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228135390"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>It's indeed a nice post, but I have a question: in the examples you give, encryption is done with the <b>private</b> key. Isn't this the way digital signatures are done? (Actually on real systems it's not, as they are typically hybrids that use both asymmetric and symmetric algorithms, to overcome the speed limitations you mentioned, but I digress).<br /> My point is, by saying things like <i>encrypt with her private key</i>, without explaining that's for digital signatures (instead of encryption proper), aren't you creating a source of confusion? Even if you reserve the details of public key system for a later post, I think you should have at least mentioned that here. But as I said in the beginning, it's a nice post nonetheless :-)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121506&amp;1=default&amp;2=en&amp;3=" token="BTkgZ4bE6-jrYEM-KL1DAk1c3B_J0qSbwPmjSzGfkXk"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Oscar (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121506">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121507" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228135744"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Some nitpicking about academic credit...</p> <p>RS and A were RE-inventors of the algorithm. It had first been discovered in the UK by James Ellis and Clifford Cocks of the GCHQ. They were soon joined by Malcolm Williamson, who went on and invented what became known as the Diffie-Hellman(-Merkle) key exchange. Unfortunately their role remained hidden, because they were not allowed to publish their discoveries at the time.</p> <p>You can read the full story in the Code Book by Simon Singh.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121507&amp;1=default&amp;2=en&amp;3=" token="VqwyRI24fcikoJZ0PN-V6NvXGfKcevKzP3UyyNgT-iU"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Lassi Hippeläinen (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121507">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2121508" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228136088"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Oscar:</p> <p>Public key encryption <em>is used for</em> digital signatures, but that's not the only use of it. And even when it is used for signature, the way that it's used is to <em>encrypt</em> a section of the message which contains an authentication code for the rest of the message.</p> <p>I'll talk about this in a later post, but a quick outline of how secure digital signatures work is:</p> <p>(1) Take a message, M, that you want to send. You don't<br /> care if other people can read M, but you want the<br /> intended recipients to be absolutely sure that it was<br /> you who sent it.<br /> (2) Using a special kind of hash function, compute a value<br /> D, called a <em>digest</em> of M, where a D is a short code<br /> that is produced solely from the content of the message.<br /> (A good digest has a set of interesting properties, but<br /> I'm not going to list them here.)<br /> (3) Encrypt D, using your <em>private</em> key, and append<br /> the result to the end of your message. The encrypted<br /> digest is called a <em>signature</em>.</p> <p>Now, anyone who sees the message M can compute D. They don't<br /> need any kind of key - the value of D is solely dependent<br /> on the content of the message.</p> <p>Anyone can verify that <em>you</em> sent the message, because<br /> <em>only you</em> could have encrypted the digest in a way that could be decrypted with your private key.</p> <p>The big advantage of this technique is that there's no secret that needs to be shared with your intended recipients. Unlike a MAC in a symmetric encryption system,<br /> the digest is not encrypted, and anyone can generate it. But only you could produce an encrypted copy of the digest. </p> <p>So digital signature is really just a particular use-case of public key encryption that encrypts the message digest instead of the entire message. </p> <p>You can see this in a nice, visible form if you use the FireGPG plugin for Firefox. Given a message, you can<br /> encrypt it without signing it; sign it without encrypting it; or encrypt it and sign it. In all three cases, the encryption is RSA; in two of the three, RSA is used to encrypt the entire message.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121508&amp;1=default&amp;2=en&amp;3=" token="4qajTDaWH8YHf1KZQnicGxiyDdSnDovGO9ClF7G0ONk"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121508">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2121509" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228136290"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Xzy:</p> <p>I know that it's called the socratic method; but in my experience, a lot of people <em>don't</em> know what the socratic method was. I figured this post already had enough<br /> jargon in it without needing to introduce the name for that teaching method, when I would still need to include the description.</p> <p>And actually, I've never seen it used in a serious way to tangle people up. In various texts, particularly Plato, I've seen it used to tangle up <em>extremely stupid</em> interviewees. But I've never seen it used in real life to tangle up someone who wasn't already being an idiot to begin with. That sort of rhetorical use of it is generally a dressed up form of proof-by-contradiction, and the questioning process is really just for show.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121509&amp;1=default&amp;2=en&amp;3=" token="Z0I7pZ8ETsf9H20rLWEbSERt4dkKnA8aNk8CrHEFI4A"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121509">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121510" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228146084"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Nice article, just a small nitpick:<br /> Perhaps you should clarify that you can only effectively compute D because you know the primes p and q. After all that is what makes the system secure.<br /> If you could just plug E and M into Mathematica and find the modular inverse, anyone could do this, since (E,M) is the public key. But luckily the Extended Euclidian Algorithm require knowledge of the prime factors of M to work.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121510&amp;1=default&amp;2=en&amp;3=" token="MA3UiPc59AjT8_nbkn-TZGar_SZJ22BkUHyzdLNy68Q"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Rasmus Faber (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121510">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121511" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228150107"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Mark:</p> <p>You're right, but the use you make of the verb "encrypt" is somewhat loose. I mean, usually when one talks about "encrypting", one means "to write in a form that cannot be easily read", and you absolutely cannot do that using ("encrypting") with the private key (because everyone with the corresponding public key will be able to "decrypt" that message). But after reading this paragraph:</p> <p><i><br /> Suppose that the ubiquitous Alice and Bob want to communicate. Alice gives Bob her public key, (N, E). Now, when Alice wants to send a message to Bob, she encodes the plaintext of the message [...]. To encrypt with her private key, (N, D), she takes that integer and computes [...]<br /> </i></p> <p>This might seem to suggest that the private key should be used to do encryption (as in "only the intended recipient gets to decrypt") which is far from being the case.</p> <p>Final remark: in your reply, you said:</p> <p><i><br /> Anyone can verify that you sent the message, because<br /> only you could have encrypted the digest in a way that could be decrypted with your private key.<br /> </i></p> <p>You meant <i>public key</i>, right? :)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121511&amp;1=default&amp;2=en&amp;3=" token="W3QU3a3a4hqBTB2mAbVpJglhSyVRMYgVQwb76GNrGzQ"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Oscar (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121511">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121512" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228154549"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Lassi: GCHQ did not invent the RSA algorithm. They invented the algorithm also known as DH. While both are public key methods, they are quite different.</p> <p>Mark: Oscar is right. You used the private key parameter, D, as part of the encryption step ("C = M^D mod N"). Like nearly all mistakes with cryptography, the impact is that your described system is totally insecure. I've already written articles (parts <a href="http://rdist.root.org/2007/05/01/rsa-public-keys-are-not-private/">1</a> and <a href="http://rdist.root.org/2007/05/03/rsa-public-keys-are-not-private-implementation/">2</a>) about how to calculate E and N given only two messages encrypted with D. In your system where D, N is the public key, the attacker can calculate E, P, and Q without seeing any encrypted messages.</p> <p>Take a moment to think about this. Inverting the sense of the E and D exponents in relation to encryption and decryption results in a system where your "private" key is no longer private! This is because of the asymmetry in selecting them, something which you used in your example for choosing the parameters.</p> <p>While I appreciate your enthusiasm for cryptography, the lack of attention to detail in your posts is troubling. In crypto, being exact with your terms and paranoid in your implementation really matters. Thanks.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121512&amp;1=default&amp;2=en&amp;3=" token="bFTUFLSWdVlBPCdddongo8Xl7G-cMN2xyt8LyoCtnJI"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.rootlabs.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Nate (not verified)</a> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121512">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121513" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228160866"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>You mentioned that for too small M, RSA is easy to break, and that your typical encoding function to turn text into M will add padding for this reason. However, since everything relating to E and D doesn't depend in any way on the way M is encoded, why can't you just use a modified encoding function that leaves out the padding, pick a plaintext to make an M that is small enough, and then do whatever you can do when M is small to break the key?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121513&amp;1=default&amp;2=en&amp;3=" token="nQOzSArGLvTi8YWfZ-EsWXk3VQAUi8OomTpuQ33SicE"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Scipio202 (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121513">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121514" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228167508"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Your detailed list had a small error: it's DÃE=1 mod Ï(N), not DxE=1 mod N.</p> <p>In fact, I'm a little surprised you didn't mention the core relation:</p> <p>aÏ(N) = 1 mod N</p> <p>(from Euler, as I recall).</p> <p>if you use the basic definition of D and E,</p> <p>D * E = 1 mod Ï(N) â D * E = n Ï(N) + 1</p> <p>then</p> <p>MD*E = Mn Ï(N) + 1 = M*Mn Ï(N) = M*(1n) = M.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121514&amp;1=default&amp;2=en&amp;3=" token="b2A3jIBwo7AqEQ3ARSBE5P_wwQW4LbcDB2Kdf3Qa0WU"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Anonymous (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121514">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121515" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228167908"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Also, on the totient of a product... you were a little too casual imho. It's not hard to explain.</p> <p>For the number from 1 to pq, you need to eliminate all multiples of 'p' (p, 2p, 3p, ..., qp) and all multiples of 'q' (q, 2q, 3q, ..., pq), and then restore the duplicate of 'pq'.</p> <p>That gives you pq - q - p + 1, or (p-1)(q-1) if you factor it.</p> <p>A really cool way of looking at it geometrically is to draw a grid of p by q cells. Color one edge -- that's the multiples of 'p'. Color an adjacent edge -- that's the multiples of 'q'. What's left is the smaller rectangle (p-1)(q-1).</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121515&amp;1=default&amp;2=en&amp;3=" token="7zFrcVkUKVBh5sAQkPOz2y9--hgB-NnzSsS86fejL4g"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Chris (not verified)</span> on 01 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121515">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121516" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228247698"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Very nice article. RSA really is quite astonishing in both its simplicity and its effectiveness. It always amazes me that although cryptography has been around for thousands of years, it was only 33 years ago that public-key crypto was conceptually invented and (in the classic Diffie-Hellman paper) and 32 years ago that RSA was designed. </p> <p>One minor point to clarify: You calaculated 573517 mod 1769 by calculating 573517 first (giving a 1426-digit number) and then reducing the result mod 1769. That's a big number before reduction mod 1769, and it can get a lot bigger in practice (where the p and q are not 2-digit primes but more like 200-digit primes). So we wouldn't actually calculate it that way, but rather use a repeated squaring technique where we start by computing 5732 mod 1769 (=1064), then 5734 mod 1769 (=10642 mod 1769 =1705), then 5738 mod 1769 (=17052 mod 1769 =558), and so on up to 573512 mod 1769, then use the results of these calculations to find 573517 mod 1769. This keeps the digit size of the numbers involved down and therefore is a lot faster and more memory-efficient. </p> <p>Of course you knew that, and were just keeping it simple for us, right? :)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121516&amp;1=default&amp;2=en&amp;3=" token="FaeXwKqd8gSlfMP3ShrFgy7O4yFGsiMJtKF5k3HZgXE"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://castingoutnines.wordpress.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Robert Talbert (not verified)</a> on 02 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121516">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121517" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228743064"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Ditto on Lloyd.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121517&amp;1=default&amp;2=en&amp;3=" token="6NnoAy0uhJxxbs1y4eyfVKg4jthqoVr6-boQxhPlN6c"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Sam Baskinger (not verified)</span> on 08 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121517">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121518" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1228985364"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I've said it before, but I'll say it again: my math is sorely lacking -- though I recognize number theory being used, mostly -- but I'm really enjoying these posts.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121518&amp;1=default&amp;2=en&amp;3=" token="gNAA5facAxaxDUtX2x9J44i8S_DcWwQ3SqZbtX72xiA"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://ahistoricality.blogspot.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Ahistoricality (not verified)</a> on 11 Dec 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121518">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2008/12/01/public-key-cryptography-using%23comment-form">Log in</a> to post comments</li></ul> Mon, 01 Dec 2008 08:29:57 +0000 goodmath 92655 at https://scienceblogs.com Asymmetric Cryptography: the Basic Idea of Public Key Cryptosystems https://scienceblogs.com/goodmath/2008/11/20/asymmetric-cryptography-the-ba <span>Asymmetric Cryptography: the Basic Idea of Public Key Cryptosystems</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p> I've been trying for a couple of weeks to put together a couple of interesting<br /> posts on the cryptographic modes of operation for confidentiality and integrity, and I<br /> just can't do it. I'm finding it boring to write about, and if it bores me to write it, I know there's no way that it's going to be engaging to readers!</p> <p> So, I'm going to move on. I've explained the basic idea of the message<br /> authentication code as an integrity check, and I've described one simple way of<br /> integrating it into a common mode of operation. If you're really interested in<br /> learning more, I recommend Bruce Schnier's book on cryptography, which has ton of<br /> material on modes of operation and protocols, how they work, and how they can<br /> fail.</p> <p> Meanwhile, I'm going to move on to something that doesn't bore me to write about,<br /> and therefore hopefully won't bore <em>you</em> to read about: asymmetric<br /> cryptography, also commonly referred to (although not entirely accurately) as public<br /> key cryptography.</p> <!--more--><p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-5aaf3053de6206e12c8582c1b1738ef7-symmetric-cipher.png" alt="i-5aaf3053de6206e12c8582c1b1738ef7-symmetric-cipher.png" /></p> <p> What we've looked at so far is symmetric cryptography. The basic idea of it is illustrated to the right. In a symmetric<br /> cryptosystem, you've got two parties who want to communicate, and they've got a<br /> <em>shared secret</em>. That shared secret is the key to the cryptosystem. Put in<br /> pseudo-mathematical syntax, the symmetric cryptosystem is a pair of functions, En and De, such that given a secret key S:</p> <ul> <li> Ciphertext = En(S, Plaintext)</li> <li> Plaintext = De(S, Ciphertext)</li> </ul> <p> We call it symmetric because both the sender and the receiver need the<br /> <em>same</em> information. Both of them can encrypt messages using the key; both can<br /> decrypt. There's no way to distinguish between the two on the basis of what<br /> information they have, or how they encrypt their messages.</p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-203eed0994e835d1347786d5aa80cd32-public-key.png" alt="i-203eed0994e835d1347786d5aa80cd32-public-key.png" /></p> <p> In an asymmetric system (as illustrated above) that's no longer true. Asymmetric systems use<br /> two keys, S<sub>1</sub> and S<sub>2</sub> (also called the private key and the public key) such that:</p> <ul> <li> Ciphertext<sub>S<sub>1</sub></sub> = En(S<sub>1</sub>, Plaintext)</li> <li> Plaintext = De(S<sub>2</sub>, Ciphertext<sub>S<sub>1</sub></sub>)</li> <li> Ciphertext<sub>S<sub>2</sub></sub> = En(S<sub>2</sub>, Plaintext)</li> <li> Plaintext = De(S<sub>1</sub>, Ciphertext<sub>S<sub>2</sub></sub>)</li> </ul> <p> In english, suppose you've got two people, Ann and Bob who want to communicate.<br /> They each have <em>their own</em> key. To send a message to Bob, Ann encrypts the<br /> message with <em>her</em> key. When Bob receives the message, he decrypts it<br /> <em>not</em> with the same key that Ann used to encrypt it, but with <em>his own</em><br /> key. When he wants to send a message back to Ann, he takes the same key that he used<br /> to <em>decrypt</em> the message from Ann, and uses it to <em>encrypt</em> a message<br /> <em>to</em> Ann.</p> <p> This leads to one of the basic terminological confusions. Reading that<br /> description: Bob's key decrypts messages <em>from</em> Ann, and encrypts messages<br /> <em>to</em> Ann has an element of symmetry to it. There is a very elegant symmetry to<br /> asymmetric encryption! But the terms asymmetric and symmetric in cryptography refer to<br /> the information that each of the parties uses in a cryptosystem. In a symmetric<br /> system, both parties have <em>exactly the same information</em>. In an asymmetric<br /> system, they've got <em>different</em> information.</p> <p> For the most part, the basic requirements of an asymmetric cryptosystem are<br /> very similar to the requirements of a symmetric one - you want to be able to compute the ciphertext easily given the encryption key and the plaintext; you want to be able to compute the plaintext easily given the ciphertext and the decryption key; you don't want to be able to compute the key given the ciphertext and the plaintext,<br /> and so on. But there's one <em>major</em> complication in asymmetric cryptosystems that creates an additional requirement: given the encryption key, it must be<br /> computationally infeasible to generate the decryption key.</p> <p> That last requirement kills the overwhelming majority of potential and proposed<br /> asymmetric systems. Having one of the keys in a pair means that you've effectively<br /> got access to an unlimited chosen plaintext attack: you've got the ability to generate<br /> the ciphertext of any plaintext, as many times as you want, and to use that to try<br /> to find the value of the key that will decrypt that text.</p> <p> The most common use of asymmetric cryptography is public key cryptography. One of the really fascinating things about it is that instead of trying to keep the keys private, you deliberate make one of the two keys widely available - you give it to <em>everyone</em>.</p> <p> The idea is that you take one key, which we call your private key, and you lock<br /> that away. No one but you should <em>ever</em> have access to your private key. The<br /> second key, called your public key, you give to everyone. You post it on public<br /> websites, you register it with key libraries, you send it to all of your friends, etc.<br /> Anyone who wants to be able to read encrypted messages from you needs to be able to<br /> get your public key.</p> <p> Now, when you want to send someone a message and prove it's from you, you encrypt<br /> it with your private key. Anyone can decrypt it - but <em>only you</em> could have<br /> encrypted it in a way that allows your public key to decrypt it.</p> <p> Similarly, when someone wants to send you an encrypted message, they encrypt it<br /> with your public key. Then <em>only you</em> can decrypt it.</p> <p> To set up a secure cryptographic channel with someone, you need to have<br /> <em>their</em> public key. So, suppose that we have Amy and Bill, who want to send<br /> secure messages to each other. What are the goals of the cryptosystem here? When Amy<br /> wants to send a message to Bill, she wants to make sure that <em>only Bill</em> can<br /> read it. When Bill gets a message from Amy, he wants to make sure that <em>only<br /> Amy</em> could have sent it.</p> <p> The way we can provide both of those is by having Amy take her message, and<br /> <em>first</em> encrypt it with <em>her</em> private key. Then she encrypts it with<br /> <em>Bill's</em> public key. The message has been encrypted twice: the first encryption<br /> pass guarantees that the message is from her (because no one else could have encrypted<br /> a message with her private key); the second encryption pass guarantees that no one but<br /> Bill can read it (because no one but Bill can decrypt a message with his private<br /> key).</p> <p> Bill does exactly the same thing when he wants to send a message to Amy. First he encrypts it with his private key, to show that it's really him who sent the message.<br /> And then he encrypts it with <em>Amy's</em> public key, which ensures that only Amy can read it.</p> <p> Towards the beginning of this message, I said that asymmetric cryptography is sometimes <em>incorrectly</em> called public key cryptography. The reason that I said that is because public key cryptography is really the combination of an asymmetric cryptosystem <em>together with</em> the infrastructure that allows the kind of scenario I described above, for Amy and Bill, to work. For it to work, Amy and Bill need to have a way of getting each other's public keys - and <em>being sure</em> that they are really getting the correct, valid public keys for each other. There's a very elegant cryptographic attack called a <em>man in the middle</em> attack, which relies on weaknesses in the public key infrastructure, not in the actual asymmetric cryptographic system used by the public key system, which I'll describe in a future post.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Thu, 11/20/2008 - 08:36</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2121462" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227211494"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Are you going to explore the different types of asymmetric encryption? I've always been interested in <a href="http://en.wikipedia.org/wiki/Elliptic_Curve_Cryptography">Elliptic Curve Cryptography</a>, but not due to any real understanding of it, just because NeXT had it when I was young, and NeXT was cool. :-)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121462&amp;1=default&amp;2=en&amp;3=" token="McqY5NGV09iknkBNxlxutah6M6w2fJiv3ZubJsW1jCE"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Robert Thille (not verified)</span> on 20 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121462">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121463" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227219625"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Years ago I had the idea of burning the private key into a processor chip during manufacture, in such a way that the processor could use the key but it was unavailable from the outside both physically and electronically. The manufacturing equipment that created the key pair would print the public key on the casing or otherwise publish it and then forget the private key completely.</p> <p>The chip would then be uniquely self-identifying; it can encode and decode with the private key, and no one else can. Nowadays you could build the chip into a cell phone, add some really good biometric hardware to make sure that only the owner can use it (say a DNA scanner), and you have a nearly unbreakable communications and identification system.</p> <p>We applied for a patent and got it; it was assigned to my employer at the time, Prime Computer. After awhile I left, Prime died, and the patent expired. <b>I really wish I knew if it was a good idea or not.</b></p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121463&amp;1=default&amp;2=en&amp;3=" token="xDRVtKNwx2mSlNp8d5iRWiAVQsRYGy172xTJ-IYO2t8"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Bob Munck (not verified)</span> on 20 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121463">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121464" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227234406"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>It was a good idea, but it was born too early. <a href="http://en.wikipedia.org/wiki/Trusted_Platform_Module">http://en.wikipedia.org/wiki/Trusted_Platform_Module</a></p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121464&amp;1=default&amp;2=en&amp;3=" token="sDWwVXPcIRmR7AuEAVj6GxB9R-3AAiHA2TkZPkJccDk"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Lassi Hippeläinen (not verified)</span> on 20 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121464">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121465" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227275851"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>What is wrong with using plain old "Alice and Bob"?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121465&amp;1=default&amp;2=en&amp;3=" token="mNge26xbAp2m1rS-7rosMML1J0BNumiDN1QlgWl7Jd8"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Tobias (not verified)</span> on 21 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121465">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2121466" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227276273"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Tobias:</p> <p>Nothing's wrong with Alice and Bob. It's just boring to always use the same names, so I went for a variation. :-)</p> <p>Robert:</p> <p>How far I get in asymmetric encryption will be determined by a combination of how long it takes before I get bored, and how well readers respond to it. If lots of people really want to know about elliptical-curve encryption, I'll probably wind up writing about it.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121466&amp;1=default&amp;2=en&amp;3=" token="l2JBolx7lVSDVGxzymJOE_gF5MJWRz9OQmTs9C-gLCA"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 21 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121466">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121467" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227277790"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I can't speak for Alice, but I'm sick and tired of just encrypting and decrypting the whole day long. Half the time it's just another string from <b>lorem ipsum</b>.</p> <p>I have to do this by moving rocks around in a desert, you know. It's not fun.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121467&amp;1=default&amp;2=en&amp;3=" token="3e_BlxM3xBRMau8WIZR--7r2wKHnCRf-ykWb-3Mf4jA"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Bob Munck (not verified)</span> on 21 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121467">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121468" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227283973"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Bob: It doesn't sound like such a great idea to me. Consider:</p> <p>1. The chip gets fried. Now no one, including yourself, can decrypt or sign any messages to/from you. Oops.</p> <p>2. The chip gets hit by a random alpha particle that flips one of the bits in the secret key. Similar to #1, except that you may not realize the problem for a while, and send out a number of critical messages signed with a random key.</p> <p>3. You really have to trust the manufacturer not to keep an extra copy of the secret key, don't you? In view of #1 and #2, this may even be what a lot of the customers want as a backup plan. But then you have to trust that the manufacturer doesn't make an extra copy of the key list for the NSA, or whoever. Given how easily most telecoms seem to have agreed to break the FISA wiretapping law at the government's request, how far do you think a manufacturer can be trusted? Now consider that a lot of chip manufacturing is currently taking place offshore...</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121468&amp;1=default&amp;2=en&amp;3=" token="EEgYHBbWuxY0z11--DKA-AGttTDGXeLXDD0wYuNXEyA"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Dave W. (not verified)</span> on 21 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121468">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121469" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227306284"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Lassi: Thanks. I hadn't looked at that effort for a couple of years. They talk about doing a hash of the OS code to verify that it hasn't been tampered with, something I had also in my patent. I really think that if the patent hadn't expired, they'd be subject to it.</p> <p>Dave W:</p> <p>#1: Losing the key is always something you have to worry about with encryption. You just have to keep the possibility in mind when you're deciding how to use it. For instance, I wouldn't use a key embedded in my cell phone for important, long-term documents, because I might lose the phone. I wouldn't store important documents in just one place, or encrypt them with just one key. I wouldn't store all my keys in the same place.</p> <p>#2: Checksums and other redundancy can reduce this problem to near-zero probability.</p> <p>#3: There's always going to be something or someone that <i>has to be trusted</i> somewhere in the implementation and use of a secure system. If the manufacturer can't be trusted, then you need an oversight agency that inspects and monitors their equipment. And you have to trust that agency.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121469&amp;1=default&amp;2=en&amp;3=" token="wbfFumURZ8qduKNbezCqiHdrKCPMCiidMG3zX3tHaKo"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Bob Munck (not verified)</span> on 21 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121469">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121470" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227426078"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>#1: Make spares.</p> <p>#3: Use a field-programmable gate array.</p> <p><i>...Bruce Schnier's book on cryptography...</i></p> <p>Which one?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121470&amp;1=default&amp;2=en&amp;3=" token="YuK3cgk9zmWAe5SyZzgaJ4FiZQRqvwcq6o14ErfYHrs"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://tualha.livejournal.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Tualha (not verified)</a> on 23 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121470">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121471" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227458303"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Wait a minute, Mark, you have this wrong.</p> <p>In public key cryptography you don't have Alice encrypting with her private key and Bob decrypting with his private key (as you write in the text and the picture suggests)!</p> <p>Alice encrypts with Bob's public key and sends the message to Bob, who can decrypt with his private key.</p> <p>Alice only uses her private key to sign the message (or better: a hash of the message) and Bob can use her public key to verify that she did the signing. </p> <p>At least as far as I have understand asymmetrical cryptography - how could decryption possible work with two private keys that have nothing to do with each other?!</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121471&amp;1=default&amp;2=en&amp;3=" token="_XYFMM7K-vVlIq9HLdp_zbpoAQB_Y7koxNgQ3gqetWE"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">WiseWoman (not verified)</span> on 23 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121471">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121472" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227525422"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>RE: WiseWoman (comment 10)<br /> &gt; In public key cryptography you don't have Alice<br /> &gt; encrypting with her private key and Bob decrypting<br /> &gt; with his private key.</p> <p>Mark has it right. </p> <p>You _DO_ have A encrypting with her private key, in order to "sign" the message. If it were signed with her public key, it wouldn't be secure (and B would need A's private key). If it were signed with B's public key, it wouldn't be verifying A's identity. And we hope that A doesn't have B's private key, so that leaves us with only one option.</p> <p>And you _DO_ have B decrypting with his private key, as that's the heart of the security. If it were decryptable with his public key, anyone could do it. If it were decryptable with A's public key, it would defeat the purpose. And if it were decryptable with A's private key, B would be out of luck.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121472&amp;1=default&amp;2=en&amp;3=" token="tWcANmw25j4jNJ9GVPJ_7jFtsui-z_8_O_cgAC-4ksQ"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Michael (not verified)</span> on 24 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121472">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121473" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227538509"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>No - the private keys have no connection! Alice cannot encrypt with her private key and Bob decrypt with his private key, that's nonsense. </p> <p>We have to differentiate signing and encrypting (two different things, that need to be done with two different keys, or there are attacks that can succeed):</p> <p>Alice signs the message to Bob with her private key, and encrypts with Bob's public key.</p> <p>Bob decrypts with his private key, and verifies the signature with Alice's public key. </p> <p>Normally, however, Alice prepares a hash of her message, signs that, and then encrypts the whole mess, to keep from encrypting twice. Asymmetric cryptography can be 1000 times slower than symmetric.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121473&amp;1=default&amp;2=en&amp;3=" token="O-_da5P7CGKJwYvKHCBg3TTMIj0iHXrt2odbkts_w7I"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">WiseWoman (not verified)</span> on 24 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121473">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121474" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1227547435"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>@WiseWoman</p> <p>You and Michael are saying the same things really, he's just taking it for granted that the order of actions is:</p> <p>1) A encrypts with A's Private Key.<br /> 2) A encrypts with B's Public Key.<br /> 3) B decrypts with B's Private Key.<br /> 4) B decrypts with A's Public Key.</p> <p>As you pointed out, 1 and 4 are usually described as signing (and it's convenient to just hash and sign said hash, as AC systems are slow). There is no real mathematical difference between signing and "encrypting", it's simply a different way of using the cryptosystem (at least with RSA, which is the algorithm I am most familiar with).</p> <p>Since WiseWoman touched on the speed of Asymmetric Cryptography, another common practice is only using an Asymmetric Cryptography algorithm to encrypt a Symmetric Key, and to encrypt the payload with a Symmetric algorithm (AES/Twofish/3DES).</p> <p>Also, +1 vote for a posting on Elliptic Curve Cryptography.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121474&amp;1=default&amp;2=en&amp;3=" token="lYJN3UT8RCfTXehJYPsPVKz0BuBeo2EANmGtlQV2A5g"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Paul (not verified)</span> on 24 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121474">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2008/11/20/asymmetric-cryptography-the-ba%23comment-form">Log in</a> to post comments</li></ul> Thu, 20 Nov 2008 13:36:25 +0000 goodmath 92653 at https://scienceblogs.com How Not to Do Message Integrity, featuring CBC-MAC https://scienceblogs.com/goodmath/2008/10/24/how-not-to-do-message-integrit <span>How Not to Do Message Integrity, featuring CBC-MAC</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p> In my <a href="http://scienceblogs.com/goodmath/2008/10/cryptographic_integrity_using.php">last cryptography post</a>, I wrote about using message authentication codes<br /> (MACs) as a way of guaranteeing message integrity. To review briefly, most ciphers<br /> are designed to provide message confidentiality - which means that no one but the<br /> sender and the intended receiver can see the plain-text of the message. But<br /> ciphers that provide confidentiality don't necessarily make any guarantees that<br /> the message received is exactly the message that was sent. There are a good number<br /> of cryptographic attacks that work by altering the message in transit, and<br /> depending on the cipher, that can result in a variety of undesirable<br /> results.</p> <p> For example, if you use DES encryption with the ECB mode of operation,<br /> you can insert new blocks anywhere in a message that you want. By using<br /> a replay attack (where you take encrypted blocks from other messages using<br /> the same encryption, and resend them), an attacker can alter your messages, and<br /> you won't be able to detect it.</p> <p> So in addition to just confidentiality, we need to provide integrity. What does integrity really mean? Basically, it expands the definition of the<br /> decryption function. Written as a function signature, confidential message<br /> decryption is a function <code>decrypt : ciphertext × key → plaintext</code>. With message integrity, we add the<br /> option that decrypt can return a result saying that the message is invalid: <code>decrypt<sub>integ</sub> : ciphertext × key → (plaintext | REJECT)</code>. </p> <!--more--><p> In the last post, I explained the basic concept behind integrity schemes: you add an addition chunk of data to the message, which summarizes the message; any change to the message will (with a very high degree of probability) result in<br /> a change in the authentication code; so if the message is altered, that change<br /> will be detected, because the authentication code will not match the rest<br /> of the message.</p> <p> The idea of the message authentication code seems quite simple. We know lots<br /> of pseudo-random functions that can do a good job as MAC functions. But like<br /> so many things in cryptography, the fact that the concept is simple doesn't<br /> mean that the actual application of that concept is simple: it's incredibly<br /> easy to get it disastrously wrong, even when all of the building blocks are right.</p> <p> For example, let's look at a very simple (and very weak) integrity<br /> system, called CBC-MAC.</p> <p> In CBC-MAC, you compute an authentication code by running a your<br /> block cipher on the message with an initialization vector set<br /> to 0. The output for encrypting the last block is your MAC.</p> <p> The reason that this works is fairly simple - CBC keeps pushing the<br /> result from the previous encryption step through to the next one - so<br /> the output from the final block conceptually includes information<br /> from all of the other blocks. So you've got an authentication code<br /> whose security is, roughly, equivalent to the security of the block<br /> cipher used in CBC mode.</p> <p> CBC-MAC isn't a bad mode of operation. It's got serious flaws - the biggest<br /> one is that there are a number of attacks against it if it's used for<br /> variable length messages. (And you can't fix it just by adding a message<br /> length indicator to the message, it's deeper than that.) But CBC is<br /> a pretty good integrity mode for fixed-length messages, and there's a widely<br /> used variant, called CMAC, which works for variable length messages.</p> <p> So how can this go wrong?</p> <p> What do you use as the password to the MAC computation? CBC is<br /> a secure cryptographic mode, so why not just use the same password? Lots<br /> of novices (and even some not-no-novice folks!) have implemented CBC-MAC<br /> where the integrity and confidentiality modes used the same key. If you<br /> compute the MAC using the same key as the message, then you're open to<br /> an attack which completely voids the integrity guarantee!</p> <p> Imagine a message M, which is divided into n blocks: (M<sub>1</sub>, ..., M<sub>n</sub>). For convenience, we'll treat the IV as if it were ciphertext block 0. Tuen using CBC with a key K, M encrypts to ciphertext blocks<br /> (C<sub>1</sub>, ..., C<sub>K</sub>), where C_i=Encrypt(M<sub>i</sub> ⊕ C<sub>i-1</sub>, K), plus a CBC-MAC integrity block. If you look<br /> at the CBC block, if it's using the same key as the main encryption,<br /> then the value of the MAC is the result of computing<br /> Encrypt(M<sub>n</sub> ⊕C<sub>n-1</sub>, k). That value<br /> is <em>exactly</em> the same as C<sub>N</sub>! So it's <em>trivial</em><br /> to fake the MAC. If you use CBC-MAC with the same encryption key as<br /> you used to encrypt the message, you're wasting your time: you might as well<br /> not bother with the MAC at all, because you've got no integrity guarantee.</p> <p> But that's an amazingly common mistake. A huge number of implementations<br /> of supposedly secure cryptosystems that claim to guarantee integrity have<br /> actually used CBC-MAC with one key.</p> <p> I mentioned above that CBC-MAC is only safe for fixed-length messages. The reason for that is closely related to the trick I described above. Basically, the nature of CBC ultimately means that given a MAC value M, it's not hard to generate a string to append to a message which will result in it having the desired<br /> MAC. Suppose we know that the message M will generate the mac T<sub>M</sub>,<br /> and we know that the block we want to replace the message with, N has<br /> the MAC T<sub>N</sub>. Then we can easily generate a string N', such that<br /> appending MAC(M,N) = MAC(N). All we do is XOR the first block of N<br /> with T<sub>M</sub>, and add it to the message. The new message<br /> is is (M<sub>1</sub>,...,M<sub>n</sub>,(N<sub>1</sub>⊕T<sub>N</sub>),<br /> N<sub>2</sub>,...,N<sub>n</sub>) - that is, we can remove the MAC from the<br /> first message, use it to glue the two messages together, and tack T<sub>N</sub> on to the message as the MAC. T<sub>N</sub>, the MAC computed for T alone, will<br /> be the MAC for the combined message. </p> <p> It's easy to do that if we're allowed to change the length of the message. If the receiver doesn't know how long the message is going to be, then they can't<br /> count on its integrity using CBC-MAC. </p> <p> Next time, I'll look at a variation of CBC-MAC that provides integrity<br /> for variable-length messages using 2 keys - one for confidentiality, and<br /> one for integrity. Then I'll go on to a two-pass single-key mode of operation<br /> that provides both confidentiality and integrity.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Fri, 10/24/2008 - 08:21</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <div class="field field--name-field-blog-categories field--type-entity-reference field--label-inline"> <div class="field--label">Categories</div> <div class="field--items"> <div class="field--item"><a href="/channel/free-thought" hreflang="en">Free Thought</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2121255" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1225186491"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Hey Mark,</p> <p>Just a suggestion, but you should really go back through all these posts and tag them with "Cryptography" or something so that they're easy to dig up (assuming SB supports tagging, of course).</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121255&amp;1=default&amp;2=en&amp;3=" token="A6cggbwGGqdlhyewg1-h5XqeNtbT1j0cAhU4kKi48gY"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Nobody Important (not verified)</span> on 28 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121255">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2008/10/24/how-not-to-do-message-integrit%23comment-form">Log in</a> to post comments</li></ul> Fri, 24 Oct 2008 12:21:52 +0000 goodmath 92644 at https://scienceblogs.com Differential Cryptanalysis https://scienceblogs.com/goodmath/2008/10/02/differential-cryptanalysis <span>Differential Cryptanalysis</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p> Now, we're finally reaching the point where the block-cipher stuff gets really fun: block cryptanalysis. </p> <p> As I've explained before, the key properties of a really good<br /> encryption system are:</p> <ol> <li> It's easy to compute the ciphertext given the plaintext and the key;</li> <li> It's easy to compute the plaintext given the ciphertext and the key;</li> <li> It's hard to compute the plaintext given the ciphertext<br /> but not the key;</li> <li> It's hard to compute the key. </li></ol> <p> That last property is actually a bit of a weasel. There are really a wide variety of attacks that try to crack an encryption<br /> system - meaning, basically, to discover the key. What makes that<br /> statement of the property so weasely is that it omits the information available to the person trying to crack it. In the first three properties, I clearly stated what information you had available to produce a result. In the last, I didn't.</p> <p> There's a reason that I weaseled that. Partly, it's because a correct statement of it would be ridiculously long and incomprehensible; and partly because it's often <em>deliberately</em> set up differently for different encryption systems. You can design systems that are extremely strong against certain attacks, but not so good against others. There's no universally ideal encryption system: it's always a matter of tradeoffs, where you can handle some scenarios better than others.</p> <p> Today we're going to look at one particularly fascinating attack that's used against block ciphers. It's called <em>differential cryptanalysis</em>. </p> <!--more--><p> So what is differential cryptanalysis? It's a technique that looks at how making specific changes in the plaintext input to the cipher produce changes in the output from that cipher. The basic idea, in its simplest form, is that you're able to select a collection of plaintexts, and encrypt them. Then based on the results of doing<br /> that, you try to compute the key.</p> <p> Differential cryptanalysis is a form of the basic <em>chosen plaintext attack</em>. What makes it a differential attack is that you use related families of plaintext. That is, you've got a family of texts T<sub>0</sub>, T<sub>1</sub>, T<sub>2</sub>, ..., where each text T<sub>i</sub> is equal to T<sub>0</sub> plus some small difference. For many differential attacks, that small difference is <em>one bit</em>.</p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-db6f62f25c630f5c9daa966abb93fb3d-differential.png" alt="i-db6f62f25c630f5c9daa966abb93fb3d-differential.png" /></p> <p> How can you crack a cipher this way? To start, we assume that you know what cipher we're using. For example, you know that we're using DES with a 56 bit key. So you take your initial plaintext,<br /> T<sub>0</sub>, and you encrypt it, giving you a ciphertext, C<sub>0</sub>. Then you change one bit of T<sub>0</sub>, giving you T<sub>1</sub>, and you encrypt that, giving you C<sub>1</sub>.</p> <p> C<sub>1</sub> differs from C<sub>0</sub> in some number of bits. Now, you've reduced the problem from "What key could produce the plaintext/ciphertext pair (T<sub>0</sub>, C<sub>0</sub>)?" to<br /> "What set of keys could produce the <em>variation</em> C<sub>0</sub> to C<sub>1</sub> by changing one bit of T<sub>0</sub>?". I've drawn an outline of this process in a diagram to the right.</p> <p> This reduction can be dramatic. For example, in one of the early proposal rivals to DES, caled FEAL, it turned out that you could crack it with a set of 8 one-block (plaintext,ciphertext) pairs. The problem is reduced from a blind search of a search-space of 2<sup>64</sup> possible keys to utter triviality by a set of 8 chosen plaintexts!</p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-0c481bf603e6852d0a9627214582ffd2-extract-diff.png" alt="i-0c481bf603e6852d0a9627214582ffd2-extract-diff.png" /></p> <p> The subtlety of this attack is in how you choose the<br /> set of plaintexts to use. For a typical Feistel network block<br /> cipher, you need to do a very delicate analysis of the S-blocks. You trace out the possible paths of each bit through the network,<br /> and using that, you can work out a set of <em>probable</em> differences - that is, bit patterns that are likely to be able to produce an <em>informative</em> difference in the ciphertexts. These probable patterns are called <em>differential characteristics</em>. Once you've worked out a large enough set of probably characteristics, you can use them to assemble a set of informative plaintexts that should provide you with what you need to determine the key.</p> <p> It can get even more subtle than that. Since you <em>know</em> the algorithm, you can isolate a single stage of the cipher (as illustrated to the right), and throw bit-blocks at it in differential style. From that, you can work out the set of subkeys that could produce the observed differential result for that stage. If you do that for all of the stages, you'll get a set of keys for each stage. Figure out which subkeys keys from each stage are mutually compatible, and then combine them, and you get a very small (usually one) key that could produce valid subkeys for each stage. </p> <p> You can even repeat this process on multiple levels. If you've got a block cipher like DES, and you know the structure, you can do the differential analysis of a single stage by decomposing it into its individual S-boxes. Analyze each S-box, and come up with a set of potential subkey-fragments, and then combine those to create a set of potential subkeys for the stage. Then combine the stage results.</p> <p> Differential analysis also reveals something fascinating about<br /> DES. Most texts attribute the invention of this attack to Shamir in<br /> the late 1980s, when he published a set of papers describing<br /> differential attacks. But when you analyze DES, you find that it's<br /> <em>not</em> very susceptible to differential attacks! In fact, it<br /> takes 2<sup>55</sup> chosen plaintexts to crack 56-bit DES - so differential analysis is effectively no better than simple brute force. But if you make some very minor changes to S-boxes in the algorithm, it becomes nearly as susceptible as FEAL. </p> <p> So how is DES so resistant to an attack that wasn't discovered<br /> until almost 15 years after DES was first published? It turns out<br /> that the IBM team that designed DES had figured out differential<br /> attacks before they designed DES in 1974. They knew about that attack and its properties, and specifically designed DES to <em>not</em> be susceptible to it. But at the time, they were working with the NSA to produce an official standard encryption system, and the NSA requested that they <em>not</em> tell anyone about the attack they'd discovered.</p> <p> This, naturally, has driven a lot of interesting discussion. Why did the NSA want to keep that secret? They claim that they did it because revealing the differential attack and how DES protected against it would "weaken the competitive advantage that the US enjoyed over other countries in the field of cryptography". But<br /> a lot of people (to be honest including me) believe that the real<br /> advantage they wanted to maintain was the ability of the US<br /> intelligence community to crack encryption systems used by other countries.</p> <p> One last comment, and I'll wrap up this post. Things like differential cryptanalysis are one of the <em>many</em> reasons not to roll your own cryptographic cipher. Some of the best cryptographers in the world - people who spent all of their time working on designing secure cryptosystems - designed systems that were <em>easy</em> to break using this technique. If you don't know about every technique that could be used against your system, and you haven't considered how your system will behave under probing by those techniques, then you have close to no chance of designing something unbreakable. Over time, so many cryptosystems have failed, because someone didn't notice one tiny little problem, or didn't think about one obscure technique, or didn't notice one tiny little bug in their implementation. Those things are fatal to a good cryptosystem. Many of us who are math geeks have tried designing a cipher for the heck of it; how many of us who've done it are able to say that we're sure that it couldn't be cracked in five minutes of differential analysis? I'd wager that the answer is zero.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Thu, 10/02/2008 - 09:07</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2121028" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222975532"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>It is an interesting history of what the NSA wanted to keep secret. I remember when George Davida at Wisconsin-Milwaukee had a paper requested to be withdrawn about DES S boxes in the late 80's. It seemed quite obscure.</p> <p>The theory (i.e. WAG's and speculation) back then was that DES had built in weaknesses from the NSA and it was fascinating when Don Coppersmaith et al started to talk about their design process and the fact that the NSA was fine with a strong version.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121028&amp;1=default&amp;2=en&amp;3=" token="zdXGN3Y25DpP6tWkck4iBczzOIEOxFdVJe3V4bgyOpE"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Markk (not verified)</span> on 02 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121028">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121029" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223000969"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>"In fact, it takes 2^55 chosen plaintexts to crack 56-bit DES - so differential analysis is effectively no better than simple brute force."</p> <p>I thought the differential attack was the reason why NSA recommended cutting the key length to 56 bits. Anything more was an overkill.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121029&amp;1=default&amp;2=en&amp;3=" token="E-qkjGzjSqMaeFT-Tk_GXuOb6FzGm61duMskL4sYlHU"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Lassi Hippeläinen (not verified)</span> on 02 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121029">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121030" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223015400"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I don't think that differential cryptanalysis is a type of chosen plaintext attack.</p> <p>Chosen plaintext attacks require access to an oracle. You must be able to submit your chosen plaintexts to the encryptor and examine (compare) the ciphertexts. In other words, you must be able to interrogate the oracle.</p> <p>However, if you have *only* ciphertexts, you still may very well carry out differential cryptanalysis. Perhaps it won't get you the key, but you possibly will get near to the plaintexts.</p> <p>Suppose you have a stream cipher, or a block cipher in OFB or CTR mode. The encrypting party is uneducated enough to encrypt two separate English (or other known-protocol) messages using the same IV. (There are examples for this in the industry.) Since both in OFB and CTR the ciphertext is produced by XOR-ing the plaintext with the plaintext-independent cipherblocks, by XOR-ing two ciphertexts, one XOR-s out the cipherblocks and ends up with the XOR of two English messages. Cryptographers break *that* in their sleep (letter and word frequency etc). This attack, although trivial, *is* differential cryptanalysis, because it's based on the difference between ciphertexts. However, no encryption (chosen plaintext) takes place in this attack.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121030&amp;1=default&amp;2=en&amp;3=" token="3t8iBTST6NNDqIJ3tdcrPnABt7WU_IVjCGRP3UeBoUM"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">amateur (not verified)</span> on 03 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121030">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121031" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223034563"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Mark, it's usually not necessary to attack multiple rounds of a cipher. One round will suffice. For DES, if you find one round key (48 bits selected from the 56 key bits), you just brute-force the remaining 16 bits.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121031&amp;1=default&amp;2=en&amp;3=" token="vVHVZlJjDgyuacC9uEDJ-sS8Ns29IyEl0OKTtu_l-yI"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.rootlabs.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Nate (not verified)</a> on 03 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121031">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121032" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223036179"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>hmm... makes my Caesar cipher encryption look pretty weak. lol. Not that i use it for anything.</p> <p>sean</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121032&amp;1=default&amp;2=en&amp;3=" token="-A1UvqEdoqnuN-nANFuZddeWlcdUYbkocFU3BjUqo0U"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.seanbennett.com.au" lang="" typeof="schema:Person" property="schema:name" datatype="">sean (not verified)</a> on 03 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121032">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2121033" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223036355"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Nate:</p> <p>My understanding (admittedly limited) is that for some ciphers, you can crack the key much faster by analyzing multiple phases and intersecting the compatible results - I don't have my texts handy (they're at home, and I'm at work), but I recall one example (FEAT-128 rings a bell?) where you could reduce the amount of brute-force work by more than an order of magnitude - from brute-force testing 64,000 keys to brute-force testing 1000 keys. </p> <p>It's another of those tradeoffs: is it faster to do the differential analysis on another round of the cipher, or to do a brute force using what you know?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121033&amp;1=default&amp;2=en&amp;3=" token="R5q6C0l8Xle5rsZnm3tL7NGuFhtXX6Rq_8x-GndwW2I"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 03 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121033">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121034" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223361839"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>There seem to be two contradictory stories about how DES became resistant to differential cryptanalysis.</p> <p>Once upon a time, what "everyone knew" was: IBM sent their design to the NSA, who sent it back with mysteriously altered S-boxes, and it later transpired that what NSA had done was to make the design resistant to differential cryptanalysis. (Alan Konheim: "We sent the S-boxes off to Washington. They came back and were all different.")</p> <p>But now the common wisdom is apparently that really IBM knew about differential cryptanalysis too (they called it the "tickle attack") and the NSA didn't change anything. (Walter Tuchman: "We developed the DES algorithm entirely within IBM using IBMers. The NSA did not dictate a single wire!")</p> <p>I don't see how these can both be correct, or even both be good approximations to the truth; either the S-boxes went off to Washington and came back all different, or they didn't.</p> <p>The "new" story seems to be a little better supported by evidence, but it's pretty thin.</p> <p>Anyone know the real history here? (The various accounts on the web seem unhelpful; they quote one story, or the other, or quote both but notice no tension between them. Perhaps I've missed one that resolves the issue.)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121034&amp;1=default&amp;2=en&amp;3=" token="a5UuZz4s8Gjg_LnLH2DonFpiUAYNuKQ9W5ee55Dp3cY"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.mccaughan.org.uk/g/" lang="" typeof="schema:Person" property="schema:name" datatype="">g (not verified)</a> on 07 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121034">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121035" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223468439"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Great thanks for dicrovering the topic.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121035&amp;1=default&amp;2=en&amp;3=" token="u1krOT6-aM854vYTJx4R8ioZNuiQb4ihPnWN4s3Qha0"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://nahtigal.wordpress.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Mykola (not verified)</a> on 08 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121035">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2121036" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1223829707"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I'm also confused on the history of the DES s-boxes, for the exact same reasons "g" cited just above.</p> <p>Anyone know of any good sources on this? We seem to have two mutually exclusive stories being circulated.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2121036&amp;1=default&amp;2=en&amp;3=" token="Ds-cXpZcCU_8f_XoKGnZNCwYfQIljOo0lv-Rm54MuF4"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://bradconte.com" lang="" typeof="schema:Person" property="schema:name" datatype="">B-Con (not verified)</a> on 12 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2121036">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2008/10/02/differential-cryptanalysis%23comment-form">Log in</a> to post comments</li></ul> Thu, 02 Oct 2008 13:07:13 +0000 goodmath 92636 at https://scienceblogs.com Screwing Up Modes of Operation: Counter done right https://scienceblogs.com/goodmath/2008/09/15/screwing-up-modes-of-operation <span>Screwing Up Modes of Operation: Counter done right</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p> So, as it turned out, I made a major screwup in my post earlier today on modes of operation. Rather than just edit the post, I'm adding a new post with the corrected description of the counter mode, and a bit of explanation. I figure that if I screw up badly, it's more honest to make a second post explaining the error than it is to just correct it and pretend that all was well.</p> <p> What I got wrong was the order in which things happen. In the counter mode,<br /> you encrypt the counter using the key, and <em>then</em> you exclusive-or the result of that with the plaintext to get the ciphertext. The plaintext <em>never</em> enters the block cipher; the block cipher just produces a complex and random looking block of bits which are then used to obscure a block of plaintext.</p> <p> What I said in the original post was that you exclusive or the plaintext with the counter, and then run it through the block cipher. In my screwed up version, the plaintext is being put through the block cipher mechanism; in the correct version, it's not. Below is some of my psuedo-python showing my screwed up CTR mode,<br /> and the (hopefully) correct CTR mode. I've also included a diagram of the correct CTR mode.</p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-6084f5650bfefa760ad928e645db18ba-ctr.png" alt="i-6084f5650bfefa760ad928e645db18ba-ctr.png" /></p> <pre> def EncryptWithMarksScrewedUpCTR(blocks, ctr, key): for b in blocks: encrypted = encrypt(key, b ^ ctr) ctr = ctr + 1 output(encrypted) def EncryptWithRealCTR(blocks, ctr, key): for b in blocks: e_ctr = encrypt(key, ctr) encrypted = e_ctr ^ b output(encrypted) ctr = ctr + 1 </pre><p> This can make a big difference in the effectiveness of the cipher against various attacks. I'm not going to get into details now, but over the course of future posts, I hope that I'll be able to make it clear why changes like this can have huge impacts on<br /> the security and quality of a cipher.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Mon, 09/15/2008 - 13:23</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2120834" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221513366"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>You still need to include an IV in with the counter. If you use the same counter again for a different stream, it is easy to do attacks by just xoring the two streams together.</p> <p>Counter mode basically turns a block cypher into a stream cypher. With that, it is important to either never reuse the counter, or never reuse the key. That's commonly done by either xoring the counter with an IV the size of the block, or setting say the upper half of the block to the IV, and the lower half to the counter.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120834&amp;1=default&amp;2=en&amp;3=" token="KXWP_-qTqRK0k6dSH4DoGllJ70SJ3wy9_u3nqeckGV0"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">David Brown (not verified)</span> on 15 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120834">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120835" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221734338"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Thanks for updating your post. David Brown is right -- without an IV, you're going to generate the same keystream on multiple messages. This means CipherText1 XOR CipherText2 = PlainText1 XOR PlainText2, revealing a lot of information about your plaintext. Are you going to revise this again?</p> <p>In my last comments, I suggested that you recommend your readers use standard protocols like SSL or password hashing algorithms like FreeBSD-MD5 or OpenBSD-Blowfish. The danger is that they'll read your posts, assume they understand enough, and then implement their own versions, recapitulating all the security flaws we've learned about in the research world. As evidence of this, consider that if you fix your post to add the IV, that will be the second important flaw you've accidentally included in describing only a single mode of operation (counter mode). Wouldn't a disclaimer help emphasize how fragile this stuff is?</p> <p>I make my living finding and fixing flaws in embedded and systems software, especially as they pertain to crypto. So while I appreciate increasing the supply of work, it would be good to issue a warning instead. :)</p> <p>Consider fiascos like this <a href="http://www.matasano.com/log/958/enough-with-the-rainbow-tables-what-you-need-to-know-about-secure-password-schemes/">"rainbow tables" set of comments</a>, where web programmers attempt to reinvent password hashing rather than just reusing the FreeBSD or OpenBSD approaches. There are 105 comments to a very informative post that warns of the dangers of trying to reinvent this, and nearly all the commenters are doing exactly that!</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120835&amp;1=default&amp;2=en&amp;3=" token="MjcwUyD2YYCZbmxN-U5NcgZltsMXJQyOhkPPW-WxyhA"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.rootlabs.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Nate (not verified)</a> on 18 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120835">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120836" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222080748"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>For those of us who are learning, what is an IV?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120836&amp;1=default&amp;2=en&amp;3=" token="6qUp6w90IJJDOKxdQbu3UN0Gs17xyYN6pWijWKDdjVQ"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://lovehateubuntu.blogspot.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Rob Britton (not verified)</a> on 22 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120836">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120837" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222080882"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Ah, oops, hadn't read that far in the older post. Sorry!</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120837&amp;1=default&amp;2=en&amp;3=" token="WCMyqigDorLtMgR-_FYMWEph2k0EgwBnZoiS-a3wN7g"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://lovehateubuntu.blogspot.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Rob Britton (not verified)</a> on 22 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120837">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2120838" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222081901"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Rob:</p> <p>The "IV" is an initialization vector. It's a collection of random bits. </p> <p>The idea is that you want to "prime the pump"; that is, you don't want an adversary to ever see a simple sequence of stuff that lets them infer much about what you're doing.</p> <p>If you use a simple counter, then effectively, you've got a message encoded with DES(1)xor(plaintext),DES(2)xor(plaintext), etc. Every message will look roughly like that. If your adversary somehow figures out what you're doing, then he can just do the same DES(1), DES(2), etc., computation, and have an easy crack to your key.</p> <p>The IV breaks that. An adversary trying to break your encryption can't just try encrypting "1,2,3" with different passwords, and see if he gets anything that makes sense out of your message. He needs to also guess the IV.</p> <p>As a computer scientist, I tend to have a somewhat odd way of looking at things, which has annoyed a few cryptographers who read this blog. My understanding of counter mode says<br /> that the counter is a function F, where you use F(N) as an input value for block N. </p> <p>In terms of functional representations of things, which is the way I think of them, the use of an IV is equivalent to a particular counter function F. </p> <p>In the diagram of the mode above, you can see that I use "counter(1)", "counter(2)" as inputs to the block cipher. counter(n) could be (n xor IV) if you wanted; it works out as equivalent.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120838&amp;1=default&amp;2=en&amp;3=" token="MzxjzabHohLIDsg1C-hWYDuFDt6k3p4ZQxaag8OwkPs"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 22 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120838">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120839" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222360755"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I would just like to say that I write software for a living, I have a computer science degree from a decent school, I read this blog and find it to be engaging and educational (especially these cryptography-related posts), and I would never roll my own security code. I'd like to think that most people interested in cryptography and security enough to read these blog posts have an appreciation for how hard real security is. I've been interested in this stuff for a while now and I've heard that message over and over again--the security community does an excellent job of communicating that point.</p> <p>This blog provides some of the most lucid descriptions of various concepts that I've encountered. I'm learning and <em>I love that</em>.</p> <p>I'm sure there are other readers like me. Keep up the good work.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120839&amp;1=default&amp;2=en&amp;3=" token="Pat9mHOoBa3iyUIj2NCtDAuzvWcPSWobpBv6AAvhfo4"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">frankzappa (not verified)</span> on 25 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120839">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120840" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222980285"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>You indeed have an IV. However, the counter and the IV need not be mutually exclusive. Since often the first thing done is to XOR the IV against the counter, you can actually just choose an IV and just start your counter from that. It's essentially the same thing, though, so if you expand your definition of a "counter", your notation works.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120840&amp;1=default&amp;2=en&amp;3=" token="uumrlDQTRgtHSwxerr7dC4maiGJgY9xvD9bS0OZkqYg"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://bradconte.com" lang="" typeof="schema:Person" property="schema:name" datatype="">B-Con (not verified)</a> on 02 Oct 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120840">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120841" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1226503364"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Hi Mark. Sorry for the late comment, I just revisited this thread. Even with your revised comment, the reason you give is incorrect.</p> <blockquote><p> The IV breaks that. An adversary trying to break your encryption can't just try encrypting "1,2,3" with different passwords, and see if he gets anything that makes sense out of your message. He needs to also guess the IV. </p></blockquote> <p>What you're saying is that the IV in counter mode prevents a known plaintext attack. That is, you're saying that knowing that the ciphertext is "DES-Encrypt(counter, key) XOR plaintext" gives the attacker a crib, since they can brute-force the key in the forward direction and see if the resultant plaintext makes sense.</p> <p>This is not the reason for using an IV. The average effort required to perform this attack on DES, assuming the key is randomly chosen, is 2^63. For AES-128, it is 2^127. This is the same effort required to brute-force a single block encrypted with the cipher in ECB mode. Any cipher that is vulnerable to a known plaintext attack is already broken and should not be used. Neither DES nor AES is subject to a known plaintext attack.</p> <p>The actual reason the IV should be different each time the counter is restarted is because without it, you produce the same keystream multiple times. This is fatal for a stream cipher since the keystream itself can be extracted for any portions of known plaintext.</p> <p>Say you're using this for packet encryption and you don't have an IV. Once I see the encrypted Packet1 and know some header fields, I know the keystream at those points. Now I can decrypt <i>any</i> packet you send by just XORing those same points with the keystream.</p> <p>Since an IV makes the keystream different (even though the counter is restarted), it would prevent this attack.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120841&amp;1=default&amp;2=en&amp;3=" token="h6epQbXhzvvu7F6MtLNZo4WgJGd-DjHWrXDGdWe0inw"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.rootlabs.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Nate (not verified)</a> on 12 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120841">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120842" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1226503576"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I forgot one more thing. Your assumption that the IV helps prevent a known plaintext attack is based on the IV being secret. An IV is never secret, and any protocol that claims it should be immediately raises red flags.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120842&amp;1=default&amp;2=en&amp;3=" token="cklw4ElLQoTQ44JRfF5sP8VLj4tsIcNckWPmA0WEfek"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.rootlabs.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Nate (not verified)</a> on 12 Nov 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120842">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2008/09/15/screwing-up-modes-of-operation%23comment-form">Log in</a> to post comments</li></ul> Mon, 15 Sep 2008 17:23:40 +0000 goodmath 92631 at https://scienceblogs.com Modes of Operation in Block Cryptography https://scienceblogs.com/goodmath/2008/09/15/modes-of-operation-in-block-cr <span>Modes of Operation in Block Cryptography</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p> Sorry for the slow pace of the blog lately. I've been sick with a horrible<br /> sinus infection for the last month, and I've also been particularly busy with work, which have left me with neither the time nor the energy to do the research necessary to put together a decent blog post. After seeing an ENT a couple of days ago, I'm on a batch of new antibiotics plus some steroids, and together, those <em>should</em> knock the infection out.</p> <p> With that out of the way: we're going to look at how to get from simple <a href="http://scienceblogs.com/goodmath/2008/09/introduction_to_block_ciphers.php">block ciphers</a> to stream ciphers, using the oh-so-imaginatively named <em>modes of operation</em>!</p> <p> As a quick refresher, block encryption specifies an encryption scheme that operates on fixed-size blocks of bits. In the case of <a href="http://scienceblogs.com/goodmath/2008/09/des_encryption_part_1_encrypti.php">DES</a>, that's 64 bits. In the<br /> real world, that's not terribly useful on its own. What we want is something called<br /> a <em>stream cipher</em>: a cipher that's usable for messages with arbitrary lengths. The way to get from a block cipher to a stream cipher is by defining<br /> some mechanism for taking an arbitrary-sized message, and describing how to break it into blocks, and how to connect those blocks together. </p><p> <em>Modes of operation</em> are formal descriptions of the way that you<br /> use block encryption on a message that's larger than a single block. Modes of operation (MOOs) are critical in making effective use of a block cipher. Of course, there's always a tradeoff in things like this: you have to choose what properties of your encrypted communication you want to protect. Particularly for DES encryption, the standard MOOs can provide <em>confidentiality</em> (making sure that no one can read your encrypted communication), or integrity (making sure that your communication isn't altered during transmission), but not both.</p> <!--more--><p> To give you a quick and foolishly simple example of that tradeoff, we can consider a real-life example of a simple mode of operation, called the electronic codebook (ECB). In the ECB MoM, you encrypt each block separately, and then just concatenate the results together. Everyone who does crypto knows that ECB is incredibly stupid; no one seriously uses it. The only case I recall hearing of anyone actually using ECB was a multiplayer online role-playing game,<br /> where they encrypted the traffic between players and the game server using ECB.<br /> So every time the player did something, it sent a message to the server, and the server sent back a message telling it how to respond.</p> <p> For performance reasons, games like this tend to do a lot of stuff on the<br /> player's computer. So, for example, when a player gets into a fight with a monster,<br /> the fight was mostly handled on the players computer, and when it was over, it sent<br /> a message to the server, either saying "player died", or "player killed<br /> monster". Since they were using ECB, a player watching network traffic<br /> could easily notice that whenever he killed a type-A monster, his would sent a particular bag-o-bits to the server. That b-o-b was always exactly the same - so while they didn't know exactly what was in the message, they were able to<br /> tell that the way the game told the server that the player killed a monster was<br /> to send those bits.</p> <p> This was, naturally, exploited by clever players, who wrote programs sending<br /> thousands of copies of that b-o-b to the server, racking up credits for killing thousands of monsters. Since it was a message that was set up to be one block long, and it was using ECB, that block always encrypted to the same ciphertext block - so they <em>knew</em> how to tell the server that they killed another monster. They<br /> had no idea of what was actually inside the block - no idea of what data specifically was being transmitted to say "Player A killed an Orc". But because<br /> of the combination of ECB with the way in which the cipher was being used, they<br /> formed a very effective exploit.</p> <p> That's an example of something called a <em>replay</em> attack, where you try<br /> to violate the integrity of the message. Encryption isn't only about hiding the<br /> message plaintext from prying eyes, but about protecting <em>a communication<br /> channel</em> from interference by intruders. In the case of this MMORPG, the<br /> attackers compromised the communication channel <em>without</em> decrypting the<br /> message. They had no idea exactly what the batch-o-bits that they were transmitting<br /> said, but they had a good idea of what they <em>meant</em>, and they were able to<br /> intrude on the communication channel, adding messages that the receiver assumed<br /> were legitimate, because they matched the expected encryption. This kind of attack<br /> is called a <em>replay</em> attack. For this application, the ECB did a decent job<br /> of protecting confidentiality (no one figured out what the specific contents of the<br /> message were, but they were able to figure out what it meant, so it didn't even do<br /> that terribly well), but it did a <em>lousy</em> job with integrity (it was easy to<br /> introduce spurious content to the communication channel without being detectable by<br /> the sender or receiver.)</p> <p> So, moving on, the way to improve the performance of the block cipher is<br /> to use a mode of operation that doesn't just blindly concatenate things.</p> <h3>The Counter (CTR) MoO</h3> <p><em> (I've been alerted by a reader that I made a major mistake in my description of the CTR mode of operation. Since I don't have time to correct it while I'm at work, I'm posting this warning: the information about CTR is incorrect. I'll fix it this evening.)</em></p> <p><strike></strike></p> <p> The simplest MoO beyond ECB is to just add a counter to the process. So, you<br /> XOR your plaintext block with a counter value, and then send it through the<br /> encryption. For a sequence of blocks, you increment the counter for each block. So<br /> a single block encoded multiple times will encode once exclusive-OR'ed with<br /> "1", once with "2", etc. Repeated blocks won't look repeated in the ciphertext.</p> <p> Below is a very simple fragment of pseudo-python that demonstrates<br /> the basic idea of this; next to it is a data-flow diagram illustrating<br /> the same thing. For each of the modes of operation I describe below, I'll provide similar pseudo-code and diagrams.</p> <pre> def EncryptWithCTR(blocks, ctr, key): for b in blocks: encrypted = encrypt(key, b ^ ctr) ctr = ctr + 1 output(encrypted) </pre><p> Of course, just using integers that way isn't ideal. It's hard to detect,<br /> but it's a natural thing to try. What's better is to use a <em>counter function</em>. A counter function is a function F from the natural numbers<br /> to a stream of bits the size of one block. So instead of exclusive-ORing<br /> cleartext block #I with "I", you XOR it with F(I). If your counter function<br /> is pseudo-random, this can be very effective. Despite the fact that this is<br /> potentially a significant benefit, most implementations that I've seen using<br /> CTR just use a plain counter - the only variation is that it often doesn't start the counter at 0 or 1.</p> <p></p> <p> Consider how the replay attack would play out with CTR (or any of the others<br /> below). People monitoring the network would be able to detect that <em>a</em> single encoded block would be sent each time a player killed a monster. But they wouldn't know what the specific payload of the message was, and they wouldn't be able to guess how to encode a copy of the block in a way that would work.</p> <p> One of the nice properties of CTR is that it's easy to parallelize: if you know the counter function, then you can encrypt/decrypt blocks in isolation without<br /> needing any information from a previous block. So you can encrypt/decrypt blocks<br /> 3, 4, 5, and 6 at the same time: you know that the key for block 5 is just the<br /> basic key XOR counter(5).</p> <p> Of course, that parallelization is a curse as well as a blessing. Someone<br /> trying to crack your system can also parallelize, and try decrypting multiple blocks at the same time. Once you've got a few blocks broken, getting the rest<br /> becomes relatively easy, and you've got lots of different blocks, some of which may (by chance) be easy to break by brute-force methods.</p> <h3>Feedback Modes of Operation</h3> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-6ae9d659000c03c6ee8da8c3c1e7555d-cbc.png" alt="i-6ae9d659000c03c6ee8da8c3c1e7555d-cbc.png" /></p> <p> Most of the common modes of operation are based on some form of feedback. You<br /> start with an initial block of random bits called an <em>initialization vector</em><br /> (IV), and you encrypt the block XORing the IV somewhere in the process of<br /> generating the ciphertext of the first block. Then for each successive block, you<br /> replace the IV with some kind of output from the previous block.</p> <p> Cipher-block chaining is a simple feedback-based MoO. Basically, you start<br /> with your agreed-upon block of bits in the initialization vector (IV). For the<br /> first block, you exclusive-OR the plaintext with the IV, and then perform the<br /> block encryption. The output ciphertext of the first block is then used as the<br /> IV for the second block; the IV of the third block is the output ciphertext of the second, and so on. So each block is scrambled by mixing it with the ciphertext of the previous blocks. This also avoids the problem of the game, because the same plain text message encrypts to different ciphertext each time.</p> <pre> def EncryptWithCBC(blocks, iv, key): feedback = iv for b in blocks: inblock = b ^ feedback encrypted = encrypt(key, inblock) feedback = encrypted output(encrypted) </pre><p> The big problem with CBC is that it's weak against many kinds of brute-force<br /> attacks. You <em>can't</em> parallelize encryption using CBC: you need to finish encrypting each block before you can encrypt the next; but for decrypting, you can<br /> try to decrypt multiple blocks; and once you've broken two adjacent blocks,<br /> you're pretty much wide-open. </p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-4981c34166621c4b61a8297cd288ed81-cfb.png" alt="i-4981c34166621c4b61a8297cd288ed81-cfb.png" /></p> <p> A slight variation is CFB; it's just a minor reshuffle of the<br /> order of things. In CBC, we XORed the plaintext of the message with an IV,<br /> and then did block encryption on that to produce the ciphertext. In CFB,<br /> to produce the ciphertext, we do the block encryption on the IV, and then XOR the result with the plaintext. The ciphertext of block N is then exclusive-or'ed<br /> with the previous IV to create the IV for block 5.</p> <pre> def EncryptWithCFB(blocks, iv, key): feedback = iv for b in blocks: encrypted = encrypt(key, feedback) out = encrypted ^ b feedback = out output(out) </pre><p> CFB has pretty much the same vulnerabilities as CBC.</p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-644daa121f2135d57771006c25e666db-ofb.png" alt="i-644daa121f2135d57771006c25e666db-ofb.png" /></p> <p> Output feedback (OFB) is yet another variation on the same theme. The only difference is that the input to block N+1 is the output of the block cipher<br /> from step N, <em>before</em> it's exclusive-OR'ed with the plaintext for step N.<br /> The interesting thing about OFB is that the plaintext doesn't affect the output of the block cipher itself: the block cipher encrypts the combination of the key and<br /> some feedback from the previous block - the plaintext gets exclusive-OR'ed afterwards.</p> <pre> def EncryptWithCFB(blocks, iv, key): feedback = iv for b in blocks: encrypted = encrypt(key, feedback) feedback = encrypted out = encrypted ^ b output(out) </pre><p> These are all modes that focus on confidentiality rather than integrity. Integrity protection is more recent innovation, and it's more complicated. In<br /> later posts, I'm going to talk a bit about the cryptanalysis and attacks that are used against block ciphers, and how they interact with different modes of operation. From there, we'll be able to see why these modes don't protect integrity, and show how we can build modes that focus on integrity.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Mon, 09/15/2008 - 04:13</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2120823" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221482147"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Mark, your description of counter mode is <a href="http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Counter_.28CTR.29">completely wrong</a>. The plaintext input is not mixed with the counter before encryption. Counter mode means encrypting only the counter itself, then XORing the cipher output with the plaintext. In other words, it turns a block cipher into a stream cipher.</p> <p>Your latter description (i.e., "counter function") sounds like you're thinking of GCM (<a href="http://en.wikipedia.org/wiki/GCM_mode">Galois Counter Mode</a>).</p> <p>As I said before:</p> <blockquote><p>I like your blog overall, but this series on crypto is a bit dangerous for amateurs. The devil is in the details, and it's very easy to make a critical mistake. So while it's good to give people an intro, I suggest a big warning letting them know that there are some dangerous assumptions lurking below the surface, and that they should always use well-reviewed implementations and protocols (i.e. SSL) rather than rolling their own for pure ego reasons.</p></blockquote> <p>Please consider posting a correction to your blog to avoid misleading people.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120823&amp;1=default&amp;2=en&amp;3=" token="p8vm5xNNx1wwM0kodCXZGU3sDdNaX4YRzIYR67rlpY4"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.rootlabs.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Nate (not verified)</a> on 15 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120823">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2120824" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221484652"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Nate:</p> <p>Thanks for the correction. I've marked it as incorrect, and I'll fix it after work, when I have some time.</p> <p>I disagree with the idea that talking about crypto is "dangerous for amateurs". It's dangerous for amateurs to think that they can go off and be cryptographers without bothering to actually study crytography - but for a series of posts that just tries to explain "what is this stuff?", I don't see the danger.</p> <p>I don't pretend to be an expert on crypto, nor do I represent my explanations as anything more than very high-level intuitive descriptions to give people a clue of what's going on. </p> <p>I don't think that anyone is going to mistake this basket of blog posts for a serious primer on how to become a cryptographer, or how to build and analyze cryptosystems, any more than I think that people are going to think that they're group theorists because they read my group theory posts.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120824&amp;1=default&amp;2=en&amp;3=" token="rq9uM0O2v8epyVnfYYSic-AdVjoUg_YQIL5gNTjJCbk"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 15 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120824">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120825" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221492768"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>The series on cryptography has been very interesting so far, thank you for the time and effort you are putting into it. I am just barely keeping up with whats going on :) The modern crypto techniques are amazing, but I still cant help wondering about security and attacks against mysterious systems. Most of the modern encryption algorithms are very well studied. How difficult is it to take a piece of encrypted message, that has been encrypted by an entirely unknown system, and break it? Might security through obscurity work if I came up with my own methods? Assuming the encryption and decryption processes are completely unknown, Id love to hear your speculation on the strength of systems. Would modern cryptographers just rip my encryption apart like it's wet toilet paper?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120825&amp;1=default&amp;2=en&amp;3=" token="ArNnfignulsxtq25r7l32WXyqklVlcPz7mfEKvcCZkQ"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Niall (not verified)</span> on 15 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120825">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120826" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221566687"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>One of the basic assumptions of information security is that the sufficiently motivated attacker WILL know your algorithm. Bribes, theft, blackmail, court orders and incarceration for contempt of court, whatever it takes.</p> <p>On top of that they probably have an idea of what you're sending. Historically that might have been "From: X; To: Y, etc.", today it might be a compression header followed by a compressed word document header. Worser case, they'll have samples of your plaintext. Worserer case, they'll have samples of plaintext and corresponding ciphertext. Worst case, they can feed arbitrary plaintext into your system and see what pops out.</p> <p>So your security has to rest in your keys. Nothing but your keys. Obscurity and misdirection(*) will help protect you from the casual attacker, but can't be relied upon. That's why you have to get the algorithm right -and- pick good keys for that algorithm. That's extremely hard to do on your own.</p> <p>(*) A good example of misdirection are the id cards that use a barcode that's behind a plastic strip that's transparent to IR, opaque to visible light. Casual attackers will think it's a magnetic strip.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120826&amp;1=default&amp;2=en&amp;3=" token="4d0VbHv3Fx8GhAyKT5j-LqN0wAfgwlbcPzGLvKKlVGs"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Anonymous (not verified)</span> on 16 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120826">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120827" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221567758"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>(hmm, why would I be anonymous earlier?)</p> <p>My intro to crypto class (at the grad level) had a few "here, crack this" problems, but they were pretty restricted since it was more theory than practice. Lots and lots of number theory. :-) We only did cryptanalysis problems that could be done by hand in a reasonable amount of time.</p> <p>Anyway, it was basically a process of looking for structure that gave us insight into the cipher, after making assumptions about the ciphertext (e.g., that it's simple English text). Count the occurance of each ciphertext symbol -- a distinctive pattern of spikes could indicate a simple substitution cipher.</p> <p>Didn't work? Sort the ciphertext symbol into bins. You might see those spikes in each bin when you use, oh, 7 bins. That indicates a substitution cipher with 7 rotors (or whatever they're called -- it's been years).</p> <p>Still didn't work? Try looking for the structure you see with a Playfair cipher. On and on.</p> <p>I don't know how you distinguish between, e.g., DES vs. AES vs. some new cipher developed by the Russians. Hopefully we'll see that in later posts.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120827&amp;1=default&amp;2=en&amp;3=" token="9CjDyx6sn-L2Caa9ptk7d4XChvmxKdmK5hWp2wuj23o"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Chris (not verified)</span> on 16 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120827">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120828" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221743588"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Your discussion of the security issues with CBC mode don't make much sense to me. In general, all the chaining modes are vulnerable to brute force attacks. That's just a consequence of the fact that given the ciphertext and the key, you can decrypt to get the plaintext. </p> <p>Were you trying to get at the idea that CBC mode doesn't parallelize well on the encryption side? If you give me 100 processors, I still can't do CBC encryption of a single long message any faster than with one processor. Or something else? </p> <p>Also, your text description of CFB mode is confused. Your code and diagram look right (the ciphertext from encrypting plaintext K should be encrypted to generate the thing that gets XORed into plaintext K+1), but the text is messed up. </p> <p>And one nitpick: Your OFB code (it looks right otherwise) is titled EncryptWithCFB. </p> <p>CFB also allows variants in which it encrypts only a fraction of a block at a time, but I'm not sure how important that is. (OFB was originally defined with such a variant, if I recall correctly, but there's a big security problem with using that variant!)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120828&amp;1=default&amp;2=en&amp;3=" token="ZoCxYny6MGCVOdf4lk2eahtMG-gXZARclF2rB7jKOAo"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">John Kelsey (not verified)</span> on 18 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120828">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120829" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221841870"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>So, if I'm reading this right, OFB is essentially a "simulated" one-time pad. Instead of using a truly random pad, you use the block cipher as a pseudorandom number generator and build the pad from that. Then you can rebuild the pad as long as you have the seed (the key and the IV).</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120829&amp;1=default&amp;2=en&amp;3=" token="fECAJd9nMqGrCdbcR6nBgCvrtEKpB-_wxLJBxRTRp2U"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">mcow (not verified)</span> on 19 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120829">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120830" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221904904"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>"Particularly for DES encryption, the standard MOOs can provide confidentiality (making sure that no one can read your encrypted communication), or integrity (making sure that your communication isn't altered during transmission), but not both."</p> <p>(Naive user) Why not encrypt once to provide confidentiality and then again (different key) to ensure integrity? When decoding, first decryption ensures preserved integrity and the second, preserved confidentiality.</p> <p>In the same vein,does successive (serial)encryption offer any advantage in confidentiality? How does successive encryption (different keys)scale? Is it just as easy, twice as difficult . . . to decrypt?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120830&amp;1=default&amp;2=en&amp;3=" token="SXOwBi6VgQC8zXPG20Md8oMvnN0vvslWP6zrwwC-oig"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">WuffenCuckoo (not verified)</span> on 20 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120830">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120831" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222408604"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>This series has been included in the <a href="http://staringatemptypages.blogspot.com/2008/09/xle-carnavaxl-des-math-40.html">40th Carnival of Mathematics</a>. Come check out the others.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120831&amp;1=default&amp;2=en&amp;3=" token="T88Ur4OgyLaDjueG3mhmdQdA90aNwjY-dk5pkfCbXcM"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://staringatemptypages.blogspot.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Barry Leiba (not verified)</a> on 26 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120831">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120832" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1222562024"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>The CTR mode description is still incorrect. What you do in CTR mode is to encrypt successive integers ctr, ctr+1, ctr+2, ... and then XOR the plaintext blocks with those ciphertexts. Decryption is just the opposite: you peel off the encryption by XORing the ciphertext with the encryptions of ctr+i.</p> <p>A requirement for security is that the same ctr+i is never used twice with the same key. In practice you can imagine using one of the two next methods:</p> <p>- Before encrypting a plaintext, choose a random ctr,<br /> encrypt with that and transmit the new ctr together with<br /> the ciphertext. If the space from where you choose<br /> counters is large enough then the probability that you<br /> use the same ctr+i twice is negligible.</p> <p>- The encrypter is stateful, that is, he remembers ctr.<br /> ctr is still a part of the ciphertext, but after<br /> encryption is done, ctr is increased to the next free slot<br /> and stored.</p> <p>As for counter function, one usually just increases ctr by one.</p> <p><a href="http://www-08.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ctr/ctr-spec.pdf">http://www-08.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/ct…</a> might be helpful.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120832&amp;1=default&amp;2=en&amp;3=" token="TD42kRTzeP2L6BuU2mD48tzeRD_TARPwK-SDH_BZDNM"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://research.cyber.ee/~lipmaa" lang="" typeof="schema:Person" property="schema:name" datatype="">Helger Lipmaa (not verified)</a> on 27 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120832">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120833" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1269521566"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>How would you explane the basic operations in cryptography?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120833&amp;1=default&amp;2=en&amp;3=" token="fRGuCxhd9Ffjkm1H_k2yjSPd9cegJ6yw0Rvmc_Vv-Uc"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Jack (not verified)</span> on 25 Mar 2010 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120833">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2008/09/15/modes-of-operation-in-block-cr%23comment-form">Log in</a> to post comments</li></ul> Mon, 15 Sep 2008 08:13:04 +0000 goodmath 92630 at https://scienceblogs.com DES Encryption Part 1: Encrypting the Blocks https://scienceblogs.com/goodmath/2008/09/08/des-encryption-part-1-encrypti <span>DES Encryption Part 1: Encrypting the Blocks</span> <div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"><p> As promised, now we're going to look at the first major block<br /> cipher: the DES. DES stands for "data encryption standard"; DES was the first encryption system standardized by the US government for official use. It's an excellent example of a strong encryption system; to this day, while there are several theoretical attacks, there's no <em>feasible</em> attack on a single DES-encrypted message that's better than brute force. The main problem with DES is the shortness of its key: only 56 bits, which makes it downright practical to implement brute-force attacks against it using today's hardware. </p> <p> DES works with 64 bit blocks, and a 56 bit key. As an interesting aside, there are some serious questions about just why the standard key was 56 bits. Officially, the key length is 64 bits, but during the standardization process, the key was modified at the request of the NSA so that 8 of the bits were used as parity checks - that is, as extra bits that could be used for checking the validity of a key. 8 bits for parity checking on a 56 bit key is really overkill - in fact, putting parity checks into the key <em>at all</em> is really rather questionable. There's been a lot of speculation that either<br /> the NSA knew some kind of trick that could be used against a 56 bit key, or that 56 bits put the encryption within the range of what they could crack using a brute force attack. But no one has ever admitted to either solution, and as far as I know, no one knows of any way that a 56 bit key could have been feasibly cracked using brute force with the technology of the time.</p> <p> Anyway - getting past the politics of it, it's still a really interesting<br /> system. It's a rather elegant combination of simplicity and complexity. It's got a simple repetitive structure based on lookup tables, which gives it its deceptive simplicity; but those lookup tables are actually an implementation of a very complex non-linear discrete mathematical system.</p> <!--more--><p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-92217cff997e982ce985a4f669ac8aa0-des-outline.png" alt="i-92217cff997e982ce985a4f669ac8aa0-des-outline.png" /></p> <p> The basic structure is a three-step process: permute the input data,<br /> run it through a sequence of 16 passes using a ladder-like data flow structure,<br /> and then reverse the initial permutation.</p> <p> The permutation is an interesting step: it doesn't really add<br /> anything to the encryption as such. What it does is add a step to the <em>computation</em>: since there's no known attack short of brute force,<br /> it serves to increase the time it takes to perform a brute-force attack. To crack a message, you need to do the encryption and/or decryption process, and that means doing the permutations - which take time. All that the permutations at<br /> the start and finish of the process do is add computation time, so that cracking<br /> the encryption by brute force requires more work.</p> <p> The interesting thing is what comes after the permutation. You split the<br /> input block into two 32-bit sub-blocks, which each contain half of the permuted<br /> block. Then you pass the subblocks through an encryption ladder called a Feistel structure, where at each step, one of the two blocks is put through<br /> something called a Feistel block. The output from the Feistel structure is then exclusive-or'ed with the result of the previous step. This is illustrated by the diagram to the right.</p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-571223847187f8305d4c442b5c514b35-f-box.png" alt="i-571223847187f8305d4c442b5c514b35-f-box.png" /></p> <p> The Feistel-box folds the encryption key into the process. What happens<br /> in each F-box is illustrated in the diagram to the right. You get a 32 bit<br /> half-block, and a 48-bit subkey. (I'll explain about getting the subkeys in<br /> a moment.) The Feistel-box does four things:</p> <ol> <li> Expand the input half-block from 32 to 48 bits by reshuffling and copying some bits. If you number the bits from 0 to 31, the expanded 48-bit block<br /> consists of the numbered bits: [31, 0, 1, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 8, 9, 10, 11, 12, 11, 12, 13, 14, 15, 16,<br /> 15, 16, 17, 18, 19, 20, 19, 20, 21, 22, 23, 22, 23, 24, 25, 26, 27, 28, 27, 28, 29, 30, 31, 0]. So you start with a copy of bit 31, and then do the bits roughly in order, duplicating the pairs (3,4), (7,8), (11,12), (19,20), (22,23),<br /> (27,28), and ending with bit 0. </li> <li> Exclusive-or the expanded half-block with the subkey;</li> <li> Break the resulting 48 bits into 8 six-bit micro-blocks.</li> <li> Run each six-bit micro-block through a <em>substitution box</em> (or S-box), generating a 4 bit result.</li> </ol> <p> The result of the S-boxes are concatenated together, resulting in a<br /> 32 bit result, which is then put through a permutation, giving the final<br /> output of the F-box.</p> <p> You can think of the expansion, X-or, and S-box complex as a sort of substitution cipher; and the final permutation is, obviously, a permutation cipher. So the full process of DES can be thought of a rather complicated series of permutations and substitutions. One of the key roles of the encryption key is that it effectively selects <em>where</em> the copied bits are really going to be passed through into the output of the S-boxes: since each S-box takes 6 bits, but loses two of them, it's really doing a four-bit substitution. But which four bits? That's really controlled by the subkey.</p> <p> The purpose of the whole Feistel function rigamarole - the splitting of<br /> the block, the shuffling through the ladder of F-boxes, the expansion, contraction, and permutation of the half-block as it moves through the F-box, was<br /> described in terms of information theory by Claude Shannon rather elegantly,<br /> as part of a general description of how encryption worked in terms of information theory: "confusion and diffusion". That's exactly what's going on: shuffle things around, diffuse the bits of the plaintext message all over the place,<br /> so that without knowing how the key guided it, the end-result is a very complex string of information, which mixes the plaintext, the encryption key, and various information about the particulars of the S-boxes in a thoroughly confused and diffused way. That's a big part of what makes this a good encryption system: there's a lot of information being added to the string, and without the key, you don't know how the separate the information you want from the information you don't.</p> <p><img src="http://scienceblogs.com/goodmath/wp-content/blogs.dir/476/files/2012/04/i-c26f2e870fba81fc2746083c87b138f5-key-schedule.png" alt="i-c26f2e870fba81fc2746083c87b138f5-key-schedule.png" /></p> <p> And where do the subkeys come from? It's a process vaguely similar to the<br /> ladder process connecting the F-boxes. You start with the 56 bit key, which you<br /> permute, and then split in half. Then you push the two halves through a<br /> left-bitshift and a permutation, generating the first subkey. Then you shift and<br /> permute again, getting the second subkey. And again, getting the third. And so on.<br /> The basic process is illustrated in the figure.</p> <p> Alas, all of this is rather vague, because I haven't described the specific permutation functions, or the S-box functions. But they're actually pretty boring:<br /> just lots of complicated tables. If you really want to see them, there's a decent list of the tables on the Wikipedia page on <a href="http://en.wikipedia.org/wiki/DES_supplementary_material">DES supplementary material.</a></p> <p> And all this is just the one-block encryption! We haven't even gotten into how the various modes of operation enter the picture. That's the next post.</p> </div> <span><a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a></span> <span>Mon, 09/08/2008 - 04:11</span> <div class="field field--name-field-blog-tags field--type-entity-reference field--label-inline"> <div class="field--label">Tags</div> <div class="field--items"> <div class="field--item"><a href="/tag/encryption" hreflang="en">Encryption</a></div> </div> </div> <section> <article data-comment-user-id="0" id="comment-2120781" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220864328"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>why 12 parity bits, and not 8 (64-56)?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120781&amp;1=default&amp;2=en&amp;3=" token="KiCYjO0bKp7eUci_9DMRubVK1x_bQJFf9ND7bkJm4tc"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">.mau. (not verified)</span> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120781">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2120782" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220864578"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>.mau.:</p> <p>I wish I knew. I have no idea what I was thinking when I wrote 12! I corrected it.</p> <p> -Mark</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120782&amp;1=default&amp;2=en&amp;3=" token="rEtryIlte2pTv_YJHXOw5eRnN3vpCPsTRQCInof3ZhY"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120782">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120783" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220867032"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Is there some way to quantify what it means to have a good block cipher, or were the various tables in DES just chosen randomly, hoping for the best?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120783&amp;1=default&amp;2=en&amp;3=" token="vRCeewpEAQdsrYJgkLs1mVUgAZd1OlWQb_AyEN9lIl4"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Flaky (not verified)</span> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120783">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120784" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220875157"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Are you sure that EP doubles (22,23), not (23,24)?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120784&amp;1=default&amp;2=en&amp;3=" token="5juzIiHiojgeZoQWcA0NCWdrTS0xiviD1qF-2LTLt3M"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://unapologetic.wordpress.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">John Armstrong (not verified)</a> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120784">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120785" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220879649"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Following on from Flaky's question, how would one go about producing a "custom" DES that was (theoretically) as secure as the original but used different look-up tables and permutations?</p> <p>(Obviously it would be an insanely bad idea to use this in a real-world crypto application, I'm just curious what the logic is.)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120785&amp;1=default&amp;2=en&amp;3=" token="ObIy9q2JiL7_oWvJHBoWOOBH4H0bSHso_x8hQ8KQ45g"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://metasyntactic.blogspot.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Corkscrew (not verified)</a> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120785">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2120786" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220880326"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>John (#4):</p> <p>No, I'm not sure. I'll have to check my text to make sure I didn't make a copy error. Since I don't have it with me, I'll check later, and let you know.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120786&amp;1=default&amp;2=en&amp;3=" token="PJUEOjGBIgnwtrmZNlKWgRKMmSlNfVZynwVX2G9mkIU"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120786">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2120787" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220880624"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Flaky (#3) and Corkscrew (#5):</p> <p>The tables for the S-boxes for DES are definitely <em>not</em> random. They're based on discrete non-linear functions with particular properties. I'll write a bit about them in a future post. But the key thing is, there are some very special properties of those functions.</p> <p>A big part of the important thing is the interaction between<br /> the key, the expansion function, and the S-box substitutions. Effectively, some bits are getting fussed about in ways where you <em>don't know</em> where the real bit is going to wind up, because it depends (in turn) on the subkey. The s-box functions have to be carefully designed to make sure that the original plaintext information can't get lost, no matter what the key. Since you're dropping two bits from every S-box input, making sure that nothing is lost is critical - the S-boxes are designed to interact with the bits in a way that is unpredictable, and yet guarantees that no data is lost.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120787&amp;1=default&amp;2=en&amp;3=" token="W5ePql93vhKUgrWVxuoQs6aJdIL-fkPa6M8r1WM1Q-s"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120787">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120788" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220883869"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I'm an admitted amateur at this, but could some of you experts please take a look at this: <a href="http://www.colorblynd.com">www.colorblynd.com</a></p> <p>It is an encryption algorithm that I devised a few years ago that is a symmetric, variable length block cipher with variable key length and variable key count. Some similarities with DES, but I think it might have some real potential.</p> <p>The color aspect is just a gimmick for visual appeal, the real power lies in the variable meta-key aspect. Email me if you are interested or might be able to help me further this.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120788&amp;1=default&amp;2=en&amp;3=" token="gAWmG-YQmeIb4Q6oGEIus3qX5YpJpDmugfF7GtIMNuM"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.colorblynd.com" lang="" typeof="schema:Person" property="schema:name" datatype="">Sam Douglas (not verified)</a> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120788">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120789" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220884748"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>In the systems I used to work with (ATMs and point-of-sale debit machines), Triple DES (or 3DES) was used to extend the key to up to 192 bits.</p> <p>B'=E(K3,E^-1(K2,E(K1,B)))</p> <p>where E is a standard DES operation, and K1, K2, and K3 are 64 bit keys. However, most implementations used a 128 bit key where K3=K1.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120789&amp;1=default&amp;2=en&amp;3=" token="euaiPFTzV5w5-7wnZDOw2VImYB66-hNkLM0Qd_zAGHg"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">GDC (not verified)</span> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120789">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120790" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220927369"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>The spooks probably chose 56 bits because there exists 28 real bitangents of the plane quartic curve. Extend that to the complex numbers and you got 56 bits. They are probably exploiting some geometric property to crack the shit out of that stuff. I have absolutely no idea how to elucidate the connection right now, but I am pretty sure its there.</p> <p><a href="http://mathworld.wolfram.com/Bitangent.html">http://mathworld.wolfram.com/Bitangent.html</a><br /> <a href="http://mathworld.wolfram.com/QuarticCurve.html">http://mathworld.wolfram.com/QuarticCurve.html</a></p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120790&amp;1=default&amp;2=en&amp;3=" token="1OVs0GudHQSe9My2N3_C4YE-i1WvUDXHaxFUZP0six8"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Stephen Crowley (not verified)</span> on 08 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120790">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120791" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220946199"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><blockquote><p> If you number the bits from 0 to 31, the expanded 48-bit block consists of the numbered bits: [31, 0, 1, 2, 3, 4, 3, 4, 5, 6, 7, 8, 7, 8, 9, 10, 11, 12, 11, 12, 13, 14, <b>15, 16, 15, 16</b>, 17, 18, 19, 20, 19, 20, 21, 22, 23, 22, 23, 24, 25, 26, 27, 28, 27, 28, 29, 30, 31, 0]. </p></blockquote> <p>If you read that carefully, you'll see that the pair (15,16) is duplicated.</p> <blockquote><p> So you start with a copy of bit 31, and then do the bits roughly in order, duplicating the pairs (3,4), (7,8), (11,12), (19,20), (22,23), (27,28), and ending with bit 0. </p></blockquote> <p>But then you forget to mention it in your summary.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120791&amp;1=default&amp;2=en&amp;3=" token="YEFSrKPt_689on0wF_mBl7jtdCnMaLwifmnM68WASm4"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">llewelly (not verified)</span> on 09 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120791">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120792" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220957709"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Hi Mark. I like your blog overall, but this series on crypto is a bit dangerous for amateurs. The devil is in the details, and it's very easy to make a critical mistake. So while it's good to give people an intro, I suggest a big warning letting them know that there are some dangerous assumptions lurking below the surface, and that they should always use well-reviewed implementations and protocols (i.e. SSL) rather than rolling their own for pure ego reasons. As an example how dangerous it can be for even experts, you might like this <a href="http://www.matasano.com/log/531/rsa-signature-forgery-explained-with-nate-lawson-wrapup/">series of articles</a> I co-authored on a subtle flaw in some RSA implementations.</p> <p>On a factual note, the IP and FP do <i>not</i> affect brute force attacks at all. This can easily be shown. Take a hypothetical brute force solver that works on "raw" DES (without the permutation) but fails somehow due to the permutation. Now run the ciphertext you plan to attack through the inverse (FP^-1) of the final permutation. Now you have a form that can be attacked by BFS.</p> <p>The best explanation why the permutations were there was to make software implementations more difficult than hardware. In fact, the original design of DES was originally going to remain secret, but was later published.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120792&amp;1=default&amp;2=en&amp;3=" token="d4BHxDSXdcNGXZI10PLD9e5DHaFdTJQ4B8W4PVIGxLs"></drupal-render-placeholder> </div> <footer> <em>By <a rel="nofollow" href="http://www.rootlabs.com/" lang="" typeof="schema:Person" property="schema:name" datatype="">Nate (not verified)</a> on 09 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120792">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120793" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220961576"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Mark, I don't understand your comment that "The s-box functions have to be carefully designed to make sure that the original plaintext information can't get lost, no matter what the key." Isn't that automatically true of any Feistel network, no matter what the f-functions look like? It looks to me like the Feistel network is guaranteed by its structure to be a 1-1 function, and so it can always be inverted.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120793&amp;1=default&amp;2=en&amp;3=" token="sYy-LSGvSDlUUYBVbKCrQ1wL40_nFuKEu6fZgkDPHNc"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Dave Empey (not verified)</span> on 09 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120793">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="138" id="comment-2120794" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220962176"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Dave:</p> <p>The Feistel structure doesn't guarantee that no information was lost <em>unless</em> the functions in the F-boxes (and, in turn, in the S-boxes) satisfy certain conditions. You can easily come up with implementations of S-boxes that wouldn't work. (For example, if the S-boxes were an alternating series of "drop last two bits" and "drop first two bits", then you could wind up with multiple inputs to the F-box producing the same output.</p> <p>People generally say that a Feistel network provides certain guarantees - but that's because the definition of the Feistel network places certain requirements on the function<br /> iterated by the network. (The constraint is usually expressed by requiring that the iterated function be a sound psuedorandom function.)</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120794&amp;1=default&amp;2=en&amp;3=" token="53TLRfQlJmyXWEPGRkKfT3IXKTrlCWGyBxUT036UMSk"></drupal-render-placeholder> </div> <footer> <em>By <a title="View user profile." href="/goodmath" lang="" about="/goodmath" typeof="schema:Person" property="schema:name" datatype="">goodmath</a> on 09 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120794">#permalink</a></em> <article typeof="schema:Person" about="/goodmath"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/goodmath" hreflang="en"><img src="/files/styles/thumbnail/public/pictures/markcc.jpg?itok=PmLQEFZp" width="92" height="100" alt="Profile picture for user goodmath" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120795" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1220965192"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Mark, I'm still missing something, or we are talking at cross-purposes. If we divide the block to be encoded into two equal parts x and y, then one round of a Feistel network will map (x,y) into (y,x XOR f(y)). This is 1-1 no matter what f() is: given y and x XOR f(y), you recover x by taking x XOR f(y) XOR f(y). Since the composition of 1-1 functions must be 1-1, the whole cipher is also certain to be 1-1, so no data can be lost, no matter what f() looks like. I can see where there could be a problem if you combined x and f(y) with something other than an XOR, but the XOR is part of the definition of a Feistel network, isn't it?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120795&amp;1=default&amp;2=en&amp;3=" token="_soxkkAyq3IZUswpFwtDEBLN4dwHbEe4ju_pWJJuMns"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Dave Empey (not verified)</span> on 09 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120795">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120796" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221042582"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>I have to agree with Dave. It really doesn't matter what f is, feistel networks are permutations as xor is a part of the definition. Now, what f is matters greatly to the security of the resulting cipher.</p> <p>If the f for each round is a random function, then you only need 5 rounds for a very secure blockcipher. If f is cryptographically pseudorandom then 5 rounds still gives you a pretty good blockcipher. Its just that cryptographically pseudorandom or just plain random functions are either difficult or impossible to compute, and usually one wants encryption to be really, really, really fast. </p> <p>So we have S-boxes. We lose the theoretical proof of security, but its not that bad.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120796&amp;1=default&amp;2=en&amp;3=" token="slBmxk3FQdzrz2DCsqZzagpUNu7_lveWEqHy0wZ5km0"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">That Other Guy (not verified)</span> on 10 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120796">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120797" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221067009"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>Is my understanding wrong, or did the NSA make a change to DES that improved its defense against differential cryptography?</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120797&amp;1=default&amp;2=en&amp;3=" token="TUuznYfylKWuh2-aUa5UC7kk6MEqmZyU4WNJ9yBz7RY"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Freak (not verified)</span> on 10 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120797">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> <article data-comment-user-id="0" id="comment-2120798" class="js-comment comment-wrapper clearfix"> <mark class="hidden" data-comment-timestamp="1221335523"></mark> <div class="well"> <strong></strong> <div class="field field--name-comment-body field--type-text-long field--label-hidden field--item"><p>"The best explanation why the permutations were there was to </p> <p>That may be true. A friend of mind back in college did his undergraduate thesis on a software implementation of the DES. He was working on the Multics Honeywell 68xx series machine which had all kinds of multiple word bit operation and table lookup instructions, including support for odd byte lengths. Needless to say his solution was surprisingly efficient. His advisor was rather surprised at the time. Luckily, this was an undergraduate thesis, so my friend and his advisor figured out what the rest of his paper should be.</p> </div> <drupal-render-placeholder callback="comment.lazy_builders:renderLinks" arguments="0=2120798&amp;1=default&amp;2=en&amp;3=" token="fmS3dehTEshx_VvYSnApXEfVn1CKF_E5rO_CZTRyBAw"></drupal-render-placeholder> </div> <footer> <em>By <span lang="" typeof="schema:Person" property="schema:name" datatype="">Kaleberg (not verified)</span> on 13 Sep 2008 <a href="https://scienceblogs.com/taxonomy/term/20098/feed#comment-2120798">#permalink</a></em> <article typeof="schema:Person" about="/user/0"> <div class="field field--name-user-picture field--type-image field--label-hidden field--item"> <a href="/user/0" hreflang="und"><img src="/files/styles/thumbnail/public/default_images/icon-user.png?itok=yQw_eG_q" width="100" height="100" alt="User Image" typeof="foaf:Image" class="img-responsive" /> </a> </div> </article> </footer> </article> </section> <ul class="links inline list-inline"><li class="comment-forbidden"><a href="/user/login?destination=/goodmath/2008/09/08/des-encryption-part-1-encrypti%23comment-form">Log in</a> to post comments</li></ul> Mon, 08 Sep 2008 08:11:55 +0000 goodmath 92627 at https://scienceblogs.com